[Insight-developers] [Insight-users] Problems with ITK

Cory Quammen cquammen at cs.unc.edu
Wed Oct 24 15:19:12 EDT 2012


Okay, I tried to build your code with Visual Studio 2008 and I get the
following error message:

1>------ Build started: Project: test6lib, Configuration: Debug x64 ------
1>Building NVCC (Device) object
test6CudaLibrary/CMakeFiles/test6lib.dir//Debug/test6lib_generated_loadVar_cuda.cu.obj
1>The command line is too long.
1>CMake Error at test6lib_generated_loadVar_cuda.cu.obj.cmake:198 (message):
1>  Error generating
1>  D:/cquammen/build/itkcuda/test6CudaLibrary/CMakeFiles/test6lib.dir//Debug/test6lib_generated_loadVar_cuda.cu.obj
1>Project : error PRJ0019: A tool returned an error code from
"Building NVCC (Device) object
test6CudaLibrary/CMakeFiles/test6lib.dir//Debug/test6lib_generated_loadVar_cuda.cu.obj"
1>Build log was saved at
"file://d:\cquammen\build\itkcuda\test6CudaLibrary\test6lib.dir\Debug\BuildLog.htm"
1>test6lib - 1 error(s), 0 warning(s)
2>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug x64 ------
2>Project not selected to build for this solution configuration
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 1 skipped ==========

This is a problem I've run into before when using CUDA in projects
that also use ITK and VTK. The includes for ITK are passed along to
nvcc (the CUDA compiler). Because ITK has so many modules, the command
line for nvcc becomes too long. The same is true for the new modular
VTK.

The only decent solution I've found to this problem is to add a
subdirectory for CUDA code, clear out the INCLUDE_DIRECTORIES property
in the CMakeLists.txt file for that subdirectory, and compile a
separate library for the CUDA code. You'll need to add this library to
the TARGET_LINK_LIBRARIES command for your executable.

I've attached the modified version of your source code. It compiles
and links for me.

HTH,
Cory

