Example #1
0
  /**
   * prints some timing values of the kernel
   *
   * @param kernelEvent
   */
  public void profile(cl_event kernelEvent) {
    long submitTime[] = new long[1];
    long queuedTime[] = new long[1];
    long startTime[] = new long[1];
    long endTime[] = new long[1];
    CL.clGetEventProfilingInfo(
        kernelEvent, CL.CL_PROFILING_COMMAND_QUEUED, Sizeof.cl_ulong, Pointer.to(queuedTime), null);
    CL.clGetEventProfilingInfo(
        kernelEvent, CL.CL_PROFILING_COMMAND_SUBMIT, Sizeof.cl_ulong, Pointer.to(submitTime), null);
    CL.clGetEventProfilingInfo(
        kernelEvent, CL.CL_PROFILING_COMMAND_START, Sizeof.cl_ulong, Pointer.to(startTime), null);
    CL.clGetEventProfilingInfo(
        kernelEvent, CL.CL_PROFILING_COMMAND_END, Sizeof.cl_ulong, Pointer.to(endTime), null);

    submitTime[0] -= queuedTime[0];
    startTime[0] -= queuedTime[0];
    endTime[0] -= queuedTime[0];

    //		System.out.println("Queued : " + String.format("%8.3f", 0.0) + " ms");
    //		System.out.println("Submit : "
    //				+ String.format("%8.3f", submitTime[0] / 1e6) + " ms");
    //		System.out.println("Start  : "
    //				+ String.format("%8.3f", startTime[0] / 1e6) + " ms");
    //		System.out.println("End    : "
    //				+ String.format("%8.3f", endTime[0] / 1e6) + " ms");

    //		long duration = endTime[0] - startTime[0];
    //		System.out.println("Time : " + String.format("%8.3f", duration / 1e6)
    //				+ " ms");
    System.out.printf(" | took : %8.3f milliseconds\n", endTime[0] / 1e6);
  }
Example #2
0
  public void reinit() throws OpenClException {
    // Obtain the platform IDs and initialize the context properties
    cl_platform_id platforms[] = new cl_platform_id[1];
    clGetPlatformIDs(platforms.length, platforms, null);
    cl_context_properties contextProperties = new cl_context_properties();
    contextProperties.addProperty(CL_CONTEXT_PLATFORM, platforms[0]);

    // Create an OpenCL context on a GPU device
    context =
        CL.clCreateContextFromType(contextProperties, CL.CL_DEVICE_TYPE_GPU, null, null, null);
    if (context == null) {
      // If no context for a GPU device could be created,
      // try to create one for a CPU device.
      context =
          CL.clCreateContextFromType(contextProperties, CL.CL_DEVICE_TYPE_CPU, null, null, null);

      if (context == null) {
        throw new OpenClException("Unable to create a context");
      }
    }

    // Enable exceptions and subsequently omit error checks in this sample
    CL.setExceptionsEnabled(true);

    // Get the list of GPU devices associated with the context
    long numBytes[] = new long[1];
    CL.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, 0, null, numBytes);

    // Obtain the cl_device_id for the first device
    int numDevices = (int) numBytes[0] / Sizeof.cl_device_id;
    cl_device_id[] devices = new cl_device_id[numDevices];
    CL.clGetContextInfo(context, CL.CL_CONTEXT_DEVICES, numBytes[0], Pointer.to(devices), null);
    device = devices[0];

    // Create a command-queue
    commandQueue = clCreateCommandQueue(context, devices[0], CL.CL_QUEUE_PROFILING_ENABLE, null);
  }