(target)
| 47 | @pytest.mark.skipif(not env.has_llvm(), reason="need llvm") |
| 48 | @pytest.mark.parametrize("target", ["llvm", {"kind": "llvm", "jit": "mcjit"}]) |
| 49 | def test_dso_module_load(target): |
| 50 | dtype = "int64" |
| 51 | temp = utils.tempdir() |
| 52 | |
| 53 | def save_object(names): |
| 54 | n = te.size_var("n") |
| 55 | Ab = tvm.tirx.decl_buffer((n,), dtype) |
| 56 | i = te.var("i") |
| 57 | # for i in 0 to n-1: |
| 58 | stmt = tvm.tirx.For( |
| 59 | i, |
| 60 | 0, |
| 61 | n - 1, |
| 62 | tvm.tirx.ForKind.SERIAL, |
| 63 | tvm.tirx.BufferStore(Ab, tvm.tirx.BufferLoad(Ab, [i]) + 1, [i + 1]), |
| 64 | ) |
| 65 | mod = tvm.IRModule.from_expr( |
| 66 | tvm.tirx.PrimFunc([Ab], stmt).with_attr("global_symbol", "main") |
| 67 | ) |
| 68 | m = tvm.tirx.build(mod, target=target) |
| 69 | for name in names: |
| 70 | m.write_to_file(name) |
| 71 | |
| 72 | path_obj = temp.relpath("test.o") |
| 73 | path_ll = temp.relpath("test.ll") |
| 74 | path_bc = temp.relpath("test.bc") |
| 75 | path_dso = temp.relpath("test.so") |
| 76 | save_object([path_obj, path_ll, path_bc]) |
| 77 | cc.create_shared(path_dso, [path_obj]) |
| 78 | |
| 79 | f1 = tvm.runtime.load_module(path_dso) |
| 80 | f2 = tvm.runtime.load_module(path_ll) |
| 81 | a = tvm.runtime.tensor(np.zeros(10, dtype=dtype)) |
| 82 | f1(a) |
| 83 | np.testing.assert_equal(a.numpy(), np.arange(a.shape[0])) |
| 84 | a = tvm.runtime.tensor(np.zeros(10, dtype=dtype)) |
| 85 | f2(a) |
| 86 | np.testing.assert_equal(a.numpy(), np.arange(a.shape[0])) |
| 87 | |
| 88 | path_runtime_py = temp.relpath("runtime.py") |
| 89 | with open(path_runtime_py, "w") as fo: |
| 90 | fo.write(runtime_py) |
| 91 | |
| 92 | proc = subprocess.run( |
| 93 | [sys.executable, path_runtime_py, path_dso, dtype], |
| 94 | stdout=subprocess.PIPE, |
| 95 | stderr=subprocess.STDOUT, |
| 96 | ) |
| 97 | assert proc.returncode == 0, f"{proc.args} exited with {proc.returncode}: {proc.stdout}" |
| 98 | |
| 99 | |
| 100 | @pytest.mark.gpu |
nothing calls this directly
no test coverage detected
searching dependent graphs…