3636@pytest .mark .skipif (torch is None , reason = "torch is not installed" )
3737def test_build_torch_c_dlpack_extension () -> None :
3838 build_script = Path (tvm_ffi .__file__ ).parent / "utils" / "_build_optional_torch_c_dlpack.py"
39- subprocess .run (
40- [sys .executable , str (build_script ), "--build_dir" , "./build_test_dir" ], check = True
41- )
39+ args = [
40+ sys .executable ,
41+ str (build_script ),
42+ "--output-dir" ,
43+ "./output-dir" ,
44+ "--libname" ,
45+ "libtorch_c_dlpack_addon_test.so" ,
46+ ]
47+ if torch .cuda .is_available ():
48+ args .append ("--build-with-cuda" )
49+ subprocess .run (args , check = True )
4250
43- lib_path = str (
44- Path (
45- "./build_test_dir/libtorch_c_dlpack_addon.{}" .format ("dll" if IS_WINDOWS else "so" )
46- ).resolve ()
47- )
51+ lib_path = str (Path ("./output-dir/libtorch_c_dlpack_addon_test.so" ).resolve ())
4852 assert Path (lib_path ).exists ()
4953
5054 lib = ctypes .CDLL (lib_path )
@@ -58,20 +62,19 @@ def test_build_torch_c_dlpack_extension() -> None:
5862def test_parallel_build () -> None :
5963 build_script = Path (tvm_ffi .__file__ ).parent / "utils" / "_build_optional_torch_c_dlpack.py"
6064 num_processes = 4
61- build_dir = "./build_test_dir_parallel"
65+ output_dir = "./output-dir-parallel"
66+ libname = "libtorch_c_dlpack_addon_test.so"
6267 processes = []
6368 for i in range (num_processes ):
64- p = subprocess .Popen ([sys .executable , str (build_script ), "--build_dir" , build_dir ])
65- processes .append ((p , build_dir ))
69+ p = subprocess .Popen (
70+ [sys .executable , str (build_script ), "--output-dir" , output_dir , "--libname" , libname ]
71+ )
72+ processes .append ((p , output_dir ))
6673
67- for p , build_dir in processes :
74+ for p , output_dir in processes :
6875 p .wait ()
6976 assert p .returncode == 0
70- lib_path = str (
71- Path (
72- "{}/libtorch_c_dlpack_addon.{}" .format (build_dir , "dll" if IS_WINDOWS else "so" )
73- ).resolve ()
74- )
77+ lib_path = str (Path (f"{ output_dir } /{ libname } " ).resolve ())
7578 assert Path (lib_path ).exists ()
7679
7780
0 commit comments