aboutsummaryrefslogtreecommitdiff
path: root/src/backends/gpuFsa/GpuFsaWorkloadFactory.cpp
blob: 687c8c0ac8ee17da07e2f2e9d965416e81918656 (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
//
// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include <Layer.hpp>
#include <armnn/backends/MemCopyWorkload.hpp>
#include <armnn/backends/TensorHandle.hpp>
#include "GpuFsaWorkloadFactory.hpp"
#include "GpuFsaBackendId.hpp"
#include "GpuFsaTensorHandle.hpp"

namespace armnn
{

namespace
{
static const BackendId s_Id{GpuFsaBackendId()};
}
template <typename QueueDescriptorType>
std::unique_ptr<IWorkload> GpuFsaWorkloadFactory::MakeWorkload(const QueueDescriptorType& descriptor,
                                                               const WorkloadInfo& info) const
{
    IgnoreUnused(descriptor);
    IgnoreUnused(info);
    return nullptr;
}

template <DataType ArmnnType>
bool IsDataType(const WorkloadInfo& info)
{
    auto checkType = [](const TensorInfo& tensorInfo) {return tensorInfo.GetDataType() == ArmnnType;};
    auto it = std::find_if(std::begin(info.m_InputTensorInfos), std::end(info.m_InputTensorInfos), checkType);
    if (it != std::end(info.m_InputTensorInfos))
    {
        return true;
    }
    it = std::find_if(std::begin(info.m_OutputTensorInfos), std::end(info.m_OutputTensorInfos), checkType);
    if (it != std::end(info.m_OutputTensorInfos))
    {
        return true;
    }
    return false;
}

GpuFsaWorkloadFactory::GpuFsaWorkloadFactory(const std::shared_ptr<GpuFsaMemoryManager>& memoryManager)
    : m_MemoryManager(memoryManager)
{
}

GpuFsaWorkloadFactory::GpuFsaWorkloadFactory()
    : m_MemoryManager(new GpuFsaMemoryManager())
{
}

const BackendId& GpuFsaWorkloadFactory::GetBackendId() const
{
    return s_Id;
}

bool GpuFsaWorkloadFactory::IsLayerSupported(const Layer& layer,
                                             Optional<DataType> dataType,
                                             std::string& outReasonIfUnsupported)
{
    return IWorkloadFactory::IsLayerSupported(s_Id, layer, dataType, outReasonIfUnsupported);
}

bool GpuFsaWorkloadFactory::IsLayerSupported(const IConnectableLayer& layer,
                                             Optional<DataType> dataType,
                                             std::string& outReasonIfUnsupported,
                                             const ModelOptions& modelOptions)
{
    return IWorkloadFactory::IsLayerSupported(s_Id, layer, dataType, outReasonIfUnsupported, modelOptions);
}

std::unique_ptr<ITensorHandle> GpuFsaWorkloadFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
                                                                         const bool isMemoryManaged) const
{
    if (isMemoryManaged)
    {
        return std::make_unique<GpuFsaTensorHandle>(tensorInfo, m_MemoryManager);
    }
    else
    {
        return std::make_unique<GpuFsaTensorHandle>(tensorInfo, static_cast<unsigned int>(MemorySource::Malloc));
    }
}

std::unique_ptr<ITensorHandle> GpuFsaWorkloadFactory::CreateTensorHandle(const TensorInfo& tensorInfo,
                                                                         DataLayout dataLayout,
                                                                         const bool isMemoryManaged) const
{
    IgnoreUnused(dataLayout);

    if (isMemoryManaged)
    {
        return std::make_unique<GpuFsaTensorHandle>(tensorInfo, m_MemoryManager);
    }
    else
    {
        return std::make_unique<GpuFsaTensorHandle>(tensorInfo, static_cast<unsigned int>(MemorySource::Malloc));
    }
}

std::unique_ptr<IWorkload> GpuFsaWorkloadFactory::CreateWorkload(LayerType type,
                                                                 const QueueDescriptor& descriptor,
                                                                 const WorkloadInfo& info) const
{
    IgnoreUnused(type);
    IgnoreUnused(descriptor);
    IgnoreUnused(info);

    return nullptr;
}

} // namespace armnn