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

[TensorV2] Refactoring TensorBase pointer to shared_ptr #2428

Merged

Conversation

djeong20
Copy link
Contributor

This PR proposes refactoring the TensorV2 class to use a shared_ptr instead of a raw pointer for managing its TensorBase object. By adopting this change, we can improve the safety and reliability of our code and reduce the likelihood of memory leaks and other issues related to manual memory management.

Changes proposed in this PR:

  • Replace the TensorBase pointer in the Tensor class with a shared_ptr.
  • Update any relevant code to use the shared_ptr instead of the raw pointer.

Self-evaluation:

  1. Build test: [X]Passed [ ]Failed [ ]Skipped
  2. Run test: [X]Passed [ ]Failed [ ]Skipped

This PR proposes refactoring the TensorV2 class to use a shared_ptr instead of a raw pointer for managing its TensorBase object.
By adopting this change, we can improve the safety and reliability of our code and reduce the likelihood of memory leaks and other issues related to manual memory management.

**Changes proposed in this PR:**
- Replace the TensorBase pointer in the Tensor class with a shared_ptr.
- Update any relevant code to use the shared_ptr instead of the raw pointer.

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghyeon Jeong <[email protected]>
@taos-ci
Copy link

taos-ci commented Jan 26, 2024

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #2428. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://ci.nnstreamer.ai/.

Copy link

@taos-ci taos-ci left a comment

Choose a reason for hiding this comment

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

@djeong20, 💯 All CI checkers are successfully verified. Thanks.

@@ -79,14 +87,16 @@ TensorV2::TensorV2(const TensorDim &d, const void *buf) {
TensorV2::TensorV2(
std::vector<std::vector<std::vector<std::vector<float>>>> const &d,
ml::train::TensorDim::TensorType t_type) {
itensor = new FloatTensor(d, t_type.format);
itensor = std::shared_ptr<FloatTensor>(new FloatTensor(d, t_type.format),
std::default_delete<FloatTensor>());
}

#ifdef ENABLE_FP16
Copy link
Collaborator

Choose a reason for hiding this comment

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

It will be removed according to our offline discussion.

Copy link
Collaborator

@jijoongmoon jijoongmoon left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@skykongkong8 skykongkong8 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jijoongmoon jijoongmoon merged commit c304e91 into nnstreamer:main Feb 2, 2024
31 checks passed
djeong20 added a commit to djeong20/nntrainer that referenced this pull request Feb 2, 2024
This PR resolves a bug that occurred after nnstreamer#2428 in the TensorV2 class when getting a shared data tensor, which shares memory.

** Self-evaluation**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghyeon Jeong <[email protected]>
jijoongmoon pushed a commit that referenced this pull request Feb 5, 2024
This PR resolves a bug that occurred after #2428 in the TensorV2 class when getting a shared data tensor, which shares memory.

** Self-evaluation**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghyeon Jeong <[email protected]>
@djeong20 djeong20 deleted the refactor/tensor_v2/tensor_base_ptr branch February 8, 2024 06:21
EunjuYang pushed a commit to EunjuYang/nntrainer that referenced this pull request Aug 28, 2024
This PR resolves a bug that occurred after nnstreamer#2428 in the TensorV2 class when getting a shared data tensor, which shares memory.

** Self-evaluation**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghyeon Jeong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants