void TearDown() { ::clReleaseMemObject(gAlpha.value); ::clReleaseMemObject(gBeta.value); clsparseInitScalar(&gAlpha); clsparseInitScalar(&gBeta); ::clReleaseMemObject(deviceMatB.values); ::clReleaseMemObject(deviceMatC.values); cldenseInitMatrix( &deviceMatB ); cldenseInitMatrix( &deviceMatC ); }
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_buffer(double pAlpha, double pBeta, const std::string& path) { sparseFile = path; // Read sparse data from file and construct a CSR matrix from it int nnz; int row; int col; clsparseStatus fileError = clsparseHeaderfromFile(&nnz, &row, &col, sparseFile.c_str()); if (clsparseSuccess != fileError) throw std::runtime_error("Could not read matrix market header from disk"); // Now initialize a CSR matrix from the CSR matrix // VK we have to handle other cases if input mtx file is not in CSR format 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 std::runtime_error("Could not read matrix market data from disk"); // Initialize the output dense matrix cldenseInitMatrix(&denseMtx); denseMtx.major = rowMajor; denseMtx.num_rows = row; denseMtx.num_cols = col; denseMtx.lead_dim = col; // To Check!! VK; denseMtx.values = ::clCreateBuffer(ctx, CL_MEM_WRITE_ONLY, denseMtx.num_rows * denseMtx.num_cols * sizeof(T), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer denseMtx.values"); }// end
void setup_buffer(double pAlpha, double pBeta, const std::string& path) { sparseFile = path; // Read sparse data from file and construct a CSR matrix from it clsparseIdx_t nnz; clsparseIdx_t row; clsparseIdx_t col; clsparseStatus fileError = clsparseHeaderfromFile(&nnz, &row, &col, sparseFile.c_str()); if (clsparseSuccess != fileError) throw clsparse::io_exception( "Could not read matrix market header from disk: " + sparseFile ); // Now initialize a CSR matrix from the CSR matrix clsparseInitCsrMatrix(&csrMtx); csrMtx.num_nonzeros = nnz; csrMtx.num_rows = row; csrMtx.num_cols = col; 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 (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 std::runtime_error("Could not read matrix market data from disk: " + sparseFile); clsparseCsrMetaCreate(&csrMtx, control); // Initialize the output dense matrix cldenseInitMatrix(&denseMtx); denseMtx.major = rowMajor; denseMtx.num_rows = row; denseMtx.num_cols = col; denseMtx.lead_dim = col; // To Check!! VK; denseMtx.values = ::clCreateBuffer(ctx, CL_MEM_WRITE_ONLY, denseMtx.num_rows * denseMtx.num_cols * sizeof(T), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer denseMtx.values"); }// end
void setup_buffer( double pAlpha, double pBeta, const std::string& path ) { sparseFile = path; // Read sparse data from file and construct a COO matrix from it int nnz; int row; int col; clsparseStatus fileError = clsparseHeaderfromFile( &nnz, &row, &col, sparseFile.c_str( ) ); if( fileError != clsparseSuccess ) throw std::runtime_error( "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" ); 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 std::runtime_error( "Could not read matrix market data from disk" ); // Initialize the input dense matrix cldenseInitMatrix(&A); A.major = rowMajor; A.num_rows = row; A.num_cols = col; A.lead_dim = col; // To Check!! VK; A.values = clCreateBuffer(ctx, CL_MEM_READ_WRITE, row * col * sizeof(T), NULL, &status); CLSPARSE_V(status, "::clCreateBuffer A.values"); if(typeid(T) == typeid(float)) { clsparseScsr2dense(&csrMtx, &A, control); } else if (typeid(T) == typeid(double)) { clsparseDcsr2dense(&csrMtx, &A, control); } // Check whether we need any barrier here: clFinish(queue) // Output CSR Matrix clsparseInitCsrMatrix(&csrMatx); csrMatx.num_cols = csrMtx.num_cols; csrMatx.num_rows = csrMtx.num_rows; csrMatx.num_nonzeros = csrMtx.num_nonzeros; csrMatx.values = ::clCreateBuffer( ctx, CL_MEM_WRITE_ONLY, csrMtx.num_nonzeros * sizeof( T ), NULL, &status ); CLSPARSE_V(status, "::clCreateBuffer csrMatx.values"); csrMatx.colIndices = ::clCreateBuffer( ctx, CL_MEM_WRITE_ONLY, csrMtx.num_nonzeros * sizeof( cl_int ), NULL, &status ); CLSPARSE_V(status, "::clCreateBuffer csrMatx.colIndices"); csrMatx.rowOffsets = ::clCreateBuffer( ctx, CL_MEM_WRITE_ONLY, (csrMtx.num_rows + 1) * sizeof( cl_int ), NULL, &status ); CLSPARSE_V(status, "::clCreateBuffer csrMatx.rowOffsets"); }// End of function