Пример #1
0
//FIXME: Some more dignified way to choose the rendering method would be
// a very nice thing.
ColorTimeCache World::trace(double x, double y) const {
	vec origin, direction;
	if (samples == 1) {
		cam->map(x, y, origin, direction);
		//return runBiDi(origin, direction);
		return runCache(origin, direction);
		//return runPhotonCache(origin, direction);
		//return runTimePhotonCache(origin, direction);
		//return runDirectPhoton(origin, direction);
		//return runSurfacePhoton(origin, direction);
		
	}
	ColorTimeCache answer;
	double weight = 1.0/samples;
	double ox, oy;
	
	for (int j=0; j<samples; j++) {
		ox = x + Random::randomCenteredUnit()/500;
		oy = y + Random::randomCenteredUnit()/500;
		cam->map(ox, oy, origin, direction);
		//answer += runBiDi(origin, direction) * weight;
		answer.addWeighted(0.0, 1.0, runCache(origin, direction));
		//answer += runPhotonCache(origin, direction) * weight;
		//answer.addWeighted(0.0, weight, runTimePhotonCache(origin, direction));
		//answer += runDirectPhoton(origin, direction) * weight;
		//answer += runSurfacePhoton(origin, direction) * weight;
	}
	return answer;
	
}
Пример #2
0
int main(int argc, char * argv[])
{
  int s = -1; // Sets,
  int E = -1; // Lines,
  int b = -1; // Blocks initialized
  char* t = NULL;
  int hits = 0;
  int misses = 0;
  int evictions = 0;
  if (!parseArgs(argc, argv, &s, &E, &b, &t)) // If inputs aren't matching, print message
  {
      printf("%s\n\n", "Usage: ./csim-ref [-hv] -s <s> -E <E> -b <b> -t <tracefile>");
      return 1;
  }
  // Initializes structs
  Cache cache; 
  // Initializes cache
  cache.setSize = pow(2, s);
  cache.setIndexBits = s;
  cache.linesPerSet = E;
  cache.blockSize = pow(2, b);
  cache.blockOffsetBits = b;
  // Malloc function allocates storage
  cache.tags = malloc(cache.setSize * sizeof(tag*));
  for (int i = 0; i < cache.setSize; i++)
  {
      cache.tags[i] = malloc(cache.linesPerSet * sizeof(tag));
      memset(cache.tags[i], -1, cache.linesPerSet * sizeof(tag));
  }
  FILE * fp = fopen(t, "r");
  // As long as the file has found something, run the cache
  runCache(&cache, fp, &hits, &misses, &evictions);
  
  printSummary(hits, misses, evictions);
  return 0;
}
Пример #3
0
/*
	Main function. Feed to options to set the cache

	Options:
	-h : print out help message
	-s : set L1 cache Size (B)
	-w : set L1 cache ways
	-l : set L1 cache line size
*/
int main(int argc, char* argv[])
{
	int i;
	uint32_t size = 32; //total size of L1$ (KB)
	uint32_t ways = 1; //# of ways in L1. Default to direct-mapped
	uint32_t line = 32; //line size (B)

  // hit and miss counts
  int totalHits = 0;
  int totalMisses = 0;

	int repPol = 0;

  char * filename;

	//strings to compare
	const char helpString[] = "-h";
	const char sizeString[] = "-s";
	const char waysString[] = "-w";
	const char lineString[] = "-l";
	const char traceString[] = "-t";
  const char lruString[] = "-lru";

  if (argc == 1) {
    // No arguments passed, show help
    printHelp(argv[0]);
    return 1;
  }

	//parse command line
	for(i = 1; i < argc; i++)
	{
		//check for help
		if(!strcmp(helpString, argv[i]))
		{
			//print out help text and terminate
      printHelp(argv[0]);
			return 1; //return 1 for help termination
		}
		//check for size
		else if(!strcmp(sizeString, argv[i]))
		{
			//take next string and convert to int
			i++; //increment i so that it skips data string in the next loop iteration
			//check next string's first char. If not digit, fail
			if(isdigit(argv[i][0]))
			{
				size = atoi(argv[i]);
			}
			else
			{
				printf("Incorrect formatting of size value\n");
				return -1; //input failure
			}
		}
		//check for ways
		else if(!strcmp(waysString, argv[i]))
		{
			//take next string and convert to int
			i++; //increment i so that it skips data string in the next loop iteration
			//check next string's first char. If not digit, fail
			if(isdigit(argv[i][0]))
			{
				ways = atoi(argv[i]);
			}
			else
			{
				printf("Incorrect formatting of ways value\n");
				return -1; //input failure
			}
		}
		//check for line size
		else if(!strcmp(lineString, argv[i]))
		{
			//take next string and convert to int
			i++; //increment i so that it skips data string in the next loop iteration
			//check next string's first char. If not digit, fail
			if(isdigit(argv[i][0]))
			{
				line = atoi(argv[i]);
			}
			else
			{
				printf("Incorrect formatting of line size value\n");
				return -1; //input failure
			}
		}
    else if (!strcmp(traceString, argv[i])) {
      filename = argv[++i];
    }
    else if (!strcmp(lruString, argv[i])) {
      // Extra Credit: Implement Me!
			repPol = 1;// = atoi(argv[i]);
    }
		//unrecognized input
		else{
			printf("Unrecognized argument. Exiting.\n");
			return -1;
		}
	}






	//run standard

	struct progOutput *fullOutput = runCache(size, line, (1024*size)/(line), filename, repPol );

	struct progOutput *standardOutput = runCache(size, line, ways, filename, repPol);



	int offsetBits = logBase2(line);
	int sets = (1024*size)/(line*ways);
	int indexBits = logBase2(sets);
	int tagBits = 32 - (indexBits + offsetBits);



	printf("Ways: %u; Sets: %u; Line Size: %uB\n", ways, sets, line); //
	printf("Tag: %d bits; Index: %d bits; Offset: %d bits\n", tagBits, indexBits, offsetBits);//
	/* Print results */
	printf("Miss Rate: %8lf%%\n", standardOutput->missRatio * 100.0);
	printf("Read Transactions: %d\n", standardOutput->totalReads);
	printf("Write Transactions: %d\n", standardOutput->totalWrites);



	char path[100] = "";

	strcat(path, filename);
	strcat(path, ".simulated");

	FILE *fp;


	fp = fopen(path, "w");




	int k = 0;
	for(k = 0; k < fullOutput->size; k++){
		fprintf(fp, "%s %s ", standardOutput->accessTypes[k], standardOutput->accessAdresses[k]);
		int fullResult = fullOutput->lines[k];
		int standResult = standardOutput->lines[k];
		if(standResult == 0){
			fprintf(fp, "hit\n");
		}else if(standResult == 2){
			fprintf(fp, "compulsory\n");
		}else if(fullResult == 1){
			fprintf(fp, "capacity\n");
		}else{
			fprintf(fp, "conflict\n");
		}


		//hit = 0 capacity = 1 compulsory = 2

	}
	fclose(fp);



	for(k = 0; k < 100; k++){//MAX_HISTORY_LENGTH
		free(fullOutput->accessAdresses[k]);
		free(fullOutput->accessTypes[k]);
	}
	free(fullOutput->accessAdresses);
	free(fullOutput->accessTypes);
	free(fullOutput->lines);
	free(fullOutput);

	for(k = 0; k < 100; k++){
		free(standardOutput->accessAdresses[k]);
		free(standardOutput->accessTypes[k]);
	}
	free(standardOutput->accessAdresses);
	free(standardOutput->accessTypes);
	free(standardOutput->lines);
	free(standardOutput);


	if(DEBUG){
		//char c = getchar();
	}







	if(DEBUG){
		printf("Dumping Tag History: \n");
		//int k;
		//for(k =0; i < cache->tagHistoryIndex; i++){
			//printf("%d\n", cache->tagHistory[i]);
		//}
	}

  /* TODO: Now we output the file */


}