Skip to content

Commit b9595a9

Browse files
committed
Use dllist on linux to check cross compile feature
1 parent 9b73a8e commit b9595a9

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

py/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pybind11==2.6.2
55
torch>=2.8.0.dev,<2.9.0
66
torchvision>=0.22.0.dev,<0.23.0
77
--extra-index-url https://pypi.ngc.nvidia.com
8-
pyyaml
8+
pyyaml
9+
dllist

py/torch_tensorrt/_utils.py

+7-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Any
55

66
import torch
7-
from torch_tensorrt import _find_lib
87

98

109
def sanitized_torch_version() -> Any:
@@ -16,24 +15,13 @@ def sanitized_torch_version() -> Any:
1615

1716

1817
def check_cross_compile_trt_win_lib():
19-
if sys.platform.startswith("linux"):
20-
LINUX_PATHS = ["/usr/local/cuda-12.8/lib64", "/usr/lib", "/usr/lib64"]
21-
22-
if platform.uname().processor == "x86_64":
23-
LINUX_PATHS += [
24-
"/usr/lib/x86_64-linux-gnu",
25-
]
26-
elif platform.uname().processor == "aarch64":
27-
LINUX_PATHS += ["/usr/lib/aarch64-linux-gnu"]
18+
# cross compile feature is only available on linux
19+
# build engine on linux and run on windows
20+
import dllist
2821

29-
LINUX_LIBS = [
30-
f"libnvinfer_builder_resource_win.so.*",
31-
]
32-
33-
for lib in LINUX_LIBS:
34-
try:
35-
ctypes.CDLL(_find_lib(lib, LINUX_PATHS))
22+
if sys.platform.startswith("linux"):
23+
loaded_libs = dllist.dllist()
24+
target_lib = "libnvinfer_builder_resource_win.so.*"
25+
if target_lib in loaded_libs:
3626
return True
37-
except:
38-
continue
3927
return False

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ requires = [
1313
"pybind11==2.6.2",
1414
"numpy",
1515
"sympy",
16+
"dllist",
1617
]
1718
build-backend = "setuptools.build_meta"
1819

@@ -63,6 +64,7 @@ dependencies = [
6364
"packaging>=23",
6465
"numpy",
6566
"typing-extensions>=4.7.0",
67+
"dllist",
6668
]
6769

6870
dynamic = ["version"]

tests/py/dynamo/runtime/test_003_cross_compile_for_windows.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ def forward(self, a, b):
4646
"Cross compile for windows can only be enabled on linux x86-64 platform",
4747
)
4848
@unittest.skipIf(
49-
not (
50-
check_cross_compile_trt_win_lib(),
51-
"TRT windows lib for cross compile not found",
52-
),
49+
not (check_cross_compile_trt_win_lib()),
50+
"TRT windows lib for cross compile not found",
5351
)
5452
@pytest.mark.unit
5553
def test_dynamo_cross_compile_for_windows(self):
@@ -79,6 +77,10 @@ def forward(self, a, b):
7977
platform.system() != "Linux" or platform.architecture()[0] != "64bit",
8078
"Cross compile for windows can only be enabled on linux x86-64 platform",
8179
)
80+
@unittest.skipIf(
81+
not (check_cross_compile_trt_win_lib()),
82+
"TRT windows lib for cross compile not found",
83+
)
8284
@pytest.mark.unit
8385
def test_dynamo_cross_compile_for_windows_multiple_output(self):
8486
class Add(torch.nn.Module):

0 commit comments

Comments
 (0)