Skip to content

Commit

Permalink
Merge pull request #80 from adanalis/master
Browse files Browse the repository at this point in the history
Added an SDE that counts flops to BLAS++.
  • Loading branch information
mgates3 authored Jun 19, 2024
2 parents 5d8514a + e793b74 commit fb00463
Show file tree
Hide file tree
Showing 49 changed files with 226 additions and 11 deletions.
47 changes: 37 additions & 10 deletions include/blas/counter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "blas/defines.h"
#include "blas/util.hh"
#include "blas/flops.hh"
#include <atomic>

#ifdef BLAS_HAVE_PAPI
#include "sde_lib.h"
Expand Down Expand Up @@ -230,13 +231,12 @@ public:
};

//--------------------------------------------------------------------------
/// Initializes PAPI counting set on first call.
/// Without PAPI, returns null.
/// @return PAPI counting set.
static CountingSet* get()
/// Initializes PAPI counters on first call.
/// @return reference to counter class.
static counter &get()
{
static counter s_cnt;
return s_cnt.set_;
return s_cnt;
}

//--------------------------------------------------------------------------
Expand All @@ -246,7 +246,7 @@ public:
static void insert( T element, Id id )
{
#ifdef BLAS_HAVE_PAPI
get()->insert( element, uint32_t( id ) );
get().set_->insert( element, uint32_t( id ) );
#endif
}

Expand All @@ -258,10 +258,33 @@ public:
static void insert( size_t hashable_size, T element, Id id )
{
#ifdef BLAS_HAVE_PAPI
get()->insert( hashable_size, element, uint32_t( id ) );
get().set_->insert( hashable_size, element, uint32_t( id ) );
#endif
}

//--------------------------------------------------------------------------
/// Get the current flop count.
/// Without PAPI, returns zero.
static long long int get_flop_count(std::atomic<long long> *atmc_var)
{
long long int fp = 0;
#ifdef BLAS_HAVE_PAPI
fp = *atmc_var;
#endif
return fp;
}

//--------------------------------------------------------------------------
/// Increment the current flop count.
/// Without PAPI, does nothing.
static void inc_flop_count(long long int fp)
{
#ifdef BLAS_HAVE_PAPI
get().total_flop_count_ += fp;
#endif
return;
}

//--------------------------------------------------------------------------
/// TODO
/// Prints out all elements in the BLAS++ counting set.
Expand Down Expand Up @@ -707,17 +730,21 @@ public:

private:
//--------------------------------------------------------------------------
/// Constructor initializes PAPI counting set on first call to get().
counter():
set_( nullptr )
/// Constructor initializes SDEs on first call to get().
counter()
{
set_ = nullptr;
total_flop_count_ = -1;
#ifdef BLAS_HAVE_PAPI
papi_sde::PapiSde sde( "blas" );
set_ = sde.create_counting_set( "counter" );
total_flop_count_ = 0;
sde.register_counter_cb("flops", PAPI_SDE_RO|PAPI_SDE_DELTA, get_flop_count, total_flop_count_);
#endif
}

CountingSet* set_;
std::atomic<long long> total_flop_count_;
}; // class count

} // namespace blas
Expand Down
3 changes: 3 additions & 0 deletions src/asum.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ real_type<scalar_t> asum(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::asum );

double gflops = 1e9 * blas::Gflop< scalar_t >::asum( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/axpy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ void axpy(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::axpy );

double gflops = 1e9 * blas::Gflop< scalar_t >::axpy( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ void copy(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::copy );

double gflops = 1e9 * blas::Gflop< scalar_t >::copy( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_batch_gemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ void gemm(
memset( &element, 0, sizeof( element ) );
element = { transA_, transB_, m_, n_, k_, batch_size };
counter::insert( element, counter::Id::dev_batch_gemm );

double gflops = 1e9 * blas::Gflop< scalar_t >::gemm( m, n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// gemm needs 3 arrays (A, B, and C).
Expand Down
3 changes: 3 additions & 0 deletions src/device_batch_hemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void hemm(
memset( &element, 0, sizeof( element ) );
element = { batch_size };
counter::insert( element, counter::Id::dev_batch_hemm );

double gflops = 1e9 * blas::Gflop< scalar_t >::hemm( side, m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

queue.fork();
Expand Down
3 changes: 3 additions & 0 deletions src/device_copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void copy(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::dev_copy );

double gflops = 1e9 * blas::Gflop< scalar_t >::copy( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_dot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void dot(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::dev_dot );

double gflops = 1e9 * blas::Gflop< scalar_t >::dot( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_gemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void gemm(
memset( &element, 0, sizeof( element ) );
element = { transA, transB, m, n, k };
counter::insert( element, counter::Id::dev_gemm );

double gflops = 1e9 * blas::Gflop< scalar_t >::gemm( m, n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_hemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ void hemm(
memset( &element, 0, sizeof( element ) );
element = { side, uplo, m, n };
counter::insert( element, counter::Id::dev_hemm );

double gflops = 1e9 * blas::Gflop< scalar_t >::hemm( side, m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_her2k.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void her2k(
memset( &element, 0, sizeof( element ) );
element = { uplo, trans, n, k };
counter::insert( element, counter::Id::dev_her2k );

double gflops = 1e9 * blas::Gflop< scalar_t >::her2k( n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_herk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ void herk(
memset( &element, 0, sizeof( element ) );
element = { uplo, trans, n, k };
counter::insert( element, counter::Id::dev_herk );

double gflops = 1e9 * blas::Gflop< scalar_t >::herk( n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_nrm2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void nrm2(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::dev_nrm2 );

double gflops = 1e9 * blas::Gflop< scalar_t >::nrm2( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_scal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void scal(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::dev_scal );

double gflops = 1e9 * blas::Gflop< scalar_t >::scal( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_swap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void swap(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::dev_swap );

double gflops = 1e9 * blas::Gflop< scalar_t >::swap( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_symm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ void symm(
memset( &element, 0, sizeof( element ) );
element = { side, uplo, m, n };
counter::insert( element, counter::Id::dev_symm );

double gflops = 1e9 * blas::Gflop< scalar_t >::symm( side, m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_syr2k.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ void syr2k(
memset( &element, 0, sizeof( element ) );
element = { uplo, trans, n, k };
counter::insert( element, counter::Id::dev_syr2k );

double gflops = 1e9 * blas::Gflop< scalar_t >::syr2k( n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_syrk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ void syrk(
memset( &element, 0, sizeof( element ) );
element = { uplo, trans, n, k };
counter::insert( element, counter::Id::dev_syrk );

double gflops = 1e9 * blas::Gflop< scalar_t >::syrk( n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_trmm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ void trmm(
memset( &element, 0, sizeof( element ) );
element = { side, uplo, trans, diag, m, n };
counter::insert( element, counter::Id::dev_trmm );

double gflops = 1e9 * blas::Gflop< scalar_t >::trmm( side, m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/device_trsm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ void trsm(
memset( &element, 0, sizeof( element ) );
element = { side, uplo, trans, diag, m, n };
counter::insert( element, counter::Id::dev_trsm );

double gflops = 1e9 * blas::Gflop< scalar_t >::trsm( side, m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/dot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ scalar_t dot(
memset( &element, 0, sizeof( element ) );
element = { n };
counter::insert( element, counter::Id::dot );

double gflops = 1e9 * blas::Gflop< scalar_t >::dot( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
4 changes: 4 additions & 0 deletions src/gemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ void gemm(
memset( &element, 0, sizeof( element ) );
element = { transA, transB, m, n, k };
counter::insert( element, counter::Id::gemm );

double gflops = 1e9 * blas::Gflop< scalar_t >::gemm( m, n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down Expand Up @@ -274,6 +277,7 @@ papi_handle_t papi_sde_hook_list_events( papi_sde_fptr_struct_t* fptr_struct )
papi_handle_t tmp_handle;
tmp_handle = fptr_struct->init( "blas" );
fptr_struct->create_counting_set( tmp_handle, "counter", NULL );
fptr_struct->register_counter_cb( tmp_handle, "flops", PAPI_SDE_RO|PAPI_SDE_DELTA, PAPI_SDE_long_long, NULL, NULL);
return tmp_handle;
}

Expand Down
3 changes: 3 additions & 0 deletions src/gemv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ void gemv(
memset( &element, 0, sizeof( element ) );
element = { trans, m, n };
counter::insert( element, counter::Id::gemv );

double gflops = 1e9 * blas::Gflop< scalar_t >::gemv( m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
6 changes: 6 additions & 0 deletions src/ger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ void ger(
memset( &element, 0, sizeof( element ) );
element = { m, n };
counter::insert( element, counter::Id::ger );

double gflops = 1e9 * blas::Gflop< scalar_t >::ger( m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down Expand Up @@ -222,6 +225,9 @@ void geru(
memset( &element, 0, sizeof( element ) );
element = { m, n };
counter::insert( element, counter::Id::geru );

double gflops = 1e9 * blas::Gflop< scalar_t >::ger( m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

blas_int m_ = to_blas_int( m );
Expand Down
3 changes: 3 additions & 0 deletions src/hemm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ void hemm(
memset( &element, 0, sizeof( element ) );
element = { side, uplo, m, n };
counter::insert( element, counter::Id::hemm );

double gflops = 1e9 * blas::Gflop< scalar_t >::hemm( side, m, n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/hemv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ void hemv(
memset( &element, 0, sizeof( element ) );
element = { uplo, n };
counter::insert( element, counter::Id::hemv );

double gflops = 1e9 * blas::Gflop< scalar_t >::hemv( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/her.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void her(
memset( &element, 0, sizeof( element ) );
element = { uplo, n };
counter::insert( element, counter::Id::her );

double gflops = 1e9 * blas::Gflop< scalar_t >::her( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/her2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ void her2(
memset( &element, 0, sizeof( element ) );
element = { uplo, n };
counter::insert( element, counter::Id::her2 );

double gflops = 1e9 * blas::Gflop< scalar_t >::her2( n );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
3 changes: 3 additions & 0 deletions src/her2k.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ void her2k(
memset( &element, 0, sizeof( element ) );
element = { uplo, trans, n, k };
counter::insert( element, counter::Id::her2k );

double gflops = 1e9 * blas::Gflop< scalar_t >::her2k( n, k );
counter::inc_flop_count( (long long int)gflops );
#endif

// convert arguments
Expand Down
Loading

0 comments on commit fb00463

Please sign in to comment.