Exemple #1
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);
  }
Exemple #2
0
  /**
   * The entry point of this program
   *
   * @param args Not used
   */
  public static void runJOCLDeviceQuery() {
    // Obtain the number of platforms
    int numPlatforms[] = new int[1];
    clGetPlatformIDs(0, null, numPlatforms);

    System.out.println("Number of platforms: " + numPlatforms[0]);

    // Obtain the platform IDs
    cl_platform_id platforms[] = new cl_platform_id[numPlatforms[0]];
    clGetPlatformIDs(platforms.length, platforms, null);

    // Collect all devices of all platforms
    List<cl_device_id> devices = new ArrayList<cl_device_id>();
    for (int i = 0; i < platforms.length; i++) {
      String platformName = getString(platforms[i], CL_PLATFORM_NAME);

      // Obtain the number of devices for the current platform
      int numDevices[] = new int[1];
      clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, null, numDevices);

      System.out.println("Number of devices in platform " + platformName + ": " + numDevices[0]);

      cl_device_id devicesArray[] = new cl_device_id[numDevices[0]];
      clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, numDevices[0], devicesArray, null);

      devices.addAll(Arrays.asList(devicesArray));
    }

    // Print the infos about all devices
    for (cl_device_id device : devices) {
      // CL_DEVICE_NAME
      String deviceName = getString(device, CL_DEVICE_NAME);
      System.out.println("--- Info for device " + deviceName + ": ---");
      System.out.printf("CL_DEVICE_NAME: \t\t\t%s\n", deviceName);

      // CL_DEVICE_VENDOR
      String deviceVendor = getString(device, CL_DEVICE_VENDOR);
      System.out.printf("CL_DEVICE_VENDOR: \t\t\t%s\n", deviceVendor);

      // CL_DRIVER_VERSION
      String driverVersion = getString(device, CL_DRIVER_VERSION);
      System.out.printf("CL_DRIVER_VERSION: \t\t\t%s\n", driverVersion);

      // CL_DEVICE_TYPE
      long deviceType = getLong(device, CL_DEVICE_TYPE);
      if ((deviceType & CL_DEVICE_TYPE_CPU) != 0)
        System.out.printf("CL_DEVICE_TYPE:\t\t\t\t%s\n", "CL_DEVICE_TYPE_CPU");
      if ((deviceType & CL_DEVICE_TYPE_GPU) != 0)
        System.out.printf("CL_DEVICE_TYPE:\t\t\t\t%s\n", "CL_DEVICE_TYPE_GPU");
      if ((deviceType & CL_DEVICE_TYPE_ACCELERATOR) != 0)
        System.out.printf("CL_DEVICE_TYPE:\t\t\t\t%s\n", "CL_DEVICE_TYPE_ACCELERATOR");
      if ((deviceType & CL_DEVICE_TYPE_DEFAULT) != 0)
        System.out.printf("CL_DEVICE_TYPE:\t\t\t\t%s\n", "CL_DEVICE_TYPE_DEFAULT");

      // CL_DEVICE_MAX_COMPUTE_UNITS
      int maxComputeUnits = getInt(device, CL_DEVICE_MAX_COMPUTE_UNITS);
      System.out.printf("CL_DEVICE_MAX_COMPUTE_UNITS:\t\t%d\n", maxComputeUnits);

      // CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
      long maxWorkItemDimensions = getLong(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS);
      System.out.printf("CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:\t%d\n", maxWorkItemDimensions);

      // CL_DEVICE_MAX_WORK_ITEM_SIZES
      int maxWorkItemSizes[] = getInts(device, CL_DEVICE_MAX_WORK_ITEM_SIZES, 3);
      System.out.printf(
          "CL_DEVICE_MAX_WORK_ITEM_SIZES:\t\t%d / %d / %d \n",
          maxWorkItemSizes[0], maxWorkItemSizes[1], maxWorkItemSizes[2]);

      // CL_DEVICE_MAX_WORK_GROUP_SIZE
      long maxWorkGroupSize = getLong(device, CL_DEVICE_MAX_WORK_GROUP_SIZE);
      System.out.printf("CL_DEVICE_MAX_WORK_GROUP_SIZE:\t\t%d\n", maxWorkGroupSize);

      // CL_DEVICE_MAX_CLOCK_FREQUENCY
      long maxClockFrequency = getLong(device, CL_DEVICE_MAX_CLOCK_FREQUENCY);
      System.out.printf("CL_DEVICE_MAX_CLOCK_FREQUENCY:\t\t%d MHz\n", maxClockFrequency);

      // CL_DEVICE_ADDRESS_BITS
      int addressBits = getInt(device, CL_DEVICE_ADDRESS_BITS);
      System.out.printf("CL_DEVICE_ADDRESS_BITS:\t\t\t%d\n", addressBits);

      // CL_DEVICE_MAX_MEM_ALLOC_SIZE
      long maxMemAllocSize = getLong(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE);
      System.out.printf(
          "CL_DEVICE_MAX_MEM_ALLOC_SIZE:\t\t%d MByte\n", (int) (maxMemAllocSize / (1024 * 1024)));

      // CL_DEVICE_GLOBAL_MEM_SIZE
      long globalMemSize = getLong(device, CL_DEVICE_GLOBAL_MEM_SIZE);
      System.out.printf(
          "CL_DEVICE_GLOBAL_MEM_SIZE:\t\t%d MByte\n", (int) (globalMemSize / (1024 * 1024)));

      // CL_DEVICE_ERROR_CORRECTION_SUPPORT
      int errorCorrectionSupport = getInt(device, CL_DEVICE_ERROR_CORRECTION_SUPPORT);
      System.out.printf(
          "CL_DEVICE_ERROR_CORRECTION_SUPPORT:\t%s\n", errorCorrectionSupport != 0 ? "yes" : "no");

      // CL_DEVICE_LOCAL_MEM_TYPE
      int localMemType = getInt(device, CL_DEVICE_LOCAL_MEM_TYPE);
      System.out.printf(
          "CL_DEVICE_LOCAL_MEM_TYPE:\t\t%s\n", localMemType == 1 ? "local" : "global");

      // CL_DEVICE_LOCAL_MEM_SIZE
      long localMemSize = getLong(device, CL_DEVICE_LOCAL_MEM_SIZE);
      System.out.printf("CL_DEVICE_LOCAL_MEM_SIZE:\t\t%d KByte\n", (int) (localMemSize / 1024));

      // CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
      long maxConstantBufferSize = getLong(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE);
      System.out.printf(
          "CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:\t%d KByte\n", (int) (maxConstantBufferSize / 1024));

      // CL_DEVICE_QUEUE_PROPERTIES
      long queueProperties = getLong(device, CL_DEVICE_QUEUE_PROPERTIES);
      if ((queueProperties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE) != 0)
        System.out.printf(
            "CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE");
      if ((queueProperties & CL_QUEUE_PROFILING_ENABLE) != 0)
        System.out.printf("CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_PROFILING_ENABLE");

      // CL_DEVICE_IMAGE_SUPPORT
      int imageSupport = getInt(device, CL_DEVICE_IMAGE_SUPPORT);
      System.out.printf("CL_DEVICE_IMAGE_SUPPORT:\t\t%d\n", imageSupport);

      // CL_DEVICE_MAX_READ_IMAGE_ARGS
      int maxReadImageArgs = getInt(device, CL_DEVICE_MAX_READ_IMAGE_ARGS);
      System.out.printf("CL_DEVICE_MAX_READ_IMAGE_ARGS:\t\t%d\n", maxReadImageArgs);

      // CL_DEVICE_MAX_WRITE_IMAGE_ARGS
      int maxWriteImageArgs = getInt(device, CL_DEVICE_MAX_WRITE_IMAGE_ARGS);
      System.out.printf("CL_DEVICE_MAX_WRITE_IMAGE_ARGS:\t\t%d\n", maxWriteImageArgs);

      // CL_DEVICE_SINGLE_FP_CONFIG
      long singleFpConfig = getLong(device, CL_DEVICE_SINGLE_FP_CONFIG);
      System.out.printf(
          "CL_DEVICE_SINGLE_FP_CONFIG:\t\t%s\n", stringFor_cl_device_fp_config(singleFpConfig));

      // CL_DEVICE_IMAGE2D_MAX_WIDTH
      int image2dMaxWidth = getInt(device, CL_DEVICE_IMAGE2D_MAX_WIDTH);
      System.out.printf("CL_DEVICE_2D_MAX_WIDTH\t\t\t%d\n", image2dMaxWidth);

      // CL_DEVICE_IMAGE2D_MAX_HEIGHT
      int image2dMaxHeight = getInt(device, CL_DEVICE_IMAGE2D_MAX_HEIGHT);
      System.out.printf("CL_DEVICE_2D_MAX_HEIGHT\t\t\t%d\n", image2dMaxHeight);

      // CL_DEVICE_IMAGE3D_MAX_WIDTH
      int image3dMaxWidth = getInt(device, CL_DEVICE_IMAGE3D_MAX_WIDTH);
      System.out.printf("CL_DEVICE_3D_MAX_WIDTH\t\t\t%d\n", image3dMaxWidth);

      // CL_DEVICE_IMAGE3D_MAX_HEIGHT
      int image3dMaxHeight = getInt(device, CL_DEVICE_IMAGE3D_MAX_HEIGHT);
      System.out.printf("CL_DEVICE_3D_MAX_HEIGHT\t\t\t%d\n", image3dMaxHeight);

      // CL_DEVICE_IMAGE3D_MAX_DEPTH
      int image3dMaxDepth = getInt(device, CL_DEVICE_IMAGE3D_MAX_DEPTH);
      System.out.printf("CL_DEVICE_3D_MAX_DEPTH\t\t\t%d\n", image3dMaxDepth);

      // CL_DEVICE_PREFERRED_VECTOR_WIDTH_<type>
      System.out.printf("CL_DEVICE_PREFERRED_VECTOR_WIDTH_<t>\t");
      int preferredVectorWidthChar = getInt(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR);
      int preferredVectorWidthShort = getInt(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT);
      int preferredVectorWidthInt = getInt(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT);
      int preferredVectorWidthLong = getInt(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG);
      int preferredVectorWidthFloat = getInt(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT);
      int preferredVectorWidthDouble = getInt(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE);
      System.out.printf(
          "CHAR %d, SHORT %d, INT %d, LONG %d, FLOAT %d, DOUBLE %d\n\n\n",
          preferredVectorWidthChar,
          preferredVectorWidthShort,
          preferredVectorWidthInt,
          preferredVectorWidthLong,
          preferredVectorWidthFloat,
          preferredVectorWidthDouble);
    }
  }