generate rtk wheels

In order to reduce the loading time if RTK, I first generate itk wheels by ITKPythonPackage with "-DITK_WRAP_IMAGE_DIMS:STRING=2;3". And then pip install itk-rtk-cuda, but that method will cause the error, so I think I need generate rtk wheels like itk.
I set "-DModule_RTK:BOOL=ON", and -DRTK_USE_CUDA:BOOL=ON", on the windows-build-wheels.py like below:

check_call([
            "cmake",
            "-DCMAKE_MAKE_PROGRAM:FILEPATH=%s" % ninja_executable,
            "-DCMAKE_BUILD_TYPE:STRING=%s" % build_type,
            "-DITK_SOURCE_DIR:PATH=%s" % source_path,
            "-DITK_BINARY_DIR:PATH=%s" % build_path,
            "-DBUILD_TESTING:BOOL=OFF",
            "-DSKBUILD:BOOL=ON",
            "-DPython3_EXECUTABLE:FILEPATH=%s" % python_executable,
            "-DITK_WRAP_unsigned_short:BOOL=ON",
            "-DITK_WRAP_unsigned_char:BOOL=ON",
            "-DITK_WRAP_float:BOOL=ON",
            "-DITK_WRAP_IMAGE_DIMS:STRING=2;3",
            "-DPython3_INCLUDE_DIR:PATH=%s" % python_include_dir,
            "-DPython3_INCLUDE_DIRS:PATH=%s" % python_include_dir,
            "-DPython3_LIBRARY:FILEPATH=%s" % python_library,
            "-DPython3_SABI_LIBRARY:FILEPATH=%s" % python_library,
            "-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel",
            "-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=ON",
            "-DPY_SITE_PACKAGES_PATH:PATH=.",
            "-DITK_LEGACY_SILENT:BOOL=ON",
            "-DITK_WRAP_PYTHON:BOOL=ON",
            "-DITK_WRAP_DOC:BOOL=ON",
            "-DDOXYGEN_EXECUTABLE:FILEPATH=C:/P/doxygen/doxygen.exe",
            "-DModule_ITKTBB:BOOL=ON",
            "-DTBB_DIR:PATH=%s" % tbb_dir,
            "-DModule_RTK:BOOL=ON",
            "-DRTK_USE_CUDA:BOOL=ON",
            "-G", "Ninja",
            source_path
        ])

But I have been unable to successfully generate it. I want to know if this approach is correct? How should I generate it if it is not correct?

@simon.rit might provide pointers.

I think you need to follow the CI which generates the wheels. You can check the current version

I am working on a migration to pyproject.toml for Python 3.12 compatibility.

Thak you very much for your reply. I’ll try it. But I have a question: do I need set "-DITK_WRAP_IMAGE_DIMS:STRING=2;3"? If I need , where to modify it?

I’m not sure, I have never done that. It seems to me that instead of using the distributed ITKPythonBuilds-windows.zip file here, you should simply use your local ITK build.

ITK_WRAP_IMAGE_DIMS is a setting in ITK’s CMake configuration, and it needs to be applied in the ITK build which is used.

Actually I confused now. :joy:
I first generate itk wheels with "-DITK_WRAP_IMAGE_DIMS:STRING=2;3" like below:
企业微信截图_20240606135109
And then use pip install itk-rtk-cuda116 from Pypi to use RTK like itk.RTK.ThreeDCircularProjectionGeometry.New(). But there will occur error like this:


I think the problem may that the pypi IMAGE_DIMS:STRING=2;3;4, which is conflict with itk. So I need to generate a rtk wheels can set same configuration as I generate itk.
As @simon.rit advise, I generate itkcudacommon wheels by default.
image
I didn’t find where to set the configuration, I install this whl on my python environment, the error still exists. It seem like there is no difference between the Whl generated by myself and the one I installed from Pypi.

As far as my understanding of ITKPythonPackage goes, it downloads an existing ITK build (from here) and compile the module on top of it. You need to do the same but use your ITK build to have the correct set of options.

1 Like

Thank you for your prompt reply. Is the website wrong? I only have these things inside when I open it.


As I generate is like below.
image

No, the builds are distributed as assets of the releases, see e.g. the latest here.

I replace ITKPythonBuild by my generate code. At fist I can successful generate ITKCudaCommon wheels, but late I failed. With the same code, there occur the error like below:

& "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 -SkipAutomaticLocation
$env:CC="cl.exe"
$env:CXX="cl.exe"
$env:ITK_PACKAGE_VERSION = 'v5.4.0'
$env:ITKPYTHONPACKAGE_TAG = 'v5.4.0'
$env:ITKPYTHONPACKAGE_ORG = 'InsightSoftwareConsortium'
$env:ITK_MODULE_PREQ = "RTKConsortium/ITKCudaCommon@c7c766a6b944124da21131c6eb689ee75e61bd6e"
$CUDA_VERSION =  "116"
$CUDA_VERSION_MAJOR=$CUDA_VERSION.substring(0,2)
$CUDA_VERSION_MINOR=$CUDA_VERSION.substring(2,$CUDA_VERSION.Length-2)
$env:CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}"
$env:Path = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin;" + $env:Path
$LIBCUDART= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cudart64*dll" ).Name
$LIBCUBLAS= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cublas64*dll" ).Name
$LIBCUBLASLT= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cublasLt64*dll" ).Name
$LIBCUFFT= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cufft64*dll" ).Name
./windows-download-cache-and-build-module-wheels.ps1 "9" -setup_options "--lib-paths ""C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}/bin"" --exclude-libs ""nvcuda.dll;concrt140.dll;${LIBCUDART};${LIBCUBLAS};${LIBCUBLASLT};${LIBCUFFT}""" -cmake_options "-DRTK_USE_CUDA:BOOL=ON"

Good news, I rebuilt ITK and I can successfully generate ITKCudaCommon wheels. But on the next step, an error occurred during the final step of generating RTK with cmake-options: '-DRTK_BUILD_APPLICATIONS:BOOL=OFF'.

Although a wheel was generated, running rtk will result in an error( I use windows and have set os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin'))).


Any help will be appreciate!

@simon.rit Can you give me some advice? Thank you very much.

I wish I could but I don’t see what is the issue. I guess you have to find out which DLL is missing for _RTKPython.dll. Maybe you can try to find out with Dependency Walker?

There is the probelm. In the final step of generating the wheel, a dependency needs to be added, but an error RuntimeError: itk\_RTKPython.pyd has a CPU architecture that is not compatible with this wheel is reported. This resulted in me not having the itk_rtk.libs folder when I finally installed the wheels for RTK.
This dependency can successfully add to ITKCudaCommon wheels.