PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_fp_ops.c
Go to the documentation of this file.
1/* This file attempts to test the floating point */
2/* performance counter PAPI_FP_OPS */
3
4/* by Vince Weaver, <vincent.weaver@maine.edu> */
5
6/* Note! There are many many many things that can go wrong */
7/* when trying to get a sane floating point measurement. */
8
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <unistd.h>
13#include <string.h>
14
15#include "papi.h"
16#include "papi_test.h"
17
18#include "display_error.h"
19#include "testcode.h"
20
21
22int main(int argc, char **argv) {
23
24 int num_runs=100,i;
25 long long high=0,low=0,average=0,expected=1500000;
26 double error,double_result;
27
28 long long count,total=0;
29 int quiet=0,retval,ins_result;
30 int eventset=PAPI_NULL;
31
32 quiet=tests_quiet(argc,argv);
33
34 if (!quiet) {
35 printf("\nTesting the PAPI_FP_OPS event.\n\n");
36 }
37
38 /* Init the PAPI library */
40 if ( retval != PAPI_VER_CURRENT ) {
41 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
42 }
43
44 /* Create the eventset */
46 if (retval!=PAPI_OK) {
47 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
48 }
49
50 /* Add FP_OPS event */
51 retval=PAPI_add_named_event(eventset,"PAPI_FP_OPS");
52 if (retval!=PAPI_OK) {
53 if (!quiet) fprintf(stderr,"PAPI_FP_OPS not available!\n");
54 test_skip( __FILE__, __LINE__, "adding PAPI_FP_OPS", retval );
55 }
56
57 /**************************************/
58 /* Test a loop with no floating point */
59 /**************************************/
60 total=0; high=0; low=0;
61 expected=0;
62
63 if (!quiet) {
64 printf("Testing a loop with %lld floating point (%d times):\n",
65 expected,num_runs);
66 }
67
68 for(i=0;i<num_runs;i++) {
69 PAPI_reset(eventset);
70 PAPI_start(eventset);
71
72 ins_result=branches_testcode();
73
74 retval=PAPI_stop(eventset,&count);
75
76 if (ins_result==CODE_UNIMPLEMENTED) {
77 fprintf(stderr,"\tCode unimplemented\n");
78 test_skip( __FILE__, __LINE__, "unimplemented", 0);
79 }
80
81 if (retval!=PAPI_OK) {
82 test_fail( __FILE__, __LINE__,
83 "reading PAPI_TOT_INS", retval );
84 }
85
86 if (count>high) high=count;
87 if ((low==0) || (count<low)) low=count;
88 total+=count;
89 }
90
91 average=(total/num_runs);
92
93 error=display_error(average,high,low,expected,quiet);
94
95 if (average>10) {
96 if (!quiet) printf("Unexpected FP event value\n");
97 test_fail( __FILE__, __LINE__, "Unexpected FP event", 1 );
98 }
99
100 if (!quiet) printf("\n");
101
102 /*******************************************/
103 /* Test a single-precision matrix multiply */
104 /*******************************************/
105 total=0; high=0; low=0;
107
108 num_runs=3;
109
110 if (!quiet) {
111 printf("Testing a matrix multiply with %lld single-precision FP operations (%d times)\n",
112 expected,num_runs);
113 }
114
115 for(i=0;i<num_runs;i++) {
116
117 PAPI_reset(eventset);
118 PAPI_start(eventset);
119
121
122 retval=PAPI_stop(eventset,&count);
123
124 if (retval!=PAPI_OK) {
125 test_fail( __FILE__, __LINE__,
126 "reading PAPI_TOT_INS", retval );
127 }
128
129 if (count>high) high=count;
130 if ((low==0) || (count<low)) low=count;
131 total+=count;
132 }
133
134 if (!quiet) printf("Result %lf\n",double_result);
135
136 average=(total/num_runs);
137
138 error=display_error(average,high,low,expected,quiet);
139
140 if ((error > 1.0) || (error<-1.0)) {
141 if (!quiet) printf("Instruction count off by more than 1%%\n");
142 test_fail( __FILE__, __LINE__, "Error too high", 1 );
143 }
144
145 if (!quiet) printf("\n");
146
147
148 /*******************************************/
149 /* Test a double-precision matrix multiply */
150 /*******************************************/
151 total=0; high=0; low=0;
153
154 num_runs=3;
155
156 if (!quiet) {
157 printf("Testing a matrix multiply with %lld double-precision FP operations (%d times)\n",
158 expected,num_runs);
159 }
160
161 for(i=0;i<num_runs;i++) {
162
163 PAPI_reset(eventset);
164 PAPI_start(eventset);
165
167
168 retval=PAPI_stop(eventset,&count);
169
170 if (retval!=PAPI_OK) {
171 test_fail( __FILE__, __LINE__,
172 "reading PAPI_TOT_INS", retval );
173 }
174
175 if (count>high) high=count;
176 if ((low==0) || (count<low)) low=count;
177 total+=count;
178 }
179
180 if (!quiet) printf("Result %lf\n",double_result);
181
182 average=(total/num_runs);
183
184 error=display_error(average,high,low,expected,quiet);
185
186 if ((error > 1.0) || (error<-1.0)) {
187 if (!quiet) printf("Instruction count off by more than 1%%\n");
188 test_fail( __FILE__, __LINE__, "Error too high", 1 );
189 }
190
191 if (!quiet) printf("\n");
192
193 test_pass( __FILE__ );
194
196
197 return 0;
198}
int i
int branches_testcode(void)
static long count
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
double flops_double_matrix_matrix_multiply(void)
int flops_double_init_matrix(void)
float flops_float_matrix_matrix_multiply(void)
int flops_float_init_matrix(void)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
Return codes and api definitions.
FILE * stderr
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 main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
static int total
Definition: rapl_overflow.c:9
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int retval
Definition: zero_fork.c:53