From 078d8ead72b069ad1ed12f404cdc7bfe138f5226 Mon Sep 17 00:00:00 2001
From: cmoineau <cyril.moineau@cea.fr>
Date: Wed, 17 Apr 2024 07:17:07 +0000
Subject: [PATCH] Add showCudaVersion method.

---
 .../aidge/utils/sys_info/CudaVersionInfo.hpp  | 42 +++++++++++++++++++
 python_binding/pybind_backend_cuda.cpp        |  4 +-
 .../utils/sys_info/pybind_CudaVersionInfo.cpp |  9 ++++
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 include/aidge/utils/sys_info/CudaVersionInfo.hpp
 create mode 100644 python_binding/utils/sys_info/pybind_CudaVersionInfo.cpp

diff --git a/include/aidge/utils/sys_info/CudaVersionInfo.hpp b/include/aidge/utils/sys_info/CudaVersionInfo.hpp
new file mode 100644
index 0000000..f67b071
--- /dev/null
+++ b/include/aidge/utils/sys_info/CudaVersionInfo.hpp
@@ -0,0 +1,42 @@
+#ifndef AIDGE_UTILS_SYS_INFO_CUDA_VERSION_INFO_H
+#define AIDGE_UTILS_SYS_INFO_CUDA_VERSION_INFO_H
+
+#include "aidge/backend/cuda/utils/CudaUtils.hpp"  // CHECK_CUDA_STATUS
+#include "aidge/utils/Log.hpp"
+
+namespace Aidge {
+
+void showCudaVersion() {
+    Log::info("CuDNN version: {}.{}.{}\n", CUDNN_MAJOR, CUDNN_MINOR,
+              CUDNN_PATCHLEVEL);
+
+    int deviceCount = 0;
+    CHECK_CUDA_STATUS(cudaGetDeviceCount(&deviceCount));
+
+    if (deviceCount == 0) {
+        Log::warn("There are no available device(s) that support CUDA");
+    } else {
+        Log::info("Detected {} CUDA Capable device(s)", deviceCount);
+    }
+
+    for (int dev = 0; dev < deviceCount; ++dev) {
+        cudaSetDevice(dev);
+        cudaDeviceProp deviceProp;
+        cudaGetDeviceProperties(&deviceProp, dev);
+
+        Log::info("\nDevice #{}: \"{}\"", dev, deviceProp.name);
+
+        int driverVersion = 0;
+        int runtimeVersion = 0;
+        cudaDriverGetVersion(&driverVersion);
+        cudaRuntimeGetVersion(&runtimeVersion);
+        Log::info(
+            "\tCUDA Driver Version / Runtime Version:          {}.{} / {}.{}",
+            (driverVersion / 1000), ((driverVersion % 100) / 10),
+            (runtimeVersion / 1000), ((runtimeVersion % 100) / 10));
+        Log::info("\tCUDA Capability Major/Minor version number:     {}.{}",
+                  deviceProp.major, deviceProp.minor);
+    }
+}
+}  // namespace Aidge
+#endif  // AIDGE_UTILS_SYS_INFO_CUDA_VERSION_INFO_H
diff --git a/python_binding/pybind_backend_cuda.cpp b/python_binding/pybind_backend_cuda.cpp
index 4b68621..abd1997 100644
--- a/python_binding/pybind_backend_cuda.cpp
+++ b/python_binding/pybind_backend_cuda.cpp
@@ -6,8 +6,10 @@ namespace py = pybind11;
 
 namespace Aidge {
 
-void init_Aidge(py::module& /*m*/){
+void init_cuda_sys_info(py::module& m);
 
+void init_Aidge(py::module& m){
+    init_cuda_sys_info(m);
 }
 
 PYBIND11_MODULE(aidge_backend_cuda, m) {
diff --git a/python_binding/utils/sys_info/pybind_CudaVersionInfo.cpp b/python_binding/utils/sys_info/pybind_CudaVersionInfo.cpp
new file mode 100644
index 0000000..64f6509
--- /dev/null
+++ b/python_binding/utils/sys_info/pybind_CudaVersionInfo.cpp
@@ -0,0 +1,9 @@
+#include <pybind11/pybind11.h>
+#include "aidge/utils/sys_info/CudaVersionInfo.hpp"
+
+namespace py = pybind11;
+namespace Aidge {
+void init_cuda_sys_info(py::module& m){
+    m.def("show_cuda_version", &showCudaVersion);
+}
+}
-- 
GitLab