Skip to content

Commit 26d17c6

Browse files
authored
Merge pull request #6 from JetBrains-Research/master
Pulling changes
2 parents 93cbc67 + 7dbbe72 commit 26d17c6

File tree

16 files changed

+359
-93
lines changed

16 files changed

+359
-93
lines changed

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
# Add this file as sub-directory to your project to use library functionality
33

44
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
5-
project(cubool LANGUAGES CXX)
5+
project(cuBool LANGUAGES CXX)
66

77
# Exposed to the user build options
8-
option(CUBOOL_WITH_CUDA "Build library with cuda backend (default)" ON)
9-
option(CUBOOL_WITH_SEQUENTIAL "Build library with cpu sequential backend (fallback)" ON)
10-
option(CUBOOL_WITH_NAIVE "Build library with naive and naive-shared dense matrix multiplication" OFF)
11-
option(CUBOOL_BUILD_TESTS "Build project unit-tests with gtest" ON)
8+
option(CUBOOL_WITH_CUDA "Build library with cuda backend (default)" ON)
9+
option(CUBOOL_WITH_SEQUENTIAL "Build library with cpu sequential backend (fallback)" ON)
10+
option(CUBOOL_WITH_NAIVE "Build library with naive and naive-shared dense matrix multiplication" OFF)
11+
option(CUBOOL_BUILD_TESTS "Build project unit-tests with gtest" ON)
12+
option(CUBOOL_COPY_TO_PY_PACKAGE "Copy compiled shared library into python package folder (for package use purposes)" ON)
1213

1314
set(CUBOOL_VERSION_MAJOR 1)
1415
set(CUBOOL_VERSION_MINOR 0)

