telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | namespace armnn |
| 8 | { |
| 9 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 10 | class TensorShape; |
| 11 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | class ITensorHandle |
| 13 | { |
| 14 | public: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | virtual ~ITensorHandle(){} |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 16 | |
| 17 | /// Indicate to the memory manager that this resource is active. |
| 18 | /// This is used to compute overlapping lifetimes of resources. |
| 19 | virtual void Manage() = 0; |
| 20 | |
| 21 | /// Indicate to the memory manager that this resource is no longer active. |
| 22 | /// This is used to compute overlapping lifetimes of resources. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 23 | virtual void Allocate() = 0; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 25 | /// Get the parent tensor if this is a subtensor. |
| 26 | /// \return a pointer to the parent tensor. Otherwise nullptr if not a subtensor. |
| 27 | virtual ITensorHandle* GetParent() const = 0; |
| 28 | |
| 29 | /// Map the tensor data for access. |
| 30 | /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent) |
| 31 | /// \return pointer to the first element of the mapped data. |
| 32 | virtual const void* Map(bool blocking=true) const = 0; |
| 33 | |
| 34 | /// Unmap the tensor data |
| 35 | virtual void Unmap() const = 0; |
| 36 | |
| 37 | /// Map the tensor data for access. Must be paired with call to Unmap(). |
| 38 | /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent) |
| 39 | /// \return pointer to the first element of the mapped data. |
| 40 | void* Map(bool blocking=true) |
| 41 | { |
| 42 | return const_cast<void*>(static_cast<const ITensorHandle*>(this)->Map(blocking)); |
| 43 | } |
| 44 | |
| 45 | /// Unmap the tensor data that was previously mapped with call to Map(). |
| 46 | void Unmap() |
| 47 | { |
| 48 | return static_cast<const ITensorHandle*>(this)->Unmap(); |
| 49 | } |
| 50 | |
| 51 | /// Get the strides for each dimension ordered from largest to smallest where |
| 52 | /// the smallest value is the same as the size of a single element in the tensor. |
| 53 | /// \return a TensorShape filled with the strides for each dimension |
| 54 | virtual TensorShape GetStrides() const = 0; |
| 55 | |
David Beck | 09e2f27 | 2018-10-30 11:38:41 +0000 | [diff] [blame] | 56 | /// Get the number of elements for each dimension ordered from slowest iterating dimension |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 57 | /// to fastest iterating dimension. |
| 58 | /// \return a TensorShape filled with the number of elements for each dimension. |
| 59 | virtual TensorShape GetShape() const = 0; |
David Beck | 09e2f27 | 2018-10-30 11:38:41 +0000 | [diff] [blame] | 60 | |
| 61 | // Testing support to be able to verify and set tensor data content |
| 62 | virtual void CopyOutTo(void* memory) const = 0; |
| 63 | virtual void CopyInFrom(const void* memory) = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | } |