<commit_before>/* ************************************************************************
 * Copyright 2015 Advanced Micro Devices, Inc.
 * ************************************************************************/

#ifndef CUBLAS_BENCHMARK_xSpMdV_HXX__
#define CUBLAS_BENCHMARK_xSpMdV_HXX__

#include "cufunc_common.hpp"
#include "include/mm_reader.hpp"
#include "include/io-exception.hpp"

template <typename T>
class xSpMdV : public cusparseFunc
{
public:
    xSpMdV( StatisticalTimer& timer ): cusparseFunc( timer ), transA( CUSPARSE_OPERATION_NON_TRANSPOSE )
    {
        cusparseStatus_t err = cusparseCreateMatDescr( &descrA );
        CUDA_V_THROW( err, "cusparseCreateMatDescr failed" );

        err = cusparseSetMatType( descrA, CUSPARSE_MATRIX_TYPE_GENERAL );
        CUDA_V_THROW( err, "cusparseSetMatType failed" );

        err = cusparseSetMatIndexBase( descrA, CUSPARSE_INDEX_BASE_ZERO );
        CUDA_V_THROW( err, "cusparseSetMatIndexBase failed" );
    }

    ~xSpMdV( )
    {
        cusparseDestroyMatDescr( descrA );
    }

    void call_func( )
    {
        timer.Start( timer_id );
        xSpMdV_Function( true );
        timer.Stop( timer_id );
    }

    double gflops( )
    {
        return 0.0;
    }

    std::string gflops_formula( )
    {
        return "N/A";
    }

    double bandwidth( )
    {
        //  Assuming that accesses to the vector always hit in the cache after the first access
        //  There are NNZ integers in the cols[ ] array
        //  You access each integer value in row_delimiters[ ] once.
        //  There are NNZ float_types in the vals[ ] array
        //  You read num_cols floats from the vector, afterwards they cache perfectly.
        //  Finally, you write num_rows floats out to DRAM at the end of the kernel.
        return ( sizeof( int )*( n_vals + n_rows ) + sizeof( T ) * ( n_vals + n_cols + n_rows ) ) / time_in_ns( );
    }

    std::string bandwidth_formula( )
    {
        return "GiB/s";
    }

    void setup_buffer( double alpha, double beta, const std::string& path )
    {
        initialize_scalars( alpha, beta );

        if (csrMatrixfromFile( row_offsets, col_indices, values, path.c_str( ) ) )
        {
            throw clsparse::io_exception( "Could not read matrix market header from disk" );
        }
        n_rows = row_offsets.size( );
        n_cols = col_indices.size( );
        n_vals = values.size( );

        cudaError_t err = cudaMalloc( (void**) &device_row_offsets, row_offsets.size( ) * sizeof( int ) );
        CUDA_V_THROW( err, "cudaMalloc device_row_offsets" );

        err = cudaMalloc( (void**) &device_col_indices, col_indices.size( ) * sizeof( int ) );
        CUDA_V_THROW( err, "cudaMalloc device_col_indices" );

        err = cudaMalloc( (void**) &device_values, values.size( ) * sizeof( T ) );
        CUDA_V_THROW( err, "cudaMalloc device_values" );

        err = cudaMalloc( (void**) &device_x, n_cols * sizeof( T ) );
        CUDA_V_THROW( err, "cudaMalloc device_values" );

        err = cudaMalloc( (void**) &device_y, n_rows * sizeof( T ) );
        CUDA_V_THROW( err, "cudaMalloc device_values" );
    }

    void initialize_cpu_buffer( )
    {<commit_msg>Bugfix on cuda benchmark; invalid matrix sizes were stored<commit_after>/* ************************************************************************
 * Copyright 2015 Advanced Micro Devices, Inc.
 * ************************************************************************/

#ifndef CUBLAS_BENCHMARK_xSpMdV_HXX__
#define CUBLAS_BENCHMARK_xSpMdV_HXX__

#include "cufunc_common.hpp"
#include "include/mm_reader.hpp"
#include "include/io-exception.hpp"

template <typename T>
class xSpMdV : public cusparseFunc
{
public:
    xSpMdV( StatisticalTimer& timer ): cusparseFunc( timer ), transA( CUSPARSE_OPERATION_NON_TRANSPOSE )
    {
        cusparseStatus_t err = cusparseCreateMatDescr( &descrA );
        CUDA_V_THROW( err, "cusparseCreateMatDescr failed" );

        err = cusparseSetMatType( descrA, CUSPARSE_MATRIX_TYPE_GENERAL );
        CUDA_V_THROW( err, "cusparseSetMatType failed" );

        err = cusparseSetMatIndexBase( descrA, CUSPARSE_INDEX_BASE_ZERO );
        CUDA_V_THROW( err, "cusparseSetMatIndexBase failed" );
    }

    ~xSpMdV( )
    {
        cusparseDestroyMatDescr( descrA );
    }

    void call_func( )
    {
        timer.Start( timer_id );
        xSpMdV_Function( true );
        timer.Stop( timer_id );
    }

    double gflops( )
    {
        return 0.0;
    }

    std::string gflops_formula( )
    {
        return "N/A";
    }

    double bandwidth( )
    {
        //  Assuming that accesses to the vector always hit in the cache after the first access
        //  There are NNZ integers in the cols[ ] array
        //  You access each integer value in row_delimiters[ ] once.
        //  There are NNZ float_types in the vals[ ] array
        //  You read num_cols floats from the vector, afterwards they cache perfectly.
        //  Finally, you write num_rows floats out to DRAM at the end of the kernel.
        return ( sizeof( int )*( n_vals + n_rows ) + sizeof( T ) * ( n_vals + n_cols + n_rows ) ) / time_in_ns( );
    }

    std::string bandwidth_formula( )
    {
        return "GiB/s";
    }

    void setup_buffer( double alpha, double beta, const std::string& path )
    {
        initialize_scalars( alpha, beta );

        if( sparseHeaderfromFile( &n_vals, &n_rows, &n_cols, path.c_str( ) ) )
        {
            throw clsparse::io_exception( "Could not read matrix market header from disk" );
        }

        if (csrMatrixfromFile( row_offsets, col_indices, values, path.c_str( ) ) )
        {
            throw clsparse::io_exception( "Could not read matrix market header from disk" );
        }

        cudaError_t err = cudaMalloc( (void**) &device_row_offsets, row_offsets.size( ) * sizeof( int ) );
        CUDA_V_THROW( err, "cudaMalloc device_row_offsets" );

        err = cudaMalloc( (void**) &device_col_indices, col_indices.size( ) * sizeof( int ) );
        CUDA_V_THROW( err, "cudaMalloc device_col_indices" );

        err = cudaMalloc( (void**) &device_values, values.size( ) * sizeof( T ) );
        CUDA_V_THROW( err, "cudaMalloc device_values" );

        err = cudaMalloc( (void**) &device_x, n_cols * sizeof( T ) );
        CUDA_V_THROW( err, "cudaMalloc device_values" );

        err = cudaMalloc( (void**) &device_y, n_rows * sizeof( T ) );
        CUDA_V_THROW( err, "cudaMalloc device_values" );
    }

    void initialize_cpu_buffer( )
    {
{'fraction_non_alphanumeric': 0.1453764760006134, 'fraction_numerical': 0.0018402085569697898, 'mean_word_length': 2.8409893992932864, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5393103', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2128, 'n_words': 514}