-
Notifications
You must be signed in to change notification settings - Fork 74
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
Conversation
📝 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/. |
5220bb1
to
232c022
Compare
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/. |
There was a problem hiding this 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.
nntrainer/tensor/uint_tensor.cpp
Outdated
template <typename T, Tdatatype D> | ||
UIntTensor<T, D>::UIntTensor(std::string name_, Tformat fm) : | ||
TensorBase(name_, fm, D) {} |
There was a problem hiding this comment.
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.
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");
}
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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<<
)
There was a problem hiding this comment.
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.
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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]>
5916650
to
c0d8a91
Compare
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]>
c0d8a91
to
ed45986
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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__ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this 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 👍
There was a problem hiding this 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!!
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Update 2024-09-23 14:54
float_tensor
,char_tensor
,uint_tensor.h
), where their corresponding.cpp
file importstneosr.h
. Reason of this change isSelf evaluation:
Build test: [X]Passed [ ]Failed [ ]Skipped
Run test: [X]Passed [ ]Failed [ ]Skipped