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

[AMDAIEInsertIntoCores] minor simplification #1118

Merged
merged 3 commits into from
Feb 20, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ namespace {

/// Utility which returns 'true' is the operation needs to be inserted with an
/// `amdaie.core` op.
/// Some ops are surrrounded by scf.for loop nests. Place the entire
/// Some ops are surrounded by scf.for loop nests. Place the entire
/// loop nest inside the amdaie.core op here. Currently look for a
/// subset of ops which we know should be in the core.
/// TODO(newling) improve this design.
static bool isCoreComputeOp(Operation *op) {
return isa<linalg::LinalgOp, vector::ContractionOp,
memref::ExtractStridedMetadataOp, func::CallOp, arith::ExtFOp,
arith::TruncFOp, arith::TruncIOp, vector::TransferReadOp,
vector::TransferWriteOp>(op);
memref::ExtractStridedMetadataOp, func::CallOp,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not necessarily, see matmul + truncf:

// input ${M}x${K}x${TYPE1}
// input ${K}x${N}x${TYPE1}

func.func @matmul_truncf(%arg0: tensor<${M}x${K}x${TYPE1}>, %arg1: tensor<${K}x${N}x${TYPE1}>) -> tensor<${M}x${N}x${TYPE1}>
{
  %cst = arith.constant ${ZERO} : ${TYPE2}
  %0 = tensor.empty() : tensor<${M}x${N}x${TYPE2}>
  %1 = linalg.fill ins(%cst : ${TYPE2}) outs(%0 : tensor<${M}x${N}x${TYPE2}>) -> tensor<${M}x${N}x${TYPE2}>
  %2 = linalg.matmul ins(%arg0, %arg1 : tensor<${M}x${K}x${TYPE1}>, tensor<${K}x${N}x${TYPE1}>)
    outs(%1: tensor<${M}x${N}x${TYPE2}>) -> tensor<${M}x${N}x${TYPE2}>
  %3 = arith.truncf %2 : tensor<${M}x${N}x${TYPE2}> to tensor<${M}x${N}x${TYPE1}>
  return %3: tensor<${M}x${N}x${TYPE1}>
}

Not sure how this PR is passing though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In one of the very early passes (convert-elementwise-to-linalg) It gets converted into a linalg.generic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, thanks, that's great! Then we can assume all computational ops will be linalg ops, which makes these checks a lot less fragile and improves maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

vector::TransferReadOp, vector::TransferWriteOp>(op);
}

/// Utility to map the parallel mapping attributes to the corresponding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,53 +300,3 @@ module {
return
}
}

// -----

// CHECK-LABEL: @insert_truncf_within_core
// CHECK: scf.forall
// CHECK: amdaie.tile
// CHECK: amdaie.core
// CHECK: vector.transfer_read
// CHECK: arith.truncf
// CHECK: vector.transfer_write
// CHECK: amdaie.end
module {
func.func @insert_truncf_within_core(%arg0: memref<10x10xf32, 2 : i32>, %arg1: memref<10x10xbf16, 2 : i32>) {
%cst = arith.constant 0.000000e+00 : f32
%c1 = arith.constant 1 : index
%c3 = arith.constant 3 : index
%c0 = arith.constant 0 : index
scf.forall (%arg3, %arg4) in (2, 2) {
%read = vector.transfer_read %arg0[%c0, %c1], %cst {in_bounds = [true, true]} : memref<10x10xf32, 2 : i32>, vector<1x1xf32>
%truncf = arith.truncf %read : vector<1x1xf32> to vector<1x1xbf16>
vector.transfer_write %truncf, %arg1[%c0, %c1] {in_bounds = [true, true]} : vector<1x1xbf16>, memref<10x10xbf16, 2 : i32>
} {mapping = [#gpu.thread<y>, #gpu.thread<x>]}
return
}
}

// -----

// CHECK-LABEL: @insert_trunci_within_core
// CHECK: scf.forall
// CHECK: amdaie.tile
// CHECK: amdaie.core
// CHECK: vector.transfer_read
// CHECK: arith.trunci
// CHECK: vector.transfer_write
// CHECK: amdaie.end
module {
func.func @insert_trunci_within_core(%arg0: memref<10x10xi32, 2 : i32>, %arg1: memref<10x10xi8, 2 : i32>) {
%cst = arith.constant 0 : i32
%c1 = arith.constant 1 : index
%c3 = arith.constant 3 : index
%c0 = arith.constant 0 : index
scf.forall (%arg3, %arg4) in (2, 2) {
%read = vector.transfer_read %arg0[%c0, %c1], %cst {in_bounds = [true, true]} : memref<10x10xi32, 2 : i32>, vector<1x1xi32>
%trunci = arith.trunci %read : vector<1x1xi32> to vector<1x1xi8>
vector.transfer_write %trunci, %arg1[%c0, %c1] {in_bounds = [true, true]} : vector<1x1xi8>, memref<10x10xi8, 2 : i32>
} {mapping = [#gpu.thread<y>, #gpu.thread<x>]}
return
}
}
Loading