// Do the work of odd multiplies
int main1( )
{
  int i, j;

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

  do {
    // get a block to work on
    i = readAndIncrement( &shared_index, BLOCK_SIZE );
    for( j = i ; j < i + BLOCK_SIZE ; j++ ) {
        if( j < DATA_SIZE ) {
            results_data[j] = multiply( input_data1[j], input_data2[j] );
        } else {
            break;
        }
    }
  } while ( i + BLOCK_SIZE < DATA_SIZE );

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

  // signal that main1 finished
  main1_done = 1;

  // always return success, main0 will keep track of accuracy
  return 0;
}
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;
}
Exemplo n.º 3
0
int main( int argc, char* argv[] )
{
  int i;
  int resr, resg, resb;
  int results_data_r[DATA_SIZE][DATA_SIZE];
  int results_data_g[DATA_SIZE][DATA_SIZE];
  int results_data_b[DATA_SIZE][DATA_SIZE];
  int cycles, insts;
  cycles = getTime();
  insts = getInsts();
  for (i = 0; i < DATA_SIZE; i++)
  {
    sharpen( input_data_r, input_data_g, input_data_b,
                results_data_r, results_data_g, results_data_b);
  }
  cycles = getTime() - cycles;
  insts = getInsts() - insts;
  printStr("Cycles = "); printInt(cycles); printChar('\n');
  printStr("Insts  = "); printInt(insts); printChar('\n');
  
  // Check the results

  resr = verify(results_data_r, verify_data_r);
  resg = verify(results_data_g, verify_data_g);
  resb = verify(results_data_b, verify_data_b);

  return (resr != 1 || resg != 1 || resb != 1);
}
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;
}
Exemplo n.º 6
0
int main( int argc, char* argv[] )
{
  int results_data[DATA_SIZE];

  // Do the filter
  int cycles, insts;
  cycles = getTime();
  insts = getInsts();
  median( DATA_SIZE, input_data, results_data );
  cycles = getTime() - cycles;
  insts = getInsts() - insts;
  printStr("Cycles = "); printInt(cycles); printChar('\n');
  printStr("Insts  = "); printInt(insts); printChar('\n');

  // Check the results
  return !(verify( DATA_SIZE, results_data, verify_data ));

}
// Do the work of even multiplies
int main0( )
{
  int i, j;

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

  do {
    // get a block to work on
    i = readAndIncrement( &shared_index, BLOCK_SIZE );
    for( j = i ; j < i + BLOCK_SIZE ; j++ ) {
        if( j < DATA_SIZE ) {
            results_data[j] = multiply( input_data1[j], input_data2[j] );
        } else {
            break;
        }
    }
  } while ( i + BLOCK_SIZE < DATA_SIZE );

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

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


  // print the cycle 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
  return verify( DATA_SIZE, results_data, verify_data );
}
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;
}
// 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;
}