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] Refactor cutlass kernel generation and selection #9800

Merged
merged 5 commits into from
Dec 30, 2021

Conversation

masahi
Copy link
Member

@masahi masahi commented Dec 23, 2021

Currently, when we enumerate cutlass kernels for profiling, for each parameter config we generate all variants of the kernel with different epilogues. See for example

op = GemmOperation(
tile_description.minimum_compute_capability,
tile_description,
A,
B,
C,
element_epilogue,
EpilogueFunctor.LinearCombination,
swizzling_functor,
)
op_bias = GemmOperation(
tile_description.minimum_compute_capability,
tile_description,
A,
B,
C,
element_epilogue,
EpilogueFunctor.LinearCombinationBias,
swizzling_functor,
)
op_bias_relu = GemmOperation(
tile_description.minimum_compute_capability,
tile_description,
A,
B,
C,
element_epilogue,
EpilogueFunctor.LinearCombinationRelu,
swizzling_functor,
)
op_bias_gelu = GemmOperation(
tile_description.minimum_compute_capability,
tile_description,
A,
B,
C,
element_epilogue,
EpilogueFunctor.LinearCombinationGelu,
swizzling_functor,
)

After profiling, we select which variant of epilogue to use based on the pattern name:

if op_type == "cutlass.conv2d":
cutlass_op_def = out["opdef"]
elif op_type == "cutlass.conv2d_bias":
cutlass_op_def = out["opdef_bias"]
elif op_type == "cutlass.conv2d_bias_relu":
cutlass_op_def = out["opdef_bias_relu"]
elif op_type == "cutlass.conv2d_bias_sigmoid":
cutlass_op_def = out["opdef_bias_sigmoid"]
elif op_type == "cutlass.conv2d_bias_silu":
cutlass_op_def = out["opdef_bias_silu"]
elif op_type == "cutlass.conv2d_bias_hardswish":
cutlass_op_def = out["opdef_bias_hardswish"]

This approach simply doesn't work when we introduce support for residual connection fusion, because there are so many different kinds of epilogues.

The idea of this change is to split kernel generation into two steps:
(1) First, we generate all kernels without any epilogue. This is used for profiling
(2) After profiling decides the best parameter configuration, use that information to generate a single kernel with the required epilogue.

Overall I believe this refactoring of kernel generation and selection have made things much cleaner, and makes us well-prepared for residual block fusion.

cc @comaniac @Laurawly

@masahi
Copy link
Member Author

masahi commented Dec 30, 2021

@comaniac Can you take a look (no functional change, should be easy)? The cutlass side change to enable residual block fusion was merged yesterday in NVIDIA/cutlass#391, so I'm ready to send residual fusion support (with good speed up!)

Copy link
Contributor

@Laurawly Laurawly left a comment

Choose a reason for hiding this comment

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

LGTM

@comaniac comaniac merged commit 6d35f0b into apache:main Dec 30, 2021
@comaniac
Copy link
Contributor

Sorry I was on vacation. Thanks @masahi @Laurawly

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.

3 participants