// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #define ORT_API_MANUAL_INIT #include "onnxruntime_cxx_api.h" #undef ORT_API_MANUAL_INIT #include "ep_factory.h" #include // To make symbols visible on macOS/iOS #ifdef __APPLE__ #define EXPORT_SYMBOL __attribute__((visibility("default"))) #else #define EXPORT_SYMBOL #endif extern "C" { // // Public symbols // EXPORT_SYMBOL OrtStatus* CreateEpFactories(const char* registration_name, const OrtApiBase* ort_api_base, const OrtLogger* default_logger, OrtEpFactory** factories, size_t max_factories, size_t* num_factories) { const OrtApi* ort_api = ort_api_base->GetApi(ORT_API_VERSION); const OrtEpApi* ep_api = ort_api->GetEpApi(); const OrtModelEditorApi* model_editor_api = ort_api->GetModelEditorApi(); // Manual init for the C++ API Ort::InitApi(ort_api); // Test hook used by AutoEP regression coverage. This keeps the default example EP behavior unchanged while allowing // one test registration to expose multiple hardware devices backed by the same factory and custom-op domains. const bool create_duplicate_virtual_devices = std::strcmp(registration_name, "example_ep_duplicate_devices") == 0; // Factory could use registration_name or define its own EP name. std::unique_ptr factory = std::make_unique(registration_name, ApiPtrs{*ort_api, *ep_api, *model_editor_api}, *default_logger, create_duplicate_virtual_devices); if (max_factories < 1) { return ort_api->CreateStatus(ORT_INVALID_ARGUMENT, "Not enough space to return EP factory. Need at least one."); } factories[0] = factory.release(); *num_factories = 1; return nullptr; } EXPORT_SYMBOL OrtStatus* ReleaseEpFactory(OrtEpFactory* factory) { delete static_cast(factory); return nullptr; } } // extern "C"