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

Function clsparseSCsrMatrixfromFile

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

Source from the content-addressed store, hash-verified

571}
572
573clsparseStatus
574clsparseSCsrMatrixfromFile(clsparseCsrMatrix* csrMatx, const char* filePath, clsparseControl control, cl_bool read_explicit_zeroes )
575{
576 clsparseCsrMatrixPrivate* pCsrMatx = static_cast<clsparseCsrMatrixPrivate*>( csrMatx );
577
578 // Check that the file format is matrix market; the only format we can read right now
579 // This is not a complete solution, and fails for directories with file names etc...
580 // TODO: Should we use boost filesystem?
581 std::string strPath( filePath );
582 if( strPath.find_last_of( '.' ) != std::string::npos )
583 {
584 std::string ext = strPath.substr( strPath.find_last_of( '.' ) + 1 );
585 if( ext != "mtx" )
586 return clsparseInvalidFileFormat;
587 }
588 else
589 return clsparseInvalidFileFormat;
590
591 // Read data from a file on disk into CPU buffers
592 // Data is read natively as COO format with the reader
593 MatrixMarketReader< cl_float > mm_reader;
594 if( mm_reader.MMReadFormat( filePath, read_explicit_zeroes ) )
595 return clsparseInvalidFile;
596 // BUG: We need to check to see if openCL buffers currently exist and deallocate them first!
597 // FIX: Below code will check whether the buffers were allocated in the first place;
598 {
599 clsparseStatus validationStatus = validateMemObject(pCsrMatx->values,
600 mm_reader.GetNumNonZeroes() * sizeof(cl_float));
601
602 // I dont want to reallocate buffer because I suppress the users buffer memory flags;
603 // It is users responsibility to provide good buffer;
604 if (validationStatus != clsparseSuccess)
605 return validationStatus;
606
607 validationStatus = validateMemObject(pCsrMatx->col_indices,
608 mm_reader.GetNumNonZeroes() * sizeof(clsparseIdx_t));
609 if (validationStatus != clsparseSuccess)
610 return validationStatus;
611
612 validationStatus = validateMemObject(pCsrMatx->row_pointer,
613 (mm_reader.GetNumRows() + 1) * sizeof(clsparseIdx_t));
614 if (validationStatus != clsparseSuccess)
615 return validationStatus;
616 }
617
618 // JPA: Shouldn't that just be an assertion check? It seems to me that
619 // the user have to call clsparseHeaderfromFile before calling this function,
620 // otherwise the whole pCsrMatrix will be broken;
621
622 pCsrMatx->num_rows = mm_reader.GetNumRows( );
623 pCsrMatx->num_cols = mm_reader.GetNumCols( );
624 pCsrMatx->num_nonzeros = mm_reader.GetNumNonZeroes( );
625
626 // Transfers data from CPU buffer to GPU buffers
627 clMemRAII< cl_float > rCsrValues( control->queue( ), pCsrMatx->values );
628 clMemRAII< clsparseIdx_t > rCsrcol_indices( control->queue( ), pCsrMatx->col_indices );
629 clMemRAII< clsparseIdx_t > rCsrrow_pointer( control->queue( ), pCsrMatx->row_pointer );
630

Callers 11

mainFunction · 0.85
mainFunction · 0.85
CSRSparseEnvironmentMethod · 0.85
setup_bufferMethod · 0.85
setup_bufferMethod · 0.85
setup_bufferMethod · 0.85
setup_bufferMethod · 0.85
setup_bufferMethod · 0.85
setup_bufferMethod · 0.85
setup_bufferMethod · 0.85
setup_bufferMethod · 0.85

Calls 10

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

Tested by 1

CSRSparseEnvironmentMethod · 0.68