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

Function test_multi_systemlib

tests/python/relax/test_vm_build.py:992–1060  ·  view source on GitHub ↗
(exec_mode)

Source from the content-addressed store, hash-verified

990
991
992def test_multi_systemlib(exec_mode):
993 pytest.importorskip("cloudpickle") # needed by popen_pool.PopenWorker
994
995 @tvm.script.ir_module
996 class ModA:
997 I.module_attrs({"system_lib_prefix": "libA_"})
998
999 @T.prim_func(s_tir=True)
1000 def tir_init(x_handle: T.handle):
1001 N = T.int64()
1002 x = T.match_buffer(x_handle, [N], "float32")
1003 for i in range(N):
1004 x[i] = T.float32(0)
1005
1006 @R.function
1007 def main(s: R.Shape(["m"])) -> R.Tensor:
1008 m = T.int64()
1009 gv0 = R.call_tir(ModA.tir_init, (), R.Tensor((m + 1,), dtype="float32"))
1010 return gv0
1011
1012 @tvm.script.ir_module
1013 class ModB:
1014 I.module_attrs({"system_lib_prefix": "libB_"})
1015
1016 @T.prim_func(s_tir=True)
1017 def tir_init(x_handle: T.handle):
1018 N = T.int64()
1019 x = T.match_buffer(x_handle, [N], "float32")
1020 for i in range(N):
1021 x[i] = T.float32(1)
1022
1023 @R.function
1024 def main(s: R.Shape(["m"])) -> R.Tensor:
1025 m = T.int64()
1026 gv0 = R.call_tir(ModB.tir_init, (), R.Tensor((m,), dtype="float32"))
1027 return gv0
1028
1029 target = tvm.target.Target("llvm", host="llvm")
1030 libA = relax.build(ModA, target, exec_mode=exec_mode)
1031 libB = relax.build(ModB, target, exec_mode=exec_mode)
1032
1033 temp = utils.tempdir()
1034 pathA = temp.relpath("libA.a")
1035 pathB = temp.relpath("libB.a")
1036 path_dso = temp.relpath("mylibAll.so")
1037 libA.export_library(pathA, fcompile=cc.create_staticlib)
1038 libB.export_library(pathB, fcompile=cc.create_staticlib)
1039
1040 # package two static libs together
1041 # check that they do not interfere with each other
1042 # even though they have shared global var names
1043 # intentionally craft same gvar function with different behaviors
1044 cc.create_shared(path_dso, ["-Wl,--whole-archive", pathA, pathB, "-Wl,--no-whole-archive"])
1045
1046 def popen_check():
1047 # Load dll, will trigger system library registration
1048 ctypes.CDLL(path_dso)
1049 # Load the system wide library

Callers

nothing calls this directly

Calls 4

sendMethod · 0.95
relpathMethod · 0.80
buildMethod · 0.45
export_libraryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…