~/bend-docscommunity

test/cuda_test.bend relies on unsafe/foreign

raw source on the hub · import bend-cuda-launcher@0.1.0.0/test/cuda_test.bend as Cuda_test

Cu.module and Cu.run against the same computations in plain Bend: an elementwise kernel with an F32 parameter (exact: written with __fmul_rn / __fadd_rn, since NVRTC, like nvcc, fuses a * b + c into one rounding by default), a per-row sum with dynamic shared memory (to 1e-5), a transpose on a 2D grid (exact), and the array sizes a kernel sees (.n, exactly each array's capacity). Prints each check; exits 1 if one fails. Native CUDA build: bend cuda_test.bend -o cuda_test && ./cuda_test

2 imports
import Base
import ../cuda.bend as CU

Definitions

def source source · line 20 · raw

String

def mix source · line 43 · raw

@+x:U32 -> U32

def rnd source · line 48 · raw

@+i:U32 -> @+seed:U32 -> F32

def one source · line 59 · raw

@u:Unit -> Array<U32>

def report source · line 164 · raw

@+name:String -> @+bad:U32 -> IO(Bool)

def ping source · line 228 · raw

@+x:U32 -> U32

Unsafe

unsafe fv source · line 9 · raw

@u:U32 -> F32

unsafe uv source · line 15 · raw

@x:F32 -> U32

unsafe fill source · line 52 · raw

@done:Bool -> @+i:U32 -> @+n:U32 -> @+seed:U32 -> @a:Array<U32> -> Array<U32>

unsafe chk_axpb source · line 66 · raw

@done:Bool -> @+i:U32 -> @+n:U32 -> @+s:F32 -> @+bad:U32 -> @a:Array<U32> -> @b:Array<U32> -> @c:Array<U32> -> U32

c[i] == a[i] * s + b[i], i < n

unsafe chk_axpb_a source · line 74 · raw

@+i:U32 -> @+n:U32 -> @+s:F32 -> @+bad:U32 -> @b:Array<U32> -> @c:Array<U32> -> @g:Pair(Array<U32>, U32) -> U32

unsafe chk_axpb_b source · line 80 · raw

@+i:U32 -> @+n:U32 -> @+s:F32 -> @+bad:U32 -> @a:Array<U32> -> @c:Array<U32> -> @+av:F32 -> @g:Pair(Array<U32>, U32) -> U32

unsafe chk_axpb_c source · line 86 · raw

@+i:U32 -> @+n:U32 -> @+s:F32 -> @+bad:U32 -> @a:Array<U32> -> @b:Array<U32> -> @+want:U32 -> @g:Pair(Array<U32>, U32) -> U32

unsafe sum_row source · line 93 · raw

@done:Bool -> @+j:U32 -> @+k:U32 -> @+base:U32 -> @+acc:F32 -> @a:Array<U32> -> Pair(Array<U32>, F32)

the sum of a's k cells from base

unsafe sum_row_g source · line 101 · raw

@+j:U32 -> @+k:U32 -> @+base:U32 -> @+acc:F32 -> @g:Pair(Array<U32>, U32) -> Pair(Array<U32>, F32)

unsafe chk_rows source · line 108 · raw

@done:Bool -> @+r:U32 -> @+rows:U32 -> @+k:U32 -> @+bad:U32 -> @a:Array<U32> -> @s:Array<U32> -> U32

|s[r] - sum of row r| <= 1e-5 * (1 + |sum|), r < rows

unsafe chk_rows_s source · line 116 · raw

@+r:U32 -> @+rows:U32 -> @+k:U32 -> @+bad:U32 -> @s:Array<U32> -> @g:Pair(Array<U32>, F32) -> U32

unsafe chk_rows_v source · line 122 · raw

@+r:U32 -> @+rows:U32 -> @+k:U32 -> @+bad:U32 -> @a:Array<U32> -> @+want:F32 -> @g:Pair(Array<U32>, U32) -> U32

unsafe chk_tr source · line 130 · raw

@done:Bool -> @+i:U32 -> @+rows:U32 -> @+cols:U32 -> @+bad:U32 -> @m:Array<U32> -> @t:Array<U32> -> U32

t[c * rows + r] == m[r * cols + c]

unsafe chk_tr_m source · line 138 · raw

@+i:U32 -> @+rows:U32 -> @+cols:U32 -> @+bad:U32 -> @t:Array<U32> -> @g:Pair(Array<U32>, U32) -> U32

unsafe chk_tr_t source · line 144 · raw

@+i:U32 -> @+rows:U32 -> @+cols:U32 -> @+bad:U32 -> @m:Array<U32> -> @+mv:U32 -> @g:Pair(Array<U32>, U32) -> U32

unsafe chk_sizes source · line 151 · raw

@+w:List<&1, U32> -> @z:Array<U32> -> @+i:U32 -> @+bad:U32 -> U32

z[0 .. 4] == the five capacities

unsafe chk_sizes_g source · line 159 · raw

@+t:List<&1, U32> -> @+i:U32 -> @+bad:U32 -> @+h:U32 -> @g:Pair(Array<U32>, U32) -> U32

unsafe t_axpb source · line 172 · raw

@+m:U32 -> IO(Bool)

unsafe axpb_got source · line 178 · raw

@r:Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Array<U32>))))) -> IO(Bool)

unsafe t_rows source · line 184 · raw

@+m:U32 -> IO(Bool)

unsafe rows_got source · line 190 · raw

@r:Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Array<U32>))))) -> IO(Bool)

unsafe t_tr source · line 196 · raw

@+m:U32 -> IO(Bool)

unsafe tr_got source · line 202 · raw

@r:Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Array<U32>))))) -> IO(Bool)

unsafe t_sizes source · line 208 · raw

@+m:U32 -> IO(Bool)

unsafe sizes_got source · line 214 · raw

@r:Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Pair(Array<U32>, Array<U32>))))) -> IO(Bool)

unsafe all source · line 220 · raw

@+m:U32 -> IO(Unit)

unsafe main source · line 232 · raw

IO(Unit)