-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Implement TMA store reduction for add, min, max #5699
base: main
Are you sure you want to change the base?
Conversation
I haven't looked in details but a high level comment: |
tl._experimental_descriptor_store(output_desc, x, [block_start]) | ||
# Load y through TMA. | ||
y = tl._experimental_descriptor_load( | ||
y_desc, [block_start], [BLOCK_SIZE], y_ptr.dtype.element_ty | ||
) | ||
# Store y to through TMA reduce add. | ||
tl._experimental_descriptor_store(output_desc, y, [block_start], store_reduce="add") |
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.
Is this a race? For the store, the PTX manual says
The copy operation in
cp.async.bulk.tensor
is treated as a weak memory operation and thecomplete-tx
operation on thembarrier
has.release
semantics at the.cluster
scope
And for the reduction,
Each reduction operation performed by
cp.reduce.async.bulk.tensor
has individually.relaxed.gpu
memory ordering semantics.
Therefore we need an aquire fence between the store and reduce ops.
self, | ||
offsets: List[constexpr | tensor], | ||
value: tensor, | ||
store_reduce, |
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.
IMO this should be a separate API from store
since it has different memory semantics.
case 1: | ||
type = CU_TENSOR_MAP_DATA_TYPE_UINT8; |
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.
Obviously this is incomplete as it breaks lots of dtypes. Also need to update the MakeTensorDescriptor
op.
no I was trying to use the reduction as a replacement to matmul with accumulator from HBM. Split-k gemm with atomics will cause non-determinism? |
That's true. I have clearly seen that causes a numerical issue with FP8 gemm, but somehow it is still used in some places where performance is more important. |
This change adds support for lowering _experimental_descriptor_store to TMA store reduction instruction cp.reduce.async.bulk.tensor. Performance of reduction operations that can utilize this async instruction should improve. That could be seen in the plot below that's generated from 10-vector-tma-reduce-add.py.
During the implementation, we noticed a discrepancy in TMA descriptor generation in driver.c that element size needed to be the element type. This is currently fixed for a subset of types for fill1DTMADescriptor and could be improved further. After we decide on a final design, fill2DTMADescriptor should be similarly updated.
I am also planning to convert the tutorial 10-vector-tma-reduce-add.py into an end-to-end test.
New contributor declaration
I am not making a trivial change, such as fixing a typo in a comment.
I have written a PR description following these
rules.
I have run
pre-commit run --from-ref origin/main --to-ref HEAD
.Select one of the following.
/test
forlit
tests/unittest
for C++ tests/python/test
for end-to-end testsFILL THIS IN
.Select one of the following.
lit
tests.lit
tests I have added follow these best practices,including the "tests should be minimal" section. (Usually running Python code
and using the instructions it generates is not minimal.)