Skip to content

Commit 7b5b696

Browse files
committed
Add linker args for more torch libs
.
1 parent 4ff027d commit 7b5b696

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

Diff for: CMakeLists.txt

+41-16
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,44 @@ target_include_directories(
4848
set(BRIDGE_OBJECT_FILES $<TARGET_OBJECTS:bridge>)
4949

5050

51-
file(GLOB PYTORCH_LIBS "${LIBTORCH_DIR}/lib/*.a" "${LIBTORCH_DIR}/lib/*.dylib" "${LIBTORCH_DIR}/lib/*.so")
52-
53-
set(PYTORCH_LIBS_LINKER_ARGS "-ltorch") # Will hold the list of "-l..." flags.
54-
foreach(lib_path IN LISTS PYTORCH_LIBS)
55-
# Get just the filename without the directory or extension
56-
get_filename_component(lib_name "${lib_path}" NAME_WE)
57-
# If it starts with "lib", strip that off
58-
string(REGEX REPLACE "^lib" "" lib_name "${lib_name}")
59-
# Now prepend "-l" to the actual library name
60-
list(APPEND PYTORCH_LIBS_LINKER_ARGS "-l${lib_name}")
51+
52+
53+
file(GLOB LIBTORCH_ALL_LIB_FILES "${LIBTORCH_DIR}/lib/*.a" "${LIBTORCH_DIR}/lib/*.dylib" "${LIBTORCH_DIR}/lib/*.so")
54+
55+
set(LIBTORCH_ALL_LIBS "")
56+
foreach(lib_path IN LISTS LIBTORCH_ALL_LIB_FILES)
57+
get_filename_component(lib_name "${lib_path}" NAME_WE)
58+
list(APPEND LIBTORCH_ALL_LIBS "${lib_name}")
59+
endforeach()
60+
61+
62+
set(REQUIRED_LIBS
63+
"libtorch"
64+
"libtorch_cpu"
65+
"libc10"
66+
"libtorch_global_deps"
67+
)
68+
69+
set(DISALLOWED_LIBS
70+
"libtorch_python"
71+
)
72+
73+
74+
set(LIBTORCH_LIBS_LINKER_ARGS "") # Will hold the list of "-l..." flags.
75+
foreach(lib_name IN LISTS LIBTORCH_ALL_LIBS)
76+
if(lib_name IN_LIST DISALLOWED_LIBS)
77+
if(lib_name IN_LIST REQUIRED_LIBS)
78+
message(FATAL_ERROR "Required lib ${lib_name} is disallowed.")
79+
else()
80+
message(STATUS "Skipping disallowed lib: ${lib_name}")
81+
continue()
82+
endif()
83+
endif()
84+
string(REGEX REPLACE "^lib" "" lib_name_short "${lib_name}")
85+
list(APPEND LIBTORCH_LIBS_LINKER_ARGS "-l${lib_name_short}")
6186
endforeach()
6287

63-
# cmake_print_variables(PYTORCH_LIBS)
64-
# cmake_print_variables(PYTORCH_LIBS_LINKER_ARGS)
88+
cmake_print_variables(LIBTORCH_LIBS_LINKER_ARGS)
6589

6690
add_executable(TorchBridge ${BRIDGE_DIR}/lib/Bridge.chpl)
6791
add_dependencies(TorchBridge bridge)
@@ -70,10 +94,11 @@ target_link_options(TorchBridge
7094
${BRIDGE_DIR}/include/bridge.h
7195
${BRIDGE_OBJECT_FILES}
7296
-L ${LIBTORCH_DIR}/lib
73-
"-ltorch"
74-
"-ltorch_cpu"
75-
"-lc10"
76-
# ${PYTORCH_LIBS_LINKER_ARGS}
97+
# "-ltorch"
98+
# "-ltorch_cpu"
99+
# "-lc10"
100+
# "-ltorch_global_deps"
101+
${LIBTORCH_LIBS_LINKER_ARGS}
77102
--ldflags "-Wl,-rpath,${LIBTORCH_DIR}/lib"
78103
)
79104
# install(TARGETS TorchBridge DESTINATION ".")

Diff for: bridge/lib/Bridge.chpl

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern record bridge_tensor_t {
1515
}
1616

1717

18+
1819
extern proc increment2(arr: [] real(32), sizes: [] int(32), dim: int(32)): bridge_tensor_t;
1920
extern proc increment3(in arr: bridge_tensor_t): bridge_tensor_t;
2021

Diff for: cmake/LibTorchDL.cmake

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ include(dlcache)
66

77
include(CMakePrintHelpers)
88

9+
10+
# set(TORCH_COMPUTE_PLATFORM "cpu") # cu118, cu124, cu126, cpu
11+
# set(TORCH_VERSION "2.1.0")
912
set(TORCH_URL_PREFIX "https://download.pytorch.org/libtorch/nightly/cpu")
1013

1114

@@ -20,7 +23,7 @@ endif()
2023
if(APPLE)
2124
set(TORCH_DISTRIBUTION "${TORCH_URL_PREFIX}/libtorch-macos-arm64-latest.zip")
2225
elseif(LINUX)
23-
set(TORCH_DISTRIBUTION "$${TORCH_URL_PREFIX}/libtorch-cxx11-abi-static-with-deps-latest.zip")
26+
set(TORCH_DISTRIBUTION "$${TORCH_URL_PREFIX}/libtorch-shared-with-deps-latest.zip")
2427
endif()
2528

2629
function(download_libtorch)

0 commit comments

Comments
 (0)