blob: 176b021d76d6dbf0821a753d3a520085c26519b7 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
7namespace armnn
8{
9
telsoa01c577f2c2018-08-31 09:22:23 +010010class TensorShape;
11
telsoa014fcda012018-03-09 14:13:49 +000012class ITensorHandle
13{
14public:
telsoa014fcda012018-03-09 14:13:49 +000015 virtual ~ITensorHandle(){}
telsoa01c577f2c2018-08-31 09:22:23 +010016
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.
telsoa014fcda012018-03-09 14:13:49 +000023 virtual void Allocate() = 0;
telsoa01c577f2c2018-08-31 09:22:23 +010024
telsoa01c577f2c2018-08-31 09:22:23 +010025 /// 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 Beck09e2f272018-10-30 11:38:41 +000056 /// Get the number of elements for each dimension ordered from slowest iterating dimension
telsoa01c577f2c2018-08-31 09:22:23 +010057 /// to fastest iterating dimension.
58 /// \return a TensorShape filled with the number of elements for each dimension.
59 virtual TensorShape GetShape() const = 0;
David Beck09e2f272018-10-30 11:38:41 +000060
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;
telsoa014fcda012018-03-09 14:13:49 +000064};
65
66}