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

[ Tensor ] UInt Tensor : UInt8 / UInt16 / Uint32 @open sesame 09/23 16:50 #2735

Merged
merged 2 commits into from
Oct 23, 2024

Conversation

EunjuYang
Copy link
Contributor

@EunjuYang EunjuYang commented Sep 13, 2024

  • This commit is related to [ Tensor ] more types of Tensors are required. #2733
  • This commit implements template of UIntTensor based on the ShortTensor class.
  • Based on the template, this commit supports UInt8 / UInt16 / UInt32
  • Implement UIntTensor Template
  • Implement UInt8Tensor / UInt16Tensor / UInt32Tensor (ShortTensor is replaced)
  • Unit tests for UInt8 and UInt32 are added

Update 2024-09-23 14:54

  • Resolving NDK build error and reflecting some review comments.
  • This PR contains 11044d7 and 5916650
  • 5916650 : removes some headers (float_tensor, char_tensor, uint_tensor.h), where their corresponding .cpp file imports tneosr.h. Reason of this change is
    • In order to clarify the files relationship.
    • uint_tensor.h should contain all implementations in one file, which is additional update in 11044d7.
  • 11044d7 : defines template uint_tensor class based on ShortTensor. Since it is based on the template class, its implementation should be in one file (NDK build does not work with template class declaration)

Self evaluation:
Build test: [X]Passed [ ]Failed [ ]Skipped
Run test: [X]Passed [ ]Failed [ ]Skipped

@taos-ci
Copy link
Collaborator

taos-ci commented Sep 13, 2024

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

@taos-ci
Copy link
Collaborator

taos-ci commented Sep 13, 2024

:octocat: cibot: @EunjuYang, A builder checker could not be completed because one of the checkers is not completed. In order to find out a reason, please go to http://ci.nnstreamer.ai/nntrainer/ci/repo-workers/pr-checker/2735-202409131121380.57520198822021-232c022878125296a7ce2b9b809a433cd68bbff1/.

Copy link
Contributor

@djeong20 djeong20 left a comment

Choose a reason for hiding this comment

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

Great work overall! Please check the comments below.

Comment on lines 25 to 27
template <typename T, Tdatatype D>
UIntTensor<T, D>::UIntTensor(std::string name_, Tformat fm) :
TensorBase(name_, fm, D) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like Tdatatype D is used only in constructors. I think it could be removed.

Suggested change
template <typename T, Tdatatype D>
UIntTensor<T, D>::UIntTensor(std::string name_, Tformat fm) :
TensorBase(name_, fm, D) {}
template <typename T>
UIntTensor<T>::UIntTensor(std::string name_, Tformat fm) :
TensorBase(name_, fm, checkTensorDataType()) {}

and define a private function checkTensorDataType().

// uint_tensor.h
Tdatatype checkTensorDataType() const {
  if (typeid(T) == typeid(uint8_t))
    return Tdatatype::UINT8;
  else if (typeid(T) == typeid(uint16_t))
    return Tdatatype::UINT16;
  else if (typeid(T) == typeid(uint32_t))
    return Tdatatype::UINT32;
  else
    throw std::runtime_error("unsupported type");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your suggestion. It sounds great! It seems much better to update the code like you recommended. I will update the code.

UINT16, /** unsigned int 16 bit */
UINT32, /** unsigned int 32 bit */
Copy link
Contributor

Choose a reason for hiding this comment

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

please check tensor_dim.cpp to reflect this patch. (e.g., getDataTypeSize(), operator<<)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the tensor_dim.cpp. Thank you for the comment.

}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

one negative test case that comes to my mind is comparing UInt16Tensor t1 and UInt32Tensor t2 with the same size and values and checking for ASSERT_NE(t1, t2).

- This commit resolves nnstreamer#2733
- This commit implements template of UIntTensor based on the ShortTensor class.
- Based on the template, this commit supports UInt8 / UInt16 / UInt32
- Implement UIntTensor Template
- Implement UInt8Tensor / UInt16Tensor / UInt32Tensor (ShortTensor is replaced)
- Unit tests for UInt8 and UInt32 are added

The `uint_tensor.cpp` file is implemented in the way to be imported in `uint_tensor.h`. Since uint_tensor.h declares class prototype with template, all its implementation should be included in one file. However, for better readability, I split the code into uint_tensor.cpp. For this reason, this code should not be included as `compile` but only used as inclusion purpose.

Self evaluation:
Build test: [X]Passed [ ]Failed [ ]Skipped
Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Eunju Yang <[email protected]>
@EunjuYang EunjuYang force-pushed the uint_tensor branch 2 times, most recently from 5916650 to c0d8a91 Compare September 23, 2024 06:03
@taos-ci
Copy link
Collaborator

taos-ci commented Sep 23, 2024

:octocat: cibot: @EunjuYang, nntrainer/tensor/uint_tensor.h does not include Doxygen tags such as @file @brief @author @bug. You must include the Doxygen tags in the source code. Please refer to a Doxygen manual at http://github.com/nnstreamer/TAOS-CI/blob/main/ci/doc/doxygen-documentation.md

- This commit removes some codes, including some tensor-related headers,
which include tensor.h again in their implementation.
- To avoid recursive inclusion, this commit removes
	- char_tensor.h
	- float_tensor.h
	- uint_tensor.h
- In terms of this, it is better to remove half_tensor.h as well, but it
raises linkage error when doing the same operation. Thus, it remains as
todo.
- [fix doxygen error] uint_tensor.h

Self evaluation:
Build test: [X]Passed [ ]Failed [ ]Skipped
Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Eunju Yang <[email protected]>
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.

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

@EunjuYang EunjuYang changed the title [ Tensor ] UInt Tensor : UInt8 / UInt16 / Uint32 [ Tensor ] UInt Tensor : UInt8 / UInt16 / Uint32 @open sesame 09/23 16:50 Sep 23, 2024
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.

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

Copy link
Contributor

@djeong20 djeong20 left a comment

Choose a reason for hiding this comment

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

Thank you for the update 👍 I left some comments on the new patch. PTAL!

@@ -203,6 +197,8 @@ class Tensor {
* @note This constructor copies vector again. needs refactoring
* @param[in] d data for the Tensor with batch size one
* @param[in] t_type Tensor Type
* @todo It is more desirable to move this implementaton into
* `tensor.cpp`, for it requires half_tensor.h
Copy link
Contributor

Choose a reason for hiding this comment

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

I see all other data type implementations have been moved to .cpp except for half tensor. could you explain why you left it as todo?

Copy link
Contributor Author

@EunjuYang EunjuYang Sep 24, 2024

Choose a reason for hiding this comment

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

I attempted to relocate it to 'tensor.cpp' with #ifdef, but encountered an undefined symbol error during compilation (I face this error only with Android build). Thus, I decided to leave it unchanged in the current version and will investigate soon.

* @bug No known bugs except for NYI items
*/

#include <iomanip>
#include <iostream>
#ifdef __UINT_TENSOR_H__
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure whether having uint_tensor.cpp file is good or not. is there a particular reason why you preserved the cpp file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct that there is no need to separate the files, and it may actually be more natural to include everything in one header file. However, I believed doing so could enhance readability and attempted to reach a consensus with other tensor implementations. Please share your thoughts, as I plan to incorporate the reviewers' feedback into the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's no right answer to this. I was just curious if there are any reasons behind this and I agree with you about the benefits of having a cpp file!

Copy link
Contributor

@djeong20 djeong20 left a comment

Choose a reason for hiding this comment

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

Appreciate the hard work! great job :) I think it is good to go 👍

Copy link
Member

@DonghakPark DonghakPark left a comment

Choose a reason for hiding this comment

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

Great discussion & Changes. LGTM!!

Copy link
Contributor

@baek2sm baek2sm left a comment

Choose a reason for hiding this comment

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

great work. LGTM!

* @param[in] d data for the Tensor. It needs to set format properly.
* @param[in] t_type Tensor Type
*/
Tensor(std::vector<std::vector<std::vector<std::vector<uint8_t>>>> const &d,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We might need a tensor constructer with zero and scale.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What else do we need besides the constructor with zero and scale?
Do you expect other methods or functions to improve with the parameters?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For now, Zero and Scale (their vector type may need to be supported) are the only two I can think of, but there are more. @djeong20, let's discuss it. I think this can be done in a later PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another think is that we need to implement the tensor operations like add, mul, etc.

@jijoongmoon jijoongmoon merged commit bf7824e into nnstreamer:main Oct 23, 2024
57 of 61 checks passed
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.

6 participants