Skip to content
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

Encapsulate Storage_base class #528

Merged
merged 6 commits into from
Dec 25, 2024
Merged

Encapsulate Storage_base class #528

merged 6 commits into from
Dec 25, 2024

Conversation

IvanaGyro
Copy link
Collaborator

@IvanaGyro IvanaGyro commented Dec 1, 2024

The first two commits are the same as #525. Please start to review from the third commit.
There are too many files changed to review. I leave comments on the changed lines which are not trivially renaming the variables. You can just review those parts.

With the current class definition, developers are able to change the variable storing the size of the storage without allocating the underlying storage, which potentially causes memory leaks.

To ensure there will be no surprising behavior caused by directly accessing the variables of Storage_base, all variables of Stroage_base are moved to its subclass, StorageImplementation, and are set as private. All functions outside of StorageImplementation should access the value of the variable via the getters.

The next step in refactoring the components related to Storage is to remove the Storage_base class.

Test result

This PR breaks no tests with CUDA, cuQuantum, cuTENSOR, MKL, CUTT, and HPTT enabled.

@IvanaGyro IvanaGyro force-pushed the encapsulate-storage branch 2 times, most recently from 0dd1be9 to 97a2597 Compare December 1, 2024 19:12
Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 16.15065% with 2627 lines in your changes missing coverage. Please review.

Project coverage is 23.58%. Comparing base (4a1fccb) to head (7b3ba91).
Report is 8 commits behind head on dev-master.

Files with missing lines Patch % Lines
src/backend/linalg_internal_cpu/Sub_internal.cpp 9.91% 327 Missing ⚠️
src/backend/linalg_internal_cpu/Div_internal.cpp 11.57% 321 Missing ⚠️
src/backend/linalg_internal_cpu/Mod_internal.cpp 1.23% 240 Missing ⚠️
src/backend/linalg_internal_cpu/Cpr_internal.cpp 0.00% 198 Missing ⚠️
src/backend/linalg_internal_cpu/iAdd_internal.cpp 10.67% 184 Missing ⚠️
src/backend/linalg_internal_cpu/iMul_internal.cpp 10.67% 184 Missing ⚠️
src/backend/linalg_internal_cpu/iSub_internal.cpp 11.65% 182 Missing ⚠️
src/backend/linalg_internal_cpu/iDiv_internal.cpp 12.62% 180 Missing ⚠️
src/backend/linalg_internal_cpu/Add_internal.cpp 18.18% 162 Missing ⚠️
src/backend/linalg_internal_cpu/Mul_internal.cpp 21.21% 156 Missing ⚠️
... and 31 more
Additional details and impacted files
@@              Coverage Diff               @@
##           dev-master     #528      +/-   ##
==============================================
- Coverage       23.64%   23.58%   -0.07%     
==============================================
  Files             211      211              
  Lines           44911    44926      +15     
  Branches        15039    14018    -1021     
==============================================
- Hits            10620    10595      -25     
- Misses          32641    32664      +23     
- Partials         1650     1667      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

`Storage::release()` serves for the function converting Storage and
Tensor to the numpy array. The reason for implementing this method is
that we are encapsulating Storage and the relative classes, which mean
we don't want other classes or functions to directly access the member
variables.

This is just a temporary solution and will be removed when we use
std::vector as the underlying storage because it is impossible to make
std::vector drops its ownership of the underlying storage.
The size of Scalar is small, so it's cheap for creating a temporary
Storage containing only a copy of the value of Scalar.

This change is a step toward encapsulating the classes related to
Storage.
@IvanaGyro IvanaGyro force-pushed the encapsulate-storage branch from 97a2597 to 36f65fd Compare December 2, 2024 13:51
With the current class definition, developers are able to change the
variable storing the size of the storage without allocating the
underlying storage, which potentially causes memory leaks.

To ensure there will be no surprising behavior caused by directly
accessing the variables of Storage_base, all variables of Stroage_base
are moved to its subclass, StorageImplementation<DType>, and are set as
private. All functions outside of StorageImplementation<DType> should
access the value of the variable via the getters.

The next step in refactoring the components related to Storage is to
remove the Storage_base class.
We can check whether HPTT is enabled from the compiler definitions in
compile_commands.json.
@IvanaGyro IvanaGyro force-pushed the encapsulate-storage branch from 36f65fd to 09b2c37 Compare December 2, 2024 14:07
@IvanaGyro IvanaGyro requested a review from hunghaoti December 3, 2024 15:57
@hunghaoti hunghaoti merged commit 3cc7736 into dev-master Dec 25, 2024
4 checks passed
@hunghaoti hunghaoti deleted the encapsulate-storage branch December 25, 2024 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants