Thread Affinity - 57300

ZenDNN User Guide (57300)

Document ID
57300
Release Date
2025-08-18
Revision
5.1 English

To improve ZenDNN performance, the behavior of OpenMP threads can be guarded precisely with thread affinity settings. A thread affinity defined at start up cannot be modified or changed during runtime of the application. Use the following methods to bind the requested OpenMP threads to the physical CPUs:

GOMP_CPU_AFFINITY environment variable binds threads to the physical CPUs.

Example

export GOMP_CPU_AFFINITY="0 3 1-2 4-15:2"

This command will bind the:

  • Initial thread to CPU 0
  • Second thread to CPU 3
  • Third and fourth threads to CPU 1 and CPU 2, respectively
  • Fifth thread to CPU 4
  • Sixth through tenth threads to CPUs 6, 8, 10, 12, and 14, respectively. It will then start the assignment back from the beginning of the list.

export GOMP_CPU_AFFINITY="0" binds all the threads to CPU 0.

Example

The affinity setting: export GOMP_CPU_AFFINITY=0-127, binds the threads to CPUs 0-127.

Note: GOMP_CPU_AFFINITY will be ignored if you export the KMP_AFFINITY variable.