Skip to content

Commit 8735b54

Browse files
authored
Merge pull request #4662 from martin-frbg/hugetlb-doc
Fix and document the two HUGETLB options for buffer allocation in Makefile.rule
2 parents c20189c + fc10673 commit 8735b54

File tree

3 files changed

+64
-20
lines changed

3 files changed

+64
-20
lines changed

Makefile.rule

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ NO_AFFINITY = 1
219219
# to the user space. If bigphysarea is enabled, it will use it.
220220
# DEVICEDRIVER_ALLOCATION = 1
221221

222+
# Use large page allocation (called hugepage support in Linux context)
223+
# for the thread buffers (with access by shared memory operations)
224+
# HUGETLB_ALLOCATION = 1
225+
226+
# Use large page allocation called hugepages in Linux) based on mmap accessing
227+
# a memory-backed pseudofile (requires hugetlbfs to be mounted in the system,
228+
# the example below has it mounted on /hugepages. OpenBLAS will create the backing
229+
# file as gotoblas.processid in that path)
230+
# HUGETLBFILE_ALLOCATION = /hugepages
231+
222232
# If you need to synchronize FP CSR between threads (for x86/x86_64 and aarch64 only).
223233
# CONSISTENT_FPCSR = 1
224234

Makefile.system

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -962,18 +962,12 @@ endif
962962

963963
ifeq ($(ARCH), loongarch64)
964964
LA64_ABI=$(shell $(CC) -mabi=lp64d -c $(TOPDIR)/cpuid_loongarch64.c -o /dev/null > /dev/null 2> /dev/null && echo lp64d)
965-
LA64_ARCH=$(shell $(CC) -march=loongarch64 -c $(TOPDIR)/cpuid_loongarch64.c -o /dev/null > /dev/null 2> /dev/null && echo loongarch64)
966965
ifneq ($(LA64_ABI), lp64d)
967966
LA64_ABI=lp64
968967
endif
969-
ifneq ($(LA64_ARCH), loongarch64)
970-
CCOMMON_OPT += -mabi=$(LA64_ABI)
971-
FCOMMON_OPT += -mabi=$(LA64_ABI)
972-
else
973968
CCOMMON_OPT += -march=loongarch64 -mabi=$(LA64_ABI)
974969
FCOMMON_OPT += -march=loongarch64 -mabi=$(LA64_ABI)
975970
endif
976-
endif
977971

978972
endif
979973

@@ -1592,13 +1586,23 @@ ifdef FUNCTION_PROFILE
15921586
CCOMMON_OPT += -DFUNCTION_PROFILE
15931587
endif
15941588

1589+
ifdef SHMEM_ALLOCATION
1590+
ifneq ($(SHMEM_ALLOCATION), 0)
1591+
CCOMMON_OPT += -DALLOC_SHM
1592+
endif
1593+
endif
1594+
15951595
ifdef HUGETLB_ALLOCATION
1596+
ifneq ($(HUGETLB_ALLOCATION), 0)
15961597
CCOMMON_OPT += -DALLOC_HUGETLB
15971598
endif
1599+
endif
15981600

15991601
ifdef HUGETLBFILE_ALLOCATION
1602+
ifneq ($(HUGETLBFILE_ALLOCATION), 0)
16001603
CCOMMON_OPT += -DALLOC_HUGETLBFILE -DHUGETLB_FILE_NAME=$(HUGETLBFILE_ALLOCATION)
16011604
endif
1605+
endif
16021606

16031607
ifdef STATIC_ALLOCATION
16041608
CCOMMON_OPT += -DALLOC_STATIC

