File: papi_sr_ins.c

package info (click to toggle)
papi 5.7.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (186 lines) | stat: -rw-r--r-- 3,887 bytes parent folder | download | duplicates (6)
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
/* This file attempts to test the PAPI_SR_INS	*/
/* performance counter (retired stores).	*/

/* This just does a generic matrix-matrix test			*/
/* Should have a comprehensive assembly language test		*/
/* (see my deterministic benchmark suite) but that would be	*/
/* a lot more complicated.					*/

/* by Vince Weaver, <vincent.weaver@maine.edu>	*/


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>

#include <time.h>

#include "papi.h"
#include "papi_test.h"

#include "display_error.h"

#include "matrix_multiply.h"

#define SLEEP_RUNS 3


int main(int argc, char **argv) {

	int quiet;

	double error;

	int i;
	long long count,high=0,low=0,total=0,average=0;
	long long mmm_count;
	long long expected;
	int retval;
	int eventset=PAPI_NULL;

	quiet=tests_quiet(argc,argv);

	/* Init the PAPI library */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
	}

	if (!quiet) {
		printf("\nTesting PAPI_SR_INS\n\n");
	}

	retval=PAPI_create_eventset(&eventset);
	if (retval!=PAPI_OK) {
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
	}

	retval=PAPI_add_named_event(eventset,"PAPI_SR_INS");
	if (retval!=PAPI_OK) {
		if (!quiet) printf("Could not add PAPI_SR_INS\n");
		test_skip( __FILE__, __LINE__, "adding PAPI_LD_INS", retval );
	}

	/**************/
	/* Sleep test */
	/**************/

	if (!quiet) {
		printf("Testing a sleep of 1 second (%d times):\n",SLEEP_RUNS);
	}


	for(i=0;i<SLEEP_RUNS;i++) {

		PAPI_reset(eventset);
		PAPI_start(eventset);

		sleep(1);

		retval=PAPI_stop(eventset,&count);
		if (retval!=PAPI_OK) {
			test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
		}

		if (count>high) high=count;
		if ((low==0) || (count<low)) low=count;
		total+=count;
	}

	average=total/SLEEP_RUNS;

	if (!quiet) {
		printf("\tAverage should be low, as no stores when sleeping\n");
		printf("\tMeasured average: %lld\n",average);
	}

	if (average>100000) {
		if (!quiet) printf("Average cycle count too high!\n");
		test_fail( __FILE__, __LINE__, "idle average", retval );
	}

	/*****************************/
	/* testing Matrix Matrix GHz */
	/*****************************/

	if (!quiet) {
		printf("\nTesting with matrix matrix multiply\n");
	}

	PAPI_reset(eventset);
	PAPI_start(eventset);

	naive_matrix_multiply(quiet);

	retval=PAPI_stop(eventset,&count);

	if (retval!=PAPI_OK) {
		test_fail( __FILE__, __LINE__, "Problem stopping!", retval );
	}

	expected=naive_matrix_multiply_estimated_stores(quiet);

	if (!quiet) {
		printf("\tActual measured stores = %lld\n",count);
	}

	error=  100.0 * (double)(count-expected) / (double)expected;

	if (!quiet) {
		printf("\tExpected %lld, got %lld\n",expected,count);
		printf("\tError=%.2f%%\n",error);
	}

	if ((error>10.0) || (error<-10.0)) {

		if (!quiet) printf("Error too high!\n");
		test_fail( __FILE__, __LINE__, "Error too high", retval );
	}


	mmm_count=count;

	/************************************/
	/* Check for Linear Speedup         */
	/************************************/

	if (!quiet) printf("\nTesting for a linear cycle increase\n");

#define REPITITIONS 2

	PAPI_reset(eventset);
	PAPI_start(eventset);

	for(i=0;i<REPITITIONS;i++) {
		naive_matrix_multiply(quiet);
	}

	retval=PAPI_stop(eventset,&count);

	if (retval!=PAPI_OK) {
		test_fail( __FILE__, __LINE__, "Problem stopping!", retval );
	}

	expected=mmm_count*REPITITIONS;

	error=  100.0 * (double)(count-expected) / (double)expected;

	if (!quiet) {
		printf("\tExpected %lld, got %lld\n",expected,count);
		printf("\tError=%.2f%%\n",error);
	}

	if ((error>10.0) || (error<-10.0)) {

		if (!quiet) printf("Error too high!\n");
		test_fail( __FILE__, __LINE__, "Error too high", retval );
	}

	if (!quiet) printf("\n");

	test_pass( __FILE__ );

	return 0;
}