Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/onnxruntime/core/session/onnxruntime_cxx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,7 @@ struct ShapeInferContext {

size_t GetInputCount() const { return input_shapes_.size(); }

Status SetOutputShape(size_t indice, const Shape& shape);
Status SetOutputShape(size_t indice, const Shape& shape, ONNXTensorElementDataType type = ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT);

int64_t GetAttrInt(const char* attr_name);

Expand Down
9 changes: 6 additions & 3 deletions include/onnxruntime/core/session/onnxruntime_cxx_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -1996,9 +1998,10 @@ inline ShapeInferContext::ShapeInferContext(const OrtApi* ort_api,
}
}

inline Status ShapeInferContext::SetOutputShape(size_t indice, const Shape& shape) {
inline Status ShapeInferContext::SetOutputShape(size_t indice, const Shape& shape, ONNXTensorElementDataType type) {
OrtTensorTypeAndShapeInfo* info = {};
ORT_CXX_RETURN_ON_API_FAIL(ort_api_->CreateTensorTypeAndShapeInfo(&info));
ORT_CXX_RETURN_ON_API_FAIL(ort_api_->SetTensorElementType(info, type));
mingyueliuh marked this conversation as resolved.
Show resolved Hide resolved

using InfoPtr = std::unique_ptr<OrtTensorTypeAndShapeInfo, std::function<void(OrtTensorTypeAndShapeInfo*)>>;

Expand All @@ -2011,7 +2014,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()) {
Expand Down