forked from microsoft/onnxruntime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecution_provider.h
More file actions
127 lines (106 loc) · 4.23 KB
/
Copy pathexecution_provider.h
File metadata and controls
127 lines (106 loc) · 4.23 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
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include <unordered_map>
#include "core/common/status.h"
#include "core/framework/tensor.h"
namespace onnxruntime {
class GraphViewer;
} // namespace onnxruntime
namespace onnxruntime {
struct ComputeCapability;
class KernelRegistry;
class KernelRegistryManager;
/**
Logical device representation.
*/
typedef std::map<int, AllocatorPtr> AllocatorMap;
class IExecutionProvider {
public:
virtual ~IExecutionProvider() = default;
/**
Get all IAllocators for <*this> execution provider.
*/
std::vector<AllocatorPtr> GetAllocatorMap() const {
std::vector<AllocatorPtr> values;
for (auto& kv : allocators_) {
values.push_back(kv.second);
}
return values;
}
/**
Get allocator with specified MemType
*/
virtual AllocatorPtr GetAllocator(int id, ONNXRuntimeMemType mem_type) const;
/**
Get execution provider's capability for the specified <graph>.
Return a bunch of IndexedSubGraphs <*this> execution provider can run if
the sub-graph contains only one node or can fuse to run if the sub-graph
contains more than one node. The node indexes contained in sub-graphs may
have overlap, and it's ONNXRuntime's responsibility to do the partition
and decide whether a node will be assigned to <*this> execution provider.
*/
virtual std::vector<std::unique_ptr<ComputeCapability>>
GetCapability(const onnxruntime::GraphViewer& graph_viewer,
const std::vector<const KernelRegistry*>& kernel_registries) const;
/**
Get kernel registry per execution provider type.
The KernelRegistry share pointer returned is shared across sessions.
NOTE: this is a tricky but final solution to achieve following goals,
1. The execution provider type based kernel registry should be shared
across sessions.
Only one copy of this kind of kernel registry exists in ONNXRuntime
with multiple sessions/models.
2. Adding an execution provider into ONNXRuntime does not need to touch ONNXRuntime
frameowrk/session code.
3. onnxruntime (framework/session) does not depend on any specific
execution provider lib.
*/
virtual std::shared_ptr<KernelRegistry> GetKernelRegistry() const = 0;
/**
Copy tensor between execution providers
*/
virtual common::Status CopyTensor(const Tensor& src, Tensor& dst) const = 0;
/**
Copy tensor between execution providers on specified exec queue
*/
virtual common::Status CopyTensor(const Tensor& src, Tensor& dst,
int exec_queue_id) const;
/**
Returns an opaque handle whose exact type varies based on the provider
and is interpreted accordingly by the corresponding kernel implementation.
For Direct3D operator kernels, this may return an IUnknown supporting
QueryInterface to ID3D12GraphicsCommandList1.
*/
virtual const void* GetExecutionHandle() const noexcept = 0;
/**
@return type of the execution provider; should match that set in the node
through the SetExecutionProvider API. Example valid return values are:
kCpuExecutionProvider, kCudaExecutionProvider
*/
virtual std::string Type() const = 0;
/**
Blocks until the device has completed all preceding requested tasks.
Currently this is primarily used by the IOBinding object to ensure that all
inputs have been copied to the device before execution begins.
*/
virtual common::Status Sync() const;
/**
Called when InferenceSession::Run started
NOTE that due to async execution in provider, the actual work of previous
Run may not be finished on device This function should be regarded as the
point after which a new Run would start to submit commands from CPU
*/
virtual common::Status OnRunStart();
/**
Called when InferenceSession::Run ended
NOTE that due to async execution in provider, the actual work of this Run
may not be finished on device This function should be regarded as the point
that all commands of current Run has been submmited by CPU
*/
virtual common::Status OnRunEnd();
void InsertAllocator(AllocatorPtr allocator);
private:
AllocatorMap allocators_;
};
} // namespace onnxruntime