From 402740da11c4fd2a9dc7aee5dadf3b1fdda0afde Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Tue, 20 Apr 2021 11:26:21 +0100 Subject: Add support for CLVK This patch enables CLVK through the graph API and inside the CLScheduler. By default the Native platform is selected. Selecting CLVK can be done via --target=clvk. Resolves COMPMID-4205 and COMPMID-4206 Change-Id: Ic60744980c6b8a60e776627ea677ed46be88f656 Signed-off-by: Michalis Spyrou Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5475 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas --- arm_compute/core/CL/OpenCL.h | 1 + arm_compute/graph/TypePrinter.h | 3 ++ arm_compute/graph/Types.h | 24 ++++++++------ arm_compute/graph/backends/CL/CLDeviceBackend.h | 2 ++ arm_compute/runtime/CL/CLHelpers.h | 15 +++++++-- arm_compute/runtime/CL/CLRuntimeContext.h | 4 ++- arm_compute/runtime/CL/CLScheduler.h | 26 +++++++++------ arm_compute/runtime/CL/CLTypes.h | 7 ++++ docs/01_library.dox | 5 +++ src/core/CL/OpenCL.cpp | 19 +++++++++++ src/graph/GraphManager.cpp | 14 +++++++- src/graph/TypeLoader.cpp | 1 + src/graph/backends/CL/CLDeviceBackend.cpp | 5 +-- src/runtime/CL/CLHelpers.cpp | 44 ++++++++++++++++++++++--- src/runtime/CL/CLRuntimeContext.cpp | 6 ++-- src/runtime/CL/CLScheduler.cpp | 10 +++--- tests/benchmark_examples/RunExample.cpp | 12 ++++++- tests/main.cpp | 2 +- tests/validate_examples/RunExample.cpp | 7 +++- utils/CommonGraphOptions.cpp | 3 +- utils/CommonGraphOptions.h | 2 +- 21 files changed, 168 insertions(+), 44 deletions(-) diff --git a/arm_compute/core/CL/OpenCL.h b/arm_compute/core/CL/OpenCL.h index 155c3e4eef..1e6b04c042 100644 --- a/arm_compute/core/CL/OpenCL.h +++ b/arm_compute/core/CL/OpenCL.h @@ -123,6 +123,7 @@ public: DECLARE_FUNCTION_PTR(clGetDeviceIDs); DECLARE_FUNCTION_PTR(clGetMemObjectInfo); DECLARE_FUNCTION_PTR(clRetainEvent); + DECLARE_FUNCTION_PTR(clGetPlatformInfo); DECLARE_FUNCTION_PTR(clGetPlatformIDs); DECLARE_FUNCTION_PTR(clGetKernelWorkGroupInfo); DECLARE_FUNCTION_PTR(clGetCommandQueueInfo); diff --git a/arm_compute/graph/TypePrinter.h b/arm_compute/graph/TypePrinter.h index 317c5a7596..0bbb4695de 100644 --- a/arm_compute/graph/TypePrinter.h +++ b/arm_compute/graph/TypePrinter.h @@ -48,6 +48,9 @@ inline ::std::ostream &operator<<(::std::ostream &os, const Target &target) case Target::CL: os << "CL"; break; + case Target::CLVK: + os << "CLVK"; + break; default: ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); } diff --git a/arm_compute/graph/Types.h b/arm_compute/graph/Types.h index 4f3ce76370..7306b82a1e 100644 --- a/arm_compute/graph/Types.h +++ b/arm_compute/graph/Types.h @@ -28,6 +28,7 @@ #include "arm_compute/core/PixelValue.h" #include "arm_compute/core/Types.h" #include "arm_compute/runtime/CL/CLTunerTypes.h" +#include "arm_compute/runtime/CL/CLTypes.h" #include #include @@ -37,6 +38,7 @@ namespace arm_compute namespace graph { using arm_compute::CLTunerMode; +using arm_compute::CLBackendType; using arm_compute::Status; using arm_compute::Coordinates; @@ -80,16 +82,17 @@ struct TensorDescriptor; /** Graph configuration structure */ struct GraphConfig { - bool use_function_memory_manager{ true }; /**< Use a memory manager to manage per-function auxilary memory */ - bool use_function_weights_manager{ true }; /**< Use a weights manager to manage transformed weights */ - bool use_transition_memory_manager{ true }; /**< Use a memory manager to manager transition buffer memory */ - bool use_tuner{ false }; /**< Use a tuner in tunable backends */ - bool use_synthetic_type{ false }; /**< Convert graph to a synthetic graph for a data type */ - DataType synthetic_type{ DataType::QASYMM8 }; /**< The data type of the synthetic graph */ - CLTunerMode tuner_mode{ CLTunerMode::EXHAUSTIVE }; /**< Tuner mode to be used by the CL tuner */ - int num_threads{ -1 }; /**< Number of threads to use (thread capable backends), if 0 the backend will auto-initialize, if -1 the backend will stay as it is. */ - std::string tuner_file{ "acl_tuner.csv" }; /**< File to load/store tuning values from */ - std::string mlgo_file{ "heuristics.mlgo" }; /**< Filename to load MLGO heuristics from */ + bool use_function_memory_manager{ true }; /**< Use a memory manager to manage per-function auxilary memory */ + bool use_function_weights_manager{ true }; /**< Use a weights manager to manage transformed weights */ + bool use_transition_memory_manager{ true }; /**< Use a memory manager to manager transition buffer memory */ + bool use_tuner{ false }; /**< Use a tuner in tunable backends */ + bool use_synthetic_type{ false }; /**< Convert graph to a synthetic graph for a data type */ + DataType synthetic_type{ DataType::QASYMM8 }; /**< The data type of the synthetic graph */ + CLTunerMode tuner_mode{ CLTunerMode::EXHAUSTIVE }; /**< Tuner mode to be used by the CL tuner */ + int num_threads{ -1 }; /**< Number of threads to use (thread capable backends), if 0 the backend will auto-initialize, if -1 the backend will stay as it is. */ + std::string tuner_file{ "acl_tuner.csv" }; /**< File to load/store tuning values from */ + std::string mlgo_file{ "heuristics.mlgo" }; /**< Filename to load MLGO heuristics from */ + CLBackendType backend_type{ CLBackendType::Native }; /**< CL backend type to use */ }; /**< Device target types */ @@ -98,6 +101,7 @@ enum class Target UNSPECIFIED, /**< Unspecified Target */ NEON, /**< Arm® Neon™ capable target device */ CL, /**< OpenCL capable target device */ + CLVK, /**< CLVK capable target device */ }; /** Supported Element-wise operations */ diff --git a/arm_compute/graph/backends/CL/CLDeviceBackend.h b/arm_compute/graph/backends/CL/CLDeviceBackend.h index 82c0eacd11..278a8e5031 100644 --- a/arm_compute/graph/backends/CL/CLDeviceBackend.h +++ b/arm_compute/graph/backends/CL/CLDeviceBackend.h @@ -28,6 +28,7 @@ #include "arm_compute/runtime/CL/CLBufferAllocator.h" #include "arm_compute/runtime/CL/CLGEMMHeuristicsHandle.h" +#include "arm_compute/runtime/CL/CLTypes.h" #include "arm_compute/runtime/CL/CLTuner.h" namespace arm_compute @@ -76,6 +77,7 @@ private: CLGEMMHeuristicsHandle _gemm_heuristics; /**< GEMM heuristics */ std::unique_ptr _allocator; /**< CL buffer affinity allocator */ std::string _tuner_file; /**< Filename to load/store the tuner's values from */ + CLBackendType _backend_type; /**< OpenCL backend type to use */ }; } // namespace backends } // namespace graph diff --git a/arm_compute/runtime/CL/CLHelpers.h b/arm_compute/runtime/CL/CLHelpers.h index 9b71561c39..fef2619071 100644 --- a/arm_compute/runtime/CL/CLHelpers.h +++ b/arm_compute/runtime/CL/CLHelpers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,6 +25,7 @@ #define ARM_COMPUTE_CL_HELPERS_H #include "arm_compute/core/CL/OpenCL.h" +#include "arm_compute/runtime/CL/CLTypes.h" #include "arm_compute/runtime/IScheduler.h" namespace arm_compute @@ -37,11 +38,13 @@ class ICLKernel; * * @note In debug builds, the function will automatically enable cl_arm_printf if the driver/device supports it. * + * @param[in] cl_backend_type The OpenCL backend type to use. + * * @return A std::tuple where the first element is the opencl context, the second element is the opencl device * and the third one an error code. The error code will be CL_SUCCESS upon successful creation, otherwise * a value telling why the function failed. */ -std::tuple create_opencl_context_and_device(); +std::tuple create_opencl_context_and_device(CLBackendType cl_backend_type); /** Schedules a kernel using the context if not nullptr else uses the legacy scheduling flow. * * @param[in] ctx Context to use. @@ -49,5 +52,13 @@ std::tuple create_opencl_context_and_device(); * @param[in] flush (Optional) Specifies if the command queue will be flushed after running the kernel. */ void schedule_kernel_on_ctx(CLRuntimeContext *ctx, ICLKernel *kernel, bool flush = true); + +/** This function selects the OpenCL platform based on the backend type. + * + * @param[in] cl_backend_type The OpenCL backend type to use. + * + * @return A cl::Platform object. + */ +cl::Platform select_preferable_platform(CLBackendType cl_backend_type); } // namespace arm_compute #endif /* ARM_COMPUTE_CL_HELPERS_H */ diff --git a/arm_compute/runtime/CL/CLRuntimeContext.h b/arm_compute/runtime/CL/CLRuntimeContext.h index 083ac0ab88..4ab8f70887 100644 --- a/arm_compute/runtime/CL/CLRuntimeContext.h +++ b/arm_compute/runtime/CL/CLRuntimeContext.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -29,6 +29,7 @@ #include "arm_compute/core/CL/OpenCL.h" #include "arm_compute/runtime/CL/CLScheduler.h" #include "arm_compute/runtime/CL/CLTuner.h" +#include "arm_compute/runtime/CL/CLTypes.h" #include "arm_compute/runtime/IScheduler.h" #include "arm_compute/runtime/RuntimeContext.h" @@ -60,6 +61,7 @@ private: CLTuner _tuner{ false }; CLSymbols _symbols{}; CLCoreRuntimeContext _core_context{}; + CLBackendType _backend_type{ CLBackendType::Native }; }; } // namespace arm_compute #endif /*ARM_COMPUTE_CLRUNTIME_CONTEXT_H */ diff --git a/arm_compute/runtime/CL/CLScheduler.h b/arm_compute/runtime/CL/CLScheduler.h index 41a074089e..56852aec6e 100644 --- a/arm_compute/runtime/CL/CLScheduler.h +++ b/arm_compute/runtime/CL/CLScheduler.h @@ -31,6 +31,8 @@ #include "arm_compute/core/Types.h" #include "arm_compute/core/experimental/Types.h" #include "arm_compute/runtime/CL/CLGEMMHeuristicsHandle.h" +#include "arm_compute/runtime/CL/CLHelpers.h" +#include "arm_compute/runtime/CL/CLTypes.h" #include "arm_compute/runtime/CL/ICLTuner.h" namespace arm_compute @@ -57,10 +59,11 @@ public: /** Initialises the context and command queue used by the scheduler to default values * and sets a default device and kernel path for the @ref CLKernelLibrary. * - * @param[in] cl_tuner (Optional) Pointer to ICLTuner (default=nullptr) - * @param[in] gemm_h (Optional) Pointer to CLGEMMHeuristicsHandle (default = nullptr) + * @param[in] cl_tuner (Optional) Pointer to ICLTuner (default=nullptr) + * @param[in] gemm_h (Optional) Pointer to CLGEMMHeuristicsHandle (default = nullptr) + * @param[in] cl_backend_type (Optional) Type of backend to use (default = CLBackendType::Native) */ - void default_init(ICLTuner *cl_tuner = nullptr, CLGEMMHeuristicsHandle *gemm_h = nullptr); + void default_init(ICLTuner *cl_tuner = nullptr, CLGEMMHeuristicsHandle *gemm_h = nullptr, CLBackendType cl_backend_type = CLBackendType::Native); /** Initialises the scheduler with context and device provided by the user * * @param[in] device OpenCL device to be used @@ -86,14 +89,16 @@ public: /** Initialises the context and command queue to be used by the scheduler. * - * @param[in] context A CL context. - * @param[in] queue A CL command queue. - * @param[in] device A CL device. - * @param[in] cl_tuner (Optional) Pointer to OpenCL tuner (default=nullptr) - * Note: It is caller's responsibility to release the allocated memory for CLTuner - * @param[in] gemm_h (Optional) Pointer to CLGEMMHeuristicsHandle (default = nullptr) + * @param[in] context A CL context. + * @param[in] queue A CL command queue. + * @param[in] device A CL device. + * @param[in] cl_tuner (Optional) Pointer to OpenCL tuner (default=nullptr) + * Note: It is caller's responsibility to release the allocated memory for CLTuner + * @param[in] gemm_h (Optional) Pointer to CLGEMMHeuristicsHandle (default = nullptr) + * @param[in] cl_backend_type (Optional) Type of backend to use (default = CLBackendType::Native) */ - void init(cl::Context context, cl::CommandQueue queue, const cl::Device &device, ICLTuner *cl_tuner = nullptr, CLGEMMHeuristicsHandle *gemm_h = nullptr); + void init(cl::Context context, cl::CommandQueue queue, const cl::Device &device, ICLTuner *cl_tuner = nullptr, CLGEMMHeuristicsHandle *gemm_h = nullptr, + CLBackendType cl_backend_type = CLBackendType::Native); /** Accessor for the associated CL context. * @@ -171,6 +176,7 @@ private: bool _is_initialised; ICLTuner *_cl_tuner; CLGEMMHeuristicsHandle *_gemm_heuristics; + CLBackendType _backend_type; }; } // namespace arm_compute #endif /* ARM_COMPUTE_CLSCHEDULER_H */ diff --git a/arm_compute/runtime/CL/CLTypes.h b/arm_compute/runtime/CL/CLTypes.h index ab973f973c..cf0486c8c3 100644 --- a/arm_compute/runtime/CL/CLTypes.h +++ b/arm_compute/runtime/CL/CLTypes.h @@ -58,5 +58,12 @@ struct CLGEMMKernelSelectionParams bool is_rhs_constant{ false }; /**< True if the content of the rhs matrix is constant */ DataType data_type{ DataType::UNKNOWN }; /**< Data type */ }; + +/** List the possible OpenCL backends */ +enum class CLBackendType +{ + Native, /**< OpenCL native backend */ + Clvk, /**< CLVK backend */ +}; } // namespace arm_compute #endif /* ARM_COMPUTE_RUNTIME_CLTYPES_H */ diff --git a/docs/01_library.dox b/docs/01_library.dox index 6f4b717bfa..722a07f958 100644 --- a/docs/01_library.dox +++ b/docs/01_library.dox @@ -542,5 +542,10 @@ This feature introduces some changes to our API. All the kernels/functions will now accept a Runtime Context object which will allow the function to use the mentioned services. Finally, we will try to adapt our code-base progressively to use the new mechanism but will continue supporting the legacy mechanism to allow a smooth transition. Changes will apply to all our three backends: Neon, OpenCL and OpenGL ES. + +@subsection S5_2_clvk CLVK + +Compute Library offers experimental support for [CLVK](https://github.com/kpet/clvk). If CLVK is installed in the system, users can select the backend when running a graph example with --target=clvk. +If no target is specified and more that one OpenCL implementations are present, Compute Library will pick the first available. */ } // namespace arm_compute diff --git a/src/core/CL/OpenCL.cpp b/src/core/CL/OpenCL.cpp index dd9960a7b3..a7be534397 100644 --- a/src/core/CL/OpenCL.cpp +++ b/src/core/CL/OpenCL.cpp @@ -122,6 +122,7 @@ bool CLSymbols::load(const std::string &library) LOAD_FUNCTION_PTR(clGetDeviceIDs, handle); LOAD_FUNCTION_PTR(clGetMemObjectInfo, handle); LOAD_FUNCTION_PTR(clRetainEvent, handle); + LOAD_FUNCTION_PTR(clGetPlatformInfo, handle); LOAD_FUNCTION_PTR(clGetPlatformIDs, handle); LOAD_FUNCTION_PTR(clGetKernelWorkGroupInfo, handle); LOAD_FUNCTION_PTR(clGetCommandQueueInfo, handle); @@ -865,6 +866,24 @@ cl_int clRetainEvent(cl_event event) } } +cl_int clGetPlatformInfo(cl_platform_id platform, + cl_platform_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret) +{ + arm_compute::CLSymbols::get().load_default(); + auto func = arm_compute::CLSymbols::get().clGetPlatformInfo_ptr; + if(func != nullptr) + { + return func(platform, param_name, param_value_size, param_value, param_value_size_ret); + } + else + { + return CL_OUT_OF_RESOURCES; + } +} + cl_int clGetPlatformIDs(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms) { arm_compute::CLSymbols::get().load_default(); diff --git a/src/graph/GraphManager.cpp b/src/graph/GraphManager.cpp index 9d53172dc8..ab7aac6230 100644 --- a/src/graph/GraphManager.cpp +++ b/src/graph/GraphManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 Arm Limited. + * Copyright (c) 2018-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -57,6 +57,18 @@ void GraphManager::finalize_graph(Graph &graph, GraphContext &ctx, PassManager & // Force target to all graph construct // TODO (COMPMID-2014) : Support heterogeneous execution Target forced_target = target; + + // In case CLVK is selected, use the CL backend and + // update config + if(target == Target::CLVK) + { + forced_target = Target::CL; + GraphConfig config = ctx.config(); + config.backend_type = CLBackendType::Clvk; + + ctx.set_config(config); + } + if(!is_target_supported(target)) { forced_target = get_default_target(); diff --git a/src/graph/TypeLoader.cpp b/src/graph/TypeLoader.cpp index 8efd66f2c5..3c51289dba 100644 --- a/src/graph/TypeLoader.cpp +++ b/src/graph/TypeLoader.cpp @@ -59,6 +59,7 @@ Target target_from_name(const std::string &name) { { "neon", Target::NEON }, { "cl", Target::CL }, + { "clvk", Target::CLVK }, }; #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED diff --git a/src/graph/backends/CL/CLDeviceBackend.cpp b/src/graph/backends/CL/CLDeviceBackend.cpp index f8e22ca7a0..eafda98669 100644 --- a/src/graph/backends/CL/CLDeviceBackend.cpp +++ b/src/graph/backends/CL/CLDeviceBackend.cpp @@ -65,7 +65,7 @@ bool file_exists(const std::string &filename) static detail::BackendRegistrar CLDeviceBackend_registrar(Target::CL); CLDeviceBackend::CLDeviceBackend() - : _context_count(0), _tuner(), _gemm_heuristics(), _allocator(nullptr), _tuner_file() + : _context_count(0), _tuner(), _gemm_heuristics(), _allocator(nullptr), _tuner_file(), _backend_type(CLBackendType::Native) { } @@ -87,7 +87,7 @@ void CLDeviceBackend::set_kernel_tuning_mode(CLTunerMode tuning_mode) void CLDeviceBackend::initialize_backend() { // Setup Scheduler - CLScheduler::get().default_init(&_tuner, &_gemm_heuristics); + CLScheduler::get().default_init(&_tuner, &_gemm_heuristics, _backend_type); // Create allocator with new context _allocator = std::make_unique(nullptr /* legacy path for CLCoreRuntimeContext */); } @@ -108,6 +108,7 @@ void CLDeviceBackend::setup_backend_context(GraphContext &ctx) _context_count++; if(_context_count == 1) { + _backend_type = ctx.config().backend_type; initialize_backend(); } diff --git a/src/runtime/CL/CLHelpers.cpp b/src/runtime/CL/CLHelpers.cpp index 5f1842f76d..5b4bbbcde0 100644 --- a/src/runtime/CL/CLHelpers.cpp +++ b/src/runtime/CL/CLHelpers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -85,14 +85,48 @@ void initialise_context_properties(const cl::Platform &platform, const cl::Devic namespace arm_compute { -std::tuple -create_opencl_context_and_device() +cl::Platform select_preferable_platform(CLBackendType cl_backend_type) { - ARM_COMPUTE_ERROR_ON(!opencl_is_available()); std::vector platforms; cl::Platform::get(&platforms); ARM_COMPUTE_ERROR_ON_MSG(platforms.size() == 0, "Couldn't find any OpenCL platform"); - cl::Platform p = platforms[0]; + + cl::Platform selected_platform{ nullptr }; + + // If the user has selected the Native platform, return the first available. + switch(cl_backend_type) + { + case CLBackendType::Native: + selected_platform = platforms[0]; + break; + case CLBackendType::Clvk: + for(auto p : platforms) + { + std::string res = p.getInfo(); + if(res.find("clvk") != std::string::npos) + { + selected_platform = p; + break; + } + } + break; + default: + ARM_COMPUTE_ERROR("Unsupported backend type"); + } + + if(!selected_platform()) + { + ARM_COMPUTE_ERROR("No valid platform found"); + } + + return selected_platform; +} + +std::tuple +create_opencl_context_and_device(CLBackendType cl_backend_type) +{ + ARM_COMPUTE_ERROR_ON(!opencl_is_available()); + cl::Platform p = select_preferable_platform(cl_backend_type); cl::Device device; std::vector platform_devices; p.getDevices(CL_DEVICE_TYPE_DEFAULT, &platform_devices); diff --git a/src/runtime/CL/CLRuntimeContext.cpp b/src/runtime/CL/CLRuntimeContext.cpp index 9d46126ee4..0c1d011f9a 100644 --- a/src/runtime/CL/CLRuntimeContext.cpp +++ b/src/runtime/CL/CLRuntimeContext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -29,10 +29,10 @@ namespace arm_compute { CLRuntimeContext::CLRuntimeContext() - : _gpu_owned_scheduler(std::make_unique()), _gpu_scheduler(_gpu_owned_scheduler.get()), _symbols(), _core_context() + : _gpu_owned_scheduler(std::make_unique()), _gpu_scheduler(_gpu_owned_scheduler.get()), _symbols(), _core_context(), _backend_type() { _symbols.load_default(); - auto ctx_dev_err = create_opencl_context_and_device(); + auto ctx_dev_err = create_opencl_context_and_device(_backend_type); ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context"); auto ctx = std::get<0>(ctx_dev_err); auto dev = std::get<1>(ctx_dev_err); diff --git a/src/runtime/CL/CLScheduler.cpp b/src/runtime/CL/CLScheduler.cpp index f228cf6513..cb5f04ce8b 100644 --- a/src/runtime/CL/CLScheduler.cpp +++ b/src/runtime/CL/CLScheduler.cpp @@ -24,7 +24,6 @@ #include "arm_compute/runtime/CL/CLScheduler.h" #include "arm_compute/core/CL/CLKernelLibrary.h" -#include "arm_compute/runtime/CL/CLHelpers.h" #include "arm_compute/runtime/CL/CLTuner.h" #include "src/core/CL/ICLKernel.h" @@ -96,7 +95,7 @@ bool CLScheduler::is_initialised() const std::once_flag CLScheduler::_initialize_symbols; CLScheduler::CLScheduler() - : _context(), _queue(), _target(GPUTarget::MIDGARD), _is_initialised(false), _cl_tuner(nullptr), _gemm_heuristics(nullptr) + : _context(), _queue(), _target(GPUTarget::MIDGARD), _is_initialised(false), _cl_tuner(nullptr), _gemm_heuristics(nullptr), _backend_type(CLBackendType::Native) { } @@ -119,14 +118,14 @@ void CLScheduler::default_init_with_context(cl::Device &device, cl::Context &ctx } } -void CLScheduler::default_init(ICLTuner *cl_tuner, CLGEMMHeuristicsHandle *gemm_h) +void CLScheduler::default_init(ICLTuner *cl_tuner, CLGEMMHeuristicsHandle *gemm_h, CLBackendType cl_backend_type) { if(!_is_initialised) { cl::Context ctx; cl::Device dev; cl_int err; - std::tie(ctx, dev, err) = create_opencl_context_and_device(); + std::tie(ctx, dev, err) = create_opencl_context_and_device(cl_backend_type); ARM_COMPUTE_ERROR_ON_MSG(err != CL_SUCCESS, "Failed to create OpenCL context"); cl::CommandQueue queue = cl::CommandQueue(ctx, dev); CLKernelLibrary::get().init("./cl_kernels/", ctx, dev); @@ -143,7 +142,7 @@ void CLScheduler::set_context(cl::Context context) CLKernelLibrary::get().set_context(_context); } -void CLScheduler::init(cl::Context context, cl::CommandQueue queue, const cl::Device &device, ICLTuner *cl_tuner, CLGEMMHeuristicsHandle *gemm_h) +void CLScheduler::init(cl::Context context, cl::CommandQueue queue, const cl::Device &device, ICLTuner *cl_tuner, CLGEMMHeuristicsHandle *gemm_h, CLBackendType cl_backend_type) { set_context(std::move(context)); _queue = std::move(queue); @@ -151,6 +150,7 @@ void CLScheduler::init(cl::Context context, cl::CommandQueue queue, const cl::De _is_initialised = true; _cl_tuner = cl_tuner; _gemm_heuristics = gemm_h; + _backend_type = cl_backend_type; } void CLScheduler::enqueue_common(ICLKernel &kernel, ITensorPack &tensors, bool flush) diff --git a/tests/benchmark_examples/RunExample.cpp b/tests/benchmark_examples/RunExample.cpp index e5dfe74d0e..a23d91e9de 100644 --- a/tests/benchmark_examples/RunExample.cpp +++ b/tests/benchmark_examples/RunExample.cpp @@ -128,7 +128,17 @@ int run_example(int argc, char **argv, std::unique_ptr example) CLGEMMHeuristicsHandle gemm_h; if(opencl_is_available()) { - auto ctx_dev_err = create_opencl_context_and_device(); + CLBackendType backend_type = CLBackendType::Native; + for(auto &arg : example_args->value()) + { + if(arg.find("--target=clvk") != std::string::npos) + { + backend_type = CLBackendType::Clvk; + break; + } + } + + auto ctx_dev_err = create_opencl_context_and_device(backend_type); ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context"); CLScheduler::get() .default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), nullptr, &gemm_h); diff --git a/tests/main.cpp b/tests/main.cpp index cecd89bdb7..308338e781 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -183,7 +183,7 @@ int main(int argc, char **argv) CLGEMMHeuristicsHandle gemm_heuristics; if(opencl_is_available()) { - auto ctx_dev_err = create_opencl_context_and_device(); + auto ctx_dev_err = create_opencl_context_and_device(CLBackendType::Native); ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context"); gemm_heuristics.reload_from_file(mlgo_file->value()); CLScheduler::get().default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), &cl_tuner, &gemm_heuristics); diff --git a/tests/validate_examples/RunExample.cpp b/tests/validate_examples/RunExample.cpp index 8ba3c2b295..70cc8f1609 100644 --- a/tests/validate_examples/RunExample.cpp +++ b/tests/validate_examples/RunExample.cpp @@ -150,7 +150,12 @@ int run_example(int argc, char **argv, std::unique_ptr example) #ifdef ARM_COMPUTE_CL if(opencl_is_available()) { - auto ctx_dev_err = create_opencl_context_and_device(); + CLBackendType backend_type = CLBackendType::Native; + if(options.target->value() == Target::CLVK) + { + backend_type = CLBackendType::Clvk; + } + auto ctx_dev_err = create_opencl_context_and_device(backend_type); ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context"); CLScheduler::get().default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err), nullptr); } diff --git a/utils/CommonGraphOptions.cpp b/utils/CommonGraphOptions.cpp index 80bcbb5110..6ee7ed1878 100644 --- a/utils/CommonGraphOptions.cpp +++ b/utils/CommonGraphOptions.cpp @@ -137,6 +137,7 @@ CommonGraphOptions::CommonGraphOptions(CommandLineParser &parser) { Target::NEON, Target::CL, + Target::CLVK, }; std::set supported_data_types @@ -203,7 +204,7 @@ CommonGraphParams consume_common_graph_parameters(CommonGraphOptions &options) common_params.data_layout = options.data_layout->value(); } common_params.enable_tuner = options.enable_tuner->is_set() ? options.enable_tuner->value() : false; - common_params.enable_cl_cache = common_params.target == arm_compute::graph::Target::CL ? (options.enable_cl_cache->is_set() ? options.enable_cl_cache->value() : true) : false; + common_params.enable_cl_cache = common_params.target == arm_compute::graph::Target::NEON ? false : (options.enable_cl_cache->is_set() ? options.enable_cl_cache->value() : true); common_params.tuner_mode = options.tuner_mode->value(); common_params.fast_math_hint = options.fast_math_hint->is_set() ? fast_math_hint_value : FastMathHint::Disabled; common_params.data_path = options.data_path->value(); diff --git a/utils/CommonGraphOptions.h b/utils/CommonGraphOptions.h index 670a3073b5..f2cbd48b72 100644 --- a/utils/CommonGraphOptions.h +++ b/utils/CommonGraphOptions.h @@ -40,7 +40,7 @@ namespace utils * * --help : Print the example's help message. * --threads : The number of threads to be used by the example during execution. - * --target : Execution target to be used by the examples. Supported target options: Neon, CL. + * --target : Execution target to be used by the examples. Supported target options: Neon, CL, CLVK. * --type : Data type to be used by the examples. Supported data type options: QASYMM8, F16, F32. * --layout : Data layout to be used by the examples. Supported data layout options : NCHW, NHWC. * --enable-tuner : Toggle option to enable the OpenCL dynamic tuner. -- cgit v1.2.1