aboutsummaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c')
-rw-r--r--src/c/AclContext.cpp122
-rw-r--r--src/c/AclOperator.cpp65
-rw-r--r--src/c/AclQueue.cpp99
-rw-r--r--src/c/AclTensor.cpp190
-rw-r--r--src/c/AclTensorPack.cpp107
-rw-r--r--src/c/AclVersion.cpp41
-rw-r--r--src/c/cl/AclOpenClExt.cpp186
-rw-r--r--src/c/operators/AclActivation.cpp49
8 files changed, 859 insertions, 0 deletions
diff --git a/src/c/AclContext.cpp b/src/c/AclContext.cpp
new file mode 100644
index 0000000000..c6c0820c92
--- /dev/null
+++ b/src/c/AclContext.cpp
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2021,2023 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclEntrypoints.h"
+#include "arm_compute/core/Error.h"
+
+#include "src/common/IContext.h"
+#include "src/common/utils/Macros.h"
+#include "src/common/utils/Validate.h"
+
+#ifdef ARM_COMPUTE_CPU_ENABLED
+#include "src/cpu/CpuContext.h"
+#endif /* ARM_COMPUTE_CPU_ENABLED */
+
+#ifdef ARM_COMPUTE_OPENCL_ENABLED
+#include "src/gpu/cl/ClContext.h"
+#endif /* ARM_COMPUTE_OPENCL_ENABLED */
+
+namespace
+{
+template <typename ContextType>
+arm_compute::IContext *create_backend_ctx(const AclContextOptions *options)
+{
+ return new (std::nothrow) ContextType(options);
+}
+
+bool is_target_valid(AclTarget target)
+{
+ return arm_compute::utils::is_in(target, {AclCpu, AclGpuOcl});
+}
+
+bool are_context_options_valid(const AclContextOptions *options)
+{
+ ARM_COMPUTE_ASSERT_NOT_NULLPTR(options);
+ return arm_compute::utils::is_in(options->mode, {AclPreferFastRerun, AclPreferFastStart});
+}
+
+arm_compute::IContext *create_context(AclTarget target, const AclContextOptions *options)
+{
+ ARM_COMPUTE_UNUSED(options);
+
+ switch (target)
+ {
+#ifdef ARM_COMPUTE_CPU_ENABLED
+ case AclCpu:
+ return create_backend_ctx<arm_compute::cpu::CpuContext>(options);
+#endif /* ARM_COMPUTE_CPU_ENABLED */
+#ifdef ARM_COMPUTE_OPENCL_ENABLED
+ case AclGpuOcl:
+ return create_backend_ctx<arm_compute::gpu::opencl::ClContext>(options);
+#endif /* ARM_COMPUTE_OPENCL_ENABLED */
+ default:
+ return nullptr;
+ }
+ return nullptr;
+}
+} // namespace
+
+extern "C" AclStatus AclCreateContext(AclContext *external_ctx, AclTarget target, const AclContextOptions *options)
+{
+ if (!is_target_valid(target))
+ {
+ ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL("Target is invalid!");
+ return AclUnsupportedTarget;
+ }
+
+ if (options != nullptr && !are_context_options_valid(options))
+ {
+ ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL("Context options are invalid!");
+ return AclInvalidArgument;
+ }
+
+ auto ctx = create_context(target, options);
+ if (ctx == nullptr)
+ {
+ ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL("Couldn't allocate internal resources for context creation!");
+ return AclOutOfMemory;
+ }
+ *external_ctx = ctx;
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclDestroyContext(AclContext external_ctx)
+{
+ using namespace arm_compute;
+
+ IContext *ctx = get_internal(external_ctx);
+
+ StatusCode status = detail::validate_internal_context(ctx);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ if (ctx->refcount() != 0)
+ {
+ ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL("Context has references on it that haven't been released!");
+ // TODO: Fix the refcount with callback when reaches 0
+ }
+
+ delete ctx;
+
+ return utils::as_cenum<AclStatus>(status);
+}
diff --git a/src/c/AclOperator.cpp b/src/c/AclOperator.cpp
new file mode 100644
index 0000000000..992cee1d11
--- /dev/null
+++ b/src/c/AclOperator.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclEntrypoints.h"
+
+#include "src/common/IOperator.h"
+#include "src/common/IQueue.h"
+#include "src/common/TensorPack.h"
+#include "src/common/utils/Macros.h"
+
+extern "C" AclStatus AclRunOperator(AclOperator external_op, AclQueue external_queue, AclTensorPack external_tensors)
+{
+ using namespace arm_compute;
+
+ auto op = get_internal(external_op);
+ auto queue = get_internal(external_queue);
+ auto pack = get_internal(external_tensors);
+
+ StatusCode status = StatusCode::Success;
+ status = detail::validate_internal_operator(op);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+ status = detail::validate_internal_queue(queue);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+ status = detail::validate_internal_pack(pack);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ status = op->run(*queue, pack->get_tensor_pack());
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclDestroyOperator(AclOperator external_op)
+{
+ using namespace arm_compute;
+
+ auto op = get_internal(external_op);
+
+ StatusCode status = detail::validate_internal_operator(op);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ delete op;
+
+ return AclSuccess;
+}
diff --git a/src/c/AclQueue.cpp b/src/c/AclQueue.cpp
new file mode 100644
index 0000000000..c3e867bffc
--- /dev/null
+++ b/src/c/AclQueue.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclEntrypoints.h"
+
+#include "src/common/IQueue.h"
+#include "src/common/utils/Macros.h"
+#include "src/common/utils/Validate.h"
+
+namespace
+{
+/** Check if queue options are valid
+ *
+ * @param[in] options Queue options
+ *
+ * @return true in case of success else false
+ */
+bool is_mode_valid(const AclQueueOptions *options)
+{
+ ARM_COMPUTE_ASSERT_NOT_NULLPTR(options);
+ return arm_compute::utils::is_in(options->mode, {AclTuningModeNone, AclRapid, AclNormal, AclExhaustive});
+}
+} // namespace
+
+extern "C" AclStatus AclCreateQueue(AclQueue *external_queue, AclContext external_ctx, const AclQueueOptions *options)
+{
+ using namespace arm_compute;
+
+ auto ctx = get_internal(external_ctx);
+
+ StatusCode status = detail::validate_internal_context(ctx);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ if (options != nullptr && !is_mode_valid(options))
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("Queue options are invalid");
+ return AclInvalidArgument;
+ }
+
+ auto queue = ctx->create_queue(options);
+ if (queue == nullptr)
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("Couldn't allocate internal resources");
+ return AclOutOfMemory;
+ }
+
+ *external_queue = queue;
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclQueueFinish(AclQueue external_queue)
+{
+ using namespace arm_compute;
+
+ auto queue = get_internal(external_queue);
+
+ StatusCode status = detail::validate_internal_queue(queue);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ status = queue->finish();
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclDestroyQueue(AclQueue external_queue)
+{
+ using namespace arm_compute;
+
+ auto queue = get_internal(external_queue);
+
+ StatusCode status = detail::validate_internal_queue(queue);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ delete queue;
+
+ return AclSuccess;
+}
diff --git a/src/c/AclTensor.cpp b/src/c/AclTensor.cpp
new file mode 100644
index 0000000000..c4cd08ac70
--- /dev/null
+++ b/src/c/AclTensor.cpp
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2021,2023 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclEntrypoints.h"
+#include "arm_compute/AclUtils.h"
+#include "arm_compute/core/Error.h"
+
+#include "src/common/ITensorV2.h"
+#include "src/common/utils/Macros.h"
+
+namespace
+{
+using namespace arm_compute;
+/**< Maximum allowed dimensions by Compute Library */
+constexpr int32_t max_allowed_dims = 6;
+
+/** Check if a descriptor is valid
+ *
+ * @param desc Descriptor to validate
+ *
+ * @return true in case of success else false
+ */
+bool is_desc_valid(const AclTensorDescriptor &desc)
+{
+ if (desc.data_type > AclFloat32 || desc.data_type <= AclDataTypeUnknown)
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("[AclCreateTensor]: Unknown data type!");
+ return false;
+ }
+ if (desc.ndims > max_allowed_dims)
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("[AclCreateTensor]: Dimensions surpass the maximum allowed value!");
+ return false;
+ }
+ if (desc.ndims > 0 && desc.shape == nullptr)
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("[AclCreateTensor]: Dimensions values are empty while dimensionality is > 0!");
+ return false;
+ }
+ return true;
+}
+
+StatusCode convert_and_validate_tensor(AclTensor tensor, ITensorV2 **internal_tensor)
+{
+ *internal_tensor = get_internal(tensor);
+ return detail::validate_internal_tensor(*internal_tensor);
+}
+} // namespace
+
+extern "C" AclStatus
+AclCreateTensor(AclTensor *external_tensor, AclContext external_ctx, const AclTensorDescriptor *desc, bool allocate)
+{
+ using namespace arm_compute;
+
+ IContext *ctx = get_internal(external_ctx);
+
+ StatusCode status = detail::validate_internal_context(ctx);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ if (desc == nullptr || !is_desc_valid(*desc))
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("[AclCreateTensor]: Descriptor is invalid!");
+ return AclInvalidArgument;
+ }
+
+ auto tensor = ctx->create_tensor(*desc, allocate);
+ if (tensor == nullptr)
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("[AclCreateTensor]: Couldn't allocate internal resources for tensor creation!");
+ return AclOutOfMemory;
+ }
+ *external_tensor = tensor;
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclMapTensor(AclTensor external_tensor, void **handle)
+{
+ using namespace arm_compute;
+
+ auto tensor = get_internal(external_tensor);
+ StatusCode status = detail::validate_internal_tensor(tensor);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ if (handle == nullptr)
+ {
+ ARM_COMPUTE_LOG_ERROR_ACL("[AclMapTensor]: Handle object is nullptr!");
+ return AclInvalidArgument;
+ }
+
+ *handle = tensor->map();
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclUnmapTensor(AclTensor external_tensor, void *handle)
+{
+ ARM_COMPUTE_UNUSED(handle);
+
+ using namespace arm_compute;
+
+ auto tensor = get_internal(external_tensor);
+ StatusCode status = detail::validate_internal_tensor(tensor);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ status = tensor->unmap();
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclTensorImport(AclTensor external_tensor, void *handle, AclImportMemoryType type)
+{
+ using namespace arm_compute;
+
+ auto tensor = get_internal(external_tensor);
+ StatusCode status = detail::validate_internal_tensor(tensor);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ status = tensor->import(handle, utils::as_enum<ImportMemoryType>(type));
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclDestroyTensor(AclTensor external_tensor)
+{
+ using namespace arm_compute;
+
+ auto tensor = get_internal(external_tensor);
+
+ StatusCode status = detail::validate_internal_tensor(tensor);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ delete tensor;
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclGetTensorSize(AclTensor tensor, uint64_t *size)
+{
+ using namespace arm_compute;
+
+ if (size == nullptr)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ ITensorV2 *internal_tensor{nullptr};
+ auto status = convert_and_validate_tensor(tensor, &internal_tensor);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ *size = internal_tensor->get_size();
+ return utils::as_cenum<AclStatus>(status);
+}
+
+extern "C" AclStatus AclGetTensorDescriptor(AclTensor tensor, AclTensorDescriptor *desc)
+{
+ using namespace arm_compute;
+
+ if (desc == nullptr)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ ITensorV2 *internal_tensor{nullptr};
+ const auto status = convert_and_validate_tensor(tensor, &internal_tensor);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ *desc = internal_tensor->get_descriptor();
+ return utils::as_cenum<AclStatus>(status);
+}
diff --git a/src/c/AclTensorPack.cpp b/src/c/AclTensorPack.cpp
new file mode 100644
index 0000000000..daf1be4f44
--- /dev/null
+++ b/src/c/AclTensorPack.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclEntrypoints.h"
+
+#include "src/common/ITensorV2.h"
+#include "src/common/TensorPack.h"
+#include "src/common/utils/Macros.h"
+
+namespace
+{
+using namespace arm_compute;
+StatusCode PackTensorInternal(TensorPack &pack, AclTensor external_tensor, int32_t slot_id)
+{
+ auto status = StatusCode::Success;
+ auto tensor = get_internal(external_tensor);
+
+ status = detail::validate_internal_tensor(tensor);
+
+ if (status != StatusCode::Success)
+ {
+ return status;
+ }
+
+ pack.add_tensor(tensor, slot_id);
+
+ return status;
+}
+} // namespace
+
+extern "C" AclStatus AclCreateTensorPack(AclTensorPack *external_pack, AclContext external_ctx)
+{
+ using namespace arm_compute;
+
+ IContext *ctx = get_internal(external_ctx);
+
+ const StatusCode status = detail::validate_internal_context(ctx);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ auto pack = new TensorPack(ctx);
+ if (pack == nullptr)
+ {
+ ARM_COMPUTE_LOG_ERROR_WITH_FUNCNAME_ACL("Couldn't allocate internal resources!");
+ return AclOutOfMemory;
+ }
+ *external_pack = pack;
+
+ return AclSuccess;
+}
+
+extern "C" AclStatus AclPackTensor(AclTensorPack external_pack, AclTensor external_tensor, int32_t slot_id)
+{
+ using namespace arm_compute;
+
+ auto pack = get_internal(external_pack);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(detail::validate_internal_pack(pack));
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(PackTensorInternal(*pack, external_tensor, slot_id));
+ return AclStatus::AclSuccess;
+}
+
+extern "C" AclStatus
+AclPackTensors(AclTensorPack external_pack, AclTensor *external_tensors, int32_t *slot_ids, size_t num_tensors)
+{
+ using namespace arm_compute;
+
+ auto pack = get_internal(external_pack);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(detail::validate_internal_pack(pack));
+
+ for (unsigned i = 0; i < num_tensors; ++i)
+ {
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(PackTensorInternal(*pack, external_tensors[i], slot_ids[i]));
+ }
+ return AclStatus::AclSuccess;
+}
+
+extern "C" AclStatus AclDestroyTensorPack(AclTensorPack external_pack)
+{
+ using namespace arm_compute;
+
+ auto pack = get_internal(external_pack);
+ StatusCode status = detail::validate_internal_pack(pack);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ delete pack;
+
+ return AclSuccess;
+}
diff --git a/src/c/AclVersion.cpp b/src/c/AclVersion.cpp
new file mode 100644
index 0000000000..a659e90837
--- /dev/null
+++ b/src/c/AclVersion.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclVersion.h"
+
+namespace
+{
+constexpr AclVersion version_info{
+ ARM_COMPUTE_LIBRARY_VERSION_MAJOR,
+ ARM_COMPUTE_LIBRARY_VERSION_MINOR,
+ ARM_COMPUTE_LIBRARY_VERSION_PATCH,
+#ifndef DOXYGEN_SKIP_THIS
+#include "arm_compute_version.embed"
+#endif /* DOXYGEN_SKIP_THIS */
+};
+} // namespace
+
+extern "C" const AclVersion *AclVersionInfo()
+{
+ return &version_info;
+}
diff --git a/src/c/cl/AclOpenClExt.cpp b/src/c/cl/AclOpenClExt.cpp
new file mode 100644
index 0000000000..8e42cf5510
--- /dev/null
+++ b/src/c/cl/AclOpenClExt.cpp
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclOpenClExt.h"
+
+#include "arm_compute/core/CL/ICLTensor.h"
+
+#include "src/common/ITensorV2.h"
+#include "src/common/Types.h"
+#include "src/gpu/cl/ClContext.h"
+#include "src/gpu/cl/ClQueue.h"
+#include "support/Cast.h"
+
+extern "C" AclStatus AclGetClContext(AclContext external_ctx, cl_context *opencl_context)
+{
+ using namespace arm_compute;
+ IContext *ctx = get_internal(external_ctx);
+
+ if (detail::validate_internal_context(ctx) != StatusCode::Success)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ if (ctx->type() != Target::GpuOcl)
+ {
+ return AclStatus::AclInvalidTarget;
+ }
+
+ if (opencl_context == nullptr)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ *opencl_context = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClContext *>(ctx)->cl_ctx().get();
+
+ return AclStatus::AclSuccess;
+}
+
+extern "C" AclStatus AclSetClContext(AclContext external_ctx, cl_context opencl_context)
+{
+ using namespace arm_compute;
+ IContext *ctx = get_internal(external_ctx);
+
+ if (detail::validate_internal_context(ctx) != StatusCode::Success)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ if (ctx->type() != Target::GpuOcl)
+ {
+ return AclStatus::AclInvalidTarget;
+ }
+
+ if (ctx->refcount() != 0)
+ {
+ return AclStatus::AclUnsupportedConfig;
+ }
+
+ auto cl_ctx = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClContext *>(ctx);
+ if (!cl_ctx->set_cl_ctx(::cl::Context(opencl_context)))
+ {
+ return AclStatus::AclRuntimeError;
+ }
+
+ return AclStatus::AclSuccess;
+}
+
+extern "C" AclStatus AclGetClDevice(AclContext external_ctx, cl_device_id *opencl_device)
+{
+ using namespace arm_compute;
+ IContext *ctx = get_internal(external_ctx);
+
+ if (detail::validate_internal_context(ctx) != StatusCode::Success)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ if (ctx->type() != Target::GpuOcl)
+ {
+ return AclStatus::AclInvalidTarget;
+ }
+
+ if (opencl_device == nullptr)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ *opencl_device = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClContext *>(ctx)->cl_dev().get();
+
+ return AclStatus::AclSuccess;
+}
+
+extern "C" AclStatus AclGetClQueue(AclQueue external_queue, cl_command_queue *opencl_queue)
+{
+ using namespace arm_compute;
+ IQueue *queue = get_internal(external_queue);
+
+ if (detail::validate_internal_queue(queue) != StatusCode::Success)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ if (queue->header.ctx->type() != Target::GpuOcl)
+ {
+ return AclStatus::AclInvalidTarget;
+ }
+
+ if (opencl_queue == nullptr)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ *opencl_queue = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClQueue *>(queue)->cl_queue().get();
+
+ return AclStatus::AclSuccess;
+}
+
+extern "C" AclStatus AclSetClQueue(AclQueue external_queue, cl_command_queue opencl_queue)
+{
+ using namespace arm_compute;
+ IQueue *queue = get_internal(external_queue);
+
+ if (detail::validate_internal_queue(queue) != StatusCode::Success)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ if (queue->header.ctx->type() != Target::GpuOcl)
+ {
+ return AclStatus::AclInvalidTarget;
+ }
+
+ auto cl_queue = utils::cast::polymorphic_downcast<arm_compute::gpu::opencl::ClQueue *>(queue);
+ if (!cl_queue->set_cl_queue(::cl::CommandQueue(opencl_queue)))
+ {
+ return AclStatus::AclRuntimeError;
+ }
+
+ return AclStatus::AclSuccess;
+}
+
+extern "C" AclStatus AclGetClMem(AclTensor external_tensor, cl_mem *opencl_mem)
+{
+ using namespace arm_compute;
+ ITensorV2 *tensor = get_internal(external_tensor);
+
+ if (detail::validate_internal_tensor(tensor) != StatusCode::Success)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ if (tensor->header.ctx->type() != Target::GpuOcl)
+ {
+ return AclStatus::AclInvalidTarget;
+ }
+
+ if (opencl_mem == nullptr)
+ {
+ return AclStatus::AclInvalidArgument;
+ }
+
+ auto cl_tensor = utils::cast::polymorphic_downcast<arm_compute::ICLTensor *>(tensor->tensor());
+ *opencl_mem = cl_tensor->cl_buffer().get();
+
+ return AclStatus::AclSuccess;
+}
diff --git a/src/c/operators/AclActivation.cpp b/src/c/operators/AclActivation.cpp
new file mode 100644
index 0000000000..bf604ee2dd
--- /dev/null
+++ b/src/c/operators/AclActivation.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2021 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/AclOperators.h"
+
+#include "src/common/IOperator.h"
+#include "src/common/utils/Macros.h"
+#include "src/common/utils/Validate.h"
+
+extern "C" AclStatus AclActivation(AclOperator *external_op,
+ AclContext external_ctx,
+ const AclTensorDescriptor *src,
+ const AclTensorDescriptor *dst,
+ const AclActivationDescriptor info)
+{
+ using namespace arm_compute;
+
+ // Extract internal context
+ auto ctx = get_internal(external_ctx);
+ StatusCode status = detail::validate_internal_context(ctx);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ bool is_validate = (external_op == ARM_COMPUTE_VALIDATE_OPERATOR_SUPPORT);
+
+ std::tie(*external_op, status) = ctx->create_activation(*src, *dst, info, is_validate);
+ ARM_COMPUTE_RETURN_CENUM_ON_FAILURE(status);
+
+ return AclSuccess;
+} \ No newline at end of file