README.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![JB Research](https://jb.gg/badges/research-flat-square.svg)](https://research.jetbrains.org/)
66
[![Ubuntu](https://github.com/JetBrains-Research/cuBool/workflows/Ubuntu/badge.svg?branch=master)](https://github.com/JetBrains-Research/cuBool/actions)
77
[![License](https://img.shields.io/badge/license-MIT-orange)](https://github.com/JetBrains-Research/cuBool/blob/master/LICENSE)
8-
[![Package](https://img.shields.io/badge/pypi%20package-alpha-%233776ab)](https://test.pypi.org/project/pycubool/)
8+
[![Package](https://img.shields.io/badge/pypi%20package-1.0.0-%233776ab)](https://pypi.org/project/pycubool/)
99

1010
**cuBool** is a linear Boolean algebra library primitives and operations for
1111
work with sparse matrices written on the NVIDIA CUDA platform. The primary
@@ -28,6 +28,8 @@ for computations on CPU side only. This backend is selected automatically
2828
if Cuda compatible device is not presented in the system. This can be quite handy for
2929
prototyping algorithms on a local computer for later running on a powerful server.
3030

31+
**PyPI package web page** is following [link](https://pypi.org/project/pycubool/).
32+
3133
### Features
3234

3335
- [X] Library C interface
@@ -45,29 +47,50 @@ prototyping algorithms on a local computer for later running on a powerful serve
4547
- [X] Device capabilities query
4648
- [X] IO matrix loading from mtx file
4749
- [X] IO matrix saving into mtx file
48-
- [ ] IO matrix saving into gviz format
50+
- [X] IO matrix saving into gviz format
4951
- [X] IO user-defined file logging
5052
- [X] Wrapper for Python API
5153
- [X] Wrapper syntax sugar
5254
- [X] Tests for Python wrapper
5355
- [X] Pip package
54-
- [ ] Code examples
55-
- [ ] User guide
56+
- [X] Code examples
57+
- [X] User guide
5658
- [X] Unit Tests collection
57-
- [ ] Publish built artifacts and shared libs
58-
- [ ] Publish stable source code archives
59+
- [X] Publish built artifacts and shared libs
60+
- [X] Publish stable source code archives
61+
62+
## Simple example
63+
64+
Create sparse matrices, compute matrix-matrix product and print the result to the output:
65+
66+
```python
67+
import pycubool as cb
68+
69+
a = cb.Matrix.empty(shape=(2, 3))
70+
a[0, 0] = True
71+
a[1, 2] = True
72+
73+
b = cb.Matrix.empty(shape=(3, 4))
74+
b[0, 1] = True
75+
b[0, 2] = True
76+
b[1, 3] = True
77+
b[2, 1] = True
78+
79+
print(a, b, a.mxm(b), sep="\n")
80+
```
5981

6082
## Installation
6183

62-
If you are running OS **Ubuntu 20.04** or higher you can download the official
84+
If you are running **Linux based** OS (tested on Ubuntu 20.04) you can download the official
6385
PyPI **pycubool** python package, which includes compiled library source code
6486
with Cuda and Sequential computations support. Installation process
6587
requires only `python3` to be installed on your machine. Python can be installed
6688
as follows [link](https://phoenixnap.com/kb/how-to-install-python-3-ubuntu).
6789

6890
If all requirements are satisfied, run the following command to install PyPI package:
91+
6992
```shell script
70-
$ python3 -m pip install -i https://test.pypi.org/simple/ pycubool
93+
$ python3 -m pip install pycubool
7194
```
7295

7396
## Getting Started
@@ -77,11 +100,11 @@ These steps are required if you want to build library for your specific platform
77100

78101
### Requirements
79102

80-
- Linux Ubuntu (tested on 20.04)
103+
- Linux based (tested on Ubuntu 20.04)
81104
- CMake Version 3.15 or higher
82-
- CUDA Compatible GPU device
105+
- CUDA Compatible GPU device (to run Cuda computations)
83106
- GCC Compiler
84-
- NVIDIA CUDA toolkit
107+
- NVIDIA CUDA toolkit (to build Cuda backend)
85108
- Python 3 (for `pycubool` library)
86109
- Git (to get source code)
87110

@@ -237,9 +260,9 @@ wrapper can be used to compute the same transitive closure problem for the
237260
directed graph within python environment:
238261
239262
```python
240-
import pycubool
263+
import pycubool as cb
241264
242-
def transitive_closure(a: pycubool.Matrix):
265+
def transitive_closure(a: cb.Matrix):
243266
"""
244267
Evaluates transitive closure for the provided
245268
adjacency matrix of the graph.
@@ -296,7 +319,7 @@ cuBool
296319
## Citation
297320
298321
```ignorelang
299-
@online{cuBool,
322+
@MISC{cuBool,
300323
author = {Orachyov, Egor and Alimov, Pavel and Grigorev, Semyon},
301324
title = {cuBool: sparse Boolean linear algebra for Nvidia Cuda},
302325
year = 2020,

cubool/CMakeLists.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,16 @@ if (CUBOOL_BUILD_TESTS)
178178
add_subdirectory(tests)
179179
endif()
180180

181-
# todo: Different platforms has specific naming conventions
182-
set(LIBRARY_FILE_NAME "libcubool.so")
183-
184-
# Copy cubool library after build
185-
add_custom_command(
186-
TARGET cubool POST_BUILD
187-
COMMAND "${CMAKE_COMMAND}" -E
188-
copy
189-
"${CMAKE_BINARY_DIR}/cubool/${LIBRARY_FILE_NAME}"
190-
"${CMAKE_BINARY_DIR}/python/pycubool"
191-
COMMENT "Copy cubool lib into python folder")
181+
# Copy cubool library after build if allowed
182+
if (CUBOOL_COPY_TO_PY_PACKAGE)
183+
# todo: Different platforms has specific naming conventions
184+
set(LIBRARY_FILE_NAME "libcubool.so")
185+
186+
add_custom_command(
187+
TARGET cubool POST_BUILD
188+
COMMAND "${CMAKE_COMMAND}" -E
189+
copy
190+
"${CMAKE_BINARY_DIR}/cubool/${LIBRARY_FILE_NAME}"
191+
"${CMAKE_BINARY_DIR}/python/pycubool"
192+
COMMENT "Copy cubool compiled lib into python folder")
193+
endif()

cubool/include/cubool/cubool.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
#endif
3333

3434
// Preserve C names in shared library
35-
#define CUBOOL_EXPORT extern "C"
35+
#ifdef __cplusplus
36+
#define CUBOOL_EXPORT extern "C"
37+
#else
38+
#define CUBOOL_EXPORT
39+
#endif
3640

3741
// Exporting/importing symbols for Microsoft Visual Studio
3842
#if (_MSC_VER && !__INTEL_COMPILER)
@@ -286,6 +290,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_SetMarker(
286290
* @note Pass null marker if you want to retrieve only the required marker buffer size.
287291
* @note After the function call the actual size of the marker is stored in the size variable.
288292
*
293+
* @note size is set to the actual marker length plus null terminator symbol.
294+
* For marker "matrix" size variable will be set to 7.
295+
*
289296
* @param matrix Matrix handle to perform operation on
290297
* @param[in,out] marker Where to store null-terminated UTF-8 encoded marker string.
291298
* @param[in,out] size Size of the provided buffer in bytes to save marker string.

cubool/sources/cuBool_Matrix_Marker.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <cuBool_Common.hpp>
2626
#include <cstring>
27+
#include <cmath>
2728

2829
cuBool_Status cuBool_Matrix_Marker(
2930
cuBool_Matrix matrix,
@@ -37,11 +38,15 @@ cuBool_Status cuBool_Matrix_Marker(
3738

3839
auto m = (cubool::Matrix*) matrix;
3940
auto actualSize = m->getDebugMarkerSizeWithNullT();
41+
auto toCopy = std::min(*size, actualSize);
4042

41-
if (marker != nullptr && *size > 0) {
43+
if (marker != nullptr && toCopy > 0) {
44+
// C str (with \0)
4245
const auto* text = m->getDebugMarker();
43-
std::memcpy(marker, text, *size);
44-
marker[*size - 1] = '\0';
46+
std::memcpy(marker, text, toCopy);
47+
48+
// Explicitly terminate (for case size < actualSize)
49+
marker[toCopy - 1] = '\0';
4550
}
4651

4752
*size = actualSize;

cubool/sources/cuda/matrix_csr.cu

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

2525
#include <cuda/matrix_csr.hpp>
2626
#include <core/error.hpp>
27-
#include <utils/exclusive_scan.hpp>
2827
#include <utils/timer.hpp>
2928
#include <algorithm>
3029

@@ -96,7 +95,7 @@ namespace cubool {
9695
return mMatrixImpl.m_vals == 0;
9796
}
9897

99-
void MatrixCsr::transferToDevice(const std::vector<index> &rowOffsets, const std::vector<index> &colIndices) {
98+
void MatrixCsr::transferToDevice(const std::vector<index> &rowOffsets, const std::vector<index> &colIndices) const {
10099
// Create device buffers and copy data from the cpu side
101100
thrust::device_vector<index, DeviceAlloc<index>> rowsDeviceVec(rowOffsets.size());
102101
thrust::device_vector<index, DeviceAlloc<index>> colsDeviceVec(colIndices.size());

cubool/sources/cuda/matrix_csr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace cubool {
6565
void clearAndResizeStorageToDim() const;
6666
bool isStorageEmpty() const;
6767
bool isMatrixEmpty() const;
68-
void transferToDevice(const std::vector<index> &rowOffsets, const std::vector<index> &colIndices);
68+
void transferToDevice(const std::vector<index> &rowOffsets, const std::vector<index> &colIndices) const;
6969
void transferFromDevice(std::vector<index> &rowOffsets, std::vector<index> &colIndices) const;
7070

7171
// Uses nsparse csr matrix implementation as a backend

cubool/tests/test_matrix_misc.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/**********************************************************************************/
2424

2525
#include <testing/testing.hpp>
26+
#include <cstring>
2627

2728
TEST(cuBool_Matrix, Duplicate) {
2829
cuBool_Matrix matrix = nullptr, duplicated = nullptr;
@@ -98,4 +99,55 @@ TEST(cuBool_Matrix, ExtractPairs) {
9899
ASSERT_EQ(cuBool_Finalize(), CUBOOL_STATUS_SUCCESS);
99100
}
100101

102+
TEST(cuBool_Matrix, Marker) {
103+
cuBool_Matrix matrix = nullptr;
104+
cuBool_Index m, n;
105+
106+
m = n = 100;
107+
108+
const cuBool_Index BUFFER_SIZE = 100;
109+
const char* marker = "Test Matrix Marker";
110+
cuBool_Index size = 0;
111+
char buffer[BUFFER_SIZE];
112+
113+
ASSERT_EQ(cuBool_Initialize(CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS);
114+
ASSERT_EQ(cuBool_Matrix_New(&matrix, m, n), CUBOOL_STATUS_SUCCESS);
115+
ASSERT_EQ(cuBool_Matrix_SetMarker(matrix, marker), CUBOOL_STATUS_SUCCESS);
116+
ASSERT_EQ(cuBool_Matrix_Marker(matrix, nullptr, &size), CUBOOL_STATUS_SUCCESS);
117+
ASSERT_LE(size, BUFFER_SIZE);
118+
ASSERT_EQ(cuBool_Matrix_Marker(matrix, buffer, &size), CUBOOL_STATUS_SUCCESS);
119+
ASSERT_EQ(cuBool_Matrix_Free(matrix), CUBOOL_STATUS_SUCCESS);
120+
ASSERT_EQ(cuBool_Finalize(), CUBOOL_STATUS_SUCCESS);
121+
122+
ASSERT_EQ(std::strlen(buffer), size - 1);
123+
ASSERT_LE(std::strcmp(marker, buffer), 0);
124+
125+
std::cout << "Source marker: " << marker << std::endl;
126+
std::cout << "Returned marker: " << buffer << std::endl;
127+
}
128+
129+
TEST(cuBool_Matrix, MarkerShort) {
130+
cuBool_Matrix matrix = nullptr;
131+
cuBool_Index m, n;
132+
133+
m = n = 100;
134+
135+
const cuBool_Index BUFFER_SIZE = 10;
136+
const char* marker = "Test Matrix Marker";
137+
cuBool_Index size = BUFFER_SIZE;
138+
char buffer[BUFFER_SIZE];
139+
140+
ASSERT_EQ(cuBool_Initialize(CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS);
141+
ASSERT_EQ(cuBool_Matrix_New(&matrix, m, n), CUBOOL_STATUS_SUCCESS);
142+
ASSERT_EQ(cuBool_Matrix_SetMarker(matrix, marker), CUBOOL_STATUS_SUCCESS);
143+
ASSERT_EQ(cuBool_Matrix_Marker(matrix, buffer, &size), CUBOOL_STATUS_SUCCESS);
144+
ASSERT_EQ(cuBool_Matrix_Free(matrix), CUBOOL_STATUS_SUCCESS);
145+
ASSERT_EQ(cuBool_Finalize(), CUBOOL_STATUS_SUCCESS);
146+
147+
ASSERT_GE(std::strcmp(marker, buffer), 0);
148+
149+
std::cout << "Source marker: " << marker << std::endl;
150+
std::cout << "Returned marker: " << buffer << std::endl;
151+
}
152+
101153
CUBOOL_GTEST_MAIN

docs/pictures/gviz_example.png

24.6 KB
Loading

0 commit comments

Comments
 (0)