Skip to content

Commit bb0a1d7

Browse files
committed
Cleanup: samples
1 parent 82b5a6e commit bb0a1d7

File tree

5 files changed

+289
-119
lines changed

5 files changed

+289
-119
lines changed

samples/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ sample-initialization
6565
sample-axpy
6666
sample-spmv
6767
sample-cg
68-
my-sample
68+
bool-add-sample
69+
bool-mult-sample
6970
spgemm-sample
7071
)
7172

7273
set (SAMPLES_C
7374
sample-initialization-c
7475
sample-norm1-c
75-
my-sample-c
76+
bool-mult-sample-c
7677
)
7778

7879
set(EXAMPLE_TARGETS)

samples/my-sample.cpp renamed to samples/bool-add-sample.cpp

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* ************************************************************************ */
1616

1717
/*! \file
18-
* \brief Simple demonstration code for how to calculate a SpM-dV (Sparse matrix
19-
* times dense Vector) multiply
18+
* \brief Simple demonstration code for how to calculate a SpMM addition
2019
*/
2120

2221
#include <iostream>
@@ -32,43 +31,21 @@
3231
#include "clSPARSE-error.h"
3332

3433
/**
35-
* \brief Sample Sparse Matrix dense Vector multiplication (SPMV C++)
36-
* \details [y = alpha * A*x + beta * y]
34+
* \brief Sample Bool Sparse Matrix Matrix addition
35+
* \details [C = A + A]
3736
*
3837
* A - [m x n] matrix in CSR format
39-
* x - dense vector of n elements
40-
* y - dense vector of m elements
41-
* alpha, beta - scalars
42-
*
43-
*
44-
* Program presents usage of clSPARSE library in csrmv (y = A*x) operation
45-
* where A is sparse matrix in CSR format, x, y are dense vectors.
46-
*
47-
* clSPARSE offers two spmv algorithms for matrix stored in CSR format.
48-
* First one is called vector algorithm, the second one is called adaptve.
49-
* Adaptive version is usually faster but for given matrix additional
50-
* structure (rowBlocks) needs to be calculated first.
51-
*
52-
* To calculate rowBlock structure you have to execute clsparseCsrMetaSize
53-
* for given matrix stored in CSR format. It is enough to calculate the
54-
* structure once, it is related to its nnz pattern.
55-
*
56-
* After the matrix is read from disk with the function
57-
* clsparse<S,D>CsrMatrixfromFile
58-
* the rowBlock structure can be calculated using clsparseCsrMetaCompute
59-
*
60-
* If rowBlocks are calculated the clsparseCsrMatrix.rowBlocks field is not null.
6138
*
6239
* Program is executing by completing following steps:
6340
* 1. Setup OpenCL environment
6441
* 2. Setup GPU buffers
6542
* 3. Init clSPARSE library
66-
* 4. Execute algorithm cldenseSaxpy
43+
* 4. Execute algorithm clsparseBoolScsrElemAdd
6744
* 5. Shutdown clSPARSE library & OpenCL
6845
*
6946
* usage:
7047
*
71-
* sample-spmv path/to/matrix/in/mtx/format.mtx
48+
* bool-add-sample path/to/matrix/in/mtx/format.mtx
7249
*
7350
*/
7451

@@ -221,8 +198,7 @@ int main (int argc, char* argv[])
221198

222199

223200
clsparseBoolCsrMatrix C;
224-
/**Step 4. Call the add algorithm */
225-
// status = clsparseBoolScsrSpGemm(&A, &B, &C, createResult.control );
201+
/**Step 4. Call the addition algorithm */
226202
status = clsparseBoolScsrElemAdd(&A, &B, &C, createResult.control );
227203

228204
std::vector<int> csrRowPtrC_h((C.num_rows + 1), 0);
@@ -235,11 +211,6 @@ int main (int argc, char* argv[])
235211
0,
236212
0,
237213
0);
238-
// for (auto i = csrRowPtrC_h.begin(); i != csrRowPtrC_h.end(); ++i)
239-
// {
240-
// std::cout << *i << ' ';
241-
// }
242-
// std::cout << std::endl;
243214

244215
std::vector<int> csrColIndC_h(C.num_nonzeros, 0);
245216
run_status = clEnqueueReadBuffer(queue(),
@@ -251,12 +222,6 @@ int main (int argc, char* argv[])
251222
0,
252223
0,
253224
0);
254-
// for (auto i = csrColIndC_h.begin(); i != csrColIndC_h.end(); ++i)
255-
// {
256-
// std::cout << *i << ' ';
257-
// }
258-
// std::cout << std::endl;
259-
260225

261226
// CPU ADDITION
262227

@@ -297,24 +262,11 @@ int main (int argc, char* argv[])
297262
dst.clear();
298263
}
299264

