Example #1
0
    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" );


    }
Example #2
0
TYPED_TEST(Blas2, csrmv_vector)
{
    // To call csrmv vector we need to artificially get rid of the rowBlocks data
    using CSRE = CSREnvironment;

    cl_int cl_status;
    cl_status = clReleaseMemObject(CSRE::csrSMatrix.rowBlocks);
    ASSERT_EQ(CL_SUCCESS, cl_status);
    CSRE::csrSMatrix.rowBlocks = nullptr;

    cl_status = clReleaseMemObject(CSRE::csrDMatrix.rowBlocks);
    ASSERT_EQ(CL_SUCCESS, cl_status);
    CSRE::csrDMatrix.rowBlocks = nullptr;

    CSRE::csrSMatrix.rowBlockSize = 0;
    CSRE::csrDMatrix.rowBlockSize = 0;

    this->test_csrmv();

    // After calling the kernel we need to recreate the rowBlocks data for
    // later use.

    clsparseStatus status;
    status = clsparseCsrMetaSize( &CSRE::csrSMatrix, CLSE::control );
    ASSERT_EQ(clsparseSuccess, status);

    status = clsparseCsrMetaSize( &CSRE::csrDMatrix, CLSE::control );
    ASSERT_EQ(clsparseSuccess, status);

    CSRE::csrSMatrix.rowBlocks =
            ::clCreateBuffer( CLSE::context, CL_MEM_READ_WRITE,
                              CSRE::csrSMatrix.rowBlockSize * sizeof( cl_ulong ),
                              NULL, &cl_status );

    ASSERT_EQ(CL_SUCCESS, cl_status);

    CSRE::csrDMatrix.rowBlocks = CSRE::csrSMatrix.rowBlocks;
    ::clRetainMemObject( CSRE::csrDMatrix.rowBlocks );

    status = clsparseCsrMetaCompute(&CSRE::csrSMatrix, CLSE::control );
    ASSERT_EQ (clsparseSuccess, status);
    status = clsparseCsrMetaCompute(&CSRE::csrDMatrix, CLSE::control );
    ASSERT_EQ (clsparseSuccess, status);
}
Example #3
0
    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