Пример #1
0
  protected void setBinaries(Map<CLDevice, byte[]> binaries) {
    if (this.devices == null) {
      this.devices = new CLDevice[binaries.size()];
      int iDevice = 0;
      for (CLDevice device : binaries.keySet()) this.devices[iDevice++] = device;
    }
    int nDevices = this.devices.length;
    NativeSize[] lengths = new NativeSize[nDevices];
    cl_device_id[] deviceIds = new cl_device_id[nDevices];
    Memory binariesArray = new Memory(Pointer.SIZE * nDevices);
    Memory[] binariesMems = new Memory[nDevices];

    for (int iDevice = 0; iDevice < nDevices; iDevice++) {
      CLDevice device = devices[iDevice];
      byte[] binary = binaries.get(device);

      Memory binaryMem = binariesMems[iDevice] = new Memory(binary.length);
      binaryMem.write(0, binary, 0, binary.length);
      binariesArray.setPointer(iDevice * Pointer.SIZE, binaryMem);

      lengths[iDevice] = toNS(binary.length);
      deviceIds[iDevice] = device.getEntity();
    }
    PointerByReference binariesPtr = new PointerByReference();
    binariesPtr.setPointer(binariesArray);

    IntBuffer errBuff = NIOUtils.directInts(1, ByteOrder.nativeOrder());
    int previousAttempts = 0;
    IntBuffer statuses = NIOUtils.directInts(nDevices, ByteOrder.nativeOrder());
    do {
      entity =
          CL.clCreateProgramWithBinary(
              context.getEntity(), nDevices, deviceIds, lengths, binariesPtr, statuses, errBuff);
    } while (failedForLackOfMemory(errBuff.get(0), previousAttempts++));
  }
Пример #2
0
  private Memory toPointer(String input) {
    byte[] data = Native.toByteArray(input);
    Memory pointer = new Memory(data.length + 1);
    pointer.write(0, data, 0, data.length);
    pointer.setByte(data.length, (byte) 0);

    return pointer;
  }
Пример #3
0
 /**
  * String representation of the buffer.
  *
  * @return Unicode string.
  */
 public String getString() {
   byte[] data = Buffer.getByteArray(0, Length);
   if (data.length < 2 || data[data.length - 1] != 0) {
     Memory newdata = new Memory(data.length + 2);
     newdata.write(0, data, 0, data.length);
     return newdata.getString(0, true);
   }
   return Buffer.getString(0, true);
 }