Compute Library
 21.08
AclOpenClExt.h File Reference
#include "arm_compute/AclTypes.h"
#include "include/CL/cl.h"

Go to the source code of this file.

Macros

#define CL_TARGET_OPENCL_VERSION   200
 
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
 
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
 

Functions

AclStatus AclGetClContext (AclContext ctx, cl_context *opencl_context)
 Extract the underlying OpenCL context used by a given Compute Library context object. More...
 
AclStatus AclGetClDevice (AclContext ctx, cl_device_id *opencl_device)
 Extract the underlying OpenCL device id used by a given Compute Library context object. More...
 
AclStatus AclSetClContext (AclContext ctx, cl_context opencl_context)
 Set the underlying OpenCL context to be used by a given Compute Library context object. More...
 
AclStatus AclGetClQueue (AclQueue queue, cl_command_queue *opencl_queue)
 Extract the underlying OpenCL queue used by a given Compute Library queue object. More...
 
AclStatus AclSetClQueue (AclQueue queue, cl_command_queue opencl_queue)
 Set the underlying OpenCL queue to be used by a given Compute Library queue object. More...
 
AclStatus AclGetClMem (AclTensor tensor, cl_mem *opencl_mem)
 Extract the underlying OpenCL memory object by a given Compute Library tensor object. More...
 

Macro Definition Documentation

◆ CL_TARGET_OPENCL_VERSION

#define CL_TARGET_OPENCL_VERSION   200

Definition at line 30 of file AclOpenClExt.h.

◆ CL_USE_DEPRECATED_OPENCL_1_1_APIS

#define CL_USE_DEPRECATED_OPENCL_1_1_APIS

Definition at line 31 of file AclOpenClExt.h.

◆ CL_USE_DEPRECATED_OPENCL_1_2_APIS

#define CL_USE_DEPRECATED_OPENCL_1_2_APIS

Definition at line 32 of file AclOpenClExt.h.

Function Documentation

◆ AclGetClContext()

AclStatus AclGetClContext ( AclContext  ctx,
cl_context *  opencl_context 
)

Extract the underlying OpenCL context used by a given Compute Library context object.

Note
AclContext should be of an OpenCL backend target
Parameters
[in]ctxA valid non-zero context
[out]opencl_contextUnderlying OpenCL context used
Returns
Status code

Definition at line 35 of file AclOpenClExt.cpp.

References AclInvalidArgument, AclInvalidTarget, AclSuccess, arm_compute::get_internal(), arm_compute::GpuOcl, arm_compute::Success, IContext::type(), and arm_compute::detail::validate_internal_context().

Referenced by arm_compute::test::validation::TEST_CASE().

36 {
37  using namespace arm_compute;
38  IContext *ctx = get_internal(external_ctx);
39 
41  {
43  }
44 
45  if(ctx->type() != Target::GpuOcl)
46  {
48  }
49 
50  if(opencl_context == nullptr)
51  {
53  }
54 
55  *opencl_context = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClContext *>(ctx)->cl_ctx().get();
56 
57  return AclStatus::AclSuccess;
58 }
Call failed as invalid argument was passed.
Definition: AclTypes.h:56
StatusCode validate_internal_context(const IContext *ctx)
Check if an internal context is valid.
Definition: IContext.h:140
Context interface.
Definition: IContext.h:50
Copyright (c) 2017-2021 Arm Limited.
Call failed as invalid argument was passed.
Definition: AclTypes.h:57
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
Target type() const
Target type accessor.
Definition: IContext.h:66
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127

◆ AclGetClDevice()

AclStatus AclGetClDevice ( AclContext  ctx,
cl_device_id *  opencl_device 
)

Extract the underlying OpenCL device id used by a given Compute Library context object.

Note
AclContext should be of an OpenCL backend target
Parameters
[in]ctxA valid non-zero context
[out]opencl_deviceUnderlying OpenCL device used
Returns
Status code

Definition at line 89 of file AclOpenClExt.cpp.

References AclInvalidArgument, AclInvalidTarget, AclSuccess, arm_compute::get_internal(), arm_compute::GpuOcl, arm_compute::Success, IContext::type(), and arm_compute::detail::validate_internal_context().

Referenced by arm_compute::test::validation::TEST_CASE().

