24.02.1
CLUtils.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020-2021, 2023 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
25
#ifndef ACL_SRC_CORE_CL_CLUTILS_H
26
#define ACL_SRC_CORE_CL_CLUTILS_H
27
28
#include "
arm_compute/core/CL/OpenCL.h
"
29
30
#include <map>
31
32
namespace
arm_compute
33
{
34
class
TensorShape;
35
class
CLBuildOptions;
36
class
ITensorInfo;
37
class
ICLTensor;
38
enum class
DataType
;
39
40
/** OpenCL Image2D types */
41
enum class
CLImage2DType
42
{
43
ReadOnly
,
44
WriteOnly
45
};
46
47
/** Create a cl::Image2D object from a tensor
48
*
49
* @param[in] tensor Tensor from which to construct Image 2D object
50
* @param[in] image_type Image 2D type (@ref CLImage2DType)
51
*
52
* @return cl::Image2D object
53
*/
54
cl::Image2D
create_image2d_from_tensor
(
const
ICLTensor *
tensor
,
CLImage2DType
image_type);
55
56
/** Create a cl::Image2D object from an OpenCL buffer
57
*
58
* @note The following conditions are required to create a OpenCL image object from OpenCL buffer,
59
* -# The platform should support the OpenCL cl_khr_image2d_from_buffer extension
60
* -# The stride Y for the input1 should satisfy the OpenCL pitch alignment requirement
61
* -# input width should be less or equal to (CL_DEVICE_IMAGE2D_MAX_WIDTH * 4)
62
* -# input height should be less or equal to CL_DEVICE_IMAGE2D_MAX_HEIGHT
63
*
64
* It is user responsibility to ensure the above conditions are satisfied since no checks are performed within this function
65
*
66
* @param[in] ctx cl::Context object
67
* @param[in] buffer cl::Buffer object from which the OpenCL image2d object is created
68
* @param[in] shape2d 2D tensor shape
69
* @param[in] data_type DataType to use. Only supported: F32,F16
70
* @param[in] image_row_pitch Image row pitch (a.k.a. stride Y) to be used in the image2d object
71
* @param[in] image_type Image 2D type (@ref CLImage2DType)
72
*
73
* @return cl::Image2D object
74
*/
75
cl::Image2D
create_image2d_from_buffer
(
const
cl::Context &ctx,
76
const
cl::Buffer &buffer,
77
const
TensorShape &shape2d,
78
DataType
data_type
,
79
size_t
image_row_pitch,
80
CLImage2DType
image_type);
81
82
/** Check for CL error code and throw exception accordingly.
83
*
84
* @param[in] function_name The name of the CL function being called.
85
* @param[in] error_code The error returned by the CL function.
86
*/
87
void
handle_cl_error
(
const
std::string &function_name, cl_int error_code);
88
89
}
// namespace arm_compute
90
91
#endif // ACL_SRC_CORE_CL_CLUTILS_H
arm_compute::create_image2d_from_tensor
cl::Image2D create_image2d_from_tensor(const ICLTensor *tensor, CLImage2DType image_type)
Create a cl::Image2D object from a tensor.
Definition:
CLUtils.cpp:37
arm_compute::CLImage2DType
CLImage2DType
OpenCL Image2D types.
Definition:
CLUtils.h:41
arm_compute::CLImage2DType::WriteOnly
@ WriteOnly
arm_compute::CLImage2DType::ReadOnly
@ ReadOnly
arm_compute::handle_cl_error
void handle_cl_error(const std::string &function_name, cl_int error_code)
Check for CL error code and throw exception accordingly.
Definition:
CLUtils.cpp:120
OpenCL.h
Wrapper to configure the Khronos OpenCL C++ header.
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition:
ClWorkloadRuntime.cpp:67
arm_compute::test::validation::data_type
data_type
Definition:
Cast.cpp:222
arm_compute::create_image2d_from_buffer
cl::Image2D create_image2d_from_buffer(const cl::Context &ctx, const cl::Buffer &buffer, const TensorShape &shape2d, DataType data_type, size_t image_row_pitch, CLImage2DType image_type)
Create a cl::Image2D object from an OpenCL buffer.
Definition:
CLUtils.cpp:62
arm_compute
Copyright (c) 2017-2024 Arm Limited.
Definition:
introduction.dox:24
arm_compute::DataType
DataType
Available data types.
Definition:
CoreTypes.h:83
src
core
CL
CLUtils.h
Generated on Mon Mar 18 2024 11:31:57 for Compute Library by
1.8.17