void TearDown() { ::clReleaseMemObject(gAlpha.value); ::clReleaseMemObject(gBeta.value); clsparseInitScalar(&gAlpha); clsparseInitScalar(&gBeta); ::clReleaseMemObject(deviceMatB.values); ::clReleaseMemObject(deviceMatC.values); cldenseInitMatrix( &deviceMatB ); cldenseInitMatrix( &deviceMatC ); }
void TearDown() { ::clReleaseMemObject(gAlpha.value); ::clReleaseMemObject(gBeta.value); ::clReleaseMemObject(gX.values); ::clReleaseMemObject(gY.values); clsparseInitScalar(&gAlpha); clsparseInitScalar(&gBeta); clsparseInitVector(&gX); clsparseInitVector(&gY); }
void SetUp() { // alpha and beta scalars are not yet supported in generating reference result; alpha = T(CSRE::alpha); beta = T(CSRE::beta); B = uBLASDenseM(CSRE::n_cols, B_num_cols, T(B_values)); C = uBLASDenseM(CSRE::n_rows, B_num_cols, T(0)); cl_int status; cldenseInitMatrix( &deviceMatB ); deviceMatB.values = clCreateBuffer( CLSE::context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, B.data().size( ) * sizeof( T ), B.data().begin(), &status ); deviceMatB.num_rows = B.size1(); deviceMatB.num_cols = B.size2(); deviceMatB.lead_dim = std::min(B.size1(), B.size2()); ASSERT_EQ(CL_SUCCESS, status); cldenseInitMatrix( &deviceMatC ); deviceMatC.values = clCreateBuffer( CLSE::context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, C.data().size( ) * sizeof( T ), C.data().begin(), &status ); deviceMatC.num_rows = C.size1(); deviceMatC.num_cols = C.size2(); deviceMatC.lead_dim = std::min(C.size1(), C.size2()); ASSERT_EQ(CL_SUCCESS, status); clsparseInitScalar( &gAlpha ); gAlpha.value = clCreateBuffer(CLSE::context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(T), &alpha, &status); ASSERT_EQ(CL_SUCCESS, status); clsparseInitScalar( &gBeta ); gBeta.value = clCreateBuffer(CLSE::context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(T), &beta, &status); ASSERT_EQ(CL_SUCCESS, status); }
void SetUp() { clsparseInitScalar(&gAlpha); clsparseInitScalar(&gBeta); clsparseInitVector(&gX); clsparseInitVector(&gY); hAlpha = T(CSRE::alpha); hBeta = T(CSRE::beta); hX = uBLAS::vector<T>(CSRE::n_cols, 1); hY = uBLAS::vector<T>(CSRE::n_rows, 2); cl_int status; gX.values = clCreateBuffer(CLSE::context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, hX.size() * sizeof(T), hX.data().begin(), &status); gX.num_values = hX.size(); ASSERT_EQ(CL_SUCCESS, status); gY.values = clCreateBuffer(CLSE::context, CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR, hY.size() * sizeof(T), hY.data().begin(), &status); gY.num_values = hY.size(); ASSERT_EQ(CL_SUCCESS, status); gAlpha.value = clCreateBuffer(CLSE::context, CL_MEM_READ_ONLY| CL_MEM_COPY_HOST_PTR, sizeof(T), &hAlpha, &status); ASSERT_EQ(CL_SUCCESS, status); gBeta.value = clCreateBuffer(CLSE::context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(T), &hBeta, &status); ASSERT_EQ(CL_SUCCESS, status); }
void setup_buffer(double pAlpha, double pBeta, const std::string& path) { sparseFile = path; alpha = static_cast<T>(pAlpha); beta = static_cast<T>(pBeta); // Read sparse data from file and construct a COO matrix from it clsparseIdx_t nnz, row, col; clsparseStatus fileError = clsparseHeaderfromFile(&nnz, &row, &col, sparseFile.c_str()); if (fileError != clsparseSuccess) throw clsparse::io_exception("Could not read matrix market header from disk"); // Now initialize a CSR matrix from the COO matrix clsparseInitCsrMatrix(&csrMtx); csrMtx.num_nonzeros = nnz; csrMtx.num_rows = row; csrMtx.num_cols = col; //clsparseCsrMetaSize(&csrMtx, control); cl_int status; csrMtx.values = ::clCreateBuffer(ctx, CL_MEM_READ_ONLY, csrMtx.num_nonzeros * sizeof(T), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer csrMtx.values"); csrMtx.col_indices = ::clCreateBuffer(ctx, CL_MEM_READ_ONLY, csrMtx.num_nonzeros * sizeof(clsparseIdx_t), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer csrMtx.col_indices"); csrMtx.row_pointer = ::clCreateBuffer(ctx, CL_MEM_READ_ONLY, (csrMtx.num_rows + 1) * sizeof(clsparseIdx_t), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer csrMtx.row_pointer"); #if 0 csrMtx.rowBlocks = ::clCreateBuffer(ctx, CL_MEM_READ_ONLY, csrMtx.rowBlockSize * sizeof(cl_ulong), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer csrMtx.rowBlocks"); #endif if (typeid(T) == typeid(float)) fileError = clsparseSCsrMatrixfromFile( &csrMtx, sparseFile.c_str(), control, explicit_zeroes ); else if (typeid(T) == typeid(double)) fileError = clsparseDCsrMatrixfromFile( &csrMtx, sparseFile.c_str(), control, explicit_zeroes ); else fileError = clsparseInvalidType; if (fileError != clsparseSuccess) throw clsparse::io_exception("Could not read matrix market data from disk"); // Initilize the output CSR Matrix clsparseInitCsrMatrix(&csrMtxC); // Initialize the scalar alpha & beta parameters clsparseInitScalar(&a); a.value = ::clCreateBuffer(ctx, CL_MEM_READ_ONLY, 1 * sizeof(T), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer a.value"); clsparseInitScalar(&b); b.value = ::clCreateBuffer(ctx, CL_MEM_READ_ONLY, 1 * sizeof(T), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer b.value"); //std::cout << "Flops = " << xSpMSpM_Getflopcount() << std::endl; flopCnt = xSpMSpM_Getflopcount(); }// end of function
void setup_buffer( double pAlpha, double pBeta, const std::string& path ) { sparseFile = path; alpha = static_cast< T >( pAlpha ); beta = static_cast< T >( pBeta ); // Read sparse data from file and construct a COO matrix from it int nnz, row, col; clsparseStatus fileError = clsparseHeaderfromFile( &nnz, &row, &col, sparseFile.c_str( ) ); if( fileError != clsparseSuccess ) throw clsparse::io_exception( "Could not read matrix market header from disk" ); // Now initialise a CSR matrix from the COO matrix clsparseInitCsrMatrix( &csrMtx ); csrMtx.num_nonzeros = nnz; csrMtx.num_rows = row; csrMtx.num_cols = col; clsparseCsrMetaSize( &csrMtx, control ); cl_int status; csrMtx.values = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, csrMtx.num_nonzeros * sizeof( T ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer csrMtx.values" ); csrMtx.colIndices = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, csrMtx.num_nonzeros * sizeof( cl_int ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer csrMtx.colIndices" ); csrMtx.rowOffsets = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, ( csrMtx.num_rows + 1 ) * sizeof( cl_int ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer csrMtx.rowOffsets" ); csrMtx.rowBlocks = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, csrMtx.rowBlockSize * sizeof( cl_ulong ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer csrMtx.rowBlocks" ); if(typeid(T) == typeid(float)) fileError = clsparseSCsrMatrixfromFile( &csrMtx, sparseFile.c_str( ), control ); else if (typeid(T) == typeid(double)) fileError = clsparseDCsrMatrixfromFile( &csrMtx, sparseFile.c_str( ), control ); else fileError = clsparseInvalidType; if( fileError != clsparseSuccess ) throw clsparse::io_exception( "Could not read matrix market data from disk" ); // Initialize the dense X & Y vectors that we multiply against the sparse matrix clsparseInitVector( &x ); x.num_values = csrMtx.num_cols; x.values = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, x.num_values * sizeof( T ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer x.values" ); clsparseInitVector( &y ); y.num_values = csrMtx.num_rows; y.values = ::clCreateBuffer( ctx, CL_MEM_READ_WRITE, y.num_values * sizeof( T ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer y.values" ); // Initialize the scalar alpha & beta parameters clsparseInitScalar( &a ); a.value = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, 1 * sizeof( T ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer a.value" ); clsparseInitScalar( &b ); b.value = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, 1 * sizeof( T ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer b.value" ); }