Skip to content

Commit 6465e9c

Browse files
committed
Fix some issues in comments
1 parent 7381aa4 commit 6465e9c

File tree

3 files changed

+12
-98
lines changed

3 files changed

+12
-98
lines changed
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
11
if(WIN32)
22
set(TORCH_PYTHON_IMPORTED_LOCATION "${PYTORCH_INSTALL_DIR}/lib/torch_python.lib")
3-
set(TORCH_PYTHON_LINK_LIBS
4-
"${PYTORCH_INSTALL_DIR}/lib/c10.lib"
5-
"${PYTORCH_INSTALL_DIR}/lib/torch_cpu.lib"
6-
)
7-
set(TORCH_PYTHON_LIBRARY_LINK
8-
"\$<TARGET_FILE:torch_python>;\$<TARGET_PROPERTY:torch_python,INTERFACE_LINK_LIBRARIES>"
9-
)
103
else()
114
set(TORCH_PYTHON_IMPORTED_LOCATION "${PYTORCH_INSTALL_DIR}/lib/libtorch_python.so")
12-
set(TORCH_PYTHON_LINK_LIBS "c10;torch_cpu")
13-
set(TORCH_PYTHON_LIBRARY_LINK
14-
"-Wl,--no-as-needed,\"\$<TARGET_FILE:torch_python>\" -Wl,--as-needed;"
15-
"\$<TARGET_PROPERTY:torch_python,INTERFACE_LINK_LIBRARIES>"
16-
)
175
endif()
186

197
add_library(torch_python SHARED IMPORTED)
208

219
set_target_properties(torch_python PROPERTIES
22-
INTERFACE_COMPILE_DEFINITIONS "USE_DISTRIBUTED;USE_C10D_GLOO;USE_C10D_MPI;USE_RPC;USE_TENSORPIPE"
2310
INTERFACE_INCLUDE_DIRECTORIES "${PYTORCH_INSTALL_DIR}/include"
24-
INTERFACE_LINK_LIBRARIES "${TORCH_PYTHON_LINK_LIBS}"
11+
INTERFACE_LINK_LIBRARIES "c10;torch_cpu"
2512
IMPORTED_LOCATION "${TORCH_PYTHON_IMPORTED_LOCATION}"
2613
)
2714

2815
add_library(torch_python_library INTERFACE IMPORTED)
2916

3017
set_target_properties(torch_python_library PROPERTIES
31-
INTERFACE_COMPILE_DEFINITIONS "\$<TARGET_PROPERTY:torch_python,INTERFACE_COMPILE_DEFINITIONS>"
32-
INTERFACE_COMPILE_OPTIONS "\$<TARGET_PROPERTY:torch_python,INTERFACE_COMPILE_OPTIONS>"
3318
INTERFACE_INCLUDE_DIRECTORIES "\$<TARGET_PROPERTY:torch_python,INTERFACE_INCLUDE_DIRECTORIES>"
34-
INTERFACE_LINK_LIBRARIES "${TORCH_PYTHON_LIBRARY_LINK}"
35-
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "\$<TARGET_PROPERTY:torch_python,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>"
19+
INTERFACE_LINK_LIBRARIES "\$<TARGET_FILE:torch_python>;\$<TARGET_PROPERTY:torch_python,INTERFACE_LINK_LIBRARIES>"
3620
)

test/cpp_extensions/open_registration_extension/torch_openreg/setup.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@
1818
RUN_BUILD_DEPS = any(arg in {"clean", "dist_info"} for arg in sys.argv)
1919

2020

21-
def check_env_flag(name, default=""):
22-
return os.getenv(name, default).upper() in ["ON", "1", "YES", "TRUE", "Y"]
23-
24-
25-
if "CMAKE_BUILD_TYPE" not in os.environ:
26-
if check_env_flag("DEBUG"):
27-
os.environ["CMAKE_BUILD_TYPE"] = "Debug"
28-
elif check_env_flag("REL_WITH_DEB_INFO"):
29-
os.environ["CMAKE_BUILD_TYPE"] = "RelWithDebInfo"
30-
else:
31-
os.environ["CMAKE_BUILD_TYPE"] = "Release"
32-
33-
3421
def make_relative_rpath_args(path):
3522
if IS_DARWIN:
3623
return ["-Wl,-rpath,@loader_path/" + path]
@@ -67,7 +54,7 @@ def build_deps():
6754
"--target",
6855
"install",
6956
"--config",
70-
os.environ["CMAKE_BUILD_TYPE"],
57+
"Release",
7158
"--",
7259
]
7360

