aboutsummaryrefslogtreecommitdiff
path: root/src/backends/reference/workloads/RefScatterNdWorkload.cpp
blob: 4713add0e9fcc23c382cf8b8b90361ea19a86e18 (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
//
// Copyright © 2024 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include <fmt/format.h>
#include "RefScatterNdWorkload.hpp"
#include "RefWorkloadUtils.hpp"
#include "ScatterNd.hpp"
#include "Profiling.hpp"

namespace armnn
{

    RefScatterNdWorkload::RefScatterNdWorkload(const ScatterNdQueueDescriptor& descriptor, const WorkloadInfo& info)
        : RefBaseWorkload(descriptor, info)
    {}

    void RefScatterNdWorkload::Execute() const
    {
        Execute(m_Data.m_Inputs, m_Data.m_Outputs);
    }

    void RefScatterNdWorkload::ExecuteAsync(ExecutionData& executionData)
    {
        WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
        Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
    }

    void RefScatterNdWorkload::Execute(std::vector<ITensorHandle*> inputs, std::vector<ITensorHandle*> outputs) const
    {
        ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefScatterNdWorkload_Execute");

        if (m_Data.m_Parameters.m_InputEnabled)
        {
            // Getting TensorInfos for three inputs slots
            const TensorInfo& inputInfo = GetTensorInfo(inputs[0]);
            const TensorInfo& indicesInfo = GetTensorInfo(inputs[1]);
            const TensorInfo& updatesInfo = GetTensorInfo(inputs[2]);

            // Getting Decoder for input
            std::unique_ptr<Decoder<float>> inputDecoder = MakeDecoder<float>(GetTensorInfo(inputs[0]),
                                                                              inputs[0]->Map());

            // Getting Decoder for indices
            std::unique_ptr<Decoder<int>> indicesDecoder = MakeDecoder<int>(GetTensorInfo(inputs[1]),
                                                                            inputs[1]->Map());

            // Getting Decoder for updates
            std::unique_ptr<Decoder<float>> updatesDecoder = MakeDecoder<float>(GetTensorInfo(inputs[2]),
                                                                                inputs[2]->Map());

            // Getting Encoder for output
            std::unique_ptr<Encoder<float>> outputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]),
                                                                               outputs[0]->Map());

            ScatterNd(inputInfo,
                      indicesInfo,
                      updatesInfo,
                      *inputDecoder,
                      *indicesDecoder,
                      *updatesDecoder,
                      *outputEncoder,
                      m_Data.m_Parameters);
        }
        else
        {
            // Getting TensorInfos for three inputs slots
            const TensorInfo& shapeInfo = GetTensorInfo(inputs[0]);
            const TensorInfo& indicesInfo = GetTensorInfo(inputs[1]);
            const TensorInfo& updatesInfo = GetTensorInfo(inputs[2]);

            // Getting Decoder for shape
            std::unique_ptr<Decoder<int>> shapeDecoder = MakeDecoder<int>(GetTensorInfo(inputs[0]),
                                                                          inputs[0]->Map());

            // Getting Decoder for indices
            std::unique_ptr<Decoder<int>> indicesDecoder = MakeDecoder<int>(GetTensorInfo(inputs[1]),
                                                                            inputs[1]->Map());

            // Getting Decoder for updates
            std::unique_ptr<Decoder<float>> updatesDecoder = MakeDecoder<float>(GetTensorInfo(inputs[2]),
                                                                                inputs[2]->Map());

            // Getting Encoder for output
            std::unique_ptr<Encoder<float>> outputEncoder = MakeEncoder<float>(GetTensorInfo(outputs[0]),
                                                                               outputs[0]->Map());

            ScatterNd(indicesInfo,
                      updatesInfo,
                      shapeInfo,
                      *indicesDecoder,
                      *updatesDecoder,
                      *shapeDecoder,
                      *outputEncoder,
                      m_Data.m_Parameters);
        }
    }

} // namespace armnn