Skip to content

Use 4B vector loads/stores in cast-transpose kernel for small matrices - #101

Merged
ptrendx merged 2 commits into
NVIDIA:mainfrom
timmoon10:small-cast-transpose
Mar 17, 2023
Merged

Use 4B vector loads/stores in cast-transpose kernel for small matrices#101
ptrendx merged 2 commits into
NVIDIA:mainfrom
timmoon10:small-cast-transpose

Conversation

@timmoon10

Copy link
Copy Markdown
Member

@vasunvidia has observed poor performance when running the cast-transpose kernel with small matrices. The issue is that we use a per-CTA tiling scheme with hard-coded 8B vector loads and stores, and if the number of CTAs drops below the number of SMs (132 for H100) we can expect reduced throughput. This PR adds a very rough heuristic: if the data is small enough that we would run with fewer than 128 CTAs, reduce the vector size to 4B to increase the number of CTAs by a factor of 4.

Running on a H100 SXM with FP16 input and FP8 output:

DimsRun time (8B vector size)Run time (heuristic vector size)
512 x 5126.17 us3.80 us
768 x 7686.43 us3.79 us
1024 x 10246.75 us3.94 us
1536 x 15366.90 us5.13 us
2048 x 20486.98 us6.93 us
3072 x 307224.59 us24.51 us
4096 x 409651.53 us51.95 us

The timings are not quite apples-to-apples since the baseline runs use the 22.12 PyTorch container while the optimized runs use 23.01. The runs for 2048 x 2048 and larger should all use the same kernel.

We could optimize even further for even smaller matrices, but it would require a more intricate performance model that considers the reduced cache efficiency. In this scale, I'd also expect the kernel launch cost to be the dominant factor in runtime.

@timmoon10timmoon10 added the enhancement New feature or request label Mar 14, 2023
@timmoon10
timmoon10 requested a review from ptrendxMarch 14, 2023 22:55
@timmoon10
timmoon10force-pushed the small-cast-transpose branch from c2a95c5 to 3a931adCompareMarch 14, 2023 23:01
@timmoon10

Copy link
Copy Markdown
MemberAuthor

/te-ci

@timmoon10
timmoon10 requested a review from ksivamanMarch 14, 2023 23:10
@timmoon10

Copy link
Copy Markdown
MemberAuthor

/te-ci

@ptrendxptrendx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with this small bandaid and revisit this (also for the other functions like regular transpose etc.) when we move to runtime compilation.

@ptrendx
ptrendx merged commit 30632f3 into NVIDIA:mainMar 17, 2023
@timmoon10
timmoon10 deleted the small-cast-transpose branch March 17, 2023 23:00
cyanguwa pushed a commit to cyanguwa/TransformerEngine that referenced this pull request Mar 31, 2023
NVIDIA#101)
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Charlene Yang <charleney@nvidia.com>
cyanguwa pushed a commit to cyanguwa/TransformerEngine that referenced this pull request Apr 1, 2023
NVIDIA#101)
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Charlene Yang <charleney@nvidia.com>
@timmoon10timmoon10 mentioned this pull request Apr 7, 2023
5 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@timmoon10@ptrendx