mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
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:
parent
94eb70d983
commit
d8888136e3
3 changed files with 4 additions and 2 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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*)>>;
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ struct OrtShapeInferContext {
|
|||
}
|
||||
}
|
||||
ONNX_NAMESPACE::updateOutputShape(ctx_, index, shape_proto);
|
||||
ONNX_NAMESPACE::updateOutputElemType(ctx_, index, info->type);
|
||||
return onnxruntime::Status::OK();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue