[Beignet] [PATCH V5] Enable OpenCL 2.0 only where supported

Yang, Rong R rong.r.yang at intel.com
Tue Feb 14 05:53:42 UTC 2017


Pushed, thanks.

> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Xiuli Pan
> Sent: Monday, February 13, 2017 9:52
> To: beignet at lists.freedesktop.org
> Cc: Pan, Xiuli <xiuli.pan at intel.com>
> Subject: [Beignet] [PATCH V5] Enable OpenCL 2.0 only where supported
> 
> From: Pan Xiuli <xiuli.pan at intel.com>
> 
> This allows a single beignet binary to both offer 2.0 where available, and still
> work on older hardware.
> V2: Default to 1.2 when -cl-std is not set (required by the OpenCL spec,
>     and also likely to be faster).
> V3: Only enable OpenCL 2.0 when llvm version is 39.
> V4: Only enable OpenCL 2.0 on x64 host.
> V5: Always return 32 as address bits.
> 
> Contributor: Rebecca N. Palmer <rebecca_palmer at zoho.com>
> Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
> ---
>  CMakeLists.txt                  | 46 ++++++++++++++++++++++++++++-------------
>  backend/src/backend/program.cpp | 19 +++++++++--------
>  src/cl_device_data.h            |  2 ++
>  src/cl_gen9_device.h            |  2 ++
>  src/cl_gt_device.h              | 14 ++++++++-----
>  src/cl_platform_id.c            |  2 +-
>  src/cl_platform_id.h            |  6 ++++--
>  7 files changed, 60 insertions(+), 31 deletions(-)
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt index 3246567..70fc10e 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -234,20 +234,18 @@ 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)
> +SET(CAN_OPENCL_20 ON)
> +IF (CMAKE_SIZEOF_VOID_P EQUAL 4)
> +  SET(CAN_OPENCL_20 OFF)
> +ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 4)
> +IF (NOT HAVE_DRM_INTEL_BO_SET_SOFTPIN)
> +  SET(CAN_OPENCL_20 OFF)
> +ENDIF (NOT HAVE_DRM_INTEL_BO_SET_SOFTPIN) IF
> (LLVM_VERSION_NODOT
> +VERSION_LESS 39)
> +  SET(CAN_OPENCL_20 OFF)
> +ENDIF (LLVM_VERSION_NODOT VERSION_LESS 39)
> 
> +IF (ENABLE_OPENCL_20)
>    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) @@ -256,9 +254,29 @@
> IF (ENABLE_OPENCL_20)
>      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)
> +  IF (CMAKE_SIZEOF_VOID_P EQUAL 4)
> +    MESSAGE(FATAL_ERROR "Please use x64 host to enable OpenCL 2.0.")
> + ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 4)
>  ENDIF(ENABLE_OPENCL_20)
> 
> +IF (DEFINED ENABLE_OPENCL_20)
> +  IF (ENABLE_OPENCL_20 AND CAN_OPENCL_20)
> +    SET(CAN_OPENCL_20 ON)
> +  ELSE(ENABLE_OPENCL_20 AND CAN_OPENCL_20)
> +    SET(CAN_OPENCL_20 OFF)
> +  ENDIF (ENABLE_OPENCL_20 AND CAN_OPENCL_20) ENDIF (DEFINED
> +ENABLE_OPENCL_20)
> +
> +OPTION(ENABLE_OPENCL_20 "Enable opencl 2.0 support"
> ${CAN_OPENCL_20})
> +
> +IF (CAN_OPENCL_20)
> +  SET (ENABLE_OPENCL_20 ON)
> +  MESSAGE(STATUS "Building with OpenCL 2.0.")
> +  ADD_DEFINITIONS(-DENABLE_OPENCL_20)
> +ELSE (CAN_OPENCL_20)
> +  MESSAGE(STATUS "Building with OpenCL 1.2.")
> +ENDIF(CAN_OPENCL_20)
> +
>  set (LIBCL_DRIVER_VERSION_MAJOR 1)
>  set (LIBCL_DRIVER_VERSION_MINOR 4)
>  if (ENABLE_OPENCL_20)
> diff --git a/backend/src/backend/program.cpp
> b/backend/src/backend/program.cpp index 85d0aa9..09c79d8 100644
> --- a/backend/src/backend/program.cpp
> +++ b/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__)
> @@ -1022,15 +1024,9 @@ EXTEND_QUOTE:
>      }
> 
>      if (useDefaultCLCVersion) {
> -#ifdef ENABLE_OPENCL_20
> -      clOpt.push_back("-D__OPENCL_C_VERSION__=200");
> -      clOpt.push_back("-cl-std=CL2.0");
> -      oclVersion = 200;
> -#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 +1057,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 +1077,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 +1140,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)) diff --git
> a/src/cl_device_data.h b/src/cl_device_data.h index 4ee4ca3..f3c5204
> 100644
> --- a/src/cl_device_data.h
> +++ b/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__ */
> 
> diff --git a/src/cl_gen9_device.h b/src/cl_gen9_device.h index
> be30a49..b0a3ab8 100644
> --- a/src/cl_gen9_device.h
> +++ b/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
> 
> diff --git a/src/cl_gt_device.h b/src/cl_gt_device.h index cf5ad7a..ca4f3c5
> 100644
> --- a/src/cl_gt_device.h
> +++ b/src/cl_gt_device.h
> @@ -16,7 +16,15 @@
>   *
>   * Author: Benjamin Segovia <benjamin.segovia at intel.com>
>   */
> -
> +#undef LIBCL_VERSION_STRING
> +#undef LIBCL_C_VERSION_STRING
> +#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,11 +47,7
> @@  .native_vector_width_float = 4,  .native_vector_width_double =
> 2,  .native_vector_width_half = 8, -#ifdef ENABLE_OPENCL_20 -.address_bits
> = 64, -#else  .address_bits = 32, -#endif  .svm_capabilities =
> CL_DEVICE_SVM_COARSE_GRAIN_BUFFER,
>  .preferred_platform_atomic_alignment =
> 0,  .preferred_global_atomic_alignment = 0, diff --git a/src/cl_platform_id.c
> b/src/cl_platform_id.c index 1f21f5d..2afafb2 100644
> --- a/src/cl_platform_id.c
> +++ b/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") diff --git a/src/cl_platform_id.h
> b/src/cl_platform_id.h index 3fdb920..89e0857 100644
> --- a/src/cl_platform_id.h
> +++ b/src/cl_platform_id.h
> @@ -72,8 +72,10 @@ extern cl_int cl_get_platform_ids(cl_uint
> num_entries,
>  #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__ */
> 
> --
> 2.7.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list