Code Monkey home page Code Monkey logo

cuda_digitallyreconstructedradiographs's Introduction

GPU accelerated generation of digitally reconstructed radiographs (DRR)

Brief Description

The repository generates a Python library (SiddonGpuPy.pyd) for generating DRRs from a CT/MRI scan with parallelization on the GPU using CUDA (Invidia). The algorithm is based on the method proposed by Siddon ("Fast calculation of the exact radiological path for a three-dimensional CT array.", 1985 Med. Phys.) and on the improvements proposed by Greef et al. ("Accelerated ray tracing for radiotherapy dose calculations on a GPU.", 2009 Med. Phys.). The original library written in C-C++ and parallelized using the CUDA toolkit (https://developer.nvidia.com/cuda-zone) is wrapped to a Python library using Cython.

A description of the parallelized algorithm for DRR generation can be found in the 5th Chapter of my PhD thesis (Chapter5_HipHop_2D3Dregistration.pdf).

The Python library SiddonGpuPy.pyd is used in the HipHop_2D3Dregistration framework (see repository https://github.com/fabio86d/HipHop_2D3Dregistration.git) for 2D/3D registration between volumetric medical images (CT/MRI scan) and X-ray images.

This repository also shows the process of generating a C++ library and wrapping it to a Python library using Cython.

Procedure to generate Cpp library

  1. Use Cmake to generate a Visual Studio project that builds the Cpp static library (SiddonGpu.lib)

The source folder for Cmake is SiddonClassLib\src, and includes a Cmake file (CMakeLists.txt), a header cuda file (.cuh) and a source cuda file (.cu) of the siddon_class. The folder where to build the binaries is SiddonClassLib\bin.

  1. Open the created Visual Studio project and BUILD ALL in Release mode. The SiddonGpu.lib file will be generated in the Release folder.

Procedure to wrap a Cpp library to a Python library using Cython.

The SiddonPythonModule folder includes:

  • include/siddon_class.cuh (header cuda file with which SiddonGpu.lib was built)
  • lib/SiddonGpu.lib (library generated with Cmake and Visual Studio, see above)
  • a setup.py file (the python script that needs to be run)
  • a SiddonGpuPy.pyx (it represents the interface between the Cpp class and the Python class)

In order to wrap the SiddonGpu.lib library to a Python library (SiddonGpuPy.pyd): from the SiddonPythonModule directory, just run "python setup.py build_ext --inplace"

Use of the package

In the HipHop_2D3Dregistration framework (https://github.com/fabio86d/HipHop_2D3Dregistration.git) the SiddonGpuPy is imported in the ProjectorsModule and used to fast generate DRR from a CT scan of the pelvis.

cuda_digitallyreconstructedradiographs's People

Contributors

fabio86d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cuda_digitallyreconstructedradiographs's Issues

error LNK2038:

when I rebuild the SiddonGpuPy.cp36-win_amd64.pyd, error occurred as follow:

SiddonGpu.lib(SiddonGpu_generated_siddon_class.cu.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MT_StaticRelease”(SiddonGpuPy.obj 中)
正在创建库 build\temp.win-amd64-3.6\Release\SiddonGpuPy.cp36-win_amd64.lib 和对象 build\temp.win-amd64-3.6\Release\SiddonGpuPy.cp36-win_amd64.exp
LINK : warning LNK4098: 默认库“MSVCRT”与其他库的使用冲突;请使用 /NODEFAULTLIB:library
G:\17 Files\CUDA_DigitallyReconstructedRadiographs-master\SiddonPythonModule\SiddonGpuPy.cp36-win_amd64.pyd : fatal error LNK1319: 检测到 1 个不匹配项
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\bin\HostX86\x64\link.exe' failed with exit status 1319

Static release ?

Hi,
I got an issue when I try to rebuild the python package with this command :

python setup.py build_ext --inplace

Here is the logs I got

running build_ext
skipping 'SiddonGpuPy.cpp' Cython extension (up-to-date)
building 'SiddonGpuPy' extension
D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -IC:\RoboDK\Python37\lib\site-packages\numpy\core\include -IC:\Users\Thomas\Documents\CUDA_DigitallyReconstructedRadiographs\SiddonPythonModule\includeD:\CUDA\include -IC:\RoboDK\Python37\include -IC:\RoboDK\Python37\include "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\ATLMFC\include" "-ID:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /EHsc /TpSiddonGpuPy.cpp /Fobuild\temp.win-amd64-3.7\Release\SiddonGpuPy.obj
SiddonGpuPy.cpp
C:\RoboDK\Python37\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /nodefaultlib:libucrt.lib ucrt.lib /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\Thomas\Documents\CUDA_DigitallyReconstructedRadiographs\SiddonClassLib\build\Release /LIBPATH:D:\CUDA\lib\x64 /LIBPATH:C:\RoboDK\Python37\libs /LIBPATH:C:\RoboDK\Python37\PCbuild\amd64 "/LIBPATH:D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\ATLMFC\lib\x64" "/LIBPATH:D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.19041.0\\um\x64" SiddonGpu.lib cudart_static.lib /EXPORT:PyInit_SiddonGpuPy build\temp.win-amd64-3.7\Release\SiddonGpuPy.obj /OUT:C:\Users\Thomas\Documents\CUDA_DigitallyReconstructedRadiographs\SiddonPythonModule\SiddonGpuPy.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\SiddonGpuPy.cp37-win_amd64.lib
SiddonGpu.lib(SiddonGpu_generated_siddon_class.cu.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in SiddonGpuPy.obj
   Creating library build\temp.win-amd64-3.7\Release\SiddonGpuPy.cp37-win_amd64.lib and object build\temp.win-amd64-3.7\Release\SiddonGpuPy.cp37-win_amd64.exp
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
C:\Users\Thomas\Documents\CUDA_DigitallyReconstructedRadiographs\SiddonPythonModule\SiddonGpuPy.cp37-win_amd64.pyd : fatal error LNK1319: 1 mismatches detected
error: command 'D:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX86\\x64\\link.exe' failed with exit status 1319

Do I need to change the compilation options of the VS project ? Is it really a LIB required for the python package ?
Sorry I'm kind of beginner in Cython.

Regards,
Thomas.

Cuda input issue

Hi... I am a beginner. I gave the inputs as specified. But I am getting the DRR output as zero. Can you please tell me about the various arguments in class object and generatedRR function and how the input looks like?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.