|
1 | 1 | 
|
2 | 2 |
|
3 |
| -# CUBOOL |
| 3 | +# cuBool |
4 | 4 |
|
5 | 5 | [](https://research.jetbrains.org/)
|
6 | 6 | [](https://github.com/JetBrains-Research/cuBool/actions)
|
7 | 7 | [](https://github.com/JetBrains-Research/cuBool/blob/master/LICENSE)
|
8 | 8 |
|
9 |
| -CuBool is a linear boolean algebra library primitives and operations for |
10 |
| -work with dense and sparse matrices written on the NVIDIA CUDA platform. The primary |
| 9 | +**cuBool** is a linear Boolean algebra library primitives and operations for |
| 10 | +work with sparse matrices written on the NVIDIA CUDA platform. The primary |
11 | 11 | goal of the library is implementation, testing and profiling algorithms for
|
12 | 12 | solving *formal-language-constrained problems*, such as *context-free*
|
13 | 13 | and *regular* path queries with various semantics for graph databases.
|
14 | 14 | The library provides C-compatible API, written in the GraphBLAS style,
|
15 |
| -as well as python high-level wrapper with automated resources management. |
| 15 | +as well as python high-level wrapper with automated resources management and fancy syntax sugar. |
16 | 16 |
|
17 |
| -> The name of the library is formed by a combination of words *Cuda* and *Boolean*, |
18 |
| -> what literally means *Cuda with Boolean* and sounds very similar to the name of |
19 |
| -> the programming language *COBOL*. |
| 17 | +**The primary library primitive** is a sparse boolean matrix. The library provides |
| 18 | +the most popular operations for matrix manipulation, such as construction from |
| 19 | +values, transpose, sub-matrix extraction, matrix-to-vector reduce, matrix-matrix |
| 20 | +element-wise addition, matrix-matrix multiplication and Kronecker product. |
| 21 | + |
| 22 | +**As a fallback** library provides sequential backend for mentioned above operations |
| 23 | +for computations on CPU side only. This backend is selected automatically |
| 24 | +if Cuda compatible is not presented in the system. This can be very quite handy for |
| 25 | +prototyping algorithms on a local computer for later running on a powerful server. |
20 | 26 |
|
21 | 27 | ### Features
|
22 | 28 |
|
@@ -55,9 +61,12 @@ as well as python high-level wrapper with automated resources management.
|
55 | 61 | - GCC Compiler
|
56 | 62 | - NVIDIA CUDA toolkit
|
57 | 63 | - Python 3 (for `pycubool` library)
|
58 |
| -- Git |
| 64 | +- Git (to get source code) |
| 65 | + |
| 66 | +### Cuda & Compiler Setup |
59 | 67 |
|
60 |
| -### Setup |
| 68 | +> Skip thia section if you want to build library with only sequential backend |
| 69 | +> without cuda backend support. |
61 | 70 |
|
62 | 71 | Before the CUDA setup process, validate your system NVIDIA driver with `nvidia-smi`
|
63 | 72 | command. if it is need, install required driver via `ubuntu-drivers devices` and
|
@@ -129,7 +138,7 @@ Configure build in Release mode with tests and run actual compilation process:
|
129 | 138 | ```shell script
|
130 | 139 | $ cmake .. -DCMAKE_BUILD_TYPE=Release -DCUBOOL_BUILD_TESTS=ON
|
131 | 140 | $ cmake --build . --target all -j `nproc`
|
132 |
| -$ sh ./scripts/tests_run_all.sh |
| 141 | +$ bash ./scripts/tests_run_all.sh |
133 | 142 | ```
|
134 | 143 |
|
135 | 144 | By default, the following cmake options will be automatically enabled:
|
@@ -159,8 +168,6 @@ which uses this variable in order to located library object.
|
159 | 168 |
|
160 | 169 | ## Usage
|
161 | 170 |
|
162 |
| -### Brief Example |
163 |
| -
|
164 | 171 | The following C++ code snipped demonstrates, how library functions and
|
165 | 172 | primitives can be used for the transitive closure evaluation of the directed
|
166 | 173 | graph, represented as an adjacency matrix with boolean values. The transitive
|
@@ -219,117 +226,6 @@ def transitive_closure(a: pycubool.Matrix):
|
219 | 226 | return t
|
220 | 227 | ```
|
221 | 228 |
|
222 |
| -### Detailed Example |
223 |
| -
|
224 |
| -The following code snippet demonstrates, how to create basic cubool based application |
225 |
| -for sparse matrix-matrix multiplication and matrix-matrix element-wise addition |
226 |
| -with cubool C API usage. |
227 |
| -
|
228 |
| -```c++ |
229 |
| -/************************************************/ |
230 |
| -/* Evaluate transitive closure for some graph G */ |
231 |
| -/************************************************/ |
232 |
| -
|
233 |
| -/* Actual cubool C API */ |
234 |
| -#include <cubool/cubool.h> |
235 |
| -#include <stdio.h> |
236 |
| -
|
237 |
| -/* Macro to check result of the function call */ |
238 |
| -#define CHECK(f) { cuBool_Status s = f; if (s != CUBOOL_STATUS_SUCCESS) return s; } |
239 |
| -
|
240 |
| -int main() { |
241 |
| - cuBool_Matrix A; |
242 |
| - cuBool_Matrix TC; |
243 |
| -
|
244 |
| - /* System may not provide Cuda compatible device */ |
245 |
| - CHECK(cuBool_Initialize(CUBOOL_HINT_NO)); |
246 |
| -
|
247 |
| - /* Input graph G */ |
248 |
| -
|
249 |
| - /* -> (1) -> */ |
250 |
| - /* | | */ |
251 |
| - /* (0) --> (2) <--> (3) */ |
252 |
| -
|
253 |
| - /* Adjacency matrix in sparse format */ |
254 |
| - cuBool_Index n = 4; |
255 |
| - cuBool_Index e = 5; |
256 |
| - cuBool_Index rows[] = { 0, 0, 1, 2, 3 }; |
257 |
| - cuBool_Index cols[] = { 1, 2, 2, 3, 2 }; |
258 |
| -
|
259 |
| - /* Create matrix */ |
260 |
| - CHECK(cuBool_Matrix_New(&A, n, n)); |
261 |
| -
|
262 |
| - /* Fill the data */ |
263 |
| - CHECK(cuBool_Matrix_Build(A, rows, cols, e, CUBOOL_HINT_VALUES_SORTED)); |
264 |
| -
|
265 |
| - /* Now we have created the following matrix */ |
266 |
| -
|
267 |
| - /* [0][1][2][3] |
268 |
| - /* [0] . 1 1 . */ |
269 |
| - /* [1] . . 1 . */ |
270 |
| - /* [2] . . . 1 */ |
271 |
| - /* [3] . . 1 . */ |
272 |
| -
|
273 |
| - /* Create result matrix from source as copy */ |
274 |
| - CHECK(cuBool_Matrix_Duplicate(A, &TC)); |
275 |
| -
|
276 |
| - /* Query current number on non-zero elements */ |
277 |
| - cuBool_Index total = 0; |
278 |
| - cuBool_Index current; |
279 |
| - CHECK(cuBool_Matrix_Nvals(TC, ¤t)); |
280 |
| -
|
281 |
| - /* Loop while values are added */ |
282 |
| - while (current != total) { |
283 |
| - total = current; |
284 |
| -
|
285 |
| - /** Transitive closure step */ |
286 |
| - CHECK(cuBool_MxM(TC, TC, TC, CUBOOL_HINT_ACCUMULATE)); |
287 |
| - CHECK(cuBool_Matrix_Nvals(TC, ¤t)); |
288 |
| - } |
289 |
| -
|
290 |
| - /** Get result */ |
291 |
| - cuBool_Index tc_rows[16], tc_cols[16]; |
292 |
| - CHECK(cuBool_Matrix_ExtractPairs(TC, tc_rows, tc_cols, &total)); |
293 |
| -
|
294 |
| - /** Now tc_rows and tc_cols contain (i,j) pairs of the result G_tc graph */ |
295 |
| -
|
296 |
| - /* [0][1][2][3] |
297 |
| - /* [0] . 1 1 1 */ |
298 |
| - /* [1] . . 1 1 */ |
299 |
| - /* [2] . . 1 1 */ |
300 |
| - /* [3] . . 1 1 */ |
301 |
| -
|
302 |
| - /* Output result size */ |
303 |
| - printf("Nnz(tc)=%lli\n", (unsigned long long) total); |
304 |
| -
|
305 |
| - for (cuBool_Index i = 0; i < total; i++) |
306 |
| - printf("(%u,%u) ", tc_rows[i], tc_cols[i]); |
307 |
| -
|
308 |
| - /* Release resources */ |
309 |
| - CHECK(cuBool_Matrix_Free(A)); |
310 |
| - CHECK(cuBool_Matrix_Free(TC)); |
311 |
| -
|
312 |
| - /* Release library */ |
313 |
| - return cuBool_Finalize() != CUBOOL_STATUS_SUCCESS; |
314 |
| -} |
315 |
| -``` |
316 |
| -
|
317 |
| -Export path to library cubool, compile the file and run with the following |
318 |
| -command (assuming, that source code is placed into tc.cpp file): |
319 |
| -
|
320 |
| -```shell script |
321 |
| -$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:path/to/folder/with/libcubool/" |
322 |
| -$ gcc tc.cpp -o tc -I/path/to/cubool/include/dir/ -L/path/to/folder/with/libcubool/ -lcubool |
323 |
| -$ ./tc |
324 |
| -``` |
325 |
| -
|
326 |
| -The program will print the following output: |
327 |
| -
|
328 |
| -``` |
329 |
| -Nnz(tc)=9 |
330 |
| -(0,1) (0,2) (0,3) (1,2) (1,3) (2,2) (2,3) (3,2) (3,3) |
331 |
| -``` |
332 |
| -
|
333 | 229 | ## Directory structure
|
334 | 230 |
|
335 | 231 | ```
|
@@ -372,4 +268,10 @@ This project is licensed under MIT License. License text can be found in the
|
372 | 268 | ## Acknowledgments
|
373 | 269 |
|
374 | 270 | This is research project of the Programming Languages and Tools Laboratory
|
375 |
| -at Jet-Brains Research company. Laboratory website [link](https://research.jetbrains.org/groups/plt_lab/projects/). |
| 271 | +at JetBrains Research company. Laboratory website [link](https://research.jetbrains.org/groups/plt_lab/). |
| 272 | +
|
| 273 | +## Also |
| 274 | +
|
| 275 | +The name of the library is formed by a combination of words *Cuda* and *Boolean*, |
| 276 | +what literally means *Cuda with Boolean* and sounds very similar to the name of |
| 277 | +the programming language *COBOL*. |
0 commit comments