Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/ai/backend_onnx.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,24 @@ static gpointer _init_ort_api(gpointer data)
return (gpointer)api;
}

// query ORT for whether a given execution provider was compiled into
// the loaded library; safe to call before CreateEnv — GetAvailableProviders
// just lists statically-linked / loadable providers, it does not load them
static gboolean _ort_has_provider(const char *name)
{
if(!g_ort || !g_ort->GetAvailableProviders) return FALSE;
char **providers = NULL;
int n = 0;
if(g_ort->GetAvailableProviders(&providers, &n) != NULL || !providers)
return FALSE;
gboolean found = FALSE;
for(int i = 0; i < n && !found; i++)
if(g_strcmp0(providers[i], name) == 0) found = TRUE;
if(g_ort->ReleaseAvailableProviders)
g_ort->ReleaseAvailableProviders(providers, n);
return found;
}

#if defined(__linux__)
// configure AMD GPU caches (MIOpen kernel db + MIGraphX compiled-program
// cache) via environment variables. these MUST be set before any ORT
Expand All @@ -879,7 +897,7 @@ static gpointer _init_ort_api(gpointer data)
// keep control
static void _setup_amd_caches(void)
{
if(!g_file_test("/opt/rocm", G_FILE_TEST_IS_DIR))
if(!_ort_has_provider("MIGraphXExecutionProvider"))
return;

char cachedir[PATH_MAX] = { 0 };
Expand Down Expand Up @@ -909,7 +927,8 @@ static void _setup_amd_caches(void)
// writes .blob files to cache_dir for instant reload on subsequent runs
static gboolean _try_openvino_with_cache(OrtSessionOptions *session_opts)
{
if(!g_ort || !g_ort->SessionOptionsAppendExecutionProvider_OpenVINO_V2)
if(!_ort_has_provider("OpenVINOExecutionProvider")
|| !g_ort->SessionOptionsAppendExecutionProvider_OpenVINO_V2)
return FALSE;

char cachedir[PATH_MAX] = { 0 };
Expand Down
Loading