Skip to content

Commit eabed83

Browse files
committed
[Code/Python] Python reg-tests:
- Minor fixes in tests structure - Add test data generation and config - Add test run step in CI - Minor readme update
1 parent 7bf439d commit eabed83

File tree

637 files changed

+8928285
-515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

637 files changed

+8928285
-515
lines changed

.github/workflows/ubuntu.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
- uses: actions/checkout@v2
2929
with:
3030
submodules: true
31+
- uses: actions/setup-python@v2
32+
with:
33+
python-version: '3.7'
3134

3235
- name: Install CUDA
3336
env:
@@ -60,4 +63,13 @@ jobs:
6063
- name: Run unit-tests (sequential backend)
6164
working-directory: ${{ env.build_dir }}
6265
run: bash scripts/tests_run_fallback.sh
63-
shell: bash
66+
shell: bash
67+
68+
- name: Run regression-tests (sequential backend)
69+
working-directory: ${{ env.build_dir }}
70+
run: |
71+
cd python
72+
export PYTHONPATH="`pwd`:$PYTHONPATH"
73+
cd tests
74+
python3 -m unittest discover -v
75+
shell: bash

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ prototyping algorithms on a local computer for later running on a powerful serve
4040
- [X] Matrix cached filling
4141
- [X] Sequential fallback backend for CPU
4242
- [X] Device capabilities query
43-
- [ ] IO matrix loading from mtx file
44-
- [ ] IO matrix saving into mtx file
43+
- [X] IO matrix loading from mtx file
44+
- [X] IO matrix saving into mtx file
4545
- [ ] IO matrix saving into gviz format
4646
- [X] IO user-defined file logging
4747
- [X] Wrapper for Python API
4848
- [X] Wrapper syntax sugar
49-
- [ ] Tests for Python wrapper
49+
- [X] Tests for Python wrapper
5050
- [X] Pip package
5151
- [ ] Code examples
5252
- [ ] User guide
@@ -162,12 +162,22 @@ By default, the following cmake options will be automatically enabled:
162162
163163
### Python Wrapper
164164
165-
After the build process, the shared library object `libcubool.so` is placed
166-
inside the build directory. Export into the environment or add into bash
167-
profile the variable `CUBOOL_PATH=/path/to/the/libcubool.so` with appropriate
168-
path to your setup. Then you will be able to use `pycubool` python wrapper,
169-
which uses this variable in order to located library object.
165+
**Export** env variable `PYTHONPATH="/build_dir_path/python/:$PYTHONPATH"` if
166+
you want to use `pycubool` without installation into default python packages dir.
167+
This variable will help python find package if you import it as `import pycubool` in your python scripts.
170168
169+
**To run regression tests** within your build directory, open folder `/build_dir_path/python` and
170+
run the following command:
171+
172+
```shell script
173+
$ export PYTHONPATH="`pwd`:$PYTHONPATH"
174+
$ cd tests
175+
$ python3 -m unittest discover -v
176+
```
177+
178+
**Note:** after the build process, the shared library object `libcubool.so` will be placed
179+
inside the build directory in the folder with python wrapper `python/pycubool/`.
180+
So, the wrapper will be able to automatically locate required lib file.
171181
172182
## Usage
173183

cubool/tests/test_matrix_mxm.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,39 @@ void testMatrixMultiplyAdd(cuBool_Index m, cuBool_Index t, cuBool_Index n, float
5858
ASSERT_EQ(cuBool_Matrix_Free(r), CUBOOL_STATUS_SUCCESS);
5959
}
6060

