コード例 #1
0
/*
 * \brief Host Initialization 
 *        Allocate and initialize memory 
 *        on the host. Print input array. 
 */
int
initializeHost(void)
{
    width				= 256;
    input				= NULL;
    output				= NULL;
    multiplier			= 2;

    /////////////////////////////////////////////////////////////////
    // Allocate and initialize memory used by host 
    /////////////////////////////////////////////////////////////////
    cl_uint sizeInBytes = width * sizeof(cl_uint);
    input = (cl_uint *) malloc(sizeInBytes);
    if(input == NULL)
    {
        printf("Error: Failed to allocate input memory on host\n");
        return 1; 
    }

    output = (cl_uint *) malloc(sizeInBytes);
    if(output == NULL)
    {
        printf("Error: Failed to allocate output memory on host\n");
        return 1; 
    }

    for(cl_uint i = 0; i < width; i++)
        input[i] = i;

    // print input array
    print1DArray(std::string("Input").c_str(), input, width);

    return 0;
}
コード例 #2
0
ファイル: template.cpp プロジェクト: dawnworld/test
/*
 * \brief Host Initialization 
 *        Allocate and initialize memory 
 *        on the host. Print input array. 
 */
int
initializeHost(void)//初始化需要处理的数据和将要存储的空间,即生成两个数组:input,output
{
	width               = 256;
	input               = NULL;
	output              = NULL;
	multiplier          = 2;

	/////////////////////////////////////////////////////////////////
	// Allocate and initialize memory used by host 
	/////////////////////////////////////////////////////////////////
	cl_uint sizeInBytes = width * sizeof(cl_uint);
	input = (cl_uint *) malloc(sizeInBytes);
	if(!input)
	{
		std::cout << "Error: Failed to allocate input memory on host\n";
		return SDK_FAILURE;
	}

	output = (cl_uint *) malloc(sizeInBytes);
	if(!output)
	{
		std::cout << "Error: Failed to allocate input memory on host\n";
		return SDK_FAILURE;
	}

	for(cl_uint i = 0; i < width; i++)
		input[i] = i;

	// print input array
	print1DArray(std::string("Input").c_str(), input, width);
	return SDK_SUCCESS;
}
コード例 #3
0
ファイル: testKernels.c プロジェクト: Pitxyoki/Cheetah
bool verifyFFTResults(JobToPUM *job) {
  cl_float *verificationOutput_i = calloc(1024, sizeof(cl_float));
  cl_float *verificationOutput_r = calloc(1024, sizeof(cl_float));

  if (!verificationOutput_i || !verificationOutput_r) {
    fprintf(stderr,"Failed to allocate host memory" "(verificationOutput)\n");
    return false;
  }

  /* Compute reference FFT on input */
  fftCPUReference(verificationOutput_r, verificationOutput_i, inBuff1, inBuff2, 1024);

  if (debug_PUM) {
    printf("Verification output imaginary buffer: \n");
    print1DArray(verificationOutput_i, NUM_PRINT1DARRAY_ELEMS);
  }

  /* Compare results */
  if (compare(verificationOutput_i, (float *) (job->arguments[1]), 1024)) {
    if (debug_PUM)
      fprintf(stderr,"Passed!\n");
    return true;
  } else {
    if (debug_PUM)
      fprintf(stderr,"Failed\n");
    return false;
  }
}
コード例 #4
0
ファイル: cheetah-common.c プロジェクト: Pitxyoki/Cheetah
void printJobResults (JobResults *printThis) {
  printf("Problem ID: %i\n", printThis->probID);
  printf("JobID: %i\n", printThis->jobID);

  printf("\nNumber of Results: %i\n", printThis->nTotalResults);

  for (cl_uint i = 0; i < printThis->nTotalResults; i++) {
    printf("results[%i] = ", i);
    print1DArray(printThis->results[i], NUM_PRINT1DARRAY_ELEMS);
  }
  printf("Return status: %s\n", printThis->returnStatus == JOB_RETURN_STATUS_SUCCESS ? "Success" : "Failure");
  printf("End of job results.\n");

}
コード例 #5
0
ファイル: pumUtils.c プロジェクト: Pitxyoki/Cheetah
/*
 * A consumer thread.
 * This will wait until the queue has a job and run it
 */
