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

atakirk: <p>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:</p>
<pre><code class="lang-auto">cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(custom_direct_conv2d_op LANGUAGES CXX)

# Set C++ standard to 14
set(CMAKE_CXX_STANDARD 14)

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

set(USE_CAFFE2 OFF)
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}")

</code></pre>
<p>When I try to create a shared library with cmake and make command I got this output:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/6/c655115dd46844bc2f2b77370174862b7b50e527.png" data-download-href="https://discuss.pytorch.org/uploads/default/c655115dd46844bc2f2b77370174862b7b50e527" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/6/c655115dd46844bc2f2b77370174862b7b50e527_2_690x268.png" alt="image" data-base62-sha1="siwNmp7VCOl7VerWLhuWfk2aKyz" width="690" height="268" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/6/c655115dd46844bc2f2b77370174862b7b50e527_2_690x268.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/6/c655115dd46844bc2f2b77370174862b7b50e527_2_1035x402.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/6/c655115dd46844bc2f2b77370174862b7b50e527_2_1380x536.png 2x" data-dominant-color="3F3540"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1390×540 79.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>If you can help me, I would be grateful.<br>
Thanks in advance.</p>

dfalbel: <p>What’s the version of your CMakeLists.txt file that works?<br>
I think you might need to tell CMake where to find the CUDA libraries as suggested in the error messages…</p>
<p>In my own libraries, I do call something like:</p>
<pre><code class="lang-auto">enable_language(CUDA)
add_compile_definitions("CUDA${CUDA_VERSION_NUMBER}")
</code></pre>
<p>to my CMakeList.txt file.</p>

atakirk: <p>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:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/8/986d5fd2ed207164d6da7423aa6d891dd5a47cef.png" data-download-href="https://discuss.pytorch.org/uploads/default/986d5fd2ed207164d6da7423aa6d891dd5a47cef" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/9/8/986d5fd2ed207164d6da7423aa6d891dd5a47cef_2_690x119.png" alt="image" data-base62-sha1="lKqUlMhNXCPTwFD3OP2rCM5hzaL" width="690" height="119" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/9/8/986d5fd2ed207164d6da7423aa6d891dd5a47cef_2_690x119.png, https://discuss.pytorch.org/uploads/default/optimized/3X/9/8/986d5fd2ed207164d6da7423aa6d891dd5a47cef_2_1035x178.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/9/8/986d5fd2ed207164d6da7423aa6d891dd5a47cef_2_1380x238.png 2x" data-dominant-color="3E3B47"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">2098×364 57.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>