InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.41k stars 663 forks source link

build itk with ITK_USE_CUFFTW ITK_USE_GPU ON gets error #3744

Open zhusihan-python opened 1 year ago

zhusihan-python commented 1 year ago

build itk master on windows 10 cmake 3.23.1 vs 2022 cuda 11.8 got errors

Description

88f033127f588834b1041ee3831050a

Steps to Reproduce

1、set option ITK_USE_GPU=ON ITK_USE_CUFFTW=ON in CmakeList.txt 2、configure cmake 18af6a41eee9b13f8c0d019c5a6927b

got some warnings as below 4751fbde926bdac8f18a81189e33f84

46fcba9965dc1a67254aace213e35be

all wrap_* has been turn on, still got the warnings, so i just ignore it and continue generate

Expected behavior

build successful, then i can build itk montage using cufft acclerated itk

Actual behavior

build failed

Error   LNK2019 unresolved external symbol "public: static void __cdecl itk::FFTWFFTImageFilterInitFactory::RegisterFactories(void)" (?RegisterFactories@FFTWFFTImageFilterInitFactory@itk@@SAXXZ) referenced in function _wrap_itkFFTWFFTImageFilterInitFactory_RegisterOneFactory ITKFFTPython    D:\build_itk_new\Wrapping\Modules\ITKFFT\itkFFTWFFTImageFilterInitFactoryPython.obj 1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "protected: __cdecl itk::FFTWFFTImageFilterInitFactory::FFTWFFTImageFilterInitFactory(void)" (??0FFTWFFTImageFilterInitFactory@itk@@IEAA@XZ) referenced in function "public: static class itk::SmartPointer<class itk::FFTWFFTImageFilterInitFactory> __cdecl itk::FFTWFFTImageFilterInitFactory::New(void)" (?New@FFTWFFTImageFilterInitFactory@itk@@SA?AV?$SmartPointer@VFFTWFFTImageFilterInitFactory@itk@@@2@XZ) ITKFFTPython    D:\build_itk_new\Wrapping\Modules\ITKFFT\itkFFTWFFTImageFilterInitFactoryPython.obj 1   

Severity    Code    Description Project File    Line    Suppression State
Error   LNK1120 2 unresolved externals  ITKFFTPython    D:\build_itk_new\Wrapping\Generators\Python\itk\_ITKFFTPython.pyd   1   

Severity    Code    Description Project File    Line    Suppression State
Error   MSB8066 Custom build for 'D:\build_itk_new\CMakeFiles\44df38219fcd6d646b4dd91a924288b1\itk-stub-files.rule' exited with code 1. itk-stub-files  D:\softwares\visualStudio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets  245 

Reproducibility

Versions

master branch commit id 38696b2609884358af0d10b062213fcfc2ffcef1

Environment

windows 10 cmake 3.23.1 vs 2022 cuda 11.8 python 3.10.8

Additional Information

dzenanz commented 1 year ago

None of your images have uploaded properly.

zhusihan-python commented 1 year ago

None of your images have uploaded properly.

sor, i have updated the images

thewtex commented 1 year ago

@zhusihan-python thanks for the report.

i can build itk montage using cufft acclerated itk

We are finalizing itk-5.3.0, at which time we will build packages for itk-montage but also itk-vkfftbackend, which provides GPU acceleration and you will be able to pip install both.

dzenanz commented 1 year ago

It looks like the problem is that GPU filters are not wrapped for Python. I guess that Matt's suggested solution is easier.

zhusihan-python commented 1 year ago

It looks like the problem is that GPU filters are not wrapped for Python. I guess that Matt's suggested solution is easier.

Sir dzenaz, i tried to set wrap_python to OFF, still got the same error, i notice that the tag 5.3.0 is released yesterday, i tried on this tag, got the same build warnings and errors too, just FYI.

dzenanz commented 1 year ago

referenced in function _wrap_itkFFTWFFTImageFilterInitFactory_RegisterOneFactory

This is clearly Python-related. Did you turn off ITK_WRAP_PYTHON?

Also possibly look at https://github.com/InsightSoftwareConsortium/ITK/issues/1809#issuecomment-628696627.

zhusihan-python commented 1 year ago

with ITK_WRAP_PYTHON OFF, ITK_USE_GPU ON, ITK_USE_CUFFTW ON got errors as below:


471>FFTImageFilterFourierDomainFiltering.obj : error LNK2001: unresolved external symbol "void __cdecl itk::FFTWFFTImageFilterInitFactoryRegister__Private(void)" (?FFTWFFTImageFilterInitFactoryRegister__Private@itk@@YAXXZ)
471>F:\build_itk\bin\Release\FFTImageFilterFourierDomainFiltering.exe : fatal error LNK1120: 1 unresolved externals
472>FFTImageFilter.obj : error LNK2001: unresolved external symbol "void __cdecl itk::FFTWFFTImageFilterInitFactoryRegister__Private(void)" (?FFTWFFTImageFilterInitFactoryRegister__Private@itk@@YAXXZ)
472>F:\build_itk\bin\Release\FFTImageFilter.exe : fatal error LNK1120: 1 unresolved externals
471>Done building project "FFTImageFilterFourierDomainFiltering.vcxproj" -- FAILED.
492>------ Build started: Project: DeformableRegistration7, Configuration: Release x64 ------
473>FFTDirectInverse2.obj : error LNK2001: unresolved external symbol "void __cdecl itk::FFTWFFTImageFilterInitFactoryRegister__Private(void)" (?FFTWFFTImageFilterInitFactoryRegister__Private@itk@@YAXXZ)
473>F:\build_itk\bin\Release\FFTDirectInverse2.exe : fatal error LNK1120: 1 unresolved externals
491>E:\projects\ITK\Modules\Filtering\Smoothing\include\itkRecursiveGaussianImageFilter.h(1,1): warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
491>E:\projects\ITK\Modules\Filtering\ImageFilterBase\include\itkRecursiveSeparableImageFilter.h(1,1): warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
473>Done building project "FFTDirectInverse2.vcxproj" -- FAILED.
493>------ Build started: Project: DeformableRegistration6, Configuration: Release x64 ------
472>Done building project "FFTImageFilter.vcxproj" -- FAILED.

