forked from icl-utk-edu/papi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_multiple_components.c
More file actions
192 lines (148 loc) · 4.69 KB
/
example_multiple_components.c
File metadata and controls
192 lines (148 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/****************************/
/* THIS IS OPEN SOURCE CODE */
/****************************/
/**
* @file example_multiple_components.c
* @author Vince Weaver
* vweaver1@eecs.utk.edu
* test if multiple components can be used at once
*
*
* @brief
* This tests to see if the CPU component and Example component
* can be used simultaneously.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "papi.h"
#include "papi_test.h"
#define NUM_EVENTS 1
int main (int argc, char **argv)
{
int retval;
int EventSet1 = PAPI_NULL, EventSet2 = PAPI_NULL;
long long values1[NUM_EVENTS];
long long values2[NUM_EVENTS];
const PAPI_component_info_t *cmpinfo = NULL;
int numcmp,cid,example_cid=-1;
int code;
int quiet=0;
/* Set TESTS_QUIET variable */
quiet=tests_quiet( argc, argv );
/* PAPI Initialization */
retval = PAPI_library_init( PAPI_VER_CURRENT );
if ( retval != PAPI_VER_CURRENT ) {
test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
}
if (!quiet) {
printf( "Testing simultaneous component use with PAPI %d.%d.%d\n",
PAPI_VERSION_MAJOR( PAPI_VERSION ),
PAPI_VERSION_MINOR( PAPI_VERSION ),
PAPI_VERSION_REVISION( PAPI_VERSION ) );
}
/* Find our component */
numcmp = PAPI_num_components();
for( cid=0; cid<numcmp; cid++) {
if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
test_fail(__FILE__, __LINE__,
"PAPI_get_component_info failed\n", 0);
}
if (!quiet) {
printf("\tComponent %d - %d events - %s\n", cid,
cmpinfo->num_native_events,
cmpinfo->name);
}
if (strstr(cmpinfo->name,"example")) {
/* FOUND! */
example_cid=cid;
}
}
if (example_cid<0) {
test_skip(__FILE__, __LINE__,
"Example component not found\n", 0);
}
if (!quiet) {
printf("\nFound Example Component at id %d\n",example_cid);
}
/* Create an eventset for the Example component */
retval = PAPI_create_eventset( &EventSet1 );
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__,
"PAPI_create_eventset() failed\n", retval );
}
retval = PAPI_event_name_to_code("example:::EXAMPLE_CONSTANT", &code);
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__,
"example:::EXAMPLE_ZERO not found\n",retval );
}
retval = PAPI_add_event( EventSet1, code);
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__,
"PAPI_add_events failed\n", retval );
}
/* Create an eventset for the CPU component */
retval = PAPI_create_eventset( &EventSet2 );
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__,
"PAPI_create_eventset() failed\n", retval );
}
retval = PAPI_event_name_to_code("PAPI_TOT_CYC", &code);
if ( retval != PAPI_OK ) {
test_skip( __FILE__, __LINE__,
"PAPI_TOT_CYC not available\n",retval );
}
retval = PAPI_add_event( EventSet2, code);
if ( retval != PAPI_OK ) {
test_skip( __FILE__, __LINE__,
"NO CPU component found\n", retval );
}
if (!quiet) printf("\nStarting example:::EXAMPLE_CONSTANT and PAPI_TOT_CYC at the same time\n");
/* Start CPU component event */
retval = PAPI_start( EventSet2 );
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__,
"PAPI_start failed\n",retval );
}
/* Start example component */
retval = PAPI_start( EventSet1 );
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__,
"PAPI_start failed\n",retval );
}
/* Stop example component */
retval = PAPI_stop( EventSet1, values1 );
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
}
/* Stop CPU component */
retval = PAPI_stop( EventSet2, values2 );
if ( retval != PAPI_OK ) {
test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
}
if (!quiet) printf("Stopping example:::EXAMPLE_CONSTANT and PAPI_TOT_CYC\n\n");
if (!quiet) printf("Results from example:::EXAMPLE_CONSTANT: %lld\n",values1[0]);
if (values1[0]!=42) {
test_fail( __FILE__, __LINE__, "Result should be 42!\n", 0);
}
if (!quiet) printf("Results from PAPI_TOT_CYC: %lld\n\n",values2[0]);
if (values2[0]<1) {
test_fail( __FILE__, __LINE__, "Result should greater than 0\n", 0);
}
/* Cleanup EventSets */
retval = PAPI_cleanup_eventset(EventSet1);
if (retval != PAPI_OK) {
test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
}
retval = PAPI_cleanup_eventset(EventSet2);
if (retval != PAPI_OK) {
test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
}
/* Destroy EventSets */
retval = PAPI_destroy_eventset(&EventSet2);
if (retval != PAPI_OK) {
test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
}
test_pass( __FILE__ );
return 0;
}