Skip to content

Commit 6e2bbf5

Browse files
Make Graph_GetModelPath return an OrtStatus*
1 parent eef415c commit 6e2bbf5

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

include/onnxruntime/core/session/onnxruntime_c_api.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5560,17 +5560,19 @@ struct OrtApi {
55605560
*/
55615561
ORT_API2_STATUS(Graph_GetName, _In_ const OrtGraph* graph, _Outptr_ const char** graph_name);
55625562

5563-
/** \brief Returns the file path to the ONNX model from which an OrtGraph is constructed.
5563+
/** \brief Get the filepath to the ONNX model from which an OrtGraph is constructed.
55645564
*
5565-
* \note Returns an empty file path if the model path is unknown, such as when the model is loaded from bytes
5565+
* \note The model's filepath is empty if the filepath is unknown, such as when the model is loaded from bytes
55665566
* via CreateSessionFromArray.
55675567
*
55685568
* \param[in] graph The OrtGraph instance.
5569-
* \return The model path, which is an empty path string if unknown.
5569+
* \param[out] model_path Output parameter set to the model's filepath, which is an empty path string if unknown.
5570+
*
5571+
* \snippet{doc} snippets.dox OrtStatus Return Value
55705572
*
55715573
* \since Version 1.23.
55725574
*/
5573-
ORT_API_T(const ORTCHAR_T*, Graph_GetModelPath, _In_ const OrtGraph* graph);
5575+
ORT_API2_STATUS(Graph_GetModelPath, _In_ const OrtGraph* graph, _Outptr_ const ORTCHAR_T** model_path);
55745576

55755577
/** \brief Returns the ONNX IR version.
55765578
*

onnxruntime/core/graph/model_editor_api_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ struct ModelEditorGraph : public OrtGraph {
173173

174174
const std::string& GetName() const override { return name; }
175175

176-
const ORTCHAR_T* GetModelPath() const override { return ORT_TSTR(""); }
176+
const ORTCHAR_T* GetModelPath() const override { return model_path.c_str(); }
177177

178178
int64_t GetOnnxIRVersion() const override {
179179
return ONNX_NAMESPACE::Version::IR_VERSION;
@@ -229,6 +229,7 @@ struct ModelEditorGraph : public OrtGraph {
229229
std::unordered_map<std::string, std::unique_ptr<OrtValue>> external_initializers;
230230
std::vector<std::unique_ptr<onnxruntime::ModelEditorNode>> nodes;
231231
std::string name = "ModelEditorGraph";
232+
std::filesystem::path model_path;
232233
};
233234

234235
} // namespace onnxruntime

onnxruntime/core/session/onnxruntime_c_api.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,8 +2579,15 @@ ORT_API_STATUS_IMPL(OrtApis::Graph_GetName, _In_ const OrtGraph* graph, _Outptr_
25792579
API_IMPL_END
25802580
}
25812581

2582-
ORT_API(const ORTCHAR_T*, OrtApis::Graph_GetModelPath, _In_ const OrtGraph* graph) {
2583-
return graph->GetModelPath();
2582+
ORT_API_STATUS_IMPL(OrtApis::Graph_GetModelPath, _In_ const OrtGraph* graph, _Outptr_ const ORTCHAR_T** model_path) {
2583+
API_IMPL_BEGIN
2584+
if (model_path == nullptr) {
2585+
return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "'model_path' argument is NULL");
2586+
}
2587+
2588+
*model_path = graph->GetModelPath();
2589+
return nullptr;
2590+
API_IMPL_END
25842591
}
25852592

25862593
ORT_API_STATUS_IMPL(OrtApis::Graph_GetOnnxIRVersion, _In_ const OrtGraph* graph, _Out_ int64_t* ir_version) {

onnxruntime/core/session/ort_apis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ ORT_API_STATUS_IMPL(ValueInfo_IsFromOuterScope, _In_ const OrtValueInfo* value_i
630630

631631
// OrtGraph
632632
ORT_API_STATUS_IMPL(Graph_GetName, _In_ const OrtGraph* graph, _Outptr_ const char** graph_name);
633-
ORT_API(const ORTCHAR_T*, Graph_GetModelPath, _In_ const OrtGraph* graph);
633+
ORT_API_STATUS_IMPL(Graph_GetModelPath, _In_ const OrtGraph* graph, _Outptr_ const ORTCHAR_T** model_path);
634634
ORT_API_STATUS_IMPL(Graph_GetOnnxIRVersion, _In_ const OrtGraph* graph, _Out_ int64_t* onnx_ir_version);
635635
ORT_API_STATUS_IMPL(Graph_GetNumOperatorSets, _In_ const OrtGraph* graph, _Out_ size_t* num_operator_sets);
636636
ORT_API_STATUS_IMPL(Graph_GetOperatorSets, _In_ const OrtGraph* graph,

onnxruntime/test/ep_graph/test_ep_graph.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ static void CheckGraphCApi(const GraphViewer& graph_viewer, const OrtGraph& api_
537537

538538
// Check the path to model.
539539
const std::filesystem::path& model_path = graph_viewer.ModelPath();
540-
const ORTCHAR_T* api_model_path = ort_api.Graph_GetModelPath(&api_graph);
540+
const ORTCHAR_T* api_model_path = nullptr;
541+
ASSERT_ORTSTATUS_OK(ort_api.Graph_GetModelPath(&api_graph, &api_model_path));
541542
ASSERT_EQ(PathString(api_model_path), PathString(model_path.c_str()));
542543

543544
// Check graph inputs.

0 commit comments

Comments
 (0)