Skip to content

umfMemspaceHighestBandwidthGet does not use HBM on SapphireRapids+HBM #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
breiters opened this issue Apr 25, 2025 · 5 comments · Fixed by #1309
Open

umfMemspaceHighestBandwidthGet does not use HBM on SapphireRapids+HBM #1289

breiters opened this issue Apr 25, 2025 · 5 comments · Fixed by #1309
Labels
bug Something isn't working

Comments

@breiters
Copy link

breiters commented Apr 25, 2025

umfMemspaceHighestBandwidthGet does not allocate from HBM on SapphireRapids+HBM

Environment Information

  • UMF version (hash commit or a tag): v0.10
$ git log
commit 5d37cac662736b7d63d1e232b513c3fb6ed3e842 (HEAD -> main, origin/main, origin/HEAD)
[...]
  • OS(es) version(s):
  • kernel version(s):
$ uname -a
Linux sap4 5.14.21-150400.24.81-default #1 SMP PREEMPT_DYNAMIC Tue Aug 8 14:10:43 UTC 2023 (90a74a8) x86_64 x86_64 x86_64 GNU/Linux
  • Compiler
$ icx -v
Intel(R) oneAPI DPC++/C++ Compiler 2025.0.4 (2025.0.4.20241205)
  • Other relevant libraries
numactl-2.0.14
hwloc/2.11.1
  • System: SapphireRapids + HBM in SNC4 mode
$ lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 57 bits virtual
  Byte Order:            Little Endian
CPU(s):                  192
  On-line CPU(s) list:   0-191
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Xeon(R) CPU Max 9468
    CPU family:          6
    Model:               143
    Thread(s) per core:  2
    Core(s) per socket:  48
    Socket(s):           2
    Stepping:            8
    Frequency boost:     enabled
    CPU max MHz:         2101,0000
    CPU min MHz:         800,0000
    BogoMIPS:            4200.00
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bt
                         s rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movb
                         e popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanc
                         ed tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_p
                         t avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln p
                         ts avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md
                         _clear serialize tsxldtrk pconfig arch_lbr avx512_fp16 amx_tile flush_l1d arch_capabilities
Virtualization features: 
  Virtualization:        VT-x
Caches (sum of all):     
  L1d:                   4,5 MiB (96 instances)
  L1i:                   3 MiB (96 instances)
  L2:                    192 MiB (96 instances)
  L3:                    210 MiB (2 instances)
NUMA:                    
  NUMA node(s):          16
  NUMA node0 CPU(s):     0-11,96-107
  NUMA node1 CPU(s):     12-23,108-119
  NUMA node2 CPU(s):     24-35,120-131
  NUMA node3 CPU(s):     36-47,132-143
  NUMA node4 CPU(s):     48-59,144-155
  NUMA node5 CPU(s):     60-71,156-167
  NUMA node6 CPU(s):     72-83,168-179
  NUMA node7 CPU(s):     84-95,180-191
  NUMA node8 CPU(s):     
  NUMA node9 CPU(s):     
  NUMA node10 CPU(s):    
  NUMA node11 CPU(s):    
  NUMA node12 CPU(s):    
  NUMA node13 CPU(s):    
  NUMA node14 CPU(s):    
  NUMA node15 CPU(s):    
Vulnerabilities:         
  Gather data sampling:  Not affected
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Not affected
  Retbleed:              Not affected
  Spec rstack overflow:  Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
  Srbds:                 Not affected
  Tsx async abort:       Not affected

HMAT is also enabled:

$ grep CONFIG_ACPI_HMAT /boot/config-$(uname -r)
CONFIG_ACPI_HMAT=y

Please provide a reproduction of the bug:

$ taskset -c 0 ./build/examples/umf_example_memspace_hmat
Allocated memory at 0x14c0c165a000 from the highest bandwidth node: 1
Allocated memory at 0x14c0c165a000 from the lowest latency node: 0

How often bug is revealed:

always

Actual behavior:

umfMemspaceHighestBandwidthGet allocates memory from NUMA node 1 (DDR).

Expected behavior:

umfMemspaceHighestBandwidthGet allocates memory from (local) HBM NUMA node.

Details

Since this CPU has HBM connected, it is a semantical error if umfMemspaceHighestBandwidthGet allocates from DDR instead of HBM. Allocating from NUMA node 1 when running on CPU 0 with taskset -c 0 is even worse than allocating from NUMA node 0, which is also DDR, but closer to CPU 0.

The desired behavior would be to allocate from the closest proximity HBM NUMA node. This would be NUMA node 8 on this CPU. See the output of numactl -H:

