Skip to content

Commit 265ca7a

Browse files
author
Kent Knox
committed
Merge pull request #180 from kknox/hide-the-meta
Hide the meta & API refactoring 👍
2 parents e48adf4 + 16adb73 commit 265ca7a

50 files changed

Lines changed: 674 additions & 627 deletions

Some content is hidden

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

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ endif()
3838
if( POLICY CMP0048 )
3939
cmake_policy( SET CMP0048 NEW )
4040

41-
project( SuperBuild.clSPARSE VERSION 0.9.0.0 )
41+
project( SuperBuild.clSPARSE VERSION 0.10.0.0 )
4242
else( )
4343
project( SuperBuild.clSPARSE )
4444

@@ -48,7 +48,7 @@ else( )
4848
endif( )
4949

5050
if( NOT DEFINED SuperBuild.clSPARSE_VERSION_MINOR )
51-
set( SuperBuild.clSPARSE_VERSION_MINOR 9 )
51+
set( SuperBuild.clSPARSE_VERSION_MINOR 10 )
5252
endif( )
5353

5454
if( NOT DEFINED SuperBuild.clSPARSE_VERSION_PATCH )

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,26 @@ an OpenCL™ library implementing Sparse linear algebra routines. This proj
1111
a collaboration between [AMD Inc.](http://www.amd.com/) and
1212
[Vratis Ltd.](http://www.vratis.com/).
1313

14-
### What's new in clSPARSE **v0.8**
15-
- New single precision SpM-SpM (SpGEMM) function
16-
- Optimizations to the sparse matrix conversion routines
17-
- [API documentation](http://clmathlibraries.github.io/clSPARSE/) available
18-
- SpM-dV routines now provide [higher precision accuracy] (https://github.com/clMathLibraries/clSPARSE/wiki/Precision)
19-
- Various bug fixes integrated
14+
### What's new in clSPARSE **v0.10**
15+
**This release introduces breaking API changes from the prior version**. clSPARSE is still in a beta phase, and we may need to change the API at times to increase maintainability or fix design issues. A few changes are introduced to more closely follow the recently published [Cpp Core Guidelines](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.html), a strong candidate to be the coding guidelines to be used in clSPARSE. Changes are noted below.
16+
- The API to create meta data for a csr encoded sparse matrix has changed. This is an attempt to hide the implementation details of how meta data is stored from the user. This allows the library freedom to change and iterate meta data without breaking clients.
17+
- `clsparseCsrMetaCompute()` renamed to `clsparseCsrMetaCreate()`, to more intuitively pair with the
18+
- New API `clsparseCsrMetaDelete()`
19+
- A few routines changed pure 'out' parameters to be returned on the stack as structs<sup>[1](#return-tuple)</sup>
20+
- `clsparseCreateControl()`
21+
- `clsparseGetEvent()`
22+
- `clsparseCreateSolverControl()`
23+
- `clsparseCsrMetaSize()`
24+
- A new index type has been introduced `clsparseIdx_t` to abstract the size of an index from the library interface; the only choice currently is 4 bytes. If users use this datatype for indices in their code, changing to 8-byte indices in the future should only be a recompile.
25+
- The names of member variables in our public structs have been renamed for consistency. Before, our member variables was not consistent with camel case and underscore naming. Member variables are now standardized to use underscores, but we keep camel casing for function and struct names<sup>[2](#consistent-naming)</sup>
26+
- `colIndices` to `col_indices`
27+
- `rowIndices` to `row_indices`
28+
- `rowOffsets` to `row_pointer` (renamed to pointer to remove confusion with buffer offsets for cl1.2)
29+
- `offValues` to `off_values`
30+
- `offColInd` to `off_col_indices`
31+
- `offRowOff` to `off_row_pointer`
32+
- `offValues` to `off_values`
33+
- All samples have been changed to compile with the above changes.
2034

2135

2236
## clSPARSE features
@@ -34,7 +48,7 @@ projects to build wrappers around clSPARSE in any language they need. A great d
3448
of thought and effort went into designing the API’s to make them less ‘cluttered’
3549
compared to the older clMath libraries. OpenCL state is not explicitly passed
3650
through the API, which enables the library to be forward compatible when users are
37-
ready to switch from OpenCL 1.2 to OpenCL 2.0 <sup>[1](#opencl-2)</sup>
51+
ready to switch from OpenCL 1.2 to OpenCL 2.0 <sup>[3](#opencl-2)</sup>
3852

3953
### Google Groups
4054
Two mailing lists have been created for the clMath projects:
@@ -105,5 +119,9 @@ clSPARSE is licensed under the [Apache License, Version 2.0](http://www.apache.o
105119
- Googletest v1.7
106120
- Boost v1.58
107121

108-
## Clarifications
109-
<a name="opencl-2">[1]</a>: OpenCL 2.0 support is not yet fully implemented; only the interfaces have been designed
122+
## Footnotes
123+
<a name="return-tuple">[1]</a>: Changed to reflect CppCoreGuidelines: [F.21](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.html#a-namerf-out-multia-f21-to-return-multiple-out-values-prefer-returning-a-tuple-or-struct)
124+
125+
<a name="consistent-naming">[2]</a>: Changed to reflect CppCoreGuidelines: [NL.8](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.html#a-namerl-namea-nl8-use-a-consistent-naming-style)
126+
127+
<a name="opencl-2">[3]</a>: OpenCL 2.0 support is not yet fully implemented; only the interfaces have been designed

cmake/ExternalBoost.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include( ExternalProject )
2424
# ExternalProject
2525

2626
# Change this one line to upgrade to newer versions of boost
27-
set( ext.Boost_VERSION "1.59.0" CACHE STRING "Boost version to download/use" )
27+
set( ext.Boost_VERSION "1.60.0" CACHE STRING "Boost version to download/use" )
2828
mark_as_advanced( ext.Boost_VERSION )
2929
string( REPLACE "." "_" ext.Boost_Version_Underscore ${ext.Boost_VERSION} )
3030

@@ -105,7 +105,7 @@ elseif( DEFINED ENV{CC} )
105105
list( APPEND Boost.Command toolset=${gccToolset} )
106106
endif( )
107107

108-
if( WIN32 )
108+
if( WIN32 AND (ext.Boost_VERSION VERSION_LESS "1.60.0") )
109109
list( APPEND Boost.Command define=BOOST_LOG_USE_WINNT6_API )
110110
endif( )
111111

@@ -151,16 +151,16 @@ if( WIN32 )
151151

152152
if( CMAKE_VERSION VERSION_LESS "3.1.0" )
153153
# .zip file
154-
set( ext.MD5_HASH "08d29a2d85db3ebc8c6fdfa3a1f2b83c" )
154+
set( ext.MD5_HASH "0cc5b9cf9ccdf26945b225c7338b4288" )
155155
else( )
156156
# .7z file
157-
set( ext.MD5_HASH "0a2e512844f3e30a6240f8139ee983f3" )
157+
set( ext.MD5_HASH "7ce7f5a4e396484da8da6b60d4ed7661" )
158158
endif( )
159159
else( )
160160
set( Boost.Bootstrap "./bootstrap.sh" )
161161

162162
# .tar.bz2
163-
set( ext.MD5_HASH "6aa9a5c6a4ca1016edd0ed1178e3cb87" )
163+
set( ext.MD5_HASH "65a840e1a0b13a558ff19eeb2c4f0cbe" )
164164

165165
if( XCODE_VERSION )
166166
list( APPEND Boost.Bootstrap --with-toolset=clang )

samples/sample-axpy.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include <CL/cl.hpp>
2929
#endif
3030

31-
#include <clSPARSE.h>
31+
#include "clSPARSE.h"
32+
#include "clSPARSE-error.h"
3233

3334
/*!
3435
* \brief Sample AXPY (C++)
@@ -174,15 +175,11 @@ int main(int argc, char* argv[])
174175

175176

176177
// Create clsparseControl object
177-
clsparseControl control = clsparseCreateControl(queue(), &status);
178-
if (status != CL_SUCCESS)
179-
{
180-
std::cout << "Problem with creating clSPARSE control object"
181-
<<" error [" << status << "]" << std::endl;
182-
}
178+
clsparseCreateResult createResult = clsparseCreateControl( queue( ) );
179+
CLSPARSE_V( createResult.status, "Failed to create clsparse control" );
183180
/** Step 4. Execute AXPY algorithm **/
184181

185-
status = cldenseSaxpy(&gpuY, &gpuAlpha, &gpuX, &gpuY, control);
182+
status = cldenseSaxpy(&gpuY, &gpuAlpha, &gpuX, &gpuY, createResult.control );
186183

187184
if (status != clsparseSuccess)
188185
{
@@ -191,7 +188,7 @@ int main(int argc, char* argv[])
191188
}
192189

193190
/** Step 5. Shutdown clSPARSE library & OpenCL **/
194-
status = clsparseReleaseControl(control);
191+
status = clsparseReleaseControl( createResult.control );
195192

196193
status = clsparseTeardown();
197194
if (status != clsparseSuccess)

samples/sample-cg.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include <CL/cl.hpp>
2929
#endif
3030

31-
#include <clSPARSE.h>
31+
#include "clSPARSE.h"
32+
#include "clSPARSE-error.h"
3233

3334
/*!
3435
* \brief Sample Conjugate Gradients Solver (CG C++)
@@ -155,17 +156,11 @@ int main (int argc, char* argv[])
155156
}
156157

157158

158-
// Create clsparseControl object
159-
clsparseControl control = clsparseCreateControl(queue(), &status);
160-
if (status != CL_SUCCESS)
161-
{
162-
std::cout << "Problem with creating clSPARSE control object"
163-
<<" error [" << status << "]" << std::endl;
164-
return -4;
165-
}
166-
159+
// Create clSPARSE control object it require queue for kernel execution
160+
clsparseCreateResult createResult = clsparseCreateControl( queue( ) );
161+
CLSPARSE_V( createResult.status, "Failed to create clsparse control" );
167162

168-
// Read matrix from file. Calculates the rowBlocks strucutres as well.
163+
// Read matrix from file. Calculates the rowBlocks structures as well.
169164
clsparseIdx_t nnz, row, col;
170165
// read MM header to get the size of the matrix;
171166
clsparseStatus fileError
@@ -185,26 +180,20 @@ int main (int argc, char* argv[])
185180
A.values = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
186181
A.num_nonzeros * sizeof( float ), NULL, &cl_status );
187182

188-
A.colIndices = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
183+
A.col_indices = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
189184
A.num_nonzeros * sizeof( clsparseIdx_t ), NULL, &cl_status );
190185

191-
A.rowOffsets = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
186+
A.row_pointer = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
192187
( A.num_rows + 1 ) * sizeof( clsparseIdx_t ), NULL, &cl_status );
193188

194-
A.rowBlocks = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
195-
A.rowBlockSize * sizeof( cl_ulong ), NULL, &cl_status );
196-
197189

198190
// Read matrix market file with explicit zero values included.
199-
fileError = clsparseSCsrMatrixfromFile( &A, matrix_path.c_str( ), control, true );
191+
fileError = clsparseSCsrMatrixfromFile( &A, matrix_path.c_str( ), createResult.control, true );
200192

201193
// This function allocates memory for rowBlocks structure. If not called
202194
// the structure will not be calculated and clSPARSE will run the vectorized
203195
// version of SpMV instead of adaptive;
204-
clsparseCsrMetaSize( &A, control );
205-
A.rowBlocks = ::clCreateBuffer( context(), CL_MEM_READ_WRITE,
206-
A.rowBlockSize * sizeof( cl_ulong ), NULL, &cl_status );
207-
clsparseCsrMetaCompute( &A, control );
196+
clsparseCsrMetaCreate( &A, createResult.control );
208197

209198
if (fileError != clsparseSuccess)
210199
{
@@ -249,28 +238,27 @@ int main (int argc, char* argv[])
249238
// relative tolerance: 1e-2
250239
// absolute tolerance: 1e-5
251240
// max iters: 1000
252-
clSParseSolverControl solverControl =
253-
clsparseCreateSolverControl(DIAGONAL, 1000, 1e-2, 1e-5);
241+
clsparseCreateSolverResult solverResult =
242+
clsparseCreateSolverControl( DIAGONAL, 1000, 1e-2, 1e-5 );
243+
CLSPARSE_V( solverResult.status, "Failed to create clsparse solver control" );
254244

255245
// We can set different print modes of the solver status:
256246
// QUIET - print no messages (default)
257247
// NORMAL - print summary
258248
// VERBOSE - per iteration status;
259-
clsparseSolverPrintMode(solverControl, VERBOSE);
249+
clsparseSolverPrintMode( solverResult.control, VERBOSE);
260250

261251
/* TODO: provide various solver statuses for different scenarios
262-
* Solver reached max numer of iterations is not a failure.
252+
* Solver reached max number of iterations is not a failure.
263253
*/
264254

265-
status = clsparseScsrcg(&x, &A, &b, solverControl, control);
255+
status = clsparseScsrcg(&x, &A, &b, solverResult.control, createResult.control );
266256

267257
//release solver control structure after finishing execution;
268-
clsparseReleaseSolverControl(solverControl);
269-
270-
258+
clsparseReleaseSolverControl( solverResult.control );
271259

272260
/** Step 5. Close & release resources */
273-
status = clsparseReleaseControl(control);
261+
status = clsparseReleaseControl( createResult.control );
274262
if (status != clsparseSuccess)
275263
{
276264
std::cout << "Problem with releasing control object."
@@ -285,10 +273,10 @@ int main (int argc, char* argv[])
285273
<< " Error: " << status << std::endl;
286274
}
287275
//release mem;
276+
clsparseCsrMetaDelete( &A );
288277
clReleaseMemObject ( A.values );
289-
clReleaseMemObject ( A.colIndices );
290-
clReleaseMemObject ( A.rowOffsets );
291-
clReleaseMemObject ( A.rowBlocks );
278+
clReleaseMemObject ( A.col_indices );
279+
clReleaseMemObject ( A.row_pointer );
292280

293281
clReleaseMemObject ( x.values );
294282
clReleaseMemObject ( b.values );

samples/sample-norm1-c.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#include <stdio.h>
1818
#include <stdlib.h>
1919

20-
#include <clSPARSE.h>
20+
#include "clSPARSE.h"
21+
#include "clSPARSE-error.h"
2122

2223
/*! \file
2324
* \brief Simple demonstration code for calculating Norm1 from within 'C' host code
@@ -34,7 +35,7 @@
3435
* 5. Shutdown clSPARSE library & OpenCL
3536
*
3637
* UNIX Hint: Before allocating more than 3GB of VRAM define GPU_FORCE_64BIT_PTR=1
37-
* in your system environment to enable 64bit addresing;
38+
* in your system environment to enable 64bit addressing;
3839
*/
3940
int main( int argc, char* argv[ ] )
4041
{
@@ -55,7 +56,7 @@ int main( int argc, char* argv[ ] )
5556

5657
if (num_platforms == 0)
5758
{
58-
printf ("No OpenCL platforms found. Exitting.\n");
59+
printf ("No OpenCL platforms found. Exiting.\n");
5960
return 0;
6061
}
6162

@@ -67,7 +68,7 @@ int main( int argc, char* argv[ ] )
6768

6869
if (cl_status != CL_SUCCESS)
6970
{
70-
printf("Poblem with getting platform IDs. Err: %d\n", cl_status);
71+
printf("Problem with getting platform IDs. Err: %d\n", cl_status);
7172
free(platforms);
7273
return -1;
7374
}
@@ -78,7 +79,7 @@ int main( int argc, char* argv[ ] )
7879

7980
if (num_devices == 0)
8081
{
81-
printf("No OpenCL GPU devices found on platform 0. Exitting\n");
82+
printf("No OpenCL GPU devices found on platform 0. Exiting\n");
8283
free(platforms);
8384
return -2;
8485
}
@@ -91,7 +92,7 @@ int main( int argc, char* argv[ ] )
9192

9293
if (cl_status != CL_SUCCESS)
9394
{
94-
printf("Problem with getting device id from platform. Exitting\n");
95+
printf("Problem with getting device id from platform. Exiting\n");
9596
free(devices);
9697
free(platforms);
9798
return -3;
@@ -134,9 +135,10 @@ int main( int argc, char* argv[ ] )
134135
}
135136

136137
// Create clSPARSE control object it require queue for kernel execution
137-
clsparseControl control = clsparseCreateControl(queue, &status);
138+
clsparseCreateResult createResult = clsparseCreateControl( queue );
139+
CLSPARSE_V( createResult.status, "Failed to create clsparse control" );
138140

139-
status = cldenseSnrm1(&norm_x, &x, control);
141+
status = cldenseSnrm1(&norm_x, &x, createResult.control );
140142

141143
// Read result
142144
float* host_norm_x =
@@ -148,7 +150,7 @@ int main( int argc, char* argv[ ] )
148150
cl_status = clEnqueueUnmapMemObject(queue, norm_x.value, host_norm_x,
149151
0, NULL, NULL);
150152

151-
status = clsparseReleaseControl(control);
153+
status = clsparseReleaseControl( createResult.control );
152154

153155
status = clsparseTeardown();
154156
if (status != clsparseSuccess)

0 commit comments

Comments
 (0)