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

[Layer] Improve forwarding logic of ConcatLayer @open sesame 08/08 18:22 #2702

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

djeong20
Copy link
Contributor

@djeong20 djeong20 commented Aug 8, 2024

Description

This pull request aims to optimize the performance of forwarding() in ConcatLayer.
This is accomplished by improving the current concatenation logic by utilizing the tensor operation concat() instead of Map().
Note that this optimization is only for forwarding() and calcDeriv() would be improved in later PR.

Result

Before

key avg min max sum
calcDeriv(concat) 1.004153s 0.997947s 1.010360s 2.008307s
forward(concat) 1.083193s 1.042626s 1.010360s 2.166386s
concat 1.129055s 0.997965s 1.252510s 9.032440s

After

key avg min max sum
calcDeriv(concat) 1.134034s 1.131812s 1.136257s 2.268069s
forward(concat) 0.017167s 0.012304s 0.022031s 0.034335s
concat 0.627868s 0.012310s 1.346551s 5.022949s

Note

input 0: 1:1:196:256 [ FP16 : NCHW ]
input 1: 1:1:196:1024 [ FP16 : NCHW ]
output: 1:1:196:1280 [ FP16 : NCHW ]

This PR updates current ConcatLayer forwarding for faster computation.

**Changes proposed in this PR:**
- Utilize the Tensor::concat() operation to perform forwarding and replace manual mapping and copying.

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

Signed-off-by: Donghyeon Jeong <dhyeon.jeong@samsung.com>
@taos-ci
Copy link
Collaborator

taos-ci commented Aug 8, 2024

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

if (out_dim[axis] != in_dim[axis]) {
/// @todo Currently a new output tensor is created. This can be optimized.
Tensor result = Tensor::cat(input_tensors, axis);
output.copy(result);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy() is unnecessary here. this will be replaced with in-place ops in a later PR.

@djeong20 djeong20 changed the title [Layer] Improve forwarding logic of ConcatLayer [Layer] Improve forwarding logic of ConcatLayer @open sesame 08/08 18:22 Aug 8, 2024
@djeong20 djeong20 linked an issue Aug 8, 2024 that may be closed by this pull request
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.

input.reshape(irh);
original_input_dims.push_back(input.getDim());
input.reshape(input_reshape_helper[idx]);
input_tensors.push_back(input);
Copy link
Collaborator

@jijoongmoon jijoongmoon Aug 9, 2024

Choose a reason for hiding this comment

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

Just for sure, when we do this push_back, there is no deep copy happened due to the

Tensor &Tensor::operator=(const Tensor &rhs) {

and could you check whether we are not using leading_helper_dim at #L80

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems leading_helper_dim is used in setBatch()!

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.

Great work!

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 Work!!!!

Copy link
Contributor

@EunjuYang EunjuYang left a comment

Choose a reason for hiding this comment

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

Awesome!👍

@jijoongmoon jijoongmoon merged commit 3b11453 into nnstreamer:main Aug 12, 2024
49 checks passed
@djeong20 djeong20 deleted the layer/concat/update_fwd branch August 27, 2024 08:20
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.

ConcatLayer performance issue
6 participants