On Wed, Oct 24, 2012 at 3:05 PM, Gabriel Santiago
<santiago.eletrica at gmail.com> wrote:
> Actually, right now, the only error message that I get with that code is:
>
> make: *** [cmake_check_build_system] Error 1 test6 C/C++ Problem
>
> (I just updated to ITK 4.2.1.)
>
> Thank you,
>
>
> On 24 October 2012 16:55, Cory Quammen <cquammen at cs.unc.edu> wrote:
>>
>> Gabriel,
>>
>> Please keep the discussion on the list so that others with similar
>> questions may benefit from our discussion.
>>
>> I suspect your error message is longer. Can you please post the full
>> error message?
>>
>> Thank you,
>> Cory
>>
>> On Wed, Oct 24, 2012 at 7:27 AM, Gabriel Santiago
>> <santiago.eletrica at gmail.com> wrote:
>> > Cory,
>> >
>> > Here they are! My .cu, .h, cpp and my CMakeLists.txt.
>> >
>> > Thank you very much for your help!
>> >
>> >
>> > On 23 October 2012 17:17, Cory Quammen <cquammen at cs.unc.edu> wrote:
>> >>
>> >> To help you further, I'll need to see your CMakeLists.txt and source
>> >> files.
>> >>
>> >> Cory
>> >>
>> >> On Tue, Oct 23, 2012 at 2:28 PM, Gabriel Santiago
>> >> <santiago.eletrica at gmail.com> wrote:
>> >> > By the way, I don't know if this is relevant, but I am actually using
>> >> > Cuda
>> >> > 5.0 with Nsight as editor/ debugger.
>> >> >
>> >> > Even if I use pure C++, I get the very same error message as if I use
>> >> > some
>> >> > Cuda code.
>> >> >
>> >> > Regards,
>> >> >
>> >> > On 23 October 2012 15:49, Gabriel Santiago
>> >> > <santiago.eletrica at gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> Still not working... The problem happens when CMake/ ITK comes into
>> >> >> scene...
>> >> >>
>> >> >> I get this error message:
>> >> >>
>> >> >> CMake Error at Proj_generated_loadVar_Cuda.cu.o.cmake:256 (message):
>> >> >>   Error generating file
>> >> >>
>> >> >>
>> >> >>
>> >> >> /home/gabriel/cuda-workspace/Proj/CMakeFiles/teste6.dir//./Proj_generated_loadVar_Cuda.cu.o
>> >> >>
>> >> >> My CMakeLists.txt is the same as the example. Also, I've found this
>> >> >> page:
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> https://gforge.sci.utah.edu/gf/project/findcuda/scmsvn/?action=browse&path=%2F*checkout*%2Ftrunk%2FFindCuda.html
>> >> >>
>> >> >> But nothing...
>> >> >>
>> >> >> On 23 October 2012 14:01, Cory Quammen <cquammen at cs.unc.edu> wrote:
>> >> >>>
>> >> >>> By including your .cuh and .cu files like that, your standard C++
>> >> >>> compiler is going to try to compile the CUDA code in those source
>> >> >>> files.  Since it doesn't know anything about CUDA, you are getting
>> >> >>> errors.
>> >> >>>
>> >> >>> This is off the top of my head, and I haven't tried to compile it,
>> >> >>> but
>> >> >>> your source files will look something like this:
>> >> >>>
>> >> >>> In my_cuda.h:
>> >> >>>
>> >> >>> extern "C"
>> >> >>> void someCudaFunction();
>> >> >>>
>> >> >>> In my_cuda.cu:
>> >> >>>
>> >> >>> __global__ void someCudaFunction()
>> >> >>> {
>> >> >>> }
>> >> >>>
>> >> >>> In my_main.cpp:
>> >> >>>
>> >> >>> #include "my_cuda.h"
>> >> >>> #include <itkMyFavoriteFilter.h>
>> >> >>>
>> >> >>> int main(int argc, char*argv[])
>> >> >>> {
>> >> >>>   // Do some ITK stuff here
>> >> >>>
>> >> >>>   // Do some CUDA stuff here.
>> >> >>>   someCudaFunction<<<block,grid>>>();
>> >> >>> }
>> >> >>>
>> >> >>> In CMakeLists.txt:
>> >> >>>
>> >> >>> PROJECT( PROJECT_NAME )
>> >> >>> CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
>> >> >>> FIND_PACKAGE ( ITK REQUIRED )
>> >> >>> FIND_PACKAGE(CUDA)
>> >> >>> INCLUDE(FindCUDA)
>> >> >>> IF ( ITK_FOUND )
>> >> >>> INCLUDE( ${ITK_USE_FILE} )
>> >> >>> ENDIF( ITK_FOUND )
>> >> >>> CUDA_ADD_EXECUTABLE( PROJECT_NAME my_cuda.cu my_main.cpp )
>> >> >>> TARGET_LINK_LIBRARIES ( PROJECT_NAME ITKCommon ITKIO)
>> >> >>>
>> >> >>> Hope that helps,
>> >> >>> Cory
>> >> >>>
>> >> >>> On Tue, Oct 23, 2012 at 11:19 AM, Gabriel Santiago
>> >> >>> <santiago.eletrica at gmail.com> wrote:
>> >> >>> > Thank you for your attention, Cory. But this can sound very
>> >> >>> > stupid,
>> >> >>> > but
>> >> >>> > *how* exactly do I do that?
>> >> >>> >
>> >> >>> > I packed everything in a .cuh and a .cu file and than included
>> >> >>> > then
>> >> >>> > in
>> >> >>> > my
>> >> >>> > main.cpp file, but the compiler complains about my cuda
>> >> >>> > functions,
>> >> >>> > saying
>> >> >>> > that the qualifier __global__ does not name a type.
>> >> >>> >
>> >> >>> > Could you please, give me a quick example on how my files should
>> >> >>> > look
>> >> >>> > like?
>> >> >>> > I would be very grateful.
>> >> >>> >
>> >> >>> >
>> >> >>> > On 23 October 2012 11:56, Cory Quammen <cquammen at cs.unc.edu>
>> >> >>> > wrote:
>> >> >>> >>
>> >> >>> >> Gabriel,
>> >> >>> >>
>> >> >>> >> You must be trying to use CUDA in your project. I wouldn't be
>> >> >>> >> surprised if the CUDA compiler has trouble with all the features
>> >> >>> >> of
>> >> >>> >> C++ that ITK uses.
>> >> >>> >>
>> >> >>> >> The good news is that you don't need to define your main
>> >> >>> >> function
>> >> >>> >> inside a CUDA source file. You can instead compile only your
>> >> >>> >> CUDA
>> >> >>> >> source with the CUDA compiler, and all your regular C++ code as
>> >> >>> >> C++
>> >> >>> >> files. Just put the CUDA code in a .cu file, put your main C++
>> >> >>> >> code
>> >> >>> >> in
>> >> >>> >> a .cpp file, then add all the source files to your call to
>> >> >>> >> CUDA_ADD_EXECUTABLE. CMake should figure out how to compile them
>> >> >>> >> automatically.
>> >> >>> >>
>> >> >>> >> Hope that helps,
>> >> >>> >> Cory
>> >> >>> >>
>> >> >>> >> On Tue, Oct 23, 2012 at 9:45 AM, Bill Lorensen
>> >> >>> >> <bill.lorensen at gmail.com>
>> >> >>> >> wrote:
>> >> >>> >> > Why are you using .cu?
>> >> >>> >> >
>> >> >>> >> > On Tue, Oct 23, 2012 at 9:37 AM, Gabriel Santiago
>> >> >>> >> > <santiago.eletrica at gmail.com> wrote:
>> >> >>> >> >>
>> >> >>> >> >> I am using 3.20.1 version.
>> >> >>> >> >>
>> >> >>> >> >> If I change to .cpp instead of .cu everything works fine.
>> >> >>> >> >>
>> >> >>> >> >>
>> >> >>> >> >> On 23 October 2012 11:34, Bill Lorensen
>> >> >>> >> >> <bill.lorensen at gmail.com>
>> >> >>> >> >> wrote:
>> >> >>> >> >>>
>> >> >>> >> >>> Please keep on list....
>> >> >>> >> >>>
>> >> >>> >> >>> What version of ITK? And what happens if you define it as a
>> >> >>> >> >>> .cxx
>> >> >>> >> >>> rather
>> >> >>> >> >>> than .cu?
>> >> >>> >> >>>
>> >> >>> >> >>>
>> >> >>> >> >>> On Tue, Oct 23, 2012 at 9:17 AM, Gabriel Santiago
>> >> >>> >> >>> <santiago.eletrica at gmail.com> wrote:
>> >> >>> >> >>>>
>> >> >>> >> >>>> Sure!
>> >> >>> >> >>>>
>> >> >>> >> >>>> In my main.cu file:
>> >> >>> >> >>>>
>> >> >>> >> >>>> #include <iostream>
>> >> >>> >> >>>> #include <string>
>> >> >>> >> >>>> #include "itkImageFileReader.h"
>> >> >>> >> >>>>
>> >> >>> >> >>>> using std::cout;
>> >> >>> >> >>>> using std::string;
>> >> >>> >> >>>>
>> >> >>> >> >>>> int main(void){
>> >> >>> >> >>>>
>> >> >>> >> >>>> string filename = "dicom_file.dcm";
>> >> >>> >> >>>>
>> >> >>> >> >>>> typedef signed int InputPixelType;
>> >> >>> >> >>>> typedef itk::Image<InputPixelType, 3> InputImageType;
>> >> >>> >> >>>> typedef itk::ImageFileReader<InputImageType> ReaderType;
>> >> >>> >> >>>> ReaderType::Pointer reader = ReaderType::New();
>> >> >>> >> >>>> reader->SetFileName(filename.c_str());
>> >> >>> >> >>>>
>> >> >>> >> >>>> return 0;
>> >> >>> >> >>>>
>> >> >>> >> >>>> }
>> >> >>> >> >>>>
>> >> >>> >> >>>> My CMakeLists.txt file conatins:
>> >> >>> >> >>>>
>> >> >>> >> >>>> PROJECT( PROJECT_NAME )
>> >> >>> >> >>>> CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
>> >> >>> >> >>>> FIND_PACKAGE ( ITK REQUIRED )
>> >> >>> >> >>>> FIND_PACKAGE(CUDA)
>> >> >>> >> >>>> INCLUDE(FindCUDA)
>> >> >>> >> >>>> IF ( ITK_FOUND )
>> >> >>> >> >>>> INCLUDE( ${ITK_USE_FILE} )
>> >> >>> >> >>>> ENDIF( ITK_FOUND )
>> >> >>> >> >>>> CUDA_ADD_EXECUTABLE( PROJECT_NAME main.cu )
>> >> >>> >> >>>> TARGET_LINK_LIBRARIES ( PROJECT_NAME ITKCommon ITKIO)
>> >> >>> >> >>>>
>> >> >>> >> >>>> Thank you for your reply,
>> >> >>> >> >>>>
>> >> >>> >> >>>> On 23 October 2012 11:08, Bill Lorensen
>> >> >>> >> >>>> <bill.lorensen at gmail.com>
>> >> >>> >> >>>> wrote:
>> >> >>> >> >>>>>
>> >> >>> >> >>>>> Gabriel,
>> >> >>> >> >>>>>
>> >> >>> >> >>>>> Can you provide a small compilable example to illustrate
>> >> >>> >> >>>>> your
>> >> >>> >> >>>>> problem?
>> >> >>> >> >>>>>
>> >> >>> >> >>>>> Bill
>> >> >>> >> >>>>>
>> >> >>> >> >>>>> On Mon, Oct 22, 2012 at 7:35 AM, Gabriel Santiago
>> >> >>> >> >>>>> <santiago.eletrica at gmail.com> wrote:
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> Hi guys,
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> I am trying to read a DICOM file using ITK. I am doing
>> >> >>> >> >>>>>> exactly
>> >> >>> >> >>>>>> what
>> >> >>> >> >>>>>> is
>> >> >>> >> >>>>>> described in the ITK User Guide but I am getting some
>> >> >>> >> >>>>>> weird
>> >> >>> >> >>>>>> error
>> >> >>> >> >>>>>> messages.
>> >> >>> >> >>>>>> Here they are:
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>>  overriding ‘itk::ImageBase<VImageDimension>::Pointer
>> >> >>> >> >>>>>> itk::ImageBase<VImageDimension>::CreateAnother() const
>> >> >>> >> >>>>>> [with
>> >> >>> >> >>>>>> unsigned int
>> >> >>> >> >>>>>> VImageDimension = 3u,
>> >> >>> >> >>>>>> itk::ImageBase<VImageDimension>::Pointer
>> >> >>> >> >>>>>> =
>> >> >>> >> >>>>>> itk::SmartPointer<itk::ImageBase<3u> >]’
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> overriding ‘virtual itk::LightObject::Pointer
>> >> >>> >> >>>>>> itk::Object::CreateAnother() const’
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> invalid covariant return type for
>> >> >>> >> >>>>>> ‘itk::ImageBase<VImageDimension>::Pointer
>> >> >>> >> >>>>>> itk::ImageBase<VImageDimension>::CreateAnother() const
>> >> >>> >> >>>>>> [with
>> >> >>> >> >>>>>> unsigned int
>> >> >>> >> >>>>>> VImageDimension = 3u,
>> >> >>> >> >>>>>> itk::ImageBase<VImageDimension>::Pointer
>> >> >>> >> >>>>>> =
>> >> >>> >> >>>>>> itk::SmartPointer<itk::ImageBase<3u> >]’
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> invalid covariant return type for
>> >> >>> >> >>>>>> ‘itk::LightObject::Pointer
>> >> >>> >> >>>>>> itk::Image<TPixel, VImageDimension>::CreateAnother()
>> >> >>> >> >>>>>> const
>> >> >>> >> >>>>>> [with
>> >> >>> >> >>>>>> TPixel =
>> >> >>> >> >>>>>> int, unsigned int VImageDimension = 3u,
>> >> >>> >> >>>>>> itk::LightObject::Pointer =
>> >> >>> >> >>>>>> itk::SmartPointer<itk::LightObject>]’
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> All of them are not in my code. Can anyone here, please
>> >> >>> >> >>>>>> tell
>> >> >>> >> >>>>>> me
>> >> >>> >> >>>>>> what
>> >> >>> >> >>>>>> is going on?
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> Thank you all,
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> --
>> >> >>> >> >>>>>> Gabriel Santiago
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> ~"As long as I live so long do I learn"~
>> >> >>> >> >>>>>> Ramakhrishna
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> _____________________________________
>> >> >>> >> >>>>>> Powered by www.kitware.com
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> Visit other Kitware open-source projects at
>> >> >>> >> >>>>>> http://www.kitware.com/opensource/opensource.html
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> Kitware offers ITK Training Courses, for more information
>> >> >>> >> >>>>>> visit:
>> >> >>> >> >>>>>> http://www.kitware.com/products/protraining.php
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> Please keep messages on-topic and check the ITK FAQ at:
>> >> >>> >> >>>>>> http://www.itk.org/Wiki/ITK_FAQ
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>> Follow this link to subscribe/unsubscribe:
>> >> >>> >> >>>>>> http://www.itk.org/mailman/listinfo/insight-users
>> >> >>> >> >>>>>>
>> >> >>> >> >>>>>
>> >> >>> >> >>>>>
>> >> >>> >> >>>>>
>> >> >>> >> >>>>> --
>> >> >>> >> >>>>> Unpaid intern in BillsBasement at noware dot com
>> >> >>> >> >>>>>
>> >> >>> >> >>>>
>> >> >>> >> >>>>
>> >> >>> >> >>>>
>> >> >>> >> >>>> --
>> >> >>> >> >>>> Gabriel Santiago
>> >> >>> >> >>>>
>> >> >>> >> >>>>
>> >> >>> >> >>>> ~"As long as I live so long do I learn"~
>> >> >>> >> >>>> Ramakhrishna
>> >> >>> >> >>>>
>> >> >>> >> >>>
>> >> >>> >> >>>
>> >> >>> >> >>>
>> >> >>> >> >>> --
>> >> >>> >> >>> Unpaid intern in BillsBasement at noware dot com
>> >> >>> >> >>>
>> >> >>> >> >>
>> >> >>> >> >>
>> >> >>> >> >>
>> >> >>> >> >> --
>> >> >>> >> >> Gabriel Santiago
>> >> >>> >> >>
>> >> >>> >> >> ~"As long as I live so long do I learn"~
>> >> >>> >> >> Ramakhrishna
>> >> >>> >> >>
>> >> >>> >> >
>> >> >>> >> >
>> >> >>> >> >
>> >> >>> >> > --
>> >> >>> >> > Unpaid intern in BillsBasement at noware dot com
>> >> >>> >> >
>> >> >>> >> >
>> >> >>> >> > _______________________________________________
>> >> >>> >> > Powered by www.kitware.com
>> >> >>> >> >
>> >> >>> >> > Visit other Kitware open-source projects at
>> >> >>> >> > http://www.kitware.com/opensource/opensource.html
>> >> >>> >> >
>> >> >>> >> > Kitware offers ITK Training Courses, for more information
>> >> >>> >> > visit:
>> >> >>> >> > http://kitware.com/products/protraining.php
>> >> >>> >> >
>> >> >>> >> > Please keep messages on-topic and check the ITK FAQ at:
>> >> >>> >> > http://www.itk.org/Wiki/ITK_FAQ
>> >> >>> >> >
>> >> >>> >> > Follow this link to subscribe/unsubscribe:
>> >> >>> >> > http://www.itk.org/mailman/listinfo/insight-developers
>> >> >>> >> >
>> >> >>> >>
>> >> >>> >>
>> >> >>> >>
>> >> >>> >> --
>> >> >>> >> Cory Quammen
>> >> >>> >> Research Associate
>> >> >>> >> Department of Computer Science
>> >> >>> >> The University of North Carolina at Chapel Hill
>> >> >>> >
>> >> >>> >
>> >> >>> >
>> >> >>> >
>> >> >>> > --
>> >> >>> > Gabriel Santiago
>> >> >>> >
>> >> >>> > ~"As long as I live so long do I learn"~
>> >> >>> > Ramakhrishna
>> >> >>> >
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> --
>> >> >>> Cory Quammen
>> >> >>> Research Associate
>> >> >>> Department of Computer Science
>> >> >>> The University of North Carolina at Chapel Hill
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Gabriel Santiago
>> >> >>
>> >> >> ~"As long as I live so long do I learn"~
>> >> >> Ramakhrishna
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Gabriel Santiago
>> >> >
>> >> > ~"As long as I live so long do I learn"~
>> >> > Ramakhrishna
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Cory Quammen
>> >> Research Associate
>> >> Department of Computer Science
>> >> The University of North Carolina at Chapel Hill
>> >
>> >
>> >
>> >
>> > --
>> > Gabriel Santiago
>> >
>> > ~"As long as I live so long do I learn"~
>> > Ramakhrishna
>> >
>>
>>
>>
>> --
>> Cory Quammen
>> Research Associate
>> Department of Computer Science
>> The University of North Carolina at Chapel Hill
>
>
>
>
> --
> Gabriel Santiago
>
> ~"As long as I live so long do I learn"~
> Ramakhrishna
>



-- 
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cuda_itk_test2.zip
Type: application/zip
Size: 2981 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20121024/32240829/attachment.zip>


More information about the Insight-developers mailing list