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, 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 std::runtime_error( "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_rows; x.values = ::clCreateBuffer( ctx, CL_MEM_READ_WRITE, x.num_values * sizeof( T ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer x.values" ); clsparseInitVector( &y ); y.num_values = csrMtx.num_cols; y.values = ::clCreateBuffer( ctx, CL_MEM_READ_WRITE, y.num_values * sizeof( T ), NULL, &status ); CLSPARSE_V( status, "::clCreateBuffer y.values" ); }
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; cl_int status; int nnz1, row1, col1; clsparseStatus fileError = clsparseHeaderfromFile( &nnz1, &row1, &col1, path.c_str( ) ); if( fileError != clsparseSuccess ) throw std::runtime_error( "Could not read matrix market header from disk" ); clsparseInitCooMatrix( &cooMatx ); cooMatx.num_nonzeros = nnz1; cooMatx.num_rows = row1; cooMatx.num_cols = col1; cooMatx.values = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, cooMatx.num_nonzeros * sizeof(T), NULL, &status ); cooMatx.colIndices = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, cooMatx.num_nonzeros * sizeof( cl_int ), NULL, &status ); cooMatx.rowIndices = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, cooMatx.num_nonzeros * sizeof( cl_int ), NULL, &status ); //JPA: Bug fix: That will not work for double precision //clsparseCooMatrixfromFile( &cooMatx, path.c_str( ), control ); if (typeid(T) == typeid(float)) clsparseSCooMatrixfromFile(&cooMatx, path.c_str(), control); if (typeid(T) == typeid(double)) clsparseDCooMatrixfromFile(&cooMatx, path.c_str(), control); //clsparseCsrMatrix csrMatx; clsparseInitCsrMatrix( &csrMtx ); //JPA:: Shouldn't be CL_MEM_WRITE_ONLY since coo ---> csr??? csrMtx.values = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, cooMatx.num_nonzeros * sizeof( T ), NULL, &status ); csrMtx.colIndices = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, cooMatx.num_nonzeros * sizeof( cl_int ), NULL, &status ); csrMtx.rowOffsets = ::clCreateBuffer( ctx, CL_MEM_READ_ONLY, ( cooMatx.num_rows + 1 ) * sizeof( cl_int ), NULL, &status ); }
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
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