~/bend-docscommunity

cuda.bend source

cuda.bend on the hub · documented module

# bend-cuda-launcher: write CUDA kernels as source text in Bend, compile them at run time (NVRTC), launch them on Bend arrays.#   import bend-cuda-launcher@<version>/cuda.bend as CU## Cu.module(source) compiles CUDA C++ source for the GPU in use and answers its handle (0, 1, 2, ...). A prelude# comes first, so a kernel is written#   BEND_KERNEL name(BEND_ARGS) { ... }# and receives a0 .. a5 (BendArr: .c, the cells as unsigned*, and .n, how many cells the array holds) and p# (BendP: .v[0 .. 11]); bf(u) and bu(x) turn cell bits into float and back. A compile error prints NVRTC's log# (line numbers of your source) and stops the program.## Cu.run(module, name, gx, gy, gz, bx, by, bz, smem, a0, a1, a2, a3, a4, a5, p0 .. p11) launches the kernel `name` on# a gx x gy x gz grid of bx x by x bz blocks with smem bytes of dynamic shared memory, waits for it, and answers the# six arrays. Unused arrays: any 1-cell array; unused parameters: 0. The arrays are read and written in place.## A kernel can write past an array's end: nothing here stops it. Check every index against .n.# Needs a native CUDA build of a program whose `!` call's result is used (Bend's heap in CUDA managed memory),# libnvrtc at run time, and Bend 2.0.40 (the C reads runtime internals). Foreign code: nothing here is proved.import Basedef Cu.module(source: String) -> IO(U32):  import "./effs/cuda.c"  import "./effs/cuda_module.js"def Cu.run(module: U32, name: String, gx: U32, gy: U32, gz: U32, bx: U32, by: U32, bz: U32, smem: U32, a0: Array<U32>, a1: Array<U32>, a2: Array<U32>, a3: Array<U32>, a4: Array<U32>, a5: Array<U32>, p0: U32, p1: U32, p2: U32, p3: U32, p4: U32, p5: U32, p6: U32, p7: U32, p8: U32, p9: U32, p10: U32, p11: U32) -> IO(Array<U32> & Array<U32> & Array<U32> & Array<U32> & Array<U32> & Array<U32>):  import "./effs/cuda.c"  import "./effs/cuda_run.js"