[Beignet] [PATCH 19/19] CMake: add an option to enable OpenCL 2.0.

Yang Rong rong.r.yang at intel.com
Mon Nov 28 11:32:45 UTC 2016


The OpenCL 2.0 is disable default, to enable it, using option
-DENABLE_OPENCL_20 to enable it.
Now skylake and newer devices support OpenCL 2.0, if enable OpenCL 2.0,
LLVM 3.9 and libdrm 2.4.66 is required.

Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
 CMakeLists.txt | 56 +++++++++++++++++++++++++++++++++++++++++---------------
 GetGenID.sh    | 50 +++++++++++++++++++++++++++++++++-----------------
 2 files changed, 74 insertions(+), 32 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 713cfa9..22090ba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,15 +16,6 @@ endif ()
 
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
 PROJECT(OCL)
-set (LIBCL_DRIVER_VERSION_MAJOR 1)
-set (LIBCL_DRIVER_VERSION_MINOR 3)
-if (ENABLE_OPENCL_20)
-  set (LIBCL_C_VERSION_MAJOR 2)
-  set (LIBCL_C_VERSION_MINOR 0)
-else (ENABLE_OPENCL_20)
-  set (LIBCL_C_VERSION_MAJOR 1)
-  set (LIBCL_C_VERSION_MINOR 2)
-endif (ENABLE_OPENCL_20)
 if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
   set(COMPILER "CLANG")
 elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
@@ -32,11 +23,6 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
 elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
   set(COMPILER "ICC")
 endif()
-configure_file (
-  "src/OCLConfig.h.in"
-  "src/OCLConfig.h"
-)
-
 set (NOT_BUILD_STAND_ALONE_UTEST 1)
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
@@ -236,10 +222,50 @@ ENDIF(OCLIcd_FOUND)
 Find_Package(PythonInterp)
 
 OPTION(EXPERIMENTAL_DOUBLE "Enable experimental double support" OFF)
-IF(EXPERIMENTAL_DOUBLE)
+IF (EXPERIMENTAL_DOUBLE)
   ADD_DEFINITIONS(-DENABLE_FP64)
 ENDIF(EXPERIMENTAL_DOUBLE)
 
+OPTION(ENABLE_OPENCL_20 "Enable opencl 2.0 support" OFF)
+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.")
+  ENDIF (NOT HAVE_DRM_INTEL_BO_SET_SOFTPIN)
+
+  IF (LLVM_VERSION_NODOT VERSION_LESS 39)
+    MESSAGE(FATAL_ERROR "Please update LLVM to version 3.9 or later to enable OpenCL 2.0.")
+  ENDIF (LLVM_VERSION_NODOT VERSION_LESS 39)
+
+  ADD_DEFINITIONS(-DENABLE_OPENCL_20)
+ENDIF(ENABLE_OPENCL_20)
+
+set (LIBCL_DRIVER_VERSION_MAJOR 1)
+set (LIBCL_DRIVER_VERSION_MINOR 3)
+if (ENABLE_OPENCL_20)
+  set (LIBCL_C_VERSION_MAJOR 2)
+  set (LIBCL_C_VERSION_MINOR 0)
+else (ENABLE_OPENCL_20)
+  set (LIBCL_C_VERSION_MAJOR 1)
+  set (LIBCL_C_VERSION_MINOR 2)
+endif (ENABLE_OPENCL_20)
+configure_file (
+  "src/OCLConfig.h.in"
+  "src/OCLConfig.h"
+)
+
+
 OPTION(BUILD_EXAMPLES "Build examples" OFF)
 IF(BUILD_EXAMPLES)
 IF(NOT X11_FOUND)
diff --git a/GetGenID.sh b/GetGenID.sh
index a0e5f85..5e5cafd 100755
--- a/GetGenID.sh
+++ b/GetGenID.sh
@@ -12,34 +12,50 @@ genpciid+=(0d02 0d12 0d22 0d0a 0d1a 0d2a 0d06 0d16 0d26 0d0b 0d1b 0d2b 0d0e 0d1e
 genpciid+=(1602 1606 160a 160d 160e 1612 1616 161a 161d 161e 1622 1626 162a 162d 162e)
 #BSW
 genpciid+=(22b0 22b1 22b2 22b3)
+#Only enable OpenCL 2.0 after SKL.
 #SKL
-genpciid+=(1906 1916 1926 190e 191e 1902 1912 1932 190b 191b 192b 193b 190a 191a 192a 193a)
+genpciid_20=(1906 1916 1926 190e 191e 1902 1912 1932 190b 191b 192b 193b 190a 191a 192a 193a)
 #BXT
-genpciid+=(5a84 5a85)
+genpciid_20+=(5a84 5a85 1a84 1a85)
 #KBL
-genpciid+=(5906 5916 5926 5913 5921 5923 5927 5902 5912 5917)
-genpciid+=(590b 591b 593b 5908 590e 591e 5915 590a 591a 591d)
+genpciid_20+=(5906 5916 5926 5913 5921 5923 5927 5902 5912 5917)
+genpciid_20+=(590b 591b 593b 5908 590e 591e 5915 590a 591a 591d)
 pciid=($(lspci -nn | grep "\[8086:.*\]" -o | awk -F : '{print $2}' | awk -F ] '{print $1}'))
 n=${#pciid[*]}
 i=0
 m=${#genpciid[*]}
+t=${#genpciid_20[*]}
 j=0
 while [ $i -lt $n ]
 do
-    id1=${pciid[$i]}
-    let j=0
+  id1=${pciid[$i]}
+  let j=0
 
-    while [ $j -lt $m ]
-    do
-	id2=${genpciid[$j]}
+  while [ $j -lt $m ]
+  do
+    id2=${genpciid[$j]}
 
-	if [ ${id1} == ${id2} ]
-	then
-	    echo ${id1}
-	    exit 0
-	fi
-	let j=j+1
-    done
+    if [ ${id1} == ${id2} ]
+    then
+      echo ${id1}
+      exit 0
+    fi
+    let j=j+1
+  done
 
-    let i=i+1
+  let j=0
+  while [ $j -lt $t ]
+  do
+    id2=${genpciid_20[$j]}
+
+    if [ ${id1} == ${id2} ]
+    then
+      echo ${id1}
+      exit 1
+    fi
+    let j=j+1
+  done
+
+  let i=i+1
 done
+exit -1
-- 
2.1.4



More information about the Beignet mailing list