Error when building cpp extension

  • OS: ubuntu 18.04
  • PyTorch version: 1.6
  • How you installed PyTorch (conda, pip, source): pip
  • Python version: 3.6
  • CUDA/cuDNN version: 10.1
  • GCC version (if compiling from source):7.4
    I am creating a custom c++ extension but I get an error on compiling when I add #include <THC/THCAtomics.cuh> in .h file and build through setup then it will have following errors:
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In member function ‘void AtomicAddIntegerImpl<T, 1>::operator()(T*, T)’:
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:31:13: error: there are no arguments to ‘atomicCAS’ that depend on a template parameter, so a declaration of ‘atomicCAS’ must be available [-fpermissive] old = atomicCAS(address_as_ui, assumed, newval);
    ^~~~~~~~~
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:31:13: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In member function ‘void AtomicAddIntegerImpl<T, 2>::operator()(T*, T)’:
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:54:13: error: there are no arguments to ‘atomicCAS’ that depend on a template parameter, so a declaration of ‘atomicCAS’ must be available [-fpermissive] old = atomicCAS(address_as_ui, assumed, newval);
    ^~~~~~~~~
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In member function ‘void AtomicAddIntegerImpl<T, 4>::operator()(T*, T)’:
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:70:13: error: there are no arguments to ‘atomicCAS’ that depend on a template parameter, so a declaration of ‘atomicCAS’ must be available [-fpermissive] old = atomicCAS(address_as_ui, assumed, newval);
    ^~~~~~~~~
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In member function ‘void AtomicAddIntegerImpl<T, 8>::operator()(T*, T)’:
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:86:13: error: there are no arguments to ‘atomicCAS’ that depend on a template parameter, so a declaration of ‘atomicCAS’ must be available [-fpermissive] old = atomicCAS(address_as_ui, assumed, newval);
    ^~~~~~~~~
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In function ‘void gpuAtomicAdd(int32_t*, int32_t)’: /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:104:3: error: ‘atomicAdd’ was not declared in this scope
    atomicAdd(address, val);
    ^~~~~~~~~
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:104:3: note: suggested alternative: ‘gpuAtomicAdd’ atomicAdd(address, val);
    ^~~~~~~~~
    gpuAtomicAdd
    usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In function ‘void gpuAtomicAdd(c10::Half*, c10::Half)’:
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:135:5: error: ‘atomicAdd’ was not declared in this scope
    atomicAdd(reinterpret_cast<__half*>(address), val);
    ^~~~~~~~~
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:135:5: note: suggested alternative: ‘gpuAtomicAdd’
    atomicAdd(reinterpret_cast<__half*>(address), val);
    ^~~~~~~~~
    gpuAtomicAdd
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In function ‘void gpuAtomicAdd(c10::BFloat16*, c10::BFloat16)’:
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:152:13: error: ‘atomicCAS’ was not declared in this scope old = atomicCAS(address_as_ui, assumed, old);
    ^~~~~~~~~
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In function 'void gpuAtomicAdd(double*, double ': /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:198:3: error: ‘atomicAdd’ was not declared in this scope atomicAdd(address, val);
    ^~~~~~~~~ /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:198:3: note: suggested alternative: ‘gpuAtomicAdd’
    atomicAdd(address, val);
    ^~~~~~~~~
    gpuAtomicAdd
    /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh: In function ‘void gpuAtomicAdd(float*, float)’:/usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:202:3: error: ‘atomicAdd’ was not declared in this scope atomicAdd(address, val);
    ^~~~~~~~~ /usr/local/lib/python3.6/dist-packages/torch/include/THC/THCAtomics.cuh:202:3: note: suggested alternative: ‘gpuAtomicAdd’
    atomicAdd(address, val);
    ^~~~~~~~~ gpuAtomicAdd