90 {
91  using namespace arm_compute;
92  IContext *ctx = get_internal(external_ctx);
93 
95  {
97  }
98 
99  if(ctx->type() != Target::GpuOcl)
100  {
102  }
103 
104  if(opencl_device == nullptr)
105  {
107  }
108 
109  *opencl_device = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClContext *>(ctx)->cl_dev().get();
110 
111  return AclStatus::AclSuccess;
112 }
Call failed as invalid argument was passed.
Definition: AclTypes.h:56
StatusCode validate_internal_context(const IContext *ctx)
Check if an internal context is valid.
Definition: IContext.h:140
Context interface.
Definition: IContext.h:50
Copyright (c) 2017-2021 Arm Limited.
Call failed as invalid argument was passed.
Definition: AclTypes.h:57
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
Target type() const
Target type accessor.
Definition: IContext.h:66
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127

◆ AclGetClMem()

AclStatus AclGetClMem ( AclTensor  tensor,
cl_mem *  opencl_mem 
)

Extract the underlying OpenCL memory object by a given Compute Library tensor object.

Parameters
[in]tensorA valid non-zero tensor
[out]opencl_memUnderlyig OpenCL memory object
Returns
Status code

Definition at line 163 of file AclOpenClExt.cpp.

References AclInvalidArgument, AclInvalidTarget, AclSuccess, Header::ctx, arm_compute::get_internal(), arm_compute::GpuOcl, AclTensor_::header, arm_compute::Success, ITensorV2::tensor(), IContext::type(), and arm_compute::detail::validate_internal_tensor().

164 {
165  using namespace arm_compute;
166  ITensorV2 *tensor = get_internal(external_tensor);
167 
169  {
171  }
172 
173  if(tensor->header.ctx->type() != Target::GpuOcl)
174  {
176  }
177 
178  if(opencl_mem == nullptr)
179  {
181  }
182 
183  auto cl_tensor = utils::cast::polymorphic_downcast<arm_compute::ICLTensor *>(tensor->tensor());
184  *opencl_mem = cl_tensor->cl_buffer().get();
185 
186  return AclStatus::AclSuccess;
187 }
Base class specifying the tensor interface.
Definition: ITensorV2.h:45
Call failed as invalid argument was passed.
Definition: AclTypes.h:56
StatusCode validate_internal_tensor(const ITensorV2 *tensor)
Check if an internal tensor is valid.
Definition: ITensorV2.h:129
Copyright (c) 2017-2021 Arm Limited.
Call failed as invalid argument was passed.
Definition: AclTypes.h:57
arm_compute::detail::Header header
Definition: ITensorV2.h:32
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
Target type() const
Target type accessor.
Definition: IContext.h:66
virtual arm_compute::ITensor * tensor() const =0
Get the legacy tensor object.
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127

◆ AclGetClQueue()

AclStatus AclGetClQueue ( AclQueue  queue,
cl_command_queue *  opencl_queue 
)

Extract the underlying OpenCL queue used by a given Compute Library queue object.

Note
AclQueue should be of an OpenCL backend target
AclQueue refcount should be 0, meaning not used by other objects
Parameters
[in]queueA valid non-zero queue
[out]opencl_queueUnderlying OpenCL queue used
Returns
Status code

Definition at line 114 of file AclOpenClExt.cpp.

References AclInvalidArgument, AclInvalidTarget, AclSuccess, Header::ctx, arm_compute::get_internal(), arm_compute::GpuOcl, AclQueue_::header, arm_compute::Success, IContext::type(), and arm_compute::detail::validate_internal_queue().

115 {
116  using namespace arm_compute;
117  IQueue *queue = get_internal(external_queue);
118 
120  {
122  }
123 
124  if(queue->header.ctx->type() != Target::GpuOcl)
125  {
127  }
128 
129  if(opencl_queue == nullptr)
130  {
132  }
133 
134  *opencl_queue = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClQueue *>(queue)->cl_queue().get();
135 
136  return AclStatus::AclSuccess;
137 }
Base class specifying the queue interface.
Definition: IQueue.h:41
arm_compute::detail::Header header
Definition: IQueue.h:31
Call failed as invalid argument was passed.
Definition: AclTypes.h:56
Copyright (c) 2017-2021 Arm Limited.
Call failed as invalid argument was passed.
Definition: AclTypes.h:57
StatusCode validate_internal_queue(const IQueue *queue)
Check if an internal queue is valid.
Definition: IQueue.h:89
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
Target type() const
Target type accessor.
Definition: IContext.h:66
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127

