diff options
Diffstat (limited to 'cuda')
-rw-r--r-- | cuda/2d/util.cu | 41 | ||||
-rw-r--r-- | cuda/3d/util3d.cu | 72 |
2 files changed, 33 insertions, 80 deletions
diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu index 1c7f6f0..a75e5ab 100644 --- a/cuda/2d/util.cu +++ b/cuda/2d/util.cu @@ -40,12 +40,8 @@ bool copyVolumeToDevice(const float* in_data, unsigned int in_pitch, { size_t width = dims.iVolWidth; size_t height = dims.iVolHeight; - // TODO: memory order - cudaError_t err; - err = cudaMemcpy2D(outD_data, sizeof(float)*out_pitch, in_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyHostToDevice); - ASTRA_CUDA_ASSERT(err); - assert(err == cudaSuccess); - return true; + + return checkCuda(cudaMemcpy2D(outD_data, sizeof(float)*out_pitch, in_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyHostToDevice), "copyVolumeToDevice"); } bool copyVolumeFromDevice(float* out_data, unsigned int out_pitch, @@ -54,10 +50,8 @@ bool copyVolumeFromDevice(float* out_data, unsigned int out_pitch, { size_t width = dims.iVolWidth; size_t height = dims.iVolHeight; - // TODO: memory order - cudaError_t err = cudaMemcpy2D(out_data, sizeof(float)*out_pitch, inD_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyDeviceToHost); - ASTRA_CUDA_ASSERT(err); - return true; + + return checkCuda(cudaMemcpy2D(out_data, sizeof(float)*out_pitch, inD_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyDeviceToHost), "copyVolumeFromDevice"); } @@ -67,10 +61,8 @@ bool copySinogramFromDevice(float* out_data, unsigned int out_pitch, { size_t width = dims.iProjDets; size_t height = dims.iProjAngles; - // TODO: memory order - cudaError_t err = cudaMemcpy2D(out_data, sizeof(float)*out_pitch, inD_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyDeviceToHost); - ASTRA_CUDA_ASSERT(err); - return true; + + return checkCuda(cudaMemcpy2D(out_data, sizeof(float)*out_pitch, inD_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyDeviceToHost), "copySinogramFromDevice"); } bool copySinogramToDevice(const float* in_data, unsigned int in_pitch, @@ -79,11 +71,8 @@ bool copySinogramToDevice(const float* in_data, unsigned int in_pitch, { size_t width = dims.iProjDets; size_t height = dims.iProjAngles; - // TODO: memory order - cudaError_t err; - err = cudaMemcpy2D(outD_data, sizeof(float)*out_pitch, in_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyHostToDevice); - ASTRA_CUDA_ASSERT(err); - return true; + + return checkCuda(cudaMemcpy2D(outD_data, sizeof(float)*out_pitch, in_data, sizeof(float)*in_pitch, sizeof(float)*width, height, cudaMemcpyHostToDevice), "copySinogramToDevice"); } @@ -102,11 +91,9 @@ bool allocateVolume(float*& ptr, unsigned int width, unsigned int height, unsign return true; } -void zeroVolume(float* data, unsigned int pitch, unsigned int width, unsigned int height) +bool zeroVolume(float* data, unsigned int pitch, unsigned int width, unsigned int height) { - cudaError_t err; - err = cudaMemset2D(data, sizeof(float)*pitch, 0, sizeof(float)*width, height); - ASTRA_CUDA_ASSERT(err); + return checkCuda(cudaMemset2D(data, sizeof(float)*pitch, 0, sizeof(float)*width, height), "zeroVolume"); } bool allocateVolumeData(float*& D_ptr, unsigned int& pitch, const SDimensions& dims) @@ -119,14 +106,14 @@ bool allocateProjectionData(float*& D_ptr, unsigned int& pitch, const SDimension return allocateVolume(D_ptr, dims.iProjDets, dims.iProjAngles, pitch); } -void zeroVolumeData(float* D_ptr, unsigned int pitch, const SDimensions& dims) +bool zeroVolumeData(float* D_ptr, unsigned int pitch, const SDimensions& dims) { - zeroVolume(D_ptr, pitch, dims.iVolWidth, dims.iVolHeight); + return zeroVolume(D_ptr, pitch, dims.iVolWidth, dims.iVolHeight); } -void zeroProjectionData(float* D_ptr, unsigned int pitch, const SDimensions& dims) +bool zeroProjectionData(float* D_ptr, unsigned int pitch, const SDimensions& dims) { - zeroVolume(D_ptr, pitch, dims.iProjDets, dims.iProjAngles); + return zeroVolume(D_ptr, pitch, dims.iProjDets, dims.iProjAngles); } void duplicateVolumeData(float* D_dst, float* D_src, unsigned int pitch, const SDimensions& dims) diff --git a/cuda/3d/util3d.cu b/cuda/3d/util3d.cu index 8b66432..4f5d134 100644 --- a/cuda/3d/util3d.cu +++ b/cuda/3d/util3d.cu @@ -72,11 +72,11 @@ cudaPitchedPtr allocateProjectionData(const SDimensions3D& dims) bool zeroVolumeData(cudaPitchedPtr& D_data, const SDimensions3D& dims) { char* t = (char*)D_data.ptr; - cudaError err; for (unsigned int z = 0; z < dims.iVolZ; ++z) { - err = cudaMemset2D(t, D_data.pitch, 0, dims.iVolX*sizeof(float), dims.iVolY); - ASTRA_CUDA_ASSERT(err); + if (!checkCuda(cudaMemset2D(t, D_data.pitch, 0, dims.iVolX*sizeof(float), dims.iVolY), "zeroVolumeData 3D")) { + return false; + } t += D_data.pitch * dims.iVolY; } return true; @@ -84,11 +84,11 @@ bool zeroVolumeData(cudaPitchedPtr& D_data, const SDimensions3D& dims) bool zeroProjectionData(cudaPitchedPtr& D_data, const SDimensions3D& dims) { char* t = (char*)D_data.ptr; - cudaError err; for (unsigned int z = 0; z < dims.iProjV; ++z) { - err = cudaMemset2D(t, D_data.pitch, 0, dims.iProjU*sizeof(float), dims.iProjAngles); - ASTRA_CUDA_ASSERT(err); + if (!checkCuda(cudaMemset2D(t, D_data.pitch, 0, dims.iProjU*sizeof(float), dims.iProjAngles), "zeroProjectionData 3D")) { + return false; + } t += D_data.pitch * dims.iProjAngles; } @@ -122,11 +122,7 @@ bool copyVolumeToDevice(const float* data, cudaPitchedPtr& D_data, const SDimens p.extent = extentV; p.kind = cudaMemcpyHostToDevice; - cudaError err; - err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - return err == cudaSuccess; + return checkCuda(cudaMemcpy3D(&p), "copyVolumeToDevice 3D"); } bool copyProjectionsToDevice(const float* data, cudaPitchedPtr& D_data, const SDimensions3D& dims, unsigned int pitch) @@ -157,11 +153,7 @@ bool copyProjectionsToDevice(const float* data, cudaPitchedPtr& D_data, const SD p.extent = extentV; p.kind = cudaMemcpyHostToDevice; - cudaError err; - err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - return err == cudaSuccess; + return checkCuda(cudaMemcpy3D(&p), "copyProjectionsToDevice 3D"); } bool copyVolumeFromDevice(float* data, const cudaPitchedPtr& D_data, const SDimensions3D& dims, unsigned int pitch) @@ -192,12 +184,9 @@ bool copyVolumeFromDevice(float* data, const cudaPitchedPtr& D_data, const SDime p.extent = extentV; p.kind = cudaMemcpyDeviceToHost; - cudaError err; - err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - return err == cudaSuccess; + return checkCuda(cudaMemcpy3D(&p), "copyVolumeFromDevice 3D"); } + bool copyProjectionsFromDevice(float* data, const cudaPitchedPtr& D_data, const SDimensions3D& dims, unsigned int pitch) { if (!pitch) @@ -226,11 +215,7 @@ bool copyProjectionsFromDevice(float* data, const cudaPitchedPtr& D_data, const p.extent = extentV; p.kind = cudaMemcpyDeviceToHost; - cudaError err; - err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - return err == cudaSuccess; + return checkCuda(cudaMemcpy3D(&p), "copyProjectionsFromDevice 3D"); } bool duplicateVolumeData(cudaPitchedPtr& D_dst, const cudaPitchedPtr& D_src, const SDimensions3D& dims) @@ -252,12 +237,9 @@ bool duplicateVolumeData(cudaPitchedPtr& D_dst, const cudaPitchedPtr& D_src, con p.extent = extentV; p.kind = cudaMemcpyDeviceToDevice; - cudaError err; - err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - return err == cudaSuccess; + return checkCuda(cudaMemcpy3D(&p), "duplicateVolumeData 3D"); } + bool duplicateProjectionData(cudaPitchedPtr& D_dst, const cudaPitchedPtr& D_src, const SDimensions3D& dims) { cudaExtent extentV; @@ -277,11 +259,7 @@ bool duplicateProjectionData(cudaPitchedPtr& D_dst, const cudaPitchedPtr& D_src, p.extent = extentV; p.kind = cudaMemcpyDeviceToDevice; - cudaError err; - err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - return err == cudaSuccess; + return checkCuda(cudaMemcpy3D(&p), "duplicateProjectionData 3D"); } @@ -343,12 +321,9 @@ bool transferVolumeToArray(cudaPitchedPtr D_volumeData, cudaArray* array, const p.extent = extentA; p.kind = cudaMemcpyDeviceToDevice; - cudaError err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - // TODO: check errors - - return true; + return checkCuda(cudaMemcpy3D(&p), "transferVolumeToArray 3D"); } + bool transferProjectionsToArray(cudaPitchedPtr D_projData, cudaArray* array, const SDimensions3D& dims) { cudaExtent extentA; @@ -370,13 +345,9 @@ bool transferProjectionsToArray(cudaPitchedPtr D_projData, cudaArray* array, con p.extent = extentA; p.kind = cudaMemcpyDeviceToDevice; - cudaError err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - // TODO: check errors - - return true; + return checkCuda(cudaMemcpy3D(&p), "transferProjectionsToArray 3D"); } + bool transferHostProjectionsToArray(const float *projData, cudaArray* array, const SDimensions3D& dims) { cudaExtent extentA; @@ -404,12 +375,7 @@ bool transferHostProjectionsToArray(const float *projData, cudaArray* array, con p.extent = extentA; p.kind = cudaMemcpyHostToDevice; - cudaError err = cudaMemcpy3D(&p); - ASTRA_CUDA_ASSERT(err); - - // TODO: check errors - - return true; + return checkCuda(cudaMemcpy3D(&p), "transferHostProjectionsToArray 3D"); } |