# NVCC compilation error for ITK 5.3

**URL:** https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612
**Category:** Beginner Questions
**Tags:** cuda, cpp
**Created:** [January 5, 2023, 9:00am UTC](https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612 "2023-01-05T09:00:06Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![mzukovec](https://discourse.itk.org/user_avatar/discourse.itk.org/mzukovec/32/2732_2.png) [@mzukovec](https://discourse.itk.org/u/mzukovec)
#### Post date: [January 5, 2023, 9:00am UTC](https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612/1 "2023-01-05T09:00:06Z")

</div>

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:

```auto
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

```auto
#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;
}

```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 5, 2023, 3:10pm UTC](https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612/2 "2023-01-05T15:10:13Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [January 5, 2023, 3:28pm UTC](https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612/3 "2023-01-05T15:28:26Z")

</div>

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

> <https://github.com/RTKConsortium/RTK/blob/master/include/rtkCudaCropImageFilter.h>

> <https://github.com/RTKConsortium/RTK/blob/master/src/rtkCudaCropImageFilter.cxx>

> <https://github.com/RTKConsortium/RTK/blob/master/include/rtkCudaCropImageFilter.hcu>

> <https://github.com/RTKConsortium/RTK/blob/master/src/rtkCudaCropImageFilter.cu>

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…

---

<div class="post-metadata">

### Author: ![zx-lhb](https://discourse.itk.org/user_avatar/discourse.itk.org/zx-lhb/32/3082_2.png) [@zx-lhb](https://discourse.itk.org/u/zx-lhb)
#### Post date: [May 26, 2023, 3:24am UTC](https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612/4 "2023-05-26T03:24:18Z")

</div>

hi，I got the same error when compiling the following code, have you came out any solution to use itk in .cu file?

```cpp
#include<iostream>
using namespace std;

#include<cuda_runtime.h>
#include<itkImage.h>
#include<itkNiftiImageIO.h>
#include<itkImageFileReader.h>
#include<itkImageFileWriter.h>

const int Dimension = 3;
using PixelType = short;
using ImageType = itk::Image<PixelType, Dimension>;

const int BPLINE_BOARD_SIZE = 3;

int main()
{
	ImageType::Pointer image;

	return 0;
}

```

---

<div class="post-metadata">

### Author: ![mzukovec](https://discourse.itk.org/user_avatar/discourse.itk.org/mzukovec/32/2732_2.png) [@mzukovec](https://discourse.itk.org/u/mzukovec)
#### Post date: [May 26, 2023, 10:28am UTC](https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612/5 "2023-05-26T10:28:12Z")

</div>

@zx-lhb

I split the code into `.cpp` and `.cu` file, read the image in the `.cpp` and passed the raw buffer pointer to `.cu` via `image->GetBufferPointer()`.

---

<div class="post-metadata">

### Author: ![zx-lhb](https://discourse.itk.org/user_avatar/discourse.itk.org/zx-lhb/32/3082_2.png) [@zx-lhb](https://discourse.itk.org/u/zx-lhb)
#### Post date: [May 27, 2023, 1:55am UTC](https://discourse.itk.org/t/nvcc-compilation-error-for-itk-5-3/5612/6 "2023-05-27T01:55:46Z")

</div>

thank you!
