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 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 7 | #include <armnn/MemorySources.hpp> |
| 8 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 9 | namespace armnn |
| 10 | { |
| 11 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 12 | class TensorShape; |
| 13 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | class ITensorHandle |
| 15 | { |
| 16 | public: |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | virtual ~ITensorHandle(){} |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 18 | |
| 19 | /// Indicate to the memory manager that this resource is active. |
| 20 | /// This is used to compute overlapping lifetimes of resources. |
| 21 | virtual void Manage() = 0; |
| 22 | |
| 23 | /// Indicate to the memory manager that this resource is no longer active. |
| 24 | /// This is used to compute overlapping lifetimes of resources. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | virtual void Allocate() = 0; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 26 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | /// Get the parent tensor if this is a subtensor. |
| 28 | /// \return a pointer to the parent tensor. Otherwise nullptr if not a subtensor. |
| 29 | virtual ITensorHandle* GetParent() const = 0; |
| 30 | |
| 31 | /// Map the tensor data for access. |
| 32 | /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent) |
| 33 | /// \return pointer to the first element of the mapped data. |
| 34 | virtual const void* Map(bool blocking=true) const = 0; |
| 35 | |
| 36 | /// Unmap the tensor data |
| 37 | virtual void Unmap() const = 0; |
| 38 | |
| 39 | /// Map the tensor data for access. Must be paired with call to Unmap(). |
| 40 | /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent) |
| 41 | /// \return pointer to the first element of the mapped data. |
| 42 | void* Map(bool blocking=true) |
| 43 | { |
| 44 | return const_cast<void*>(static_cast<const ITensorHandle*>(this)->Map(blocking)); |
| 45 | } |
| 46 | |
| 47 | /// Unmap the tensor data that was previously mapped with call to Map(). |
| 48 | void Unmap() |
| 49 | { |
| 50 | return static_cast<const ITensorHandle*>(this)->Unmap(); |
| 51 | } |
| 52 | |
| 53 | /// Get the strides for each dimension ordered from largest to smallest where |
| 54 | /// the smallest value is the same as the size of a single element in the tensor. |
| 55 | /// \return a TensorShape filled with the strides for each dimension |
| 56 | virtual TensorShape GetStrides() const = 0; |
| 57 | |
David Beck | 09e2f27 | 2018-10-30 11:38:41 +0000 | [diff] [blame] | 58 | /// Get the number of elements for each dimension ordered from slowest iterating dimension |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 59 | /// to fastest iterating dimension. |
| 60 | /// \return a TensorShape filled with the number of elements for each dimension. |
| 61 | virtual TensorShape GetShape() const = 0; |
David Beck | 09e2f27 | 2018-10-30 11:38:41 +0000 | [diff] [blame] | 62 | |
| 63 | // Testing support to be able to verify and set tensor data content |
| 64 | virtual void CopyOutTo(void* memory) const = 0; |
| 65 | virtual void CopyInFrom(const void* memory) = 0; |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 66 | |
| 67 | /// Get flags describing supported import sources. |
| 68 | virtual unsigned int GetImportFlags() const { return 0; } |
| 69 | |
| 70 | /// Import externally allocated memory |
| 71 | /// \param memory base address of the memory being imported. |
| 72 | /// \param source source of the allocation for the memory being imported. |
| 73 | /// \return true on success or false on failure |
| 74 | virtual bool Import(void* memory, MemorySource source) { return false; }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } |