int main( int argc, char* argv[] )
{
	int results_data[DATA_SIZE];

	printStr("Benchmark median\n");

#if HOST_DEBUG
	// Output the input array
	printArray( "input",  DATA_SIZE, input_data  );
	printArray( "verify", DATA_SIZE, verify_data );
#endif

	uint32_t cycle = getCycle();
	uint32_t insts = getInsts();

	median( DATA_SIZE, input_data, results_data );

	cycle = getCycle() - cycle;
	insts = getInsts() - insts;
	printStr("Cycles = "); printInt(cycle); printChar('\n');
	printStr("Insts  = "); printInt(insts); printChar('\n');

#if HOST_DEBUG
	// Print out the results
	printArray( "results", DATA_SIZE, results_data );
#endif

	// Check the results
	int ret = verify( DATA_SIZE, results_data, verify_data );
	printStr("Return "); printInt((uint32_t)ret); printChar('\n');
	return ret;
}
int main0( )
{

  printStr("Benchmark mc_median\n");

  // start counting instructions and cycles
  int cycles, insts;
  cycles = getCycle();
  insts = getInsts();

  // do the median filter
  median_first_half( DATA_SIZE, input_data, results_data );

  // stop counting instructions and cycles
  cycles = getCycle() - cycles;
  insts = getInsts() - insts;

  // wait for main1 to finish
  while( main1_done == 0 );

  // print the cycles and inst count
  printStr("Cycles (core 0) = "); printInt(cycles); printChar('\n');
  printStr("Insts  (core 0) = "); printInt(insts); printChar('\n');
  printStr("Cycles (core 1) = "); printInt(main1_cycles); printChar('\n');
  printStr("Insts  (core 1) = "); printInt(main1_insts); printChar('\n');
  cycles = (cycles > main1_cycles) ? cycles : main1_cycles;
  insts = insts + main1_insts;
  printStr("Cycles  (total) = "); printInt(cycles); printChar('\n');
  printStr("Insts   (total) = "); printInt(insts); printChar('\n');

  // Check the results
  int ret = verify( DATA_SIZE, results_data, verify_data );
	printStr("Return "); printInt(ret); printChar('\n');
	return ret;
}
// Core 0
// consume & check data
int core0()
{
	printStr("Benchmark mc_produce_consume\n");

	// start counting instructions and cycles
	int cycles, insts;
	cycles = getCycle();
	insts = getInsts();

    // check data found in the common fifo
    uint32_t data = 0;
    int new_head_index = 0;
    for(int i = 0; i < DATA_SIZE; i++) {
		new_head_index = *head_index;
        while( new_head_index == *tail_index ); // wait for data to be produced
        data = fifo_data[new_head_index];
        new_head_index++;
        if( new_head_index == FIFO_SIZE ) {
            new_head_index = 0;
        }
        *head_index = new_head_index;
        if( data != input_data[i] ) {
			printStr("At index "); printInt(i);
			printStr(", receive data = ");
			printInt(data);
			printStr(", but expected data = ");
			printInt(input_data[i]);
			printStr(", mismatch!\n");
			printStr("Return "); printInt(i+1); printChar('\n');
			return (i+1);
        }
    }

	// stop counting instructions and cycles
	cycles = getCycle() - cycles;
	insts = getInsts() - insts;

	// wait for core 1 to complete
	while(main1_done == 0);

	// print the cycles and inst count
	printStr("Cycles (core 0) = "); printInt(cycles); printChar('\n');
	printStr("Insts  (core 0) = "); printInt(insts); printChar('\n');
	printStr("Cycles (core 1) = "); printInt(main1_cycles); printChar('\n');
	printStr("Insts  (core 1) = "); printInt(main1_insts); printChar('\n');
	cycles = (cycles > main1_cycles) ? cycles : main1_cycles;
	insts = insts + main1_insts;
	printStr("Cycles  (total) = "); printInt(cycles); printChar('\n');
	printStr("Insts   (total) = "); printInt(insts); printChar('\n');

	printStr("Return 0\n");
	return 0;
}
int main1( )
{
  // start counting instructions and cycles
  int cycles, insts;
  cycles = getCycle();
  insts = getInsts();

  // do the median filter
  median_second_half( DATA_SIZE, input_data, results_data );

  // stop counting instructions and cycles
  cycles = getCycle() - cycles;
  insts = getInsts() - insts;
  main1_cycles = cycles;
  main1_insts = insts;
  main1_done = 1;

  // Return success
  return 0;
}
void VsRegistry::loadTime(VsGroup* group) {
  VsLog::debugLog() <<"VsRegistry::loadTime() - Group is NULL?" << "'" << group << "'" <<std::endl;
  if (!group) {
    VsLog::debugLog() <<"VsRegistry::loadTime() - Group is NULL?" <<std::endl;
    return;
  }
  
  //try to load a value for "time"
  double foundTime = -1.0;
  VsAttribute* timeAtt = group->getAttribute(VsSchema::timeAtt);
  if (timeAtt) {
    std::vector<float> in;
    int err = timeAtt->getFloatVectorValue(&in);
    if (err < 0) {
      VsLog::debugLog() <<"VsRegistry::loadTime(): Error " <<err <<" while trying to load time attribute." <<std::endl;
    } else {
      foundTime = in[0];
      VsLog::debugLog() <<"VsRegistry::loadTime() - loaded time: " <<foundTime  <<std::endl;
    }
  }

  //try to load a value for "cycle"
  int foundCycle = -1;
  VsAttribute* cycleAtt = group->getAttribute(VsSchema::cycleAtt);
  if (cycleAtt) {
    std::vector<int> in;
    int err = cycleAtt->getIntVectorValue(&in);
    if (err < 0) {
      VsLog::debugLog() <<"VsRegistry::loadTime(): Error " <<err <<" while trying to load cycle attribute." <<std::endl;
    } else {
      foundCycle = in[0];
      VsLog::debugLog() <<"VsRegistry::loadTime() - loaded cycle: " <<foundCycle <<std::endl;
    }
  }
 
  //check for existing time data, and compare
  if ((foundTime != -1) && hasTime() && (foundTime != getTime())) {
    VsLog::warningLog() <<"VsRegistry::loadTime() - was asked to load time data again, but time data already exists." <<std::endl;
    VsLog::warningLog() <<"VsRegistry::loadTime() - and is in conflict: " <<foundTime <<" vs " <<getTime() <<std::endl;
  } else {
    timeValue = foundTime;
  }
  
  if ((foundCycle != -1) && hasCycle() && (foundCycle != getCycle())) {
    VsLog::warningLog() <<"VsRegistry::loadTime() - was asked to load cycle data again, but cycle data already exists." <<std::endl;
    VsLog::warningLog() <<"VsRegistry::loadTime() - and is in conflict: " <<foundCycle <<" vs " <<getCycle() <<std::endl;
  } else {
    cycle = foundCycle;
  }
}
// Core 1
// Generate the data
int core1()
{
	// start counting instructions and cycles
	int cycles, insts;
	cycles = getCycle();
	insts = getInsts();

    // copy input_data to a common fifo
    int data = 0;
    int new_tail_index = 0; // temp var to contain intermediate index val
    for(int i = 0; i < DATA_SIZE; i++) {
        data = input_data[i];
        
        // now write data to the fifo
		new_tail_index = *tail_index;
        fifo_data[new_tail_index] = data;

        new_tail_index++;
        if( new_tail_index == FIFO_SIZE ) {
            new_tail_index = 0;
        }
        while( *head_index == new_tail_index ); // wait for consumer to catch up
        *tail_index = new_tail_index;
    }

	// stop counting instructions and cycles
	cycles = getCycle() - cycles;
	insts = getInsts() - insts;
	main1_cycles = cycles;
	main1_insts = insts;

	// set done bit
	main1_done = 1;

    return 0;
}
Ejemplo n.º 7
0
int64_t Problem26::solve()
{
    int longest = 0;
    int value = 0;
    for(int i = 999; i > 1; --i)
    {
        if(i < longest)
            break;
        
        int cycle = getCycle(i);
        if(cycle > longest)
        {
            longest = cycle;
            value = i;
        }
    }
    
    return value;
}
Ejemplo n.º 8
0
void DaySimulator::setRandomTime(const uint &randomTime)
{
    EventSimulator::setRandomTime(randomTime);
    setTiming( ((getCycle()-randomTime) / 2.0) / getCycle());
}