From a35b30e2379352540b8611429c9ef83ee50faa0e Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Sun, 14 Feb 2021 15:16:07 -0800 Subject: [PATCH] Change BuildKernelDefConstraintsFunctorFromTypeList struct to BuildKernelDefConstraintsFromTypeList function. (#6674) --- .../onnxruntime/core/framework/op_kernel.h | 27 +++++++++--------- .../cpu/generator/constant_of_shape.cc | 4 +-- .../providers/cpu/math/element_wise_ops.cc | 28 +++++++++---------- .../core/providers/cpu/tensor/cast_op.cc | 8 +++--- .../core/providers/cpu/tensor/gather.cc | 4 +-- .../core/providers/cpu/tensor/isinf.cc | 4 +-- .../core/providers/cpu/tensor/slice.cc | 8 +++--- .../core/providers/cpu/tensor/transpose.cc | 4 +-- 8 files changed, 44 insertions(+), 43 deletions(-) diff --git a/include/onnxruntime/core/framework/op_kernel.h b/include/onnxruntime/core/framework/op_kernel.h index b39a1bb66e..afd215df44 100644 --- a/include/onnxruntime/core/framework/op_kernel.h +++ b/include/onnxruntime/core/framework/op_kernel.h @@ -482,24 +482,25 @@ using BuildKernelCreateInfoFn = KernelCreateInfo (*)(); static_cast([](const OpKernelInfo& info) -> OpKernel* { return new __VA_ARGS__(info); })); \ } -// Use within macro definitions to create a custom vector of constraints. -// Example: #define REG_KERNEL(OP, VERSION, KERNEL_CLASS, Type, ...) -// .TypeConstraint("T", BuildKernelDefConstraints()) -template -inline std::vector BuildKernelDefConstraints() { - return {DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType()...}; -} - -// functor that calls BuildKernelDefConstraints() template -struct BuildKernelDefConstraintsFunctor { +struct BuildKernelDefConstraintsImpl { std::vector operator()() const { - return BuildKernelDefConstraints(); + return {DataTypeImpl::GetTensorType()...}; } }; -// the type BuildKernelDefConstraintsFunctor given a type list L +// Use within macro definitions to create a custom vector of constraints. +// Example: #define REG_KERNEL(OP, VERSION, KERNEL_CLASS, Type, ...) +// .TypeConstraint("T", BuildKernelDefConstraints()) +template +inline std::vector BuildKernelDefConstraints() { + return BuildKernelDefConstraintsImpl{}(); +} + +// version of BuildKernelDefConstraints() which takes a type list template -using BuildKernelDefConstraintsFunctorFromTypeList = boost::mp11::mp_apply; +std::vector BuildKernelDefConstraintsFromTypeList() { + return boost::mp11::mp_apply{}(); +} } // namespace onnxruntime diff --git a/onnxruntime/core/providers/cpu/generator/constant_of_shape.cc b/onnxruntime/core/providers/cpu/generator/constant_of_shape.cc index a3c3e17416..176924c1da 100644 --- a/onnxruntime/core/providers/cpu/generator/constant_of_shape.cc +++ b/onnxruntime/core/providers/cpu/generator/constant_of_shape.cc @@ -70,8 +70,8 @@ ONNX_CPU_OPERATOR_KERNEL( KernelDefBuilder() .TypeConstraint("T1", DataTypeImpl::GetTensorType()) .TypeConstraint("T2", - BuildKernelDefConstraintsFunctorFromTypeList{}(), - BuildKernelDefConstraintsFunctorFromTypeList{}()), + BuildKernelDefConstraintsFromTypeList(), + BuildKernelDefConstraintsFromTypeList()), ConstantOfShape); } // namespace onnxruntime diff --git a/onnxruntime/core/providers/cpu/math/element_wise_ops.cc b/onnxruntime/core/providers/cpu/math/element_wise_ops.cc index fa7fa56b0d..cf27e62b25 100644 --- a/onnxruntime/core/providers/cpu/math/element_wise_ops.cc +++ b/onnxruntime/core/providers/cpu/math/element_wise_ops.cc @@ -230,12 +230,12 @@ REG_ELEMENTWISE_VERSIONED_TYPED_KERNEL(Sqrt, 6, 12, double, Sqrt); REG_ELEMENTWISE_TYPED_KERNEL(Sqrt, 13, float, Sqrt); REG_ELEMENTWISE_TYPED_KERNEL(Sqrt, 13, double, Sqrt); -const auto supported_pow7_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_pow7_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto supported_pow12_base_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto supported_pow12_exp_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_pow12_base_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_pow12_exp_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); +const auto supported_pow7_types = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_pow7_types = BuildKernelDefConstraintsFromTypeList(); +const auto supported_pow12_base_types = BuildKernelDefConstraintsFromTypeList(); +const auto supported_pow12_exp_types = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_pow12_base_types = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_pow12_exp_types = BuildKernelDefConstraintsFromTypeList(); REG_ELEMENTWISE_VERSIONED_KERNEL_NONT(Pow, 7, 11, Pow, supported_pow7_types, enabled_pow7_types); REG_ELEMENTWISE_VERSIONED_KERNEL_NONT_2(Pow, 12, 12, Pow, supported_pow12_base_types, enabled_pow12_base_types, @@ -264,19 +264,19 @@ REG_ELEMENTWISE_TYPED_KERNEL(Sum, 13, double, Sum_8); REG_ELEMENTWISE_VERSIONED_TYPED_KERNEL(Max, 6, 7, float, Max_6); -const auto supported_max8_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto supported_max12_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_max8_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_max12_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); +const auto supported_max8_types = BuildKernelDefConstraintsFromTypeList(); +const auto supported_max12_types = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_max8_types = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_max12_types = BuildKernelDefConstraintsFromTypeList(); REG_ELEMENTWISE_VERSIONED_KERNEL_NONT(Max, 8, 11, Max_8, supported_max8_types, enabled_max8_types); REG_ELEMENTWISE_VERSIONED_KERNEL_NONT(Max, 12, 12, Max_8, supported_max12_types, enabled_max12_types); // Supposed to add BFloat16 but we are not supporting now, however, separate registration REG_ELEMENTWISE_KERNEL_NONT(Max, 13, Max_8, supported_max12_types, enabled_max12_types); -const auto supported_min8_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto supported_min12_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_min8_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_min12_types = BuildKernelDefConstraintsFunctorFromTypeList{}(); +const auto supported_min8_types = BuildKernelDefConstraintsFromTypeList(); +const auto supported_min12_types = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_min8_types = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_min12_types = BuildKernelDefConstraintsFromTypeList(); REG_ELEMENTWISE_VERSIONED_TYPED_KERNEL(Min, 6, 7, float, Min_6); REG_ELEMENTWISE_VERSIONED_KERNEL_NONT(Min, 8, 11, Min_8, supported_min8_types, enabled_min8_types); REG_ELEMENTWISE_VERSIONED_KERNEL_NONT(Min, 12, 12, Min_8, supported_min12_types, enabled_min12_types); diff --git a/onnxruntime/core/providers/cpu/tensor/cast_op.cc b/onnxruntime/core/providers/cpu/tensor/cast_op.cc index aae2f1a5b3..716939a5ce 100644 --- a/onnxruntime/core/providers/cpu/tensor/cast_op.cc +++ b/onnxruntime/core/providers/cpu/tensor/cast_op.cc @@ -308,10 +308,10 @@ Status Cast::Compute(OpKernelContext* context) const { return Status::OK(); } -const auto supported_src_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto supported_dst_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_src_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_dst_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); +const auto supported_src_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto supported_dst_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_src_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_dst_type_constraints = BuildKernelDefConstraintsFromTypeList(); } // namespace diff --git a/onnxruntime/core/providers/cpu/tensor/gather.cc b/onnxruntime/core/providers/cpu/tensor/gather.cc index c7385be504..f9678d05c2 100644 --- a/onnxruntime/core/providers/cpu/tensor/gather.cc +++ b/onnxruntime/core/providers/cpu/tensor/gather.cc @@ -21,8 +21,8 @@ using SupportedIndexTypes = ORT_OP_KERNEL_ARG_SUPPORTED_TYPE_LIST_ALL_OPSETS(kCp using EnabledIndexTypes = ORT_OP_KERNEL_ARG_ENABLED_TYPE_LIST_ALL_OPSETS(kCpuExecutionProvider, kOnnxDomain, Gather, Input, 1); -const auto supported_index_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_index_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); +const auto supported_index_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_index_type_constraints = BuildKernelDefConstraintsFromTypeList(); } // namespace ONNX_CPU_OPERATOR_VERSIONED_KERNEL( diff --git a/onnxruntime/core/providers/cpu/tensor/isinf.cc b/onnxruntime/core/providers/cpu/tensor/isinf.cc index a7c37ae612..d3f67ba1d8 100644 --- a/onnxruntime/core/providers/cpu/tensor/isinf.cc +++ b/onnxruntime/core/providers/cpu/tensor/isinf.cc @@ -40,8 +40,8 @@ ONNX_CPU_OPERATOR_KERNEL( 10, KernelDefBuilder() .TypeConstraint("T1", - BuildKernelDefConstraintsFunctorFromTypeList{}(), - BuildKernelDefConstraintsFunctorFromTypeList{}()) + BuildKernelDefConstraintsFromTypeList(), + BuildKernelDefConstraintsFromTypeList()) .TypeConstraint("T2", DataTypeImpl::GetTensorType()), IsInf); diff --git a/onnxruntime/core/providers/cpu/tensor/slice.cc b/onnxruntime/core/providers/cpu/tensor/slice.cc index 75c81a9bf7..9a105c0228 100644 --- a/onnxruntime/core/providers/cpu/tensor/slice.cc +++ b/onnxruntime/core/providers/cpu/tensor/slice.cc @@ -33,10 +33,10 @@ using EnabledDataTypes = ORT_OP_KERNEL_ARG_ENABLED_TYPE_LIST_ALL_OPSETS(kCpuExec using EnabledIndicesTypes = ORT_OP_KERNEL_ARG_ENABLED_TYPE_LIST_ALL_OPSETS(kCpuExecutionProvider, kOnnxDomain, Slice, Input, 1); -const auto supported_data_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto supported_indices_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_data_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_indices_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); +const auto supported_data_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto supported_indices_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_data_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_indices_type_constraints = BuildKernelDefConstraintsFromTypeList(); // std::clamp doesn't exist until C++17 so create a local version template diff --git a/onnxruntime/core/providers/cpu/tensor/transpose.cc b/onnxruntime/core/providers/cpu/tensor/transpose.cc index e8b09b0a4d..ed15ae437a 100644 --- a/onnxruntime/core/providers/cpu/tensor/transpose.cc +++ b/onnxruntime/core/providers/cpu/tensor/transpose.cc @@ -25,8 +25,8 @@ using SupportedDataTypes = ORT_OP_KERNEL_ARG_SUPPORTED_TYPE_LIST_ALL_OPSETS(kCpu using EnabledDataTypes = ORT_OP_KERNEL_ARG_ENABLED_TYPE_LIST_ALL_OPSETS(kCpuExecutionProvider, kOnnxDomain, Transpose, Input, 0); -const auto supported_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); -const auto enabled_type_constraints = BuildKernelDefConstraintsFunctorFromTypeList{}(); +const auto supported_type_constraints = BuildKernelDefConstraintsFromTypeList(); +const auto enabled_type_constraints = BuildKernelDefConstraintsFromTypeList(); } // namespace /* A permutation [a,b,c,...] indicates that