@@ -11,10 +11,12 @@ work with dense and sparse matrices written on the NVIDIA CUDA platform. The pri
1111goal of the library is implementation, testing and profiling algorithms for
1212solving * formal-language-constrained problems* , such as * context-free*
1313and * regular* path queries with various semantics for graph databases.
14+ The library provides C-compatible API, written in the GraphBLAS style,
15+ as well as python high-level wrapper with automated resources management.
1416
15- The name of the library is formed by a combination of words * Cuda* and * Boolean* ,
16- what literally means * Cuda with Boolean* and sounds very similar to the name of
17- the programming language * COBOL* .
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* .
1820
1921## Features
2022
@@ -37,11 +39,12 @@ the programming language *COBOL*.
3739
3840## Requirements
3941
40- - Linux Ubuntu 18 or higher (current version is 20.04)
42+ - Linux Ubuntu (tested on 20.04)
4143- CMake Version 3.17 or higher
4244- CUDA Compatible GPU device
4345- GCC 8 Compiler
4446- NVIDIA CUDA 10 toolkit
47+ - Python 3 (for ` pycubool ` library)
4548
4649## Setup
4750
@@ -91,6 +94,14 @@ if you want to build library from the command line only.
9194- [ CUDA Hello world program] ( https://developer.nvidia.com/blog/easy-introduction-cuda-c-and-c/ )
9295- [ CUDA CMake tutorial] ( https://developer.nvidia.com/blog/building-cuda-applications-cmake/ )
9396
97+ ## Python Setup
98+
99+ After the build process, the shared library object ` libcubool.so ` is placed
100+ inside the build directory. Export into the environment or add into bash
101+ profile the variable ` CUBOOL_PATH=/path/to/the/libcubool.so ` with appropriate
102+ path to your setup. Then you will be able to use ` pycubool ` python wrapper,
103+ which uses this variable in order to located library object.
104+
94105## Get and run
95106
96107Run the following commands in the command shell to download the repository,
@@ -103,7 +114,7 @@ $ mkdir build
103114$ cd build
104115$ cmake .. -DCUBOOL_BUILD_TESTS=ON
105116$ cmake --build . --target all -j ` nproc`
106- $ sh .. /scripts/tests_run_all.sh
117+ $ sh ./scripts/tests_run_all.sh
107118```
108119
109120> Note: in order to provide correct GCC version for CUDA sources compiling,
@@ -199,6 +210,130 @@ def transitive_closure(a: pycubool.Matrix):
199210 return t
200211```
201212
213+ ## Basic application
214+
215+ The following code snippet demonstrates, how to create basic cubool based application
216+ for sparse matrix-matrix multiplication and matrix-matrix element-wise addition
217+ with cubool C API usage.
218+
219+ ``` c++
220+ /* ***********************************************/
221+ /* Evaluate transitive closure for some graph G */
222+ /* ***********************************************/
223+
224+ /* Actual cubool C API */
225+ #include < cubool/cubool.h>
226+ #include < stdio.h>
227+
228+ /* Macro to check result of the function call */
229+ #define CHECK (f ) { CuBoolStatus s = f; if (s != CUBOOL_STATUS_SUCCESS) return s; }
230+
231+ int main () {
232+ /* Return code of the operation */
233+ CuBoolStatus status;
234+
235+ /* Declare resources for the application */
236+ CuBoolInstance I;
237+ CuBoolMatrix A;
238+ CuBoolMatrix TC;
239+
240+ /* Initialize instance of the library */
241+ CuBoolInstanceDesc desc{};
242+ desc.memoryType = CUBOOL_GPU_MEMORY_TYPE_GENERIC;
243+
244+ status = CuBool_Instance_New(&desc, &I);
245+
246+ if (status == CUBOOL_STATUS_DEVICE_NOT_PRESENT) {
247+ /* System does not provide Cuda compatible device */
248+ return 1;
249+ }
250+
251+ /* Input graph G */
252+
253+ /* -> (1) -> */
254+ /* | | */
255+ /* (0) --> (2) <--> (3) */
256+
257+ /* Adjacency matrix in sparse format */
258+ CuBoolIndex_t n = 4;
259+ CuBoolSize_t e = 5;
260+ CuBoolIndex_t rows[] = { 0, 0, 1, 2, 3 };
261+ CuBoolIndex_t cols[] = { 1, 2, 2, 3, 2 };
262+
263+ /* Create matrix */
264+ CHECK (CuBool_Matrix_New (I, &A, n, n));
265+
266+ /* Fill the data */
267+ CHECK (CuBool_Matrix_Build (I, A, rows, cols, e, CUBOOL_HINT_VALUES_SORTED));
268+
269+ /* Now we have created the following matrix */
270+
271+ /* [0][1][2][3]
272+ /* [0] . 1 1 . */
273+ /* [1] . . 1 . */
274+ /* [2] . . . 1 */
275+ /* [3] . . 1 . */
276+
277+ /* Create result matrix from source as copy */
278+ CHECK (CuBool_Matrix_Duplicate (I, A, &TC));
279+
280+ /* Query current number on non-zero elements */
281+ CuBoolSize_t total = 0;
282+ CuBoolSize_t current;
283+ CHECK (CuBool_Matrix_Nvals (I, TC, ¤t));
284+
285+ /* Loop while values are added */
286+ while (current != total) {
287+ total = current;
288+
289+ /** Transitive closure step */
290+ CHECK (CuBool_MxM (I, TC, TC, TC));
291+ CHECK(CuBool_Matrix_Nvals(I, TC, ¤t));
292+ }
293+
294+ /** Get result */
295+ CuBoolIndex_t tc_rows[16], tc_cols[16];
296+ CHECK (CuBool_Matrix_ExtractPairs (I, TC, tc_rows, tc_cols, &total));
297+
298+ /** Now tc_rows and tc_cols contain (i,j) pairs of the result G_tc graph */
299+
300+ /* [0][1][2][3]
301+ /* [0] . 1 1 1 */
302+ /* [1] . . 1 1 */
303+ /* [2] . . 1 1 */
304+ /* [3] . . 1 1 */
305+
306+ /* Output result size */
307+ printf ("Nnz(tc)=%lli\n", (unsigned long long) total);
308+
309+ for (CuBoolSize_t i = 0; i < total; i++)
310+ printf ("(%u,%u) ", tc_rows[ i] , tc_cols[ i] );
311+
312+ /* Release resources */
313+ CHECK (CuBool_Matrix_Free (I, A));
314+ CHECK(CuBool_Matrix_Free(I, TC));
315+
316+ /* Release library instance */
317+ return CuBool_Instance_Free(I) != CUBOOL_STATUS_SUCCESS;
318+ }
319+ ```
320+
321+ Export path to library cubool, compile the file and run with the following
322+ command (assuming, that source code is placed into tc.cpp file):
323+
324+ ``` shell script
325+ $ export LD_LIBRARY_PATH=" $LD_LIBRARY_PATH :path/to/folder/with/libcubool/"
326+ $ gcc tc.cpp -o tc -I/path/to/cubool/include/dir/ -Lpath/to/folder/with/libcubool/ -lcubool
327+ $ ./tc
328+ ```
329+
330+ The program will print the following output:
331+
332+ ```
333+ Nnz(tc)=9
334+ (0,1) (0,2) (0,3) (1,2) (1,3) (2,2) (2,3) (3,2) (3,3)
335+ ```
336+
202337## License
203338
204339This project is licensed under MIT License. License text can be found in the
0 commit comments