Ejemplo n.º 1
0
/* Calculate the rate of reading from disk cache
 *
 * This is achieved by first opening a file,
 * doing one read from it to move it into disk cache
 * then timing how long it takes to read many bytes from it.
 */
long int getDiskCacheReadRate(char* buf) {
  long int i,j;
  struct timespec startTime, endTime;
  
  //First, open the file and do the first read
  //so we know it is in the cache and not on disk
  int fd = open(TESTFILE_DAT_LOC, O_RDONLY);

  //do a read, so we know the file is in disk cache
  read(fd, buf, BUF_SIZE);
  //now, seek back to the beginning of the file
  lseek(fd, 0, SEEK_SET);

  //Start the clock
  clock_gettime(CLOCK_REALTIME, &startTime);
  //do our read
  ssize_t numRead = read(fd, buf, BUF_SIZE);
  //Stop the clock
  clock_gettime(CLOCK_REALTIME, &endTime);
  
  //close the file
  close(fd);

  //calculate the speed of access
  //divide the time taken (in nanoseconds) by the number of bytes
  //that were read, to get the time taken to read one byte
  //units are nanoseconds / byte
  return numRead * 1000.0 / subtractTimes(&startTime, &endTime);
}
Ejemplo n.º 2
0
	float Timer::delta()
	{
		uint64_t counter = mach_absolute_time();
		float dt = subtractTimes( counter, _deltaTime );
		_deltaTime = counter;
		return dt;
	}
Ejemplo n.º 3
0
int main() {

	Time t1(6, 30);
	Time t2(8, 51);

	bool isGreaterThan = greaterThan(t1, t2);
	if (isGreaterThan) cout << "t1 > t2: TRUE" << endl;
	else cout << "t1 > t2: FALSE" << endl;

	bool isLessThan = lessThan(t1, t2);
	if (isLessThan) cout << "t1 < t2: TRUE" << endl;
	else cout << "t1 < t2: FALSE" << endl;

	bool isEqual = equals(t1, t2);
	if (isEqual) cout << "t1 = t2: TRUE" << endl;
	else cout << "t1 = t2: FALSE" << endl;

	Time t3 = addTimes(t1, t2);
	cout << "t3 - minutes: " << t3.getMinutes() << " seconds: " << t3.getSeconds() << endl;

	Time t4 = subtractTimes(t1, t2);
	cout << "t4 - minutes: " << t4.getMinutes() << " seconds: " << t4.getSeconds() << endl;

	return 0;
}
Ejemplo n.º 4
0
    double Timer::elapsed() {
#if WIN32
        LARGE_INTEGER timenow;
        QueryPerformanceCounter(&timenow) ;
        LARGE_INTEGER time;
        time.QuadPart = timenow.QuadPart - mTimer.start.QuadPart;
        mLastElapsed = LIToSecs( time) ;
#else
        double now = clock();
        mLastElapsed = subtractTimes(now, mStart);
#endif
        return mLastElapsed;
    }
Ejemplo n.º 5
0
    void Timer::stopTimer() {
        mIsRunning = false;
#if WIN32
        QueryPerformanceCounter(&mTimer.stop) ;
        LARGE_INTEGER time;
        time.QuadPart = mTimer.stop.QuadPart - mTimer.start.QuadPart;
        mLastElapsed = LIToSecs( time) ;
#else 
        mStop = clock();
        mLastElapsed = subtractTimes(mStop, mStart);
#endif
        mTotal += mLastElapsed;
    }
Ejemplo n.º 6
0
/*
 * Computes the amount of time that running a for loop
 * of our consumeCycles function takes per iteration
 * This will allow us to remove this time per cycle later
 * so we are measure just the read time, as opposed to the
 * read time along with the overhead of the loop.
 */
long int getBaseLoopTime() {
  long int i,j;
  struct timespec startTime, endTime;
  clock_gettime(CLOCK_REALTIME, &startTime);

  for(i = 0; i < NUM_ITERATIONS; ++i) {
    //waste CPU cycles, so we can measure the time the loop plus wasting takes
    j = consumeCycles(i,j);
  }

  clock_gettime(CLOCK_REALTIME, &endTime);

  return subtractTimes(&startTime, &endTime) / NUM_ITERATIONS;
}
Ejemplo n.º 7
0
/* This returns the rate at which we can read directly from disk
 * This is achieved by first creating many files, and writing a lot to them.
 * This pushes any information that was in the cache out.
 * When we then proceed to read from those files, they will have
 * to be accessed from disk.
 * This means we'll be able to time how long it takes to read a byte from disk
 * A few other tricks:
 * - Keep all of the files open before reading. Opening the files does not
     move them into cache, and then we don't need to time it takes to open
     each file.
*/
double getDiskReadRate(char* buf, long int overheadPerLoop) {
  //just to be nice, make sure buf ends in a '\0'
  buf[BUF_SIZE-1] = '\0';

  //make a directory for our files
  mkdir(READFILES_LOC, 0774);

  //make a lot of new files in that directory
  long int i,j;
  int fd;
  char fileLoc[1024];
  for(i = 0; i < NUM_ITERATIONS; ++i) {
    sprintf(fileLoc, "%s%ld.dat", READFILES_LOC, i);
    fd = open(fileLoc, O_WRONLY | O_CREAT);
    write(fd, buf, BUF_SIZE/10);
    close(fd);
  }

  struct timespec startTime, endTime;
  
  //re-open all of the files
  int fds[NUM_ITERATIONS];
  for(i = 0; i < NUM_ITERATIONS; ++i) {
    sprintf(fileLoc, "%s%ld.dat", READFILES_LOC, i);
    fds[i] = open(fileLoc, O_RDONLY);
  }
  //do our reads
  char* a;
  clock_gettime(CLOCK_REALTIME, &startTime);
  for(i = 0; i < NUM_ITERATIONS; ++i) {
    j = consumeCycles(i,j);
    read(fds[i], a, 1);
  }
  clock_gettime(CLOCK_REALTIME, &endTime);

  //close and delete all of the files
  for(i = 0; i < NUM_ITERATIONS; ++i) {
    close(fds[i]);
    sprintf(fileLoc, "%s%ld.dat", READFILES_LOC, i);
    unlink(fileLoc);
  }

  //remove the directory
  rmdir(READFILES_LOC);

  //return the result
  //make sure we remove the time it takes to conume the extra cycles
  //so we ONLY measure the reads, and not the overhead of the for loop.
  return 1000.0 * NUM_ITERATIONS / (subtractTimes(&startTime, &endTime) - (overheadPerLoop * NUM_ITERATIONS));
}
Ejemplo n.º 8
0
/* Calculate how the rate at which we can write to the disk cache
 * This is achieve by first opening a file
 * then writing to it, as every write will be directly to cache.
 * The changes are written out of cache at a later time
 * after the write command returns
 */
double getDiskCacheWriteRate(char* buf) {
  long int i, j;
  struct timespec startTime, endTime;

  //first, open the file and do a write
  //to get it into the disk cache
  int fd = open("./writeout.dat", O_WRONLY | O_CREAT);
  
  //start the clock
  clock_gettime(CLOCK_REALTIME, &startTime);
  //write a whole bunch of stuff from memory
  ssize_t numWritten = write(fd, buf, BUF_SIZE);
  //stop the clock
  clock_gettime(CLOCK_REALTIME, &endTime);

  close(fd);
  
  //delet the file we made
  unlink("./writeout.dat");

  //return (subtractTimes(&startTime, &endTime) - (overheadPerLoop * NUM_ITERATIONS)) / NUM_ITERATIONS;
  return 1000.0 * numWritten / subtractTimes(&startTime, &endTime);
}
Ejemplo n.º 9
0
	float Timer::time()
	{
		uint64_t counter = mach_absolute_time();
		float time = subtractTimes( counter, _startTime );
		return time;
	}
Ejemplo n.º 10
0
int runTest(clFFT_Dim3 n, int batchSize, clFFT_Direction dir, clFFT_Dimension dim, 
			clFFT_DataFormat dataFormat, int numIter, clFFT_TestType testType)
{	
	cl_int err = CL_SUCCESS;
	int iter;
	double t;
	
	uint64_t t0, t1;
	int mx = log2(n.x);
	int my = log2(n.y);
	int mz = log2(n.z);

	int length = n.x * n.y * n.z * batchSize;
		
	double gflops = 5e-9 * ((double)mx + (double)my + (double)mz) * (double)n.x * (double)n.y * (double)n.z * (double)batchSize * (double)numIter;
	
	clFFT_SplitComplex data_i_split = (clFFT_SplitComplex) { NULL, NULL };
	clFFT_SplitComplex data_cl_split = (clFFT_SplitComplex) { NULL, NULL };
	clFFT_Complex *data_i = NULL;
	clFFT_Complex *data_cl = NULL;
	clFFT_SplitComplexDouble data_iref = (clFFT_SplitComplexDouble) { NULL, NULL }; 
	clFFT_SplitComplexDouble data_oref = (clFFT_SplitComplexDouble) { NULL, NULL };
	
	clFFT_Plan plan = NULL;
	cl_mem data_in = NULL;
	cl_mem data_out = NULL;
	cl_mem data_in_real = NULL;
	cl_mem data_in_imag = NULL;
	cl_mem data_out_real = NULL;
	cl_mem data_out_imag = NULL;
	
	if(dataFormat == clFFT_SplitComplexFormat) {
		data_i_split.real     = (float *) malloc(sizeof(float) * length);
		data_i_split.imag     = (float *) malloc(sizeof(float) * length);
		data_cl_split.real    = (float *) malloc(sizeof(float) * length);
		data_cl_split.imag    = (float *) malloc(sizeof(float) * length);
		if(!data_i_split.real || !data_i_split.imag || !data_cl_split.real || !data_cl_split.imag)
		{
			err = -1;
			log_error("Out-of-Resources\n");
			goto cleanup;
		}
	}
	else {
		data_i  = (clFFT_Complex *) malloc(sizeof(clFFT_Complex)*length);
		data_cl = (clFFT_Complex *) malloc(sizeof(clFFT_Complex)*length);
		if(!data_i || !data_cl)
		{
			err = -2;
			log_error("Out-of-Resouces\n");
			goto cleanup;
		}
	}
	
	data_iref.real   = (double *) malloc(sizeof(double) * length);
	data_iref.imag   = (double *) malloc(sizeof(double) * length);
	data_oref.real   = (double *) malloc(sizeof(double) * length);
	data_oref.imag   = (double *) malloc(sizeof(double) * length);	
	if(!data_iref.real || !data_iref.imag || !data_oref.real || !data_oref.imag)
	{
		err = -3;
		log_error("Out-of-Resources\n");
		goto cleanup;
	}

	int i;
	if(dataFormat == clFFT_SplitComplexFormat) {
		for(i = 0; i < length; i++)
		{
			data_i_split.real[i] = 2.0f * (float) rand() / (float) RAND_MAX - 1.0f;
			data_i_split.imag[i] = 2.0f * (float) rand() / (float) RAND_MAX - 1.0f;
			data_cl_split.real[i] = 0.0f;
			data_cl_split.imag[i] = 0.0f;			
			data_iref.real[i] = data_i_split.real[i];
			data_iref.imag[i] = data_i_split.imag[i];
			data_oref.real[i] = data_iref.real[i];
			data_oref.imag[i] = data_iref.imag[i];	
		}
	}
	else {
		for(i = 0; i < length; i++)
		{
			data_i[i].real = 2.0f * (float) rand() / (float) RAND_MAX - 1.0f;
			data_i[i].imag = 2.0f * (float) rand() / (float) RAND_MAX - 1.0f;
			data_cl[i].real = 0.0f;
			data_cl[i].imag = 0.0f;			
			data_iref.real[i] = data_i[i].real;
			data_iref.imag[i] = data_i[i].imag;
			data_oref.real[i] = data_iref.real[i];
			data_oref.imag[i] = data_iref.imag[i];	
		}		
	}
	
	plan = clFFT_CreatePlan( context, n, dim, dataFormat, &err );
	if(!plan || err) 
	{
		log_error("clFFT_CreatePlan failed\n");
		goto cleanup;
	}
	
	//clFFT_DumpPlan(plan, stdout);
	
	if(dataFormat == clFFT_SplitComplexFormat)
	{
		data_in_real = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, length*sizeof(float), data_i_split.real, &err);
	    if(!data_in_real || err) 
	    {
			log_error("clCreateBuffer failed\n");
			goto cleanup;
	    }
		
		data_in_imag = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, length*sizeof(float), data_i_split.imag, &err);
	    if(!data_in_imag || err) 
	    {
			log_error("clCreateBuffer failed\n");
			goto cleanup;
	    }
		
		if(testType == clFFT_OUT_OF_PLACE)
		{
			data_out_real = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, length*sizeof(float), data_cl_split.real, &err);
			if(!data_out_real || err) 
			{
				log_error("clCreateBuffer failed\n");
				goto cleanup;
			}
			
			data_out_imag = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, length*sizeof(float), data_cl_split.imag, &err);
			if(!data_out_imag || err) 
			{
				log_error("clCreateBuffer failed\n");
				goto cleanup;
			}			
		}
		else
		{
			data_out_real = data_in_real;
			data_out_imag = data_in_imag;
		}
	}
	else
	{
	    data_in = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, length*sizeof(float)*2, data_i, &err);
	    if(!data_in) 
	    {
			log_error("clCreateBuffer failed\n");
			goto cleanup;
	    }
		if(testType == clFFT_OUT_OF_PLACE)
		{
			data_out = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, length*sizeof(float)*2, data_cl, &err);
			if(!data_out) 
			{
				log_error("clCreateBuffer failed\n");
				goto cleanup;
			}			
		}
		else
			data_out = data_in;
	}
		
			
	err = CL_SUCCESS;
	
	t0 = mach_absolute_time();
	if(dataFormat == clFFT_SplitComplexFormat)
	{
		for(iter = 0; iter < numIter; iter++)
		    err |= clFFT_ExecutePlannar(queue, plan, batchSize, dir, data_in_real, data_in_imag, data_out_real, data_out_imag, 0, NULL, NULL);
	}
	else
	{
	    for(iter = 0; iter < numIter; iter++) 
			err |= clFFT_ExecuteInterleaved(queue, plan, batchSize, dir, data_in, data_out, 0, NULL, NULL);
	}
	
	err |= clFinish(queue);
	
	if(err) 
	{
		log_error("clFFT_Execute\n");
		goto cleanup;	
	}
	
	t1 = mach_absolute_time(); 
	t = subtractTimes(t1, t0);
	char temp[100];
	sprintf(temp, "GFlops achieved for n = (%d, %d, %d), batchsize = %d", n.x, n.y, n.z, batchSize);
	log_perf(gflops / (float) t, 1, "GFlops/s", "%s", temp);

	if(dataFormat == clFFT_SplitComplexFormat)
	{	
		err |= clEnqueueReadBuffer(queue, data_out_real, CL_TRUE, 0, length*sizeof(float), data_cl_split.real, 0, NULL, NULL);
		err |= clEnqueueReadBuffer(queue, data_out_imag, CL_TRUE, 0, length*sizeof(float), data_cl_split.imag, 0, NULL, NULL);
	}
	else
	{
		err |= clEnqueueReadBuffer(queue, data_out, CL_TRUE, 0, length*sizeof(float)*2, data_cl, 0, NULL, NULL);
	}
	
	if(err) 
	{
		log_error("clEnqueueReadBuffer failed\n");
        goto cleanup;
	}	

	computeReferenceD(&data_oref, n, batchSize, dim, dir);
	
	double diff_avg, diff_max, diff_min;
	if(dataFormat == clFFT_SplitComplexFormat) {
		diff_avg = computeL2Error(&data_cl_split, &data_oref, n.x*n.y*n.z, batchSize, &diff_max, &diff_min);
		if(diff_avg > eps_avg)
			log_error("Test failed (n=(%d, %d, %d), batchsize=%d): %s Test: rel. L2-error = %f eps (max=%f eps, min=%f eps)\n", n.x, n.y, n.z, batchSize, (testType == clFFT_OUT_OF_PLACE) ? "out-of-place" : "in-place", diff_avg, diff_max, diff_min);
		else
			log_info("Test passed (n=(%d, %d, %d), batchsize=%d): %s Test: rel. L2-error = %f eps (max=%f eps, min=%f eps)\n", n.x, n.y, n.z, batchSize, (testType == clFFT_OUT_OF_PLACE) ? "out-of-place" : "in-place", diff_avg, diff_max, diff_min);			
	}
	else {
		clFFT_SplitComplex result_split;
		result_split.real = (float *) malloc(length*sizeof(float));
		result_split.imag = (float *) malloc(length*sizeof(float));
		convertInterleavedToSplit(&result_split, data_cl, length);
		diff_avg = computeL2Error(&result_split, &data_oref, n.x*n.y*n.z, batchSize, &diff_max, &diff_min);
		
		if(diff_avg > eps_avg)
			log_error("Test failed (n=(%d, %d, %d), batchsize=%d): %s Test: rel. L2-error = %f eps (max=%f eps, min=%f eps)\n", n.x, n.y, n.z, batchSize, (testType == clFFT_OUT_OF_PLACE) ? "out-of-place" : "in-place", diff_avg, diff_max, diff_min);
		else
			log_info("Test passed (n=(%d, %d, %d), batchsize=%d): %s Test: rel. L2-error = %f eps (max=%f eps, min=%f eps)\n", n.x, n.y, n.z, batchSize, (testType == clFFT_OUT_OF_PLACE) ? "out-of-place" : "in-place", diff_avg, diff_max, diff_min);	
		free(result_split.real);
		free(result_split.imag);
	}
	
