Skip to content

feat: add kernel-based copy mode to nvlink_bw_test - #2

Merged
staryxchen merged 1 commit into
mainfrom
add-kernel-copy-mode
Jul 10, 2026
Merged

feat: add kernel-based copy mode to nvlink_bw_test#2
staryxchen merged 1 commit into
mainfrom
add-kernel-copy-mode

Conversation

@staryxchen

Copy link
Copy Markdown
Owner

Summary

Add a __global__ copy kernel as an alternative to cudaMemcpyDeviceToDevice in example/nvlink_bw_test, selectable via a new -m/--mode memcpy|kernel flag (default: memcpy). The kernel uses vectorized uint4 (16-byte) load/stores and launches on the source GPU, writing to the destination GPU over P2P/NVLink.

This produces NVLink traffic that nvlink_monitor can observe, mirroring the memcpy path but exercising the SMs instead of the copy engine — useful for validating that NVML counters pick up SM-initiated traffic (they do).

Changes

New files

  • example/copy_kernel.h — declares launchCopyKernel()
  • example/copy_kernel.cu__global__ copyKernel (uint4, 256 threads/block) + launch wrapper. The only file compiled by nvcc; g++ compiles everything else and does the final link.

Modified

  • example/arg_parser.{h,cpp}CopyMode enum + mode field + -m/--mode parsing. Stays CUDA-free (arg_parser.h is included by the GPU-less test binary).
  • example/nvlink_bw_test.cppmeasureCopyTimeKernel() mirrors measureCopyTime()'s event timing; testCopyPerformance() dispatches on mode; mode printed in Configuration; -m in printUsage().
  • MakefileNVCC/NVCC_ARCH (sm_70/sm_80/sm_90 + compute_90 PTX for forward-compat), build/copy_kernel.o rule, linked into nvlink_bw_test. make test/check-format stay nvcc-free.
  • test/test_bw_test_args.cpp — 6 new --mode test cases.
  • README.md — documents -m/--mode and the nvcc requirement.

Verification

  • make check-format — clean (clang-format 14)
  • make test58/58 pass (52 existing + 6 new mode tests), no GPU/nvcc needed
  • make example — builds with nvcc 12.8 + g++ link
  • End-to-end on 8x H20 (sm_90): kernel mode ~266 GiB/s avg, memcpy ~285 GiB/s avg (100MB D2D). Kernel slightly slower as expected (SM load/store vs copy-engine DMA).
  • Cross-checked against nvlink_monitor: with a 3.5s memcpy test (500×2GB), bw_test reported 369.45 GiB/s vs nvlink_monitor steady-state 368.4 GiB/s — within 0.3%, confirming both tools agree when the test spans multiple monitor sampling windows.

Notes

  • CopyMode enum deliberately lives in arg_parser.h (CUDA-free) so CI's make test (no CUDA toolkit) still builds.
  • nvcc multi-arch covers V100/A100/H100 + PTX for future GPUs.

🤖 Generated with CodeBuddy Code

Add a __global__ copy kernel as an alternative to cudaMemcpyDeviceToDevice,
selectable via `-m/--mode memcpy|kernel` (default: memcpy). The kernel uses
vectorized uint4 (16-byte) loads/stores and launches on the source GPU,
writing to the destination GPU over P2P/NVLink. This produces NVLink traffic
that nvlink_monitor can observe, mirroring the memcpy path but exercising the
SMs instead of the copy engine.

New files:
- example/copy_kernel.h    declares launchCopyKernel()
- example/copy_kernel.cu   defines __global__ copyKernel + launch wrapper
  (compiled by nvcc; only file that needs nvcc)

Build:
- Makefile gains NVCC/NVCC_ARCH/NVCC_FLAGS (sm_70/sm_80/sm_90 + PTX for
  forward compat), a build/copy_kernel.o rule, and links it into
  nvlink_bw_test. g++ still does the final link. make test/check-format
  remain nvcc-free (copy_kernel.cu is not in TEST_SOURCES).

Tests:
- 6 new BwTestArgs cases for --mode (default, memcpy explicit, kernel short/
  long, invalid rejected, missing arg rejected). 58/58 pass.

Verified end-to-end on 8x H20: kernel mode ~266 GiB/s avg, memcpy ~285 GiB/s
avg for 100MB D2D copies (kernel slightly slower as expected for SM
load/store vs copy-engine DMA).

Signed-off-by: staryxchen <staryxchen@tencent.com>
@staryxchen
staryxchen merged commit 3560754 into main Jul 10, 2026
2 checks passed
@staryxchen
staryxchen deleted the add-kernel-copy-mode branch July 10, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants