Skip to content

Commit

Permalink
Merge pull request #108 from jpola/samplesFixup
Browse files Browse the repository at this point in the history
Samples fix
  • Loading branch information
Kent Knox committed Jul 15, 2015
2 parents 676dd2f + 6d0f2f7 commit f9138f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
16 changes: 8 additions & 8 deletions samples/sample-axpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ int main(int argc, char* argv[])
clsparseScalar gpuAlpha;
clsparseInitScalar(&gpuAlpha);

clsparseVector gpuY;
cldenseVector gpuY;
clsparseInitVector(&gpuY);

clsparseVector gpuX;
cldenseVector gpuX;
clsparseInitVector(&gpuX);


Expand All @@ -119,8 +119,8 @@ int main(int argc, char* argv[])
gpuY.values = ::clCreateBuffer (context(), CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
N * sizeof(float), y.data(), &cl_status);

// set the size of clsparseVector;
gpuY.n = N;
// set the size of cldenseVector;
gpuY.num_values = N;

if (cl_status != CL_SUCCESS )
{
Expand All @@ -129,8 +129,8 @@ int main(int argc, char* argv[])

gpuX.values = ::clCreateBuffer (context(), CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
N * sizeof(float), x.data(), &cl_status);
// set the size of clsparseVector;
gpuX.n = N;
// set the size of cldenseVector;
gpuX.num_values = N;

if (cl_status != CL_SUCCESS )
{
Expand Down Expand Up @@ -188,9 +188,9 @@ int main(int argc, char* argv[])

::clReleaseMemObject(gpuAlpha.value);
::clReleaseMemObject(gpuY.values);
gpuY.n = 0;
gpuY.num_values = 0;
::clReleaseMemObject(gpuX.values);
gpuX.n = 0;
gpuX.num_values = 0;

//OpenCL Wrapper automatically release allocated resources

Expand Down
28 changes: 14 additions & 14 deletions samples/sample-cg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ int main (int argc, char* argv[])

//we will allocate it after matrix will be loaded;

clsparseVector x;
cldenseVector x;
clsparseInitVector(&x);

clsparseVector b;
cldenseVector b;
clsparseInitVector(&b);

clsparseCsrMatrix A;
Expand Down Expand Up @@ -151,9 +151,9 @@ int main (int argc, char* argv[])
return -5;
}

A.nnz = nnz;
A.m = row;
A.n = col;
A.num_nonzeros = nnz;
A.num_rows = row;
A.num_cols = col;

// This function allocates memory for rowBlocks structure. If not called
// the structure will not be calculated and clSPARSE will run the vectorized
Expand All @@ -162,13 +162,13 @@ int main (int argc, char* argv[])

// Allocate memory for CSR matrix
A.values = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
A.nnz * sizeof( float ), NULL, &cl_status );
A.num_nonzeros * sizeof( float ), NULL, &cl_status );

A.colIndices = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
A.nnz * sizeof( cl_int ), NULL, &cl_status );
A.num_nonzeros * sizeof( cl_int ), NULL, &cl_status );

A.rowOffsets = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
( A.m + 1 ) * sizeof( cl_int ), NULL, &cl_status );
( A.num_rows + 1 ) * sizeof( cl_int ), NULL, &cl_status );

A.rowBlocks = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
A.rowBlockSize * sizeof( cl_ulong ), NULL, &cl_status );
Expand All @@ -189,21 +189,21 @@ int main (int argc, char* argv[])

// Allocate memory for vector of unknowns;
// We will fill it with zeros as a initial guess
x.n = A.n;
x.values = clCreateBuffer(context(), CL_MEM_READ_ONLY, x.n * sizeof(float),
x.num_values = A.num_cols;
x.values = clCreateBuffer(context(), CL_MEM_READ_ONLY, x.num_values * sizeof(float),
NULL, &cl_status);

cl_status = clEnqueueFillBuffer(queue(), x.values, &zero, sizeof(float),
0, x.n * sizeof(float), 0, nullptr, nullptr);
0, x.num_values * sizeof(float), 0, nullptr, nullptr);

// Allocate memory for rhs vector

b.n = A.m;
b.values = clCreateBuffer(context(), CL_MEM_READ_WRITE, b.n * sizeof(float),
b.num_values = A.num_rows;
b.values = clCreateBuffer(context(), CL_MEM_READ_WRITE, b.num_values * sizeof(float),
NULL, &cl_status);
// Fill it with ones.
cl_status = clEnqueueFillBuffer(queue(), b.values, &one, sizeof(float),
0, b.n * sizeof(float), 0, nullptr, nullptr);
0, b.num_values * sizeof(float), 0, nullptr, nullptr);



Expand Down
4 changes: 2 additions & 2 deletions samples/sample-norm1-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ int main( int argc, char* argv[ ] )
/** Allocate GPU buffers **/

int N = 1024;
clsparseVector x;
cldenseVector x;
clsparseInitVector(&x);
clsparseScalar norm_x;
clsparseInitScalar(&norm_x);

x.values = clCreateBuffer(context, CL_MEM_READ_WRITE, N * sizeof (float),
NULL, &cl_status);
x.n = N;
x.num_values = N;

// Fill x buffer with ones;
float one = 1.0f;
Expand Down
28 changes: 14 additions & 14 deletions samples/sample-spmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ int main (int argc, char* argv[])
nullptr, &cl_status);


clsparseVector x;
cldenseVector x;
clsparseInitVector(&x);

clsparseVector y;
cldenseVector y;
clsparseInitVector(&y);

clsparseCsrMatrix A;
Expand Down Expand Up @@ -183,9 +183,9 @@ int main (int argc, char* argv[])
return -5;
}

A.nnz = nnz;
A.m = row;
A.n = col;
A.num_nonzeros = nnz;
A.num_rows = row;
A.num_cols = col;

// This function allocates memory for rowBlocks structure. If not called
// the structure will not be calculated and clSPARSE will run the vectorized
Expand All @@ -194,13 +194,13 @@ int main (int argc, char* argv[])

// Allocate memory for CSR matrix
A.values = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
A.nnz * sizeof( float ), NULL, &cl_status );
A.num_nonzeros * sizeof( float ), NULL, &cl_status );

A.colIndices = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
A.nnz * sizeof( cl_int ), NULL, &cl_status );
A.num_nonzeros * sizeof( cl_int ), NULL, &cl_status );

A.rowOffsets = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
( A.m + 1 ) * sizeof( cl_int ), NULL, &cl_status );
( A.num_rows + 1 ) * sizeof( cl_int ), NULL, &cl_status );

A.rowBlocks = ::clCreateBuffer( context(), CL_MEM_READ_ONLY,
A.rowBlockSize * sizeof( cl_ulong ), NULL, &cl_status );
Expand Down Expand Up @@ -236,19 +236,19 @@ int main (int argc, char* argv[])
0, nullptr, nullptr);


x.n = A.n;
x.values = clCreateBuffer(context(), CL_MEM_READ_ONLY, x.n * sizeof(float),
x.num_values = A.num_cols;
x.values = clCreateBuffer(context(), CL_MEM_READ_ONLY, x.num_values * sizeof(float),
NULL, &cl_status);

cl_status = clEnqueueFillBuffer(queue(), x.values, &one, sizeof(float),
0, x.n * sizeof(float), 0, nullptr, nullptr);
0, x.num_values * sizeof(float), 0, nullptr, nullptr);

y.n = A.m;
y.values = clCreateBuffer(context(), CL_MEM_READ_WRITE, y.n * sizeof(float),
y.num_values = A.num_rows;
y.values = clCreateBuffer(context(), CL_MEM_READ_WRITE, y.num_values * sizeof(float),
NULL, &cl_status);

cl_status = clEnqueueFillBuffer(queue(), y.values, &zero, sizeof(float),
0, y.n * sizeof(float), 0, nullptr, nullptr);
0, y.num_values * sizeof(float), 0, nullptr, nullptr);



Expand Down

0 comments on commit f9138f5

Please sign in to comment.