Skip to content

Commit dc9aaae

Browse files
committed
[Code] Add device caps query support
1 parent e0a49bb commit dc9aaae

18 files changed

+125
-25
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ prototyping algorithms on a local computer for later running on a powerful serve
3737
- [X] CSR matrix reduce
3838
- [X] CSR slicing
3939
- [X] Sequential fallback backend for CPU
40+
- [X] Device capabilities query
4041
- [ ] IO matrix loading from mtx file
4142
- [ ] IO matrix saving into mtx file
4243
- [ ] IO matrix saving into gviz format
43-
- [ ] IO user-defined file logging
44+
- [X] IO user-defined file logging
4445
- [X] Wrapper for Python API
4546
- [ ] Wrapper syntax sugar
4647
- [ ] Tests for Python wrapper

cubool/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ set(CUBOOL_SOURCES
2727

2828
set(CUBOOL_C_API_SOURCES
2929
include/cubool/cubool.h
30-
sources/cuBool_Version_Get.cpp
31-
sources/cuBool_About_Get.cpp
32-
sources/cuBool_LicenseInfo_Get.cpp
30+
sources/cuBool_GetAbout.cpp
31+
sources/cuBool_GetVersion.cpp
32+
sources/cuBool_GetLicenseInfo.cpp
33+
sources/cuBool_GetDeviceCaps.cpp
3334
sources/cuBool_Initialize.cpp
3435
sources/cuBool_Finalize.cpp
3536
sources/cuBool_SetupLogger.cpp

cubool/include/cubool/cubool.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,24 @@ typedef uint32_t cuBool_Index;
102102
typedef struct cuBool_Matrix_t* cuBool_Matrix;
103103

104104
/** Cuda device capabilities */
105-
typedef struct CuBool_DeviceCaps {
105+
typedef struct cuBool_DeviceCaps {
106106
char name[256];
107+
bool cudaSupported;
107108
int major;
108109
int minor;
109110
int warp;
110-
bool cudaSupported;
111-
cuBool_Index globalMemoryKiBs;
112-
cuBool_Index sharedMemoryPerMultiProcKiBs;
113-
cuBool_Index sharedMemoryPerBlockKiBs;
114-
} CuBool_DeviceCaps;
111+
int globalMemoryKiBs;
112+
int sharedMemoryPerMultiProcKiBs;
113+
int sharedMemoryPerBlockKiBs;
114+
} cuBool_DeviceCaps;
115115

116116
/**
117117
* Query human-readable text info about the project implementation
118118
* @note It is safe to call this function before the library is initialized.
119119
*
120120
* @return Read-only library about info
121121
*/
122-
CUBOOL_EXPORT CUBOOL_API const char* cuBool_About_Get(
122+
CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetAbout(
123123
);
124124

125125
/**
@@ -128,7 +128,7 @@ CUBOOL_EXPORT CUBOOL_API const char* cuBool_About_Get(
128128
129129
* @return Read-only library license info
130130
*/
131-
CUBOOL_EXPORT CUBOOL_API const char* cuBool_LicenseInfo_Get(
131+
CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetLicenseInfo(
132132
);
133133

134134
/**
@@ -141,7 +141,7 @@ CUBOOL_EXPORT CUBOOL_API const char* cuBool_LicenseInfo_Get(
141141
*
142142
* @return Error if failed to query version info
143143
*/
144-
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Version_Get(
144+
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_GetVersion(
145145
int* major,
146146
int* minor,
147147
int* sub
@@ -202,8 +202,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Finalize(
202202
*
203203
* @return Error if cuda device not present or if failed to query capabilities
204204
*/
205-
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_DeviceCaps_Get(
206-
CuBool_DeviceCaps* deviceCaps
205+
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_GetDeviceCaps(
206+
cuBool_DeviceCaps* deviceCaps
207207
);
208208

209209
/**

cubool/sources/backend/backend_base.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace cubool {
3838
virtual bool isInitialized() const = 0;
3939
virtual MatrixBase* createMatrix(size_t nrows, size_t ncols) = 0;
4040
virtual void releaseMatrix(MatrixBase* matrixBase) = 0;
41+
virtual void queryCapabilities(cuBool_DeviceCaps& caps) = 0;
4142
};
4243

4344
}

cubool/sources/core/library.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ namespace cubool {
8787

8888
CHECK_RAISE_ERROR(mBackend != nullptr, BackendError, "Failed to select backend");
8989
mRelaxedRelease = initHints & CUBOOL_HINT_RELAXED_FINALIZE;
90+
91+
// Log device caps
92+
cuBool_DeviceCaps caps;
93+
queryCapabilities(caps);
94+
95+
std::stringstream ss;
96+
97+
if (caps.cudaSupported) {
98+
ss << "Cuda device capabilities" << std::endl
99+
<< " name: " << caps.name << std::endl
100+
<< " major: " << caps.major << std::endl
101+
<< " minor: " << caps.minor << std::endl
102+
<< " warp size: " << caps.warp << std::endl
103+
<< " globalMemoryKiBs: " << caps.globalMemoryKiBs << std::endl
104+
<< " sharedMemoryPerMultiProcKiBs: " << caps.sharedMemoryPerMultiProcKiBs << std::endl
105+
<< " sharedMemoryPerBlockKiBs: " << caps.sharedMemoryPerBlockKiBs << std::endl;
106+
}
107+
else {
108+
ss << "Cuda device is not presented";
109+
}
110+
111+
mLogger->logInfo(ss.str());
90112
}
91113

92114
void Library::finalize() {
@@ -187,6 +209,19 @@ namespace cubool {
187209
mLogger->log(Logger::Level::Error, error.what());
188210
}
189211

212+
void Library::queryCapabilities(cuBool_DeviceCaps &caps) {
213+
caps.name[0] = '\0';
214+
caps.cudaSupported = false;
215+
caps.major = 0;
216+
caps.minor = 0;
217+
caps.warp = 0;
218+
caps.globalMemoryKiBs = 0;
219+
caps.sharedMemoryPerBlockKiBs = 0;
220+
caps.sharedMemoryPerMultiProcKiBs = 0;
221+
222+
mBackend->queryCapabilities(caps);
223+
}
224+
190225
class Logger * Library::getLogger() {
191226
return mLogger.get();
192227
}

cubool/sources/core/library.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#include <core/config.hpp>
2929
#include <core/error.hpp>
30-
#include <memory>
3130
#include <unordered_set>
31+
#include <memory>
3232

3333
namespace cubool {
3434

@@ -41,6 +41,7 @@ namespace cubool {
4141
static class MatrixBase *createMatrix(size_t nrows, size_t ncols);
4242
static void releaseMatrix(class MatrixBase *matrixBase);
4343
static void handleError(const std::exception& error);
44+
static void queryCapabilities(cuBool_DeviceCaps& caps);
4445
static class Logger* getLogger();
4546

4647
private:

cubool/sources/cuBool_About_Get.cpp renamed to cubool/sources/cuBool_GetAbout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include <cuBool_Common.hpp>
2626

27-
const char* cuBool_About_Get() {
27+
const char* cuBool_GetAbout() {
2828
static const char about[] =
2929
"CuBool is a linear boolean algebra library primitives and operations for \n"
3030
"work with dense and sparse matrices written on the NVIDIA CUDA platform. The primary \n"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**********************************************************************************/
2+
/* MIT License */
3+
/* */
4+
/* Copyright (c) 2020, 2021 JetBrains-Research */
5+
/* */
6+
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
7+
/* of this software and associated documentation files (the "Software"), to deal */
8+
/* in the Software without restriction, including without limitation the rights */
9+
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
10+
/* copies of the Software, and to permit persons to whom the Software is */
11+
/* furnished to do so, subject to the following conditions: */
12+
/* */
13+
/* The above copyright notice and this permission notice shall be included in all */
14+
/* copies or substantial portions of the Software. */
15+
/* */
16+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
17+
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
18+
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
19+
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
20+
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
21+
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
22+
/* SOFTWARE. */
23+
/**********************************************************************************/
24+
25+
#include <cuBool_Common.hpp>
26+
27+
cuBool_Status cuBool_GetDeviceCaps(
28+
cuBool_DeviceCaps* deviceCaps
29+
) {
30+
CUBOOL_BEGIN_BODY
31+
CUBOOL_VALIDATE_LIBRARY
32+
CUBOOL_ARG_NOT_NULL(deviceCaps)
33+
cubool::Library::queryCapabilities(*deviceCaps);
34+
CUBOOL_END_BODY
35+
}

cubool/sources/cuBool_LicenseInfo_Get.cpp renamed to cubool/sources/cuBool_GetLicenseInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include <cuBool_Common.hpp>
2626

27-
const char* cuBool_LicenseInfo_Get() {
27+
const char* cuBool_GetLicenseInfo() {
2828
static const char license[] =
2929
"MIT License\n"
3030
"\n"

cubool/sources/cuBool_Version_Get.cpp renamed to cubool/sources/cuBool_GetVersion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include <cuBool_Common.hpp>
2626

27-
cuBool_Status cuBool_Version_Get(
27+
cuBool_Status cuBool_GetVersion(
2828
int *major,
2929
int *minor,
3030
int *sub

0 commit comments

Comments
 (0)