blob: feb44ce04b63e366b408df2a8b86d5c7d7085b33 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyroua9676112018-02-22 18:07:43 +00002 * Copyright (c) 2016-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010027#include "arm_compute/core/CL/CLTypes.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#include "arm_compute/core/CL/OpenCL.h"
Michele Di Giorgiob8fc60f2018-04-25 11:58:07 +010029#include "arm_compute/core/GPUTarget.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030#include "arm_compute/core/Helpers.h"
Moritz Pflanzerd0ae8b82017-06-29 14:51:57 +010031#include "support/ToolchainSupport.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032
33#include <string>
34
35namespace arm_compute
36{
37enum class DataType;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038
39/** Max vector width of an OpenCL vector */
Anthony Barbier7068f992017-10-26 15:23:08 +010040static constexpr unsigned int max_cl_vector_width = 16;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041
42/** Translates a tensor data type to the appropriate OpenCL type.
43 *
44 * @param[in] dt @ref DataType to be translated to OpenCL type.
45 *
46 * @return The string specifying the OpenCL type to be used.
47 */
48std::string get_cl_type_from_data_type(const DataType &dt);
49
SiCong Lic51b72f2017-07-28 14:46:20 +010050/** Get the size of a data type in number of bits.
51 *
52 * @param[in] dt @ref DataType.
53 *
54 * @return Number of bits in the data type specified.
55 */
56std::string get_data_size_from_data_type(const DataType &dt);
57
Georgios Pinitasac4e8732017-07-05 17:02:25 +010058/** Translates fixed point tensor data type to the underlying OpenCL type.
59 *
60 * @param[in] dt @ref DataType to be translated to OpenCL type.
61 *
62 * @return The string specifying the underlying OpenCL type to be used.
63 */
64std::string get_underlying_cl_type_from_data_type(const DataType &dt);
65
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066/** Helper function to get the GPU target from CL device
67 *
68 * @param[in] device A CL device
69 *
70 * @return the GPU target
71 */
72GPUTarget get_target_from_device(cl::Device &device);
73
steniu0134702472017-07-11 09:22:58 +010074/** Helper function to get the highest OpenCL version supported
75 *
76 * @param[in] device A CL device
77 *
78 * @return the highest OpenCL version supported
79 */
80CLVersion get_cl_version(const cl::Device &device);
Vidhya Sudhan Loganathaneb8a3992018-04-10 12:23:22 +010081
82/** Helper function to check whether a given extension is supported
83 *
84 * @param[in] device A CL device
85 * @param[in] extension_name Name of the extension to be checked
86 *
87 * @return True if the extension is supported
88 */
89bool device_supports_extension(const cl::Device &device, const char *extension_name);
90
Matthew Bentham6f31f8c2017-10-27 11:50:06 +010091/** Helper function to check whether the cl_khr_fp16 extension is supported
92 *
93 * @param[in] device A CL device
94 *
95 * @return True if the extension is supported
96 */
Anthony Barbierd727e852018-04-20 11:05:29 +010097bool fp16_supported(const cl::Device &device);
steniu0134702472017-07-11 09:22:58 +010098/** Helper function to check whether the arm_non_uniform_work_group_size extension is supported
99 *
100 * @param[in] device A CL device
101 *
102 * @return True if the extension is supported
103 */
Anthony Barbierd727e852018-04-20 11:05:29 +0100104bool arm_non_uniform_workgroup_supported(const cl::Device &device);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100105}
Anthony Barbierac69aa12017-07-03 17:39:37 +0100106#endif /* __ARM_COMPUTE_CLHELPERS_H__ */