void OCLFPGADevice::init()

in src/oclfpga/oclfpga_device.cc [55:100]


void OCLFPGADevice::init(const std::vector<std::string> &supported_platforms) {
  cl_int status;
  cl_device_id *device;
  cl_platform_id *platform;
  cl_uint n;
  size_t size;
  std::vector<char> name;
  std::vector<cl_platform_id> platforms;
  std::vector<cl_device_id> devices;

  status = clGetPlatformIDs(0, NULL, &n);
  CHECK(CL_STATUS_SUCCESS(status)) << "Failed to query number of OpenCL platforms";
  platforms.resize(n);
  CHECK(platforms.size() > 0) << "No OpenCL platform available";
  status = clGetPlatformIDs(platforms.size(), platforms.data(), NULL);
  CHECK(CL_STATUS_SUCCESS(status)) << "Failed to query OpenCL platform IDs";

  platform = find_platform(&platforms, supported_platforms);
  CHECK(platform) << "Unable to find supported OpenCL platform";

  status = clGetDeviceIDs(*platform, CL_DEVICE_TYPE_ALL, 0, NULL, &n);
  CHECK(CL_STATUS_SUCCESS(status)) << "Failed to query number of OpenCL devices";
  devices.resize(n);
  CHECK(devices.size() > 0) << "No OpenCL device found";
  status = clGetDeviceIDs(*platform, CL_DEVICE_TYPE_ALL, devices.size(), devices.data(), NULL);
  CHECK(CL_STATUS_SUCCESS(status)) << "Failed to query OpenCL devices IDs";

  device = NULL;
  for (auto &id : devices) {
    _context = clCreateContext(NULL, 1, &id, NULL, NULL, &status);
    if (CL_STATUS_SUCCESS(status)) {
      status = clGetDeviceInfo(id, CL_DEVICE_NAME, 0, NULL, &size);
      CHECK(CL_STATUS_SUCCESS(status)) << "Failed to query OpenCL device info";
      name.resize(size);
      status = clGetDeviceInfo(id, CL_DEVICE_NAME, name.size(), name.data(), NULL);
      CHECK(CL_STATUS_SUCCESS(status)) << "Failed to query OpenCL device name";
      LOG(INFO) << "Using FPGA device: " << name.data();
      device = &id;
      break;
    } else {
      LOG(INFO) << "This FPGA Device is not available. Skipped.";
    }
  }
  CHECK(device) << "No FPGA device available";
  _device = *device;
}