xref: /aosp_15_r20/external/ComputeLibrary/arm_compute/AclOpenClExt.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2021-2022 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_ACL_OPENCL_EXT_H_
25 #define ARM_COMPUTE_ACL_OPENCL_EXT_H_
26 
27 #include "arm_compute/AclTypes.h"
28 
29 #ifndef CL_TARGET_OPENCL_VERSION
30 #define CL_TARGET_OPENCL_VERSION 300
31 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
32 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
33 #endif /* CL_TARGET_OPENCL_VERSION */
34 #pragma GCC diagnostic push
35 #pragma GCC diagnostic ignored "-Weffc++"
36 #include "include/CL/cl.h"
37 #pragma GCC diagnostic pop
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42 
43 /** Extract the underlying OpenCL context used by a given Compute Library context object
44  *
45  * @note @ref AclContext should be of an OpenCL backend target
46  *
47  * @param[in]  ctx            A valid non-zero context
48  * @param[out] opencl_context Underlying OpenCL context used
49  *
50  * @return Status code
51  */
52 AclStatus AclGetClContext(AclContext ctx, cl_context *opencl_context);
53 
54 /** Extract the underlying OpenCL device id used by a given Compute Library context object
55  *
56  * @note @ref AclContext should be of an OpenCL backend target
57  *
58  * @param[in]  ctx           A valid non-zero context
59  * @param[out] opencl_device Underlying OpenCL device used
60  *
61  * @return Status code
62  */
63 AclStatus AclGetClDevice(AclContext ctx, cl_device_id *opencl_device);
64 
65 /** Set the underlying OpenCL context to be used by a given Compute Library context object
66  *
67  * @note @ref AclContext should be of an OpenCL backend target
68  *
69  * @param[in]  ctx            A valid non-zero context object
70  * @param[out] opencl_context Underlying OpenCL context to be used
71  *
72  * @return Status code
73  */
74 AclStatus AclSetClContext(AclContext ctx, cl_context opencl_context);
75 
76 /** Extract the underlying OpenCL queue used by a given Compute Library queue object
77  *
78  * @note @ref AclQueue should be of an OpenCL backend target
79  * @note @ref AclQueue refcount should be 0, meaning not used by other objects
80  *
81  * @param[in]  queue        A valid non-zero queue
82  * @param[out] opencl_queue Underlying OpenCL queue used
83  *
84  * @return Status code
85  */
86 AclStatus AclGetClQueue(AclQueue queue, cl_command_queue *opencl_queue);
87 
88 /** Set the underlying OpenCL queue to be used by a given Compute Library queue object
89  *
90  * @note @ref AclQueue should be of an OpenCL backend target
91  * @note opecl_queue needs to be created from the same context that the AclContext that the queue will use
92  *
93  * @param[in]  queue        A valid non-zero queue object
94  * @param[out] opencl_queue Underlying OpenCL queue to be used
95  *
96  * @return Status code
97  */
98 AclStatus AclSetClQueue(AclQueue queue, cl_command_queue opencl_queue);
99 
100 /** Extract the underlying OpenCL memory object by a given Compute Library tensor object
101  *
102  * @param[in]  tensor     A valid non-zero tensor
103  * @param[out] opencl_mem Underlyig OpenCL memory object
104  *
105  * @return Status code
106  */
107 AclStatus AclGetClMem(AclTensor tensor, cl_mem *opencl_mem);
108 
109 #ifdef __cplusplus
110 }
111 #endif /* __cplusplus */
112 #endif /* ARM_COMPUTE_ACL_OPENCL_EXT_H_ */
113