MCPcopy Create free account
hub / github.com/clMathLibraries/clSPARSE / clsparseDCooMatrixfromFile

Function clsparseDCooMatrixfromFile

src/library/io/mm-reader.cpp:523–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

521}
522
523clsparseStatus
524clsparseDCooMatrixfromFile( clsparseCooMatrix* cooMatx, const char* filePath, clsparseControl control, cl_bool read_explicit_zeroes )
525{
526 clsparseCooMatrixPrivate* pCooMatx = static_cast<clsparseCooMatrixPrivate*>( cooMatx );
527
528 // Check that the file format is matrix market; the only format we can read right now
529 // This is not a complete solution, and fails for directories with file names etc...
530 // TODO: Should we use boost filesystem?
531 std::string strPath( filePath );
532 if( strPath.find_last_of( '.' ) != std::string::npos )
533 {
534 std::string ext = strPath.substr( strPath.find_last_of( '.' ) + 1 );
535 if( ext != "mtx" )
536 return clsparseInvalidFileFormat;
537 }
538 else
539 return clsparseInvalidFileFormat;
540
541 MatrixMarketReader< cl_double > mm_reader;
542 if( mm_reader.MMReadFormat( filePath, read_explicit_zeroes ) )
543 return clsparseInvalidFile;
544
545 pCooMatx->num_rows = mm_reader.GetNumRows( );
546 pCooMatx->num_cols = mm_reader.GetNumCols( );
547 pCooMatx->num_nonzeros = mm_reader.GetNumNonZeroes( );
548
549 // Transfers data from CPU buffer to GPU buffers
550 clMemRAII< cl_double > rCooValues( control->queue( ), pCooMatx->values );
551 clMemRAII< clsparseIdx_t > rCoocol_indices( control->queue( ), pCooMatx->col_indices );
552 clMemRAII< clsparseIdx_t > rCoorow_indices( control->queue( ), pCooMatx->row_indices );
553
554 cl_double* fCooValues = rCooValues.clMapMem( CL_TRUE, CL_MAP_WRITE_INVALIDATE_REGION, pCooMatx->valOffset( ), pCooMatx->num_nonzeros );
555 clsparseIdx_t* iCoocol_indices = rCoocol_indices.clMapMem( CL_TRUE, CL_MAP_WRITE_INVALIDATE_REGION, pCooMatx->colIndOffset( ), pCooMatx->num_nonzeros );
556 clsparseIdx_t* iCoorow_indices = rCoorow_indices.clMapMem( CL_TRUE, CL_MAP_WRITE_INVALIDATE_REGION, pCooMatx->rowOffOffset( ), pCooMatx->num_nonzeros );
557
558 Coordinate< cl_double >* coords = mm_reader.GetUnsymCoordinates( );
559 //JPA:: Coo matrix is need to be sorted as well because we need to have matrix
560 // which is sorted by row and then column, in the mtx files usually is opposite.
561 std::sort( coords, coords + pCooMatx->num_nonzeros, CoordinateCompare< cl_double > );
562
563 for( clsparseIdx_t c = 0; c < pCooMatx->num_nonzeros; ++c )
564 {
565 iCoorow_indices[ c ] = coords[ c ].x;
566 iCoocol_indices[ c ] = coords[ c ].y;
567 fCooValues[ c ] = coords[ c ].val;
568 }
569
570 return clsparseSuccess;
571}
572
573clsparseStatus
574clsparseSCsrMatrixfromFile(clsparseCsrMatrix* csrMatx, const char* filePath, clsparseControl control, cl_bool read_explicit_zeroes )

Callers 2

test_coo_to_csrMethod · 0.85
setup_bufferMethod · 0.85

Calls 9

MMReadFormatMethod · 0.45
GetNumRowsMethod · 0.45
GetNumColsMethod · 0.45
GetNumNonZeroesMethod · 0.45
clMapMemMethod · 0.45
valOffsetMethod · 0.45
colIndOffsetMethod · 0.45
rowOffOffsetMethod · 0.45
GetUnsymCoordinatesMethod · 0.45

Tested by 1

test_coo_to_csrMethod · 0.68