Skip to content

Commit 7d5fc93

Browse files
authored
Merge pull request #75 from khammernik/master
Fix memory leak and move print statement to debug mode.
2 parents 4508792 + 234d38c commit 7d5fc93

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

CUDA/inc/gpuNUFFT_operator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class GpuNUFFTOperator
6464
freeLocalMemberArray(this->kernel.data);
6565

6666
if (!matlabSharedMem) {
67+
freeLocalMemberArray(this->dens.data);
6768
freeLocalMemberArray(this->deapo.data);
6869
freeLocalMemberArray(this->kSpaceTraj.data);
6970
freeLocalMemberArray(this->sectorCenters.data);

CUDA/src/gpu/std_gpuNUFFT_kernels.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void performFFTScaling(CufftType* data,int N, gpuNUFFT::GpuNUFFTInfo* gi_host)
134134
dim3 block_dim(64, 1, 8);
135135
//dim3 block_dim(THREAD_BLOCK_SIZE);
136136
dim3 grid_dim(getOptimalGridDim(N,THREAD_BLOCK_SIZE));
137-
DType scaling_factor = (DType)1.0 / (DType) sqrt((DType)gi_host->im_width_dim);
137+
DType scaling_factor = (DType)1.0 / (DType) sqrt((DType)gi_host->gridDims_count);
138138

139139
fftScaleKernel<<<grid_dim,block_dim>>>(data,scaling_factor,N);
140140
}

CUDA/src/gpuNUFFT_operator.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ void gpuNUFFT::GpuNUFFTOperator::performGpuNUFFTAdj(
505505

506506
freeTotalDeviceMemory(imdata_sum_d, NULL);
507507

508-
printf("last cuda error: %s\n", cudaGetErrorString(cudaGetLastError()));
508+
if (DEBUG)
509+
printf("last cuda error: %s\n", cudaGetErrorString(cudaGetLastError()));
509510
return;
510511
}
511512
if (DEBUG && (cudaThreadSynchronize() != cudaSuccess))
@@ -780,8 +781,8 @@ void gpuNUFFT::GpuNUFFTOperator::performGpuNUFFTAdj(
780781
copyFromDevice<CufftType>(imdata_d, imgData.data, gi_host->imgDims_count);
781782

782783
freeTotalDeviceMemory(data_d, imdata_d, imdata_sum_d, NULL);
783-
784-
printf("last cuda error: %s\n", cudaGetErrorString(cudaGetLastError()));
784+
if (DEBUG)
785+
printf("last cuda error: %s\n", cudaGetErrorString(cudaGetLastError()));
785786
return;
786787
}
787788
if (DEBUG && (cudaThreadSynchronize() != cudaSuccess))

CUDA/src/gpuNUFFT_operator_factory.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,15 @@ gpuNUFFT::Array<DType> gpuNUFFT::GpuNUFFTOperatorFactory::computeDeapodizationFu
412412
// cleanup locally initialized arrays here
413413
free(dataArray.data);
414414
free(assignedSectors.data);
415-
delete deapoGpuNUFFTOp;
416415

417416
// Compute abs values of deapo function and compensate
418417
// FFT scaling sqrt(N)
419418
Array<DType> deapoAbs = initDeapoData(deapoFunction.count());
420419

421420
DType maxDeapoVal = 0;
422421
DType minDeapoVal = std::numeric_limits<DType>::max();
423-
double fft_scaling_factor = std::sqrt(imgDims.count());
422+
double fft_scaling_factor = std::sqrt(deapoGpuNUFFTOp->getGridDims().count());
423+
424424
for (unsigned cnt = 0; cnt < deapoFunction.count(); cnt++)
425425
{
426426
deapoFunction.data[cnt].x = deapoFunction.data[cnt].x * fft_scaling_factor;
@@ -432,6 +432,8 @@ gpuNUFFT::Array<DType> gpuNUFFT::GpuNUFFTOperatorFactory::computeDeapodizationFu
432432
minDeapoVal = deapoAbs.data[cnt];
433433
}
434434

435+
// cleanup
436+
delete deapoGpuNUFFTOp;
435437
free(deapoFunction.data);
436438
return deapoAbs;
437439
}
@@ -531,6 +533,7 @@ gpuNUFFT::GpuNUFFTOperatorFactory::createGpuNUFFTOperator(
531533

532534
// free temporary array
533535
free(assignedSectors.data);
536+
assignedSectors.data = NULL;
534537

535538
gpuNUFFTOp->setDeapodizationFunction(
536539
this->computeDeapodizationFunction(kernelWidth, osf, imgDims));

0 commit comments

Comments
 (0)