$ numactl -H
available: 16 nodes (0-15)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 96 97 98 99 100 101 102 103 104 105 106 107
node 0 size: 64132 MB
node 0 free: 61658 MB
node 1 cpus: 12 13 14 15 16 17 18 19 20 21 22 23 108 109 110 111 112 113 114 115 116 117 118 119
node 1 size: 64505 MB
node 1 free: 61513 MB
node 2 cpus: 24 25 26 27 28 29 30 31 32 33 34 35 120 121 122 123 124 125 126 127 128 129 130 131
node 2 size: 64505 MB
node 2 free: 63757 MB
node 3 cpus: 36 37 38 39 40 41 42 43 44 45 46 47 132 133 134 135 136 137 138 139 140 141 142 143
node 3 size: 64505 MB
node 3 free: 62177 MB
node 4 cpus: 48 49 50 51 52 53 54 55 56 57 58 59 144 145 146 147 148 149 150 151 152 153 154 155
node 4 size: 64505 MB
node 4 free: 63986 MB
node 5 cpus: 60 61 62 63 64 65 66 67 68 69 70 71 156 157 158 159 160 161 162 163 164 165 166 167
node 5 size: 64459 MB
node 5 free: 63834 MB
node 6 cpus: 72 73 74 75 76 77 78 79 80 81 82 83 168 169 170 171 172 173 174 175 176 177 178 179
node 6 size: 64505 MB
node 6 free: 62546 MB
node 7 cpus: 84 85 86 87 88 89 90 91 92 93 94 95 180 181 182 183 184 185 186 187 188 189 190 191
node 7 size: 64456 MB
node 7 free: 63130 MB
node 8 cpus:
node 8 size: 16384 MB
node 8 free: 16280 MB
node 9 cpus:
node 9 size: 16384 MB
node 9 free: 16377 MB
node 10 cpus:
node 10 size: 16384 MB
node 10 free: 16330 MB
node 11 cpus:
node 11 size: 16384 MB
node 11 free: 16316 MB
node 12 cpus:
node 12 size: 16384 MB
node 12 free: 16330 MB
node 13 cpus:
node 13 size: 16384 MB
node 13 free: 16346 MB
node 14 cpus:
node 14 size: 16384 MB
node 14 free: 16356 MB
node 15 cpus:
node 15 size: 16384 MB
node 15 free: 16362 MB
node distances:
node   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15 
  0:  10  12  12  12  21  21  21  21  13  14  14  14  23  23  23  23 
  1:  12  10  12  12  21  21  21  21  14  13  14  14  23  23  23  23 
  2:  12  12  10  12  21  21  21  21  14  14  13  14  23  23  23  23 
  3:  12  12  12  10  21  21  21  21  14  14  14  13  23  23  23  23 
  4:  21  21  21  21  10  12  12  12  23  23  23  23  13  14  14  14 
  5:  21  21  21  21  12  10  12  12  23  23  23  23  14  13  14  14 
  6:  21  21  21  21  12  12  10  12  23  23  23  23  14  14  13  14 
  7:  21  21  21  21  12  12  12  10  23  23  23  23  14  14  14  13 
  8:  13  14  14  14  23  23  23  23  10  14  14  14  23  23  23  23 
  9:  14  13  14  14  23  23  23  23  14  10  14  14  23  23  23  23 
 10:  14  14  13  14  23  23  23  23  14  14  10  14  23  23  23  23 
 11:  14  14  14  13  23  23  23  23  14  14  14  10  23  23  23  23 
 12:  23  23  23  23  13  14  14  14  23  23  23  23  10  14  14  14 
 13:  23  23  23  23  14  13  14  14  23  23  23  23  14  10  14  14 
 14:  23  23  23  23  14  14  13  14  23  23  23  23  14  14  10  14 
 15:  23  23  23  23  14  14  14  13  23  23  23  23  14  14  14  10 
  • hwloc reads the HMAT table and reports higher bandwidths correctly (output of lstopo is truncated, note that hwloc uses a different NUMA node numbering compared to numactl):
$ lstopo -v
[...]

