mzukovec
(Martin Zukovec)
January 5, 2023, 9:00am
1
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;
}
dzenanz
(Dženan Zukić)
January 5, 2023, 3:10pm
2
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?
simon.rit
(Simon Rit)
January 5, 2023, 3:28pm
3
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
/*=========================================================================
*
* Copyright RTK Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef rtkCudaCropImageFilter_h
#define rtkCudaCropImageFilter_h
This file has been truncated. show original
/*=========================================================================
*
* Copyright RTK Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "rtkCudaCropImageFilter.h"
#include "rtkCudaUtilities.hcu"
This file has been truncated. show original
/*=========================================================================
*
* Copyright RTK Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef rtkCudaCropImageFilter_hcu
#define rtkCudaCropImageFilter_hcu
This file has been truncated. show original
/*=========================================================================
*
* Copyright RTK Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
// rtk includes
#include "rtkCudaUtilities.hcu"
This file has been truncated. show original
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
zx-lhb
(zx-lhb)
May 26, 2023, 3:24am
4
hi,I got the same error when compiling the following code, have you came out any solution to use itk in .cu file?
#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;
}
mzukovec
(Martin Zukovec)
May 26, 2023, 10:28am
5
@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()
.