File tree Expand file tree Collapse file tree 4 files changed +20
-2
lines changed Expand file tree Collapse file tree 4 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,17 @@ class AddonBackendUnloadWorker : public Napi::AsyncWorker {
152152};
153153
154154Napi::Value addonLoadBackends (const Napi::CallbackInfo& info) {
155- ggml_backend_load_all ();
155+ const bool forceLoadLibraries = info.Length () == 0
156+ ? false
157+ : info[0 ].IsBoolean ()
158+ ? info[0 ].As <Napi::Boolean>().Value ()
159+ : false ;
160+
161+ ggml_backend_reg_count ();
162+
163+ if (forceLoadLibraries) {
164+ ggml_backend_load_all ();
165+ }
156166
157167 return info.Env ().Undefined ();
158168}
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ export type BindingModule = {
7676 free : number
7777 } ,
7878 init ( ) : Promise < void > ,
79- loadBackends ( ) : void ,
79+ loadBackends ( forceLoadLibraries ?: boolean ) : void ,
8080 dispose ( ) : Promise < void >
8181} ;
8282
Original file line number Diff line number Diff line change @@ -127,6 +127,9 @@ export class Llama {
127127 }
128128
129129 this . _bindings . loadBackends ( ) ;
130+ const loadedGpu = bindings . getGpuType ( ) ;
131+ if ( loadedGpu == null || ( loadedGpu === false && gpu !== false ) )
132+ this . _bindings . loadBackends ( true ) ;
130133
131134 this . _onExit = this . _onExit . bind ( this ) ;
132135
Original file line number Diff line number Diff line change @@ -196,7 +196,12 @@ if (process.env.TEST_BINDING_CP === "true" && (process.parentPort != null || pro
196196 if ( message . type === "start" ) {
197197 try {
198198 const binding : BindingModule = require ( message . bindingBinaryPath ) ;
199+
199200 binding . loadBackends ( ) ;
201+ const loadedGpu = binding . getGpuType ( ) ;
202+ if ( loadedGpu == null || ( loadedGpu === false && message . gpu !== false ) )
203+ binding . loadBackends ( true ) ;
204+
200205 await binding . init ( ) ;
201206 binding . getGpuVramInfo ( ) ;
202207 binding . getGpuDeviceInfo ( ) ;
You can’t perform that action at this time.
0 commit comments