From 17ebcfefa7c42cff61a81bf12a915983b330ed15 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 17 Oct 2017 17:20:40 +0200 Subject: Add astra.astra.get_gpu_info utility function --- cuda/2d/util.cu | 24 ++++++++++++++++++++++++ cuda/2d/util.h | 4 ++++ 2 files changed, 28 insertions(+) (limited to 'cuda/2d') diff --git a/cuda/2d/util.cu b/cuda/2d/util.cu index 09d1a2b..9c1bb28 100644 --- a/cuda/2d/util.cu +++ b/cuda/2d/util.cu @@ -274,5 +274,29 @@ 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 875aae3..31fcfbd 100644 --- a/cuda/2d/util.h +++ b/cuda/2d/util.h @@ -30,6 +30,7 @@ along with the ASTRA Toolbox. If not, see . #include #include +#include #ifdef _MSC_VER @@ -92,6 +93,9 @@ 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); } -- cgit v1.2.3 From d753de051893698bfd1e107a2d03b1a38b55dd91 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 31 Oct 2017 17:10:56 +0100 Subject: Remove some unnecessary includes --- cuda/2d/algo.h | 3 ++- cuda/2d/astra.h | 1 - cuda/2d/cgls.h | 1 - cuda/2d/darthelper.h | 2 +- cuda/2d/em.h | 1 - cuda/2d/sart.h | 1 - cuda/2d/sirt.h | 1 - cuda/2d/util.h | 16 +--------------- 8 files changed, 4 insertions(+), 22 deletions(-) (limited to 'cuda/2d') diff --git a/cuda/2d/algo.h b/cuda/2d/algo.h index dc3bb05..4a75907 100644 --- a/cuda/2d/algo.h +++ b/cuda/2d/algo.h @@ -28,7 +28,8 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_ALGO_H #define _CUDA_ALGO_H -#include "util.h" +#include "astra/Globals.h" +#include "dims.h" namespace astraCUDA { diff --git a/cuda/2d/astra.h b/cuda/2d/astra.h index 78d00e3..c9e0762 100644 --- a/cuda/2d/astra.h +++ b/cuda/2d/astra.h @@ -28,7 +28,6 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_ASTRA_H #define _CUDA_ASTRA_H -#include "fft.h" #include "fbp_filters.h" #include "dims.h" #include "algo.h" diff --git a/cuda/2d/cgls.h b/cuda/2d/cgls.h index 804f943..c45b5a4 100644 --- a/cuda/2d/cgls.h +++ b/cuda/2d/cgls.h @@ -28,7 +28,6 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_CGLS_H #define _CUDA_CGLS_H -#include "util.h" #include "algo.h" namespace astraCUDA { diff --git a/cuda/2d/darthelper.h b/cuda/2d/darthelper.h index a2f1f45..9a2837c 100644 --- a/cuda/2d/darthelper.h +++ b/cuda/2d/darthelper.h @@ -28,7 +28,7 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_ARITH2_H #define _CUDA_ARITH2_H -#include "util.h" +#include "astra/Globals.h" namespace astraCUDA { diff --git a/cuda/2d/em.h b/cuda/2d/em.h index f99e798..15795f7 100644 --- a/cuda/2d/em.h +++ b/cuda/2d/em.h @@ -28,7 +28,6 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_EM_H #define _CUDA_EM_H -#include "util.h" #include "algo.h" namespace astraCUDA { diff --git a/cuda/2d/sart.h b/cuda/2d/sart.h index ab99e66..06051ae 100644 --- a/cuda/2d/sart.h +++ b/cuda/2d/sart.h @@ -28,7 +28,6 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_SART_H #define _CUDA_SART_H -#include "util.h" #include "algo.h" namespace astraCUDA { diff --git a/cuda/2d/sirt.h b/cuda/2d/sirt.h index 488ab0a..7c440d5 100644 --- a/cuda/2d/sirt.h +++ b/cuda/2d/sirt.h @@ -28,7 +28,6 @@ along with the ASTRA Toolbox. If not, see . #ifndef _CUDA_SIRT_H #define _CUDA_SIRT_H -#include "util.h" #include "algo.h" namespace astraCUDA { diff --git a/cuda/2d/util.h b/cuda/2d/util.h index 31fcfbd..6e36b6e 100644 --- a/cuda/2d/util.h +++ b/cuda/2d/util.h @@ -32,21 +32,7 @@ along with the ASTRA Toolbox. If not, see . #include #include -#ifdef _MSC_VER - -#ifdef DLL_EXPORTS -#define _AstraExport __declspec(dllexport) -#define EXPIMP_TEMPLATE -#else -#define _AstraExport __declspec(dllimport) -#define EXPIMP_TEMPLATE extern -#endif - -#else - -#define _AstraExport - -#endif +#include "astra/Globals.h" #include "dims.h" -- cgit v1.2.3 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/2d') 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