Hi there,
I have a PyTorch model that I’ve trained in a python project that I’d like to load into a C++ project. From what I understand, my best option is to trace my model using TorchScript and then use the C++ library to load the model. I’m having trouble including TorchScript in my Visual Studio 2017 project, though.
After adding the path for the “\Python310\Lib\site-packages\torch\include” folder and “\torch\lib” to the project properties, the project won’t compile. I get a million notes and warnings, and one single error:
...\python310\lib\site-packages\torch\include\c10\util\safe_numerics.h(26): error C3861: '_addcarry_u64': identifier not found
That file contains this:
#if defined(_M_IX86) || defined(_M_X64)
auto carry = _addcarry_u64(0, a, b, &tmp);
#else
tmp = a + b;
unsigned long long vector = (a & b) ^ ((a ^ b) & ~tmp);
auto carry = vector >> 63;
#endif
*out = tmp;
return carry;
After some googling, it seems the recommended work around is to simply comment out the part of the file that references _addcarry_u64
so that it always falls down into the #else
section. If I do that and try building again, I now get 96 unresolved externals. I don’t want to list them all but here’s the first few:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall c10::ValueError::ValueError(struct c10::SourceLocation,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (__imp_??0ValueError@c10@@QAE@USourceLocation@1@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: static void __cdecl c10::ivalue::Future::ensureIsSubsetOfDevices(class std::vector<struct c10::Device,class std::allocator<struct c10::Device> > const &,class std::vector<struct c10::Device,class std::allocator<struct c10::Device> > const &)" (?ensureIsSubsetOfDevices@Future@ivalue@c10@@CAXABV?$vector@UDevice@c10@@V?$allocator@UDevice@c10@@@std@@@std@@0@Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) char const * __cdecl c10::detail::torchCheckMsgImpl(char const *)" (__imp_?torchCheckMsgImpl@detail@c10@@YAPBDPBD@Z) referenced in function "public: void __thiscall c10::ivalue::Object::unsafeRemoveSlot(unsigned int)" (?unsafeRemoveSlot@Object@ivalue@c10@@QAEXI@Z)
error LNK2019: unresolved external symbol "__declspec(dllimport) char const * __cdecl c10::detail::torchCheckMsgImpl(char const *,char const *)" (__imp_?torchCheckMsgImpl@detail@c10@@YAPBDPBD0@Z) referenced in function __catch$?markCompleted@Future@ivalue@c10@@QAEXUIValue@3@V?$optional@V?$vector@V?$weak_intrusive_ptr@UStorageImpl@c10@@U?$intrusive_target_default_null_type@UStorageImpl@c10@@@detail@2@@c10@@V?$allocator@V?$weak_intrusive_ptr@UStorageImpl@c10@@U?$intrusive_target_default_null_type@UStorageImpl@c10@@@detail@2@@c10@@@std@@@std@@@3@@Z$0
Would anyone have any clues as to why this is happening and what I can do? I’m on windows 10 using VS 2017 and the project I’m working from needs to build in 32 bit, would I need to download/build a 32 bit version of PyTorch? I see nothing suggesting that if I try looking that up.
Thanks in advance for any help.