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

Function test_vm_module

tests/python/disco/test_session.py:226–266  ·  view source on GitHub ↗
(session_kind)

Source from the content-addressed store, hash-verified

224
225@pytest.mark.parametrize("session_kind", _all_session_kinds)
226def test_vm_module(session_kind):
227 num_workers = 4
228 sess = session_kind(num_workers=num_workers)
229
230 # pylint: disable=invalid-name
231 @I.ir_module(s_tir=True)
232 class TestMod:
233 @T.prim_func(s_tir=True)
234 def transpose(A: T.Buffer((8, 16), "float32"), B: T.Buffer((16, 8), "float32")):
235 for i, j in T.grid(16, 8):
236 with T.sblock("transpose"):
237 vi, vj = T.axis.remap("SS", [i, j])
238 B[vi, vj] = A[vj, vi]
239
240 @R.function
241 def main(A: R.Tensor((8, 16), dtype="float32")) -> R.Tensor((16, 8), dtype="float32"):
242 cls = TestMod
243 with R.dataflow():
244 B = R.call_tir(cls.transpose, (A,), out_sinfo=R.Tensor((16, 8), dtype="float32"))
245 R.output(B)
246 return B
247
248 # pylint: enable=invalid-name
249 with tempfile.TemporaryDirectory() as tmpdir:
250 path = tmpdir + "/test.so"
251 device = tvm.cpu()
252 x_np = np.arange(8 * 16).astype("float32").reshape([8, 16])
253 y_np = x_np.transpose()
254
255 tvm.compile(TestMod, target="llvm").export_library(path)
256 mod = sess.load_vm_module(path, device=device)
257
258 x_disc = _numpy_to_worker_0(sess, x_np, device=device)
259 y_disc = mod["main"](x_disc)
260 y_nd = _numpy_from_worker_0(sess, y_disc, shape=y_np.shape, dtype=y_np.dtype)
261 np.testing.assert_equal(y_nd, y_np)
262
263 # sync all workers to make sure the temporary files are cleaned up after all workers
264 # finish the execution
265 for i in range(num_workers):
266 sess._sync_worker(i)
267
268
269@pytest.mark.parametrize("session_kind", _all_session_kinds)

Callers

nothing calls this directly

Calls 11

_numpy_to_worker_0Function · 0.85
_numpy_from_worker_0Function · 0.85
load_vm_moduleMethod · 0.80
_sync_workerMethod · 0.80
cpuMethod · 0.45
reshapeMethod · 0.45
astypeMethod · 0.45
arangeMethod · 0.45
transposeMethod · 0.45
export_libraryMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…