aboutsummaryrefslogtreecommitdiff
path: root/python/pyarmnn/src/pyarmnn/swig/modules/armnn_types.i
blob: 50afda9fd374354221b7105aac8a30b4f1154435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
%{
#include "armnn/Types.hpp"
%}

%include <typemaps/permutation_vector.i>


namespace armnn
{

%feature("docstring",
"
Vector used to permute a tensor.

For a 4-d tensor laid out in a memory with the format (Batch Element, Height, Width, Channels),
which is to be passed as an input to Arm NN, each source dimension is mapped to the corresponding
Arm NN dimension. The Batch dimension remains the same (0 -> 0). The source Height dimension is mapped
to the location of the ArmNN Height dimension (1 -> 2). Similar arguments are made for the Width and
Channels (2 -> 3 and 3 -> 1). This will lead to m_DimMappings pointing to the following array:
[ 0, 2, 3, 1 ].

Note that the mapping should be reversed if considering the case of Arm NN 4-d outputs (Batch Element,
Channels, Height, Width) being written to a destination with the format mentioned above. We now have
0 -> 0, 2 -> 1, 3 -> 2, 1 -> 3, which, when reordered, lead to the following m_DimMappings contents:
[ 0, 3, 1, 2 ].

Args:
    dimMappings (list): Indicates how to translate tensor elements from a given source into the target destination,
                        when source and target potentially have different memory layouts.
") PermutationVector;

class PermutationVector
{
public:
    using ValueType = unsigned int;
    using SizeType = unsigned int;

    %permutation_vector_typemap(const ValueType *dimMappings, SizeType numDimMappings);
    PermutationVector(const ValueType *dimMappings, SizeType numDimMappings);
    %clear_permutation_vector_typemap(const ValueType *dimMappings, SizeType numDimMappings);


    %feature("docstring",
    "
    Get the PermutationVector size.

    Return:
        SizeType: Current size of the PermutationVector.

    ") GetSize;
    SizeType GetSize();

    %feature("docstring",
    "
    Checks if a specified permutation vector is its inverse

    Return:
        bool: returns true if the specified Permutation vector is its inverse.

    ") IsInverse;
    bool IsInverse(const PermutationVector& other);
};

%extend PermutationVector {

    unsigned int __getitem__(unsigned int i) const {
        return $self->operator[](i);
    }

    bool __eq__(PermutationVector other) {
        int size = $self->GetSize();
        int otherSize = other.GetSize();
        if(size != otherSize)
        {
            return false;
        }
        for(int i = 0; i < size; ++i){
            if($self->operator[](i) != other[i])
            {
                return false;
            }
            return true;
        }
        return true;
    }
}

}
%feature("docstring",
"
Interface for device specifications. Main use is to get information relating to what compute capability the device being used has.
") IDeviceSpec;


%feature("docstring",
"
Returns the backends supported by this compute device.

Returns:
    set: This devices supported backends.

") GetSupportedBackends;

%ignore ProfilingGuid;
%ignore PermutationVector;
%include "armnn/Types.hpp"

%extend armnn::IDeviceSpec {


    std::string __str__() {

        std::string deviceStr = "IDeviceSpec { supportedBackends: [";

        auto bends = $self->GetSupportedBackends();
        auto sizeBends = $self->GetSupportedBackends().size();
        for (std::unordered_set<armnn::BackendId>::const_iterator p = bends.begin(); p != bends.end(); ++p) {

            deviceStr += p->Get();

            if (sizeBends - 1 > 0) {
                deviceStr += ", ";
            }
            sizeBends--;

        }
        deviceStr = deviceStr + "]}";

        return deviceStr;
    }

}