diff options
-rw-r--r-- | arm_compute/core/CL/CLHelpers.h | 10 | ||||
-rw-r--r-- | arm_compute/runtime/CL/CLScheduler.h | 32 | ||||
-rw-r--r-- | src/core/CL/CLHelpers.cpp | 18 | ||||
-rw-r--r-- | src/core/CL/cl_kernels/helpers.h | 2 |
4 files changed, 43 insertions, 19 deletions
diff --git a/arm_compute/core/CL/CLHelpers.h b/arm_compute/core/CL/CLHelpers.h index d239a6159b..c7182656df 100644 --- a/arm_compute/core/CL/CLHelpers.h +++ b/arm_compute/core/CL/CLHelpers.h @@ -134,6 +134,16 @@ GPUTarget get_arch_from_target(GPUTarget target); * @return the highest OpenCL version supported */ CLVersion get_cl_version(const cl::Device &device); + +/** Helper function to check whether a given extension is supported + * + * @param[in] device A CL device + * @param[in] extension_name Name of the extension to be checked + * + * @return True if the extension is supported + */ +bool device_supports_extension(const cl::Device &device, const char *extension_name); + /** Helper function to check whether the cl_khr_fp16 extension is supported * * @param[in] device A CL device diff --git a/arm_compute/runtime/CL/CLScheduler.h b/arm_compute/runtime/CL/CLScheduler.h index e1e7ff637f..2fe3c2cf42 100644 --- a/arm_compute/runtime/CL/CLScheduler.h +++ b/arm_compute/runtime/CL/CLScheduler.h @@ -73,18 +73,28 @@ public: if(!_is_initialised) { #if defined(ARM_COMPUTE_DEBUG_ENABLED) - // Create a cl_context with a printf_callback and user specified buffer size. - cl_context_properties properties[] = + bool is_cl_arm_printf_supported = false; + + //query devices in the context for cl_arm_printf support + std::vector<cl::Device> def_platform_devices; + cl::Platform::getDefault().getDevices(CL_DEVICE_TYPE_DEFAULT, &def_platform_devices); + is_cl_arm_printf_supported = device_supports_extension(def_platform_devices[0], "cl_arm_printf"); + + if(is_cl_arm_printf_supported) { - // Enable a printf callback function for this context. - CL_PRINTF_CALLBACK_ARM, reinterpret_cast<cl_context_properties>(printf_callback), - // Request a minimum printf buffer size of 4MB for devices in the - // context that support this extension. - CL_PRINTF_BUFFERSIZE_ARM, static_cast<cl_context_properties>(0x100000), - CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(cl::Platform::get()()), - 0 - }; - cl::Context::setDefault(cl::Context(CL_DEVICE_TYPE_DEFAULT, properties)); + // Create a cl_context with a printf_callback and user specified buffer size. + cl_context_properties properties[] = + { + // Enable a printf callback function for this context. + CL_PRINTF_CALLBACK_ARM, reinterpret_cast<cl_context_properties>(printf_callback), + // Request a minimum printf buffer size of 4MB for devices in the + // context that support this extension. + CL_PRINTF_BUFFERSIZE_ARM, static_cast<cl_context_properties>(0x100000), + CL_CONTEXT_PLATFORM, reinterpret_cast<cl_context_properties>(cl::Platform::get()()), + 0 + }; + cl::Context::setDefault(cl::Context(CL_DEVICE_TYPE_DEFAULT, properties)); + } #endif // defined(ARM_COMPUTE_DEBUG_ENABLED) CLKernelLibrary::get().init("./cl_kernels/", cl::Context::getDefault(), cl::Device::getDefault()); diff --git a/src/core/CL/CLHelpers.cpp b/src/core/CL/CLHelpers.cpp index eb1b06e7a8..378e910f21 100644 --- a/src/core/CL/CLHelpers.cpp +++ b/src/core/CL/CLHelpers.cpp @@ -93,12 +93,6 @@ arm_compute::GPUTarget get_midgard_target(const std::string &version) } } -bool extension_support(const cl::Device &device, const char *extension_name) -{ - std::string extensions = device.getInfo<CL_DEVICE_EXTENSIONS>(); - auto pos = extensions.find(extension_name); - return (pos != std::string::npos); -} } // namespace namespace arm_compute @@ -253,12 +247,12 @@ GPUTarget get_arch_from_target(GPUTarget target) bool non_uniform_workgroup_support(const cl::Device &device) { - return extension_support(device, "cl_arm_non_uniform_work_group_size"); + return device_supports_extension(device, "cl_arm_non_uniform_work_group_size"); } bool fp16_support(const cl::Device &device) { - return extension_support(device, "cl_khr_fp16"); + return device_supports_extension(device, "cl_khr_fp16"); } CLVersion get_cl_version(const cl::Device &device) @@ -284,4 +278,12 @@ CLVersion get_cl_version(const cl::Device &device) return CLVersion::UNKNOWN; } + +bool device_supports_extension(const cl::Device &device, const char *extension_name) +{ + std::string extensions = device.getInfo<CL_DEVICE_EXTENSIONS>(); + auto pos = extensions.find(extension_name); + return (pos != std::string::npos); +} + } // namespace arm_compute diff --git a/src/core/CL/cl_kernels/helpers.h b/src/core/CL/cl_kernels/helpers.h index 02c6c4cc41..615c5188a1 100644 --- a/src/core/CL/cl_kernels/helpers.h +++ b/src/core/CL/cl_kernels/helpers.h @@ -29,7 +29,9 @@ #endif // defined(ARM_COMPUTE_OPENCL_FP16_ENABLED) #if defined(ARM_COMPUTE_DEBUG_ENABLED) +#if defined(cl_arm_printf) #pragma OPENCL EXTENSION cl_arm_printf : enable +#endif // defined(cl_arm_printf) #endif // defined(ARM_COMPUTE_DEBUG_ENABLED) #define EXPAND(x) x |