@@ -100,13 +87,15 @@ def main():
10087
if IS_WINDOWS:
10188
# /NODEFAULTLIB makes sure we only link to DLL runtime
10289
# and matches the flags set for protobuf and ONNX
103-
extra_link_args: list[str] = ["/NODEFAULTLIB:LIBCMT.LIB"]
90+
extra_link_args: list[str] = ["/NODEFAULTLIB:LIBCMT.LIB"] + [
91+
*make_relative_rpath_args("lib")
92+
]
10493
# /MD links against DLL runtime
10594
# and matches the flags set for protobuf and ONNX
10695
# /EHsc is about standard C++ exception handling
10796
extra_compile_args: list[str] = ["/MD", "/FS", "/EHsc"]
10897
else:
109-
extra_link_args = []
98+
extra_link_args = [*make_relative_rpath_args("lib")]
11099
extra_compile_args = [
111100
"-Wall",
112101
"-Wextra",
@@ -120,21 +109,6 @@ def main():
120109
"-fno-strict-aliasing",
121110
]
122111

123-
if os.environ["CMAKE_BUILD_TYPE"] == "Debug":
124-
if IS_WINDOWS:
125-
extra_compile_args += ["/Z7"]
126-
extra_link_args += ["/DEBUG:FULL"]
127-
else:
128-
extra_compile_args += ["-O0", "-g"]
129-
extra_link_args += ["-O0", "-g"]
130-
elif os.environ["CMAKE_BUILD_TYPE"] == "RelWithDebInfo":
131-
if IS_WINDOWS:
132-
extra_compile_args += ["/Z7"]
133-
extra_link_args += ["/DEBUG:FULL"]
134-
else:
135-
extra_compile_args += ["-g"]
136-
extra_link_args += ["-g"]
137-
138112
ext_modules = [
139113
Extension(
140114
name="torch_openreg._C",
@@ -143,7 +117,7 @@ def main():
143117
extra_compile_args=extra_compile_args,
144118
libraries=["torch_bindings"],
145119
library_dirs=[os.path.join(BASE_DIR, "torch_openreg/lib")],
146-
extra_link_args=[*make_relative_rpath_args("lib")],
120+
extra_link_args=extra_link_args,
147121
)
148122
]
149123

test/cpp_extensions/open_registration_extension/torch_openreg/torch_openreg/_utils.py

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
import ctypes
22
import glob
33
import os
4-
import platform
5-
import sys
6-
import sysconfig
7-
import textwrap
84

95

106
def _load_dll_libraries() -> None:
11-
py_dll_path = os.path.join(sys.exec_prefix, "Library", "bin")
12-
th_dll_path = os.path.join(os.path.dirname(__file__), "lib")
13-
usebase_path = os.path.join(sysconfig.get_config_var("userbase"), "Library", "bin")
14-
py_root_bin_path = os.path.join(sys.exec_prefix, "bin")
15-
16-
# When users create a virtualenv that inherits the base environment,
17-
# we will need to add the corresponding library directory into
18-
# DLL search directories. Otherwise, it will rely on `PATH` which
19-
# is dependent on user settings.
20-
if sys.exec_prefix != sys.base_exec_prefix:
21-
base_py_dll_path = os.path.join(sys.base_exec_prefix, "Library", "bin")
22-
else:
23-
base_py_dll_path = ""
24-
25-
dll_paths = [
26-
p
27-
for p in (
28-
th_dll_path,
29-
py_dll_path,
30-
base_py_dll_path,
31-
usebase_path,
32-
py_root_bin_path,
33-
)
34-
if os.path.exists(p)
35-
]
7+
openreg_dll_path = os.path.join(os.path.dirname(__file__), "lib")
368

379
kernel32 = ctypes.WinDLL("kernel32.dll", use_last_error=True)
3810
with_load_library_flags = hasattr(kernel32, "AddDllDirectory")
@@ -42,25 +14,9 @@ def _load_dll_libraries() -> None:
4214
if with_load_library_flags:
4315
kernel32.LoadLibraryExW.restype = ctypes.c_void_p
4416

45-
for dll_path in dll_paths:
46-
os.add_dll_directory(dll_path)
47-
48-
try:
49-
ctypes.CDLL("vcruntime140.dll")
50-
ctypes.CDLL("msvcp140.dll")
51-
if platform.machine() != "ARM64":
52-
ctypes.CDLL("vcruntime140_1.dll")
53-
except OSError:
54-
print(
55-
textwrap.dedent(
56-
"""
57-
Microsoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure.
58-
It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exe
59-
"""
60-
).strip()
61-
)
17+
os.add_dll_directory(openreg_dll_path)
6218

63-
dlls = glob.glob(os.path.join(th_dll_path, "*.dll"))
19+
dlls = glob.glob(os.path.join(openreg_dll_path, "*.dll"))
6420
path_patched = False
6521
for dll in dlls:
6622
is_loaded = False
@@ -75,7 +31,7 @@ def _load_dll_libraries() -> None:
7531
is_loaded = True
7632
if not is_loaded:
7733
if not path_patched:
78-
os.environ["PATH"] = ";".join(dll_paths + [os.environ["PATH"]])
34+
os.environ["PATH"] = ";".join([openreg_dll_path] + [os.environ["PATH"]])
7935
path_patched = True
8036
res = kernel32.LoadLibraryW(dll)
8137
if res is None:

0 commit comments

Comments
 (0)