summaryrefslogtreecommitdiffstats
path: root/cuda/2d/astra.cu
diff options
context:
space:
mode:
Diffstat (limited to 'cuda/2d/astra.cu')
-rw-r--r--cuda/2d/astra.cu41
1 files changed, 41 insertions, 0 deletions
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;
+}
}