Add support tensor element type for register custom op shape infer function (#21387)

### Description
Functionality extension for the SetOutputShape method in custom op shape inference.


### Motivation and Context
-  **SetOutputShape** Interface enhancement Actually, the shape infer function need set the tensor type and shape ,Add a parameter **type** to allow users to specify the tensor type, and set **ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT** as default value to ensure compatibility.

Co-authored-by: mingyue <mingyue@amd.com>
This commit is contained in:
mingyueliuh 2024-07-29 12:45:52 -04:00 committed by GitHub
parent 94eb70d983
commit d8888136e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 2 deletions

View file

@ -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);

View file

@ -1998,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));
using InfoPtr = std::unique_ptr<OrtTensorTypeAndShapeInfo, std::function<void(OrtTensorTypeAndShapeInfo*)>>;

View file

@ -105,6 +105,7 @@ struct OrtShapeInferContext {
}
}
ONNX_NAMESPACE::updateOutputShape(ctx_, index, shape_proto);
ONNX_NAMESPACE::updateOutputElemType(ctx_, index, info->type);
return onnxruntime::Status::OK();
}