From 7bd9e9a543c085e452719d725e42b44cc21f6669 Mon Sep 17 00:00:00 2001 From: ytl0623 Date: Fri, 16 Jan 2026 16:33:30 +0800 Subject: [PATCH 1/3] Clean unused constructors in pushpull C++/CUDA implementation Signed-off-by: ytl0623 --- monai/csrc/resample/pushpull_cpu.cpp | 70 ++++++++++++++-------------- monai/csrc/resample/pushpull_cuda.cu | 70 ++++++++++++++-------------- 2 files changed, 72 insertions(+), 68 deletions(-) diff --git a/monai/csrc/resample/pushpull_cpu.cpp b/monai/csrc/resample/pushpull_cpu.cpp index c638958a47..adca3e9df9 100644 --- a/monai/csrc/resample/pushpull_cpu.cpp +++ b/monai/csrc/resample/pushpull_cpu.cpp @@ -35,7 +35,7 @@ limitations under the License. // . [DONE] spatial gradient mode (without multiplication with output gradient) // . [DONE] second order gradients (backward pass for spatial gradients) // . performance tests -// . input bound/inter are always vectors -> clean unused constructors +// . [DONE] input bound/inter are always vectors -> clean unused constructors #include #include @@ -2187,39 +2187,42 @@ MONAI_NAMESPACE_DEVICE { // cpu // FUNCTIONAL FORM WITH DISPATCH // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#define PUSHPULL_INSTANTIATE3(BoundType0, InterpolationType0, SourceType0) \ - template std::deque pushpull( \ - const SourceType0&, \ - const Tensor&, \ - const Tensor&, \ - BoundType0, \ - InterpolationType0, \ - bool, \ - bool, \ - bool, \ - bool, \ - bool, \ - bool); \ - template std::deque pushpull( \ - const SourceType0&, const Tensor&, BoundType0, InterpolationType0, bool, bool, bool, bool, bool, bool) -#define PUSHPULL_INSTANTIATE2(BoundType0, InterpolationType0) \ - PUSHPULL_INSTANTIATE3(BoundType0, InterpolationType0, IntArrayRef); \ - PUSHPULL_INSTANTIATE3(BoundType0, InterpolationType0, Tensor) -#define PUSHPULL_INSTANTIATE1(BoundType0) \ - PUSHPULL_INSTANTIATE2(BoundType0, InterpolationType); \ - PUSHPULL_INSTANTIATE2(BoundType0, InterpolationVectorRef) -#define PUSHPULL_INSTANTIATE \ - PUSHPULL_INSTANTIATE1(BoundType); \ - PUSHPULL_INSTANTIATE1(BoundVectorRef) +#define PUSHPULL_INSTANTIATE_SOURCE(SourceType) \ + template std::deque pushpull( \ + const SourceType&, \ + const Tensor&, \ + const Tensor&, \ + BoundVectorRef, \ + InterpolationVectorRef, \ + bool, \ + bool, \ + bool, \ + bool, \ + bool); \ + template std::deque pushpull( \ + const SourceType&, \ + const Tensor&, \ + BoundVectorRef, \ + InterpolationVectorRef, \ + bool, \ + bool, \ + bool, \ + bool, \ + bool, \ + bool) + +#define PUSHPULL_INSTANTIATE \ + PUSHPULL_INSTANTIATE_SOURCE(IntArrayRef); \ + PUSHPULL_INSTANTIATE_SOURCE(Tensor) // Two arguments (source, grid) - // > `bound` and `interpolation` can be single arguments or vectors. - template + // > bound and interpolation are strictly VectorRef. + template MONAI_HOST std::deque pushpull( const SourceType& source, const Tensor& grid, - BoundType bound, - InterpolationType interpolation, + BoundVectorRef bound, + InterpolationVectorRef interpolation, bool extrapolate, bool do_pull, bool do_push, @@ -2238,15 +2241,14 @@ MONAI_NAMESPACE_DEVICE { // cpu } // Three arguments (source, grid, target) - // > `bound` and `interpolation` can be single arguments or vectors. - // > `source` can be a tensor or a vector of dimensions. - template + // > bound and interpolation are strictly VectorRef. + template MONAI_HOST std::deque pushpull( const SourceType& source, const Tensor& grid, const Tensor& target, - BoundType bound, - InterpolationType interpolation, + BoundVectorRef bound, + InterpolationVectorRef interpolation, bool extrapolate, bool do_pull, bool do_push, diff --git a/monai/csrc/resample/pushpull_cuda.cu b/monai/csrc/resample/pushpull_cuda.cu index 461962cb80..733a8aba80 100644 --- a/monai/csrc/resample/pushpull_cuda.cu +++ b/monai/csrc/resample/pushpull_cuda.cu @@ -35,7 +35,7 @@ limitations under the License. // . [DONE] spatial gradient mode (without multiplication with output gradient) // . [DONE] second order gradients (backward pass for spatial gradients) // . performance tests -// . input bound/inter are always vectors -> clean unused constructors +// . [DONE] input bound/inter are always vectors -> clean unused constructors #include #include @@ -2149,39 +2149,42 @@ MONAI_NAMESPACE_DEVICE { // cuda // FUNCTIONAL FORM WITH DISPATCH // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#define PUSHPULL_INSTANTIATE3(BoundType0, InterpolationType0, SourceType0) \ - template std::deque pushpull( \ - const SourceType0&, \ - const Tensor&, \ - const Tensor&, \ - BoundType0, \ - InterpolationType0, \ - bool, \ - bool, \ - bool, \ - bool, \ - bool, \ - bool); \ - template std::deque pushpull( \ - const SourceType0&, const Tensor&, BoundType0, InterpolationType0, bool, bool, bool, bool, bool, bool) -#define PUSHPULL_INSTANTIATE2(BoundType0, InterpolationType0) \ - PUSHPULL_INSTANTIATE3(BoundType0, InterpolationType0, IntArrayRef); \ - PUSHPULL_INSTANTIATE3(BoundType0, InterpolationType0, Tensor) -#define PUSHPULL_INSTANTIATE1(BoundType0) \ - PUSHPULL_INSTANTIATE2(BoundType0, InterpolationType); \ - PUSHPULL_INSTANTIATE2(BoundType0, InterpolationVectorRef) -#define PUSHPULL_INSTANTIATE \ - PUSHPULL_INSTANTIATE1(BoundType); \ - PUSHPULL_INSTANTIATE1(BoundVectorRef) +#define PUSHPULL_INSTANTIATE_SOURCE(SourceType) \ + template std::deque pushpull( \ + const SourceType&, \ + const Tensor&, \ + const Tensor&, \ + BoundVectorRef, \ + InterpolationVectorRef, \ + bool, \ + bool, \ + bool, \ + bool, \ + bool); \ + template std::deque pushpull( \ + const SourceType&, \ + const Tensor&, \ + BoundVectorRef, \ + InterpolationVectorRef, \ + bool, \ + bool, \ + bool, \ + bool, \ + bool, \ + bool) + +#define PUSHPULL_INSTANTIATE \ + PUSHPULL_INSTANTIATE_SOURCE(IntArrayRef); \ + PUSHPULL_INSTANTIATE_SOURCE(Tensor) // Two arguments (source, grid) - // > `bound` and `interpolation` can be single arguments or vectors. - template + // > bound and interpolation are strictly VectorRef. + template MONAI_HOST std::deque pushpull( const SourceType& source, const Tensor& grid, - BoundType bound, - InterpolationType interpolation, + BoundVectorRef bound, + InterpolationVectorRef interpolation, bool extrapolate, bool do_pull, bool do_push, @@ -2206,15 +2209,14 @@ MONAI_NAMESPACE_DEVICE { // cuda } // Three arguments (source, grid, target) - // > `bound` and `interpolation` can be single arguments or vectors. - // > `source` can be a tensor or a vector of dimensions. - template + // > bound and interpolation are strictly VectorRef. + template MONAI_HOST std::deque pushpull( const SourceType& source, const Tensor& grid, const Tensor& target, - BoundType bound, - InterpolationType interpolation, + BoundVectorRef bound, + InterpolationVectorRef interpolation, bool extrapolate, bool do_pull, bool do_push, From 69da7bf39f7ca79a52203d1673da9020299b5b00 Mon Sep 17 00:00:00 2001 From: ytl0623 Date: Fri, 16 Jan 2026 22:56:20 +0800 Subject: [PATCH 2/3] resolve template signature mismatch in pushpull header Signed-off-by: ytl0623 --- monai/csrc/resample/pushpull.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/monai/csrc/resample/pushpull.h b/monai/csrc/resample/pushpull.h index b056bb77c2..b9c36b18d8 100644 --- a/monai/csrc/resample/pushpull.h +++ b/monai/csrc/resample/pushpull.h @@ -22,25 +22,25 @@ limitations under the License. #define MONAI_PUSHPULL_DECLARE(space) \ namespace space { \ - template \ + template \ std::deque pushpull( \ const SourceType& source, \ const at::Tensor& grid, \ - BoundType bound, \ - InterpolationType interpolation, \ + monai::BoundVectorRef bound, \ + monai::InterpolationVectorRef interpolation, \ bool extrapolate, \ bool do_pull, \ bool do_push, \ bool do_count, \ bool do_grad, \ bool do_sgrad); \ - template \ + template \ std::deque pushpull( \ const SourceType& source, \ const at::Tensor& grid, \ const at::Tensor& target, \ - BoundType bound, \ - InterpolationType interpolation, \ + monai::BoundVectorRef bound, \ + monai::InterpolationVectorRef interpolation, \ bool extrapolate, \ bool do_pull, \ bool do_push, \ From cbd9305b73ac3691bed9ff59fbcf7cd0fe344038 Mon Sep 17 00:00:00 2001 From: ytl0623 Date: Fri, 16 Jan 2026 23:28:22 +0800 Subject: [PATCH 3/3] fix missing bool in 3-arg explicit instantiation Signed-off-by: ytl0623 --- monai/csrc/resample/pushpull_cpu.cpp | 1 + monai/csrc/resample/pushpull_cuda.cu | 1 + 2 files changed, 2 insertions(+) diff --git a/monai/csrc/resample/pushpull_cpu.cpp b/monai/csrc/resample/pushpull_cpu.cpp index adca3e9df9..463782571d 100644 --- a/monai/csrc/resample/pushpull_cpu.cpp +++ b/monai/csrc/resample/pushpull_cpu.cpp @@ -2198,6 +2198,7 @@ MONAI_NAMESPACE_DEVICE { // cpu bool, \ bool, \ bool, \ + bool, \ bool); \ template std::deque pushpull( \ const SourceType&, \ diff --git a/monai/csrc/resample/pushpull_cuda.cu b/monai/csrc/resample/pushpull_cuda.cu index 733a8aba80..c254e18d73 100644 --- a/monai/csrc/resample/pushpull_cuda.cu +++ b/monai/csrc/resample/pushpull_cuda.cu @@ -2160,6 +2160,7 @@ MONAI_NAMESPACE_DEVICE { // cuda bool, \ bool, \ bool, \ + bool, \ bool); \ template std::deque pushpull( \ const SourceType&, \