Skip to content

Commit b956a66

Browse files
authored
Merge pull request #1171 from tinohager/master
Get gpu count and name
2 parents cfc5fed + c021841 commit b956a66

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/yolo_v2_class.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ int dispose() {
6060
return 1;
6161
}
6262

63+
int get_device_count() {
64+
#ifdef GPU
65+
int count = 0;
66+
cudaGetDeviceCount(&count);
67+
return count;
68+
#else
69+
return -1;
70+
#endif // GPU
71+
}
72+
73+
int get_device_name(int gpu, char* deviceName) {
74+
#ifdef GPU
75+
cudaDeviceProp prop;
76+
cudaGetDeviceProperties(&prop, gpu);
77+
std::string result = prop.name;
78+
std::copy(result.begin(), result.end(), deviceName);
79+
return 1;
80+
#else
81+
return -1;
82+
#endif // GPU
83+
}
84+
6385
#ifdef GPU
6486
void check_cuda(cudaError_t status) {
6587
if (status != cudaSuccess) {

src/yolo_v2_class.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ extern "C" YOLODLL_API int init(const char *configurationFilename, const char *w
4949
extern "C" YOLODLL_API int detect_image(const char *filename, bbox_t_container &container);
5050
extern "C" YOLODLL_API int detect_mat(const uint8_t* data, const size_t data_length, bbox_t_container &container);
5151
extern "C" YOLODLL_API int dispose();
52+
extern "C" YOLODLL_API int get_device_count();
53+
extern "C" YOLODLL_API int get_device_name(int gpu, char* deviceName);
5254

5355
class Detector {
5456
std::shared_ptr<void> detector_gpu_ptr;

0 commit comments

Comments
 (0)