Conversation
Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
|
@copilot With the introduction of unique_ptr, I suspect we may introduced a memory leak potential, specifically at the destruction of the DEMSolver class. Can you have a check and figure out the possible cause? |
The risk was real in the initial commit ( This was already caught and corrected in commit
No further changes are needed; the current code is safe. |
Two improvements to
DEMSolver: controllable GPU selection at construction time, and exception-safe ownership of internal worker objects viastd::unique_ptr.GPU selection flavors
Flavor 1 – default (existing behavior, now explicit): scans available GPUs, uses at most 2.
DEMSolver sim; // or DEMSolver sim(2);Flavor 2 – integer count: warns if
nGPUs > 2, falls back to 1 GPU (both threads share device 0) when fewer than requested are available.Flavor 3 – explicit device IDs:
Changes
GpuManager: newGpuManager(const std::vector<int>& device_ids)constructor; duplicate IDs intentionally produce multiple streams on one device (single-GPU mode).scanNumDevices()madestaticfor pre-construction use.DEMSolver: newDEMSolver(std::vector<int>)overload; integer constructor now validates/warns instead of silently ignoringnGPUs.unique_ptrmigration:kT,dT,kTMain_InteractionManager,dTMain_InteractionManager,dTkT_InteractionManager,dTkT_GpuManagerare nowstd::unique_ptr. Destructor no longer requires manualdeletecalls; members are destroyed in safe reverse-declaration order (workers before managers).packTransferPointerssignature changed fromT*&toT*(pointer-by-value); no semantic change, required forunique_ptrcompatibility at call sites.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.