summaryrefslogtreecommitdiffstats
path: root/cuda
diff options
context:
space:
mode:
Diffstat (limited to 'cuda')
-rw-r--r--cuda/2d/util.cu24
-rw-r--r--cuda/2d/util.h4
2 files changed, 28 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
#include <cuda.h>
#include <driver_types.h>
+#include <string>
#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);
}