From c3c352e60050f3deacad767e429a88dc24b31af0 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 18 Mar 2021 10:59:40 +0000 Subject: Add Queue support Queues are responsible for scheduling operators and performing other runtime related activities like for example tuning. Signed-off-by: Georgios Pinitas Change-Id: I0366d9048470d277b8cbf59fa42f95c0ae57c5c9 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5487 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Reviewed-by: Michalis Spyrou Comments-Addressed: Arm Jenkins --- arm_compute/Acl.hpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 8 deletions(-) (limited to 'arm_compute/Acl.hpp') diff --git a/arm_compute/Acl.hpp b/arm_compute/Acl.hpp index 01f7179c2f..93ac2d8ed9 100644 --- a/arm_compute/Acl.hpp +++ b/arm_compute/Acl.hpp @@ -42,6 +42,7 @@ namespace acl { // Forward declarations class Context; +class Queue; class Tensor; class TensorPack; @@ -83,6 +84,7 @@ struct ObjectDeleter }; OBJECT_DELETER(AclContext, AclDestroyContext) +OBJECT_DELETER(AclQueue, AclDestroyQueue) OBJECT_DELETER(AclTensor, AclDestroyTensor) OBJECT_DELETER(AclTensorPack, AclDestroyTensorPack) @@ -384,7 +386,7 @@ public: AclContext ctx; const auto st = detail::as_enum(AclCreateContext(&ctx, detail::as_cenum(target), &options.copts)); reset(ctx); - report_status(st, "[Arm Compute Library] Failed to create context"); + report_status(st, "[Compute Library] Failed to create context"); if(status) { *status = st; @@ -392,6 +394,92 @@ public: } }; +/**< Available tuning modes */ +enum class TuningMode +{ + Rapid = AclRapid, + Normal = AclNormal, + Exhaustive = AclExhaustive +}; + +/** Queue class + * + * Queue is responsible for the execution related aspects, with main responsibilities those of + * scheduling and tuning operators. + * + * Multiple queues can be created from the same context, and the same operator can be scheduled on each concurrently. + * + * @note An operator might depend on the maximum possible compute units that are provided in the context, + * thus in cases where the number of the scheduling units of the queue are greater might lead to errors. + */ +class Queue : public detail::ObjectBase +{ +public: + /**< Queue options */ + struct Options + { + /** Default Constructor + * + * As default options, no tuning will be performed, and the number of scheduling units will + * depends on internal device discovery functionality + */ + Options() + : opts{ AclTuningModeNone, 0 } {}; + /** Constructor + * + * @param[in] mode Tuning mode to be used + * @param[in] compute_units Number of scheduling units to be used + */ + Options(TuningMode mode, int32_t compute_units) + : opts{ detail::as_cenum(mode), compute_units } + { + } + + AclQueueOptions opts; + }; + +public: + /** Constructor + * + * @note Serves as a simpler delegate constructor + * @note As queue options, default conservative options will be used + * + * @param[in] ctx Context to create queue for + * @param[out] status Status information if requested + */ + explicit Queue(Context &ctx, StatusCode *status = nullptr) + : Queue(ctx, Options(), status) + { + } + /** Constructor + * + * @note As queue options, default conservative options will be used + * + * @param[in] ctx Context from where the queue will be created from + * @param[in] options Queue options to be used + * @param[out] status Status information if requested + */ + explicit Queue(Context &ctx, const Options &options = Options(), StatusCode *status = nullptr) + { + AclQueue queue; + const auto st = detail::as_enum(AclCreateQueue(&queue, ctx.get(), &options.opts)); + reset(queue); + report_status(st, "[Compute Library] Failed to create queue!"); + if(status) + { + *status = st; + } + } + /** Block until all the tasks of the queue have been marked as finished + * + * @return Status code + */ + StatusCode finish() + { + return detail::as_enum(AclQueueFinish(_object.get())); + } +}; + /**< Data type enumeration */ enum class DataType { @@ -519,7 +607,7 @@ public: AclTensor tensor; const auto st = detail::as_enum(AclCreateTensor(&tensor, ctx.get(), desc.get(), allocate)); reset(tensor); - report_status(st, "[Arm Compute Library] Failed to create tensor!"); + report_status(st, "[Compute Library] Failed to create tensor!"); if(status) { *status = st; @@ -533,7 +621,7 @@ public: { void *handle = nullptr; const auto st = detail::as_enum(AclMapTensor(_object.get(), &handle)); - report_status(st, "[Arm Compute Library] Failed to map the tensor and extract the tensor's backing memory!"); + report_status(st, "[Compute Library] Failed to map the tensor and extract the tensor's backing memory!"); return handle; } /** Unmaps tensor's memory @@ -545,7 +633,7 @@ public: StatusCode unmap(void *handle) { const auto st = detail::as_enum(AclUnmapTensor(_object.get(), handle)); - report_status(st, "[Arm Compute Library] Failed to unmap the tensor!"); + report_status(st, "[Compute Library] Failed to unmap the tensor!"); return st; } /** Import external memory to a given tensor object @@ -558,7 +646,7 @@ public: StatusCode import(void *handle, ImportType type) { const auto st = detail::as_enum(AclTensorImport(_object.get(), handle, detail::as_cenum(type))); - report_status(st, "[Arm Compute Library] Failed to import external memory to tensor!"); + report_status(st, "[Compute Library] Failed to import external memory to tensor!"); return st; } /** Get the size of the tensor in byte @@ -571,7 +659,7 @@ public: { uint64_t size{ 0 }; const auto st = detail::as_enum(AclGetTensorSize(_object.get(), &size)); - report_status(st, "[Arm Compute Library] Failed to get the size of the tensor"); + report_status(st, "[Compute Library] Failed to get the size of the tensor"); return size; } /** Get the descriptor of this tensor @@ -582,7 +670,7 @@ public: { AclTensorDescriptor desc; const auto st = detail::as_enum(AclGetTensorDescriptor(_object.get(), &desc)); - report_status(st, "[Arm Compute Library] Failed to get the descriptor of the tensor"); + report_status(st, "[Compute Library] Failed to get the descriptor of the tensor"); return TensorDescriptor(desc); } }; @@ -623,7 +711,7 @@ public: AclTensorPack pack; const auto st = detail::as_enum(AclCreateTensorPack(&pack, ctx.get())); reset(pack); - report_status(st, "[Arm Compute Library] Failure during tensor pack creation"); + report_status(st, "[Compute Library] Failure during tensor pack creation"); if(status) { *status = st; -- cgit v1.2.1