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

Function test_device_module_dump

tests/python/runtime/test_runtime_module_load.py:102–156  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100@pytest.mark.gpu
101@pytest.mark.skipif(not env.has_gpu(), reason="need gpu")
102def test_device_module_dump():
103 pytest.importorskip("cloudpickle") # needed by popen_pool.PopenWorker
104
105 # graph
106 n = tvm.runtime.convert(1024)
107 A = te.placeholder((n,), name="A")
108 B = te.compute(A.shape, lambda *i: A(*i) + 1.0, name="B")
109
110 sch = tvm.s_tir.Schedule(te.create_prim_func([A, B]))
111 # create iter var and assign them tags.
112 num_thread = 8
113 bx, tx = sch.split(sch.get_loops("B")[0], factors=[None, num_thread])
114 sch.bind(bx, "blockIdx.x")
115 sch.bind(tx, "threadIdx.x")
116
117 def check_device(device):
118 dev = tvm.device(device, 0)
119 if not tvm.testing.device_enabled(device):
120 print(f"Skip because {device} is not enabled")
121 return
122 temp = utils.tempdir()
123 f = tvm.compile(sch.mod, target=device)
124
125 path_dso = temp.relpath("dev_lib.so")
126 # test cross compiler function
127 f.export_library(path_dso, fcompile=cc.cross_compiler("g++"))
128
129 def popen_check():
130 import tvm
131
132 f1 = tvm.runtime.load_module(path_dso)
133 a = tvm.runtime.tensor(np.random.uniform(size=1024).astype(A.dtype), dev)
134 b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
135 f1(a, b)
136 np.testing.assert_equal(b.numpy(), a.numpy() + 1)
137
138 # system lib should be loaded in different process
139 worker = popen_pool.PopenWorker()
140 worker.send(popen_check)
141 worker.recv()
142
143 def check_c(device):
144 dev = tvm.device(device, 0)
145 if not tvm.testing.device_enabled(device):
146 print(f"Skip because {device} is not enabled")
147 return
148 f = tvm.compile(sch.mod, target=tvm.target.Target(device, host="c"))
149 a = tvm.runtime.tensor(np.random.uniform(size=1024).astype(A.dtype), dev)
150 b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
151 f["main"](a, b)
152 np.testing.assert_equal(b.numpy(), a.numpy() + 1)
153
154 for device in ["cuda", "vulkan", "opencl", "metal"]:
155 check_device(device)
156 check_c(device)
157
158
159@pytest.mark.skipif(not env.has_llvm(), reason="need llvm")

Callers

nothing calls this directly

Calls 7

splitMethod · 0.95
get_loopsMethod · 0.95
bindMethod · 0.95
check_deviceFunction · 0.85
placeholderMethod · 0.80
check_cFunction · 0.70
convertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…