Ndefined symbol: _ZNK2at6Tensor6deviceEv when using c++ cuda extensions

Kracozebr: <p>I’m building some custom ops with cuda and c++.<br>
When I build my extensions in pytorch 1.8.1+cu102 it works properly.<br>
Here is the code from my setup.py:</p>
<pre><code class="lang-auto">from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension

if __name__ == '__main__':
    setup(
    name='my_extension',
    ext_modules=[
        CUDAExtension(
        'my_extension',
        sources=['src/my_exteinsion.cpp','src/my_extension.cu'],
    )
    ],
    cmdclass={
        'build_ext': BuildExtension
    }
)
</code></pre>
<p>When I try to build with pytorch 1.10.0+cu102 it builds the extension but when i try to import my extension it gives me the error:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "/workplace/test_custom_op.py", line 1, in &lt;module&gt;
    import my_extension
ImportError: /home/appuser/.local/lib/python3.6/site-packages/my_extension-0.0.0-py3.6-linux-x86_64.egg/mod_dcn_op_v2.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZNK2at6Tensor6deviceEv
</code></pre>
<p>I tryied to find the similar issues, but they were unresolved:</p><aside class="quote quote-modified" data-post="2" data-topic="121888">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pascal_notsawo/48/22829_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/colab-not-working/121888/2">Colab not working</a> 
  </div>
  <blockquote>
    Briefly: 

you have installed :

!pip install -q torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.0+cu101.html
!pip install -q torch-sparse -f https://pytorch-geometric.com/whl/torch-1.7.0+cu101.html
!pip install -q torch-geometric
!pip install ogb


when you do this import :

from torch_geometric.datasets import TUDataset



you get this error :

---------------------------------------------------------------------------
/usr/local/lib/python3.7/dist-packages/torch_geometric/__init_…
  </blockquote>
</aside>
<aside class="quote quote-modified" data-post="1" data-topic="127208">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/d_xu/48/31128_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/torch-geometric-installation-issue-with-colab/127208">Torch_geometric installation issue with Colab</a> 
  </div>
  <blockquote>
    I followed this <a href="https://colab.research.google.com/drive/1h3-vJGRVloF5zStxL5I0rSy4ZUPNsjy8?usp=sharing" rel="noopener nofollow ugc">colab notebook</a> to install torch_geometric to Google Colab: 
(I turned on the GPU of the notebook and ensured the version of torch and Cuda is 1.9.0+cu102) 
!pip install -q torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-sparse -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-geometric

And it appeared to be successful: 
Looking in links: https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
Requir…
  </blockquote>
</aside>
<aside class="quote quote-modified" data-post="1" data-topic="54195">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/ed8c4c/48.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/undefined-symbol-znk2at6tensor4dataiceept-v-when-build-pytorch-cuda-extension/54195">Undefined symbol: _ZNK2at6Tensor4dataIcEEPT_v when build pytorch cuda extension</a> <a class="badge-category__wrapper " href="/c/c/11"><span data-category-id="11" data-drop-close="true" class="badge-category " title="Topics related to the C++ Frontend, C++ API or C++ Extensions"><span class="badge-category__name">C++</span></span></a>
  </div>
  <blockquote>
    HI, Dear guys, 
I’m build a cuda extention for my pytorch script. However, the following error occurs. 
File "&lt;frozen importlib._bootstrap&gt;", line 684, in _load File "&lt;frozen importlib._bootstrap&gt;", line 658, in _load_unlocked File "&lt;frozen importlib._bootstrap&gt;", line 571, in module_from_spec File "&lt;frozen importlib._bootstrap_external&gt;", line 922, in create_module File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed ImportError: /tmp/torch_extensions/tools/tools.so: und…
  </blockquote>
</aside>
<p>
I’ve read the tutorial that describes how to build the extensions:<br>
<a href="https://pytorch.org/tutorials/advanced/cpp_extension.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/tutorials/advanced/cpp_extension.html</a><br>
Here is the quote</p>
<blockquote>
<p>A small note on compilers: Due to ABI versioning issues, the compiler you use to build your C++ extension must be <em>ABI-compatible</em> with the compiler PyTorch was built with. In practice, this means that you must use GCC version 4.9 and above on Linux.</p>
</blockquote>
<p>So as I understand ther error could be occurred due to  compiler version mismatch. I check the gcc version and it is v. 7.5.0<br>
Am I write about my suggestion? If so what version I should use and if I’m wrong what can be the source of error?</p>