Skip to content

Commit

Permalink
Use float gam instead of double in CudaOptimiser
Browse files Browse the repository at this point in the history
Even though tests show otherwise, using float gets better results in real world scenarios.
  • Loading branch information
onurulgen committed Nov 27, 2023
1 parent 25aba87 commit b9c9bec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion niftyreg_build_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371
372
6 changes: 3 additions & 3 deletions reg-lib/cuda/CudaOptimiser.cu
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void GetConjugateGradient(float4 *gradientCuda,
return make_double2(dgg, gg);
};

double gam;
float gam;
thrust::counting_iterator<int> it(0);
const double2 gg = thrust::transform_reduce(thrust::device, it, it + nVoxels, [=]__device__(const int index) {
return calcGam(gradientTexture, conjugateGTexture, conjugateHTexture, index);
Expand All @@ -247,8 +247,8 @@ void GetConjugateGradient(float4 *gradientCuda,
const double2 ggBw = thrust::transform_reduce(thrust::device, it, it + nVoxelsBw, [=]__device__(const int index) {
return calcGam(gradientBwTexture, conjugateGBwTexture, conjugateHBwTexture, index);
}, make_double2(0, 0), thrust::plus<double2>());
gam = (gg.x + ggBw.x) / (gg.y + ggBw.y);
} else gam = gg.x / gg.y;
gam = static_cast<float>((gg.x + ggBw.x) / (gg.y + ggBw.y));
} else gam = static_cast<float>(gg.x / gg.y);

// Conjugate gradient
auto conjugate = [gam]__device__(float4 *gradientCuda, float4 *conjugateGCuda, float4 *conjugateHCuda,
Expand Down

0 comments on commit b9c9bec

Please # to comment.