From f8bb0928ed5e2acce2f6e0c2fd8caf8884141c79 Mon Sep 17 00:00:00 2001 From: Viet-Hoa Do Date: Mon, 30 May 2022 15:15:15 +0100 Subject: Add support OpenCL 3.0 non-uniform workgroup * Add OpenCL version 3 detection. * Use -cl-std=CL3.0 build option to support non-uniform workgroup when OpenCL 3 is detected and the feature is supported. Resolves: COMPMID-5208 Signed-off-by: Viet-Hoa Do Change-Id: Ifd8cbae6b34228c07e761bcb94ee8f35bdf1bace Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/7655 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Pablo Marquez Tello Benchmark: Arm Jenkins --- arm_compute/AclOpenClExt.h | 4 ++-- arm_compute/core/CL/CLDevice.h | 28 +++++++++++++++++++++++++++- arm_compute/core/CL/CLHelpers.h | 10 +++++++++- arm_compute/core/CL/CLTypes.h | 3 ++- arm_compute/core/CL/OpenCL.h | 4 ++-- src/core/CL/CLCompileContext.cpp | 12 ++++++------ src/core/CL/CLHelpers.cpp | 17 +++++++++++++++-- 7 files changed, 63 insertions(+), 15 deletions(-) diff --git a/arm_compute/AclOpenClExt.h b/arm_compute/AclOpenClExt.h index c349f76d86..ef80fd2443 100644 --- a/arm_compute/AclOpenClExt.h +++ b/arm_compute/AclOpenClExt.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited. + * Copyright (c) 2021-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -27,7 +27,7 @@ #include "arm_compute/AclTypes.h" #ifndef CL_TARGET_OPENCL_VERSION -#define CL_TARGET_OPENCL_VERSION 200 +#define CL_TARGET_OPENCL_VERSION 300 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS #define CL_USE_DEPRECATED_OPENCL_1_2_APIS #endif /* CL_TARGET_OPENCL_VERSION */ diff --git a/arm_compute/core/CL/CLDevice.h b/arm_compute/core/CL/CLDevice.h index 06aaac88f4..5e0f86e6d9 100644 --- a/arm_compute/core/CL/CLDevice.h +++ b/arm_compute/core/CL/CLDevice.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Arm Limited. + * Copyright (c) 2020-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -143,6 +143,32 @@ public: return _options.extensions.count(extension) != 0; } + /** Returns whether non-uniform workgroup is supported and the build options. + * + * If the feature is supported, the appropriate build options will be + * appended to the specified string. + * + * @return A tuple (supported, build_options) indicating whether the feature + * is supported and the corresponding build options to enable it. + */ + std::tuple is_non_uniform_workgroup_supported() const + { + if(version() == CLVersion::CL30 && get_cl_non_uniform_work_group_supported(_device)) + { + return {true, " -cl-std=CL3.0 "}; + } + else if(version() == CLVersion::CL20) + { + return {true, " -cl-std=CL2.0 "}; + } + else if(supported("cl_arm_non_uniform_work_group_size")) + { + return {true, " -cl-arm-non-uniform-work-group-size "}; + } + + return {false, ""}; + } + private: cl::Device _device; /**< OpenCL device. */ struct CLDeviceOptions _options; /**< OpenCL device options */ diff --git a/arm_compute/core/CL/CLHelpers.h b/arm_compute/core/CL/CLHelpers.h index 729eb13398..94ec5d781b 100644 --- a/arm_compute/core/CL/CLHelpers.h +++ b/arm_compute/core/CL/CLHelpers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2021 Arm Limited. + * Copyright (c) 2016-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -124,6 +124,14 @@ CLVersion get_cl_version(const cl::Device &device); */ size_t get_cl_image_pitch_alignment(const cl::Device &device); +/** Helper function to check whether non-uniform work group is supported + * + * @param[in] device A CL device + * + * @return True if the feature is supported + */ +bool get_cl_non_uniform_work_group_supported(const cl::Device &device); + /** Helper function to check whether a given extension is supported * * @param[in] device A CL device diff --git a/arm_compute/core/CL/CLTypes.h b/arm_compute/core/CL/CLTypes.h index 86335dae67..00b7cda2e1 100644 --- a/arm_compute/core/CL/CLTypes.h +++ b/arm_compute/core/CL/CLTypes.h @@ -41,7 +41,8 @@ enum class CLVersion CL10, /* the OpenCL 1.0 */ CL11, /* the OpenCL 1.1 */ CL12, /* the OpenCL 1.2 */ - CL20, /* the OpenCL 2.0 and above */ + CL20, /* the OpenCL 2.x */ + CL30, /* the OpenCL 3.x */ UNKNOWN /* unkown version */ }; diff --git a/arm_compute/core/CL/OpenCL.h b/arm_compute/core/CL/OpenCL.h index 4ff42c6b8a..93f7c318dd 100644 --- a/arm_compute/core/CL/OpenCL.h +++ b/arm_compute/core/CL/OpenCL.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2021 Arm Limited. + * Copyright (c) 2016-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -31,7 +31,7 @@ #ifndef ARM_COMPUTE_NO_EXCEPTIONS #define CL_HPP_ENABLE_EXCEPTIONS #endif // ARM_COMPUTE_NO_EXCEPTIONS -#define CL_TARGET_OPENCL_VERSION 200 +#define CL_TARGET_OPENCL_VERSION 300 #define CL_HPP_TARGET_OPENCL_VERSION 110 #define CL_HPP_MINIMUM_OPENCL_VERSION 110 #pragma GCC diagnostic push diff --git a/src/core/CL/CLCompileContext.cpp b/src/core/CL/CLCompileContext.cpp index 2fed76555b..81eb748ab8 100644 --- a/src/core/CL/CLCompileContext.cpp +++ b/src/core/CL/CLCompileContext.cpp @@ -232,6 +232,8 @@ void CLCompileContext::set_context(cl::Context context) std::string CLCompileContext::generate_build_options(const StringSet &build_options_set, const std::string &kernel_path) const { std::string concat_str; + bool ext_supported = false; + std::string ext_buildopts; #if defined(ARM_COMPUTE_DEBUG_ENABLED) // Enable debug properties in CL kernels @@ -257,13 +259,11 @@ std::string CLCompileContext::generate_build_options(const StringSet &build_opti concat_str += " -DARM_COMPUTE_OPENCL_DOT8_ACC_ENABLED=1 "; } - if(_device.version() == CLVersion::CL20) - { - concat_str += " -cl-std=CL2.0 "; - } - else if(_device.supported("cl_arm_non_uniform_work_group_size")) + std::tie(ext_supported, ext_buildopts) = _device.is_non_uniform_workgroup_supported(); + + if(ext_supported) { - concat_str += " -cl-arm-non-uniform-work-group-size "; + concat_str += ext_buildopts; } else { diff --git a/src/core/CL/CLHelpers.cpp b/src/core/CL/CLHelpers.cpp index 8685180b7f..5172a7730a 100644 --- a/src/core/CL/CLHelpers.cpp +++ b/src/core/CL/CLHelpers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2021 Arm Limited. + * Copyright (c) 2016-2022 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -256,7 +256,11 @@ bool dot8_acc_supported(const cl::Device &device) CLVersion get_cl_version(const cl::Device &device) { std::string version_str = device.getInfo(); - if(version_str.find("OpenCL 2") != std::string::npos) + if(version_str.find("OpenCL 3") != std::string::npos) + { + return CLVersion::CL30; + } + else if(version_str.find("OpenCL 2") != std::string::npos) { return CLVersion::CL20; } @@ -388,6 +392,15 @@ size_t get_cl_image_pitch_alignment(const cl::Device &device) } } +bool get_cl_non_uniform_work_group_supported(const cl::Device &device) +{ + cl_bool supported = CL_FALSE; + + cl_int err = clGetDeviceInfo(device(), CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, sizeof(cl_bool), &supported, nullptr); + + return (err == CL_SUCCESS && supported == CL_TRUE); +} + cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set &build_opts) { opencl::ClKernelLibrary &klib = opencl::ClKernelLibrary::get(); -- cgit v1.2.1