diff --git a/onnxruntime/contrib_ops/cpu/image_scaler.h b/onnxruntime/contrib_ops/cpu/image_scaler.h index 9e9d9908ab188..865bca51f1e85 100644 --- a/onnxruntime/contrib_ops/cpu/image_scaler.h +++ b/onnxruntime/contrib_ops/cpu/image_scaler.h @@ -16,8 +16,8 @@ template class ImageScaler final : public OpKernel { public: ImageScaler(const OpKernelInfo& info) : OpKernel(info) { - ORT_ENFORCE(info.GetAttr("scale", &scale_).IsOK()); - ORT_ENFORCE(info.GetAttrs("bias", bias_).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttr("scale", &scale_)); + ORT_THROW_IF_ERROR(info.GetAttrs("bias", bias_)); } Status Compute(OpKernelContext* context) const override { diff --git a/onnxruntime/contrib_ops/cuda/collective/sharding.cc b/onnxruntime/contrib_ops/cuda/collective/sharding.cc index b6b509023a1a9..1b4cc4502cff8 100644 --- a/onnxruntime/contrib_ops/cuda/collective/sharding.cc +++ b/onnxruntime/contrib_ops/cuda/collective/sharding.cc @@ -244,7 +244,7 @@ DistributedKernel::DistributedKernel(const OpKernelInfo& info) : NcclKernel(info // stored on a 1-D mesh with 2 devices and the second input on another 1-D // mesh with 1 device. std::vector attr_input_device_mesh_shapes; - ORT_ENFORCE(info.GetAttrs("input_device_mesh_shapes", attr_input_device_mesh_shapes).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("input_device_mesh_shapes", attr_input_device_mesh_shapes)); // input_device_mesh_elements[i] is the flattened device mesh for the i-th input. // Note that its actual shape is input_device_mesh_shapes[i]. @@ -255,12 +255,12 @@ DistributedKernel::DistributedKernel(const OpKernelInfo& info) : NcclKernel(info // Then the first input is stored on a 1-D mesh with 2 devices and the second // input on another 1-D mesh with 1 device. std::vector attr_input_device_mesh_elements; - ORT_ENFORCE(info.GetAttrs("input_device_mesh_elements", attr_input_device_mesh_elements).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("input_device_mesh_elements", attr_input_device_mesh_elements)); // input_shard_specs[i] is the sharding spec of the i-th input; e.g., // "RR" if the i-th input is not sharded. std::vector input_shard_specs; - ORT_ENFORCE(info.GetAttrs("input_shard_specs", input_shard_specs).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("input_shard_specs", input_shard_specs)); ORT_ENFORCE(attr_input_device_mesh_shapes.size() == attr_input_device_mesh_elements.size()); ORT_ENFORCE(attr_input_device_mesh_shapes.size() == input_shard_specs.size()); @@ -274,13 +274,13 @@ DistributedKernel::DistributedKernel(const OpKernelInfo& info) : NcclKernel(info } std::vector attr_output_device_mesh_shapes; - ORT_ENFORCE(info.GetAttrs("output_device_mesh_shapes", attr_output_device_mesh_shapes).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("output_device_mesh_shapes", attr_output_device_mesh_shapes)); std::vector attr_output_device_mesh_elements; - ORT_ENFORCE(info.GetAttrs("output_device_mesh_elements", attr_output_device_mesh_elements).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("output_device_mesh_elements", attr_output_device_mesh_elements)); std::vector output_shard_specs; - ORT_ENFORCE(info.GetAttrs("output_shard_specs", output_shard_specs).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("output_shard_specs", output_shard_specs)); ORT_ENFORCE(attr_output_device_mesh_shapes.size() == attr_output_device_mesh_elements.size()); ORT_ENFORCE(attr_output_device_mesh_shapes.size() == output_shard_specs.size()); diff --git a/onnxruntime/contrib_ops/cuda/tensor/image_scaler.cc b/onnxruntime/contrib_ops/cuda/tensor/image_scaler.cc index a2169b29dc8f5..befad5661c43f 100644 --- a/onnxruntime/contrib_ops/cuda/tensor/image_scaler.cc +++ b/onnxruntime/contrib_ops/cuda/tensor/image_scaler.cc @@ -26,8 +26,8 @@ REGISTER_KERNEL_TYPED(MLFloat16) template ImageScaler::ImageScaler(const OpKernelInfo& info) : CudaKernel(info) { - ORT_ENFORCE(info.GetAttr("scale", &scale_).IsOK()); - ORT_ENFORCE(info.GetAttrs("bias", bias_).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttr("scale", &scale_)); + ORT_THROW_IF_ERROR(info.GetAttrs("bias", bias_)); b_data_ = GetScratchBuffer(bias_.size(), nullptr); // the transfer in kernel construction need to be sync on default stream. diff --git a/onnxruntime/core/codegen/passes/op_ir_creator/nn/conv.cc b/onnxruntime/core/codegen/passes/op_ir_creator/nn/conv.cc index c3a9e5950acce..19545d1554405 100644 --- a/onnxruntime/core/codegen/passes/op_ir_creator/nn/conv.cc +++ b/onnxruntime/core/codegen/passes/op_ir_creator/nn/conv.cc @@ -29,9 +29,9 @@ Status GENERIC_OP_IR_CREATOR_CLASS(Conv)::Evaluate( info.GetAttrOrDefault("group", &group, 1); info.GetAttrOrDefault("auto_pad", &auto_pad, "NOTSET"); - ORT_ENFORCE(info.GetAttrs("kernel_shape", kernel_shape).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("kernel_shape", kernel_shape)); ORT_ENFORCE(kernel_shape.size() <= 2, "Only support 1D/2D convolution currently!"); - ORT_ENFORCE(info.GetAttrs("strides", strides).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("strides", strides)); dilations = info.GetAttrs("dilations", dilations).IsOK() ? dilations : std::vector(kernel_shape.size(), 1); ORT_ENFORCE(dilations == std::vector(kernel_shape.size(), 1), "Only support dilation is 1 currently"); diff --git a/onnxruntime/core/codegen/passes/op_ir_creator/tensor/pad.cc b/onnxruntime/core/codegen/passes/op_ir_creator/tensor/pad.cc index ecff2c7b73847..e9e20e8a43998 100644 --- a/onnxruntime/core/codegen/passes/op_ir_creator/tensor/pad.cc +++ b/onnxruntime/core/codegen/passes/op_ir_creator/tensor/pad.cc @@ -23,9 +23,9 @@ Status GENERIC_OP_IR_CREATOR_CLASS(Pad)::Evaluate( std::vector pads; float value; - ORT_ENFORCE(attrs.GetAttr("mode", &mode).IsOK()); - ORT_ENFORCE(attrs.GetAttrs("pads", pads).IsOK()); - ORT_ENFORCE(attrs.GetAttr("value", &value).IsOK()); + ORT_THROW_IF_ERROR(attrs.GetAttr("mode", &mode)); + ORT_THROW_IF_ERROR(attrs.GetAttrs("pads", pads)); + ORT_THROW_IF_ERROR(attrs.GetAttr("value", &value)); if (mode != "constant" && mode != "edge" && mode != "reflect") return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Pad: Unsupported padding mode!"); diff --git a/onnxruntime/core/providers/cpu/ml/category_mapper.h b/onnxruntime/core/providers/cpu/ml/category_mapper.h index 62432a0ef00ff..481cc8cebdcd9 100644 --- a/onnxruntime/core/providers/cpu/ml/category_mapper.h +++ b/onnxruntime/core/providers/cpu/ml/category_mapper.h @@ -16,11 +16,11 @@ class CategoryMapper final : public OpKernel { std::vector string_categories; std::vector int_categories; - ORT_ENFORCE(info.GetAttrs("cats_strings", string_categories).IsOK()); - ORT_ENFORCE(info.GetAttrs("cats_int64s", int_categories).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("cats_strings", string_categories)); + ORT_THROW_IF_ERROR(info.GetAttrs("cats_int64s", int_categories)); - ORT_ENFORCE(info.GetAttr("default_string", &default_string_).IsOK()); - ORT_ENFORCE(info.GetAttr("default_int64", &default_int_).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttr("default_string", &default_string_)); + ORT_THROW_IF_ERROR(info.GetAttr("default_int64", &default_int_)); auto num_entries = string_categories.size(); diff --git a/onnxruntime/core/providers/cpu/ml/label_encoder.h b/onnxruntime/core/providers/cpu/ml/label_encoder.h index a935fd64d5da4..1b4fa01900ae9 100644 --- a/onnxruntime/core/providers/cpu/ml/label_encoder.h +++ b/onnxruntime/core/providers/cpu/ml/label_encoder.h @@ -15,7 +15,7 @@ class LabelEncoder final : public OpKernel { LabelEncoder(const OpKernelInfo& info) : OpKernel(info) { std::vector string_classes; - ORT_ENFORCE(info.GetAttrs("classes_strings", string_classes).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("classes_strings", string_classes)); ORT_ENFORCE(info.GetAttr("default_string", &default_string_).IsOK()); ORT_ENFORCE(info.GetAttr("default_int64", &default_int_).IsOK()); @@ -53,8 +53,8 @@ class LabelEncoder_2 final : public OpKernel { std::vector keys; std::vector values; - ORT_ENFORCE(info.GetAttrs(_key_field_name, keys).IsOK()); - ORT_ENFORCE(info.GetAttrs(_value_field_name, values).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs(_key_field_name, keys)); + ORT_THROW_IF_ERROR(info.GetAttrs(_value_field_name, values)); auto num_keys = keys.size(); auto num_values = values.size(); diff --git a/onnxruntime/core/providers/cpu/ml/linearregressor.cc b/onnxruntime/core/providers/cpu/ml/linearregressor.cc index 6ed5545e7063f..4df7081b17b6e 100644 --- a/onnxruntime/core/providers/cpu/ml/linearregressor.cc +++ b/onnxruntime/core/providers/cpu/ml/linearregressor.cc @@ -21,8 +21,8 @@ LinearRegressor::LinearRegressor(const OpKernelInfo& info) : OpKernel(info), intercepts_(info.GetAttrsOrDefault("intercepts")), post_transform_(MakeTransform(info.GetAttrOrDefault("post_transform", "NONE"))) { - ORT_ENFORCE(info.GetAttr("targets", &num_targets_).IsOK()); - ORT_ENFORCE(info.GetAttrs("coefficients", coefficients_).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttr("targets", &num_targets_)); + ORT_THROW_IF_ERROR(info.GetAttrs("coefficients", coefficients_)); // use the intercepts_ if they're valid use_intercepts_ = intercepts_.size() == static_cast(num_targets_); diff --git a/onnxruntime/core/providers/cpu/ml/svmclassifier.cc b/onnxruntime/core/providers/cpu/ml/svmclassifier.cc index 8c356b4c62023..4bfb0f673404a 100644 --- a/onnxruntime/core/providers/cpu/ml/svmclassifier.cc +++ b/onnxruntime/core/providers/cpu/ml/svmclassifier.cc @@ -32,8 +32,8 @@ SVMClassifier::SVMClassifier(const OpKernelInfo& info) probb_(info.GetAttrsOrDefault("prob_b")), support_vectors_(info.GetAttrsOrDefault("support_vectors")), post_transform_(MakeTransform(info.GetAttrOrDefault("post_transform", "NONE"))) { - ORT_ENFORCE(info.GetAttrs("rho", rho_).IsOK()); - ORT_ENFORCE(info.GetAttrs("coefficients", coefficients_).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("rho", rho_)); + ORT_THROW_IF_ERROR(info.GetAttrs("coefficients", coefficients_)); // prob_a and prob_b are optional for Z output ORT_ENFORCE(proba_.size() == probb_.size()); diff --git a/onnxruntime/core/providers/cpu/ml/svmclassifier.h b/onnxruntime/core/providers/cpu/ml/svmclassifier.h index e2ba20e08e30e..e0303c10f670e 100644 --- a/onnxruntime/core/providers/cpu/ml/svmclassifier.h +++ b/onnxruntime/core/providers/cpu/ml/svmclassifier.h @@ -18,7 +18,7 @@ class SVMCommon { SVMCommon(const OpKernelInfo& info) : kernel_type_(MakeKernel(info.GetAttrOrDefault("kernel_type", "LINEAR"))) { std::vector kernel_params; - ORT_ENFORCE(info.GetAttrs("kernel_params", kernel_params).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("kernel_params", kernel_params)); if (!kernel_params.empty()) { gamma_ = kernel_params[0]; diff --git a/onnxruntime/core/providers/cpu/ml/svmregressor.cc b/onnxruntime/core/providers/cpu/ml/svmregressor.cc index 68367470a6176..48792be5ffdbd 100644 --- a/onnxruntime/core/providers/cpu/ml/svmregressor.cc +++ b/onnxruntime/core/providers/cpu/ml/svmregressor.cc @@ -19,10 +19,10 @@ SVMRegressor::SVMRegressor(const OpKernelInfo& info) support_vectors_(info.GetAttrsOrDefault("support_vectors")), post_transform_(MakeTransform(info.GetAttrOrDefault("post_transform", "NONE"))) { int64_t vector_count = 0; - ORT_ENFORCE(info.GetAttr("n_supports", &vector_count).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttr("n_supports", &vector_count)); vector_count_ = narrow(vector_count); - ORT_ENFORCE(info.GetAttrs("rho", rho_).IsOK()); - ORT_ENFORCE(info.GetAttrs("coefficients", coefficients_).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("rho", rho_)); + ORT_THROW_IF_ERROR(info.GetAttrs("coefficients", coefficients_)); ORT_ENFORCE(!coefficients_.empty()); auto onec = info.GetAttrOrDefault("one_class", 0); diff --git a/onnxruntime/core/providers/cpu/nn/roi_pool.h b/onnxruntime/core/providers/cpu/nn/roi_pool.h index c916d0b05c3e9..1719ee5055ed7 100644 --- a/onnxruntime/core/providers/cpu/nn/roi_pool.h +++ b/onnxruntime/core/providers/cpu/nn/roi_pool.h @@ -14,7 +14,7 @@ class RoiPool : public OpKernel { public: RoiPool(const OpKernelInfo& info) : OpKernel(info) { std::vector pooled_shape; - ORT_ENFORCE(info.GetAttrs("pooled_shape", pooled_shape).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("pooled_shape", pooled_shape)); ORT_ENFORCE(pooled_shape.size() == 2); pooled_height_ = pooled_shape[0]; diff --git a/onnxruntime/core/providers/cpu/nn/unpool.h b/onnxruntime/core/providers/cpu/nn/unpool.h index 81733449c664d..b51241870b549 100644 --- a/onnxruntime/core/providers/cpu/nn/unpool.h +++ b/onnxruntime/core/providers/cpu/nn/unpool.h @@ -13,8 +13,7 @@ namespace onnxruntime { class MaxUnpool : public OpKernel { public: MaxUnpool(const OpKernelInfo& info) : OpKernel(info) { - ORT_ENFORCE(info.GetAttrs("kernel_shape", kernel_shape_).IsOK(), - "No kernel shape is set."); + ORT_THROW_IF_ERROR(info.GetAttrs("kernel_shape", kernel_shape_)); num_inputs_ = OpKernel::Node().InputDefs().size(); diff --git a/onnxruntime/core/providers/cpu/tensor/upsamplebase.h b/onnxruntime/core/providers/cpu/tensor/upsamplebase.h index 0b3ce6f477843..a0e7ca1084fef 100644 --- a/onnxruntime/core/providers/cpu/tensor/upsamplebase.h +++ b/onnxruntime/core/providers/cpu/tensor/upsamplebase.h @@ -77,7 +77,7 @@ class UpsampleBase { auto input_count = info.GetInputCount(); if (input_count == 1) { // opset < 10 - ORT_ENFORCE(info.GetAttrs("scales", scales_).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("scales", scales_)); ORT_THROW_IF_ERROR(ScalesValidation(scales_, mode_)); scales_cached_ = true; } diff --git a/onnxruntime/core/providers/js/operators/conv.h b/onnxruntime/core/providers/js/operators/conv.h index 3a01a4aa46be4..8f438a319f138 100644 --- a/onnxruntime/core/providers/js/operators/conv.h +++ b/onnxruntime/core/providers/js/operators/conv.h @@ -30,7 +30,7 @@ class ConvBase : public JsKernel { } if (is_fused_conv) { ORT_THROW_IF_ERROR(info.GetAttr("activation", &conv_attrs_.activation)); - ORT_ENFORCE(info.GetAttrs("activation_params", activation_params).IsOK()); + ORT_THROW_IF_ERROR(info.GetAttrs("activation_params", activation_params)); } else { conv_attrs_.activation = info.GetAttrOrDefault("activation", ""); activation_params = info.GetAttrsOrDefault("activation_params", activation_params);