Migrating to SYCL
One-stop forum for getting assistance migrating your existing code to SYCL
39 Discussions

Linking Sycl with Libtorch DevCloud

YuanM
Novice
517 Views

Hi! I am working on a project which relies heavily on the Libtorch. However, I was not able to build a simple SYCL+libtorch project on DevCloud due to a strange linker error. I am using the vector-add example provided by vector-add-buffers.cpp to show a step-by-step minimal reproducible example of the error:

 

  1. I installed libtorch using the following command in the home directory:
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip

unzip libtorch-shared-with-deps-latest.zip
  1. I used the following command (without cmake/make) to compile and link the project:
mkdir build

cd build

[compile] icpx -fsycl -I/home/u186670/libtorch/include -I/home/u186670/libtorch/include/torch/csrc/api/include -D_GLIBCXX_USE_CXX11_ABI=0 -std=gnu++17 -L/home/u186670/libtorch/lib -Wl,-R/home/u186670/libtorch/lib -ltorch -ltorch_cpu -lc10 -o vector-add-buffers.cpp.o -c ../src/vector-add-buffers.cpp

[link] icpx -fsycl -I/home/u186670/libtorch/include -I/home/u186670/libtorch/include/torch/csrc/api/include -D_GLIBCXX_USE_CXX11_ABI=0 -std=gnu++17 -L/home/u186670/libtorch/lib -Wl,-R/home/u186670/libtorch/lib -ltorch -ltorch_cpu -lc10 vector-add-buffers.cpp.o -o vector-add-buffers

Note: the only libtorch code added to the vector-add-buffers.cpp are simply:

#include <torch/torch.h>

// dpc++ code for vector add ...

torch::Tensor tensor = torch::rand({2, 3});

std::cout << tensor << std::endl;

return 0; //retun for main()

} //ending main()

Result & error:

The compilation was successful. The link gives the following error (seems to be a problem with sycl exception handler):

/home/u186670/tmp/icpx-515249/vector-add-buffers-7e91ab.o: In function `std::_Function_handler<void (sycl::_V1::handler&), VectorAdd(sycl::_V1::queue&, std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)::{lambda(sycl::_V1::handler&)#1}>::_M_invoke(std::_Any_data const&, sycl::_V1::handler&)':

vector-add-buffers-32895f.cpp:(.text+0x28d1): undefined reference to `sycl::_V1::handler::verifyUsedKernelBundle(std::string const&)'

/home/u186670/tmp/icpx-515249/vector-add-buffers-7e91ab.o: In function `sycl::_V1::exception::exception(std::error_code, std::string const&, int, std::shared_ptr<sycl::_V1::context>)':

vector-add-buffers-32895f.cpp:(.text._ZN4sycl3_V19exceptionC2ESt10error_codeRKSsiSt10shared_ptrINS0_7contextEE[_ZN4sycl3_V19exceptionC2ESt10error_codeRKSsiSt10shared_ptrINS0_7contextEE]+0x23d): undefined reference to `sycl::_V1::exception::exception(std::error_code, std::shared_ptr<sycl::_V1::context>, std::string const&)'

icpx: error: linker command failed with exit code 1 (use -v to see invocation)

Could anyone please give some pointers on what could possibly cause such linker error, and/or whether linking DPC++ code with libtorch is possible in general (if so, any minimal working examples)?

 

 

0 Kudos
1 Reply
NoorjahanSk_Intel
Moderator
478 Views

Hi,


Thanks for posting in Intel Communities.


Since this is a duplicate thread of https://community.intel.com/t5/Intel-oneAPI-Data-Parallel-C/Error-in-Linking-Sycl-with-Libtorch-for-project-on-heterogeneous/m-p/1464043#M2888, we will no longer monitor this thread. We will continue addressing this issue in the other thread.


Thanks & Regards,

Noorjahan.


0 Kudos
Reply