aboutsummaryrefslogtreecommitdiff
path: root/src/backends/tosaCommon/TosaLayerSupportRules.hpp
blob: 8855dd612d3f1de6b97ed037ed8700cf933896e1 (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
//
// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

// List of Layer Support Rules common to TOSA backends only, for use with CheckSupportRule()

struct TosaOperatorAttributeOfAny : public Rule
{
    template<typename Container>
    explicit TosaOperatorAttributeOfAny(TosaSerializationOperator* op, const Container& c)
    {
        m_Res = std::any_of(c.begin(), c.end(), [&op](Attribute attribute)
        {
            return attribute == op->GetAttributeType();
        });
    }
};

struct TosaTypeAnyOf : public Rule
{
    template<typename Container>
    TosaTypeAnyOf(TosaSerializationTensor* tensor, const Container& c)
    {
        m_Res = std::any_of(c.begin(), c.end(), [&tensor](DType dt)
        {
            return dt == tensor->GetDtype();
        });
    }
};

struct TosaTensorNumDimensionsWithinBounds : public Rule
{
    explicit TosaTensorNumDimensionsWithinBounds(TosaSerializationTensor* tensor)
    {
        m_Res = (tensor->GetShape().size() <= MaxNumOfTensorDimensions) || (!tensor->GetShape().empty());
    }
};

struct TosaAssertSize : public Rule
{
    template<typename Container>
    explicit TosaAssertSize(const Container& c1, const Container& c2)
    {
        m_Res = (c1.size() == c2.size());
    }
};

struct TosaContainerContainsTwoTypes : public Rule
{
    explicit TosaContainerContainsTwoTypes(std::tuple<DType, DType>& check,
                                           const std::vector<std::tuple<DType, DType>>& c)
    {
        for (auto item: c)
        {
            if (std::get<0>(check) == std::get<0>(item) &&
                std::get<1>(check) == std::get<1>(item))
            {
                m_Res = true;
                return;
            }
        }
        m_Res = false;
    }
};

struct TosaContainerContainsThreeTypes : public Rule
{
    explicit TosaContainerContainsThreeTypes(std::tuple<DType, DType, DType>& check,
                                             const std::vector<std::tuple<DType, DType, DType>>& c)
    {
        for (auto item: c)
        {
            if (std::get<0>(check) == std::get<0>(item) &&
                std::get<1>(check) == std::get<1>(item) &&
                std::get<2>(check) == std::get<2>(item))
            {
                m_Res = true;
                return;
            }
        }
        m_Res = false;
    }
};