Skip to content

Commit 17449ae

Browse files
authored
refactor(device): remove dead code from DeviceContext, add dsp_count guard (#7361)
* refactor(device): remove dead code from DeviceContext, add dsp_count 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). * fix(dsp): replace assert with runtime WARNING_QUIT for dsp_count 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 #7361.
1 parent 23e677e commit 17449ae

3 files changed

Lines changed: 4 additions & 61 deletions

File tree

source/source_base/module_device/device.h

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,6 @@ class DeviceContext {
117117
*/
118118
void init();
119119

120-
/**
121-
* @brief Check if the DeviceContext has been initialized
122-
* @return true if init() has been called successfully
123-
*/
124-
bool is_initialized() const { return initialized_; }
125-
126-
/**
127-
* @brief Check if GPU is enabled and available
128-
* @return true if GPU device is bound and usable
129-
*/
130-
bool is_gpu_enabled() const { return gpu_enabled_; }
131-
132120
/**
133121
* @brief Get the bound GPU device ID
134122
* @return Device ID (0-based), or -1 if not initialized
@@ -147,36 +135,6 @@ class DeviceContext {
147135
*/
148136
int get_local_rank() const { return local_rank_; }
149137

150-
/**
151-
* @brief Set the device type (CpuDevice, GpuDevice, or DspDevice)
152-
* @param type The device type
153-
*/
154-
void set_device_type(AbacusDevice_t type) { device_type_ = type; }
155-
156-
/**
157-
* @brief Get the device type
158-
* @return AbacusDevice_t The device type
159-
*/
160-
AbacusDevice_t get_device_type() const { return device_type_; }
161-
162-
/**
163-
* @brief Check if the device is CPU
164-
* @return true if the device is CPU
165-
*/
166-
bool is_cpu() const { return device_type_ == CpuDevice; }
167-
168-
/**
169-
* @brief Check if the device is GPU
170-
* @return true if the device is GPU
171-
*/
172-
bool is_gpu() const { return device_type_ == GpuDevice; }
173-
174-
/**
175-
* @brief Check if the device is DSP
176-
* @return true if the device is DSP
177-
*/
178-
bool is_dsp() const { return device_type_ == DspDevice; }
179-
180138
// Disable copy and assignment
181139
DeviceContext(const DeviceContext&) = delete;
182140
DeviceContext& operator=(const DeviceContext&) = delete;
@@ -190,21 +148,9 @@ class DeviceContext {
190148
int device_id_ = -1;
191149
int device_count_ = 0;
192150
int local_rank_ = 0;
193-
AbacusDevice_t device_type_ = CpuDevice;
194-
195151
std::mutex init_mutex_;
196152
};
197153

198-
/**
199-
* @brief Get the device type enum from DeviceContext (runtime version).
200-
* @param ctx Pointer to DeviceContext
201-
* @return AbacusDevice_t enum value
202-
*/
203-
inline AbacusDevice_t get_device_type(const DeviceContext* ctx)
204-
{
205-
return ctx->get_device_type();
206-
}
207-
208154
} // end of namespace base_device
209155

210156
#endif // MODULE_DEVICE_H_

source/source_base/module_device/device_helpers.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ namespace base_device
2121
// Forward declaration
2222
class DeviceContext;
2323

24-
/**
25-
* @brief Get the device type enum from DeviceContext (runtime version).
26-
* @param ctx Pointer to DeviceContext
27-
* @return AbacusDevice_t enum value
28-
*/
29-
inline AbacusDevice_t get_device_type(const DeviceContext* ctx);
30-
3124
/**
3225
* @brief Get the device type enum for a given device type (compile-time version).
3326
* @tparam Device The device type (DEVICE_CPU or DEVICE_GPU)

source/source_main/driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ void Driver::reading()
130130
#endif
131131

132132
#ifdef __DSP
133+
if (PARAM.inp.dsp_count <= 0)
134+
{
135+
ModuleBase::WARNING_QUIT("driver", "dsp_count must be > 0");
136+
}
133137
base_device::memory::set_dsp_cluster_id(GlobalV::MY_RANK % PARAM.inp.dsp_count);
134138
BlasConnector::set_dsp_cluster_id(GlobalV::MY_RANK % PARAM.inp.dsp_count);
135139
#endif

0 commit comments

Comments
 (0)