From 2895e27613dab0815e9f0f2f0ed7853d31f856b4 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 2 Apr 2014 14:21:59 +0000 Subject: Add global astra_set_gpu_index function --- cuda/2d/algo.cu | 12 +++++++----- cuda/2d/astra.cu | 53 ++++++++++++++++++++++++++++----------------------- cuda/2d/darthelper.cu | 12 +++++++----- cuda/2d/darthelper.h | 2 -- 4 files changed, 43 insertions(+), 36 deletions(-) (limited to 'cuda/2d') diff --git a/cuda/2d/algo.cu b/cuda/2d/algo.cu index 5ae5d08..f04607f 100644 --- a/cuda/2d/algo.cu +++ b/cuda/2d/algo.cu @@ -99,12 +99,14 @@ void ReconAlgo::reset() bool ReconAlgo::setGPUIndex(int iGPUIndex) { - cudaSetDevice(iGPUIndex); - cudaError_t err = cudaGetLastError(); + if (iGPUIndex != -1) { + cudaSetDevice(iGPUIndex); + cudaError_t err = cudaGetLastError(); - // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) - return false; + // Ignore errors caused by calling cudaSetDevice multiple times + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + return false; + } return true; } diff --git a/cuda/2d/astra.cu b/cuda/2d/astra.cu index 5d53da0..2240629 100644 --- a/cuda/2d/astra.cu +++ b/cuda/2d/astra.cu @@ -195,13 +195,15 @@ bool AstraFBP::init(int iGPUIndex) return false; } - cudaSetDevice(iGPUIndex); - cudaError_t err = cudaGetLastError(); + if (iGPUIndex != -1) { + cudaSetDevice(iGPUIndex); + cudaError_t err = cudaGetLastError(); - // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) - { - return false; + // Ignore errors caused by calling cudaSetDevice multiple times + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + { + return false; + } } bool ok = allocateVolume(pData->D_volumeData, pData->dims.iVolWidth+2, pData->dims.iVolHeight+2, pData->volumePitch); @@ -563,13 +565,14 @@ bool astraCudaFP(const float* pfVolume, float* pfSinogram, dims.iVolWidth = iVolWidth; dims.iVolHeight = iVolHeight; - cudaSetDevice(iGPUIndex); - cudaError_t err = cudaGetLastError(); - - // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) - return false; + if (iGPUIndex != -1) { + cudaSetDevice(iGPUIndex); + cudaError_t err = cudaGetLastError(); + // Ignore errors caused by calling cudaSetDevice multiple times + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + return false; + } bool ok; @@ -649,13 +652,14 @@ bool astraCudaFanFP(const float* pfVolume, float* pfSinogram, dims.iVolWidth = iVolWidth; dims.iVolHeight = iVolHeight; - cudaSetDevice(iGPUIndex); - cudaError_t err = cudaGetLastError(); - - // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) - return false; + if (iGPUIndex != -1) { + cudaSetDevice(iGPUIndex); + cudaError_t err = cudaGetLastError(); + // Ignore errors caused by calling cudaSetDevice multiple times + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + return false; + } bool ok; @@ -759,13 +763,14 @@ bool astraCudaFanFP(const float* pfVolume, float* pfSinogram, dims.iVolWidth = iVolWidth; dims.iVolHeight = iVolHeight; - cudaSetDevice(iGPUIndex); - cudaError_t err = cudaGetLastError(); - - // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) - return false; + if (iGPUIndex != -1) { + cudaSetDevice(iGPUIndex); + cudaError_t err = cudaGetLastError(); + // Ignore errors caused by calling cudaSetDevice multiple times + if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) + return false; + } bool ok; diff --git a/cuda/2d/darthelper.cu b/cuda/2d/darthelper.cu index db0036e..28b77cc 100644 --- a/cuda/2d/darthelper.cu +++ b/cuda/2d/darthelper.cu @@ -344,12 +344,14 @@ void dartSmoothing(float* out, const float* in, float b, unsigned int radius, un bool setGPUIndex(int iGPUIndex) { - cudaSetDevice(iGPUIndex); - cudaError_t err = cudaGetLastError(); + if (iGPUIndex != -1) { + cudaSetDevice(iGPUIndex); + cudaError_t err = cudaGetLastError(); - // Ignore errors caused by calling cudaSetDevice multiple times - if (err != cudaSuccess && err != cudaErrorSetOnActiveProcess) - return false; + // 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 e05f01e..3694b96 100644 --- a/cuda/2d/darthelper.h +++ b/cuda/2d/darthelper.h @@ -29,8 +29,6 @@ $Id$ #ifndef _CUDA_ARITH2_H #define _CUDA_ARITH2_H -#include - namespace astraCUDA { void roiSelect(float* out, float radius, unsigned int width, unsigned int height); -- cgit v1.2.3