-
Notifications
You must be signed in to change notification settings - Fork 306
Fix kernel map collision on MGPU context #2401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -242,11 +242,17 @@ float fmha_fwd_v3(mha_fwd_args a, const ck_tile::stream_config& s) | |||||||||||||||||||||||||||||||||||
| static thread_local std::unordered_map<std::string, std::unique_ptr<AiterAsmKernel>> | ||||||||||||||||||||||||||||||||||||
| impl_ptr_map; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Include device ID in cache key so each GPU gets its own loaded module | ||||||||||||||||||||||||||||||||||||
| int current_device; | ||||||||||||||||||||||||||||||||||||
| HIP_CALL(hipGetDevice(¤t_device)); | ||||||||||||||||||||||||||||||||||||
| std::string dev_prefix = std::to_string(current_device) + ":"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const auto& cfg = it->second; | ||||||||||||||||||||||||||||||||||||
| const char* name = cfg.knl_name.c_str(); | ||||||||||||||||||||||||||||||||||||
| std::string co_name = get_kernel_co_name(cfg.co_name, arch_id); | ||||||||||||||||||||||||||||||||||||
| std::string key = dev_prefix + name; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+245
to
+253
|
||||||||||||||||||||||||||||||||||||
| // Include device ID in cache key so each GPU gets its own loaded module | |
| int current_device; | |
| HIP_CALL(hipGetDevice(¤t_device)); | |
| std::string dev_prefix = std::to_string(current_device) + ":"; | |
| const auto& cfg = it->second; | |
| const char* name = cfg.knl_name.c_str(); | |
| std::string co_name = get_kernel_co_name(cfg.co_name, arch_id); | |
| std::string key = dev_prefix + name; | |
| // Include device ID and co_name in cache key so each GPU/variant gets its own loaded module | |
| int current_device; | |
| HIP_CALL(hipGetDevice(¤t_device)); | |
| const auto& cfg = it->second; | |
| const char* name = cfg.knl_name.c_str(); | |
| std::string co_name = get_kernel_co_name(cfg.co_name, arch_id); | |
| std::string key = std::to_string(current_device) + ":" + co_name + ":" + name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
impl_ptr_mapis a process-widestatic std::unordered_mapthat is mutated viaemplace()without any synchronization. In MGPU setups it’s common for different host threads to run on different devices concurrently, and concurrent inserts/reads onunordered_mapare undefined behavior (can crash/corrupt the cache). Consider making this cachethread_local(as infmha_fwd_v3) or protecting all accesses with a mutex (or another thread-safe cache).