blob: 26253e3f38cfaed90c4a1a89bc6564014c62964f [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_CLHELPERS_H__
25#define __ARM_COMPUTE_CLHELPERS_H__
26
27#include "arm_compute/core/CL/OpenCL.h"
28#include "arm_compute/core/Helpers.h"
29
30#include <string>
31
32namespace arm_compute
33{
34enum class DataType;
35enum class GPUTarget;
36
37/** Enable operation operations on GPUTarget enumerations */
38template <>
39struct enable_bitwise_ops<arm_compute::GPUTarget>
40{
41 static constexpr bool value = true;
42};
43
44/** Max vector width of an OpenCL vector */
45static constexpr const unsigned int max_cl_vector_width = 16;
46
47/** Translates a tensor data type to the appropriate OpenCL type.
48 *
49 * @param[in] dt @ref DataType to be translated to OpenCL type.
50 *
51 * @return The string specifying the OpenCL type to be used.
52 */
53std::string get_cl_type_from_data_type(const DataType &dt);
54
55/** Translates a given gpu device target to string.
56 *
57 * @param[in] target Given gpu target.
58 *
59 * @return The string describing the target.
60 */
61const std::string &string_from_target(GPUTarget target);
62
63/** Helper function to create and return a unique_ptr pointed to a CL kernel object
64 * It also calls the kernel's configuration.
65 *
66 * @param[in] args All the arguments that need pass to kernel's configuration.
67 *
68 * @return A unique pointer pointed to a CL kernel object
69 */
70template <typename Kernel, typename... T>
71std::unique_ptr<Kernel> create_configure_kernel(T &&... args)
72{
73 std::unique_ptr<Kernel> k = arm_compute::cpp14::make_unique<Kernel>();
74 k->configure(std::forward<T>(args)...);
75 return k;
76}
77
78/** Helper function to create and return a unique_ptr pointed to a CL kernel object
79 *
80 * @return A unique pointer pointed to a CL kernel object
81 */
82template <typename Kernel>
83std::unique_ptr<Kernel> create_kernel()
84{
85 std::unique_ptr<Kernel> k = arm_compute::cpp14::make_unique<Kernel>();
86 return k;
87}
88
89/** Helper function to get the GPU target from CL device
90 *
91 * @param[in] device A CL device
92 *
93 * @return the GPU target
94 */
95GPUTarget get_target_from_device(cl::Device &device);
96
97/** Helper function to get the GPU arch
98 *
99 * @param[in] target GPU target
100 *
101 * @return the GPU target which shows the arch
102 */
103GPUTarget get_arch_from_target(GPUTarget target);
104}
105#endif