void *JobConsumer (void *device) {
  JobToPUM *job;
  int devID = *((int *) device);

  jobNResult jnr;

  struct timeval start, end, result,
                 overheadstart, overheadend, overheadresult; //for capturing job execution times
  finishedJobNotification fjn;

  //  cl_device_type dev = *((cl_device_type *)device);

  //TODO: Does doing this only once have any consequences? (Can we reuse a command queue *safely*? What if the device is left on an "inconsistent state"?)
  //prepare OpenCL
/*  if (!initializeCLExec(dev)) {
    fprintf(stderr,"PUM (%i):  FAILED INITIALIZING %s DEVICE\n", myid, dev == CL_DEVICE_TYPE_CPU ? "CPU" : "GPU");
    return NULL;
  }*/

  printf("PUM (%i): Job consumer started\n", myid);

  while (true) {
    //wait until the queue has a job
    job = dequeue(devID);

    jnr.job = job;
    fjn.category = job->category;
    fjn.ranAtPU = job->runOn;
    fjn.executionTime = 0.0;
    fjn.succeeded = false;
    if (gettimeofday(&overheadstart, NULL)) {
      perror("gettimeofday");
      exit (EXIT_FAILURE);
    }

    if (!initializeCLBuffers(job)) {
      fprintf(stderr,"PUM (%i):  FAILED INITIALIZING BUFFERS\n", myid);

      fjn.executionTime = DBL_MAX ;
      sendFinishedJobNotification(&fjn);


      jnr.res = JOB_RETURN_STATUS_FAILURE;
      resultPrepareAndSend(&jnr);
      continue;
    }

    if (debug_PUM) {
      printf("PUM (%i):  Arguments BEFORE execution:\n", myid);
      for (cl_uint i = 0; i < job->nTotalArgs; i++) {
        printf("arg %i: ", i);
        if (job->argTypes[i] == EMPTY_BUFFER)
          printf("EMPTY BUFFER.\n");
        else
          print1DArray(job->arguments[i], job->argSizes[i] / sizeof(unsigned int));
      }
    }
    if (gettimeofday(&overheadend, NULL)) {
      perror("gettimeofday");
      return false;
    }

    start = overheadend;
    if (!execJob(job)) {
      fprintf(stderr,"PUM (%i):  FAILED RUNNING JOB\n", myid);

      fjn.executionTime = DBL_MAX ;
      sendFinishedJobNotification(&fjn);

      jnr.res = JOB_RETURN_STATUS_FAILURE;
      fprintf(stderr,"JOB FAIL NOTIFICATION SENT TO JS. Sending to RC as well.\n");
      resultPrepareAndSend(&jnr);
      continue;
    }
    if (gettimeofday(&end, NULL)) {
      perror("gettimeofday");
      return false;
    }

    if (debug_PUM) {
      printf("PUM (%i):  Arguments AFTER execution:\n", myid);
      for (cl_uint i = 0; i < job->nTotalArgs; i++) {
        printf("arg %i: ", i);
        if (job->argTypes[i] == EMPTY_BUFFER)
          printf("EMPTY BUFFER.\n");
        else
          print1DArray(job->arguments[i], job->argSizes[i] / sizeof(unsigned int));
      }
    }

    if (!SILENT)
      printf("PUM (%i):  Finished running job (%s).\n", myid, job->startingKernel);
//    if (debug_PUM)
//      printJobToPUM(job);


    jnr.res = JOB_RETURN_STATUS_SUCCESS;

//    sendResults(&jnr);//TODO: include this on a file-transfer metric for the scheduler?

    timeval_subtract(&result, &end, &start);
    fjn.executionTime = result.tv_sec + (result.tv_usec / 1000000.0);
    timeval_subtract(&overheadresult, &overheadend, &overheadstart);
    fjn.overheads = overheadresult.tv_sec + (overheadresult.tv_usec / 1000000.0);
    fjn.succeeded = jnr.res;
    sendFinishedJobNotification(&fjn);


    resultPrepareAndSend(&jnr);
  }
}
コード例 #6
0
ファイル: testKernels.c プロジェクト: Pitxyoki/Cheetah
bool createTestFFT (JobToPUM *job) {
  job->probID = myid;

//  job->runOn = CL_DEVICE_TYPE_CPU; //TO BE FILLED BY THE JS

  job->nDimensions = 1;
  job->nItems[0] = 64;
  job->nGroupItems[0] = 64;

  job->startingKernel = malloc(sizeof("kfft"));
  strcpy(job->startingKernel,"kfft");
  job->startingNameSize = strlen(job->startingKernel)+1;

  job->taskSource = fileToString(DATADIR"/pumanager/FFT_Kernels.cl");
  if (job->taskSource == NULL) {
    fprintf(stderr,"FILE NOT FOUND! (building testFFT)\n");
    return false;
  }
  job->taskSourceSize = strlen(job->taskSource)+1;

  ///Setting up arguments
  job->nTotalArgs = 2;
  job->argTypes = calloc(job->nTotalArgs, sizeof(argument_type));
  job->argTypes[0] = INPUT_OUTPUT;
  job->argTypes[1] = INPUT_OUTPUT;

  job->argSizes = calloc(job->nTotalArgs, sizeof(int));
  job->argSizes[0] = job->argSizes[1] = 1024*sizeof(cl_uint);


  inBuff1 = calloc(1024, sizeof(cl_float));
  inBuff2 = calloc(1024, sizeof(cl_float));


  if (!fillRandom(inBuff1, 1024, 0, 255)) {
    fprintf(stderr, "Error filling input buffer 1 for FFT kernel\n");
    return false;
  }
  if (!fillRandom(inBuff2, 1024, 0, 0)) {
    fprintf(stderr, "Error filling input buffer 2 for FFT kernel\n");
    return false;
  }

  job->arguments = calloc(job->nTotalArgs, sizeof(void *));
  job->arguments[0] = calloc(1024, sizeof(cl_float));
  job->arguments[1] = calloc(1024, sizeof(cl_float));
  memcpy(job->arguments[0], inBuff1, 1024*sizeof(cl_float));
  memcpy(job->arguments[1], inBuff2, 1024*sizeof(cl_float));


  if(debug_PUM) {
    printf("Original Input Real: ");
    print1DArray(inBuff1, NUM_PRINT1DARRAY_ELEMS);
    printf("Original Input Imaginary: ");
    print1DArray(inBuff2, NUM_PRINT1DARRAY_ELEMS);
  }

//  job->returnTo = defaultRCID; //not used


  return true;
}