Skip to content

Commit 1cd2c29

Browse files
committed
allow total memory hiding
1 parent 9c45678 commit 1cd2c29

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/hook.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "utlist.h"
4242

4343
#define ENV_NVSHARE_ENABLE_SINGLE_OVERSUB "NVSHARE_ENABLE_SINGLE_OVERSUB"
44+
#define ENV_NVSHARE_HIDE_MEMINFO_RESERVE_MIB "NVSHARE_HIDE_MEMINFO_RESERVE_MIB"
4445

4546
#define MEMINFO_RESERVE_MIB 1536 /* MiB */
4647
#define KERN_SYNC_DURATION_BIG 10 /* seconds */
@@ -84,6 +85,7 @@ int pending_kernel_window = 1;
8485
pthread_mutex_t kcount_mutex;
8586

8687
int enable_single_oversub = 0;
88+
int hide_meminfo_reserve_mib = 0;
8789
int nvml_ok = 1;
8890

8991
/* Representation of a CUDA memory allocation */
@@ -330,6 +332,11 @@ static void initialize_libnvshare(void)
330332
log_warn("Enabling GPU memory oversubscription for this"
331333
" application");
332334
}
335+
value = getenv(ENV_NVSHARE_HIDE_MEMINFO_RESERVE_MIB);
336+
if (value != NULL) {
337+
hide_meminfo_reserve_mib = 1;
338+
log_warn("Hiding %d MiB from CUDA memory info", MEMINFO_RESERVE_MIB);
339+
}
333340

334341
bootstrap_cuda();
335342
}
@@ -782,6 +789,10 @@ CUresult cuMemGetInfo(size_t *free, size_t *total)
782789
reserve_mib = (MEMINFO_RESERVE_MIB) MiB;
783790
*free = *total - (size_t) reserve_mib;
784791

792+
if (hide_meminfo_reserve_mib == 1) {
793+
*total -= reserve_mib;
794+
}
795+
785796
log_debug("nvshare's cuMemGetInfo returning free=%.2f MiB,"
786797
" total=%.2f MiB", toMiB(*free), toMiB(*total));
787798
return result;

0 commit comments

Comments
 (0)