61+
void testMatrixMultiply(cuBool_Index m, cuBool_Index t, cuBool_Index n, float density, cuBool_Hints flags) {
62+
cuBool_Matrix a, b, r;
63+
64+
// Generate test data with specified density
65+
testing::Matrix ta = testing::Matrix::generateSparse(m, t, density);
66+
testing::Matrix tb = testing::Matrix::generateSparse(t, n, density);
67+
testing::Matrix tr = testing::Matrix::empty(m, n);
68+
69+
// Allocate input matrices and resize to fill with input data
70+
ASSERT_EQ(cuBool_Matrix_New(&a, m, t), CUBOOL_STATUS_SUCCESS);
71+
ASSERT_EQ(cuBool_Matrix_New(&b, t, n), CUBOOL_STATUS_SUCCESS);
72+
ASSERT_EQ(cuBool_Matrix_New(&r, m, n), CUBOOL_STATUS_SUCCESS);
73+
74+
// Transfer input data into input matrices
75+
ASSERT_EQ(cuBool_Matrix_Build(a, ta.rowsIndex.data(), ta.colsIndex.data(), ta.nvals, CUBOOL_HINT_VALUES_SORTED & CUBOOL_HINT_NO_DUPLICATES), CUBOOL_STATUS_SUCCESS);
76+
ASSERT_EQ(cuBool_Matrix_Build(b, tb.rowsIndex.data(), tb.colsIndex.data(), tb.nvals, CUBOOL_HINT_VALUES_SORTED & CUBOOL_HINT_NO_DUPLICATES), CUBOOL_STATUS_SUCCESS);
77+
78+
// Evaluate naive r += a x b on the cpu to compare results
79+
testing::MatrixMultiplyFunctor functor;
80+
tr = std::move(functor(ta, tb, tr, false));
81+
82+
// Evaluate r += a x b
83+
ASSERT_EQ(cuBool_MxM(r, a, b, flags), CUBOOL_STATUS_SUCCESS);
84+
85+
// Compare results
86+
ASSERT_EQ(tr.areEqual(r), true);
87+
88+
// Deallocate matrices
89+
ASSERT_EQ(cuBool_Matrix_Free(a), CUBOOL_STATUS_SUCCESS);
90+
ASSERT_EQ(cuBool_Matrix_Free(b), CUBOOL_STATUS_SUCCESS);
91+
ASSERT_EQ(cuBool_Matrix_Free(r), CUBOOL_STATUS_SUCCESS);
92+
}
93+
6194
void testRun(cuBool_Index m, cuBool_Index t, cuBool_Index n, cuBool_Hints setup) {
6295
// Setup library
6396
ASSERT_EQ(cuBool_Initialize(setup), CUBOOL_STATUS_SUCCESS);
@@ -66,37 +99,41 @@ void testRun(cuBool_Index m, cuBool_Index t, cuBool_Index n, cuBool_Hints setup)
6699
testMatrixMultiplyAdd(m, t, n, 0.1f + (0.05f) * ((float) i), CUBOOL_HINT_NO);
67100
}
68101

102+
for (size_t i = 0; i < 5; i++) {
103+
testMatrixMultiply(m, t, n, 0.1f + (0.05f) * ((float) i), CUBOOL_HINT_NO);
104+
}
105+
69106
// Finalize library
70107
ASSERT_EQ(cuBool_Finalize(), CUBOOL_STATUS_SUCCESS);
71108
}
72109

73-
TEST(cuBool_Matrix, MultiplyAddSmall) {
110+
TEST(cuBool_Matrix, MultiplySmall) {
74111
cuBool_Index m = 60, t = 100, n = 80;
75112
testRun(m, t, n, CUBOOL_HINT_NO);
76113
}
77114

78-
TEST(cuBool_Matrix, MultiplyAddMedium) {
115+
TEST(cuBool_Matrix, MultiplyMedium) {
79116
cuBool_Index m = 500, t = 1000, n = 800;
80117
testRun(m, t, n, CUBOOL_HINT_NO);
81118
}
82119

83-
TEST(cuBool_Matrix, MultiplyAddLarge) {
120+
TEST(cuBool_Matrix, MultiplyLarge) {
84121
cuBool_Index m = 1000, t = 2000, n = 500;
85122
testRun(m, t, n, CUBOOL_HINT_NO);
86123
}
87124

88-
TEST(cuBool_Matrix, MultiplyAddSmallFallback) {
125+
TEST(cuBool_Matrix, MultiplySmallFallback) {
89126
cuBool_Index m = 60, t = 100, n = 80;
90127
testRun(m, t, n, CUBOOL_HINT_CPU_BACKEND);
91128
}
92129

93-
TEST(cuBool_Matrix, MultiplyAddMediumFallback) {
130+
TEST(cuBool_Matrix, MultiplyMediumFallback) {
94131
cuBool_Index m = 500, t = 1000, n = 800;
95132
testRun(m, t, n, CUBOOL_HINT_CPU_BACKEND);
96133

97134
}
98135

99-
TEST(cuBool_Matrix, MultiplyAddLargeFallback) {
136+
TEST(cuBool_Matrix, MultiplyLargeFallback) {
100137
cuBool_Index m = 1000, t = 2000, n = 500;
101138
testRun(m, t, n, CUBOOL_HINT_CPU_BACKEND);
102139
}

cubool/utils/testing/matrix.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ namespace testing {
218218
return std::move(matrix);
219219
}
220220

221+
static Matrix empty(size_t nrows, size_t ncols) {
222+
Matrix out;
223+
out.nrows = nrows;
224+
out.ncols = ncols;
225+
return std::move(out);
226+
}
227+
221228
};
222229

223230
}

0 commit comments

Comments
 (0)