From 8df3e87b7063fc071c0d5fe35384d966915a6e87 Mon Sep 17 00:00:00 2001 From: ybrnathan <7902510+ybrnathan@users.noreply.github.com> Date: Fri, 27 Sep 2019 13:04:08 -0700 Subject: [PATCH] OpSet 11 Update for Neg Axis (9 Ops) (#1893) * OpSet 11 Update for Neg Axis: scan, flatten, compress, concat, gather, slice, split, squeeze, unsqueeze * fix flatten op test * Fix flatten and Squeeze * fix test cases * add gather neg indices to both cpu and cuda * Exclude nGraph from neg axis test * re-enable test cases * Fix test cases --- .../core/providers/cpu/controlflow/scan_9.cc | 12 +- .../providers/cpu/cpu_execution_provider.cc | 127 ++++++++++++------ onnxruntime/core/providers/cpu/nn/flatten.cc | 12 +- onnxruntime/core/providers/cpu/nn/flatten.h | 13 +- .../core/providers/cpu/tensor/compress.cc | 26 +++- .../core/providers/cpu/tensor/concat.cc | 10 +- .../core/providers/cpu/tensor/gather.cc | 19 ++- .../core/providers/cpu/tensor/slice.cc | 30 ++++- .../core/providers/cpu/tensor/split.cc | 14 +- .../core/providers/cpu/tensor/squeeze.cc | 11 +- .../core/providers/cpu/tensor/squeeze.h | 17 ++- .../core/providers/cpu/tensor/unsqueeze.cc | 15 ++- .../core/providers/cuda/tensor/gather_impl.cu | 1 + onnxruntime/test/onnx/main.cc | 27 +--- .../test/providers/cpu/nn/flatten_op_test.cc | 10 +- .../providers/cpu/tensor/compress_op.test.cc | 18 +++ .../providers/cpu/tensor/gather_op_test.cc | 18 +++ .../providers/cpu/tensor/slice_op.test.cc | 12 ++ .../providers/cpu/tensor/squeeze_op_test.cc | 13 ++ .../providers/cpu/tensor/unsqueeze_op_test.cc | 10 ++ .../test/python/onnx_backend_test_series.py | 7 - 21 files changed, 326 insertions(+), 96 deletions(-) diff --git a/onnxruntime/core/providers/cpu/controlflow/scan_9.cc b/onnxruntime/core/providers/cpu/controlflow/scan_9.cc index 741f6bfc46..c39afbf958 100644 --- a/onnxruntime/core/providers/cpu/controlflow/scan_9.cc +++ b/onnxruntime/core/providers/cpu/controlflow/scan_9.cc @@ -485,11 +485,19 @@ Status ScanImpl::TransposeOutput() { return status; } +ONNX_CPU_OPERATOR_VERSIONED_KERNEL(Scan, + 9, + 10, + KernelDefBuilder() + .TypeConstraint("I", DataTypeImpl::GetTensorType()) + .TypeConstraint("V", DataTypeImpl::AllTensorTypes()), + Scan<9>); + +// Opset 11 starts to support Neg Axis. ONNX_CPU_OPERATOR_KERNEL(Scan, - 9, + 11, KernelDefBuilder() .TypeConstraint("I", DataTypeImpl::GetTensorType()) .TypeConstraint("V", DataTypeImpl::AllTensorTypes()), Scan<9>); - } // namespace onnxruntime diff --git a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc index 53edf49d03..2c5e8a9e05 100644 --- a/onnxruntime/core/providers/cpu/cpu_execution_provider.cc +++ b/onnxruntime/core/providers/cpu/cpu_execution_provider.cc @@ -116,7 +116,7 @@ class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDoma class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Conv); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, ConvTranspose); class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 8, Flatten); -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Flatten); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, 10, Flatten); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 6, InstanceNormalization); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, LpNormalization); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, LRN); @@ -172,8 +172,8 @@ class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOn class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 6, 9, float, Cast); class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 6, 9, double, Cast); class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 6, 9, MLFloat16, Cast); -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 4, Concat); -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Gather); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 4, 10, Concat); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, Gather); class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 9, Dropout); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Identity); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 2, Pad); @@ -196,11 +196,11 @@ class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOn class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 9, string, Slice); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, SpaceToDepth); class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, DepthToSpace); -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 2, Split); -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Squeeze); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 2, 10, Split); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, Squeeze); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 6, Tile); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Transpose); -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, Unsqueeze); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, Unsqueeze); class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 9, float, Upsample); class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 9, int32_t, Upsample); class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 7, 9, uint8_t, Upsample); @@ -221,7 +221,7 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, If) class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 1, 10, Loop); // Opset 9 -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Compress); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, 10, Compress); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, ConstantOfShape); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, MeanVarianceNormalization); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, int32_t, Greater); @@ -250,7 +250,7 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Cos class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Asinh); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Acosh); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Atanh); -class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, Scan); +class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, 10, Scan); class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, 10, Scatter); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, string, TfIdfVectorizer); class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 9, int32_t, TfIdfVectorizer); @@ -284,19 +284,19 @@ class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, int8_t, MatMulInteger); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, ConvInteger); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, QLinearConv); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, bool, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, float, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, double, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, MLFloat16, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, uint8_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, uint16_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, uint32_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, uint64_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, int8_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, int16_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, int32_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, int64_t, Slice); -class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, string, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, bool, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, float, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, double, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, MLFloat16, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, uint8_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, uint16_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, uint32_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, uint64_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, int8_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, int16_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, int32_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, int64_t, Slice); +class ONNX_OPERATOR_VERSIONED_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, string, Slice); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, Dropout); class ONNX_OPERATOR_VERSIONED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, 10, NonMaxSuppression); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 10, IsInf); @@ -323,10 +323,32 @@ class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Lo class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Softmax); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Loop); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, DepthToSpace); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Scan); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Flatten); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Compress); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Concat); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Gather); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, bool, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, float, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, double, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, MLFloat16, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, uint8_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, uint16_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, uint32_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, uint64_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, int8_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, int16_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, int32_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, int64_t, Slice); +class ONNX_OPERATOR_TYPED_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, string, Slice); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Split); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Squeeze); +class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Unsqueeze); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, Det); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, ScatterElements); class ONNX_OPERATOR_KERNEL_CLASS_NAME(kCpuExecutionProvider, kOnnxDomain, 11, NonMaxSuppression); + void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { static const BuildKernelCreateInfoFn function_table[] = { BuildKernelCreateInfo, @@ -427,7 +449,7 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, - BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, @@ -483,8 +505,8 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, @@ -507,11 +529,11 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, - BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, @@ -532,7 +554,7 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, // Opset 9 - BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, @@ -561,7 +583,7 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, - BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, @@ -595,19 +617,19 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, - BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, @@ -634,6 +656,27 @@ void RegisterOnnxOperatorKernels(KernelRegistry& kernel_registry) { BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, + BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, BuildKernelCreateInfo, diff --git a/onnxruntime/core/providers/cpu/nn/flatten.cc b/onnxruntime/core/providers/cpu/nn/flatten.cc index d267848fcc..515d726d52 100644 --- a/onnxruntime/core/providers/cpu/nn/flatten.cc +++ b/onnxruntime/core/providers/cpu/nn/flatten.cc @@ -13,9 +13,19 @@ ONNX_CPU_OPERATOR_VERSIONED_KERNEL( .TypeConstraint("T", DataTypeImpl::AllTensorTypes()), Flatten); -ONNX_CPU_OPERATOR_KERNEL( +ONNX_CPU_OPERATOR_VERSIONED_KERNEL( Flatten, 9, + 10, + KernelDefBuilder() + .Alias(0, 0) + .TypeConstraint("T", DataTypeImpl::AllTensorTypes()), + Flatten); + +// Opset 11 starts to support Neg Axis. +ONNX_CPU_OPERATOR_KERNEL( + Flatten, + 11, KernelDefBuilder() .Alias(0, 0) .TypeConstraint("T", DataTypeImpl::AllTensorTypes()), diff --git a/onnxruntime/core/providers/cpu/nn/flatten.h b/onnxruntime/core/providers/cpu/nn/flatten.h index ed650554f8..ccc5d09a61 100644 --- a/onnxruntime/core/providers/cpu/nn/flatten.h +++ b/onnxruntime/core/providers/cpu/nn/flatten.h @@ -7,6 +7,7 @@ #include "core/framework/op_kernel.h" #include "gsl/gsl_util" #include "core/providers/cpu/tensor/utils.h" +#include "core/providers/common.h" namespace onnxruntime { @@ -21,9 +22,17 @@ class Flatten final : public OpKernel { if (X == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch"); const TensorShape& X_shape = X->Shape(); - ORT_ENFORCE(gsl::narrow_cast(X_shape.NumDimensions()) >= axis_, "The rank of input tensor must be >= axis"); + auto axis = axis_; + + // Valid axis range is [-rank, rank] instead of [-rank, rank-1], add additional check to only handle neg axis case. + if (axis < 0) + { + axis = HandleNegativeAxis(axis, X_shape.NumDimensions()); // handle negative and enforce axis is valid + } + + ORT_ENFORCE(gsl::narrow_cast(X_shape.NumDimensions()) >= axis, "The rank of input tensor must be >= axis"); - Tensor* Y = context->Output(0, TensorShape({X_shape.SizeToDimension(axis_), X_shape.SizeFromDimension(axis_)})); + Tensor* Y = context->Output(0, TensorShape({X_shape.SizeToDimension(axis), X_shape.SizeFromDimension(axis)})); CopyCpuTensor(X, Y); diff --git a/onnxruntime/core/providers/cpu/tensor/compress.cc b/onnxruntime/core/providers/cpu/tensor/compress.cc index b3f82bf9fd..d4c7168ffd 100644 --- a/onnxruntime/core/providers/cpu/tensor/compress.cc +++ b/onnxruntime/core/providers/cpu/tensor/compress.cc @@ -2,13 +2,23 @@ // Licensed under the MIT License. #include "core/providers/cpu/tensor/compress.h" +#include "core/providers/common.h" using namespace ::onnxruntime::common; namespace onnxruntime { -ONNX_CPU_OPERATOR_KERNEL( +ONNX_CPU_OPERATOR_VERSIONED_KERNEL( Compress, 9, + 10, + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::AllTensorTypes()) + .TypeConstraint("T1", DataTypeImpl::GetTensorType()), + Compress); + +// Opset 11 starts to support Neg Axis. +ONNX_CPU_OPERATOR_KERNEL( + Compress, + 11, KernelDefBuilder().TypeConstraint("T", DataTypeImpl::AllTensorTypes()) .TypeConstraint("T1", DataTypeImpl::GetTensorType()), Compress); @@ -17,8 +27,10 @@ Status Compress::Compute(OpKernelContext* ctx) const { const auto* input_tensor = ctx->Input(0); size_t rank = input_tensor->Shape().NumDimensions(); auto& input_dimensions = input_tensor->Shape().GetDims(); + int64_t axis = axis_; if (has_axis_) { - ORT_ENFORCE(axis_ < static_cast(rank), "axis greater than input data dimension!"); + axis = HandleNegativeAxis(axis, rank); // handle negative and enforce axis is valid + ORT_ENFORCE(axis < static_cast(rank), "axis greater than input data dimension!"); } const auto* condition = ctx->Input(1); @@ -27,7 +39,7 @@ Status Compress::Compute(OpKernelContext* ctx) const { int64_t positive_condition_count = 0; // if has axis, we need to compress on dimension[axis], otherwise compress on the flattened input data - int64_t compress_input_length = has_axis_ ? input_dimensions[axis_] : input_tensor->Shape().Size(); + int64_t compress_input_length = has_axis_ ? input_dimensions[axis] : input_tensor->Shape().Size(); int64_t valid_condition_length = compress_input_length < condition_length ? compress_input_length : condition_length; // Figure out output shape @@ -39,7 +51,7 @@ Status Compress::Compute(OpKernelContext* ctx) const { std::vector output_dims(input_dimensions); if (has_axis_) { - output_dims[axis_] = positive_condition_count; + output_dims[axis] = positive_condition_count; } else { output_dims.resize(1); output_dims[0] = positive_condition_count; @@ -60,14 +72,14 @@ Status Compress::Compute(OpKernelContext* ctx) const { if (has_axis_) { int64_t axes_left_stride = 1; int64_t axes_right_stride = 1; - for (int i = 0; i < axis_; ++i) { + for (int i = 0; i < axis; ++i) { axes_left_stride *= input_dimensions[i]; } - for (auto i = static_cast(axis_ + 1); i < rank; ++i) { + for (auto i = static_cast(axis + 1); i < rank; ++i) { axes_right_stride *= input_dimensions[i]; } - int64_t axes_included_right_stride = axes_right_stride * input_dimensions[axis_]; + int64_t axes_included_right_stride = axes_right_stride * input_dimensions[axis]; int64_t axes_included_right_stride_bytes = axes_included_right_stride * element_bytes; ORT_ENFORCE(axes_right_stride >= 0 && static_cast(axes_right_stride) < std::numeric_limits::max()); diff --git a/onnxruntime/core/providers/cpu/tensor/concat.cc b/onnxruntime/core/providers/cpu/tensor/concat.cc index 0a26ea2a0d..cd797daeba 100644 --- a/onnxruntime/core/providers/cpu/tensor/concat.cc +++ b/onnxruntime/core/providers/cpu/tensor/concat.cc @@ -6,9 +6,17 @@ namespace onnxruntime { -ONNX_CPU_OPERATOR_KERNEL( +ONNX_CPU_OPERATOR_VERSIONED_KERNEL( Concat, 4, + 10, + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::AllTensorTypes()), + Concat); + +// Opset 11 starts to support Neg Axis. +ONNX_CPU_OPERATOR_KERNEL( + Concat, + 11, KernelDefBuilder().TypeConstraint("T", DataTypeImpl::AllTensorTypes()), Concat); diff --git a/onnxruntime/core/providers/cpu/tensor/gather.cc b/onnxruntime/core/providers/cpu/tensor/gather.cc index 817bf6794e..a9a97848bf 100644 --- a/onnxruntime/core/providers/cpu/tensor/gather.cc +++ b/onnxruntime/core/providers/cpu/tensor/gather.cc @@ -7,9 +7,16 @@ namespace onnxruntime { -ONNX_CPU_OPERATOR_KERNEL( +ONNX_CPU_OPERATOR_VERSIONED_KERNEL( Gather, 1, + 10, + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::AllTensorTypes()).TypeConstraint("Tind", std::vector{DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType()}), + Gather); + +ONNX_CPU_OPERATOR_KERNEL( + Gather, + 11, KernelDefBuilder().TypeConstraint("T", DataTypeImpl::AllTensorTypes()).TypeConstraint("Tind", std::vector{DataTypeImpl::GetTensorType(), DataTypeImpl::GetTensorType()}), Gather); @@ -49,11 +56,14 @@ Status GatherCopyData(const Tensor* indices_tensor, const uint8_t* src_base, uin // Check the indices first in case there's a out of bound index. // We can't merge this code in the omp loop below as omp does not allow return in the loop + auto axis_dim_limit = input_data_shape[axis]; + for (int64_t i = 0; i < N; ++i) { Tin idx = indices_data[i]; - if (idx < 0 || idx >= input_data_shape[axis]) { - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "indices element out of data bounds, idx=", idx, - " data_dim=", input_data_shape[axis]); + if (idx < -axis_dim_limit || idx >= axis_dim_limit) { + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, + "indices element out of data bounds, idx=", idx, + " must be within the inclusive range [", -axis_dim_limit,",", axis_dim_limit - 1, "]"); } } @@ -67,6 +77,7 @@ Status GatherCopyData(const Tensor* indices_tensor, const uint8_t* src_base, uin const int64_t src_offset_batch = batch * data_batch_bytes; const int64_t dst_offset_batch = batch * gathered_batch_bytes; Tin idx = indices_data[i]; + idx = idx < 0 ? idx + static_cast(axis_dim_limit) : idx; const int64_t src_offset = src_offset_batch + idx * block_size; const int64_t dst_offset = dst_offset_batch + i * block_size; diff --git a/onnxruntime/core/providers/cpu/tensor/slice.cc b/onnxruntime/core/providers/cpu/tensor/slice.cc index 6ca011e73c..4865bfcf31 100644 --- a/onnxruntime/core/providers/cpu/tensor/slice.cc +++ b/onnxruntime/core/providers/cpu/tensor/slice.cc @@ -3,6 +3,7 @@ #include "core/providers/cpu/tensor/slice.h" #include "core/providers/cpu/tensor/utils.h" +#include "core/providers/common.h" #include #include @@ -33,9 +34,10 @@ ADD_TYPED_SLICE_V9_OP(bool); ADD_TYPED_SLICE_V9_OP(string); #define ADD_TYPED_SLICE_V10_OP(data_type) \ - ONNX_CPU_OPERATOR_TYPED_KERNEL( \ + ONNX_CPU_OPERATOR_VERSIONED_TYPED_KERNEL( \ Slice, \ 10, \ + 10, \ data_type, \ KernelDefBuilder().TypeConstraint("T", DataTypeImpl::GetTensorType()) \ .TypeConstraint("Tind", {DataTypeImpl::GetTensorType(), \ @@ -56,6 +58,30 @@ ADD_TYPED_SLICE_V10_OP(MLFloat16); ADD_TYPED_SLICE_V10_OP(bool); ADD_TYPED_SLICE_V10_OP(string); +#define ADD_TYPED_SLICE_V11_OP(data_type) \ + ONNX_CPU_OPERATOR_TYPED_KERNEL( \ + Slice, \ + 11, \ + data_type, \ + KernelDefBuilder().TypeConstraint("T", DataTypeImpl::GetTensorType()) \ + .TypeConstraint("Tind", {DataTypeImpl::GetTensorType(), \ + DataTypeImpl::GetTensorType()}), \ + Slice); + +ADD_TYPED_SLICE_V11_OP(uint8_t); +ADD_TYPED_SLICE_V11_OP(uint16_t); +ADD_TYPED_SLICE_V11_OP(uint32_t); +ADD_TYPED_SLICE_V11_OP(uint64_t); +ADD_TYPED_SLICE_V11_OP(int8_t); +ADD_TYPED_SLICE_V11_OP(int16_t); +ADD_TYPED_SLICE_V11_OP(int32_t); +ADD_TYPED_SLICE_V11_OP(int64_t); +ADD_TYPED_SLICE_V11_OP(float); +ADD_TYPED_SLICE_V11_OP(double); +ADD_TYPED_SLICE_V11_OP(MLFloat16); +ADD_TYPED_SLICE_V11_OP(bool); +ADD_TYPED_SLICE_V11_OP(string); + namespace { // std::clamp doesn't exist until C++17 so create a local version template @@ -85,7 +111,7 @@ Status SliceBase::PrepareForCompute(const std::vector& raw_starts, std::unordered_set unique_axes; const auto& dimension_count = input_dimensions.size(); for (size_t axis_index = 0, axes_count = axes.size(); axis_index < axes_count; ++axis_index) { - auto axis = axes[axis_index] < 0 ? axes[axis_index] + static_cast(dimension_count) : axes[axis_index]; + auto axis = HandleNegativeAxis(axes[axis_index], dimension_count); // handle negative and enforce axis is valid if (axis >= static_cast(dimension_count) || axis < 0) return Status(ONNXRUNTIME, INVALID_ARGUMENT, "'axes' has an axis outside of the tensor dimension count"); if (unique_axes.find(axis) != unique_axes.end()) diff --git a/onnxruntime/core/providers/cpu/tensor/split.cc b/onnxruntime/core/providers/cpu/tensor/split.cc index cbe8cf7c2e..7272d12471 100644 --- a/onnxruntime/core/providers/cpu/tensor/split.cc +++ b/onnxruntime/core/providers/cpu/tensor/split.cc @@ -10,9 +10,21 @@ namespace onnxruntime { -ONNX_CPU_OPERATOR_KERNEL( +ONNX_CPU_OPERATOR_VERSIONED_KERNEL( Split, 2, + 10, + KernelDefBuilder().TypeConstraint("T", + std::vector{ + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType(), + DataTypeImpl::GetTensorType()}), + Split); + +// Opset 11 starts to support Neg Axis. +ONNX_CPU_OPERATOR_KERNEL( + Split, + 11, KernelDefBuilder().TypeConstraint("T", std::vector{ DataTypeImpl::GetTensorType(), diff --git a/onnxruntime/core/providers/cpu/tensor/squeeze.cc b/onnxruntime/core/providers/cpu/tensor/squeeze.cc index b29af6ac67..defcb83873 100644 --- a/onnxruntime/core/providers/cpu/tensor/squeeze.cc +++ b/onnxruntime/core/providers/cpu/tensor/squeeze.cc @@ -5,12 +5,21 @@ namespace onnxruntime { -ONNX_CPU_OPERATOR_KERNEL( +ONNX_CPU_OPERATOR_VERSIONED_KERNEL( Squeeze, 1, + 10, KernelDefBuilder() .TypeConstraint("T", DataTypeImpl::AllTensorTypes()) .Alias(0, 0), Squeeze); +// Opset 11 starts to support Neg Axis. +ONNX_CPU_OPERATOR_KERNEL( + Squeeze, + 11, + KernelDefBuilder() + .TypeConstraint("T", DataTypeImpl::AllTensorTypes()) + .Alias(0, 0), + Squeeze); } // namespace onnxruntime diff --git a/onnxruntime/core/providers/cpu/tensor/squeeze.h b/onnxruntime/core/providers/cpu/tensor/squeeze.h index f6489e5cf2..7a3d82f436 100644 --- a/onnxruntime/core/providers/cpu/tensor/squeeze.h +++ b/onnxruntime/core/providers/cpu/tensor/squeeze.h @@ -6,6 +6,7 @@ #include "core/common/common.h" #include "core/framework/op_kernel.h" #include "utils.h" +#include "core/providers/common.h" namespace onnxruntime { @@ -29,9 +30,19 @@ class SqueezeBase { const TensorShape& axes) { size_t j = 0; std::vector output_shape; - for (size_t i = 0; i < input_shape.NumDimensions(); ++i) { - if ((j < axes.NumDimensions() && axes[j] == static_cast(i)) || - (axes.NumDimensions() == 0 && input_shape[i] == 1)) { + auto num_dimensions = input_shape.NumDimensions(); + + // Handle negtive axis, then resort and uniq. + std::vector axes_corrected(axes.NumDimensions()); + for (size_t i = 0; i < axes.NumDimensions(); i++) { + axes_corrected[i] = HandleNegativeAxis(axes[i], num_dimensions); + } + std::sort(axes_corrected.begin(), axes_corrected.end()); + axes_corrected.erase(std::unique(axes_corrected.begin(), axes_corrected.end()), axes_corrected.end()); + + for (size_t i = 0; i < num_dimensions; ++i) { + if ((j < axes_corrected.size() && axes_corrected[j] == static_cast(i)) || + (axes_corrected.size() == 0 && input_shape[i] == 1)) { ORT_ENFORCE(input_shape[i] == 1, "Dimension of input ", i, " must be 1 instead of ", input_shape[i], ". shape=", input_shape); ++j; diff --git a/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc b/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc index f39472441b..58a7caeaa4 100644 --- a/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc +++ b/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc @@ -3,13 +3,24 @@ #include "core/providers/cpu/tensor/unsqueeze.h" #include "utils.h" +#include "core/providers/common.h" + using namespace ::onnxruntime::common; namespace onnxruntime { -ONNX_CPU_OPERATOR_KERNEL( +ONNX_CPU_OPERATOR_VERSIONED_KERNEL( Unsqueeze, 1, + 10, + KernelDefBuilder() + .Alias(0, 0) + .TypeConstraint("T", DataTypeImpl::AllTensorTypes()), + Unsqueeze); + +ONNX_CPU_OPERATOR_KERNEL( + Unsqueeze, + 11, KernelDefBuilder() .Alias(0, 0) .TypeConstraint("T", DataTypeImpl::AllTensorTypes()), @@ -26,6 +37,8 @@ Status UnsqueezeBase::PrepareCompute(OpKernelContext* ctx, Prepare& p) const { // Set all axes_ indices to 1 in output_dims and check for duplicates for (int64_t axis : axes_) { + // Valid axis range is [0, output_rank - 1] + axis = HandleNegativeAxis(axis, output_dims.size()); if (axis < 0 || axis >= static_cast(output_dims.size())) return Status(ONNXRUNTIME, INVALID_ARGUMENT, "'axes' has an out of range axis"); if (output_dims[axis] != 0) diff --git a/onnxruntime/core/providers/cuda/tensor/gather_impl.cu b/onnxruntime/core/providers/cuda/tensor/gather_impl.cu index bcc0ce73af..1fb7cb0b88 100644 --- a/onnxruntime/core/providers/cuda/tensor/gather_impl.cu +++ b/onnxruntime/core/providers/cuda/tensor/gather_impl.cu @@ -24,6 +24,7 @@ __global__ void _GatherKernel( div_strides[1].divmod(block_offset, indices_index, offset); int block_size = div_strides[1].d_; int64_t idx = indices_data[indices_index]; + idx = idx < 0 ? idx + indices_max : idx; if (idx < 0 || idx >= indices_max) { output_data[id] = 0; return; diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index dbbfb3a8fa..5ab1b22444 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -445,16 +445,6 @@ int real_main(int argc, char* argv[], Ort::Env& env) { {"sequence_model3", "SequenceConstruct not implemented yet"}, {"sequence_model2", "SequenceConstruct not implemented yet"}, {"sequence_model1", "Sequence* not implemented yet"}, - {"unsqueeze_unsorted_axes", "Unsqueeze not implemented yet"}, - {"unsqueeze_two_axes", "Unsqueeze not implemented yet"}, - {"unsqueeze_three_axes", "Unsqueeze not implemented yet"}, - {"unsqueeze_negative_axes", "Unsqueeze not implemented yet"}, - {"unsqueeze_axis_3", "Unsqueeze not implemented yet"}, - {"unsqueeze_axis_2", "Unsqueeze not implemented yet"}, - {"unsqueeze_axis_1", "Unsqueeze not implemented yet"}, - {"unsqueeze_axis_0", "Unsqueeze not implemented yet"}, - {"squeeze_negative_axes", "Squeeze(11) not implemented yet"}, - {"slice_negative_axes", "Slice(11) not implemented yet"}, {"scatter_elements_with_negative_indices", "ScatterElements(11) not implemented yet"}, {"reduce_sum_square_negative_axes_keepdims_random", "ReduceSumSquare(11) not implemented yet"}, {"reduce_sum_square_negative_axes_keepdims_example", "ReduceSumSquare(11) not implemented yet"}, @@ -480,20 +470,9 @@ int real_main(int argc, char* argv[], Ort::Env& env) { {"onehot_with_axis", "OneHot(11) not implemented yet"}, {"onehot_negative_indices", "OneHot(11) not implemented yet"}, {"gather_elements_negative_indices", "GatherElements(11) not implemented yet"}, - {"flatten_negative_axis4", "Flatten(11) not implemented yet"}, - {"flatten_negative_axis3", "Flatten(11) not implemented yet"}, - {"flatten_negative_axis2", "Flatten(11) not implemented yet"}, - {"flatten_negative_axis1", "Flatten(11) not implemented yet"}, {"reflect_pad", "Pad(11) not implemented yet"}, {"edge_pad", "Pad(11) not implemented yet"}, {"constant_pad", "Pad(11) not implemented yet"}, - {"concat_3d_axis_negative_3", "Concat(11) not implemented yet"}, - {"concat_3d_axis_negative_2", "Concat(11) not implemented yet"}, - {"concat_3d_axis_negative_1", "Concat(11) not implemented yet"}, - {"concat_2d_axis_negative_2", "Concat(11) not implemented yet"}, - {"concat_2d_axis_negative_1", "Concat(11) not implemented yet"}, - {"concat_1d_axis_negative_1", "Concat(11) not implemented yet"}, - {"compress_negative_axis", "Compress(11) not implemented yet"}, {"bitshift_right_uint8", "BitShift(11) not implemented yet"}, {"bitshift_right_uint64", "BitShift(11) not implemented yet"}, {"bitshift_right_uint32", "BitShift(11) not implemented yet"}, @@ -523,6 +502,12 @@ int real_main(int argc, char* argv[], Ort::Env& env) { broken_tests.insert({"argmin_negative_axis_keepdims_random", "not implemented yet for opset 11"}); broken_tests.insert({"gemm_default_no_bias", "not implemented yet for opset 11"}); broken_tests.insert({"hardmax_negative_axis", "not implemented yet for opset 11"}); + broken_tests.insert({"flatten_negative_axis1", "not implemented yet for opset 11"}); + broken_tests.insert({"flatten_negative_axis2", "not implemented yet for opset 11"}); + broken_tests.insert({"flatten_negative_axis3", "not implemented yet for opset 11"}); + broken_tests.insert({"flatten_negative_axis4", "not implemented yet for opset 11"}); + broken_tests.insert({"squeeze_negative_axes", "not implemented yet for opset 11"}); + broken_tests.insert({"unsqueeze_negative_axes", "not implemented yet for opset 11"}); #endif #ifdef USE_MKLDNN diff --git a/onnxruntime/test/providers/cpu/nn/flatten_op_test.cc b/onnxruntime/test/providers/cpu/nn/flatten_op_test.cc index 62bfcebcc2..e5902287b1 100644 --- a/onnxruntime/test/providers/cpu/nn/flatten_op_test.cc +++ b/onnxruntime/test/providers/cpu/nn/flatten_op_test.cc @@ -11,7 +11,7 @@ namespace test { class FlattenOpTest : public testing::Test { public: - FlattenOpTest() : test_("Flatten"), data0_(120, 1.0f) {} + FlattenOpTest() : test_("Flatten", 11), data0_(120, 1.0f) {} protected: OpTester test_; @@ -56,5 +56,13 @@ TEST_F(FlattenOpTest, Flatten_axis4) { test_.AddOutput("output", {16L, 1L}, data1_); test_.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } + +TEST_F(FlattenOpTest, Flatten_neg_axis3) { + test_.AddAttribute("axis", -1L); + test_.AddInput("data", {2L, 3L, 4L, 5L}, data0_); + test_.AddOutput("output", {24L, 5L}, data0_); + test_.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider, kNGraphExecutionProvider}); +} + } // namespace test } // namespace onnxruntime diff --git a/onnxruntime/test/providers/cpu/tensor/compress_op.test.cc b/onnxruntime/test/providers/cpu/tensor/compress_op.test.cc index 5178a3382a..7f2782ca06 100644 --- a/onnxruntime/test/providers/cpu/tensor/compress_op.test.cc +++ b/onnxruntime/test/providers/cpu/tensor/compress_op.test.cc @@ -153,5 +153,23 @@ TEST(CompressTest, Compress_default_axis_string) { test.Run(); } +TEST(CompressTest, Compress_3dims_neg_axis) { + OpTester test("Compress", 11); + + test.AddAttribute("axis", int64_t(-2)); + + test.AddInput("input", {2, 2, 3}, { + 1.0f, 2.0f, 3.0f, + 4.0f, 5.0f, 6.0f, + + 7.0f, 8.0f, 9.0f, + 10.0f, 11.0f, 12.0f}); + test.AddInput("condition", {2}, {0, 1}); + test.AddOutput("output", {2, 1, 3}, { + 4.0f, 5.0f, 6.0f, + 10.0f, 11.0f, 12.0f}); + test.Run(); +} + } // namespace Test } // namespace onnxruntime diff --git a/onnxruntime/test/providers/cpu/tensor/gather_op_test.cc b/onnxruntime/test/providers/cpu/tensor/gather_op_test.cc index 65801b8b01..93d4b06f91 100644 --- a/onnxruntime/test/providers/cpu/tensor/gather_op_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/gather_op_test.cc @@ -305,5 +305,23 @@ TEST(GatherOpTest, Gather_perf) { test.AddOutput("output", {800, 1, 100}, output); test.Run(); } + +TEST(GatherOpTest, Gather_axis1_neg_indices2d_int8) { + OpTester test("Gather", 11); + test.AddAttribute("axis", 1LL); + test.AddInput("data", {3, 3}, + {0, 1, 2, + 10, 11, 12, + 20, 21, 22}); + test.AddInput("indices", {2, 2}, + {-2, -3, + -1, -2}); + test.AddOutput("output", {3, 2, 2}, + {1, 0, 2, 1, + 11, 10, 12, 11, + 21, 20, 22, 21}); + test.Run(); +} + } // namespace test } // namespace onnxruntime diff --git a/onnxruntime/test/providers/cpu/tensor/slice_op.test.cc b/onnxruntime/test/providers/cpu/tensor/slice_op.test.cc index 83ee06bed5..9139538eb5 100644 --- a/onnxruntime/test/providers/cpu/tensor/slice_op.test.cc +++ b/onnxruntime/test/providers/cpu/tensor/slice_op.test.cc @@ -528,5 +528,17 @@ TEST(SliceTest, OptionalAxesInputAloneMissing) { testv10.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } +TEST(SliceTest, Slice2D_ReverseSubsetOfNegAxes_1) { + RunSliceTest({2, 2}, + {1.0f, 2.0f, 3.0f, 4.0f}, + {-1}, + {std::numeric_limits::max()}, + {-1}, // axis = -1 only + {-1}, + {2, 2}, + {2.0f, 1.0f, 4.0f, 3.0f}, + true); +} + } // namespace test } // namespace onnxruntime diff --git a/onnxruntime/test/providers/cpu/tensor/squeeze_op_test.cc b/onnxruntime/test/providers/cpu/tensor/squeeze_op_test.cc index 4287d1369b..b45784266b 100644 --- a/onnxruntime/test/providers/cpu/tensor/squeeze_op_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/squeeze_op_test.cc @@ -94,5 +94,18 @@ TEST(SqueezeOpTest, BadAxes) { // Expect failure. test.Run(OpTester::ExpectResult::kExpectFailure, "Dimension of input 0 must be 1 instead of 3", {kTensorrtExecutionProvider}); } + +TEST(SqueezeOpTest, SqueezeNegAxis_2) { + OpTester test("Squeeze", 11); + test.AddAttribute("axes", std::vector{0, -3, -2}); + test.AddInput("data", {1, 4, 1, 1, 2}, + std::vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}); + test.AddOutput("squeezed", {4, 2}, + std::vector{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f}); + + // nGraph does not support neg axis. + test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kNGraphExecutionProvider}); +} + } // namespace test } // namespace onnxruntime diff --git a/onnxruntime/test/providers/cpu/tensor/unsqueeze_op_test.cc b/onnxruntime/test/providers/cpu/tensor/unsqueeze_op_test.cc index 93ec7832ec..39a629d8d3 100644 --- a/onnxruntime/test/providers/cpu/tensor/unsqueeze_op_test.cc +++ b/onnxruntime/test/providers/cpu/tensor/unsqueeze_op_test.cc @@ -63,5 +63,15 @@ TEST(TensorOpTest, Unsqueeze_OutOfRange) { test.Run(OpTester::ExpectResult::kExpectFailure, "Mismatch between number of source and target dimensions."); } +TEST(TensorOpTest, UnsqueezeNegAxis_3) { + OpTester test("Unsqueeze", 11); + + test.AddAttribute("axes", std::vector{-4, 1, -6}); + test.AddInput("input", {2, 3, 4}, std::vector(2 * 3 * 4, 1.0f)); + test.AddOutput("output", {1, 1, 1, 2, 3, 4}, std::vector(2 * 3 * 4, 1.0f)); + // nGraph does not support negative axis. + test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kNGraphExecutionProvider}); +} + } // namespace test } // namespace onnxruntime diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index b33cd7d569..ae24fd917a 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -144,18 +144,11 @@ def create_backend_test(testname=None): '^test_resize_upsample_sizes_nearest_round_prefer_ceil_asymmetric_cpu.*', '^test_scatternd_cpu.*', '^test_sequence_*', - '^test_unsqueeze_*', - '^test_squeeze_*', - '^test_slice_*', '^test_scatter_*', '^test_reduce_*', '^test_onehot_*', - '^test_flatten_*', - '^test_concat_*', - '^test_compress_*', '^test_constant_pad_cpu.*', '^test_gemm_default_scalar_bias_cpu.*', - '^test_gather_negative_indices_cpu.*', '^test_gemm_*', '^test_edge_pad_cpu.*', '^test_reflect_pad_cpu.*'