Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/tir/transforms/inject_ptx_async_copy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <tvm/tir/analysis.h>
#include <tvm/tir/builtin.h>
#include <tvm/tir/expr.h>
#include <tvm/tir/op.h>
#include <tvm/tir/stmt_functor.h>
#include <tvm/tir/transform.h>

Expand Down Expand Up @@ -79,7 +80,7 @@ class PTXAsyncCopyInjector : public StmtMutator {
if (indices_lanes == 1) {
auto src_offset = load->indices[0];
auto dst_offset = store->indices[0];
Array<PrimExpr> args = {store->buffer->data, tir::Mul(dst_offset, PrimExpr(index_factor)),
Array<PrimExpr> args = {store->buffer->data, mul(dst_offset, PrimExpr(index_factor)),
load->buffer->data, src_offset, PrimExpr(bytes)};
// use arguments size to indicate whether or not to use predicated cp.async
if (predicated) {
Expand Down Expand Up @@ -114,7 +115,7 @@ class PTXAsyncCopyInjector : public StmtMutator {
}();
if (src_offset.defined() && dst_offset.defined()) {
return Evaluate(Call(store->buffer->dtype, tvm::tir::builtin::ptx_cp_async(),
{store->buffer->data, tir::Mul(dst_offset, PrimExpr(index_factor)),
{store->buffer->data, mul(dst_offset, PrimExpr(index_factor)),
load->buffer->data, src_offset, PrimExpr(bytes)}));
}
} else {
Expand Down Expand Up @@ -144,7 +145,7 @@ class PTXAsyncCopyInjector : public StmtMutator {
if (src_offset.defined() && dst_offset.defined()) {
return Evaluate(
Call(store->buffer->dtype, tvm::tir::builtin::ptx_cp_async(),
{store->buffer->data, tir::Mul(dst_offset, PrimExpr(index_factor)),
{store->buffer->data, mul(dst_offset, PrimExpr(index_factor)),
load->buffer->data, src_offset, PrimExpr(bytes), predicate_value}));
}
}
Expand Down
34 changes: 34 additions & 0 deletions tests/python/unittest/test_tir_transform_inject_ptx_async_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,5 +938,39 @@ def complex_compute(
assert "setp.ne.b32" in generated_code


class TestMultiplicationNodesAreInligned(tvm.testing.CompareBeforeAfter):
transform = tvm.tir.transform.InjectPTXAsyncCopy()

def before(A: T.Buffer((32, 128), "float16")):
tx = T.launch_thread("threadIdx.x", T.int64(32))
A_flattened = T.Buffer((4096,), "float16", data=A.data)
A_shared = T.decl_buffer([4096], "float16", scope="shared")

T.attr("default", "async_scope", 1)
for i in range(16):
cse_var_1: T.int64 = T.Cast("int64", i)
A_shared[
T.Ramp(tx * T.int64(128) + cse_var_1 * T.int64(8), T.int64(1), 8)
] = A_flattened[T.Ramp(tx * T.int64(128) + cse_var_1 * T.int64(8), T.int64(1), 8)]
T.ptx_commit_group()
T.ptx_wait_group(0)

def expected(A: T.Buffer((32, 128), "float16")):
tx = T.launch_thread("threadIdx.x", T.int64(32))
A_shared = T.decl_buffer((4096,), "float16", scope="shared")
for i in range(16):
cse_var_1: T.int64 = T.Cast("int64", i)
T.ptx_cp_async(
"float16",
A_shared.data,
T.Cast("int64", tx) * T.int64(128) + cse_var_1 * T.int64(8),
A.data,
T.Cast("int64", tx) * T.int64(128) + cse_var_1 * T.int64(8),
16,
)
T.ptx_commit_group()
T.ptx_wait_group(0)


if __name__ == "__main__":
tvm.testing.main()