MCPcopy Index your code
hub / github.com/apache/tvm / test_half_broadcast

Function test_half_broadcast

tests/python/codegen/test_target_codegen_cuda_fp8.py:226–254  ·  view source on GitHub ↗
(bcast_length)

Source from the content-addressed store, hash-verified

224@pytest.mark.gpu
225@pytest.mark.skipif(not env.has_cuda_compute(8), reason="need cuda compute >= 8.0")
226def test_half_broadcast(bcast_length):
227 dtype = "float16"
228
229 def _create_mod(bcast_length, dtype):
230 @I.ir_module(s_tir=True)
231 class Module:
232 @T.prim_func(s_tir=True)
233 def main(a: T.Buffer((), dtype), vec: T.Buffer((bcast_length,), dtype)):
234 for i_0 in T.thread_binding(1, thread="blockIdx.x"):
235 for i_1 in T.thread_binding(1, thread="threadIdx.x"):
236 with T.sblock("broadcast"):
237 vec[0:bcast_length] = T.broadcast(a[()], bcast_length)
238
239 return Module
240
241 mod = _create_mod(bcast_length, dtype)
242 target = "cuda"
243 func = tvm.compile(mod, target=target)
244 dev = tvm.device(target, 0)
245
246 a_np = np.random.uniform(low=0, high=4, size=()).astype(dtype)
247 a = tvm.runtime.tensor(a_np, device=dev)
248 b = tvm.runtime.empty((bcast_length,), dtype=dtype, device=dev)
249
250 func(a, b)
251
252 b_np = np.full((bcast_length,), a_np)
253
254 tvm.testing.assert_allclose(b.numpy(), b_np)
255
256
257vector_length = tvm.testing.parameter(2, 4)

Callers

nothing calls this directly

Calls 9

_create_modFunction · 0.85
uniformMethod · 0.80
numpyMethod · 0.80
funcFunction · 0.70
compileMethod · 0.45
deviceMethod · 0.45
astypeMethod · 0.45
emptyMethod · 0.45
fullMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…