Skip to content

refactor: device module#7222

Open
mohanchen wants to merge 3 commits intodeepmodeling:developfrom
mohanchen:refactor4
Open

refactor: device module#7222
mohanchen wants to merge 3 commits intodeepmodeling:developfrom
mohanchen:refactor4

Conversation

@mohanchen
Copy link
Copy Markdown
Collaborator

refactor: device module

…iles

This refactoring separates DSP-related memory operations from the main memory_op files:

- Created memory_op_dsp.h: Contains DSP-specific struct declarations (resize_memory_op_mt, set_memory_op_mt, delete_memory_op_mt)
- Created memory_op_dsp.cpp: Contains DSP-specific implementation and template instantiations
- Modified memory_op.h: Added include for memory_op_dsp.h and removed DSP-related code
- Modified memory_op.cpp: Removed DSP-related headers and implementation
- Updated Makefile.Objects: Added memory_op_dsp.o to OBJS_BASE
- Removed unused CMakeLists.txt

The refactoring maintains all existing functionality while improving code organization by separating DSP-specific code from general memory operations.

Modified files:
- source/Makefile.Objects
- source/source_base/module_device/memory_op.cpp
- source/source_base/module_device/memory_op.h

New files:
- source/source_base/module_device/memory_op_dsp.cpp
- source/source_base/module_device/memory_op_dsp.h

Removed files:
- source/source_base/module_device/CMakeLists.txt (unused)
@mohanchen mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Apr 9, 2026
This refactoring implements dependency inversion for DSP selector:

- Created dsp_selector.h and dsp_selector.cpp: Define abstract interface and default implementation for DSP selector
- Created dsp_config.cpp: Initialize DSP selector with rank calculation
- Modified memory_op_dsp.cpp: Use new DSP selector instead of direct PARAM dependency
- Modified input_conv.cpp: Call init_dsp_selector during parameter conversion
- Modified parameter.h: Add init_dsp_selector declaration
- Updated CMakeLists.txt and Makefile.Objects: Add new files to build system

The refactoring eliminates direct dependency between module_device and source_io by using an abstract interface for DSP rank selection.

Changes made:
- Implemented abstract DspSelector interface
- Created DefaultDspSelector implementation
- Added create_default_selector factory function
- Modified code to use standard C++ exceptions instead of ModuleBase::WARNING_QUIT
- Updated build configuration to include new files

This change improves code modularity and maintainability by following the dependency inversion principle.
@mohanchen mohanchen requested a review from Cstandardlib April 9, 2026 04:12
@mohanchen mohanchen requested a review from Critsium-xy April 9, 2026 09:24
@Critsium-xy
Copy link
Copy Markdown
Collaborator

Need testing about whether this can exactly run on DPS hardware. @Cstandardlib


namespace base_device
{
namespace memory
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dsp_selector belongs to base_device::memory, but will be used by every function that needs to be run on DSP.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine.

@Critsium-xy
Copy link
Copy Markdown
Collaborator

Code logic seems a bit strange. This seems to make things much more complex

@mohanchen
Copy link
Copy Markdown
Collaborator Author

Code logic seems a bit strange. This seems to make things much more complex

It is a new style of coding, we need to have more discussion on this topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants