Skip to content

Commit 285874e

Browse files
committed
[Cuda] Add mem type query in device caps
1 parent e651ea5 commit 285874e

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

cubool/include/cubool/cubool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ typedef struct cuBool_Vector_t* cuBool_Vector;
118118
typedef struct cuBool_DeviceCaps {
119119
char name[256];
120120
bool cudaSupported;
121+
bool managedMem;
121122
int major;
122123
int minor;
123124
int warp;

cubool/sources/core/library.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ namespace cubool {
249249
void Library::queryCapabilities(cuBool_DeviceCaps &caps) {
250250
caps.name[0] = '\0';
251251
caps.cudaSupported = false;
252+
caps.managedMem = false;
252253
caps.major = 0;
253254
caps.minor = 0;
254255
caps.warp = 0;
@@ -272,6 +273,7 @@ namespace cubool {
272273
<< " name: " << caps.name << ","
273274
<< " major: " << caps.major << ","
274275
<< " minor: " << caps.minor << ","
276+
<< " mem type: " << (caps.managedMem? "managed": "default") << ","
275277
<< " warp size: " << caps.warp << ","
276278
<< " globalMemoryKiBs: " << caps.globalMemoryKiBs << ","
277279
<< " sharedMemoryPerMultiProcKiBs: " << caps.sharedMemoryPerMultiProcKiBs << ","

cubool/sources/cuda/cuda_backend.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace cubool {
9292
}
9393

9494
void CudaBackend::queryCapabilities(cuBool_DeviceCaps &caps) {
95-
CudaInstance::queryDeviceCapabilities(caps);
95+
mInstance->queryDeviceCapabilities(caps);
9696
}
9797

9898
CudaInstance & CudaBackend::getInstance() {

cubool/sources/cuda/cuda_instance.cu

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,7 @@ namespace cubool {
8686
}
8787
}
8888

89-
CudaInstance::MemType CudaInstance::getMemoryType() const {
90-
return mMemoryType;
91-
}
92-
93-
bool CudaInstance::isCudaDeviceSupported() {
94-
int device;
95-
cudaError error = cudaGetDevice(&device);
96-
return error == cudaSuccess;
97-
}
98-
99-
void CudaInstance::queryDeviceCapabilities(cuBool_DeviceCaps &deviceCaps) {
89+
void CudaInstance::queryDeviceCapabilities(cuBool_DeviceCaps &deviceCaps) const {
10090
const unsigned long long KiB = 1024;
10191

10292
int device;
@@ -109,6 +99,7 @@ namespace cubool {
10999
if (error == cudaSuccess) {
110100
strcpy(deviceCaps.name, deviceProp.name);
111101
deviceCaps.cudaSupported = true;
102+
deviceCaps.managedMem = mMemoryType == MemType::Managed;
112103
deviceCaps.minor = deviceProp.minor;
113104
deviceCaps.major = deviceProp.major;
114105
deviceCaps.warp = deviceProp.warpSize;
@@ -119,6 +110,16 @@ namespace cubool {
119110
}
120111
}
121112

113+
CudaInstance::MemType CudaInstance::getMemoryType() const {
114+
return mMemoryType;
115+
}
116+
117+
bool CudaInstance::isCudaDeviceSupported() {
118+
int device;
119+
cudaError error = cudaGetDevice(&device);
120+
return error == cudaSuccess;
121+
}
122+
122123
void CudaInstance::allocate(void* &ptr, size_t size) const {
123124
ptr = malloc(size);
124125
CHECK_RAISE_ERROR(ptr != nullptr, MemOpFailed, "Failed to allocate memory on the CPU");

cubool/sources/cuda/cuda_instance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ namespace cubool {
5151
void allocateOnGpu(void* &ptr, size_t s) const;
5252
void deallocate(void* ptr) const;
5353
void deallocateOnGpu(void* ptr) const;
54+
void queryDeviceCapabilities(cuBool_DeviceCaps& deviceCaps) const;
5455

5556
void syncHostDevice() const;
5657
MemType getMemoryType() const;
5758

5859
static bool isCudaDeviceSupported();
59-
static void queryDeviceCapabilities(cuBool_DeviceCaps& deviceCaps);
6060
static CudaInstance& getInstanceRef();
6161
static CudaInstance* getInstancePtr();
6262
static bool isInstancePresent();

0 commit comments

Comments
 (0)