close
Skip to content

GPU gibbs priors refactoring#1629

Merged
KrisThielemans merged 81 commits intoUCL:masterfrom
ColomboMatte0:GPU_gibbs_priors
Oct 27, 2025
Merged

GPU gibbs priors refactoring#1629
KrisThielemans merged 81 commits intoUCL:masterfrom
ColomboMatte0:GPU_gibbs_priors

Conversation

@ColomboMatte0
Copy link
Copy Markdown
Contributor

Main changes:

See presentation:
[https://www.ccpsynerbi.ac.uk/wp-content/uploads/2025/09/GibbsPrior_presentation.pdf]

GibbsPrior.pptx

##Minor changes

  • added SWIG bindings for the original version CudaRelativedifferencePrior
  • moved GeneralizedPrior.cxx into GeneralizedPrior.inl
  • modified src/utilities/stir_timings.cxx to include timings with the new priors (i' ve created also a python notebook used to generate the results of the presentation not included in this pull request, let me know if i should add it (where?) )

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have added docstrings/doxygen in line with the guidance in the developer guide
  • I have implemented unit tests that cover any new or modified functionality (if applicable)
  • The code builds and runs on my machine
  • [] documentation/release_XXX.md has been updated with any functionality change (if applicable)

Please tick the following:

  • [ x] The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in STIR (the Work) under the terms and conditions of the Apache-2.0 License.
  • [ x] I (or my institution) have signed the STIR Contribution License Agreement (not required for small changes).

root and others added 21 commits July 25, 2025 12:05
- Delete generated CMake and Makefile files
- Remove build configuration files
- Clean up repository for pull request
…ginal

- Remove generated CMake and Makefile build artifacts
- Revert QuadraticPrior.cxx to upstream version (removed experimental changes)
- Revert QuadraticPrior.h to upstream version
- Revert RelativeDifferencePrior.h to upstream version
- Revert CudaRelativeDifferencePrior.cu to upstream version
- Revert RelativeDifferencePrior.cxx to upstream version
- Remove VS Code workspace file from version control

Only keeping new CUDA Gibbs prior implementation files
…tions

- Add GibbsRelativeDifferencePrior to recon_buildblock registries
- Remove duplicate QuadraticPotential template instantiation
- Ensure proper class registration for Python bindings
- Add STIR_WITH_CUDA flag to CMake SWIG flags for proper conditional compilation
- Reorganize stir_priors.i to use #ifdef guards for CUDA-specific declarations
- Move CUDA shared_ptr declarations and template instantiations inside conditional blocks
- Revert utilities/CMakeLists.txt to original (remove test utilities)
- Remove personal test file stir_prior_timings.cxx from version control
- Clean up template instantiation order and remove duplicate declarations

This ensures CUDA priors are only compiled when CUDA support is available,
improving build compatibility across different environments.
Removed CUDA Toolkit dependency from CMake configuration.
Comment thread src/include/stir/cuda_utilities.cuh Outdated
Comment thread src/utilities/stir_timings.cxx Outdated
Comment thread src/include/stir/recon_buildblock/GibbsRelativeDifferencePrior.h Outdated
ColomboMatte0 and others added 2 commits October 9, 2025 12:57
Co-authored-by: Kris Thielemans <KrisThielemans@users.noreply.github.com>
… profiling headers from CudaGibbsPrior.cuh
Comment thread src/CMakeLists.txt Outdated
Comment thread src/include/stir/cuda_utilities.cuh Outdated
Comment thread src/include/stir/cuda_utilities.h
Comment thread src/include/stir/recon_buildblock/CUDA/CudaGibbsPrior.cuh Outdated
Comment thread src/include/stir/recon_buildblock/CUDA/CudaGibbsPrior.cuh Outdated
Comment thread src/include/stir/recon_buildblock/GibbsRelativeDifferencePrior.h Outdated
Comment thread src/include/stir/recon_buildblock/GibbsRelativeDifferencePrior.h
Comment thread src/include/stir/recon_buildblock/GibbsPenalty.h
Comment thread src/recon_buildblock/GeneralisedPrior.cxx
Comment thread src/recon_buildblock/recon_buildblock_registries.cxx Outdated
@KrisThielemans
Copy link
Copy Markdown
Collaborator

Appveyor errors with

C:\projects\stir\src\include\stir\recon_buildblock\CUDA\CudaGibbsPrior.h(25,10): error C1083: Cannot open include file: 'cuda_runtime.h': No such file or directory [C:\projects\stir\build\src\swig\_stir.vcxproj]
  (compiling source file 'CMakeFiles/_stir.dir/stirPYTHON_wrap.cxx')
  
Command exited with code 1

so still something wrong with STIR_WITH_CUDA guards or something

Comment thread src/include/stir/recon_buildblock/CUDA/CudaGibbsPenalty.cuh
Comment thread src/include/stir/recon_buildblock/CUDA/CudaGibbsPenalty.cuh
Comment thread src/include/stir/recon_buildblock/CUDA/CudaGibbsPenalty.cuh
Comment thread src/include/stir/recon_buildblock/CUDA/CudaGibbsPenalty.cuh
@KrisThielemans
Copy link
Copy Markdown
Collaborator

@casperdcl can you help with the following? @ColomboMatte0 commited sometimes as root@DESKTOP-U7AVDMQ.
This doesn't feel good, and would likely create difficult with our mailmap. What is the best way to correct this? It'd be nice to preserve history in this PR, but we're going to squash-merge this. First commit was by the root user, so I guess it will the squash-merge will be assigned to root.

I suppose I could do the squash locally, correct the author, then push that to master, then close this PR. Not so great, as github will claim it wasn't merged.

@ColomboMatte0
Copy link
Copy Markdown
Contributor Author

i guess there are some instantiation problem for the cpu classes now? amazing!

@casperdcl
Copy link
Copy Markdown
Collaborator

You should be able to squash-merge from the UI, and the author will be @ColomboMatte0 as the person who opened the PR - just tidy the squash commit message (remove the "coauthored by root" line at the bottom).

@KrisThielemans
Copy link
Copy Markdown
Collaborator

i guess there are some instantiation problem for the cpu classes now? amazing!

no, this isn't instantiation.

In file included from /home/runner/work/STIR/STIR/build/src/swig/CMakeFiles/_stir.dir/stirPYTHON_wrap.cxx:4635:
/home/runner/work/STIR/STIR/src/include/stir/recon_buildblock/GibbsQuadraticPenalty.h:124:9: error: no matching constructor for initialization of 'RegisteredParsingObject<GibbsQuadraticPenalty<float>, GeneralisedPrior<DiscretisedDensity<3, float>>, GibbsPenalty<float, QuadraticPotential<float>>>'
  124 |       : base_type(only_2D, penalisation_factor)
      |         ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/STIR/STIR/build/src/swig/CMakeFiles/_stir.dir/stirPYTHON_wrap.cxx:168950:60: note: in instantiation of member function 'stir::GibbsQuadraticPenalty<float>::GibbsQuadraticPenalty' requested here
 168950 |       result = (stir::GibbsQuadraticPenalty< float > *)new stir::GibbsQuadraticPenalty< float >(arg1,arg2);
        |                                                            ^
/home/runner/work/STIR/STIR/src/include/stir/RegisteredParsingObject.h:77:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
   77 | class RegisteredParsingObject : public Parent
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/home/runner/work/STIR/STIR/src/include/stir/RegisteredParsingObject.h:77:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
   77 | class RegisteredParsingObject : public Parent
      |       ^~~~~~~~~~~~~~~~~~~~~~~

The problem is that RegisteredParsingObject<GibbsPenalty,...> doesn't have the constructors of GibbsPenalty. This is likely related to

// import constructors from Parent
// Note: disabled for older SWIG as that generates an error before 4.2, and a warning for 4.2
#if !defined(SWIG) || (SWIG_VERSION >= 0x040300)
using Parent::Parent;
#endif

I don't know why this only appears now though.

@KrisThielemans
Copy link
Copy Markdown
Collaborator

Ubuntu jobs fail, and are running SWIG 4.2.0. MacOS and AppVeyor jobs are fine, and are running SWIG 4.4.0.

@KrisThielemans
Copy link
Copy Markdown
Collaborator

I don't know why this only appears now though.

Looks like we might not have run the Actions workflow recentl (as I need to approve it)

@ColomboMatte0
Copy link
Copy Markdown
Contributor Author

ColomboMatte0 commented Oct 26, 2025

Ubuntu jobs fail, and are running SWIG 4.2.0. MacOS and AppVeyor jobs are fine, and are running SWIG 4.4.0.

I guess it's related to having removed the .cxx and .cu. The constructors were working fine back there.

@KrisThielemans
Copy link
Copy Markdown
Collaborator

The problem is the "overloading" of the SWIG preprocessor definition in STIR, see #1646.

@KrisThielemans
Copy link
Copy Markdown
Collaborator

KrisThielemans commented Oct 26, 2025

The SWIG preprocessor thing is a bit horrible. As a test, I think replacing SWIG with IGNORESWIG in RegisteredParsingObject.h

#if !defined(SWIG) || (SWIG_VERSION >= 0x040300)
  using Parent::Parent;
#endif

might work, but I need to find something better

@KrisThielemans
Copy link
Copy Markdown
Collaborator

Ubuntu jobs fail, and are running SWIG 4.2.0. MacOS and AppVeyor jobs are fine, and are running SWIG 4.4.0.

I guess it's related to having removed the .cxx and .cu. The constructors were working fine back there.

yes, before the definition of the constructor was in the .cxx and .cu, which meant that the wrapper just linked to it. Now it's in the .h, which means that they also need to be compiled when compiling the wrapper .

In any case, having a class definition that changes depending on preprocessor options seems like a recipe for disaster. The only place where it should be safe is for the typedef problem mentioned in #1646

@ColomboMatte0
Copy link
Copy Markdown
Contributor Author

The test you suggestet is working, but now i get another error on the MacOS job on recon_testpack related to SRT2D, which i think belong to another PR.Have i done something wrong?

@KrisThielemans
Copy link
Copy Markdown
Collaborator

KrisThielemans commented Oct 26, 2025

MacOS clang 21 failure due to #1420, all the rest got through! So no, you didn't do anything wrong :-)

@KrisThielemans
Copy link
Copy Markdown
Collaborator

@ColomboMatte0 I've created #1647. Let's see...

No longer use `#ifdef SWIG` to change the class definition when compiling
the wrapper, but introduce a new preprocessor symbol
STIR_COMPILING_SWIG_WRAPPER.

This should be used with care! (currently only for
typedef etc).
now that we no longer compile the SWIG-generated wrapper with -DSWIG,
go back to original version
@KrisThielemans
Copy link
Copy Markdown
Collaborator

I've merged #1647 and updated this PR accordingly. Fingers crossed.

@ColomboMatte0
Copy link
Copy Markdown
Contributor Author

I've merged #1647 and updated this PR accordingly. Fingers crossed.

Everything worked right?

@KrisThielemans KrisThielemans added this to the v6.3 milestone Oct 27, 2025
@KrisThielemans KrisThielemans merged commit f2e1ca3 into UCL:master Oct 27, 2025
@KrisThielemans
Copy link
Copy Markdown
Collaborator

celebration time!

@ColomboMatte0 ColomboMatte0 deleted the GPU_gibbs_priors branch October 28, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants