diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2020-07-31 22:21:38 +0100 |
---|---|---|
committer | Michalis Spyrou <michalis.spyrou@arm.com> | 2020-08-05 09:13:13 +0000 |
commit | 0499dff9293a86d3d53f72fed0a38b2823563674 (patch) | |
tree | bb76735e53f46cc8e362a7b528e549cdc7a2e346 /arm_compute/core/ITensorPack.h | |
parent | ac4c03042d7a3020f87cea641e69aa38a684ddd7 (diff) | |
download | ComputeLibrary-0499dff9293a86d3d53f72fed0a38b2823563674.tar.gz |
COMPMID-3392: Collapse TensorMaps into a single TensorPack
Collapse InputTensorMap and OutputTensorMap to a single TensorPack
mechanism.
Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com>
Change-Id: Ie2fdfc6b07d84ad589169ec99ca64fcf45a00bec
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/c/VisualCompute/ComputeLibrary/+/253783
Tested-by: bsgcomp <bsgcomp@arm.com>
Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com>
Signed-off-by: Michalis Spyrou <michalis.spyrou@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3641
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: SiCong Li <sicong.li@arm.com>
Reviewed-by: Sheri Zhang <sheri.zhang@arm.com>
Diffstat (limited to 'arm_compute/core/ITensorPack.h')
-rw-r--r-- | arm_compute/core/ITensorPack.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/arm_compute/core/ITensorPack.h b/arm_compute/core/ITensorPack.h new file mode 100644 index 0000000000..36b6aea490 --- /dev/null +++ b/arm_compute/core/ITensorPack.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2020 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. + */ +#ifndef ARM_COMPUTE_ITENSORPACK_H +#define ARM_COMPUTE_ITENSORPACK_H + +#include <cstdint> +#include <map> + +namespace arm_compute +{ +// Forward declaration +class ITensor; + +/** Tensor packing service */ +class ITensorPack +{ +private: + struct PackElement + { + PackElement() = default; + PackElement(ITensor *tensor) + : tensor(tensor), ctensor(nullptr) + { + } + PackElement(const ITensor *ctensor) + : tensor(nullptr), ctensor(ctensor) + { + } + + ITensor *tensor{ nullptr }; + const ITensor *ctensor{ nullptr }; + }; + +public: + /** Default Constructor */ + ITensorPack() = default; + /** Add tensor to the pack + * + * @param[in] id ID/type of the tensor to add + * @param[in] tensor Tensor to add + */ + void add_tensor(int id, ITensor *tensor); + + /** Add const tensor to the pack + * + * @param[in] id ID/type of the tensor to add + * @param[in] tensor Tensor to add + */ + void add_tensor(int id, const ITensor *tensor); + /** Get tensor of a given id from the pac + * + * @param[in] id ID of tensor to extract + * + * @return The pointer to the tensor if exist and is non-const else nullptr + */ + ITensor *get_tensor(int id); + /** Get constant tensor of a given id + * + * @param[in] id ID of tensor to extract + * + * @return The pointer to the tensor if exist and is const else nullptr + */ + const ITensor *get_const_tensor(int id) const; + /** Pack size accessor + * + * @return Number of tensors registered to the pack + */ + size_t size() const; + /** Checks if pack is empty + * + * @return True if empty else false + */ + bool empty() const; + +private: + std::map<unsigned int, PackElement> _pack{}; /**< Container with the packed tensors */ +}; +} // namespace arm_compute +#endif /*ARM_COMPUTE_ITENSORPACK_H */ |