From f70f68fcd465f421b566b199e23e66c1f186b01d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 1 Nov 2017 15:05:13 +0100 Subject: Separate cuda from astra headers further --- cuda/2d/astra.cu | 41 +++++++++++++++++++++++++++++++++++++++++ cuda/2d/astra.h | 9 +++++++++ cuda/2d/darthelper.cu | 16 ---------------- cuda/2d/darthelper.h | 2 -- cuda/2d/util.cu | 25 ------------------------- cuda/2d/util.h | 4 ---- 6 files changed, 50 insertions(+), 47 deletions(-) (limited to 'cuda') diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu index 2ff9230..c0132b2 100644 --- a/cuda/2d/astra.cu +++ b/cuda/2d/astra.cu @@ -986,6 +986,47 @@ bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom, } +} + +namespace astraCUDA { + + +_AstraExport std::string getCudaDeviceString(int device) +{ + char buf[1024]; + cudaError_t err; + if (device == -1) { + err = cudaGetDevice(&device); + if (err != cudaSuccess) { + return "Error getting current GPU index"; + } + } + + cudaDeviceProp prop; + err = cudaGetDeviceProperties(&prop, device); + if (err != cudaSuccess) { + snprintf(buf, 1024, "GPU #%d: Invalid device (%d): %s", device, err, cudaGetErrorString(err)); + return buf; + } + + long mem = prop.totalGlobalMem / (1024*1024); + snprintf(buf, 1024, "GPU #%d: %s, with %ldMB", device, prop.name, mem); + return buf; +} + +_AstraExport bool setGPUIndex(int iGPUIndex) +{ + if (iGPUIndex != -1) { + cudaSetDevice(iGPUIndex); + cudaError_t err = cudaGetLastError(); + + // Ignore errors caused by calling cudaSetDevice multiple times + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + return false; + } + + return true; +} } diff --git a/cuda/2d/astra.h b/cuda/2d/astra.h index c9e0762..e4cefac 100644 --- a/cuda/2d/astra.h +++ b/cuda/2d/astra.h @@ -224,6 +224,15 @@ _AstraExport bool convertAstraGeometry(const CVolumeGeometry2D* pVolGeom, astraCUDA::SFanProjection*& pProjs, float& outputScale); +} + +namespace astraCUDA { + +// Return string with CUDA device number, name and memory size. +// Use device == -1 to get info for the current device. +_AstraExport std::string getCudaDeviceString(int device); + +_AstraExport bool setGPUIndex(int index); } #endif diff --git a/cuda/2d/darthelper.cu b/cuda/2d/darthelper.cu index 744184e..d4b5220 100644 --- a/cuda/2d/darthelper.cu +++ b/cuda/2d/darthelper.cu @@ -356,20 +356,4 @@ void dartSmoothing(float* out, const float* in, float b, unsigned int radius, un } - -_AstraExport bool setGPUIndex(int iGPUIndex) -{ - if (iGPUIndex != -1) { - cudaSetDevice(iGPUIndex); - cudaError_t err = cudaGetLastError(); - - // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) - return false; - } - - return true; -} - - } diff --git a/cuda/2d/darthelper.h b/cuda/2d/darthelper.h index 9a2837c..67a6a7d 100644 --- a/cuda/2d/darthelper.h +++ b/cuda/2d/darthelper.h @@ -36,8 +36,6 @@ namespace astraCUDA { void dartMask(float* out, const float* in, unsigned int conn, unsigned int radius, unsigned int threshold, unsigned int width, unsigned int height); void dartSmoothing(float* out, const float* in, float b, unsigned int radius, unsigned int width, unsigned int height); - _AstraExport bool setGPUIndex(int index); - } #endif diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu index 9c1bb28..871e139 100644 --- a/cuda/2d/util.cu +++ b/cuda/2d/util.cu @@ -274,29 +274,4 @@ void reportCudaError(cudaError_t err) } -_AstraExport std::string getCudaDeviceString(int device) -{ - char buf[1024]; - cudaError_t err; - if (device == -1) { - err = cudaGetDevice(&device); - if (err != cudaSuccess) { - return "Error getting current GPU index"; - } - } - - cudaDeviceProp prop; - err = cudaGetDeviceProperties(&prop, device); - if (err != cudaSuccess) { - snprintf(buf, 1024, "GPU #%d: Invalid device (%d): %s", device, err, cudaGetErrorString(err)); - return buf; - } - - long mem = prop.totalGlobalMem / (1024*1024); - snprintf(buf, 1024, "GPU #%d: %s, with %ldMB", device, prop.name, mem); - return buf; -} - - - } diff --git a/cuda/2d/util.h b/cuda/2d/util.h index 6e36b6e..382d862 100644 --- a/cuda/2d/util.h +++ b/cuda/2d/util.h @@ -79,10 +79,6 @@ void reportCudaError(cudaError_t err); float dotProduct2D(float* D_data, unsigned int pitch, unsigned int width, unsigned int height); -// Return string with CUDA device number, name and memory size. -// Use device == -1 to get info for the current device. -_AstraExport std::string getCudaDeviceString(int device); - } #endif -- cgit v1.2.3