From 0ad6cb01b9176e99c3e4bb5643ac6a5dd477aad6 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 9 Nov 2017 20:57:31 +0100 Subject: Check for CUDA support at run-time in use_cuda() --- cuda/2d/astra.cu | 11 +++++++++++ cuda/2d/astra.h | 2 ++ cuda/3d/mem3d.cu | 19 ++++++------------- cuda/3d/mem3d.h | 1 - 4 files changed, 19 insertions(+), 14 deletions(-) (limited to 'cuda') diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu index 81459de..69a4e86 100644 --- a/cuda/2d/astra.cu +++ b/cuda/2d/astra.cu @@ -529,5 +529,16 @@ _AstraExport bool setGPUIndex(int iGPUIndex) return true; } +_AstraExport size_t availableGPUMemory() +{ + size_t free, total; + cudaError_t err = cudaMemGetInfo(&free, &total); + if (err != cudaSuccess) + return 0; + return free; +} + + + } diff --git a/cuda/2d/astra.h b/cuda/2d/astra.h index 9355cb4..119d172 100644 --- a/cuda/2d/astra.h +++ b/cuda/2d/astra.h @@ -121,5 +121,7 @@ _AstraExport std::string getCudaDeviceString(int device); _AstraExport bool setGPUIndex(int index); +_AstraExport size_t availableGPUMemory(); + } #endif diff --git a/cuda/3d/mem3d.cu b/cuda/3d/mem3d.cu index 2369149..e55cc13 100644 --- a/cuda/3d/mem3d.cu +++ b/cuda/3d/mem3d.cu @@ -32,6 +32,8 @@ along with the ASTRA Toolbox. If not, see . #include "mem3d.h" +#include "../2d/astra.h" + #include "astra3d.h" #include "cone_fp.h" #include "cone_bp.h" @@ -53,15 +55,6 @@ struct SMemHandle3D_internal unsigned int nz; }; -size_t availableGPUMemory() -{ - size_t free, total; - cudaError_t err = cudaMemGetInfo(&free, &total); - if (err != cudaSuccess) - return 0; - return free; -} - int maxBlockDimension() { int dev; @@ -88,7 +81,7 @@ MemHandle3D allocateGPUMemory(unsigned int x, unsigned int y, unsigned int z, Me hnd.ny = y; hnd.nz = z; - size_t free = availableGPUMemory(); + size_t free = astraCUDA::availableGPUMemory(); cudaError_t err; err = cudaMalloc3D(&hnd.ptr, make_cudaExtent(sizeof(float)*x, y, z)); @@ -97,7 +90,7 @@ MemHandle3D allocateGPUMemory(unsigned int x, unsigned int y, unsigned int z, Me return MemHandle3D(); } - size_t free2 = availableGPUMemory(); + size_t free2 = astraCUDA::availableGPUMemory(); ASTRA_DEBUG("Allocated %d x %d x %d on GPU. (Pre: %lu, post: %lu)", x, y, z, free, free2); @@ -127,9 +120,9 @@ bool zeroGPUMemory(MemHandle3D handle, unsigned int x, unsigned int y, unsigned bool freeGPUMemory(MemHandle3D handle) { - size_t free = availableGPUMemory(); + size_t free = astraCUDA::availableGPUMemory(); cudaError_t err = cudaFree(handle.d->ptr.ptr); - size_t free2 = availableGPUMemory(); + size_t free2 = astraCUDA::availableGPUMemory(); ASTRA_DEBUG("Freeing memory. (Pre: %lu, post: %lu)", free, free2); diff --git a/cuda/3d/mem3d.h b/cuda/3d/mem3d.h index 619354b..12a532d 100644 --- a/cuda/3d/mem3d.h +++ b/cuda/3d/mem3d.h @@ -77,7 +77,6 @@ enum Mem3DZeroMode { INIT_ZERO }; -size_t availableGPUMemory(); int maxBlockDimension(); _AstraExport MemHandle3D wrapHandle(float *D_ptr, unsigned int x, unsigned int y, unsigned int z, unsigned int pitch); -- cgit v1.2.3