Skip to content

Commit 53f020e

Browse files
committed
STYLE: Address Greptile review on SmoothingRecursiveYvvGaussianFilter
Greptile P1/P2 findings: - itk-module.cmake: rename `GPU_DEPENDANCIES` -> `GPU_DEPENDENCIES` (typo). - src/CMakeLists.txt: drop `${INRIA_ITK_LIBRARIES}` / `${OPENCL_LIBRARIES}` (undefined in ITK; OpenCL linkage is provided by the `ITKGPUCommon` module dep). Drop the `GPU_HANDLES_DOUBLE` / `NVIDIA_GPU` guards (variables are never set in ITK's build, so the branches were unreachable). - test/CMakeLists.txt: same `GPU_HANDLES_DOUBLE` / `NVIDIA_GPU` guard removal. - src/OpenCLInfo.cpp: remove the standalone-only diagnostic utility (it has its own `main()` and is not listed in src/CMakeLists.txt). - include/itkGPUSmoothingRecursiveYvvGaussianImageFilter.h{,xx}: replace raw `new ScalarRealType[N]` for `m_Bvalues` and `m_CPUMatrix` with `std::vector<ScalarRealType>`. The previous code leaked on every `SetUp()` re-entry (the destructor is `= default` and there is no matching `delete[]`). `SetCPUBufferPointer` now uses `.data()`.
1 parent 57695a8 commit 53f020e

6 files changed

Lines changed: 15 additions & 145 deletions

File tree

Modules/Filtering/SmoothingRecursiveYvvGaussianFilter/include/itkGPUSmoothingRecursiveYvvGaussianImageFilter.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# include "itkSmoothingRecursiveYvvGaussianImageFilter.h"
2929
# include "itkOpenCLUtil.h"
3030
# include "itkGPUImageToImageFilter.h"
31+
# include <vector>
3132

3233
namespace itk
3334
{
@@ -170,14 +171,14 @@ class ITK_EXPORT GPUSmoothingRecursiveYvvGaussianImageFilter
170171

171172
std::ostringstream defines;
172173

173-
ScalarRealType m_B1;
174-
ScalarRealType m_B2;
175-
ScalarRealType m_B3;
176-
ScalarRealType m_B;
177-
ScalarRealType * m_Bvalues;
174+
ScalarRealType m_B1;
175+
ScalarRealType m_B2;
176+
ScalarRealType m_B3;
177+
ScalarRealType m_B;
178+
std::vector<ScalarRealType> m_Bvalues;
178179

179180
// Initialization matrix for anti-causal pass
180-
ScalarRealType * m_CPUMatrix;
181+
std::vector<ScalarRealType> m_CPUMatrix;
181182

182183
using GPUDataPointer = GPUDataManager::Pointer;
183184

Modules/Filtering/SmoothingRecursiveYvvGaussianFilter/include/itkGPUSmoothingRecursiveYvvGaussianImageFilter.hxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ GPUSmoothingRecursiveYvvGaussianImageFilter<TInputImage, TOutputImage>::SetUp(Sc
106106
ScalarRealType m1 = 1.10783;
107107
ScalarRealType m2 = 1.40586;
108108
ScalarRealType scale = (m0 + q) * (m1 * m1 + m2 * m2 + 2 * m1 * q + q * q);
109-
m_Bvalues = new ScalarRealType[4];
109+
m_Bvalues.assign(4, ScalarRealType{});
110110

111111
m_B1 = m_Bvalues[1] = q * (2 * m0 * m1 + m1 * m1 + m2 * m2 + (2 * m0 + 4 * m1) * q + 3 * q * q) / scale;
112112
m_B2 = m_Bvalues[2] = -q * q * (m0 + 2 * m1 + 3 * q) / scale;
@@ -117,7 +117,7 @@ GPUSmoothingRecursiveYvvGaussianImageFilter<TInputImage, TOutputImage>::SetUp(Sc
117117

118118
// M Matrix for initialization on backward pass, from Triggs and Sdika, IEEE
119119
// TSP
120-
m_CPUMatrix = new ScalarRealType[9];
120+
m_CPUMatrix.assign(9, ScalarRealType{});
121121
const ScalarRealType factor =
122122
(1 + m_B1 - m_B2 + m_B3) * (1 - m_B1 - m_B2 - m_B3) * (1 + m_B2 + (m_B1 - m_B3) * m_B3);
123123

@@ -261,20 +261,20 @@ GPUSmoothingRecursiveYvvGaussianImageFilter<TInputImage, TOutputImage>::Allocate
261261
{
262262
m_GPUBCoefficientsDataManager = GPUDataManager::New();
263263
m_GPUBCoefficientsDataManager->SetBufferSize(4 * sizeof(ScalarRealType));
264-
m_GPUBCoefficientsDataManager->SetCPUBufferPointer(m_Bvalues);
264+
m_GPUBCoefficientsDataManager->SetCPUBufferPointer(m_Bvalues.data());
265265
m_GPUBCoefficientsDataManager->SetBufferFlag(CL_MEM_READ_ONLY);
266266
m_GPUBCoefficientsDataManager->Allocate();
267-
if (m_Bvalues)
267+
if (!m_Bvalues.empty())
268268
{
269269
m_GPUBCoefficientsDataManager->SetGPUDirtyFlag(true);
270270
}
271271

272272
m_GPUMMatrixDataManager = GPUDataManager::New();
273273
m_GPUMMatrixDataManager->SetBufferSize(9 * sizeof(ScalarRealType));
274-
m_GPUMMatrixDataManager->SetCPUBufferPointer(m_CPUMatrix);
274+
m_GPUMMatrixDataManager->SetCPUBufferPointer(m_CPUMatrix.data());
275275
m_GPUMMatrixDataManager->SetBufferFlag(CL_MEM_READ_ONLY);
276276
m_GPUMMatrixDataManager->Allocate();
277-
if (m_CPUMatrix)
277+
if (!m_CPUMatrix.empty())
278278
{
279279
m_GPUMMatrixDataManager->SetGPUDirtyFlag(true);
280280
}

Modules/Filtering/SmoothingRecursiveYvvGaussianFilter/itk-module.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# define the dependencies of the include module and the tests
1111
set(ModuleName "SmoothingRecursiveYvvGaussianFilter")
1212
if(ITK_USE_GPU)
13-
set(${ModuleName}_GPU_DEPENDANCIES "ITKGPUSmoothing")
13+
set(${ModuleName}_GPU_DEPENDENCIES "ITKGPUSmoothing")
1414
set(${ModuleName}_GPU_COMMON "ITKGPUCommon")
1515
endif()
1616
itk_module(
@@ -20,7 +20,7 @@ itk_module(
2020
ITKIOImageBase
2121
ITKImageFilterBase
2222
ITKSmoothing
23-
${${ModuleName}_GPU_DEPENDANCIES}
23+
${${ModuleName}_GPU_DEPENDENCIES}
2424
${${ModuleName}_GPU_COMMON}
2525
TEST_DEPENDS
2626
ITKTestKernel #to handle IO in src
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
if(ITK_USE_GPU)
2-
if(GPU_HANDLES_DOUBLE)
3-
add_definitions(-DWITH_DOUBLE)
4-
endif()
5-
62
set(GPU_SRC)
7-
83
set(GPU_Kernels GPUSmoothingRecursiveYvvGaussianImageFilter.cl)
94

105
#essentially a #define GPU.
116
add_definitions(-DGPU)
127

13-
if(NVIDIA_GPU)
14-
add_definitions(-DNVIDIA)
15-
endif()
16-
178
write_gpu_kernels("${GPU_Kernels}" GPU_SRC)
189

1910
itk_module_add_library(${itk-module} ${GPU_SRC})
20-
target_link_libraries(
21-
${itk-module}
22-
${INRIA_ITK_LIBRARIES}
23-
${OPENCL_LIBRARIES}
24-
)
2511
endif()

Modules/Filtering/SmoothingRecursiveYvvGaussianFilter/src/OpenCLInfo.cpp

Lines changed: 0 additions & 108 deletions
This file was deleted.

Modules/Filtering/SmoothingRecursiveYvvGaussianFilter/test/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ itk_module_test()
33
if(ITK_USE_GPU)
44
add_definitions(-DGPU)
55

6-
if(GPU_HANDLES_DOUBLE)
7-
add_definitions(-DWITH_DOUBLE)
8-
endif()
9-
10-
if(NVIDIA_GPU)
11-
add_definitions(-DNVIDIA)
12-
message(STATUS "NVIDIA platform detected")
13-
endif()
14-
156
include_directories("${${itk-module}_SOURCE_DIR}/include")
167
include_directories("${${itk-module}KernelDir}")
178

0 commit comments

Comments
 (0)