From e79e1207f2cb06250d2e97a10c4b7097f0120644 Mon Sep 17 00:00:00 2001 From: jpekkila Date: Thu, 8 Aug 2019 20:35:02 +0300 Subject: [PATCH] Added a function for checking whether CUDA-capable devices are available --- include/astaroth.h | 4 ++++ src/core/astaroth.cu | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/astaroth.h b/include/astaroth.h index b071c81..19eee0d 100644 --- a/include/astaroth.h +++ b/include/astaroth.h @@ -49,6 +49,10 @@ AcResult acInit(const AcMeshInfo mesh_info); * called at exit. */ AcResult acQuit(void); +/** Checks whether there are any CUDA devices available. Returns AC_SUCCESS if there is 1 or more, + * AC_FAILURE otherwise. */ +AcResult acCheckDeviceAvailability(void); + /** Synchronizes a specific stream. All streams are synchronized if STREAM_ALL is passed as a * parameter*/ AcResult acSynchronizeStream(const Stream stream); diff --git a/src/core/astaroth.cu b/src/core/astaroth.cu index 1bd0c42..59b6b89 100644 --- a/src/core/astaroth.cu +++ b/src/core/astaroth.cu @@ -19,6 +19,7 @@ // #include "astaroth_defines.h" #include "astaroth.h" +#include "errchk.h" #include "math_utils.h" // int3 + int3 #define AC_GEN_STR(X) #X @@ -51,6 +52,17 @@ acQuit(void) return acNodeDestroy(nodes[0]); } +AcResult +acCheckDeviceAvailability(void) +{ + int device_count; // Separate from num_devices to avoid side effects + ERRCHK_CUDA_ALWAYS(cudaGetDeviceCount(&device_count)); + if (device_count > 0) + return AC_SUCCESS; + else + return AC_FAILURE; +} + AcResult acSynchronize(void) {