Skip to content

Commit ca607fd

Browse files
committed
feat: improve stability on unified memory systems
1 parent aa50af2 commit ca607fd

18 files changed

Lines changed: 506 additions & 81 deletions

llama/addon/addon.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
#include "addonGlobals.h"
1+
#include <atomic>
2+
#include <cstdlib>
3+
#include <mutex>
4+
5+
#include "AddonContext.h"
26
#include "AddonGgufMetadata.h"
3-
#include "AddonModel.h"
4-
#include "AddonModelLora.h"
57
#include "AddonGrammar.h"
68
#include "AddonGrammarEvaluationState.h"
9+
#include "AddonModel.h"
10+
#include "AddonModelLora.h"
711
#include "AddonSampler.h"
8-
#include "AddonContext.h"
12+
#include "addonGlobals.h"
913
#include "globals/addonLog.h"
1014
#include "globals/addonProgress.h"
1115
#include "globals/getGpuInfo.h"
16+
#include "globals/getProcessMemoryInfo.h"
1217
#include "globals/getSwapInfo.h"
13-
#include "globals/getMemoryInfo.h"
14-
15-
#include <atomic>
16-
#include <cstdlib>
17-
#include <mutex>
18+
#include "globals/getSystemMemoryInfo.h"
1819

19-
std::mutex backendMutex;
20+
std::mutex backendMutex;
2021
bool backendInitialized = false;
2122
bool backendDisposed = false;
2223

@@ -307,7 +308,8 @@ Napi::Object registerCallback(Napi::Env env, Napi::Object exports) {
307308
Napi::PropertyDescriptor::Function("getGpuType", getGpuType),
308309
Napi::PropertyDescriptor::Function("ensureGpuDeviceIsSupported", ensureGpuDeviceIsSupported),
309310
Napi::PropertyDescriptor::Function("getSwapInfo", getSwapInfo),
310-
Napi::PropertyDescriptor::Function("getMemoryInfo", getMemoryInfo),
311+
Napi::PropertyDescriptor::Function("getProcessMemoryInfo", getProcessMemoryInfo),
312+
Napi::PropertyDescriptor::Function("getSystemMemoryInfo", getSystemMemoryInfo),
311313
Napi::PropertyDescriptor::Function("loadBackends", addonLoadBackends),
312314
Napi::PropertyDescriptor::Function("setNuma", addonSetNuma),
313315
Napi::PropertyDescriptor::Function("init", addonInit),

llama/addon/globals/getMemoryInfo.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

llama/addon/globals/getMemoryInfo.cpp renamed to llama/addon/globals/getProcessMemoryInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "getMemoryInfo.h"
1+
#include "getProcessMemoryInfo.h"
22
#include "addonLog.h"
33

44
#ifdef __APPLE__
@@ -16,7 +16,7 @@
1616
#endif
1717

1818

19-
Napi::Value getMemoryInfo(const Napi::CallbackInfo& info) {
19+
Napi::Value getProcessMemoryInfo(const Napi::CallbackInfo& info) {
2020
uint64_t totalMemoryUsage = 0;
2121

2222
#ifdef __APPLE__
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
#include "napi.h"
3+
4+
Napi::Value getProcessMemoryInfo(const Napi::CallbackInfo& info);

0 commit comments

Comments
 (0)