[Fix] C++ API SetOutputShape for register custom op. (#21366)

### Description
Bug fix  for the SetOutputShape method in custom op shape inference.


### Motivation and Context

- Bug a :   A obvious bug that will cause all dimensions to be 1. 

https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_cxx_inline.h#L2014
integer_dims.push_back(dim.IsInt()); ->
integer_dims.push_back(dim.AsInt());

- Bug b :  vector out of range error
op's input maybe a scalar and shape is empty.

https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_cxx_inline.h#L1985

---------

Co-authored-by: mingyue <mingyue@amd.com>
This commit is contained in:
mingyueliuh 2024-07-23 19:51:00 -04:00 committed by GitHub
parent c65afcea55
commit 86cedc6832
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1982,7 +1982,9 @@ inline ShapeInferContext::ShapeInferContext(const OrtApi* ort_api,
TensorTypeAndShapeInfo type_shape_info(info);
auto integer_shape = type_shape_info.GetShape();
std::vector<const char*> symbolic_shape(integer_shape.size(), {});
type_shape_info.GetSymbolicDimensions(&symbolic_shape[0], integer_shape.size());
if (!integer_shape.empty()) {
type_shape_info.GetSymbolicDimensions(&symbolic_shape[0], integer_shape.size());
}
Shape shape;
for (size_t ith = 0; ith < integer_shape.size(); ++ith) {
if (symbolic_shape[ith] && std::string{symbolic_shape[ith]}.size() > 0) {
@ -2011,7 +2013,7 @@ inline Status ShapeInferContext::SetOutputShape(size_t indice, const Shape& shap
for (const auto dim : shape) {
if (dim.IsInt()) {
integer_dims.push_back(dim.IsInt());
integer_dims.push_back(dim.AsInt());
symbolic_dims.push_back("");
} else {
if (!dim.AsSym() || std::string{dim.AsSym()}.empty()) {