IVGCVSW-2093 Add SpaceToBatchNd layer and corresponding no-op factory implementations
[platform/upstream/armnn.git] / src / backends / backendsCommon / ITensorHandle.hpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6
7 namespace armnn
8 {
9
10 class TensorShape;
11
12 class ITensorHandle
13 {
14 public:
15     enum Type
16     {
17         Cpu,
18         CL,
19         Neon
20     };
21
22     virtual ~ITensorHandle(){}
23
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.
30     virtual void Allocate() = 0;
31
32     /// Get the type backend associated with the tensor handle.
33     /// \return Type enum
34     virtual ITensorHandle::Type GetType() const = 0;
35
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;
71 };
72
73 }