feat: add kernel-based copy mode to nvlink_bw_test - #2
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
__global__copy kernel as an alternative tocudaMemcpyDeviceToDeviceinexample/nvlink_bw_test, selectable via a new-m/--mode memcpy|kernelflag (default:memcpy). The kernel uses vectorizeduint4(16-byte) load/stores and launches on the source GPU, writing to the destination GPU over P2P/NVLink.This produces NVLink traffic that
nvlink_monitorcan 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— declareslaunchCopyKernel()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}—CopyModeenum +modefield +-m/--modeparsing. Stays CUDA-free (arg_parser.his included by the GPU-less test binary).example/nvlink_bw_test.cpp—measureCopyTimeKernel()mirrorsmeasureCopyTime()'s event timing;testCopyPerformance()dispatches onmode; mode printed in Configuration;-minprintUsage().Makefile—NVCC/NVCC_ARCH(sm_70/sm_80/sm_90 + compute_90 PTX for forward-compat),build/copy_kernel.orule, linked intonvlink_bw_test.make test/check-formatstay nvcc-free.test/test_bw_test_args.cpp— 6 new--modetest cases.README.md— documents-m/--modeand the nvcc requirement.Verification
make check-format— clean (clang-format 14)make test— 58/58 pass (52 existing + 6 new mode tests), no GPU/nvcc neededmake example— builds with nvcc 12.8 + g++ linknvlink_monitor: with a 3.5s memcpy test (500×2GB),bw_testreported 369.45 GiB/s vsnvlink_monitorsteady-state 368.4 GiB/s — within 0.3%, confirming both tools agree when the test spans multiple monitor sampling windows.Notes
CopyModeenum deliberately lives inarg_parser.h(CUDA-free) so CI'smake test(no CUDA toolkit) still builds.🤖 Generated with CodeBuddy Code