-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMiopenEngine.cpp
More file actions
84 lines (72 loc) · 2.42 KB
/
MiopenEngine.cpp
File metadata and controls
84 lines (72 loc) · 2.42 KB
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
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include "MiopenEngine.hpp"
#include "plans/MiopenBatchnormPlanBuilder.hpp"
#include <hipdnn_sdk/data_objects/engine_details_generated.h>
namespace miopen_legacy_plugin
{
MiopenEngine::MiopenEngine(int64_t id)
: _id(id)
{
}
int64_t MiopenEngine::id() const
{
return _id;
}
bool MiopenEngine::isApplicable(HipdnnEnginePluginHandle& handle,
const hipdnn_plugin::IGraph& opGraph) const
{
// This is wrong if we ever have more than 1 plan builder thats applicable.
// If this is the case, we should split plan builders accross multiple engines.
for(const auto& planBuilder : _planBuilders)
{
if(planBuilder->isApplicable(handle, opGraph))
{
return true;
}
}
return false;
}
void MiopenEngine::getDetails(HipdnnEnginePluginHandle& handle,
hipdnnPluginConstData_t& detailsOut) const
{
flatbuffers::FlatBufferBuilder builder;
auto engineDetails = hipdnn_sdk::data_objects::CreateEngineDetails(builder, _id);
builder.Finish(engineDetails);
auto detachedBuffer = std::make_unique<flatbuffers::DetachedBuffer>(builder.Release());
detailsOut.ptr = detachedBuffer->data();
detailsOut.size = detachedBuffer->size();
handle.storeEngineDetailsDetachedBuffer(detailsOut.ptr, std::move(detachedBuffer));
}
size_t MiopenEngine::getWorkspaceSize(const HipdnnEnginePluginHandle& handle,
const hipdnn_plugin::IGraph& opGraph) const
{
size_t workspaceSize = 0;
for(const auto& planBuilder : _planBuilders)
{
if(planBuilder->isApplicable(handle, opGraph))
{
workspaceSize = std::max(workspaceSize, planBuilder->getWorkspaceSize(handle, opGraph));
}
}
return workspaceSize;
}
void MiopenEngine::initializeExecutionContext(
const HipdnnEnginePluginHandle& handle,
const hipdnn_plugin::IGraph& opGraph,
HipdnnEnginePluginExecutionContext& executionContext) const
{
for(const auto& planBuilder : _planBuilders)
{
if(planBuilder->isApplicable(handle, opGraph))
{
planBuilder->buildPlan(handle, opGraph, executionContext);
break;
}
}
}
void MiopenEngine::addPlanBuilder(std::unique_ptr<IPlanBuilder> planBuilder)
{
_planBuilders.insert(std::move(planBuilder));
}
}