Relative latency matrix (name NUMALatency kind 5) between 16 NUMANodes (depth -3) by logical indexes:
 index     0     2     4     6     8    10    12    14     1     3     5     7     9    11    13    15
     0    10    12    12    12    21    21    21    21    13    14    14    14    23    23    23    23
     2    12    10    12    12    21    21    21    21    14    13    14    14    23    23    23    23
     4    12    12    10    12    21    21    21    21    14    14    13    14    23    23    23    23
     6    12    12    12    10    21    21    21    21    14    14    14    13    23    23    23    23
     8    21    21    21    21    10    12    12    12    23    23    23    23    13    14    14    14
    10    21    21    21    21    12    10    12    12    23    23    23    23    14    13    14    14
    12    21    21    21    21    12    12    10    12    23    23    23    23    14    14    13    14
    14    21    21    21    21    12    12    12    10    23    23    23    23    14    14    14    13
     1    13    14    14    14    23    23    23    23    10    14    14    14    23    23    23    23
     3    14    13    14    14    23    23    23    23    14    10    14    14    23    23    23    23
     5    14    14    13    14    23    23    23    23    14    14    10    14    23    23    23    23
     7    14    14    14    13    23    23    23    23    14    14    14    10    23    23    23    23
     9    23    23    23    23    13    14    14    14    23    23    23    23    10    14    14    14
    11    23    23    23    23    14    13    14    14    23    23    23    23    14    10    14    14
    13    23    23    23    23    14    14    13    14    23    23    23    23    14    14    10    14
    15    23    23    23    23    14    14    14    13    23    23    23    23    14    14    14    10
Memory attribute #2 name `Bandwidth' flags 5
  NUMANode L#0 = 219100 from cpuset 0x00000fff,,,0x00000fff (Group0 L#0)
  NUMANode L#2 = 219100 from cpuset 0x00fff000,,,0x00fff000 (Group0 L#1)
  NUMANode L#4 = 219100 from cpuset 0x0000000f,0xff000000,,0x0000000f,0xff000000 (Group0 L#2)
  NUMANode L#6 = 219100 from cpuset 0x0000fff0,,,0x0000fff0,0x0 (Group0 L#3)
  NUMANode L#8 = 219100 from cpuset 0x0fff0000,,,0x0fff0000,0x0 (Group0 L#4)
  NUMANode L#10 = 219100 from cpuset 0x000000ff,0xf0000000,,0x000000ff,0xf0000000,0x0 (Group0 L#5)
  NUMANode L#12 = 219100 from cpuset 0x000fff00,,,0x000fff00,,0x0 (Group0 L#6)
  NUMANode L#14 = 219100 from cpuset 0xfff00000,,,0xfff00000,,0x0 (Group0 L#7)
  NUMANode L#1 = 743650 from cpuset 0x00000fff,,,0x00000fff (Group0 L#0)
  NUMANode L#3 = 743650 from cpuset 0x00fff000,,,0x00fff000 (Group0 L#1)
  NUMANode L#5 = 743650 from cpuset 0x0000000f,0xff000000,,0x0000000f,0xff000000 (Group0 L#2)
  NUMANode L#7 = 743650 from cpuset 0x0000fff0,,,0x0000fff0,0x0 (Group0 L#3)
  NUMANode L#9 = 743650 from cpuset 0x0fff0000,,,0x0fff0000,0x0 (Group0 L#4)
  NUMANode L#11 = 743650 from cpuset 0x000000ff,0xf0000000,,0x000000ff,0xf0000000,0x0 (Group0 L#5)
  NUMANode L#13 = 743650 from cpuset 0x000fff00,,,0x000fff00,,0x0 (Group0 L#6)
  NUMANode L#15 = 743650 from cpuset 0xfff00000,,,0xfff00000,,0x0 (Group0 L#7)

[...]

Additional information about Priority and Help Requested:

Are you willing to submit a pull request with a proposed change? (Perhaps)

Requested priority: (Showstopper if you want to use this library function to allocate memory from HBM on this CPU)

  • It also does not work as expected in the (discontinued) Memkind library:
$ memkind-hbw-nodes 
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

This should report 8,9,10,11,12,13,14,15 instead.

  • Intel Compiler's, LLVM's and GCC's OpenMP implementations of the high bandwidth memory allocator rely on Memkind they do not work correct, too.
@breiters breiters added the bug Something isn't working label Apr 25, 2025
lplewa added a commit to lplewa/unified-memory-framework that referenced this issue May 9, 2025
physical_id field stores os index, so we should use correct function
to get hwloc numanode object.

fixes: oneapi-src#1289
@lplewa
Copy link
Contributor

lplewa commented May 9, 2025

@breiters Thanks for the issue. I created a PR with a fix for this problem #1309 - can you check if it's resolves the issue on your side?

@breiters
Copy link
Author

breiters commented May 9, 2025

Hi, and thanks for taking care. Yes it does fix the issue. At least in the simple case that I have tested:

$ for i in $(seq 0 95); do echo cpu=$i; taskset -c $i ./build/examples/umf_example_memspace_hmat ; done
cpu=0
Allocated memory at 0x152b446dc000 from the highest bandwidth node: 8
Allocated memory at 0x152b446dc000 from the lowest latency node: 0
cpu=1
Allocated memory at 0x14811e054000 from the highest bandwidth node: 8
Allocated memory at 0x14811e054000 from the lowest latency node: 0

[...]

cpu=11
Allocated memory at 0x1483b216c000 from the highest bandwidth node: 8
Allocated memory at 0x1483b216c000 from the lowest latency node: 0
cpu=12
Allocated memory at 0x14dea2c65000 from the highest bandwidth node: 9
Allocated memory at 0x14dea2c65000 from the lowest latency node: 1

[...]

cpu=95
Allocated memory at 0x14eb9d837000 from the highest bandwidth node: 15
Allocated memory at 0x14eb9d837000 from the lowest latency node: 7

Since hwloc's logical index was used here, where the OS index should have been used instead, it subsequently seems likely to me that this is not the only such occurrence.

Another question regarding a more complex case:

Does first-touch still work as expected with multiple threads using umfMemspaceHighestBandwidthGet? That is, let's assume we allocate memory for two pages with umfMemspaceHighestBandwidthGet. One page is touched first by a thread running on a CPU local to HBM NUMA node A, while the other page is touched first by a thread running on a CPU local to HBM NUMA node B. Will these pages then be physically placed on NUMA node A and B, respectively? How would you test this?

Background:

I have tested using umfMemspaceHighestBandwidthGet to allocate vectors in a Triad benchmark. I compared it to using plain malloc + controlling affinity with numactl. UMF gives less performance:

  • UMF: ~1040 GiB/s
  • numactl --membind=8-15: ~1120 GiB/s

These performance results are stable. I have used 96 OpenMP threads, each pinned to a core of the system described above.

lplewa added a commit to lplewa/unified-memory-framework that referenced this issue May 12, 2025
physical_id field stores os index, so we should use correct function
to get hwloc numanode object.

fixes: oneapi-src#1289
@lplewa
Copy link
Contributor

lplewa commented May 12, 2025

In UMF we do exactly what you did with numactl—we generate a HighestBandwidth namespace, which is really just a set of NUMA nodes (for each CPU we add the node with the highest bandwidth to the set). We membind every allocation to this set and let the kernel choose where to place each page.

Another alternative is to bind memory based on the memory‑allocating thread, but we think the first approach is better. If we get a request for the second approach, we can consider to add that option.

Regarding performance, could you share the benchmark details so we can test it on our side?

@breiters
Copy link
Author

breiters commented May 12, 2025

Here is the benchmark code (Makfile included) @lplewa .

It compares three memory allocation versions:

  • Plain malloc + numactl
  • OpenMP High Bandwidth Allocator (requires libmemkind)
  • UMF High Bandwidth Allocator

This is the output:

$ CC=icx make run
icx -qopenmp -O3 -march=native -I/home/ru37geh/local/include -L/home/ru37geh/local/lib64 triad.c -lnuma -lumf -o triad

numactl + malloc
OMP_NUM_THREADS=96 OMP_PLACES=CORES OMP_PROC_BIND=CLOSE numactl --membind=8-15 ./triad 0
Threads=96 N=1073741824 (32GiB)
GFLOPS=56.376196, Bandwidth[GiB/s]=1127.52

OpenMP high bandwidth allocator
OMP_NUM_THREADS=96 OMP_PLACES=CORES OMP_PROC_BIND=CLOSE ./triad 1
Threads=96 N=1073741824 (32GiB)
GFLOPS=2.870415, Bandwidth[GiB/s]=57.41

UMF high bandwidth allocator
OMP_NUM_THREADS=96 OMP_PLACES=CORES OMP_PROC_BIND=CLOSE ./triad 2
Threads=96 N=1073741824 (32GiB)
GFLOPS=52.112066, Bandwidth[GiB/s]=1042.24

Regarding binding memory to the allocating thread:
This would not be desired for us. Can't speak for everyone, but from our side, we would expect and prefer that memory is by default physically placed according to the first-touch policy on a local HBM node.

@lukaszstolarczuk
Copy link
Contributor

Discussion is still in progress, so I'll re-open this issue.

lplewa added a commit to lplewa/unified-memory-framework that referenced this issue May 14, 2025
lplewa added a commit to lplewa/unified-memory-framework that referenced this issue May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants