[Beignet] Building beignet with OpenCL 2.0 support in distros

Rebecca N. Palmer rebecca_palmer at zoho.com
Sat Jan 21 17:39:00 UTC 2017


> I have a first attempt at "enable/disable 2.0 at run time" written, but haven't yet tested it. 

It worked for me, and here it is; testing on other hardware (in
particular, hardware that supports 2.0: the last 15 tests of the test
suite appear to be the ones that test that) would be appreciated.

(Upstream may not want to take this as-is, as it doesn't scale very
well to more than one 2.0-supporting hardware generation: it's
intended as a quick relatively-low-risk fix for packagers.)

Signed-off-by: Rebecca N. Palmer <rebecca_palmer at zoho.com>

--- beignet-1.3.0.orig/CMakeLists.txt
+++ beignet-1.3.0/CMakeLists.txt
@@ -231,19 +231,8 @@ IF (EXPERIMENTAL_DOUBLE)
   ADD_DEFINITIONS(-DENABLE_FP64)
 ENDIF(EXPERIMENTAL_DOUBLE)
 
-OPTION(ENABLE_OPENCL_20 "Enable opencl 2.0 support" OFF)
+OPTION(ENABLE_OPENCL_20 "Enable opencl 2.0 support" ON)
 IF (ENABLE_OPENCL_20)
-  Find_Program(LSPCI lspci)
-  IF (NOT LSPCI)
-    MESSAGE(FATAL_ERROR "Looking for lspci - not found")
-  ENDIF (NOT LSPCI)
-  EXECUTE_PROCESS(COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/GetGenID.sh"
-                          RESULT_VARIABLE SUPPORT_OCL20_DEVICE
-                          OUTPUT_VARIABLE PCI_ID_NOT_USED)
-
-  IF (NOT SUPPORT_OCL20_DEVICE EQUAL 1)
-    MESSAGE(FATAL_ERROR "Only SKL and newer devices support OpenCL 2.0 now, your device don't support.")
-  ENDIF (NOT SUPPORT_OCL20_DEVICE EQUAL 1)
 
   IF (NOT HAVE_DRM_INTEL_BO_SET_SOFTPIN)
     MESSAGE(FATAL_ERROR "Please update libdrm to version 2.4.66 or later to enable OpenCL 2.0.")
--- beignet-1.3.0.orig/backend/src/backend/program.cpp
+++ beignet-1.3.0/backend/src/backend/program.cpp
@@ -31,6 +31,7 @@
 #include "ir/value.hpp"
 #include "ir/unit.hpp"
 #include "ir/printf.hpp"
+#include "../src/cl_device_data.h"
 
 #ifdef GBE_COMPILER_AVAILABLE
 #include "llvm/llvm_to_gen.hpp"
@@ -855,6 +856,7 @@ namespace gbe {
                                      size_t *errSize,
                                      uint32_t &oclVersion)
   {
+    uint32_t maxoclVersion = oclVersion;
     std::string pchFileName;
     bool findPCH = false;
 #if defined(__ANDROID__)
@@ -1023,14 +1025,18 @@ EXTEND_QUOTE:
 
     if (useDefaultCLCVersion) {
 #ifdef ENABLE_OPENCL_20
+      if(maxoclVersion >= 200){
+#else
+      if(0){
+#endif
       clOpt.push_back("-D__OPENCL_C_VERSION__=200");
       clOpt.push_back("-cl-std=CL2.0");
       oclVersion = 200;
-#else
+      }else{
       clOpt.push_back("-D__OPENCL_C_VERSION__=120");
       clOpt.push_back("-cl-std=CL1.2");
       oclVersion = 120;
-#endif
+      }
     }
     //for clCompilerProgram usage.
     if(temp_header_path){
@@ -1061,7 +1067,12 @@ EXTEND_QUOTE:
       clOpt.push_back("-include-pch");
       clOpt.push_back(pchFileName);
     }
-
+    if (oclVersion > maxoclVersion){
+      if (err && stringSize > 0 && errSize) {
+         *errSize = snprintf(err, stringSize, "Requested OpenCL version %lf is higher than maximum supported version %lf\n", (float)oclVersion/100.0,(float)maxoclVersion/100.0);
+      }
+      return false;
+    }
     return true;
   }
 
@@ -1076,7 +1087,7 @@ EXTEND_QUOTE:
     std::vector<std::string> clOpt;
     std::string dumpLLVMFileName, dumpASMFileName;
     std::string dumpSPIRBinaryName;
-    uint32_t oclVersion = 0;
+    uint32_t oclVersion = MAX_OCLVERSION(deviceID);
     if (!processSourceAndOption(source, options, NULL, clOpt,
                                 dumpLLVMFileName, dumpASMFileName, dumpSPIRBinaryName,
                                 optLevel,
@@ -1139,7 +1150,7 @@ EXTEND_QUOTE:
     std::vector<std::string> clOpt;
     std::string dumpLLVMFileName, dumpASMFileName;
     std::string dumpSPIRBinaryName;
-    uint32_t oclVersion = 0;
+    uint32_t oclVersion = MAX_OCLVERSION(deviceID);
     if (!processSourceAndOption(source, options, temp_header_path, clOpt,
                                 dumpLLVMFileName, dumpASMFileName, dumpSPIRBinaryName,
                                 optLevel, stringSize, err, errSize, oclVersion))
--- beignet-1.3.0.orig/src/cl_device_data.h
+++ beignet-1.3.0/src/cl_device_data.h
@@ -363,5 +363,7 @@
 
 #define IS_GEN9(devid)     (IS_SKYLAKE(devid) || IS_BROXTON(devid) || IS_KABYLAKE(devid))
 
+#define MAX_OCLVERSION(devid) (IS_GEN9(devid) ? 200 : 120)
+
 #endif /* __CL_DEVICE_DATA_H__ */
 
--- beignet-1.3.0.orig/src/cl_gen9_device.h
+++ beignet-1.3.0/src/cl_gen9_device.h
@@ -27,5 +27,7 @@
 .max_mem_alloc_size = 4 * 1024 * 1024 * 1024ul,
 .global_mem_size = 4 * 1024 * 1024 * 1024ul,
 
+#define GEN9_DEVICE 1
 #include "cl_gt_device.h"
+#undef GEN9_DEVICE
 
--- beignet-1.3.0.orig/src/cl_gt_device.h
+++ beignet-1.3.0/src/cl_gt_device.h
@@ -16,7 +16,13 @@
  *
  * Author: Benjamin Segovia <benjamin.segovia at intel.com>
  */
-
+#ifdef GEN9_DEVICE
+#define LIBCL_VERSION_STRING GEN9_LIBCL_VERSION_STRING
+#define LIBCL_C_VERSION_STRING GEN9_LIBCL_C_VERSION_STRING
+#else
+#define LIBCL_VERSION_STRING NONGEN9_LIBCL_VERSION_STRING
+#define LIBCL_C_VERSION_STRING NONGEN9_LIBCL_C_VERSION_STRING
+#endif
 /* Common fields for both all GT devices (IVB / SNB) */
 .device_type = CL_DEVICE_TYPE_GPU,
 .device_id=0,/* == device_id (set when requested) */
@@ -39,7 +45,7 @@
 .native_vector_width_float = 4,
 .native_vector_width_double = 2,
 .native_vector_width_half = 8,
-#ifdef ENABLE_OPENCL_20
+#if defined(ENABLE_OPENCL_20) && defined (GEN9_DEVICE)
 .address_bits = 64,
 #else
 .address_bits = 32,
--- beignet-1.3.0.orig/src/cl_platform_id.c
+++ beignet-1.3.0/src/cl_platform_id.c
@@ -32,7 +32,7 @@
 
 static struct _cl_platform_id intel_platform_data = {
   DECL_INFO_STRING(profile, "FULL_PROFILE")
-  DECL_INFO_STRING(version, LIBCL_VERSION_STRING)
+  DECL_INFO_STRING(version, GEN9_LIBCL_VERSION_STRING)
   DECL_INFO_STRING(name, "Intel Gen OCL Driver")
   DECL_INFO_STRING(vendor, "Intel")
   DECL_INFO_STRING(icd_suffix_khr, "Intel")
--- beignet-1.3.0.orig/src/cl_platform_id.h
+++ beignet-1.3.0/src/cl_platform_id.h
@@ -72,8 +72,10 @@ extern cl_int cl_get_platform_ids(cl_uin
 #else
 #define LIBCL_DRIVER_VERSION_STRING _JOINT(LIBCL_DRIVER_VERSION_MAJOR, LIBCL_DRIVER_VERSION_MINOR)
 #endif
-#define LIBCL_VERSION_STRING "OpenCL " _JOINT(LIBCL_C_VERSION_MAJOR, LIBCL_C_VERSION_MINOR) " beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
-#define LIBCL_C_VERSION_STRING "OpenCL C " _JOINT(LIBCL_C_VERSION_MAJOR, LIBCL_C_VERSION_MINOR) " beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+#define GEN9_LIBCL_VERSION_STRING "OpenCL " _JOINT(LIBCL_C_VERSION_MAJOR, LIBCL_C_VERSION_MINOR) " beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+#define GEN9_LIBCL_C_VERSION_STRING "OpenCL C " _JOINT(LIBCL_C_VERSION_MAJOR, LIBCL_C_VERSION_MINOR) " beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+#define NONGEN9_LIBCL_VERSION_STRING "OpenCL 1.2 beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+#define NONGEN9_LIBCL_C_VERSION_STRING "OpenCL C 1.2 beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
 
 #endif /* __CL_PLATFORM_ID_H__ */
 



More information about the Beignet mailing list