driver/others/memory.c

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,11 +1165,10 @@ void *blas_memory_alloc(int procpos){
11651165
#ifdef ALLOC_DEVICEDRIVER
11661166
alloc_devicedirver,
11671167
#endif
1168-
/* Hugetlb implicitly assumes ALLOC_SHM */
1169-
#ifdef ALLOC_SHM
1168+
#ifdef ALLOC_SHM && !defined(ALLOC_HUGETLB)
11701169
alloc_shm,
11711170
#endif
1172-
#if ((defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS))
1171+
#if ((defined ALLOC_HUGETLB) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS))
11731172
alloc_hugetlb,
11741173
#endif
11751174
#ifdef ALLOC_MMAP
@@ -1190,7 +1189,6 @@ void *blas_memory_alloc(int procpos){
11901189
struct alloc_t * alloc_info;
11911190
struct alloc_t ** alloc_table;
11921191

1193-
11941192
#if defined(SMP) && !defined(USE_OPENMP)
11951193
int mi;
11961194
LOCK_COMMAND(&alloc_lock);
@@ -1282,7 +1280,7 @@ UNLOCK_COMMAND(&alloc_lock);
12821280
}
12831281
#endif
12841282

1285-
#if (defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
1283+
#if (defined ALLOC_HUGETLB) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
12861284
if ((*func == alloc_hugetlb) && (map_address != (void *)-1)) hugetlb_allocated = 1;
12871285
#endif
12881286

@@ -2494,7 +2492,7 @@ static void *alloc_devicedirver(void *address){
24942492

24952493
#endif
24962494

2497-
#ifdef ALLOC_SHM
2495+
#if defined(ALLOC_SHM) && !defined(ALLOC_HUGETLB)
24982496

24992497
static void alloc_shm_free(struct release_t *release){
25002498

@@ -2506,7 +2504,9 @@ static void alloc_shm_free(struct release_t *release){
25062504
static void *alloc_shm(void *address){
25072505
void *map_address;
25082506
int shmid;
2509-
2507+
#ifdef DEBUG
2508+
fprintf(stderr,"alloc_shm got called\n");
2509+
#endif
25102510
shmid = shmget(IPC_PRIVATE, BUFFER_SIZE,IPC_CREAT | 0600);
25112511

25122512
map_address = (void *)shmat(shmid, address, 0);
@@ -2533,6 +2533,7 @@ static void *alloc_shm(void *address){
25332533

25342534
return map_address;
25352535
}
2536+
#endif
25362537

25372538
#if defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS
25382539

@@ -2562,6 +2563,10 @@ static void *alloc_hugetlb(void *address){
25622563

25632564
void *map_address = (void *)-1;
25642565

2566+
#ifdef DEBUG
2567+
fprintf(stderr,"alloc_hugetlb got called\n");
2568+
#endif
2569+
25652570
#if defined(OS_LINUX) || defined(OS_AIX)
25662571
int shmid;
25672572

@@ -2583,7 +2588,7 @@ static void *alloc_hugetlb(void *address){
25832588

25842589
if (map_address != (void *)-1){
25852590
shmctl(shmid, IPC_RMID, 0);
2586-
}
2591+
}else printf("alloc_hugetlb failed\n");
25872592
}
25882593
#endif
25892594

@@ -2645,7 +2650,6 @@ static void *alloc_hugetlb(void *address){
26452650
}
26462651
#endif
26472652

2648-
#endif
26492653

26502654
#ifdef ALLOC_HUGETLBFILE
26512655

@@ -2762,11 +2766,10 @@ void *blas_memory_alloc(int procpos){
27622766
#ifdef ALLOC_DEVICEDRIVER
27632767
alloc_devicedirver,
27642768
#endif
2765-
/* Hugetlb implicitly assumes ALLOC_SHM */
2766-
#ifdef ALLOC_SHM
2769+
#ifdef ALLOC_SHM && !defined(ALLOC_HUGETLB)
27672770
alloc_shm,
27682771
#endif
2769-
#if ((defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS))
2772+
#if ((defined ALLOC_HUGETLB) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS))
27702773
alloc_hugetlb,
27712774
#endif
27722775
#ifdef ALLOC_MMAP
@@ -2945,8 +2948,22 @@ void *blas_memory_alloc(int procpos){
29452948
}
29462949
#endif
29472950

2948-
#if (defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
2951+
#if (defined ALLOC_HUGETLB) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
29492952
if ((*func == alloc_hugetlb) && (map_address != (void *)-1)) hugetlb_allocated = 1;
2953+
#ifdef DEBUG
2954+
if (hugetlb_allocated) printf("allocating via shared memory with large page support (hugetlb)\n");
2955+
#endif
2956+
#endif
2957+
2958+
#if (defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
2959+
#ifdef DEBUG
2960+
printf("allocating via shared memory\n");
2961+
#endif
2962+
if ((*func == alloc_shm) && (map_address == (void *)-1)) {
2963+
#ifndef OS_WINDOWS
2964+
fprintf(stderr, "OpenBLAS Warning ... shared memory allocation was failed.\n");
2965+
#endif
2966+
}
29502967
#endif
29512968

29522969
func ++;
@@ -3061,10 +3078,23 @@ void *blas_memory_alloc(int procpos){
30613078
}
30623079
#endif
30633080

3064-
#if (defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
3081+
#if (defined ALLOC_HUGETLB) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
3082+
#ifdef DEBUG
3083+
fprintf(stderr,"OpenBLAS: allocating via shared memory with large page support (hugetlb)\n");
3084+
#endif
30653085
if ((*func == alloc_hugetlb) && (map_address != (void *)-1)) hugetlb_allocated = 1;
30663086
#endif
30673087

3088+
#if (defined ALLOC_SHM) && (defined OS_LINUX || defined OS_AIX || defined __sun__ || defined OS_WINDOWS)
3089+
#ifdef DEBUG
3090+
fprintf(stderr,"allocating via shared memory\n");
3091+
#endif
3092+
if ((*func == alloc_shm) && (map_address == (void *)-1)) {
3093+
#ifndef OS_WINDOWS
3094+
fprintf(stderr, "OpenBLAS Warning ... shared memory allocation was failed.\n");
3095+
#endif
3096+
}
3097+
#endif
30683098
func ++;
30693099
}
30703100

0 commit comments

Comments
 (0)