Creating custom operator for pytorch is failing when I try to convert it into shared library

I am trying to implement direct_conv2d in a custom way using C++ and test it with a pytorch timm model. I have implemented the algorithm but when I try to convert it into shared library (.so) I got some errors. Here is the CMakeLists.txt file that I use to create shared library:

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(custom_direct_conv2d_op LANGUAGES CXX)

# Set C++ standard to 14

set(Torch_DIR "/users/ayavuzyasar/custom_dnns_operators/pysdk/lib/python3.8/site-packages/torch/share/cmake/Torch")

find_package(Torch REQUIRED)

add_library(custom_direct_conv2d_op MODULE direct_conv2d.cpp)

# Link against LibTorch
target_link_libraries(custom_direct_conv2d_op "${TORCH_LIBRARIES}")

When I try to create a shared library with cmake and make command I got this output:

If you can help me, I would be grateful.
Thanks in advance.

What’s the version of your CMakeLists.txt file that works?
I think you might need to tell CMake where to find the CUDA libraries as suggested in the error messages…

In my own libraries, I do call something like:


to my CMakeList.txt file.

I dont have CUDA libraries in the server and I dont need them either. This will be working on CPU. With installing the libraries with “+cpu” flag, (such as torch and torchvision) I fixed the problem but now I have another problem. When I try to compile it throws an error that indicates that it can not find lmkl libraries. It looks like this: