Single precision computations and rudimentary GPU support#895
Conversation
…izedRayTracing
…to feature/single_precision_dosecalc # Conflicts: # matRad/rayTracing/matRad_rayTracing.m
…atives) for fmincon
# Conflicts: # matRad/gui/widgets/matRad_ViewingWidget.m
# Conflicts: # matRad/MatRad_Config.m # matRad/optimization/optimizer/matRad_OptimizerIPOPT.m # matRad/util/matRad_interp1.m # matRad_calcDoseInit.m # matRad_generateStf.m
# Conflicts: # matRad/rayTracing/matRad_rayTracing.m
# Conflicts: # examples/matRad_example3_photonsDAO.m
…arrays and single precision
There was a problem hiding this comment.
Pull request overview
This PR propagates single-precision computations through core dose-calculation workflows, introduces initial GPU data movement helpers, and refactors ray tracing into a new vectorized Siddon-based class to enable future acceleration.
Changes:
- Added precision handling (default
'single') across dose engines and related utilities. - Introduced experimental GPU support via
MatRad_Config.enableGPUplus GPU move/gather helpers. - Refactored ray tracing to use new
matRad_RayTracer/matRad_RayTracerSiddonclasses and deprecated legacy ray-tracing functions.
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| test/util/test_interp1.m | Adds a test for multi-dataset interpolation behavior. |
| test/optimizers/test_optimizerIPOPT.m | Updates tests to new optimizer method names (isAvailable, getStatus). |
| test/optimizers/test_optimizerFmincon.m | Updates tests to new optimizer method names and formatting. |
| submodules/ompMC | Updates the ompMC submodule pointer. |
| matRad/util/octaveCompat/matRad_underlyingTypeCompat.m | Adds Octave-compatible helper for determining underlying numeric type. |
| matRad/util/matRad_interp1.m | Extends interpolation helper for mixed precision and GPU inputs. |
| matRad/steering/matRad_StfGeneratorParticleSingleBeamlet.m | Switches steering ray tracing to the new Siddon tracer class. |
| matRad/steering/matRad_StfGeneratorParticleRayBixelAbstract.m | Stores a ray tracer instance and initializes it during patient-geometry creation. |
| matRad/steering/matRad_StfGeneratorParticleIMPT.m | Uses the new ray tracer for per-scenario ray traces. |
| matRad/steering/matRad_StfGeneratorBase.m | Adds optional GPU movement of CT/CST during STF generation. |
| matRad/rayTracing/matRad_siddonRayTracer.m | Deprecates old Siddon function and forwards to new tracer class. |
| matRad/rayTracing/matRad_rayTracing.m | Deprecates old ray tracing and forwards to new tracer class. |
| matRad/rayTracing/matRad_RayTracerSiddon.m | Adds new vectorized Siddon ray tracer implementation. |
| matRad/rayTracing/matRad_RayTracer.m | Adds new base ray tracing infrastructure (candidate ray matrix + traceCube). |
| matRad/plotting/matRad_plotVoiContourSlice.m | Casts inputs for contourc to double to support non-double cubes. |
| matRad/plotting/matRad_plotPlan3D.m | Casts inputs for contourc to double to support non-double matrices. |
| matRad/plotting/matRad_plotIsoDoseLines.m | Casts inputs for contourc to double to support single precision cubes. |
| matRad/plotting/matRad_computeVoiContours.m | Casts inputs for contourc to double to support non-double masks. |
| matRad/optimization/optimizer/matRad_OptimizerSimulannealbnd.m | Renames API to isAvailable/getStatus and formatting cleanup. |
| matRad/optimization/optimizer/matRad_OptimizerIPOPT.m | Renames API, adds gather wrappers for GPU flows, and improves plotting robustness. |
| matRad/optimization/optimizer/matRad_OptimizerFmincon.m | Renames API and improves option setup / wrappers. |
| matRad/optimization/optimizer/matRad_Optimizer.m | Updates base optimizer API to isAvailable/getStatus. |
| matRad/matRad_fluenceOptimization.m | Moves cst/dij to GPU when configured and updates optimizer availability checks. |
| matRad/gui/widgets/matRad_WorkflowWidget.m | Updates GUI status call to getStatus(). |
| matRad/gui/widgets/matRad_ViewingWidget.m | Replaces legacy Siddon calls with new tracer usage in plotting path. |
| matRad/gpu/matRad_moveDijToGPU.m | Adds helper to move selected dij quantities to GPU (optionally casting). |
| matRad/gpu/matRad_moveCtToGPU.m | Adds helper to move CT cubes to GPU (optionally casting). |
| matRad/gpu/matRad_moveCstToGPU.m | Adds helper to move CST voxel-index lists to GPU (optionally casting). |
| matRad/gpu/matRad_getDijFromGPU.m | Adds helper to gather dij quantities back from GPU (optionally casting). |
| matRad/gpu/matRad_getCtFromGPU.m | Adds helper to gather CT cubes back from GPU (optionally casting). |
| matRad/gpu/matRad_getCstFromGPU.m | Adds helper to gather CST back from GPU (optionally casting). |
| matRad/geometry/matRad_cubeIndex2worldCoords.m | Forces numeric arithmetic to double to reduce class/precision pitfalls. |
| matRad/doseCalc/matRad_computeSSD.m | Switches SSD computation to use the new Siddon tracer. |
| matRad/doseCalc/+DoseEngines/matRad_PhotonPencilBeamSVDEngine.m | Propagates precision into key intermediate allocations. |
| matRad/doseCalc/+DoseEngines/matRad_PencilBeamEngineAbstract.m | Adds GPU movements, precision casts, and uses new tracer for ray tracing. |
| matRad/doseCalc/+DoseEngines/@matRad_DoseEngineBase/matRad_DoseEngineBase.m | Adds precision property and sparse-single capability check helper. |
| matRad/doseCalc/+DoseEngines/@matRad_DoseEngineBase/initDoseCalc.m | Casts computed world coordinates to engine precision. |
| matRad/MatRad_Config.m | Adds experimental enableGPU flag. |
| examples/matRad_example15_brachy.m | Formatting/typo fixes and updated availability API usage in example. |
Comments suppressed due to low confidence (3)
matRad/util/matRad_interp1.m:1
- Casting against
class(x)/class(xi)will fail for GPU inputs becauseclass(gpuArray)is'gpuArray', which is not a numeric class forcast. Use the underlying numeric type (e.g., viamatRad_underlyingTypeCompatorclassUnderlying) and then move to GPU, or use'like'semantics. Also,isgpuarrayis MATLAB-specific and will error in Octave unless guarded (e.g.,exist('isgpuarray','file')).
matRad/util/matRad_interp1.m:1 - Casting against
class(x)/class(xi)will fail for GPU inputs becauseclass(gpuArray)is'gpuArray', which is not a numeric class forcast. Use the underlying numeric type (e.g., viamatRad_underlyingTypeCompatorclassUnderlying) and then move to GPU, or use'like'semantics. Also,isgpuarrayis MATLAB-specific and will error in Octave unless guarded (e.g.,exist('isgpuarray','file')).
test/util/test_interp1.m:1 - This test name indicates a single-precision path but the inputs are created as doubles. Also,
all(...,'all')is not supported in older MATLAB versions and is not supported in many Octave versions; it can make the test suite fail in those environments. Consider explicitly creatingsingleinputs and using a compatibility-safe reduction (e.g., nestedall(all(...)))or linearizing with(:)depending on test conventions in this repo.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #895 +/- ##
==========================================
- Coverage 54.94% 54.86% -0.08%
==========================================
Files 310 320 +10
Lines 20303 20514 +211
==========================================
+ Hits 11155 11255 +100
- Misses 9148 9259 +111 ☔ View full report in Codecov by Sentry. |
Test Results 3 files ±0 3 suites ±0 32m 17s ⏱️ - 10m 58s Results for commit d185f63. ± Comparison against base commit 6117a65. This pull request removes 7 and adds 10 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
…w loop raytracing
…ith linear indexing
…nput type on linux in octave
…set to true. Also reset it to false by default.
Since Matlab R2025 sparse matrices can have single precision value storage.
This PR enables this throughout all basic computations and adds rudimentary GPU support. This can benefit optimization quite substantially. Dose calculation is, however, to fragmented to be accelerated, apart from RayTracing. To enable sensible acceleration, RayTracing is now performed in a vectorized manner (similarly to our implementation in pyRadPlan.
CoPilot Summary:
This pull request introduces significant improvements to the matRad dose calculation engines, focusing on enhanced floating-point precision handling, initial GPU support, and improved code consistency. The most important changes are grouped below by theme.
Precision Handling and Consistency:
precisionproperty (default'single') tomatRad_DoseEngineBaseand propagated its use throughout the dose calculation pipeline, including casting arrays and matrices to the specified precision inmatRad_PencilBeamEngineAbstractandmatRad_PhotonPencilBeamSVDEngine. This ensures consistent floating-point operations and enables future support for mixed-precision or GPU computing. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]allowsSinglePrecisionSparseDij. [1] [2] [3]GPU Support:
enableGPUflag inMatRad_Config, and added logic inmatRad_PencilBeamEngineAbstractto move CT and CST data to GPU when enabled. [1] [2]matRad_getCstFromGPUto gather CST data from the GPU and cast it to the desired precision.Ray Tracing Refactor:
matRad_RayTracerSiddonobject, storing it as a property and using its methods for radiological depth calculations and SSD computation, improving modularity and code reuse. [1] [2] [3]Minor Fixes and Documentation:
matRad_example15_brachy.m, and corrected a method call to use the proper case forisAvailable. [1] [2] [3]These changes collectively modernize the matRad codebase, laying the groundwork for improved performance, precision, and hardware acceleration.