mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
Consolidate several types into onnxruntime::ArgType. (#11430)
This commit is contained in:
parent
288892335e
commit
738d9b153c
8 changed files with 39 additions and 43 deletions
|
|
@ -10,4 +10,10 @@ namespace onnxruntime {
|
|||
/** A computed hash value. */
|
||||
using HashValue = uint64_t;
|
||||
|
||||
/** The type of an argument (input or output).*/
|
||||
enum class ArgType : uint8_t {
|
||||
kInput,
|
||||
kOutput,
|
||||
};
|
||||
|
||||
} // namespace onnxruntime
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "core/common/basic_types.h"
|
||||
#include "core/graph/runtime_optimization_record.h"
|
||||
|
||||
namespace onnxruntime {
|
||||
|
|
@ -135,9 +136,6 @@ struct NodesToOptimizeIndicesBuilder {
|
|||
// Action helpers
|
||||
//
|
||||
|
||||
enum class ArgType { kInput,
|
||||
kOutput };
|
||||
|
||||
// struct to define the location of an input or output definition for a Node
|
||||
struct InOutDefSlot {
|
||||
ArgType in_out;
|
||||
|
|
|
|||
|
|
@ -225,8 +225,8 @@ common::Status GetQuantizationScaleAndZeroPoint(
|
|||
|
||||
common::Status GetQuantizationScaleAndZeroPoint(
|
||||
const InitializedTensorSet& initializers, const NodeUnit& node_unit, const std::string& name,
|
||||
float& scale, int32_t& zero_point, IOKind io_kind) {
|
||||
const auto& io_defs = io_kind == IOKind::Input ? node_unit.Inputs() : node_unit.Outputs();
|
||||
float& scale, int32_t& zero_point, ArgType arg_type) {
|
||||
const auto& io_defs = arg_type == ArgType::kInput ? node_unit.Inputs() : node_unit.Outputs();
|
||||
for (const auto& io_def : io_defs) {
|
||||
if (io_def.node_arg.Name() == name)
|
||||
return GetQuantizationScaleAndZeroPoint(initializers, io_def, node_unit.ModelPath(),
|
||||
|
|
|
|||
|
|
@ -105,11 +105,6 @@ enum class ConvType : uint8_t {
|
|||
Grouped,
|
||||
};
|
||||
|
||||
enum class IOKind : uint8_t {
|
||||
Input,
|
||||
Output,
|
||||
};
|
||||
|
||||
QuantizedOpType GetQuantizedOpType(const NodeUnit& node_unit);
|
||||
|
||||
// Return the type of the conv ops,
|
||||
|
|
@ -138,7 +133,7 @@ common::Status GetQuantizationScaleAndZeroPoint(
|
|||
|
||||
common::Status GetQuantizationScaleAndZeroPoint(
|
||||
const InitializedTensorSet& initializers, const NodeUnit& node_unit, const std::string& name,
|
||||
float& scale, int32_t& zero_point, IOKind io_kind = IOKind::Input);
|
||||
float& scale, int32_t& zero_point, ArgType arg_type = ArgType::kInput);
|
||||
|
||||
// Get Shape/Type of a NodeArg
|
||||
// TODO, move to shared_utils
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ static Status GetInputDataType(
|
|||
// TODO, verify the scale and zero point match if there are multiple op using same input
|
||||
const auto* node_unit = all_quantized_op_inputs.at(name)[0];
|
||||
ORT_RETURN_IF_ERROR(GetQuantizationScaleAndZeroPoint(
|
||||
initializers, *node_unit, name, scale, zero_point, IOKind::Input));
|
||||
initializers, *node_unit, name, scale, zero_point, ArgType::kInput));
|
||||
break;
|
||||
}
|
||||
// case ONNX_NAMESPACE::TensorProto_DataType_INT8:
|
||||
|
|
|
|||
|
|
@ -1770,7 +1770,7 @@ Status GemmOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const N
|
|||
"bias of QDQGemm should be int32, actual type: ", bias_tensor.data_type());
|
||||
Shape bias_dimen;
|
||||
for (auto dim : bias_tensor.dims())
|
||||
bias_dimen.push_back(dim);
|
||||
bias_dimen.push_back(SafeInt<uint32_t>(dim));
|
||||
std::vector<uint8_t> unpacked_tensor;
|
||||
ORT_RETURN_IF_ERROR(onnxruntime::utils::UnpackInitializerData(bias_tensor, unpacked_tensor));
|
||||
OperandType bias_operand_type(Type::TENSOR_INT32, bias_dimen, a_scale * b_scale);
|
||||
|
|
|
|||
|
|
@ -208,13 +208,13 @@ static bool IsQuantizationZeroPointSupported(const InitializedTensorSet& initial
|
|||
|
||||
// Check if the given quantized input(s) or output(s) is supported
|
||||
static bool IsQuantizedIOSupported(const InitializedTensorSet& initializers, const NodeUnit& node_unit,
|
||||
const std::vector<size_t>& indices, const OpSupportCheckParams& params, IOKind io_kind) {
|
||||
const std::vector<size_t>& indices, const OpSupportCheckParams& params, ArgType arg_type) {
|
||||
const auto& op_type = node_unit.OpType();
|
||||
auto quant_op_type = GetQuantizedOpType(node_unit);
|
||||
|
||||
ORT_ENFORCE(quant_op_type != QuantizedOpType::Unknown, "[", op_type, "] is not a quantized op");
|
||||
|
||||
const bool is_input = io_kind == IOKind::Input;
|
||||
const bool is_input = arg_type == ArgType::kInput;
|
||||
const bool is_quant_conv = IsQuantizedConv(quant_op_type);
|
||||
const bool is_quant_matmul = (quant_op_type == QuantizedOpType::QLinearMatMul) || (quant_op_type == QuantizedOpType::QDQMatMul);
|
||||
const bool is_quant_gemm = (quant_op_type == QuantizedOpType::QDQGemm);
|
||||
|
|
@ -572,10 +572,10 @@ bool BinaryOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
if (!HasValidBinaryOpQuantizedInputTypes(node_unit))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0, 1}, params, IOKind::Input))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0, 1}, params, ArgType::kInput))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -678,10 +678,10 @@ bool TransposeOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
}
|
||||
|
||||
if (IsQuantizedOp(node_unit)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Input))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kInput))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -766,11 +766,11 @@ bool ReshapeOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
return BaseOpSupportChecker::HasSupportedInputOutputsImpl(initializers, node_unit, params);
|
||||
}
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Input)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kInput)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1006,10 +1006,10 @@ bool PoolOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
return BaseOpSupportChecker::HasSupportedInputOutputsImpl(initializers, node_unit, params);
|
||||
|
||||
if (is_quant_average_pool) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Input))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kInput))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1079,10 +1079,10 @@ bool ConvOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
if (!HasValidBinaryOpQuantizedInputTypes(node_unit))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0, 1}, params, IOKind::Input))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0, 1}, params, ArgType::kInput))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -1272,11 +1272,11 @@ bool SoftMaxOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
return BaseOpSupportChecker::HasSupportedInputOutputsImpl(initializers, node_unit, params);
|
||||
}
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Input)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kInput)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1328,10 +1328,10 @@ bool GemmOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
if (!HasValidBinaryOpQuantizedInputTypes(node_unit))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0, 1}, params, IOKind::Input))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0, 1}, params, ArgType::kInput))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -1558,10 +1558,10 @@ bool UnaryOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
if (node_unit.OpType() != "QLinearSigmoid")
|
||||
return BaseOpSupportChecker::HasSupportedInputOutputsImpl(initializers, node_unit, params);
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Input))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kInput))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -1653,11 +1653,11 @@ bool ConcatOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
if (IsQuantizedOp(node_unit)) {
|
||||
std::vector<size_t> input_indices(input_size);
|
||||
std::iota(input_indices.begin(), input_indices.end(), 0);
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, input_indices, params, IOKind::Input)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, input_indices, params, ArgType::kInput)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -1758,7 +1758,7 @@ class QuantizeLinearOpSupportChecker : public BaseOpSupportChecker {
|
|||
bool HasSupportedInputOutputsImpl(
|
||||
const InitializedTensorSet& initializers, const NodeUnit& node_unit,
|
||||
const OpSupportCheckParams& params) const override {
|
||||
return IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output);
|
||||
return IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -1776,7 +1776,7 @@ class DequantizeLinearOpSupportChecker : public BaseOpSupportChecker {
|
|||
bool HasSupportedInputOutputsImpl(
|
||||
const InitializedTensorSet& initializers, const NodeUnit& node_unit,
|
||||
const OpSupportCheckParams& params) const override {
|
||||
return IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Input);
|
||||
return IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kInput);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -2020,10 +2020,10 @@ bool ResizeOpSupportChecker::HasSupportedInputOutputsImpl(
|
|||
}
|
||||
|
||||
if (IsQuantizedOp(node_unit)) {
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Input))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kInput))
|
||||
return false;
|
||||
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, IOKind::Output))
|
||||
if (!IsQuantizedIOSupported(initializers, node_unit, {0}, params, ArgType::kOutput))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "boost/mp11.hpp"
|
||||
|
||||
#include "core/common/basic_types.h"
|
||||
#include "core/common/type_list.h"
|
||||
#include "core/common/type_set_utils.h"
|
||||
|
||||
|
|
@ -41,12 +42,8 @@
|
|||
namespace onnxruntime {
|
||||
namespace op_kernel_type_control {
|
||||
|
||||
enum class OpArgDirection {
|
||||
Input,
|
||||
Output
|
||||
};
|
||||
|
||||
using OpArgIndex = size_t;
|
||||
using OpArgDirection = ArgType;
|
||||
|
||||
// constant to use for type lists that are valid across all opsets
|
||||
constexpr int kAllOpSets = -1;
|
||||
|
|
@ -172,7 +169,7 @@ struct EnabledTypes {
|
|||
::onnxruntime::op_kernel_type_control::tags::OpArg< \
|
||||
::onnxruntime::op_kernel_type_control:: \
|
||||
ORT_OP_KERNEL_TYPE_CTRL_INTERNAL_OP_TAG_CLASS_NAME(OpDomain, OpName), \
|
||||
::onnxruntime::op_kernel_type_control::OpArgDirection::ArgDirection, \
|
||||
::onnxruntime::op_kernel_type_control::OpArgDirection::k##ArgDirection, \
|
||||
ArgIndex>
|
||||
|
||||
// INTERNAL
|
||||
|
|
|
|||
Loading…
Reference in a new issue