NVCC compilation error for ITK 5.3

Hello.

When I try to use image reading functionality inside .cu file, I get compilation errors, whereas if I put the same code inside .cpp file, which is compiler using regular host compiler, the code normally compiles.

Platform:
Windows 11
Visual Studio 2022 17.4
CUDA 11.7 / 12.0 (same error on both)

I get the following errors:

C:\.conan\79dfc2\1\include\ITK-5.3\itkImageBase.h(117): error C2555: 'itk::ImageBase<3>::CreateAnother': overriding virtual function return type differs and is not covariant from 'itk::Object::CreateAnother'
  C:\.conan\79dfc2\1\include\ITK-5.3\itkObject.h(82): note: see declaration of 'itk::Object::CreateAnother'
  C:\.conan\79dfc2\1\include\ITK-5.3\itkImage.h(88): note: see reference to class template instantiation 'itk::ImageBase<3>' being compiled
  
  C:\Users\zukov\source\repos\GIR\testing\registration\registration.cu(10): note: see reference to class template instantiation 'itk::Image<float,3>' being compiled
  
C:\.conan\79dfc2\1\include\ITK-5.3\itkImage.h(101): error C2555: 'itk::Image<float,3>::CreateAnother': overriding virtual function return type differs and is not covariant from 'itk::ImageBase<3>::CreateAnother'
  
  C:\.conan\79dfc2\1\include\ITK-5.3\itkImageBase.h(117): note: see declaration of 'itk::ImageBase<3>::CreateAnother'
  
  ninja: build stopped: subcommand failed.

Build All failed.

main.cu

#include "itkImage.h"
#include "itkImageFileReader.h"

int
main(int argc, char * argv[])
{
    typedef float PixelType;
    typedef itk::Image<PixelType, 3> ImageType;

    itk::ReadImage<ImageType>(argv[1]);

    return 0;
}

I am not sure what subset of ITK can be used within CUDA code, but probably only GPU-related classes. @simon.rit @LucasGandel do have a more detailed answer?

I have never managed to use ITK in cu files when I tried a few years ago. This is why RTK separates the Cuda code completely from ITK. See for example

Only the cu files are compiled with nvcc. But RTK is quite old now and we sticked to this approach. Things might have changed since…

1 Like