Repository navigation
feat(ep): sync KIWI EP with upstream tuning, proxy affinity and fixes - #950
Conversation
- Select the automatic num_blocks/rcomp_backend from per-(GPU arch, NIC family) tuning tables (gfx942/CX7, gfx950/Pollara), falling back to the generic rule; make_config resolves the NIC, arch and NIC family, and ranks agree on HIP IPC provisioning - Bind proxy threads to the GPU's PCI-local CPUs within the process affinity mask instead of pinning each to one core - Space payload readiness flags 64 bytes apart - Rename KIWI's throwing HIP_CHECK to KIWI_HIP_CHECK so it no longer clashes with the EP's aborting HIP_CHECK - Keep invoke::Context's callback registry on the heap so a moved context's endpoints stay valid
|
GPU CI for
Test groups (the steps that run in those jobs): kiwi. Lanes follow the changed files. Adding |
jhchouuu
left a comment
There was a problem hiding this comment.
These match upstream KIWI d7bb0d1 (apps/ep, apps/common/topology, invoke.hpp). CI on c4aedef ran the KIWI single-node test and all six EP16 backend/dtype runs on MI300X_MLX, and they pass, so the two-node entry is covered. A few comments inline.
| if (hca_name.empty()) { | ||
| return {}; | ||
| } | ||
| std::string prefix = hca_name.substr(0, hca_name.find('_')); |
There was a problem hiding this comment.
The family comes from the device name, so a NIC renamed by rdma-core's persistent naming (for example an ionic device named rocep9s0) falls back to the generic rule without any message. net_context_t already opens the device through mori's RdmaContext, and RdmaDevice::GetDeviceAttr() has vendor_id / vendor_part_id (Pensando 0x1dd8; Mellanox 0x15b3, part 0x1021 for CX7). Could the family come from those instead?
There was a problem hiding this comment.
Good catch, agreed. A renamed device misses both prefixes and silently gets the generic rule, and a renamed CX7 also loses the cx7 check. I now key the family off the PCI vendor/device IDs instead of the name. They are read from /sys/class/infiniband//device/{vendor,device}, which exist whatever the device is called: 0x1dd8 is pollara, and 0x15b3 with 0x1021 is cx7. The name prefix stays only as a fallback. I didn't go through RdmaContext / GetDeviceAttr() for two reasons. First, ibv_device_attr.vendor_id is whatever the driver reports, and on CX7 that is the OUI 0x02c9, not the PCI vendor 0x15b3 (vendor_part_id is 4129 = 0x1021). Second, the family is needed in make_config() to size the queues, before ep_comm_context_t creates net_context_t. So using the attributes would mean opening the device a second time or moving net_context_t creation ahead of the EP context. I also added a one-time warning when no tuning table matches the GPU arch and NIC family, so a fallback is visible.
| {8, 4, 32, rcomp_backend_t::RDMA_ONLY}, {8, 8, 32, rcomp_backend_t::HYBRID}, | ||
| {8, 16, 32, rcomp_backend_t::HYBRID}, {8, 32, 32, rcomp_backend_t::HYBRID}, | ||
| {8, 64, 64, rcomp_backend_t::HYBRID}, {16, 1, 12, rcomp_backend_t::RDMA_ONLY}, | ||
| {16, 2, 20, rcomp_backend_t::RDMA_ONLY}, {16, 4, 32, rcomp_backend_t::HYBRID}, |
There was a problem hiding this comment.
The description says this table matches the old generic rule, but it does only at power-of-two token counts: at world size 8, 5-7 tokens now pick HYBRID (generic: RDMA_ONLY below 8), and at world size 16/32/64, 3 tokens now pick HYBRID (generic: below 4). Is that intended?
There was a problem hiding this comment.
For now I only measured power-of-two token counts. We can always refine this table if necessary.
| // capacity selects hybrid; explicit backend selection remains fixed. | ||
| // capacity selects hybrid, which the capacity bucket does if any does; | ||
| // explicit backend selection remains fixed. | ||
| bool rcomp_ipc_resources_required() const { |
There was a problem hiding this comment.
provisioned_num_blocks() and this read only the capacity bucket, so they rely on every table being monotonic (blocks never decreasing, HYBRID at capacity if any smaller bucket is HYBRID). Nothing in mori checks that: a decreasing block row aborts at launch (dispatch.hip.cpp:744-749), and a HYBRID row below an RDMA_ONLY capacity row launches dispatch<true> without IPC resources. Upstream has the check in apps/ep/tests/test_ep_block_count.hip.cpp (require_monotonic). Could it come along, or could these two take the max / any over the rules up to capacity?
There was a problem hiding this comment.
Yeah we should also add the same check from kiwi here.
There was a problem hiding this comment.
Good point. I went with the second option: make_config now scans every token count up to capacity once and stores the max num_blocks and whether any count selects HYBRID. provisioned_num_blocks() and rcomp_ipc_resources_required() read that instead of the capacity bucket, so provisioning no longer depends on the tables being monotonic, and the per-launch check is still a field read. For the current tables the result is identical to the capacity bucket (checked at world sizes 2-64, capacity 1-4096).
| } // namespace | ||
|
|
||
| std::vector<int> current_allowed_cpus() { | ||
| std::vector<int> proxy_thread_cpu_set() { |
There was a problem hiding this comment.
In #860 @JiakunYan asked for a per-thread vs per-GPU-set pinning comparison before changing this, and the description lists the affinity change as not measured. Do you have before/after numbers? It now reads the same local_cpulist as mori's GpuLocalCpuList (include/mori/application/utils/cpu_affinity.hpp:47); could it reuse that helper and honor MORI_IGNORE_CPU_AFFINITY (#935)? It also still aborts if sched_setaffinity fails (L166), where mori's helper warns.
There was a problem hiding this comment.
I measured per-thread and per-GPU-set pinning and I didn't see meaningful difference, so I just changed it in kiwi-ep to do it the mori way. Yes it should reuse the mori helper here.
| // cache line, and writes from different QPs into that shared line appear to | ||
| // serialize at the NIC/memory controller. Padding every flag out to its own | ||
| // cache line removes that false sharing. | ||
| inline constexpr size_t KIWI_EP_READINESS_FLAG_STRIDE = 64; |
There was a problem hiding this comment.
This makes both readiness regions 64x larger (2 x world_size x max tokens x 64 B, e.g. 32 MiB at EP64 with 4096 tokens, 512 KiB before), and reset() clears all of it. Are there upstream measurements of the gain?
There was a problem hiding this comment.
Yes, I measured it. It makes 64 tokens/GPU 3-8% faster at 2/4/8 nodes. I don't think the memory usage matters since it is negligible compared the the memory usage of the token data.
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| // SOFTWARE. | ||
|
|
||
| // MI355X with Pollara NICs: BF16, hidden 7168, top-k 8, eight ranks per node. |
There was a problem hiding this comment.
KIWI isn't built in the MI355X CI jobs, and the description says this table wasn't run on hardware here. Was it measured upstream? The key has no dtype or hidden size, so it also applies to shapes other than BF16 / 7168 / top-8.
There was a problem hiding this comment.
It was measured upstream on MI355X + Pollara at EP8/16/32, 1–64 tokens/rank, with BF16 / 7168 / top-8. We can always add dtype or hidden size in the future when we have more data points.
| CPU_ZERO(&actual); | ||
| sched_getaffinity(0, sizeof(actual), &actual); | ||
| std::fprintf(stderr, "KIWI_PROXY_AFFINITY_DEBUG pid=%ld tid=%ld bound=%s\n", | ||
| static_cast<long>(getpid()), static_cast<long>(gettid()), |
There was a problem hiding this comment.
Nit: gettid() needs glibc 2.30, and the wheel image is manylinux_2_28 (glibc 2.28), so this file won't compile there if KIWI is ever enabled in wheels. syscall(SYS_gettid) avoids that.
There was a problem hiding this comment.
Good point, fixed: it now uses syscall(SYS_gettid), so the file builds on manylinux_2_28 (glibc 2.28) if KIWI is ever enabled in wheels.
|
|
||
| // Check HIP call and throw on failure | ||
| #define HIP_CHECK(call) \ | ||
| #define KIWI_HIP_CHECK(call) \ |
There was a problem hiding this comment.
Nit: with this renamed, the #undef HIP_CHECK in src/ops/dispatch_combine_kiwi/hip_check.hpp:54 is no longer needed.
There was a problem hiding this comment.
Right, removed the #undef; this is now the only HIP_CHECK definition.
rdma-core's persistent naming can rename RDMA devices (e.g. an ionic NIC to rocep9s0), so the name prefix missed both ionic_* and mlx5_* and the tuning lookup silently fell back to the generic rule. Read the PCI vendor/device IDs under /sys/class/infiniband/<name>/device for every device (0x1dd8 is pollara, 0x15b3:0x1021 is cx7) and keep the name rule only as a fallback. Log at debug level when no tuning table matches.
gettid() needs glibc 2.30, and the wheel image is manylinux_2_28 (glibc 2.28), so topology.cpp would not build there if KIWI were enabled in wheels.
The KIWI queue header now defines KIWI_HIP_CHECK, so nothing else defines HIP_CHECK before this header.
jhchouuu
left a comment
There was a problem hiding this comment.
Thanks for the fixes. 89c4c59 (NIC family from the PCI vendor/device IDs), 93322a4 (syscall(SYS_gettid)) and da1a530 (#undef removed) look good, and the answers on affinity, flag stride and the tuning tables make sense.
A correction to my earlier comment: ibv_device_attr.vendor_id is the OUI (0x02c9 for Mellanox, as in mori's RdmaDeviceVendorId), not the PCI vendor ID, so reading the PCI IDs from sysfs is the right approach.
On the monotonic table check: will you add it in this PR or in a follow-up? Either works for me.
The MI300X_MLX internode failure on da1a530 is node2 being unreachable (No route to host), not this change; it needs a rerun once the runner is back.
provisioned_num_blocks() and rcomp_ipc_resources_required() read only the capacity bucket, so they relied on every tuning table being monotonic. A table with a larger block count below capacity would abort at launch, and a HYBRID row below an RDMA_ONLY capacity row would launch dispatch<true> without IPC resources. make_config now scans token counts 1..capacity once (provisioned_runtime_defaults) and stores the max num_blocks and whether any count selects HYBRID; both functions read that. Results are unchanged for the current tables.
Thanks, and thanks for the OUI correction. For the monotonic table check I took the second option from your comment instead of porting require_monotonic: 097731d makes provisioned_num_blocks() take the maximum block count over every token count from 1 to capacity, and rcomp_ipc_resources_required() is true if any of those counts selects HYBRID. Provisioning no longer depends on the tables being monotonic, so a decreasing block row can't exceed what was provisioned, and a HYBRID row below an RDMA_ONLY capacity row still gets IPC resources. With that, I don't think the check is needed in this PR; I can add it as a follow-up if you'd still like it as a guard on the tuning tables. BTW, the two-node test is still broken. |
Summary
This brings
mori.ops.dispatch_combine_kiwiup to date with five KIWI changes made after the import in #860: per-hardware tuning tables, a new way of placing proxy threads on CPUs, wider spacing for readiness flags, and two correctness fixes in the queue/invoke core.Changes
Tuning tables per GPU arch and NIC family
num_blocksorrcomp_backendis left on automatic, the values now come from a table keyed by GPU arch and NIC family.ep_tuning.{hpp,cpp}, with one file per platform undertuning/.make_configresolves the NIC name,gpu_archandnic_family, and still applies the CU-count cap at the same point.rdma::resolve_device_name(), whichnet_context_talso uses, so the tuning key always describes the NIC the proxies actually open.ep_context_tnow allgathers each rank's choice and sets up HIP IPC if any rank needs it.Proxy thread CPU affinity
topology.cppfrom 583 to about 180 lines.KIWI_PROXY_AFFINITY_DEBUG=1prints the chosen set and each thread's binding.Readiness flag stride
KIWI_EP_READINESS_FLAG_STRIDE). The flag index, heap layout andreset()memsets are updated to match.Fixes in the queue/invoke core
HIP_CHECKis renamed toKIWI_HIP_CHECK. It clashed with the EP's abortingHIP_CHECK, and which one a file got depended on include order.invoke::Contextnow keeps its callback registry on the heap. Before, moving a context left its endpoint dispatchers pointing at the registry in the moved-from object. Its device buffers are now held byunique_ptr, so the default move operations are correct.Testing
BUILD_OPS_KIWI=ONandGPU_TARGETS=gfx942;gfx950;gfx1250. The KIWI sources compile without warnings.tests/python/ops/test_kiwi_dispatch_combine.pygives 20 passed and 18 skipped, the same as onmain.ionicbecomespollara, andmlx5with device 0x1021 becomescx7;KIWI_PROXY_AFFINITY_DEBUG=1, every proxy thread was bound to the GPU-local CPUs within the process mask.Not covered: the gfx950/Pollara table on real hardware, the two-node EP16 entry, and performance measurements for the flag stride and the affinity change.