Fix minimal build.

Fix some more old 'graph api' naming
This commit is contained in:
Scott McKay 2024-12-30 11:15:03 +10:00
parent 6f2a5c3c46
commit 019edc9264
6 changed files with 46 additions and 23 deletions

View file

@ -22,6 +22,7 @@ endif()
if (onnxruntime_MINIMAL_BUILD)
set(onnxruntime_session_src_exclude
"${ONNXRUNTIME_ROOT}/core/session/provider_bridge_ort.cc"
"${ONNXRUNTIME_ROOT}/core/session/model_builder_c_api.cc"
)
list(REMOVE_ITEM onnxruntime_session_srcs ${onnxruntime_session_src_exclude})

View file

@ -148,7 +148,15 @@ std::vector<std::string> GetAvailableProviders();
/// This returns a reference to the ORT C Model Builder API. Used if building or augmenting a model at runtime.
/// </summary>
/// <returns>ORT C Model Builder API reference</returns>
inline const OrtModelBuilderApi& GetModelBuilderApi() noexcept { return *GetApi().GetModelBuilderApi(); }
inline const OrtModelBuilderApi& GetModelBuilderApi() {
auto* api = GetApi().GetModelBuilderApi();
if (api == nullptr) {
// minimal build
ORT_CXX_API_THROW("Model Builder API is not available in this build", ORT_FAIL);
}
return *api;
}
/** \brief IEEE 754 half-precision floating point data type
*
@ -533,14 +541,14 @@ ORT_DEFINE_RELEASE(KernelInfo);
#undef ORT_DEFINE_RELEASE
#define ORT_DEFINE_GRAPH_API_RELEASE(NAME) \
#define ORT_DEFINE_MODELBUILDER_API_RELEASE(NAME) \
inline void OrtRelease(Ort##NAME* ptr) { GetModelBuilderApi().Release##NAME(ptr); }
ORT_DEFINE_GRAPH_API_RELEASE(ValueInfo);
ORT_DEFINE_GRAPH_API_RELEASE(Node);
ORT_DEFINE_GRAPH_API_RELEASE(Graph);
ORT_DEFINE_GRAPH_API_RELEASE(Model);
#undef ORT_DEFINE_GRAPH_API_RELEASE
ORT_DEFINE_MODELBUILDER_API_RELEASE(ValueInfo);
ORT_DEFINE_MODELBUILDER_API_RELEASE(Node);
ORT_DEFINE_MODELBUILDER_API_RELEASE(Graph);
ORT_DEFINE_MODELBUILDER_API_RELEASE(Model);
#undef ORT_DEFINE_MODELBUILDER_API_RELEASE
/** \brief This is a tagging template type. Use it with Base<T> to indicate that the C++ interface object
* has no ownership of the underlying C object.
@ -1283,9 +1291,9 @@ struct TensorTypeAndShapeInfoImpl : Base<T> {
[[deprecated("use GetShape()")]] void GetDimensions(int64_t* values, size_t values_count) const; ///< Wraps OrtApi::GetDimensions
void GetSymbolicDimensions(const char** values, size_t values_count) const; ///< Wraps OrtApi::GetSymbolicDimensions
std::vector<const char*> GetSymbolicDimensions() const;
std::vector<int64_t> GetShape() const; ///< Uses GetDimensionsCount & GetDimensions to return a std::vector of the shape
std::vector<const char*> GetSymbolicDimensions() const;
};
} // namespace detail
@ -2544,7 +2552,7 @@ struct CustomOpBase : OrtCustomOp {
};
//
// Graph API C++ wrappers
// Model Builder API C++ wrappers
//
namespace ModelBuilderAPI {

View file

@ -3637,16 +3637,6 @@ Status Graph::InjectExternalInitializersFromFilesInMemory(
return Status::OK();
}
bool Graph::GetOrtValueInitializer(const std::string& name, OrtValue& value) const {
auto it = ortvalue_initializers_.find(name);
if (it == ortvalue_initializers_.end()) {
return false;
}
value = it->second;
return true;
}
#endif // DISABLE_EXTERNAL_INITIALIZERS
#endif // !defined(ORT_MINIMAL_BUILD)
@ -3660,6 +3650,16 @@ bool Graph::GetInitializedTensor(const std::string& tensor_name, const TensorPro
return true;
}
bool Graph::GetOrtValueInitializer(const std::string& name, OrtValue& value) const {
auto it = ortvalue_initializers_.find(name);
if (it == ortvalue_initializers_.end()) {
return false;
}
value = it->second;
return true;
}
void Graph::CleanAllInitializedTensors() noexcept {
name_to_initial_tensor_.clear();
#if !defined(DISABLE_SPARSE_TENSORS)

View file

@ -740,7 +740,7 @@ Status Model::Load(int fd, const PathString& model_path, std::shared_ptr<Model>&
}
// static
common::Status Model::LoadFromModelBuilderApiModel(const OrtModel& graph_api_model,
common::Status Model::LoadFromModelBuilderApiModel(const OrtModel& model_builder_api_model,
const IOnnxRuntimeOpSchemaRegistryList* local_registries,
const ModelOptions& options,
const logging::Logger& logger,
@ -758,9 +758,9 @@ common::Status Model::LoadFromModelBuilderApiModel(const OrtModel& graph_api_mod
}
}
ORT_RETURN_IF_ERROR(Graph::LoadFromModelBuilderApiModel(*graph_api_model.graph,
ORT_RETURN_IF_ERROR(Graph::LoadFromModelBuilderApiModel(*model_builder_api_model.graph,
*model,
graph_api_model.domain_to_version,
model_builder_api_model.domain_to_version,
schema_registry,
options.strict_shape_type_inference,
logger,

View file

@ -2385,7 +2385,12 @@ ORT_API(const OrtTrainingApi*, OrtApis::GetTrainingApi, uint32_t version) {
}
ORT_API(const OrtModelBuilderApi*, OrtApis::GetModelBuilderApi) {
#if !defined(ORT_MINIMAL_BUILD)
return OrtModelBuilderAPI::GetModelBuilderApi();
#else
fprintf(stderr, "The Model Builder API is not supported in a minimal build.\n");
return nullptr;
#endif
}
static constexpr OrtApiBase ort_api_base = {

View file

@ -468,12 +468,21 @@ TEST(ModelBuilderAPITest, InvalidDimension) {
input_dims);
// invalid dim of -2 should cause exception
TypeInfo::CreateTensorInfo(tensor_type_info.GetConst());
FAIL();
FAIL() << "Expected exception for invalid dimension";
} catch (const Ort::Exception& e) {
ASSERT_STREQ(e.what(), "dim_values must be -1 (symbolic dimension) or larger.");
}
}
TEST(ModelBuilderAPITest, TestSqueezenet) {
static constexpr PATH_TYPE MODEL_URI = TSTR("testdata/squeezenet/model.onnx");
SessionOptions so;
Ort::Session session(*ort_env, MODEL_URI, so);
auto in0 = session.GetInputTypeInfo(0);
}
/*
Tests required