PAPI  5.7.0.0
papi_dp_ops.c
Go to the documentation of this file.
1 /* This file attempts to test the double-precision floating point */
2 /* performance counter PAPI_DP_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 
22 int 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_DP_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 */
45  retval=PAPI_create_eventset(&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_DP_OPS");
52  if (retval!=PAPI_OK) {
53  if (!quiet) fprintf(stderr,"PAPI_DP_OPS not available!\n");
54  test_skip( __FILE__, __LINE__, "adding PAPI_DP_OPS", retval );
55  }
56 
57  /**************************************/
58  /* Test a loop with no floating point */
59  /**************************************/
60  expected=0;
61 
62  if (!quiet) {
63  printf("Testing a loop with %lld floating point (%d times):\n",
64  expected,num_runs);
65  }
66 
67  for(i=0;i<num_runs;i++) {
68  PAPI_reset(eventset);
69  PAPI_start(eventset);
70 
71  ins_result=branches_testcode();
72 
73  retval=PAPI_stop(eventset,&count);
74 
75  if (ins_result==CODE_UNIMPLEMENTED) {
76  fprintf(stderr,"\tCode unimplemented\n");
77  test_skip( __FILE__, __LINE__, "unimplemented", 0);
78  }
79 
80  if (retval!=PAPI_OK) {
81  test_fail( __FILE__, __LINE__,
82  "reading PAPI_TOT_INS", retval );
83  }
84 
85  if (count>high) high=count;
86  if ((low==0) || (count<low)) low=count;
87  total+=count;
88  }
89 
90  average=(total/num_runs);
91 
92  error=display_error(average,high,low,expected,quiet);
93 
94  if (average>10) {
95  if (!quiet) printf("Unexpected FP event value\n");
96  test_fail( __FILE__, __LINE__, "Unexpected FP event", 1 );
97  }
98 
99  if (!quiet) printf("\n");
100 
101  /*******************************************/
102  /* Test a single precision matrix multiply */
103  /*******************************************/
104  total=0; high=0; low=0;
106 
107  expected=expected*0;
108 
109  num_runs=3;
110 
111  if (!quiet) {
112  printf("Testing a matrix multiply with %lld single-precision FP operations (%d times)\n",
113  expected,num_runs);
114  }
115 
116  for(i=0;i<num_runs;i++) {
117 
118  PAPI_reset(eventset);
119  PAPI_start(eventset);
120 
121  double_result=flops_float_matrix_matrix_multiply();
122 
123  retval=PAPI_stop(eventset,&count);
124 
125  if (retval!=PAPI_OK) {
126  test_fail( __FILE__, __LINE__,
127  "reading PAPI_TOT_INS", retval );
128  }
129 
130  if (count>high) high=count;
131  if ((low==0) || (count<low)) low=count;
132  total+=count;
133  }
134 
135  if (!quiet) printf("Result %lf\n",double_result);
136 
137  average=(total/num_runs);
138 
139  error=display_error(average,high,low,expected,quiet);
140 
141  if ((error > 1.0) || (error<-1.0)) {
142  if (!quiet) printf("Instruction count off by more than 1%%\n");
143  test_fail( __FILE__, __LINE__, "Error too high", 1 );
144  }
145 
146  if (!quiet) printf("\n");
147 
148 
149  /*******************************************/
150  /* Test a double precision matrix multiply */
151  /*******************************************/
152  total=0; high=0; low=0;
154 
155  num_runs=3;
156 
157  if (!quiet) {
158  printf("Testing a matrix multiply with %lld double-precision FP operations (%d times)\n",
159  expected,num_runs);
160  }
161 
162  for(i=0;i<num_runs;i++) {
163 
164  PAPI_reset(eventset);
165  PAPI_start(eventset);
166 
167  double_result=flops_double_matrix_matrix_multiply();
168 
169  retval=PAPI_stop(eventset,&count);
170 
171  if (retval!=PAPI_OK) {
172  test_fail( __FILE__, __LINE__,
173  "reading PAPI_TOT_INS", retval );
174  }
175 
176  if (count>high) high=count;
177  if ((low==0) || (count<low)) low=count;
178  total+=count;
179  }
180 
181  if (!quiet) printf("Result %lf\n",double_result);
182 
183  average=(total/num_runs);
184 
185  error=display_error(average,high,low,expected,quiet);
186 
187  if ((error > 1.0) || (error<-1.0)) {
188  if (!quiet) printf("Instruction count off by more than 1%%\n");
189  test_fail( __FILE__, __LINE__, "Error too high", 1 );
190  }
191 
192  if (!quiet) printf("\n");
193 
194 
195  test_pass( __FILE__ );
196 
197  PAPI_shutdown();
198 
199  return 0;
200 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
double flops_double_matrix_matrix_multiply(void)
void test_pass(const char *filename)
Definition: test_utils.c:432
static int expected[NUM_THREADS]
int PAPI_reset(int EventSet)
Definition: papi.c:2459
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
int PAPI_library_init(int version)
Definition: papi.c:500
void PAPI_shutdown(void)
Definition: papi.c:4461
int quiet
Definition: rapl_overflow.c:18
int flops_float_init_matrix(void)
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int branches_testcode(void)
static int total
Definition: rapl_overflow.c:9
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int main(int argc, char **argv)
Definition: papi_dp_ops.c:22
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_start(int EventSet)
Definition: papi.c:2096
float flops_float_matrix_matrix_multiply(void)
int flops_double_init_matrix(void)
static long count
int i
Definition: fileop.c:140