Refactor device info retrieval into shared utility with global caching - #1
Draft
kiddyjinjin with Copilot wants to merge 5 commits into
Draft
Refactor device info retrieval into shared utility with global caching#1kiddyjinjin with Copilot wants to merge 5 commits into
kiddyjinjin with Copilot wants to merge 5 commits into
Conversation
- Add DeviceInfo struct and getter functions to flag_gems::utils namespace - Move device info caching logic from mm.cpp to shared utils.cpp - Update flash_attn_varlen_func.cpp to use cached utils::get_sm_count() - Remove redundant cuda_runtime includes from mm.cpp and flash_attn_varlen_func.cpp Co-authored-by: kiddyjinjin <54064850+kiddyjinjin@users.noreply.github.com>
…ault Co-authored-by: kiddyjinjin <54064850+kiddyjinjin@users.noreply.github.com>
Co-authored-by: kiddyjinjin <54064850+kiddyjinjin@users.noreply.github.com>
Co-authored-by: kiddyjinjin <54064850+kiddyjinjin@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor device information retrieval logic into a shared module
Refactor device info retrieval into shared utility with global caching
Dec 3, 2025
kiddyjinjin
force-pushed
the
master
branch
2 times, most recently
from
December 16, 2025 12:21
4801325 to
c6b714e
Compare
kiddyjinjin
force-pushed
the
master
branch
7 times, most recently
from
January 29, 2026 08:07
24bbc5c to
a63d0f4
Compare
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.
PR Category
Refactor
Type of Change
Performance Optimization | Refactor
Description
Extract device info retrieval logic from
flash_attn_varlen_func.cppand consolidate withmm.cppinto a shared, globally-cached utility inflag_gems::utils.Changes:
DeviceInfostruct and cached getter toinclude/flag_gems/utils.handlib/utils.cppcudaGetDevice/cudaGetDevicePropertiesinflash_attn_varlen_func.cppwithutils::get_sm_count()DeviceInfoimplementation frommm.cpp, use shared utilityUsage:
Provides
get_device_id(),get_l2_cache_size(),get_sm_count(),get_major()with thread-safe initialization (C++17 static local).Issue
Resolves device info retrieval inefficiency - properties now queried once per process instead of every function call.
Progress
Performance
Eliminates repeated CUDA runtime API calls for device properties. Fallback defaults (A100: 108 SMs, 40MB L2, major=8) if queries fail.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.