@BeforeClass
  public static void checkOpenCL() throws Exception {

    // Verify that we can load the JavaCL library; ignore tests of OpenCL parsers on platforms that
    // do not
    // support OpenCL
    try {
      createBestContext();
    } catch (final Throwable t) {
      org.junit.Assume.assumeNoException(t);
    }
    f2_21_grammar = null;
    simpleGrammar1 = null;
    simpleGrammar2 = null;
  }
示例#2
0
  public OpenCLInnerLoop(int numThreads) {
    // choose device
    List<CLDevice> devices = new ArrayList<CLDevice>();
    System.out.println();
    for (CLPlatform platform : JavaCL.listPlatforms()) {
      for (CLDevice device : platform.listAllDevices(true)) {
        System.out.println("Type: " + device.getType());
        System.out.println("Vendor: " + device.getVendor());
        System.out.println("Name: " + device.getName());
        System.out.println("Compute units: " + device.getMaxComputeUnits());
        System.out.println("Global mem: " + device.getGlobalMemSize() / 1e6 + "MB");
        System.out.println("Driver version: " + device.getDriverVersion());
        System.out.println();
        devices.add(device);
      }
    }
    if (context == null) {
      for (CLDevice device : devices) {
        if (device.getVendor().toLowerCase().contains("intel")
            && device.getType().contains(CLDevice.Type.GPU)
            && device.getMaxComputeUnits() >= 140
            && device.getGlobalMemSize() > 512e6) {
          this.context = JavaCL.createContext(null, device);
        }
      }
    }
    //	    if (context == null) {
    //	    	for (CLDevice device : devices) {
    //	    		if (device.getVendor().toLowerCase().contains("nvidia") &&
    // device.getType().contains(CLDevice.Type.GPU) && device.getMaxComputeUnits() >= 8 &&
    // device.getGlobalMemSize() > 1e9 &&
    // !device.getPlatform().getName().toLowerCase().contains("apple")) {
    //	    			this.context = JavaCL.createContext(null, device);
    //	    		}
    //	    	}
    //	    }
    if (context == null) {
      this.context = JavaCL.createBestContext(DeviceFeature.CPU);
    }
    if (context.getDevices()[0].getType().contains(CLDevice.Type.GPU)
        && context.getDevices()[0].getVendor().toLowerCase().contains("nvidia")) {
      this.blockSizeX = NVIDIA_GPU_BLOCK_SIZE_X;
      this.rollX = NVIDIA_GPU_ROLL_X;
      this.blockSizeY = NVIDIA_GPU_BLOCK_SIZE_Y;
    } else if (context.getDevices()[0].getType().contains(CLDevice.Type.GPU)
        && context.getDevices()[0].getVendor().toLowerCase().contains("intel")) {
      this.blockSizeX = INTEL_GPU_BLOCK_SIZE_X;
      this.rollX = INTEL_GPU_ROLL_X;
      this.blockSizeY = INTEL_GPU_BLOCK_SIZE_Y;
    } else if (context.getDevices()[0].getType().contains(CLDevice.Type.CPU)) {
      this.blockSizeX = CPU_BLOCK_SIZE_X;
      this.rollX = CPU_ROLL_X;
      this.blockSizeY = CPU_BLOCK_SIZE_Y;
    }
    System.out.println("Using context:");
    System.out.println(context.toString());
    System.out.println("Block size x: " + blockSizeX);
    System.out.println("Roll x: " + rollX);
    System.out.println("Block size y: " + blockSizeY);

    this.context.setCacheBinaries(false);
    this.queue = context.createDefaultQueue();
    this.program = context.createProgram(kernelSrc());
    this.program.addBuildOption("-cl-fast-relaxed-math");
    this.program.addBuildOption("-cl-mad-enable");
    this.program.addBuildOption("-cl-unsafe-math-optimizations");
    this.program.addBuildOption("-cl-fast-relaxed-math");
    this.program.addBuildOption("-cl-single-precision-constant");
    this.program.build();

    this.pc = new PointerCapturer();
    this.numThreads = numThreads;
  }