liangfu commented on a change in pull request #9:
URL: https://github.com/apache/incubator-tvm-vta/pull/9#discussion_r483942451



##########
File path: src/oclfpga/oclfpga_device.cc
##########
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "oclfpga_device.h"
+#include <dmlc/logging.h>
+#include <vta/hw_spec.h>
+#include <cstring>
+#include <numeric>
+
+#define CL_STATUS_SUCCESS(x) ((x) == CL_SUCCESS)
+
+static const char *kernel_names[] = {"vta_core"};
+
+static cl_platform_id *find_platform(std::vector<cl_platform_id> *platforms,
+                                     const std::vector<std::string> 
&supported_platforms) {
+  cl_int status;
+  size_t size;
+  std::vector<char> name;
+  for (auto &id : *platforms) {
+    status = clGetPlatformInfo(id, CL_PLATFORM_NAME, 0, NULL, &size);
+    if (!CL_STATUS_SUCCESS(status)) continue;
+    name.resize(size);
+    status = clGetPlatformInfo(id, CL_PLATFORM_NAME, name.size(), name.data(), 
NULL);
+    if (!CL_STATUS_SUCCESS(status)) continue;
+    for (auto &p : supported_platforms) {
+      if (strstr(name.data(), p.c_str()) != NULL) {
+        return &id;
+      }
+    }
+  }
+  return NULL;
+}
+
+OCLFPGADevice::OCLFPGADevice() {
+  std::vector<std::string> supported_platforms = {"Intel(R) FPGA SDK for 
OpenCL(TM)", "Xilinx"};
+  init(supported_platforms);
+}
+
+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;
+}
+
+int OCLFPGADevice::setup(size_t mem_size, std::string aocx_file) {
+  cl_int status;
+  unsigned int argi;
+  size_t size;
+  FILE *binary_file;
+  unsigned char *binary;
+
+  LOG(INFO) << "Using AOCX: " << aocx_file;

Review comment:
       Just curious, as I've seem `Xilinx` in among part of the 
`supported_platforms`, does Xilinx toolchain support loading aocx binary files?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to