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

[CUTLASS] Residual connection fusion #9820

Merged
merged 4 commits into from
Jan 3, 2022

Conversation

masahi
Copy link
Member

@masahi masahi commented Jan 3, 2022

This adds support for fusing a residual block of the form UnaryOp(BinaryOp(ActivationOp(TensorOp(X) + bias), residual)) into one cutlass kernel, which I thought was not possible until recently. As discussed in NVIDIA/cutlass#347 (comment), it turns out that one of cutlass conv2d kernels already supports computing elementwise(alpha x conv + beta x C + per_channel_bias). With a little tweak (or one might say it is an abuse of the intended API usage), it is possible to support fully general residual blocks found in deep learning models.

As expected, this brings good speedup on resnet based models (resnet50 and DETR-R50 below). On other models, speedup is modest or it even becomes worse (deeplabv3, strange result, haven't looked into what's going on).

@comaniac @Laurawly @hwu36

Model name Input size CUTLASS with activation fusion only CUTLASS with activation + residual block fusion cuDNN
resnet50 (8, 3, 224, 224) 3.16 2.76 4.08
efficientnet_v2 (8, 3, 224, 224) 8.05 7.87 14.0
DETR-R50 (8, 3, 800, 750) 57.19 51.6 68.4
deeplabv3_mobilenet_v3_large (8, 3, 512, 512) 9.16 9.68 (?) 17.5
YOLOv5l (8, 3, 512, 512) 25.4 24.2 34.8

commit d4a78a3
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:33:41 2021 +0900

    fixed residual block check condition

commit 6ee5a39
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:25:04 2021 +0900

    minor fix

commit 8af8b30
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:18:50 2021 +0900

    remove SimplifyExpr pass

commit 20ae2d8
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:16:46 2021 +0900

    fix bad merge

commit 17eed22
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:13:53 2021 +0900

    black

commit fda151b
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:09:45 2021 +0900

    Support residual block fusion

commit ce9d52f
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 15:56:32 2021 +0900

    Remove SimplifyExpr pass from the pipeline (makes DETR result nan)

commit d3b681d
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 15:47:07 2021 +0900

    fix no_beta_scaling values

commit 87b36db
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 14:59:40 2021 +0900

    fill in TODO doc

commit fd67595
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 14:31:06 2021 +0900

    Refactor cutlass kernel generation and selection
Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

LGTM

@vinx13 vinx13 merged commit e7f3648 into apache:main Jan 3, 2022
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
* [CUTLASS] Support residual block fusion for conv2d

commit d4a78a3
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:33:41 2021 +0900

    fixed residual block check condition

commit 6ee5a39
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:25:04 2021 +0900

    minor fix

commit 8af8b30
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:18:50 2021 +0900

    remove SimplifyExpr pass

commit 20ae2d8
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:16:46 2021 +0900

    fix bad merge

commit 17eed22
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:13:53 2021 +0900

    black

commit fda151b
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:09:45 2021 +0900

    Support residual block fusion

commit ce9d52f
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 15:56:32 2021 +0900

    Remove SimplifyExpr pass from the pipeline (makes DETR result nan)

commit d3b681d
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 15:47:07 2021 +0900

    fix no_beta_scaling values

commit 87b36db
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 14:59:40 2021 +0900

    fill in TODO doc

commit fd67595
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 14:31:06 2021 +0900

    Refactor cutlass kernel generation and selection

* do not try to support broadcast binary op

* add comments

* remove residual input shape check
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
* [CUTLASS] Support residual block fusion for conv2d

commit d4a78a3
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:33:41 2021 +0900

    fixed residual block check condition

commit 6ee5a39
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:25:04 2021 +0900

    minor fix

commit 8af8b30
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:18:50 2021 +0900

    remove SimplifyExpr pass

commit 20ae2d8
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:16:46 2021 +0900

    fix bad merge

commit 17eed22
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:13:53 2021 +0900

    black

commit fda151b
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 16:09:45 2021 +0900

    Support residual block fusion

commit ce9d52f
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 15:56:32 2021 +0900

    Remove SimplifyExpr pass from the pipeline (makes DETR result nan)

commit d3b681d
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 15:47:07 2021 +0900

    fix no_beta_scaling values

commit 87b36db
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 14:59:40 2021 +0900

    fill in TODO doc

commit fd67595
Author: Masahiro Masuda <masahi129@gmail.com>
Date:   Thu Dec 23 14:31:06 2021 +0900

    Refactor cutlass kernel generation and selection

* do not try to support broadcast binary op

* add comments

* remove residual input shape check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants