I’m following the https://pytorch.org/tutorials/advanced/torch_script_custom_classes.html in order to expose my C++ dll in Python.
The bulk of the code that I have at the moment is this :
#include <string>
#include <vector>
#include <torch/script.h>
include <FV/FV.h>
struct PyManager : torch::CustomClassHolder {
PyManager(std::string model, std::string root, std::string cache, bool rebuildCache)
{
auto config = FV::Load_Default_Settings();
config.mutable_configuration()->mutable_x()->mutable_settings()->set_x_rebuild_cache(rebuildCache);
config.mutable_configuration()->mutable_x()->mutable_settings()->set_x_cache_folder(cache_folder);
//... some other settings being set using protobuf config here
fv = std::make_shared<FV>(config);
}
int AddUser(std::string user_id, std::string path)
{
fv->AddNewUser(user_id, path);
}
int RemoveUser(std::string user_id)
{
fv->RemoveUser(user_id);
}
int UpdateUser(std::string usier_id, std::string new_path)
{
fv->UpdateUser(usier_id, new_path);
}
int UpdateUsersInBulk(std::vector<std::string> userIDs, std::string path, bool is_delete_granted = true, bool show_dbg_info = true)
{
fv->UpdateUsersInBulk(userIDs, path, is_delete_granted, show_dbg_info);
}
int RenameId(std::string old_id, std::string new_id)
{
fv->RenameUserID(old_id, new_id);
}
private:
std::shared_ptr<FV> fv;
};
TORCH_LIBRARY(my_classes, m) {
m.class_<PyManager>("PyManager")
.def(torch::init<std::string, std::string, std::string, bool>())
.def("add", &PyManager::AddUser)
.def("remove", &PyManager::RemoveUser)
.def("update", &PyManager::UpdateUser)
.def("update_in_bulk", &PyManager::UpdateUsersInBulk);
}
And this is the cmake file that I use :
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(custom_class)
find_package(Torch REQUIRED)
find_package(Protobuf REQUIRED)
INCLUDE_DIRECTORIES(
"D:/Codes/cpp/port/LibtorchPort/Dependencies/include"
"D:/External Libs/Opencv3.4.10_vc14_vc15/opencv3.4/include"
)
LINK_DIRECTORIES(
"D:/Codes/cpp/port/LibtorchPort/x64"
"D:/External Libs/Opencv3.4.10_vc14_vc15/opencv3.4/x64/vc14/lib"
)
# Define our library target
add_library(custom_class SHARED class1.cpp)
#define our c++ standard
set(CMAKE_CXX_STANDARD 17)
# Link against LibTorch
target_link_libraries(custom_class "${TORCH_LIBRARIES}")
and I’m calling cmake like this :
cmake -DCMAKE_PREFIX_PATH="$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')" ..
but I get the following error :
Severity Code Description Project File Line Suppression State
Error C2338 INVALID TYPE: Only int64_t and bool are supported as an integral argument type custom_class D:\Codes\cpp\port\LibtorchPort\Dependencies\libtorch-debug-latest\libtorch\include\ATen\core\op_registration\infer_schema.h 39
What am I missing here ?
Any help is greatly appreciated