10 #include <unordered_map>
18 namespace onnxruntime {
21 typedef std::map<size_t, OrtMemType>
MemTypeMap;
26 constexpr
static inline bool MemTypeOnCpuExplicitly(OrtMemType mem_type) {
27 return mem_type == OrtMemTypeCPUInput || mem_type == OrtMemTypeCPUOutput;
42 *start = op_since_version_start_;
43 *end = op_since_version_end_;
47 return std::pair<int, int>(op_since_version_start_, op_since_version_end_);
51 return provider_type_;
55 const std::unordered_map<std::string, std::vector<MLDataType>>&
TypeConstraints()
const {
56 return type_constraints_;
59 const std::vector<std::pair<int, int>>&
MayInplace()
const {
63 const std::vector<std::pair<int, int>>&
Alias()
const {
68 return variadic_alias_offsets_;
72 auto it = input_memory_type_args_.find(input_index);
73 if (it == input_memory_type_args_.end())
74 return default_inputs_mem_type_;
86 #ifdef ENABLE_STRIDED_TENSORS
87 const std::vector<int>& MayStridedInput()
const {
return may_strided_inputs_; }
88 const std::vector<std::pair<int, int>>& MayStridedOutput()
const {
return may_strided_output_map_; }
92 auto it = output_memory_type_args_.find(output_index);
93 if (it == output_memory_type_args_.end())
94 return default_outputs_mem_type_;
99 return exec_queue_id_;
113 int op_since_version_start_ = 1;
114 int op_since_version_end_ = INT_MAX;
126 std::unordered_map<std::string, std::vector<MLDataType>> type_constraints_;
129 std::vector<std::pair<int, int>> inplace_map_;
132 std::vector<std::pair<int, int>> alias_map_;
136 std::optional<std::pair<int, int>> variadic_alias_offsets_;
139 bool allocate_inputs_contiguously_ =
false;
142 bool external_outputs_ =
false;
144 #ifdef ENABLE_STRIDED_TENSORS
146 std::vector<int> may_strided_inputs_;
149 std::vector<std::pair<int, int>> may_strided_output_map_;
157 int exec_queue_id_ = 0;
159 OrtMemType default_inputs_mem_type_{OrtMemTypeDefault};
161 OrtMemType default_outputs_mem_type_{OrtMemTypeDefault};
166 static std::unique_ptr<KernelDefBuilder>
Create() {
return std::make_unique<KernelDefBuilder>(); }
169 : kernel_def_(std::make_unique<
KernelDef>()) {}
181 kernel_def_->op_since_version_start_ = since_version;
193 kernel_def_->op_since_version_start_ = since_version_start;
194 kernel_def_->op_since_version_end_ = since_version_end;
249 kernel_def_->allocate_inputs_contiguously_ =
true;
258 kernel_def_->external_outputs_ =
true;
262 #ifdef ENABLE_STRIDED_TENSORS
280 kernel_def_->input_memory_type_args_.insert(std::make_pair(input_index, type));
289 for (
auto input_index : input_indexes) {
290 kernel_def_->input_memory_type_args_.insert(std::make_pair(input_index, type));
300 kernel_def_->output_memory_type_args_.insert(std::make_pair(output_index, type));
309 for (
auto output_index : output_indexes) {
310 kernel_def_->output_memory_type_args_.insert(std::make_pair(output_index, type));
319 kernel_def_->exec_queue_id_ = queue_id;
327 kernel_def_->default_inputs_mem_type_ = mem_type;
335 kernel_def_->default_outputs_mem_type_ = mem_type;
342 std::unique_ptr<KernelDef>
Build() {
343 return std::move(kernel_def_);
348 std::unique_ptr<KernelDef> kernel_def_;
KernelDefBuilder & Provider(ProviderType provider_type)
static std::unique_ptr< KernelDefBuilder > Create()
KernelDefBuilder & Alias(const std::vector< std::pair< int, int >> &aliases)
const std::string & ProviderType
Base class for MLDataType.
KernelDefBuilder & ExternalOutputs()
const std::vector< std::pair< int, int > > & MayInplace() const
GLsizei const GLchar *const * string
OrtMemType InputMemoryType(size_t input_index) const
const std::string & Domain() const
const std::vector< std::pair< int, int > > & Alias() const
bool HasExternalOutputs() const
KernelDefBuilder & SetDomain(const std::string &domain)
onnxruntime::ProviderType Provider() const
KernelDefBuilder & ExecQueueId(int queue_id)
KernelDefBuilder & VariadicAlias(int input_offset, int output_offset)
bool AllocateInputsContiguously() const
bool IsConflict(const KernelDef &other) const
void SinceVersion(int *start, int *end) const
KernelDefBuilder & OutputMemoryType(OrtMemType type, const std::vector< int > &output_indexes)
KernelDefBuilder & SetDefaultOutputMemoryType(OrtMemType mem_type)
KernelDefBuilder & AllocateInputsContiguously()
KernelDefBuilder & SetName(const std::string &op_name)
const std::unordered_map< std::string, std::vector< MLDataType > > & TypeConstraints() const
KernelDefBuilder & SinceVersion(int since_version)
bool IsOutputOnCpu(size_t output_index) const
std::map< size_t, OrtMemType > MemTypeMap
KernelDefBuilder & TypeConstraint(const std::string &arg_name, std::vector< MLDataType > types)
const std::pair< int, int > SinceVersion() const
const std::string & OpName() const
OrtMemType OutputMemoryType(size_t output_index) const
KernelDefBuilder & MayInplace(const std::vector< std::pair< int, int >> &inplaces)
KernelDefBuilder & InputMemoryType(OrtMemType type, int input_index)
KernelDefBuilder & InputMemoryType(OrtMemType type, const std::vector< int > &input_indexes)
std::unique_ptr< KernelDef > Build()
KernelDefBuilder & SetDefaultInputsMemoryType(OrtMemType mem_type)
GLsizei GLenum GLenum * types
const std::optional< std::pair< int, int > > & VariadicAlias() const
KernelDefBuilder & OutputMemoryType(OrtMemType type, int output_index)
KernelDefBuilder & SinceVersion(int since_version_start, int since_version_end)
bool IsInputOnCpu(size_t input_index) const