MCPcopy Create free account
hub / github.com/apache/tvm / check_cuda

Function check_cuda

tests/python/codegen/test_target_codegen_cuda.py:62–93  ·  view source on GitHub ↗
(dtype, n, lanes)

Source from the content-addressed store, hash-verified

60 num_thread = 8
61
62 def check_cuda(dtype, n, lanes):
63 if dtype == "float16" and not have_fp16(tvm.cuda(0).compute_version):
64 print("Skip because gpu does not have fp16 support")
65 return
66 if dtype == "int8" and not have_int8(tvm.cuda(0).compute_version):
67 print("skip because gpu does not support int8")
68 return
69 vec_dtype = f"{dtype}x{lanes}"
70 one = tvm.tirx.const(1, vec_dtype)
71 num_blocks = (n + num_thread - 1) // num_thread
72
73 @I.ir_module(s_tir=True)
74 class Module:
75 @T.prim_func(s_tir=True)
76 def main(A: T.Buffer((n,), vec_dtype), B: T.Buffer((n,), vec_dtype)):
77 T.func_attr({"tirx.noalias": True})
78 for i_0 in T.thread_binding(num_blocks, thread="blockIdx.x"):
79 for i_1 in T.thread_binding(num_thread, thread="threadIdx.x"):
80 with T.sblock("B"):
81 v_i = T.axis.spatial(n, i_0 * num_thread + i_1)
82 T.where(i_0 * num_thread + i_1 < n)
83 T.reads(A[v_i])
84 T.writes(B[v_i])
85 B[v_i] = A[v_i] + one
86
87 fun = tvm.compile(Module, target="cuda")
88
89 dev = tvm.cuda(0)
90 a = tvm.runtime.empty((n,), vec_dtype, dev).copyfrom(np.random.uniform(size=(n, lanes)))
91 c = tvm.runtime.empty((n,), vec_dtype, dev)
92 fun(a, c)
93 tvm.testing.assert_allclose(c.numpy(), a.numpy() + 1)
94
95 check_cuda("float32", 64, 2)
96 check_cuda("float32", 64, 3)

Callers 6

test_cuda_vectorize_addFunction · 0.85
test_cuda_multiply_addFunction · 0.85
test_cuda_vectorize_loadFunction · 0.85
test_cuda_make_int8Function · 0.85

Calls 15

have_fp16Function · 0.90
have_int8Function · 0.90
printFunction · 0.85
np_bf162np_floatFunction · 0.85
np_float2np_bf16Function · 0.85
copyfromMethod · 0.80
uniformMethod · 0.80
numpyMethod · 0.80
sumFunction · 0.50
cudaMethod · 0.45
compileMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…