Skip to content

Commit 309ad13

Browse files
authored
Merge branch 'master' into xt_ci_build_compatibility
2 parents a5bf609 + 1d6edf9 commit 309ad13

File tree

4 files changed

+311
-6
lines changed

4 files changed

+311
-6
lines changed

CMakeLists.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ option(VTR_ENABLE_PROFILING "Enable performance profiler (gprof)" OFF)
3232
option(VTR_ENABLE_COVERAGE "Enable code coverage tracking (gcov)" OFF)
3333
option(VTR_ENABLE_DEBUG_LOGGING "Enable debug logging" OFF)
3434
option(VTR_ENABLE_VERBOSE "Enable increased debug verbosity" OFF)
35+
option(SPEC_CPU "Enable SPEC CPU v8 support" OFF)
3536

3637
#Allow the user to decide whether to compile the graphics library
3738
set(VPR_USE_EZGL "auto" CACHE STRING "Specify whether vpr uses the graphics library")
@@ -298,6 +299,16 @@ if(VTR_ENABLE_VERBOSE)
298299
message(STATUS "Enabling increased debugging verbosity")
299300
endif()
300301

302+
#
303+
# Build for SPEC CPU Benchmark v8
304+
#
305+
set(SPEC_CPU_FLAGS "")
306+
if(SPEC_CPU)
307+
# Enable SPEC CPU flag - Maximizes portability of code and minimizing the variation in how much work we do on different platforms
308+
set(SPEC_CPU_FLAGS "-DSPEC_CPU")
309+
message(STATUS "SPEC CPU FLAGS: ${SPEC_CPU_FLAGS}")
310+
endif()
311+
301312
if (CMAKE_MAKE_PROGRAM EQUAL "ninja" )
302313
#Only for coloured output for ninja, it may be desired
303314
#to not force colours with other make programs (e.g. if
@@ -315,7 +326,7 @@ endif()
315326
# Set final flags
316327
#
317328
separate_arguments(
318-
ADDITIONAL_FLAGS UNIX_COMMAND "${SANITIZE_FLAGS} ${PROFILING_FLAGS} ${COVERAGE_FLAGS} ${LOGGING_FLAGS} ${COLORED_COMPILE} ${EXTRA_FLAGS}"
329+
ADDITIONAL_FLAGS UNIX_COMMAND "${SANITIZE_FLAGS} ${PROFILING_FLAGS} ${COVERAGE_FLAGS} ${LOGGING_FLAGS} ${COLORED_COMPILE} ${EXTRA_FLAGS} ${SPEC_CPU_FLAGS}"
319330
)
320331
separate_arguments(
321332
WARN_FLAGS UNIX_COMMAND "${WARN_FLAGS}"

libs/libvtrutil/src/specrand.cpp

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* * For inclusion in the SPEC cpu benchmarks
3+
* This file implements the random number generation necessary for the SPEC cpu benchmarks. The functions
4+
* defined here are used in vtr_random.h/cpp
5+
*
6+
*
7+
* A C-program for MT19937, with initialization improved 2002/1/26.
8+
* Coded by Takuji Nishimura and Makoto Matsumoto.
9+
*
10+
* Before using, initialize the state by using init_genrand(seed)
11+
* or init_by_array(init_key, key_length).
12+
*
13+
* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
14+
* All rights reserved.
15+
* Copyright (C) 2005, Mutsuo Saito,
16+
* All rights reserved.
17+
*
18+
* Redistribution and use in source and binary forms, with or without
19+
* modification, are permitted provided that the following conditions
20+
* are met:
21+
*
22+
* 1. Redistributions of source code must retain the above copyright
23+
* notice, this list of conditions and the following disclaimer.
24+
*
25+
* 2. Redistributions in binary form must reproduce the above copyright
26+
* notice, this list of conditions and the following disclaimer in the
27+
* documentation and/or other materials provided with the distribution.
28+
*
29+
* 3. The names of its contributors may not be used to endorse or promote
30+
* products derived from this software without specific prior written
31+
* permission.
32+
*
33+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44+
*
45+
*
46+
* Any feedback is very welcome.
47+
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
48+
* email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
49+
*/
50+
/* Slightly modified for use in SPEC CPU by Cloyce D. Spradling (5 Nov 2009)
51+
*/
52+
53+
#include "specrand.h"
54+
55+
/* Period parameters */
56+
#define N 624
57+
#define M 397
58+
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
59+
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
60+
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
61+
62+
static unsigned long mt[N]; /* the array for the state vector */
63+
static int mti = N + 1; /* mti==N+1 means mt[N] is not initialized */
64+
65+
void spec_srand(int seed) {
66+
spec_init_genrand((unsigned long)seed);
67+
}
68+
69+
/* Just a copy of spec_genrand_real2() */
70+
double spec_rand() {
71+
return spec_genrand_int32() * (1.0 / 4294967296.0);
72+
}
73+
74+
/* Just a copy of spec_genrand_int31() */
75+
long spec_lrand48() {
76+
return (long)(spec_genrand_int32() >> 1);
77+
}
78+
79+
/* initializes mt[N] with a seed */
80+
void spec_init_genrand(unsigned long s) {
81+
mt[0] = s & 0xffffffffUL;
82+
for (mti = 1; mti < N; mti++) {
83+
mt[mti] = (1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti);
84+
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
85+
/* In the previous versions, MSBs of the seed affect */
86+
/* only MSBs of the array mt[]. */
87+
/* 2002/01/09 modified by Makoto Matsumoto */
88+
mt[mti] &= 0xffffffffUL;
89+
/* for >32 bit machines */
90+
}
91+
}
92+
93+
/* initialize by an array with array-length */
94+
/* init_key is the array for initializing keys */
95+
/* key_length is its length */
96+
/* slight change for C++, 2004/2/26 */
97+
void spec_init_by_array(unsigned long init_key[], int key_length) {
98+
int i, j, k;
99+
spec_init_genrand(19650218UL);
100+
i = 1;
101+
j = 0;
102+
k = (N > key_length ? N : key_length);
103+
for (; k; k--) {
104+
mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL))
105+
+ init_key[j] + j; /* non linear */
106+
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
107+
i++;
108+
j++;
109+
if (i >= N) {
110+
mt[0] = mt[N - 1];
111+
i = 1;
112+
}
113+
if (j >= key_length) j = 0;
114+
}
115+
for (k = N - 1; k; k--) {
116+
mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL))
117+
- i; /* non linear */
118+
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
119+
i++;
120+
if (i >= N) {
121+
mt[0] = mt[N - 1];
122+
i = 1;
123+
}
124+
}
125+
126+
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
127+
}
128+
129+
/* generates a random number on [0,0xffffffff]-interval */
130+
unsigned long spec_genrand_int32() {
131+
unsigned long y;
132+
static unsigned long mag01[2] = {0x0UL, MATRIX_A};
133+
/* mag01[x] = x * MATRIX_A for x=0,1 */
134+
135+
if (mti >= N) { /* generate N words at one time */
136+
int kk;
137+
138+
if (mti == N + 1) /* if init_genrand() has not been called, */
139+
spec_init_genrand(5489UL); /* a default initial seed is used */
140+
141+
for (kk = 0; kk < N - M; kk++) {
142+
y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
143+
mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1UL];
144+
}
145+
for (; kk < N - 1; kk++) {
146+
y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
147+
mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
148+
}
149+
y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
150+
mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL];
151+
152+
mti = 0;
153+
}
154+
155+
y = mt[mti++];
156+
157+
/* Tempering */
158+
y ^= (y >> 11);
159+
y ^= (y << 7) & 0x9d2c5680UL;
160+
y ^= (y << 15) & 0xefc60000UL;
161+
y ^= (y >> 18);
162+
163+
return y;
164+
}
165+
166+
/* generates a random number on [0,0x7fffffff]-interval */
167+
long spec_genrand_int31() {
168+
return (long)(spec_genrand_int32() >> 1);
169+
}
170+
171+
/* generates a random number on [0,1]-real-interval */
172+
double spec_genrand_real1() {
173+
return spec_genrand_int32() * (1.0 / 4294967295.0);
174+
/* divided by 2^32-1 */
175+
}
176+
177+
/* generates a random number on [0,1)-real-interval */
178+
double spec_genrand_real2() {
179+
return spec_genrand_int32() * (1.0 / 4294967296.0);
180+
/* divided by 2^32 */
181+
}
182+
183+
/* generates a random number on (0,1)-real-interval */
184+
double spec_genrand_real3() {
185+
return (((double)spec_genrand_int32()) + 0.5) * (1.0 / 4294967296.0);
186+
/* divided by 2^32 */
187+
}
188+
189+
/* generates a random number on [0,1) with 53-bit resolution*/
190+
double spec_genrand_res53() {
191+
unsigned long a = spec_genrand_int32() >> 5, b = spec_genrand_int32() >> 6;
192+
return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
193+
}
194+
/* These real versions are due to Isaku Wada, 2002/01/09 added */

libs/libvtrutil/src/specrand.h

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#ifndef VPR_SPEC_RAND_H
2+
#define VPR_SPEC_RAND_H
3+
/*
4+
* For inclusion in the SPEC cpu benchmarks
5+
* This file implements the random number generation necessary for the SPEC cpu benchmarks. The functions
6+
* defined here are used in vtr_random.h/cpp
7+
*
8+
*
9+
* A C-program for MT19937, with initialization improved 2002/1/26.
10+
* Coded by Takuji Nishimura and Makoto Matsumoto.
11+
*
12+
* Before using, initialize the state by using init_genrand(seed)
13+
* or init_by_array(init_key, key_length).
14+
*
15+
* Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
16+
* All rights reserved.
17+
* Copyright (C) 2005, Mutsuo Saito
18+
* All rights reserved.
19+
*
20+
* Redistribution and use in source and binary forms, with or without
21+
* modification, are permitted provided that the following conditions
22+
* are met:
23+
*
24+
* 1. Redistributions of source code must retain the above copyright
25+
* notice, this list of conditions and the following disclaimer.
26+
*
27+
* 2. Redistributions in binary form must reproduce the above copyright
28+
* notice, this list of conditions and the following disclaimer in the
29+
* documentation and/or other materials provided with the distribution.
30+
*
31+
* 3. The names of its contributors may not be used to endorse or promote
32+
* products derived from this software without specific prior written
33+
* permission.
34+
*
35+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
39+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
42+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46+
*
47+
*
48+
* Any feedback is very welcome.
49+
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
50+
* email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
51+
*/
52+
/* Slightly modified for use in SPEC CPU by Cloyce D. Spradling (5 Nov 2009)
53+
*/
54+
55+
void spec_srand(int seed);
56+
double spec_rand();
57+
long spec_lrand48();
58+
59+
/* initializes mt[N] with a seed */
60+
void spec_init_genrand(unsigned long s);
61+
62+
/* initialize by an array with array-length */
63+
/* init_key is the array for initializing keys */
64+
/* key_length is its length */
65+
/* slight change for C++, 2004/2/26 */
66+
void spec_init_by_array(unsigned long init_key[], int key_length);
67+
68+
/* generates a random number on [0,0xffffffff]-interval */
69+
unsigned long spec_genrand_int32();
70+
71+
/* generates a random number on [0,0x7fffffff]-interval */
72+
long spec_genrand_int31();
73+
74+
/* generates a random number on [0,1]-real-interval */
75+
double spec_genrand_real1();
76+
77+
/* generates a random number on [0,1)-real-interval */
78+
double spec_genrand_real2();
79+
80+
/* generates a random number on (0,1)-real-interval */
81+
double spec_genrand_real3();
82+
83+
/* generates a random number on [0,1) with 53-bit resolution*/
84+
double spec_genrand_res53();
85+
86+
#endif

libs/libvtrutil/src/vtr_random.cpp

+19-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "vtr_random.h"
44
#include "vtr_util.h"
55
#include "vtr_error.h"
6+
#include "specrand.h"
67

78
#define CHECK_RAND
89

@@ -21,6 +22,10 @@ static RandState random_state = 0;
2122
*/
2223
void srandom(int seed) {
2324
random_state = (unsigned int)seed;
25+
#ifdef SPEC_CPU
26+
/* SPEC CPU requires a different random number generator */
27+
spec_init_genrand((unsigned long)seed);
28+
#endif
2429
}
2530

2631
/* returns the random_state value */
@@ -29,6 +34,10 @@ RandState get_random_state() {
2934
}
3035

3136
int irand(int imax, RandState& state) {
37+
#ifdef SPEC_CPU
38+
/* SPEC CPU requires a different random number generator */
39+
return (int)(spec_genrand_int31() % (imax + 1));
40+
#else
3241
/* Creates a random integer between 0 and imax, inclusive. i.e. [0..imax] */
3342
int ival;
3443

@@ -37,7 +46,7 @@ int irand(int imax, RandState& state) {
3746
ival = state & (IM - 1); /* Modulus */
3847
ival = (int)((float)ival * (float)(imax + 0.999) / (float)IM);
3948

40-
#ifdef CHECK_RAND
49+
# ifdef CHECK_RAND
4150
if ((ival < 0) || (ival > imax)) {
4251
if (ival == imax + 1) {
4352
/* Due to random floating point rounding, sometimes above calculation gives number greater than ival by 1 */
@@ -46,9 +55,10 @@ int irand(int imax, RandState& state) {
4655
throw VtrError(string_fmt("Bad value in my_irand, imax = %d ival = %d", imax, ival), __FILE__, __LINE__);
4756
}
4857
}
49-
#endif
58+
# endif
5059

5160
return ival;
61+
#endif
5262
}
5363

5464
int irand(int imax) {
@@ -57,21 +67,25 @@ int irand(int imax) {
5767

5868
float frand() {
5969
/* Creates a random float between 0 and 1. i.e. [0..1). */
60-
70+
#ifdef SPEC_CPU
71+
/* SPEC CPU requires a different random number generator */
72+
return (float)spec_genrand_real2();
73+
#else
6174
float fval;
6275
int ival;
6376

6477
random_state = random_state * IA + IC; /* Use overflow to wrap */
6578
ival = random_state & (IM - 1); /* Modulus */
6679
fval = (float)ival / (float)IM;
6780

68-
#ifdef CHECK_RAND
81+
# ifdef CHECK_RAND
6982
if ((fval < 0) || (fval > 1.)) {
7083
throw VtrError(string_fmt("Bad value in my_frand, fval = %g", fval), __FILE__, __LINE__);
7184
}
72-
#endif
85+
# endif
7386

7487
return (fval);
88+
#endif
7589
}
7690

7791
} // namespace vtr

0 commit comments

Comments
 (0)