@@ -134,14 +134,24 @@ struct ggml_backend_registry {
134
134
135
135
ggml_backend_reg_t load_backend (const char * path, bool silent) {
136
136
#ifdef _WIN32
137
+ // suppress error dialogs for missing DLLs
138
+ DWORD old_mode = SetErrorMode (SEM_FAILCRITICALERRORS);
139
+ SetErrorMode (old_mode | SEM_FAILCRITICALERRORS);
140
+
137
141
HMODULE handle = LoadLibraryA (path);
142
+
138
143
if (!handle) {
139
144
if (!silent) {
140
145
GGML_LOG_ERROR (" %s: failed to load %s: %lu\n " , __func__, path, GetLastError ());
141
146
}
147
+ SetErrorMode (old_mode);
142
148
return nullptr ;
143
149
}
150
+
144
151
ggml_backend_init_t backend_init = (ggml_backend_init_t ) GetProcAddress (handle, " ggml_backend_init" );
152
+
153
+ SetErrorMode (old_mode);
154
+
145
155
if (!backend_init) {
146
156
if (!silent) {
147
157
GGML_LOG_ERROR (" %s: failed to find ggml_backend_init in %s: %lu\n " , __func__, path, GetLastError ());
@@ -151,13 +161,16 @@ struct ggml_backend_registry {
151
161
}
152
162
#else
153
163
void * handle = dlopen (path, RTLD_NOW | RTLD_LOCAL);
164
+
154
165
if (!handle) {
155
166
if (!silent) {
156
167
GGML_LOG_ERROR (" %s: failed to load %s: %s\n " , __func__, path, dlerror ());
157
168
}
158
169
return nullptr ;
159
170
}
171
+
160
172
auto * backend_init = (ggml_backend_init_t ) dlsym (handle, " ggml_backend_init" );
173
+
161
174
if (!backend_init) {
162
175
if (!silent) {
163
176
GGML_LOG_ERROR (" %s: failed to find ggml_backend_init in %s: %s\n " , __func__, path, dlerror ());
@@ -167,6 +180,7 @@ struct ggml_backend_registry {
167
180
}
168
181
#endif
169
182
ggml_backend_reg_t reg = backend_init ();
183
+
170
184
if (!reg || reg->api_version != GGML_BACKEND_API_VERSION) {
171
185
if (!silent) {
172
186
if (!reg) {
@@ -176,11 +190,11 @@ struct ggml_backend_registry {
176
190
__func__, path, reg->api_version , GGML_BACKEND_API_VERSION);
177
191
}
178
192
}
179
- #ifdef _WIN32
193
+ #ifdef _WIN32
180
194
FreeLibrary (handle);
181
- #else
195
+ #else
182
196
dlclose (handle);
183
- #endif
197
+ #endif
184
198
return nullptr ;
185
199
}
186
200
0 commit comments