refactor(device): remove dead code from DeviceContext, add dsp_count guard#7361
Merged
mohanchen merged 2 commits intoMay 18, 2026
Merged
Conversation
…guard Remove unused device_type subsystem from DeviceContext: - Delete set_device_type(), get_device_type(), is_cpu(), is_gpu(), is_dsp() methods (all zero callers verified via exhaustive search) - Delete is_initialized(), is_gpu_enabled() (zero callers) - Delete device_type_ private field (only consumed by removed methods) - Delete standalone get_device_type(const DeviceContext*) function (zero callers; all 48 call sites use the template version get_device_type(const Device*)) - Delete forward declaration in device_helpers.h Add assert(PARAM.inp.dsp_count > 0) guard in driver.cpp to prevent modulo-by-zero undefined behavior. All other DeviceContext members retained (init(), get_device_id(), get_device_count(), get_local_rank() — all have active callers). Build verified with cmake --build (MPI+LCAO).
There was a problem hiding this comment.
Pull request overview
This PR is a cleanup/refactor following the DSP routing fix work, removing unused DeviceContext “device_type” APIs and adding a guard intended to prevent modulo-by-zero when computing DSP cluster IDs from dsp_count.
Changes:
- Removed the unused
DeviceContextruntimedevice_typeaccessors and the associateddevice_type_field. - Removed the unused
get_device_type(const DeviceContext*)runtime helper declaration. - Added a
dsp_count > 0guard before computing DSP cluster IDs inDriver::reading().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| source/source_main/driver.cpp | Adds a DSP dsp_count guard before setting DSP cluster IDs for memory/BLAS routing. |
| source/source_base/module_device/device.h | Removes unused DeviceContext runtime device-type APIs and device_type_ storage. |
| source/source_base/module_device/device_helpers.h | Removes unused runtime get_device_type(const DeviceContext*) forward declaration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
assert() is removed in release builds (NDEBUG), leaving modulo-by-zero\nunprotected. Replace with WARNING_QUIT that works in all builds.\n\nAlso remove now-unused #include <cassert> from the #ifdef __DSP block.\n\nAddresses PR review feedback on deepmodeling#7361.
mohanchen
approved these changes
May 18, 2026
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
Removes dead code from DeviceContext and adds a
dsp_count > 0guard to prevent modulo-by-zero.Changes
1. Remove dead
device_typesubsystem from DeviceContext (device.h)Exhaustive code search across entire
source/tree confirmed zero callers for:set_device_type()get_device_type()memberget_device_type()call sites use the template version fromdevice_helpers.his_cpu()is_gpu()is_gpuin codebase are local bool variables, not this method)is_dsp()is_initialized()is_gpu_enabled()Also removed:
get_device_type(const DeviceContext*)— zero callers (all call sites useget_device_type(const Device*)template)device_helpers.hKept (all have active callers):
init(),get_device_id(),get_device_count(),get_local_rank()2. Add
dsp_count > 0guard (driver.cpp)Prevents modulo-by-zero undefined behavior (4 sites do
MY_RANK % dsp_count;dsp_countdefaults to 4 but has no input validation).