PAPI 7.1.0.0
Loading...
Searching...
No Matches
libmsr_basic.c File Reference
Include dependency graph for libmsr_basic.c:

Go to the source code of this file.

Data Structures

union  ll_dbl_union_t
 

Macros

#define MAX_LIBMSR_EVENTS   64
 Tests basic functionality of libmsr component.
 
#define MATRIX_SIZE   1024
 

Functions

void run_test (int quiet)
 
int main (int argc, char **argv)
 

Variables

static double a [MATRIX_SIZE][MATRIX_SIZE]
 
static double b [MATRIX_SIZE][MATRIX_SIZE]
 
static double c [MATRIX_SIZE][MATRIX_SIZE]
 

Macro Definition Documentation

◆ MATRIX_SIZE

#define MATRIX_SIZE   1024

Definition at line 36 of file libmsr_basic.c.

◆ MAX_LIBMSR_EVENTS

#define MAX_LIBMSR_EVENTS   64
Author
Asim YarKhan
Vince Weaver (original rapl version)

Test case for libmsr component

Definition at line 22 of file libmsr_basic.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 76 of file libmsr_basic.c.

77{
78 int retval,cid,libmsr_cid=-1,numcmp;
79 int EventSet = PAPI_NULL;
80 long long *values;
81 int num_events=0;
82 int code;
86 int r,i, do_wrap = 0;
87 const PAPI_component_info_t *cmpinfo = NULL;
88 PAPI_event_info_t evinfo;
89 long long before_time,after_time;
90 double elapsed_time;
91 ll_dbl_union_t tmp_ll_dbl;
92 int repeat;
93
94 (void) do_wrap; // 'wrap' option is not implemented.
95 /* Set TESTS_QUIET variable */
96 tests_quiet( argc, argv );
97 if ( argc > 1 && strstr( argv[1], "-w" ) )
98 do_wrap = 1;
99
100 /* PAPI Initialization */
102 if ( retval != PAPI_VER_CURRENT )
103 test_fail( __FILE__, __LINE__,"PAPI_library_init failed\n",retval );
104
105 if ( !TESTS_QUIET )
106 printf( "Trying all LIBMSR events\n" );
107
108 numcmp = PAPI_num_components();
109
110 for( cid=0; cid<numcmp; cid++ ) {
111
112 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
113 test_fail( __FILE__, __LINE__,"PAPI_get_component_info failed\n", 0 );
114
115 if ( strstr( cmpinfo->name,"libmsr" ) ) {
116 libmsr_cid=cid;
117 if ( !TESTS_QUIET ) printf( "Found libmsr component at cid %d\n",libmsr_cid );
118 if ( cmpinfo->disabled ) {
119 if ( !TESTS_QUIET ) printf( "libmsr component disabled: %s\n",cmpinfo->disabled_reason );
120 test_skip( __FILE__,__LINE__, "libmsr component disabled", 0 );
121 }
122 break;
123 }
124 }
125
126 /* Component not found */
127 if ( cid==numcmp )
128 test_skip( __FILE__,__LINE__,"No libmsr component found\n",0 );
129
130 /* Create EventSet */
132 if ( retval != PAPI_OK )
133 test_fail( __FILE__, __LINE__, "PAPI_create_eventset()",retval );
134
135 /* Add all events */
136 num_events = 0;
137 code = PAPI_NATIVE_MASK;
138 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, libmsr_cid );
139 while ( r == PAPI_OK ) {
141 if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
142 retval = PAPI_get_event_info( code,&evinfo );
143 if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__,"Error getting event info\n",retval );
144 strncpy( units[num_events], evinfo.units, sizeof( units[0] )-1 );
145 // buffer must be null terminated to safely use strstr operation on it below
146 units[num_events][sizeof( units[0] )-1] = '\0';
148
149 retval = PAPI_add_event( EventSet, code );
150 if ( retval != PAPI_OK )
151 break; /* We've hit an event limit */
152 num_events++;
153
154 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, libmsr_cid );
155 }
156
157 values=calloc( num_events,sizeof( long long ) );
158 if ( values==NULL )
159 test_fail( __FILE__, __LINE__,"No memory - calloc failed",retval );
160
161 if ( !TESTS_QUIET ) printf( "Starting measurements...\n" );
162
163 /* Start Counting */
166 if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start()",retval );
167
168 for ( repeat=0; repeat<3; repeat++ ) {
169
170 /* Run test */
172
173 /* Stop Counting */
176 if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
177
178 elapsed_time=( ( double )( after_time-before_time ) )/1.0e9;
179
180 if ( !TESTS_QUIET ) {
181 printf( "Stopping measurements, took %.3fs, gathering results...\n", elapsed_time );
182 for( i=0; i<num_events; i++ ) {
183 tmp_ll_dbl.ll = values[i];
185 printf( "%-40s %12.6f %s\n", event_names[i], tmp_ll_dbl.dbl, units[i] );
186 } else if ( data_type[i]==PAPI_DATATYPE_UINT64 ) {
187 printf( "%-40s %12lld %s\n", event_names[i], tmp_ll_dbl.ll, units[i] );
188 }
189 }
190 printf( "\n" );
191 }
192 }
193
195 if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop()",retval );
196
198 if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset()",retval );
199
201 if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__,"PAPI_destroy_eventset()",retval );
202
203 test_pass( __FILE__ );
204
205 return 0;
206}
static const char * event_names[2]
Definition: Gamum.c:27
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
Get the event's name and description info.
Get real time counter value in nanoseconds.
initialize the PAPI library.
Get the number of components available on the system.
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_MIN_STR_LEN
Definition: f90papi.h:208
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DATATYPE_FP64
Definition: f90papi.h:171
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_DATATYPE_UINT64
Definition: f90papi.h:278
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void run_test(int quiet)
Definition: libmsr_basic.c:43
#define MAX_LIBMSR_EVENTS
Tests basic functionality of libmsr component.
Definition: libmsr_basic.c:22
static int num_events
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_NATIVE_MASK
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int data_type[MAX_EVENTS]
Definition: powercap_plot.c:16
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
static long long after_time
Definition: rapl_overflow.c:15
static long long before_time
Definition: rapl_overflow.c:15
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
long long ll
Definition: libmsr_basic.c:24
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ run_test()

