aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/c/AclTensor.cpp44
-rw-r--r--src/c/AclTensorPack.cpp2
-rw-r--r--src/c/cl/AclOpenClExt.cpp2
-rw-r--r--src/common/ITensorV2.cpp39
-rw-r--r--src/common/ITensorV2.h (renamed from src/common/ITensor.h)14
-rw-r--r--src/common/TensorPack.cpp2
-rw-r--r--src/common/utils/LegacySupport.cpp53
-rw-r--r--src/common/utils/LegacySupport.h7
-rw-r--r--src/common/utils/Utils.h4
-rw-r--r--src/cpu/CpuTensor.cpp2
-rw-r--r--src/cpu/CpuTensor.h4
-rw-r--r--src/gpu/cl/ClTensor.cpp2
-rw-r--r--src/gpu/cl/ClTensor.h4
13 files changed, 162 insertions, 17 deletions
diff --git a/src/c/AclTensor.cpp b/src/c/AclTensor.cpp
index 0d884b1ec3..8f6ce45628 100644
--- a/src/c/AclTensor.cpp
+++ b/src/c/AclTensor.cpp
@@ -22,11 +22,13 @@
* SOFTWARE.
*/
#include "arm_compute/AclEntrypoints.h"
-#include "src/common/ITensor.h"
+#include "arm_compute/AclUtils.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;
@@ -55,6 +57,12 @@ bool is_desc_valid(const AclTensorDescriptor &desc)
}
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,
@@ -146,3 +154,37 @@ extern "C" AclStatus AclDestroyTensor(AclTensor external_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);
+} \ No newline at end of file
diff --git a/src/c/AclTensorPack.cpp b/src/c/AclTensorPack.cpp
index 6700ef464c..6202524ca7 100644
--- a/src/c/AclTensorPack.cpp
+++ b/src/c/AclTensorPack.cpp
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
#include "arm_compute/AclEntrypoints.h"
-#include "src/common/ITensor.h"
+#include "src/common/ITensorV2.h"
#include "src/common/TensorPack.h"
#include "src/common/utils/Macros.h"
diff --git a/src/c/cl/AclOpenClExt.cpp b/src/c/cl/AclOpenClExt.cpp
index a144f97f55..ce6d2969de 100644
--- a/src/c/cl/AclOpenClExt.cpp
+++ b/src/c/cl/AclOpenClExt.cpp
@@ -23,7 +23,7 @@
*/
#include "arm_compute/AclOpenClExt.h"
-#include "src/common/ITensor.h"
+#include "src/common/ITensorV2.h"
#include "src/common/Types.h"
#include "src/gpu/cl/ClContext.h"
diff --git a/src/common/ITensorV2.cpp b/src/common/ITensorV2.cpp
new file mode 100644
index 0000000000..39bf1c6fb3
--- /dev/null
+++ b/src/common/ITensorV2.cpp
@@ -0,0 +1,39 @@
+/*
+ * 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 "src/common/ITensorV2.h"
+#include "arm_compute/core/TensorInfo.h"
+#include "src/common/utils/LegacySupport.h"
+
+namespace arm_compute
+{
+size_t ITensorV2::get_size() const
+{
+ return tensor()->info()->total_size();
+}
+
+AclTensorDescriptor ITensorV2::get_descriptor() const
+{
+ return detail::convert_to_descriptor(*tensor()->info());
+}
+} // namespace arm_compute \ No newline at end of file
diff --git a/src/common/ITensor.h b/src/common/ITensorV2.h
index ee7eac7688..965aacea23 100644
--- a/src/common/ITensor.h
+++ b/src/common/ITensorV2.h
@@ -92,7 +92,19 @@ public:
*
* @return The legacy underlying tensor object
*/
- virtual arm_compute::ITensor *tensor() = 0;
+ virtual arm_compute::ITensor *tensor() const = 0;
+ /** Get the size of the tensor in byte
+ *
+ * @note The size isn't based on allocated memory, but based on information in its descriptor (dimensions, data type, etc.).
+ *
+ * @return The size of the tensor in byte
+ */
+ size_t get_size() const;
+ /** Get the descriptor of this tensor
+ *
+ * @return The descriptor describing the characteristics of this tensor
+ */
+ AclTensorDescriptor get_descriptor() const;
};
/** Extract internal representation of a Tensor
diff --git a/src/common/TensorPack.cpp b/src/common/TensorPack.cpp
index c582c7b106..6c2c7f9622 100644
--- a/src/common/TensorPack.cpp
+++ b/src/common/TensorPack.cpp
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
#include "src/common/TensorPack.h"
-#include "src/common/ITensor.h"
+#include "src/common/ITensorV2.h"
#include "src/common/utils/Validate.h"
namespace arm_compute
diff --git a/src/common/utils/LegacySupport.cpp b/src/common/utils/LegacySupport.cpp
index 5981c657bd..569b2abd89 100644
--- a/src/common/utils/LegacySupport.cpp
+++ b/src/common/utils/LegacySupport.cpp
@@ -29,7 +29,7 @@ namespace detail
{
namespace
{
-DataType data_type_mapper(AclDataType data_type)
+DataType convert_to_legacy_data_type(AclDataType data_type)
{
switch(data_type)
{
@@ -41,11 +41,25 @@ DataType data_type_mapper(AclDataType data_type)
return DataType::BFLOAT16;
default:
return DataType::UNKNOWN;
- ;
}
}
-TensorShape tensor_shape_mapper(int32_t ndims, int32_t *shape)
+AclDataType convert_to_c_data_type(DataType data_type)
+{
+ switch(data_type)
+ {
+ case DataType::F32:
+ return AclDataType::AclFloat32;
+ case DataType::F16:
+ return AclDataType::AclFloat16;
+ case DataType::BFLOAT16:
+ return AclDataType::AclBFloat16;
+ default:
+ return AclDataType::AclDataTypeUnknown;
+ }
+}
+
+TensorShape create_legacy_tensor_shape(int32_t ndims, int32_t *shape)
{
TensorShape legacy_shape{};
for(int32_t d = 0; d < ndims; ++d)
@@ -54,13 +68,44 @@ TensorShape tensor_shape_mapper(int32_t ndims, int32_t *shape)
}
return legacy_shape;
}
+int32_t *create_tensor_shape_array(const TensorInfo &info)
+{
+ const auto num_dims = info.num_dimensions();
+ if(num_dims <= 0)
+ {
+ return nullptr;
+ }
+
+ int32_t *shape_array = new int32_t[num_dims];
+
+ for(size_t d = 0; d < num_dims; ++d)
+ {
+ shape_array[d] = info.tensor_shape()[d];
+ }
+
+ return shape_array;
+}
} // namespace
TensorInfo convert_to_legacy_tensor_info(const AclTensorDescriptor &desc)
{
TensorInfo legacy_desc;
- legacy_desc.init(tensor_shape_mapper(desc.ndims, desc.shape), 1, data_type_mapper(desc.data_type));
+ legacy_desc.init(create_legacy_tensor_shape(desc.ndims, desc.shape), 1, convert_to_legacy_data_type(desc.data_type));
return legacy_desc;
}
+
+AclTensorDescriptor convert_to_descriptor(const TensorInfo &info)
+{
+ const auto num_dims = info.num_dimensions();
+ AclTensorDescriptor desc
+ {
+ static_cast<int32_t>(num_dims),
+ create_tensor_shape_array(info),
+ convert_to_c_data_type(info.data_type()),
+ nullptr,
+ 0
+ };
+ return desc;
+}
} // namespace detail
} // namespace arm_compute
diff --git a/src/common/utils/LegacySupport.h b/src/common/utils/LegacySupport.h
index 37329b747c..c2cc1bc182 100644
--- a/src/common/utils/LegacySupport.h
+++ b/src/common/utils/LegacySupport.h
@@ -38,6 +38,13 @@ namespace detail
* @return Legacy tensor meta-data
*/
TensorInfo convert_to_legacy_tensor_info(const AclTensorDescriptor &desc);
+/** Convert a legacy tensor meta-data to a descriptor
+ *
+ * @param[in] info Legacy tensor meta-data
+ *
+ * @return A converted descriptor
+ */
+AclTensorDescriptor convert_to_descriptor(const TensorInfo &info);
} // namespace detail
} // namespace arm_compute
diff --git a/src/common/utils/Utils.h b/src/common/utils/Utils.h
index 87be9df509..79f4f39c47 100644
--- a/src/common/utils/Utils.h
+++ b/src/common/utils/Utils.h
@@ -40,7 +40,7 @@ namespace utils
* @return A corresponding plain old C enumeration
*/
template <typename E, typename SE>
-constexpr E as_cenum(SE v) noexcept
+constexpr E as_cenum(const SE v) noexcept
{
return static_cast<E>(static_cast<std::underlying_type_t<SE>>(v));
}
@@ -55,7 +55,7 @@ constexpr E as_cenum(SE v) noexcept
* @return A corresponding strongly typed enumeration
*/
template <typename SE, typename E>
-constexpr SE as_enum(E val) noexcept
+constexpr SE as_enum(const E val) noexcept
{
return static_cast<SE>(val);
}
diff --git a/src/cpu/CpuTensor.cpp b/src/cpu/CpuTensor.cpp
index 79dc812c58..6dd6d9c31b 100644
--- a/src/cpu/CpuTensor.cpp
+++ b/src/cpu/CpuTensor.cpp
@@ -72,7 +72,7 @@ StatusCode CpuTensor::import(void *handle, ImportMemoryType type)
return bool(st) ? StatusCode::Success : StatusCode::RuntimeError;
}
-arm_compute::ITensor *CpuTensor::tensor()
+arm_compute::ITensor *CpuTensor::tensor() const
{
return _legacy_tensor.get();
}
diff --git a/src/cpu/CpuTensor.h b/src/cpu/CpuTensor.h
index a46f1a26cb..b078774c99 100644
--- a/src/cpu/CpuTensor.h
+++ b/src/cpu/CpuTensor.h
@@ -24,7 +24,7 @@
#ifndef SRC_CPU_CPUTENSOR_H
#define SRC_CPU_CPUTENSOR_H
-#include "src/common/ITensor.h"
+#include "src/common/ITensorV2.h"
#include "arm_compute/runtime/Tensor.h"
@@ -51,7 +51,7 @@ public:
// Inherrited functions overriden
void *map() override;
StatusCode unmap() override;
- arm_compute::ITensor *tensor() override;
+ arm_compute::ITensor *tensor() const override;
StatusCode import(void *handle, ImportMemoryType type) override;
private:
diff --git a/src/gpu/cl/ClTensor.cpp b/src/gpu/cl/ClTensor.cpp
index db2081c4ed..0df07813e3 100644
--- a/src/gpu/cl/ClTensor.cpp
+++ b/src/gpu/cl/ClTensor.cpp
@@ -83,7 +83,7 @@ StatusCode ClTensor::import(void *handle, ImportMemoryType type)
return StatusCode::Success;
}
-arm_compute::ITensor *ClTensor::tensor()
+arm_compute::ITensor *ClTensor::tensor() const
{
return _legacy_tensor.get();
}
diff --git a/src/gpu/cl/ClTensor.h b/src/gpu/cl/ClTensor.h
index 4188f622d6..99d228c0b8 100644
--- a/src/gpu/cl/ClTensor.h
+++ b/src/gpu/cl/ClTensor.h
@@ -24,7 +24,7 @@
#ifndef SRC_GPU_CLTENSOR_H
#define SRC_GPU_CLTENSOR_H
-#include "src/common/ITensor.h"
+#include "src/common/ITensorV2.h"
#include "arm_compute/runtime/CL/CLTensor.h"
@@ -53,7 +53,7 @@ public:
// Inherrited functions overriden
void *map() override;
StatusCode unmap() override;
- arm_compute::ITensor *tensor() override;
+ arm_compute::ITensor *tensor() const override;
StatusCode import(void *handle, ImportMemoryType type) override;
private: