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

Function test_dso_module_load

tests/python/runtime/test_runtime_module_load.py:49–97  ·  view source on GitHub ↗
(target)

Source from the content-addressed store, hash-verified

47@pytest.mark.skipif(not env.has_llvm(), reason="need llvm")
48@pytest.mark.parametrize("target", ["llvm", {"kind": "llvm", "jit": "mcjit"}])
49def 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

Callers

nothing calls this directly

Calls 8

save_objectFunction · 0.85
relpathMethod · 0.80
numpyMethod · 0.80
writeMethod · 0.65
load_moduleMethod · 0.45
zerosMethod · 0.45
arangeMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…