void run_test ( int  quiet)

Definition at line 43 of file libmsr_basic.c.

44{
45 double s;
46 int i,j,k;
47 if ( !quiet )
48 printf( "Doing a naive %dx%d MMM...\n",MATRIX_SIZE,MATRIX_SIZE );
49 for( i=0; i<MATRIX_SIZE; i++ ) {
50 for( j=0; j<MATRIX_SIZE; j++ ) {
51 a[i][j]=( double )i*( double )j;
52 b[i][j]=( double )i/( double )( j+5 );
53 }
54 }
55 for( j=0; j<MATRIX_SIZE; j++ ) {
56 for( i=0; i<MATRIX_SIZE; i++ ) {
57 s=0;
58 for( k=0; k<MATRIX_SIZE; k++ ) {
59 s+=a[i][k]*b[k][j];
60 }
61 c[i][j] = s;
62 }
63 }
64 s=0.0;
65 for( i=0; i<MATRIX_SIZE; i++ ) {
66 for( j=0; j<MATRIX_SIZE; j++ ) {
67 s+=c[i][j];
68 }
69 }
70 if ( !quiet ) printf( "Matrix multiply sum: s=%lf\n",s );
71}
double s
Definition: byte_profile.c:36
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
#define MATRIX_SIZE
Definition: libmsr_basic.c:36
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
int quiet
Definition: rapl_overflow.c:19
Here is the caller graph for this function:

Variable Documentation

◆ a

double a[MATRIX_SIZE][MATRIX_SIZE]
static

Definition at line 38 of file libmsr_basic.c.

◆ b

double b[MATRIX_SIZE][MATRIX_SIZE]
static

Definition at line 39 of file libmsr_basic.c.

◆ c

double c[MATRIX_SIZE][MATRIX_SIZE]
static

Definition at line 40 of file libmsr_basic.c.