Skip to content

Commit

Permalink
[bugfix] Only link the pytorch tensordispatcher against libtorch (dml…
Browse files Browse the repository at this point in the history
…c#3225)

* Only link tensordispatcher against pytorch

* Only modify libraries when not using MSVC
  • Loading branch information
nv-dlasalle authored Aug 8, 2021
1 parent bcf92f6 commit 799c091
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/runtime/tensordispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ bool TensorDispatcher::Load(const char *path) {
#else // !WIN32
handle_ = dlopen(path, RTLD_LAZY);

if (!handle_)
if (!handle_) {
LOG(WARNING) << "TensorDispatcher: dlopen failed: " << dlerror();
return false;
}

for (int i = 0; i < num_entries_; ++i) {
entrypoints_[i] = dlsym(handle_, names_[i]);
Expand Down
11 changes: 9 additions & 2 deletions tensoradapter/pytorch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,22 @@ set(TORCH_TARGET_NAME "tensoradapter_pytorch_${TORCH_VER}")
file(GLOB TA_TORCH_SRC *.cpp)
add_library(${TORCH_TARGET_NAME} SHARED "${TA_TORCH_SRC}")

if (MSVC)
# Linking on windows requires all libraries
set(TENSORADAPTER_TORCH_LIBS ${TORCH_LIBRARIES})
else()
set(TENSORADAPTER_TORCH_LIBS ${TORCH_LIBRARY})
endif(MSVC)

message(STATUS "tensoradapter found PyTorch includes: ${TORCH_INCLUDE_DIRS}")
message(STATUS "tensoradapter found PyTorch lib: ${TORCH_LIBRARIES}")
message(STATUS "tensoradapter found PyTorch lib: ${TENSORADAPTER_TORCH_LIBS}")

target_include_directories(
${TORCH_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include")
target_include_directories(
${TORCH_TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/dlpack/include")
target_include_directories(
${TORCH_TARGET_NAME} PRIVATE "${TORCH_INCLUDE_DIRS}")
target_link_libraries(${TORCH_TARGET_NAME} PRIVATE "${TORCH_LIBRARIES}")
target_link_libraries(${TORCH_TARGET_NAME} PRIVATE "${TENSORADAPTER_TORCH_LIBS}")
set_property(TARGET ${TORCH_TARGET_NAME} PROPERTY CXX_STANDARD 14)
message(STATUS "Configured target ${TORCH_TARGET_NAME}")

0 comments on commit 799c091

Please sign in to comment.