◆ AclSetClContext()

AclStatus AclSetClContext ( AclContext  ctx,
cl_context  opencl_context 
)

Set the underlying OpenCL context to be used by a given Compute Library context object.

Note
AclContext should be of an OpenCL backend target
Parameters
[in]ctxA valid non-zero context object
[out]opencl_contextUnderlying OpenCL context to be used
Returns
Status code

Definition at line 60 of file AclOpenClExt.cpp.

References AclInvalidArgument, AclInvalidTarget, AclRuntimeError, AclSuccess, AclUnsupportedConfig, arm_compute::get_internal(), arm_compute::GpuOcl, IContext::refcount(), arm_compute::Success, IContext::type(), and arm_compute::detail::validate_internal_context().

61 {
62  using namespace arm_compute;
63  IContext *ctx = get_internal(external_ctx);
64 
66  {
68  }
69 
70  if(ctx->type() != Target::GpuOcl)
71  {
73  }
74 
75  if(ctx->refcount() != 0)
76  {
78  }
79 
80  auto cl_ctx = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClContext *>(ctx);
81  if(!cl_ctx->set_cl_ctx(::cl::Context(opencl_context)))
82  {
84  }
85 
86  return AclStatus::AclSuccess;
87 }
Call failed during execution.
Definition: AclTypes.h:52
Call failed as invalid argument was passed.
Definition: AclTypes.h:56
StatusCode validate_internal_context(const IContext *ctx)
Check if an internal context is valid.
Definition: IContext.h:140
Context interface.
Definition: IContext.h:50
Copyright (c) 2017-2021 Arm Limited.
Call failed as invalid argument was passed.
Definition: AclTypes.h:57
int refcount() const
Reference counter accessor.
Definition: IContext.h:84
Call failed as configuration is unsupported.
Definition: AclTypes.h:58
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
Target type() const
Target type accessor.
Definition: IContext.h:66
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127

◆ AclSetClQueue()

AclStatus AclSetClQueue ( AclQueue  queue,
cl_command_queue  opencl_queue 
)

Set the underlying OpenCL queue to be used by a given Compute Library queue object.

Note
AclQueue should be of an OpenCL backend target
opecl_queue needs to be created from the same context that the AclContext that the queue will use
Parameters
[in]queueA valid non-zero queue object
[out]opencl_queueUnderlying OpenCL queue to be used
Returns
Status code

Definition at line 139 of file AclOpenClExt.cpp.

References AclInvalidArgument, AclInvalidTarget, AclRuntimeError, AclSuccess, Header::ctx, arm_compute::get_internal(), arm_compute::GpuOcl, AclQueue_::header, arm_compute::Success, IContext::type(), and arm_compute::detail::validate_internal_queue().

140 {
141  using namespace arm_compute;
142  IQueue *queue = get_internal(external_queue);
143 
145  {
147  }
148 
149  if(queue->header.ctx->type() != Target::GpuOcl)
150  {
152  }
153 
154  auto cl_queue = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClQueue *>(queue);
155  if(!cl_queue->set_cl_queue(::cl::CommandQueue(opencl_queue)))
156  {
158  }
159 
160  return AclStatus::AclSuccess;
161 }
Base class specifying the queue interface.
Definition: IQueue.h:41
Call failed during execution.
Definition: AclTypes.h:52
arm_compute::detail::Header header
Definition: IQueue.h:31
Call failed as invalid argument was passed.
Definition: AclTypes.h:56
Copyright (c) 2017-2021 Arm Limited.
Call failed as invalid argument was passed.
Definition: AclTypes.h:57
StatusCode validate_internal_queue(const IQueue *queue)
Check if an internal queue is valid.
Definition: IQueue.h:89
Call succeeded, leading to valid state for all involved objects/data.
Definition: AclTypes.h:51
Target type() const
Target type accessor.
Definition: IContext.h:66
IContext * get_internal(AclContext ctx)
Extract internal representation of a Context.
Definition: IContext.h:127