[EBPF] gpu: replace map with fixed-size array for memory usage tracking#46799
Open
pjo256 wants to merge 3 commits intoDataDog:mainfrom
Open
[EBPF] gpu: replace map with fixed-size array for memory usage tracking#46799pjo256 wants to merge 3 commits intoDataDog:mainfrom
pjo256 wants to merge 3 commits intoDataDog:mainfrom
Conversation
Signed-off-by: Philip Ottesen <phiott256@gmail.com>
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
|
Hi @pjo256. From a first look it looks good, I'll run the full test pipeline and will make a full review later. Thanks a lot! |
Signed-off-by: Philip Ottesen <phiott256@gmail.com>
Author
|
@gjulianm Thanks! I've added a reno release note in the latest commit, let me know if anything else needs adjusting. |
Contributor
|
Hi @pjo256, CI is green. Just one minor change, could you remove the changelog note? We don't usually write them for changes like these to avoid having a massive changelog :D |
Signed-off-by: Philip Ottesen <phiott256@gmail.com>
Author
|
@gjulianm Done! I saw a failing release-notes check earlier and wasn't sure from the Reno docs 👍 |
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.
What does this PR do?
Replaces
map[memAllocType]uint64with[memAllocTypeCount]uint64fixed-size arrays in the GPU monitoring hot path. This affects two locations:kernelSpan.avgMemoryUsagein stream.go — accessed on every CUDA synchronization eventmemTsBuildersin aggregator.go — used when computing per-process GPU memory stats\If new memory types are added in the future, adding a new constant before
memAllocTypeCountin thememAllocTypeenum is all that's needed.Motivation
memAllocTypeis a 4-value enum (kernel binary, global, shared, constant memory). Using a map here adds overhead: hash computation, bucket lookups, and heap allocations on every access. A fixed-size array replaces this with direct indexing.A benchmarking script shows 6-23x speedup depending on workload (number of kernel launches between syncs), with allocations dropping from 240 B/op to 64 B/op.
Describe how you validated your changes
Existing unit tests in
stream_test.goandstats_test.goalready indexavgMemoryUsagebymemAllocTypeconstants (e.g.,span.avgMemoryUsage[sharedMemAlloc]), which works for both arrays and maps.Wrote standalone microbenchmarks reproducing the exact access patterns of
getCurrentKernelSpanandgetRawStats, comparing map vs array across varying kernel launch counts.In a production setting, serving an LLM like
Qwen3.5-397B-A17B, we might expect 1500-3000+ kernel launches per forward pass and 10+ forward passes per second - so this can cumulatively save ~20+ms of agent CPU time per second.