higherorderco / bend Goto Github PK
View Code? Open in Web Editor NEWA massively parallel, high-level programming language
Home Page: https://higherorderco.com
License: Apache License 2.0
A massively parallel, high-level programming language
Home Page: https://higherorderco.com
License: Apache License 2.0
color = demo_shader
should be
color = shader
When doesnt_work()
is uncommented, the code:
object Vec3 {x, y, z}
def abs(x):
if x < 0.0:
return -1.0 * x
else:
return x
def works():
return Vec3 {x: 0, y: 1, z: 0}
#def doesnt_work():
# return Vec3 {x: 0.0, y: 1.0, z: 0.0}
def main():
return "Hello, World!"
yields the error:
assertion failed: expo >= -63 && expo <= 63
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
exit status: 101
Hello there, this project looks incredible! Had a quick look at the code and found out a thing, that could be correct, but at the same time here is an alternative would make sense, let me know what you think!
Is your feature request related to a problem? Please describe.
Expr
and Stmt
types are defined as enums
, which can make it difficult to work with their data fields. Accessing fields requires pattern matching or using tuple indexing, which can be error-prone.
Describe the solution you'd like
Using structs
instead of enums
so that each variant's fields can be named and accessed directly.
Describe alternatives you've considered
One alternative would be to keep using enums but add helper methods or functions to access the fields in a more convenient way. However, this would very likely just add an extra layer of indirection and complexity.
An example where this could be done is in src/imp/mod.rs
Hope this helps!
Please can you provide a grammar definition for Bend's imperative syntax, and review the grammar definition for the functional syntax? Do you plan to release a language server (LSP)?
I have experience with language integration for the JetBrains IntelliJ Platform and would like to contribute such a language plugin to your project. In fact, I have already submitted the first release to the JetBrains Marketplace for approval. Unfortunately I can't commit to completing the grammar definitions myself, however I can work around incompleteness to maximise the developer experience for the time being.
I will also happily share or migrate both the repository and marketplace page to you guys. 🙌🏻
Is your feature request related to a problem? Please describe.
I want to use Bend to perform some parallel computations for a research paper, however, the values used in it do not fit into a 24-bit integer, therefore I would need at least 32-bit integers, at most - 64-bits.
Describe the solution you'd like
Support of 32 or 64 bit integers in Bend/HVM. Due to untyped nature of the language, maybe this can be configured per program via a flag.
Describe alternatives you've considered
OpenCL or manual CUDA code
The following code results in the following panic (instead of a syntax error).
Main = (List.at 1 [10,20,30])
data NotFound.T = NotFound
List.at * LNil = NotFound
List.at 0 (LCons x *) = x
List.at +p (LCons * xs) = (List.at p xs)
⬇️
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', src/term/transform/encode_pattern_matching.rs:106:22
stack backtrace:
0: 0x10308ee74 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6d1ef757ca6aa08c
1: 0x102fbf1f4 - core::fmt::write::h24aade456e61cbc1
2: 0x10306fa9c - std::io::Write::write_fmt::h5df313f4d7305ca8
3: 0x1030926a8 - std::sys_common::backtrace::print::h509ed65c6d882fc0
4: 0x1030922e0 - std::panicking::default_hook::{{closure}}::h9d25327d11b3fd1b
5: 0x1030931cc - std::panicking::rust_panic_with_hook::h1d6008cc2f3fe794
6: 0x103092d44 - std::panicking::begin_panic_handler::{{closure}}::hd15752c0e75f10f5
7: 0x103092cb8 - std::sys_common::backtrace::__rust_end_short_backtrace::h6334164110c20096
8: 0x103092cac - _rust_begin_unwind
9: 0x103094d60 - core::panicking::panic_fmt::h09e6dc0b209e1ff9
10: 0x103094db0 - core::panicking::panic_bounds_check::hd8160bda82568c20
11: 0x10304557c - hvml::term::transform::encode_pattern_matching::make_pattern_matching_case::h43cb1431ec698b5d
12: 0x1030442e8 - hvml::term::transform::encode_pattern_matching::make_pattern_matching_case::h43cb1431ec698b5d
13: 0x1030478b0 - hvml::term::transform::encode_pattern_matching::make_num_pattern_matching_case::h363482753de0d2da
14: 0x1030439b8 - hvml::term::transform::encode_pattern_matching::make_pattern_matching_case::h43cb1431ec698b5d
15: 0x103023608 - hvml::encode_pattern_matching::h458283e08e63c9b1
16: 0x10301f904 - hvml::desugar_book::h573b13fbfebc5e1e
17: 0x1030186c4 - hvml::compile_book::ha4683499abf11109
18: 0x10302432c - hvml::run_book::h66005b570d1d9e8e
19: 0x102f7d934 - hvml::main::h8fbd06c6401904b1
20: 0x103065320 - std::sys_common::backtrace::__rust_begin_short_backtrace::hfa8dbb995ed5396e
21: 0x102f81b3c - _main
Grab the CUDA toolkit for WSL from here:
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=WSL-Ubuntu&target_version=2.0&target_type=runfile_local
sudo sh cuda_12.4.1_550.54.15_linux.run
Even tho CUDA is available, the bend run-cu
tells me otherwise:
Error reading result from hvm. Output :
CUDA not available!
it would be nice for learning the language if i could use a repl or jupyter notebook
thanks
The output of the following bend-lang 0.2.7 code executing via bend run
is Result: 5
while it is expected to be Result: "8, 8, "
.
type WindowRow:
Branch {~left, ~right}
Leaf {value}
def concat(str1, str2):
match str1:
case String/Cons:
return String/Cons{head: str1.head, tail: concat(str1.tail, str2)}
case String/Nil:
return str2
def window_row_to_string(win_row, elem_to_string):
match win_row:
case WindowRow/Branch:
left_str = window_row_to_string(win_row.left)
right_str = window_row_to_string(win_row.right)
return concat(left_str, right_str)
case WindowRow/Leaf:
return concat(elem_to_string(win_row.value), ", ")
def main():
return window_row_to_string(
WindowRow/Branch {
left: WindowRow/Leaf {value: 5},
right: WindowRow/Leaf {value: 3}
},
lambda x: "8"
)
Is your feature request related to a problem? Please describe.
I find the approach very useful and thanks for the development of bend!
For some smaller applications, would it be possible to export a time -> execution graph? I have many little scripts that most of them could use some parallelization and exporting the graph would visualize them very quickly (only for very very small programs).
EDIT: Additional benefit is to visually see what was not optimized by the compiler and what could after optimization can get optimized even more.
Describe the solution you'd like
bend run-create-executiongraph <file.hvm>
Describe alternatives you've considered
Imagine the graph is completely above my grade :-) kinda like tinygrad (ml library in python) that can show the graph of all processes that can run in parallel
Currently, the boolean data type is not defined by default; you must define it yourself (see examples/all_tree.bend).
At present, if you perform a comparison like 0 == 0
, it returns 1
.
The boolean values should be like those in Python: True
and False
. The standard operators can also be like those in Python: not
, and
, or
.
Another additional feature you can add is the shortcut version of the operators. To provide different syntax options, you can use the usual C++ syntax: ||
and &&
. The difference between the two types should be that the first ones (Python-style) evaluate all conditions, while the second ones (C++-style) follow the original order and stop as soon as the result is determined. For example, in True || (False || False)
, the evaluation should stop at the first True
because the final outcome is already known.
This is not done for performance reasons but for safety. In other programming languages, it is common to do things like n < len(vector) && vector[n]
, where the shortcut acts as a prevention system to avoid accessing illegal memory locations accidentally.
I = λx x
T = λx λy x
L = λn (λz (z T (L (I n))))
Main = (T I (L I))
when run produces
$ hvml run bug2.hvm
0105d8e00105d8df 010166cc0105d8e1
thread '' panicked at 'internal error: entered unreachable code', /Users/tromp/.cargo/git/checkouts/hvm-core-31580e46fc731f4f/013c775/src/run.rs:690:67
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
When changing L to either
L = λn (λz (z T (L n)))
or
L = λn (λz (z n (L (I n))))
it instead hangs (or loops forever).
It would be nice to create a docker image to run workloads on Kubernetes. I'm going to try to create my own ubuntu (not sure about alpine or how that works) based bend+hvm image and see where that leads.
main = (add 32 10)
x = 0
add x y = (+ x y)
✅ Expected: 42 (or a compilation error saying the name x
is already in scope)
❌ Actual: 10 (the top-level x
is getting used instead of the argument)
Hi!
I believe the description for the first code sample on README is slightly incorrect. Below the code one can read:
This code adds all numbers from 0 to 2^30
But, it's sums the numbers till 2^30, but not the 2^30 itself. For example:
sum(3,0)
will return 28. But the sum from zero to 2^3=8 is, in fact, (1+2+3+4+5+6+7+8)=36. Although, 28+8=36.
The docs should probably be updated like
-match x = 4 {
+switch 4 {
or perhaps
let x = 4
switch x {
// ... use the x-1 syntax
}
This note is in rather small font and is really easily overlooked. Ideally the examples on README.md on the main branch should just work. Otherwise, at least the warning should be put in big red letters like
@renxida ➜ /workspaces/myhvm $ bend --version
bend 0.1.0
@renxida ➜ /workspaces/myhvm $ hvm --version
hvm 1.0.11
@renxida ➜ /workspaces/myhvm $ cat fib.bend
add = λa λb (+ a b)
fib = λx switch x {
0: 1
_: let p = x-1; switch p {
0: 1
_: (+ (fib p) (fib p-1))
}
}
main = (fib 30)@renxida ➜ /workspaces/myhvm $ bend run fib.bend
Errors:
Error reading result from hvm. Output :
Expected `Term`:
2 | HVM_MAIN_CALL = .out.hvm
exit status: 1
@renxida ➜ /workspaces/myhvm $ bend compile fib.bend
Warnings:
In definition 'add':
Definition is unused.
@add = ($(:[+] $(a b)) (a b))
@fib = (?((1 @fib__C1) a) a)
@fib__C0 = ({$([+1] a) b} d)
& @fib ~ (a $(:[+] $(c d)))
&! @fib ~ (b c)
@fib__C1 = (?((1 @fib__C0) a) a)
@main = a
& @fib ~ (30 a)
@renxida ➜ /workspaces/myhvm $
@renxida ➜ /workspaces/myhvm $ cat add.bend
def main:
return 2 + 3
@renxida ➜ /workspaces/myhvm $
</details>
When I run the compiled CUDA bitonic sorter example (linked in the README) I get this error:
Failed to launch kernels (error code an illegal memory access was encountered)!
Steps to reproduce the behavior:
bend gen-cu sorter.bend > sorter.cu
nvcc sorter.cu -o sorter
prime-run ./sorter
(Launches it on the GPU for Arch Linux.)The program runs on the GPU.
The program runs using the C codegen backend, but with the CUDA backend, it seems to fail regardless of what I do. If anyone is curious about the prime-run
command, it's really just a script that forces the dGPU to handle a task - nothing fancy.
Describe the bug
The link to the paper at the end of README.md leads to a non-existing page (404-like error) https://paper.higherorderco.com/
while the actual link to HVM2 paper should be smthg along the lines of: https://github.com/HigherOrderCO/HVM/blob/main/paper/PAPER.pdf
Does this natively support parallelism accross gpus?
Also feature request: natively perform flash attention please
Thank you for Bend, it seems very neat!
Describe the bug
Getting strange output, instead of the (idx, value) for the tree, as per the GUIDE.md.
To Reproduce
Steps to reproduce the behavior:
bend run ./main.bend
type Tree:
Node { ~lft, ~rgt }
Leaf { val }
def enum(tree):
idx = 0
fold tree with idx:
case Tree/Node:
return Tree/Node {
lft: tree.lft(idx * 2 + 0),
rgt: tree.rgt(idx * 2 + 1),
}
case Tree/Leaf:
return (idx, tree.val)
def main:
tree = Tree/Node {
lft: Tree/Node { lft: Tree/Leaf { val: 1 }, rgt: Tree/Leaf { val: 2 }, },
rgt: Tree/Node { lft: Tree/Leaf { val: 3 }, rgt: Tree/Leaf { val: 4 }, }
}
return enum(tree)
Result: λa λ* (a λb λ* (b (0, 1) (1, 2)) λc λ* (c (2, 3) (3, 4)))
Expected behavior
I feel like it should only be a list of an index and a value, based on the docs.
Desktop (please complete the following information):
Additional context
It's entirely possible that this is the correct output, but I'm not sure. Unrelated I can't figure out how to implement how to reverse a list either.
Describe the bug
Updating crates.io index Installing hvm v2.0.8 Updating crates.io index Locking 29 packages to latest compatible versions Compiling libc v0.2.155 Compiling utf8parse v0.2.1 Compiling anstyle v1.0.7 Compiling anstyle-query v1.0.3 Compiling is_terminal_polyfill v1.70.0 Compiling colorchoice v1.0.1 Compiling clap_lex v0.7.0 Compiling strsim v0.11.1 Compiling anstyle-parse v0.2.4 Compiling cc v1.0.97 Compiling highlight_error v0.1.1 Compiling TSPL v0.0.12 Compiling anstream v0.6.14 error: linker
cc` not found
|
= note: No such file or directory (os error 2)
error: could not compile libc
(build script) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: failed to compile hvm v2.0.8
, intermediate artifacts can be found at /tmp/cargo-installz7F0B2
.
To reuse those artifacts with a future compilation, set the environment variable CARGO_TARGET_DIR
to that path.`
To Reproduce
Steps to reproduce the behavior:
Is your feature request related to a problem? Please describe.
No.
Describe the solution you'd like
A guide and explanation to whether contributions are accepted, and if so, the proper channels to contribute through
Describe alternatives you've considered
Submitting random issues and PRs? :)
Additional context
Add any other context or screenshots about the feature request here.
Describe the bug
I'm currently trying to install bend with cargo as said in the README, but it's crashing with the following error: https://gist.github.com/Robocraft999/034e7f45073c77f6117a338522e38ad4
I have installed following rust versions:
stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
To Reproduce
Steps to reproduce the behavior:
cargo +nightly install bend-lang
Expected behavior
describe the expected behavior.
Desktop (please complete the following information):
Additional context
Tested on hvml
master commit 89b0c80. Panics:
Main = (+ λx(x) 1)
I understand that this is not correctly typed, but could it maybe print a proper error message? I had to reduce my expression by hand multiple steps to understand what the issue was.
Now the above code only panics and crashes, but it can also be made to hang indefenitely:
Main = (+ λfλx(x) 1)
EDIT: During the writing of this issue I noticed two additional things:
bend run
and bend run-c
.I don't know if those are worthy of separate issues. /EDIT
The example in GUIDE.md with area calculation reveals an operator precedence bug:
type Shape:
Circle { radius }
Rectangle { width, height }
def area(shape):
match shape:
case Shape/Circle:
return 3.14 * shape.radius ^ 2.0
case Shape/Rectangle:
return shape.width * shape.height
def main:
return area(Shape/Circle { radius: 10.0 })
This program returns 985.938 = (3.14 * 10.0)^2.0 and not 313.996 = 3.14 * (10.0^2.0), as expected. Tested with bend run
and bend run-c
on Apple M2. Both numbers also deviate from what you get with python.
An additional note is that I get slightly different results with run
and run-c
, when I replace
return 3.14 * shape.radius ^ 2.0 -> return 3.14 * (shape.radius ^ 2.0)
Hello! I think I've encountered a bug. When running this example from the readme:
def sum(depth, x):
switch depth:
case 0:
return x
case _:
fst = sum(depth-1, x*2+0) # adds the fst half
snd = sum(depth-1, x*2+1) # adds the snd half
return fst + snd
def main:
return sum(30, 0)
The output is 0. I've tried bend run
, bend run-c
, and bend gen-cu
(bend run-cu says cuda is not available, so I manually compile it with nvcc).
The output on my machine when running sum(24, 0)
is 8388608, but on equivalent Haskell and Python programs the programs return 140737479966720. The results start to diverge when depth>=13.
I was wondering what could be causing these issues, both the incorrect result when depth>=13, and the result=0 when depth>=25.
My computer specs:
Hi everyone!
I'm just wondering why Bend is not statically-typed. Here's an example similar to this one.
object V2 { x, y }
def distance(a, b):
open V2: a
open V2: b
dx = b.x - a.x
dy = b.y - a.y
return (dx * dx + dy * dy) ** 0.5
def main():
a = V2 { x: 10.0, y: 10.0 }
b = V2 { x: 20.0, y: 22.0 }
return distance(a, b)
The first thing that I thought was about setting a
and b
as we do in Rust, for example. This would remove the need to open
the variables. We can annotate function output and object fields as well.
object V2 { x: f24, y: f24 }
def distance(a: V2, b: V2) -> f24:
dx = b.x - a.x
dy = b.y - a.y
return (dx * dx + dy * dy) ** 0.5
def main():
a = V2 { x: 10.0, y: 10.0 }
b = V2 { x: 20.0, y: 22.0 }
return distance(a, b)
It looks cleaner to me. Also, currently if I try to pass the incorrect type to the distance
function it does not throws an error about opening a
as V2
. It returns a non-sense value as if it had run correctly. Here's an example.
object V2 { x, y }
def distance(a, b):
open V2: a
open V2: b
dx = b.x - a.x
dy = b.y - a.y
return (dx * dx + dy * dy) ** 0.5
def main():
a = 2.3
b = V2 { x: 20.0, y: 22.0 }
return distance(a, b)
Code output:
bend run hello.bend
Result: 2.300
I don't think every language should be statically-typed as it's a design decision. However, such a non-sense output sounds like a bug to me. What do you guys are planning about it?
Is your feature request related to a problem? Please describe.
I have an AMD GPU so I cannot take advantage of the CUDA running.
Describe the solution you'd like
I would love either an Open-CL or a Vulkan running mode (or both) if possible.
Describe alternatives you've considered
I have tried compiling to CUDA and then running a translation layer to Open-CL but the performance isn't what I expected.
Additional context
None.
Is your feature request related to a problem? Please describe.
Not a problem, but a feature request. It would be extremely useful to have various hash functions and other cryptographic primitives inside of bend.
Describe the solution you'd like
Having standard hash functions such as SHA256 or keccak256, and then ZK oriented hash functions such as Poseidon2, Blake3, RPO, would make Bend a bombshell in the cryptography / blockchain engineering world.
Describe alternatives you've considered
Implementing these hash functions natively in Bend would be time intensive, I was wondering if it is possible to import rust hash function implementations into bend.
I tried the command in the docs to install it in windows
cargo +nightly install hvm bend-lang
and then i ran into an error when it tryied to install the hvm package:
note: hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.04.rcgu.o : error LNK2019: unresolved external symbol hvm_c referenced in function _ZN3hvm4main17h9d0e7038147c7cf8E
C:\Users\reina\AppData\Local\Temp\cargo-installznCpQK\release\deps\hvm-b266db4375d86db5.exe : fatal error LNK1120: 1 unresolved externals
I think it is a windows thing but it was supposed to build on windows now?
The full link command:
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.39.33519\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\reina\\AppData\\Local\\Temp\\rustcD1wes3\\symbols.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.00.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.01.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.02.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.03.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.04.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.05.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.06.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.07.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.08.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.09.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.10.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.hvm.5172ccb141a9a085-cgu.11.rcgu.o" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.8o44al3c0u1vj3af7cq28h0vv.rcgu.o" "/LIBPATH:C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps" "/LIBPATH:C:\\Users\\reina\\.cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\windows_x86_64_msvc-0.52.5\\lib" "/LIBPATH:C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libnum_cpus-24f4a5e95e6d67b9.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libTSPL-aa28b9841fd84d1f.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libhighlight_error-ed7aa468da91f2e6.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libclap-24d7fcf444061c20.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libclap_builder-ca608aa2d49012a5.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libstrsim-1b997b708aecf187.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libanstream-d39fabb69b82ff27.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libanstyle_query-b863eb0643b112e8.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libis_terminal_polyfill-2faf6b245b04076e.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libanstyle_wincon-5c3abe4fc243cd20.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libwindows_sys-8f81600731bfed40.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libwindows_targets-d36526a52e6dcccb.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libcolorchoice-6b425effce0b6fe1.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libanstyle_parse-3317e79119e65ae9.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libutf8parse-5b1735cde9ef2b42.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libclap_lex-dbb8064a384be4e7.rlib" "C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\libanstyle-e3e42454002bbed9.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-ac24efe4baa6f4b5.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-50670a58b21a47e0.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-175d80d3c3db88b7.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-07381e2f40221155.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-c83e267e89319fe0.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-6fd6593ddc25dc10.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-27634911093fa9aa.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-60c84f47f1803ffa.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-5a103e4f86f1aa20.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-7bfd0a6d1a588dbd.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-cca5aeb939a92213.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-0a7d9524c210bd3d.rlib" "C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-d827b00cff8216d8.rlib" "windows.0.52.0.lib" "kernel32.lib" "advapi32.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "kernel32.lib" "ws2_32.lib" "kernel32.lib" "msvcrt.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/LIBPATH:C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Users\\reina\\AppData\\Local\\Temp\\cargo-installznCpQK\\release\\deps\\hvm-b266db4375d86db5.exe" "/OPT:REF,ICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\reina\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
Describe the bug
When running a program with bend run-cu
it says:
Error reading result from hvm. Output :
CUDA not available!
I just installed CUDA on WSL following the nvidia guide and the command nvcc --version
works fine on the same terminal I am running bend. I followed the guide on the README to install bend.
To Reproduce
Run a program with cuda.
Expected behavior
I expect the program to run.
Desktop (please complete the following information):
Terminal output
~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
~$ bend run-cu test.bend
Errors:
Error reading result from hvm. Output :
CUDA not available!
The following code take the first two elements of a list:
I = λx x
T = λx λy x
F = λx λy y
Cons = λx λy λz (z x y)
Two = λf λx (f (f x))
List = (Two (Cons I) F)
Take = λcont λx λxs λz (z x (xs cont))
Main = (List (Two Take (T (T F))))
$ hvml run bug1.hvm
λa ((a λb b) λc ((c λd d) λe e))
which is a list of two elements, but terminated with I instead of F.
We get the correct F termination for taking only one element:
Main = (List (I Take (T (T F))))
$ hvml run bug1.hvm
λa ((a λb b) λ* λc c)
Describe the bug
When running the fib.bend
program with an input value larger than 30, the time to generate an output becomes unusably slow.
In contrast, running the same program in Rust produces a near-instant output. This might be due to the fib.bend
program not being parallelizable.
fib.bend
(very slow):
add = λa λb (+ a b)
fib = λx switch x {
0: 1
_: let p = x-1; switch p {
0: 1
_: (+ (fib p) (fib p-1))
}
}
main = (fib 30)
fibonacci in rust (near instant)
fn fibonacci(n: u32) -> u64 {
if n == 0 {
return 0;
}
let mut prev = 0;
let mut curr = 1;
for _ in 1..n {
let next = prev + curr;
prev = curr;
curr = next;
}
curr
}
fn main() {
let n = 31;
let fib_n = fibonacci(n);
println!("{}", fib_n);
}
To Reproduce
Run fib.bend
with a value larger than 30.
Expected behavior
Similar output speed to Rust.
Desktop (please complete the following information):
OS: macOS
CPU: M2 Pro
Additional context
Just wondering why it is slow. Does the program need to be compiled into HVM first and then executed to run fast?
Is your feature request related to a problem? Please describe.
I want to replace the use of CUDA with Bend within my ROS2 project
Describe the solution you'd like
I was wondering if it has been tested with ROS2 or if it could readily replace CUDA
Describe alternatives you've considered
I've used CUDA.
Additional context
Nothing more :)
Describe the bug
On my machine, the C interpreter (bend run-c
) sometimes hangs or OOMs when running the bitonic sorter example. Just running the same command over and over again results in either an exit after ~3.5s , an infinite loop printing OOM
, or indefinite execution.
The probability of hanging seems to correlate with higher TPC
values (set by changing the output of bend gen-c
):
TPC_L2 |
Threads / TPC (1 << TPC_L2 ) |
Avg. Runtime | Approx. Runs Hanged |
---|---|---|---|
1 | 2 | 13.51s | 0% |
2 | 4 | 5.86s | 0% |
3 | 8 | 3.78s | 0% |
4 | 16 | 2.98s | 6% |
5 | 32 | 2.76s | 12% |
6 | 64 | 3.75s | 60% |
My guess is that there is some sort of thread synchronization problem.
To Reproduce
Steps to reproduce the hanging:
$ curl https://gist.githubusercontent.com/VictorTaelin/face210ca4bc30d96b2d5980278d3921/raw/f0aaa21e137651ae673f67e11d8f553063e1ad69/sorter.bend --output sorter.bend
bend run-c
multiple times.
$ bend run-c sorter.bend
Result: 16515072
$ bend run-c sorter.bend
Result: 16515072
$ bend run-c sorter.bend
[no output for more than 5 minutes with CPU maxed out]
# (extremely rarely)
$ bend run-c sorter.bend
OOM
OOM
OOM
...
Steps to reproduce the TPC changes:
$ bend gen-c sorter.bend > sorter.c
TPC_L2
constant to the desired value. For example, the command below sets it to 3
, resulting in TPC
=8
:
$ sed -i "s/TPC_L2 [0-9]\+/TPC_L2 3/g" sorter.c
$ gcc -pthread -O3 sorter.c -o sorter -lm
$ ./sorter
Result: 16515072
- ITRS: 1259339749
- TIME: 3.47s
- MIPS: 362.84
Expected behavior
I would expect the C interpreter to never OOM or inconsistently hang.
Desktop (please complete the following information):
nvcc --version
)Additional context
This program fails (via hvml run
) with the error In definition 'String.isEmpty': Unbound constructor 'SCons'
:
main = 42
String.isEmpty SNil = 1
String.isEmpty (SCons x xs) = 0
while this one passes:
main = 42
unrelatedString = "x"
String.isEmpty SNil = 1
String.isEmpty (SCons x xs) = 0
Similarly with lists (LCons
and LNil
and unrelatedList = []
).
My expectation was that these would be always known (as a part of some kind of HVM "stdlib"). Otherwise it would mean that HVM requires the higher-level languages using it as a target to perform dead code removal / tree shaking of some sort, and never emit string-facing functions if there are no strings used in the program.
Describe the bug
I installed the Bend lang on WSL2 Windows 11 Pro 64 bit, Ubuntu 24:
BUT:
user@DESKTOP-UID:/mnt/c/Users/User/Downloads$ cargo +nightly install hvm
Updating crates.io index
Ignored package hvm v2.0.8
is already installed, use --force to override
user@DESKTOP-UID:/mnt/c/Users/User/Downloads$ cargo +nightly install bend-lang
Updating crates.io index
Ignored package bend-lang v0.2.7
is already installed, use --force to override
user@DESKTOP-UID:/mnt/c/Users/User/Downloads$ bend --help
Command 'bend' not found, did you mean:
command 'tend' from snap tend (0+git.1ad02aa)
command 'ben' from deb ben (0.10.3ubuntu2)
command 'blend' from deb mrtrix3 (3.0.4-1)
command 'send' from deb mailutils-mh (1:3.16-1build1)
command 'send' from deb mmh (0.4-6)
command 'send' from deb nmh (1.8-1)
command 'bnd' from deb bnd (5.0.1-4)
See 'snap info ' for additional versions.
Is your feature request related to a problem? Please describe.
On high performance computing clusters, MPI is often used as an interface between multiple machines. Adding support for MPI in Bend would allow code to be scheduled on multiple machines and utilize more parallelism.
Describe the solution you'd like
Figure out where to implement MPI (must this be done in HSM2 first) and add support to bend.
Describe alternatives you've considered
N/A
Additional context
N/A
I can't trivially find out what license this is under?
I recommend putting some open source license. I use GPLv3+ for example in https://github.com/purpleidea/mgmt/
Otherwise this will be seen as proprietary software, and probably not be great for adoption.
HTH
When comiling main = switch {}
, there is no parse error for an empty switch statement, so the compiler panics when unwrapping last_mut() in children_mut_with_binds.
thread 'main' panicked at src/fun/mod.rs:656:51: called 'Option::unwrap()' on a 'None' value
A proper error message would be nice.
Version info and replication result:
@renxida ➜ /workspaces/myhvm (main) $ bash ./report.sh treesum.bend
+ bend --version
bend-lang 0.2.5
+ cat treesum.bend
enum MyTree:
Node(val, ~left, ~right)
Leaf
def MyTree.sum(x):
# Sum all the values in the tree.
fold x:
# The fold is implicitly called for fields marked with '~' in their definition.
Node:
return val + x.left + x.right
Leaf:
return 0
def main:
bend val = 0 while val < 0:
# 'fork' calls the bend recursively with the provided values.
x = Node(val=val, left=fork(val + 1), right=fork(val + 1))
then:
# 'then' is the base case, when the condition fails.
x = Leaf
return MyTree.sum(x)
+ bend run treesum.bend
Errors:
In treesum.bend :
- expected: pattern-matching pattern
- detected:
1 | enum MyTree:
@renxida ➜ /workspaces/myhvm (main) $
Does it have any libraries or support libraries from other languages ( Rust, Python etc ...) ?
How can we make a webserver with it ?
Is your feature request related to a problem? Please describe.
Support request for AMD GPUs utilizing AMD ROCm software.
Describe the solution you'd like
bend run-ro file.hvm
# uses the ROCM interpreter (massively parallel)
Describe alternatives you've considered
NA
Additional context
Currently it supports only one vendor, nvidia. however it would be great to support atleast 2 of industry's leading GPU makers. AMD's rocm is an alternative to nvidia's cuda. Requesting an option for the same.
Is your feature request related to a problem? Please describe.
My computer has an AMD GPU and so I can only use "bend run-c"
Describe the solution you'd like
Would it be possible one day to get a compilation for ROCm (I know it is not an easy task)
Additional context
I never really did some research on ROCm and CUDA so my request may be a bit naïve.
This looks like a really cool project!
I just read through the guide, and really liked the writing style :)
At a few points, I was curious, would love to learn more about:
fork
function does exactly?object
and type
, instead of e.g. just struct
and enum
, like in Rust?Bending is the opposite of folding. Whatever
fold
consumes,bend
creates. The idea is that, by defining an initial state and a halting condition, we can "grow" a recursive structure, layer by layer, until the condition is met.
Here I was wondering why bend
was chosen as a keyword? Given the above explanation, wouldn't something like spread
, unfold
, or grow
be more intuitive then? Or are there other use cases not covered in the guide, where bend
makes more sense as a keyword? Or is there some history from other languages?
case Shape/Circle:
Was curious why /
was chosen for these kinds of namespaces / variants, instead of e.g. the ::
like in Rust? Since normally /
is used for division?
Bend comes with 3 built-in numeric types:
u24
,i24
,f24
. That's quite small, we admit. Soon, we'll have larger types.
Is there already a plan for how other types, e.g. u32
, will be indicated? Will there be something like Rust-like type annotations?
Thank you! I'm looking forward to where this project is going :)
return sum(tree)
should be
return enum(tree)
in the def enum example, line 382
data Array
= (Value x)
| (Array a0 a1)
Array.foldl fn init (Value x) = (fn x init)
Array.foldl fn init (Array a0 a1) =
(Array.foldl fn (Array.foldl fn init a0) a1)
main = (Array.foldl
(@x @acc (+ x acc))
// 0 // arity mismatch! uncomment for a program that finishes with `3`
(Array (Value 1) (Value 2)))
The above program calls Array.foldl
with two arguments instead of three, but the compiler doesn't catch that and instead expands the program somehow (can be seen with -d
which I don't know how to read)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.