blob: 02f4ed6e5ab7fb11b738fc9b201736e6e9aa2710 [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:
15 enum Type
16 {
17 Cpu,
18 CL,
19 Neon
20 };
21
22 virtual ~ITensorHandle(){}
telsoa01c577f2c2018-08-31 09:22:23 +010023
24 /// Indicate to the memory manager that this resource is active.
25 /// This is used to compute overlapping lifetimes of resources.
26 virtual void Manage() = 0;
27
28 /// Indicate to the memory manager that this resource is no longer active.
29 /// This is used to compute overlapping lifetimes of resources.
telsoa014fcda012018-03-09 14:13:49 +000030 virtual void Allocate() = 0;
telsoa01c577f2c2018-08-31 09:22:23 +010031
32 /// Get the type backend associated with the tensor handle.
33 /// \return Type enum
telsoa014fcda012018-03-09 14:13:49 +000034 virtual ITensorHandle::Type GetType() const = 0;
telsoa01c577f2c2018-08-31 09:22:23 +010035
36 /// Get the parent tensor if this is a subtensor.
37 /// \return a pointer to the parent tensor. Otherwise nullptr if not a subtensor.
38 virtual ITensorHandle* GetParent() const = 0;
39
40 /// Map the tensor data for access.
41 /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent)
42 /// \return pointer to the first element of the mapped data.
43 virtual const void* Map(bool blocking=true) const = 0;
44
45 /// Unmap the tensor data
46 virtual void Unmap() const = 0;
47
48 /// Map the tensor data for access. Must be paired with call to Unmap().
49 /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent)
50 /// \return pointer to the first element of the mapped data.
51 void* Map(bool blocking=true)
52 {
53 return const_cast<void*>(static_cast<const ITensorHandle*>(this)->Map(blocking));
54 }
55
56 /// Unmap the tensor data that was previously mapped with call to Map().
57 void Unmap()
58 {
59 return static_cast<const ITensorHandle*>(this)->Unmap();
60 }
61
62 /// Get the strides for each dimension ordered from largest to smallest where
63 /// the smallest value is the same as the size of a single element in the tensor.
64 /// \return a TensorShape filled with the strides for each dimension
65 virtual TensorShape GetStrides() const = 0;
66
67 /// Get the number of elements for each dimension orderd from slowest iterating dimension
68 /// to fastest iterating dimension.
69 /// \return a TensorShape filled with the number of elements for each dimension.
70 virtual TensorShape GetShape() const = 0;
telsoa014fcda012018-03-09 14:13:49 +000071};
72
73}