From c021841a52a7b71224b755bfbf779b05012b59d5 Mon Sep 17 00:00:00 2001
From: Tino Hager <tino.hager@nager.at>
Date: Tue, 10 Jul 2018 19:46:14 +0000
Subject: [PATCH] Get gpu count and name
---
src/yolo_v2_class.cpp | 22 ++++++++++++++++++++++
src/yolo_v2_class.hpp | 2 ++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/yolo_v2_class.cpp b/src/yolo_v2_class.cpp
index 4df9be5..64f2afc 100644
--- a/src/yolo_v2_class.cpp
+++ b/src/yolo_v2_class.cpp
@@ -60,6 +60,28 @@
return 1;
}
+int get_device_count() {
+#ifdef GPU
+ int count = 0;
+ cudaGetDeviceCount(&count);
+ return count;
+#else
+ return -1;
+#endif // GPU
+}
+
+int get_device_name(int gpu, char* deviceName) {
+#ifdef GPU
+ cudaDeviceProp prop;
+ cudaGetDeviceProperties(&prop, gpu);
+ std::string result = prop.name;
+ std::copy(result.begin(), result.end(), deviceName);
+ return 1;
+#else
+ return -1;
+#endif // GPU
+}
+
#ifdef GPU
void check_cuda(cudaError_t status) {
if (status != cudaSuccess) {
diff --git a/src/yolo_v2_class.hpp b/src/yolo_v2_class.hpp
index 8f7f6ca..9ed7dd4 100644
--- a/src/yolo_v2_class.hpp
+++ b/src/yolo_v2_class.hpp
@@ -49,6 +49,8 @@
extern "C" YOLODLL_API int detect_image(const char *filename, bbox_t_container &container);
extern "C" YOLODLL_API int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container);
extern "C" YOLODLL_API int dispose();
+extern "C" YOLODLL_API int get_device_count();
+extern "C" YOLODLL_API int get_device_name(int gpu, char* deviceName);
class Detector {
std::shared_ptr<void> detector_gpu_ptr;
--
Gitblit v1.10.0