Esempio n. 1
0
/*
 * Output a log message (called by debug(), info(), warn(), error(), console())
 *
 * Supports printf() like syntax:
 *
 * %% - outputs a '%' character
 * %s - prints the next parameter as string
 * %d - prints the next parameter as decimal
 * %f - prints the next parameter as double float
 * %x - prints the next parameter as hex value
 * %X - prints the next parameter as hex value with '0x' added before
 * %b - prints the next parameter as binary value
 * %B - prints the next parameter as binary value with '0b' added before
 * %l - prints the next parameter as long
 * %c - prints the next parameter as a character
 * %t - prints the next parameter as boolean ('T' or 'F')
 * %T - prints the next parameter as boolean ('true' or 'false')
 */
void Logger::log(DeviceId deviceId, LogLevel level, char *format, va_list args) {
	lastLogTime = millis();
	SerialUSB.print(lastLogTime);
	SerialUSB.print(" - ");

	switch (level) {
	case Debug:
		SerialUSB.print("DEBUG");
		break;
	case Info:
		SerialUSB.print("INFO");
		break;
	case Warn:
		SerialUSB.print("WARNING");
		break;
	case Error:
		SerialUSB.print("ERROR");
		break;
	}
	SerialUSB.print(": ");

	if (deviceId)
		printDeviceName(deviceId);

	logMessage(format, args);
}
Esempio n. 2
0
int
buildProgramFromAmdBin(unsigned int platform_id,unsigned int dev_id,char *binFile)
{
    int i = 0;
    cl_int err = CL_SUCCESS;

    cl_int nPlatforms = 0;
    cl_platform_id *platforms = NULL;
    cl_platform_id platform = (cl_platform_id)NULL;
    cl_context_properties cprops[3];
    cl_context context;
    size_t nDevices = 0;
    cl_device_id devices[MAXGPUS];
    cl_device_id device_id = 0;
    size_t binary_size = 0;
    char * binary = NULL;
    cl_program program = NULL;
    char pbuf[100];
    cl_command_queue cmdq;
    cl_mem iBuf,oBuf;
    cl_kernel kernel;
    cl_int *inBuf,*outBuf;
    inBuf=(cl_int*)malloc(MAX_THREADS*sizeof(cl_int));
    outBuf=(cl_int*)malloc(MAX_THREADS*sizeof(cl_int));
    size_t N=MAX_THREADS;
    cl_event evnt;
    char buildOptions[200];
    char opencl_log[1024*64];

    /* figure out the number of platforms on this system. */
    err = clGetPlatformIDs( 0, NULL, &nPlatforms );
    checkErr( "clGetPlatformIDs", err );
    printf( "Number of platforms found: %d\n", nPlatforms );
    if( nPlatforms == 0 )
    {
        fprintf( stderr, "Cannot continue without any platforms. Exiting.\n" );
        return( -1 );
    }
    platforms = (cl_platform_id *)malloc( sizeof(cl_platform_id) * nPlatforms );
    err = clGetPlatformIDs( nPlatforms, platforms, NULL );
    checkErr( "clGetPlatformIDs", err );

    /* Check for AMD platform. */

    err = clGetPlatformInfo( platforms[platform_id], CL_PLATFORM_VENDOR,
                             sizeof(pbuf), pbuf, NULL );
    checkErr( "clGetPlatformInfo", err );
    if( strcmp(pbuf, "Advanced Micro Devices, Inc.") == 0 )
    {
        printf( "Found AMD platform\n" );
        platform = platforms[platform_id];

    }

    if( platform == (cl_context_properties)0 )
    {
        fprintf( stderr, "Could not find an AMD platform. Exiting.\n" );
        exit(0);
    }

    clGetDeviceIDs(platform,
                   CL_DEVICE_TYPE_ALL,MAXGPUS, devices, &nDevices);

    cprops[0] = CL_CONTEXT_PLATFORM;
    cprops[1] = (cl_context_properties)platform;
    cprops[2] = (cl_context_properties)NULL;

    context =   clCreateContext(cprops, 1, &devices[dev_id], NULL, NULL,
                                &err);
    checkErr( "clCreateContext", err );

    printDeviceName(dev_id,devices[dev_id]);

    /* read in the binary kernel. */
    binary = readKernelBin( &binary_size, binFile );

    /* create an OpenCL program from the binary kernel. */
    program = clCreateProgramWithBinary( context, 1, &devices[dev_id], &binary_size,
                                         (const unsigned char**)&binary, NULL, &err );
    checkErr( "clCreateProgramWithBinary", err );

    sprintf(buildOptions,"%s %s",OCL_BINARY_OPTIONS ,OCL_OPTIMIZATIONS);

    /* build the kernel source for all available devices in the context. */
    err = clBuildProgram( program, 0, NULL,buildOptions , NULL, NULL );

    checkErr("clGetProgramBuildInfo",clGetProgramBuildInfo(program, devices[dev_id],
             CL_PROGRAM_BUILD_LOG, sizeof(opencl_log), (void *) opencl_log,
             NULL));

    /*Report build errors and warnings*/
    if (err != CL_SUCCESS)
    {   fprintf(stderr, "Compilation log: %s\n", opencl_log);
        exit(0);
    }
#ifdef REPORT_OPENCL_WARNINGS
    else if (strlen(opencl_log) > 1)
        fprintf(stderr, "Compilation log: %s\n", opencl_log);
#endif


    /* IT IS APPLICATION-DEPENDENT WHAT TO DO AFTER THIS POINT. */
    printf( "\n*** REPLACE THIS WITH ACTUAL WORK ***\n" );

    for(i=0; i<MAX_THREADS; i++)
        inBuf[i]=i;

    kernel=clCreateKernel(program,"test",&err) ;

    if(err) {
        printf("Create Kernel test FAILED\n");
        return 0;
    }

    cmdq=clCreateCommandQueue(context, devices[dev_id], CL_QUEUE_PROFILING_ENABLE,&err);
    checkErr("Create CMDQ FAILED\n",err);

    iBuf=clCreateBuffer(context,CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR,MAX_THREADS*sizeof(cl_int),inBuf,&err);
    if((iBuf==(cl_mem)0)) {
        checkErr("Create Buffer FAILED\n",err);
    }

    oBuf=clCreateBuffer(context,CL_MEM_WRITE_ONLY,MAX_THREADS*sizeof(cl_int),NULL,&err);
    if((oBuf==(cl_mem)0)) {
        checkErr("Create Buffer FAILED\n",err);
    }


    checkErr("Set Kernel Arg FAILED arg0\n",clSetKernelArg(kernel,0,sizeof(cl_mem),&iBuf));

    checkErr("Set Kernel Arg FAILED arg1\n",clSetKernelArg(kernel,1,sizeof(cl_mem),&oBuf));

    err=clEnqueueNDRangeKernel(cmdq,kernel,1,NULL,&N,NULL,0,NULL,&evnt);

    clWaitForEvents(1,&evnt);

    checkErr("Write FAILED\n",clEnqueueReadBuffer(cmdq,oBuf,CL_TRUE,0,MAX_THREADS*sizeof(cl_uint),outBuf, 0, NULL, NULL));

    for(i=0; i<MAX_THREADS; i++)
        printf("%d\n",outBuf[i]);

    return (0);
}
Esempio n. 3
0
int main (int argc, char *argv[])
{
  cl_int error;
  struct arguments arguments;

  /* Default values. */
  arguments.silent = 0;
  arguments.verbose = 0;
  arguments.nocharext = 0;
  arguments.mandeliterations = 25;
  arguments.info = 0;

  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  // CL initialisation
  error = initialisecl(arguments.verbose);
  if(error != CL_SUCCESS) {
    fprintf (stdout, "initialisecl() returned %s\n", errorMessageCL(error));
    return 1;
  }

  if (arguments.info) {
    // Print all the info about the CL device
    printPlatformInfo();
    printDevInfo();
    return CL_SUCCESS;
  }

  // Some general information
  fprintf (stdout, "========= CL DEVICE =========\n");
  printDeviceName();
  printDevExt();

  // SIN
  sinTest();

  // OCCOIDS
  occoidsTest();

  // MANDELBROT VIS TEST
  mandelbrotVisTest();

  // check for --nocharext
  if (!arguments.nocharext) {
    // Check device supports extensions we need for rot13 & mandelbrot
    if (getCorrectDevice("cl_khr_byte_addressable_store")) {
      fprintf (stdout, "No devices supporting cl_khr_byte_addressable_store found - bypassing rot13, mandelbrot and modulot tests.\n");
      return 2;
    }

    // ROT13
    rot13Test();

    // MANDELBROT
    mandelbrotTest(arguments.verbose, arguments.mandeliterations);

    if (getCorrectDevice("cl_khr_fp64")) {
      fprintf (stdout, "No devices supporting cl_khr_fp64 found - bypassing modulo tests.\n");
      return 3;
    }

    // MODULO PRECISION
    moduloTest();
  }

  // cleaup cl
  destroycl();

  return error;
}