Core Binding Optimization

Enablement

You can set the following environment variables to enable this feature, which is applicable to network scenarios where the task scheduling capability is insufficient or the slow response problem is prominent.

export CPU_AFFINITY_CONF=<mode>,npu<value1>:<value2>-<value3>
  • <mode>: core binding mode. If this parameter is 0 or not set, core binding is disabled. If it is 1, coarse-grained core binding is enabled. If it is 2, fine-grained core binding is enabled.
  • npu<value1>:<value2>-<value3>: user-defined core binding range. This parameter is valid only when <mode> is not set to 0. <value1> indicates the NPU ID, and <value2>-<value3> specifies the CPU core binding range of the NPU process.

Working Principles

  • Coarse-grained core binding: All threads associated with a single NPU are bound to a specified CPU core area.
  • Fine-grained core binding: The main threads associated with a single NPU are bound to a specified CPU core area. Each thread exclusively occupies a core to implement isolation.

Example

  1. Enable coarse-grained core binding.
    export CPU_AFFINITY_CONF=1
  2. Enable fine-grained core binding.
    export CPU_AFFINITY_CONF=2
  3. Enable custom core binding.
    export CPU_AFFINITY_CONF=1,npu0:0-1,npu1:2-5,npu3:6-6
  4. After the preceding configuration is complete, the NPU binding details are as follows:
    • The NPU 0 process is bound to CPU cores 0 and 1.
    • The NPU 1 process is bound to CPU cores 2 to 5.
    • The NPU 3 process is bound to CPU core 6.
    • Other NPU processes use the default core zone.