-3

I have some code written in c++ that simulates a prefetcher for a CPU. In the code I have some definitions that look like this

#define x 5
...
for(int i = 0; i < x; i++)
...

At the end of the simulation the simulator outputs the average access time which is a measure of how good the prefetcher did. The performance of the prefetcher depends on x and some other similar definitions.

I would like to have a program that changes x, recompiles the new code, runs it, looks at the value, and based on the change in simulated access time repeats the process.

Does anyone know of an easy way to do this that isn't manually changing values?

EDIT: I think I need to clarify that I do not want to have to program a learning algorithm since I have never done it and probably couldn't do it nearly as well as others.

Zach
  • 3
  • 2
  • just write a shell script to do that...put #define x in a separate include file. have your shell script regenerate the file – thang Feb 26 '15 at 04:42
  • @thang but then I would need to program some machine learning algorithm into a shell script and I don't want to seem too lazy but that seems like a lot of work – Zach Feb 26 '15 at 05:30
  • If changes to `x` involve machine learning, then `x` should not be a `#define`. It should be variable, and all of your existing code should be encapsulated so that it can be called multiple times with different values of `x`. – user3386109 Feb 26 '15 at 05:42
  • Honestly, and I don't mean this as an insult... if you're having a problem with this then I question how accurate your simulation could possibly be. – Ed S. Feb 26 '15 at 07:08

1 Answers1

0

I guess your current program looks something like this

 int main() {
 #define x 5
 <do the simulation>
 cout << "x=" << x << " time=" << aat << endl;

Instead you might create a simulate function that takes x as an explicit parameter and returns the average access time ...

double simulate( int x ) {
    <do simulation>
 }

And call it from main

 int main() {
   x= initial x value
   While ( necessary ) {
     Double aat = simulate(x)
     Cout << "x=" << x << " time=" << aat << endl;
     x = <updated x according to some strategy>

This way your machine learning to learn x happens in main.

But ... If you're writing a program to simulate CPU prefetching I can't help thinking that you know all this perfectly well already. I don't really understand why you were using the compiler to change a simulation parameter in the first place.

Wilf Rosenbaum
  • 518
  • 3
  • 10