cleanup:
	clFFT_DestroyPlan(plan);	
	if(dataFormat == clFFT_SplitComplexFormat) 
	{
		if(data_i_split.real)
			free(data_i_split.real);
		if(data_i_split.imag)
			free(data_i_split.imag);
		if(data_cl_split.real)
			free(data_cl_split.real);
		if(data_cl_split.imag)
			free(data_cl_split.imag);
		
		if(data_in_real)
			clReleaseMemObject(data_in_real);
		if(data_in_imag)
			clReleaseMemObject(data_in_imag);
		if(data_out_real && testType == clFFT_OUT_OF_PLACE)
			clReleaseMemObject(data_out_real);
		if(data_out_imag && clFFT_OUT_OF_PLACE)
			clReleaseMemObject(data_out_imag);
	}
	else 
	{
		if(data_i)
			free(data_i);
		if(data_cl)
			free(data_cl);
		
		if(data_in)
			clReleaseMemObject(data_in);
		if(data_out && testType == clFFT_OUT_OF_PLACE)
			clReleaseMemObject(data_out);
	}
	
	if(data_iref.real)
		free(data_iref.real);
	if(data_iref.imag)
		free(data_iref.imag);		
	if(data_oref.real)
		free(data_oref.real);
	if(data_oref.imag)
		free(data_oref.imag);
	
	return err;
}