486>DicomPrintPatientInformation.vcxproj -> F:\build_itk\bin\Release\DicomPrintPatientInformation.exe 474>FFTDirectInverse.obj : error LNK2001: unresolved external symbol "void cdecl itk::FFTWFFTImageFilterInitFactoryRegisterPrivate(void)" (?FFTWFFTImageFilterInitFactoryRegister__Private@itk@@YAXXZ) 497>------ Build started: Project: DeformableRegistration2, Configuration: Release x64 ------ 474>F:\build_itk\bin\Release\FFTDirectInverse.exe : fatal error LNK1120: 1 unresolved externals 492>DeformableRegistration7.cxx 497>Building Custom Rule E:/projects/ITK/Examples/RegistrationITKv4/CMakeLists.txt 477>EllipseSpatialObject.vcxproj -> F:\build_itk\bin\Release\EllipseSpatialObject.exe 474>Done building project "FFTDirectInverse.vcxproj" -- FAILED.


then add ITK_USE_FFTWD_DEFAULT ON, ITK_USE_FFTWF_DEFAULT ON, ITK_USE_SYSTEM_FFTW_DEFAULT ON build success.
with ITK_WRAP_PYTHON ON still got errors.
branch master [commit](https://github.com/InsightSoftwareConsortium/ITK/commit/935533fbcbb451f32038c4643843a0bc606123ca)
dzenanz commented 1 year ago

MKL and cuFFT impersonate FFTW, so ITK_USE_FFTWD_DEFAULT ON, ITK_USE_FFTWF_DEFAULT ON, ITK_USE_SYSTEM_FFTW_DEFAULT ON are needed as a side-effect of build-system simplification.

I don't remember whether Python is supposed to work with cuFFTW, or even just any GPU filters. @tbirdso and/or @thewtex might know.

tbirdso commented 1 year ago

@dzenanz yes, FFTW should work with Python. This does sound like a bug.

tbirdso commented 1 year ago

Interestingly, in attempting to reproduce with ITK_USE_SYSTEM_FFTW=ON and ITK_USE_GPU=ON on Linux I was able to build successfully but importing ITKFFT fails:

>>> import itk
>>> itk.auto_progress(2)
>>> itk.FFTWForwardFFTImageFilter
Loading ITKPyBase... done
Loading ITKCommon... done
Loading ITKStatistics... done
Loading ITKImageFilterBase... done
Loading ITKTransform... done
Loading ITKImageFunction... done
Loading ITKImageGrid... done
Loading ITKFFT... Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tom/builds/ITK-base-dev/Wrapping/Generators/Python/itk/support/lazy.py", line 138, in __getattribute__
    base.itk_load_swig_module(module, namespace)
  File "/home/tom/builds/ITK-base-dev/Wrapping/Generators/Python/itk/support/base.py", line 132, in itk_load_swig_module
    l_module = loader.load(swig_module_name)
  File "/home/tom/builds/ITK-base-dev/Wrapping/Generators/Python/itk/support/base.py", line 291, in load
    l_spec.loader.exec_module(l_module)  # pytype: disable=attribute-error
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/tom/builds/ITK-base-dev/Wrapping/Generators/Python/itk/support/../ITKFFTPython.py", line 13, in <module>
    from . import _ITKFFTPython
ImportError: /home/tom/builds/ITK-base-dev/Wrapping/Generators/Python/itk/_ITKFFTPython.so: undefined symbol: _ZTIN3itk29FFTWFFTImageFilterInitFactoryE
zhusihan-python commented 1 year ago

update with ITK_WRAP_PYTHON ON, ITK_USE_GPU ON, ITK_USE_CUFFTW ON, ITK_USE_FFTWD_DEFAULT ON, ITK_USE_FFTWF_DEFAULT ON, ITK_USE_SYSTEM_FFTW_DEFAULT ON compile tag v5.2.1 success on windows 10 then build itk montage and montage examples success

tbirdso commented 1 year ago

@dzenanz should this be kept open? My understanding is the build passed for v5.2.1 but failed for v5.3.0.

dzenanz commented 1 year ago

@zhusihan-python can reopen if the issue was not fixed, and further clarify the problem if it is something other than "build passed for v5.2.1 but failed for v5.3.0".

tbirdso commented 1 year ago

Re-opening this issue, @zhusihan-python has confirmed in https://github.com/InsightSoftwareConsortium/ITKVkFFTBackend/issues/64 that the issue persists in ITK v5.3.0. Platform and build environment details are available in https://github.com/InsightSoftwareConsortium/ITKVkFFTBackend/issues/64.