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] Multiply strided inputs and output #2434

Merged

Conversation

djeong20
Copy link
Contributor

Commits to be reviewed in this PR

[TensorV2] Multiply strided inputs and output

This patch adds the implementation of multiplication operation that supports different strided inputs and output.

Self-evaluation:

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

Signed-off-by:Donghyeon Jeong [email protected]

[TensorV2] Additional functionality to access tensor elements

This commit adds functionality to retrieving and modifying tensor elements in specific locations.
This will provide convenience in implementing the math operation of tensor.

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
Collaborator

taos-ci commented Jan 29, 2024

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #2434. 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
Collaborator

@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.

return ((float *)getData())[i];
}

const float FloatTensor::getValue(unsigned int batch, unsigned int c,
Copy link
Contributor

Choose a reason for hiding this comment

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

b,c,h,w or batch, channel, height, width ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

b,c,h,w seems more reasonable.

* @brief return value at specific location
* @param[in] idx location
*/
const float getValue(unsigned int i) const noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

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

idx ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

This commit adds functionality to retrieving and modifying tensor elements in specific locations.
This will provide convenience in implementing the math operation of tensor.

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

Signed-off-by: Donghyeon Jeong <[email protected]>
This patch adds the implementation of multiplication operation that supports different strided inputs and output.

**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 force-pushed the impl/tensor_v2/multiply_strided branch from d4ab173 to c436e3c Compare January 30, 2024 01:32
Copy link
Collaborator

@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.

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!

* @param[in] h height location
* @param[in] w width location
* @param[in] value value to be stored
* @param[in] beta scalar to multiply output with and add
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion:
How about describing params like beta something like:
x = x * beta + value for better intuition? Would it make doc more nasty?

for (unsigned int h = 0; h < height(); ++h) {
for (unsigned int w = 0; w < width(); ++w) {
output.addValue(
b, c, h, w, getValue(b, c, h, w) * m.getValue<_FP16>(b, c, h, w),
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need _FP16 in m.getValue? I thought we do not need to specify the type in TensorV2 level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do. m is a TensorV2, not a HalfTensor, which means getValue is a Tensor::getValue that requires template argument.

for (unsigned int h = 0; h < height(); ++h) {
_FP16 *out_data = output.getAddress<_FP16>(b, c, h, 0);
const _FP16 *m_data = m.getAddress<_FP16>(b, c, h, 0);
const _FP16 *in_data = (_FP16 *)getAddress(getIndex(b, c, h, 0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need the type casting for getAddress? This is HalfTensor->getAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Since getAddress is an override method from TensorBase, it returns a void pointer, not _FP16 pointer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need overwrite getAddress function from tensor base? How about add getAddress function without overwriting?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We discussed offline and we will remove getAddress function in tensor_base.h later.

Copy link
Member

@SeoHyungjun SeoHyungjun 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
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

@jijoongmoon jijoongmoon merged commit 5e07bd1 into nnstreamer:main Feb 5, 2024
40 checks passed
@djeong20 djeong20 deleted the impl/tensor_v2/multiply_strided branch February 8, 2024 06:21
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.

None yet

6 participants