()
| 192 | np.testing.assert_equal(b.numpy(), a.numpy() + 1) |
| 193 | |
| 194 | def check_system_lib(): |
| 195 | dev = tvm.cpu(0) |
| 196 | if not tvm.testing.device_enabled("llvm"): |
| 197 | print("Skip because llvm is not enabled") |
| 198 | return |
| 199 | temp = utils.tempdir() |
| 200 | print("Running popen check") |
| 201 | fadd1 = tvm.tirx.build(mod1.with_attr("system_lib_prefix", ""), "llvm") |
| 202 | fadd2 = tvm.tirx.build(mod2.with_attr("system_lib_prefix", ""), "llvm") |
| 203 | path1 = temp.relpath("myadd1.o") |
| 204 | path2 = temp.relpath("myadd2.o") |
| 205 | path_dso = temp.relpath("mylib.so") |
| 206 | fadd1.write_to_file(path1) |
| 207 | fadd2.write_to_file(path2) |
| 208 | cc.create_shared(path_dso, [path1, path2]) |
| 209 | |
| 210 | def popen_check(): |
| 211 | import ctypes |
| 212 | |
| 213 | import tvm.runtime |
| 214 | |
| 215 | # Load dll, will trigger system library registration |
| 216 | ctypes.CDLL(path_dso) |
| 217 | # Load the system wide library |
| 218 | mm = tvm.runtime.system_lib() |
| 219 | a = tvm.runtime.tensor(np.random.uniform(size=nn).astype(A.dtype), dev) |
| 220 | b = tvm.runtime.tensor(np.zeros(nn, dtype=A.dtype), dev) |
| 221 | mm["myadd1"](a, b) |
| 222 | np.testing.assert_equal(b.numpy(), a.numpy() + 1) |
| 223 | mm["myadd2"](a, b) |
| 224 | np.testing.assert_equal(b.numpy(), a.numpy() + 1) |
| 225 | |
| 226 | # system lib should be loaded in different process |
| 227 | worker = popen_pool.PopenWorker() |
| 228 | worker.send(popen_check) |
| 229 | worker.recv() |
| 230 | |
| 231 | if sys.platform != "win32": |
| 232 | check_system_lib() |
no test coverage detected
searching dependent graphs…