(session_kind)
| 224 | |
| 225 | @pytest.mark.parametrize("session_kind", _all_session_kinds) |
| 226 | def 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…