summaryrefslogtreecommitdiffstats
path: root/cuda/3d/util3d.cu
diff options
context:
space:
mode:
Diffstat (limited to 'cuda/3d/util3d.cu')
-rw-r--r--cuda/3d/util3d.cu103
1 files changed, 24 insertions, 79 deletions
diff --git a/cuda/3d/util3d.cu b/cuda/3d/util3d.cu
index 844b880..71b5668 100644
--- a/cuda/3d/util3d.cu
+++ b/cuda/3d/util3d.cu
@@ -46,12 +46,9 @@ cudaPitchedPtr allocateVolumeData(const SDimensions3D& dims)
cudaPitchedPtr volData;
- cudaError err = cudaMalloc3D(&volData, extentV);
- if (err != cudaSuccess) {
- astraCUDA::reportCudaError(err);
+ if (!checkCuda(cudaMalloc3D(&volData, extentV), "allocateVolumeData 3D")) {
ASTRA_ERROR("Failed to allocate %dx%dx%d GPU buffer", dims.iVolX, dims.iVolY, dims.iVolZ);
volData.ptr = 0;
- // TODO: return 0 somehow?
}
return volData;
@@ -65,12 +62,9 @@ cudaPitchedPtr allocateProjectionData(const SDimensions3D& dims)
cudaPitchedPtr projData;
- cudaError err = cudaMalloc3D(&projData, extentP);
- if (err != cudaSuccess) {
- astraCUDA::reportCudaError(err);
+ if (!checkCuda(cudaMalloc3D(&projData, extentP), "allocateProjectionData 3D")) {
ASTRA_ERROR("Failed to allocate %dx%dx%d GPU buffer", dims.iProjU, dims.iProjAngles, dims.iProjV);
projData.ptr = 0;
- // TODO: return 0 somehow?
}
return projData;
@@ -78,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;
@@ -90,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;
}
@@ -128,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)
@@ -163,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)
@@ -198,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)
@@ -232,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)
@@ -258,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;
@@ -283,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");
}
@@ -303,9 +275,8 @@ cudaArray* allocateVolumeArray(const SDimensions3D& dims)
extentA.width = dims.iVolX;
extentA.height = dims.iVolY;
extentA.depth = dims.iVolZ;
- cudaError err = cudaMalloc3DArray(&cuArray, &channelDesc, extentA);
- if (err != cudaSuccess) {
- astraCUDA::reportCudaError(err);
+
+ if (!checkCuda(cudaMalloc3DArray(&cuArray, &channelDesc, extentA), "allocateVolumeArray 3D")) {
ASTRA_ERROR("Failed to allocate %dx%dx%d GPU array", dims.iVolX, dims.iVolY, dims.iVolZ);
return 0;
}
@@ -320,10 +291,8 @@ cudaArray* allocateProjectionArray(const SDimensions3D& dims)
extentA.width = dims.iProjU;
extentA.height = dims.iProjAngles;
extentA.depth = dims.iProjV;
- cudaError err = cudaMalloc3DArray(&cuArray, &channelDesc, extentA);
- if (err != cudaSuccess) {
- astraCUDA::reportCudaError(err);
+ if (!checkCuda(cudaMalloc3DArray(&cuArray, &channelDesc, extentA), "allocateProjectionArray 3D")) {
ASTRA_ERROR("Failed to allocate %dx%dx%d GPU array", dims.iProjU, dims.iProjAngles, dims.iProjV);
return 0;
}
@@ -352,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;
@@ -379,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;
@@ -413,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");
}
@@ -430,18 +387,6 @@ float dotProduct3D(cudaPitchedPtr data, unsigned int x, unsigned int y,
}
-bool cudaTextForceKernelsCompletion()
-{
- cudaError_t returnedCudaError = cudaThreadSynchronize();
-
- if(returnedCudaError != cudaSuccess) {
- ASTRA_ERROR("Failed to force completion of cuda kernels: %d: %s.", returnedCudaError, cudaGetErrorString(returnedCudaError));
- return false;
- }
-
- return true;
-}
-
int calcNextPowerOfTwo(int _iValue)
{
int iOutput = 1;