300-
// for (auto i = row_ptr_C.begin(); i != row_ptr_C.end(); ++i)
301-
// {
302-
// std::cout << *i << ' ';
303-
// }
304-
// std::cout << std::endl;
305-
306-
// for (auto i = cols_C.begin(); i != cols_C.end(); ++i)
307-
// {
308-
// std::cout << *i << ' ';
309-
// }
310-
// std::cout << std::endl;
311-
312265
// VERIFY RESULTS
313266

314267
assert(csrRowPtrC_h == row_ptr_C);
315268
assert(csrColIndC_h == cols_C);
316269

317-
318270
if (status != clsparseSuccess)
319271
{
320272
std::cout << "Problem with execution SpMV algorithm."

samples/my-sample-c.c renamed to samples/bool-mult-sample-c.c

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
* ************************************************************************ */
1616

1717
/*! \file
18-
* \brief Simple demonstration code for how to calculate a SpM-dV (Sparse matrix
19-
* times dense Vector) multiply
18+
* \brief Simple demonstration code for how to calculate a BoolSpMM multiplication
2019
*/
2120
#include <stdio.h>
2221
#include <stdlib.h>
@@ -32,43 +31,21 @@
3231
#include "clSPARSE-error.h"
3332

3433
/**
35-
* \brief Sample Sparse Matrix dense Vector multiplication (SPMV C++)
36-
* \details [y = alpha * A*x + beta * y]
34+
* \brief Sample Bool Sparse Matrix Matrix multiplication
35+
* \details [C = A * A]
3736
*
3837
* A - [m x n] matrix in CSR format
39-
* x - dense vector of n elements
40-
* y - dense vector of m elements
41-
* alpha, beta - scalars
42-
*
43-
*
44-
* Program presents usage of clSPARSE library in csrmv (y = A*x) operation
45-
* where A is sparse matrix in CSR format, x, y are dense vectors.
46-
*
47-
* clSPARSE offers two spmv algorithms for matrix stored in CSR format.
48-
* First one is called vector algorithm, the second one is called adaptve.
49-
* Adaptive version is usually faster but for given matrix additional
50-
* structure (rowBlocks) needs to be calculated first.
51-
*
52-
* To calculate rowBlock structure you have to execute clsparseCsrMetaSize
53-
* for given matrix stored in CSR format. It is enough to calculate the
54-
* structure once, it is related to its nnz pattern.
55-
*
56-
* After the matrix is read from disk with the function
57-
* clsparse<S,D>CsrMatrixfromFile
58-
* the rowBlock structure can be calculated using clsparseCsrMetaCompute
59-
*
60-
* If rowBlocks are calculated the clsparseBoolCsrMatrix.rowBlocks field is not null.
6138
*
6239
* Program is executing by completing following steps:
6340
* 1. Setup OpenCL environment
6441
* 2. Setup GPU buffers
6542
* 3. Init clSPARSE library
66-
* 4. Execute algorithm cldenseSaxpy
43+
* 4. Execute algorithm clsparseBoolScsrSpGemm
6744
* 5. Shutdown clSPARSE library & OpenCL
6845
*
6946
* usage:
7047
*
71-
* sample-spmv path/to/matrix/in/mtx/format.mtx
48+
* bool-mult-sample-c path/to/matrix/in/mtx/format.mtx
7249
*
7350
*/
7451

@@ -285,26 +262,26 @@ int main(int argc, char* argv[])
285262
printf( "Problem with closing clSPARSE library.\n Error: \n", status);
286263
}
287264

288-
printf("A \n");
265+
// printf("A \n");
289266

290267
clsparseIdx_t* row_ptr_A = malloc((A.num_rows + 1) * sizeof(clsparseIdx_t));
291268
clsparseIdx_t* cols_A = malloc(A.num_nonzeros * sizeof(clsparseIdx_t));
292269
float* vals_A = malloc(A.num_nonzeros * sizeof(float));
293270

294271
returnCsrToHost(A, row_ptr_A, cols_A, vals_A, queue);
295272

296-
printMatrixNonZeros(A.num_rows, row_ptr_A, cols_A);
273+
// printMatrixNonZeros(A.num_rows, row_ptr_A, cols_A);
297274
// printMatrixDense(A, row_ptr_A, cols_A);
298275

299-
printf("C \n");
276+
// printf("C \n");
300277

301278
clsparseIdx_t* row_ptr_C = malloc((C.num_rows + 1) * sizeof(clsparseIdx_t));
302279
clsparseIdx_t* cols_C = malloc(C.num_nonzeros * sizeof(clsparseIdx_t));
303280
float* vals_C = malloc(C.num_nonzeros * sizeof(clsparseIdx_t));
304281

305282
returnCsrToHost(C, row_ptr_C, cols_C, vals_C, queue);
306283

307-
printMatrixNonZeros(C.num_rows, row_ptr_C, cols_C);
284+
// printMatrixNonZeros(C.num_rows, row_ptr_C, cols_C);
308285
// printMatrixDense(C, row_ptr_C, cols_C);
309286

310287
//release mem;

0 commit comments

Comments
 (0)