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

Function run_test

tests/python/codegen/test_target_codegen_vulkan.py:527–562  ·  view source on GitHub ↗
(tvm_intrin, np_func)

Source from the content-addressed store, hash-verified

525 ]
526
527 def run_test(tvm_intrin, np_func):
528 n = 16
529
530 @I.ir_module(s_tir=True)
531 class Module:
532 @T.prim_func(s_tir=True)
533 def main(var_A: T.handle, var_B: T.handle):
534 m = T.int32(is_size_var=True)
535 A = T.match_buffer(var_A, (m,), "float32")
536 B = T.match_buffer(var_B, (m,), "float32")
537 for i_0 in T.thread_binding((m + 63) // 64, thread="blockIdx.x"):
538 for i_1 in T.thread_binding(64, thread="threadIdx.x"):
539 with T.sblock("B"):
540 v_i = T.axis.spatial(m, i_0 * 64 + i_1)
541 T.where(i_0 * 64 + i_1 < m)
542 T.reads(A[v_i])
543 T.writes(B[v_i])
544 B[v_i] = tvm_intrin(A[v_i])
545
546 target = tvm.target.Target("vulkan")
547 dev = tvm.device(target.kind.name, 0)
548 func = tvm.compile(Module, target=target)
549
550 if tvm_intrin in [tvm.tirx.asin, tvm.tirx.acos]:
551 data = np.random.uniform(-1.0, 1.0, size=n)
552 elif tvm_intrin == tvm.tirx.atanh:
553 data = np.random.uniform(-0.999, 0.999, size=n)
554 elif tvm_intrin == tvm.tirx.acosh:
555 data = np.random.uniform(1.0, 5.0, size=n)
556 else:
557 data = np.random.uniform(0.1, 0.9, size=n)
558
559 a = tvm.runtime.tensor(data.astype("float32"), dev)
560 b = tvm.runtime.tensor(np.zeros(n, dtype="float32"), dev)
561 func(a, b)
562 tvm.testing.assert_allclose(b.numpy(), np_func(a.numpy()), atol=1e-3, rtol=1e-3)
563
564 for func in test_funcs:
565 run_test(*func)

Callers 1

test_unaryFunction · 0.70

Calls 8

np_funcFunction · 0.85
uniformMethod · 0.80
numpyMethod · 0.80
funcFunction · 0.70
deviceMethod · 0.45
compileMethod · 0.45
astypeMethod · 0.45
zerosMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…