CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
113 lines
5.6 KiB
MLIR
113 lines
5.6 KiB
MLIR
// RUN: mlir-opt %s \
|
|
// RUN: --pass-pipeline="builtin.module(transform-interpreter{ \
|
|
// RUN: debug-bind-trailing-args=linalg.matmul,linalg.elementwise},\
|
|
// RUN: canonicalize,cse,symbol-dce)" |\
|
|
// RUN: FileCheck %s
|
|
|
|
// ****************************** IMPORTANT NOTE ******************************
|
|
//
|
|
// If you are changing this file, you may also need to change
|
|
// mlir/docs/Tutorials/Transform accordingly.
|
|
//
|
|
// ****************************************************************************
|
|
|
|
// Original function to optimize.
|
|
func.func @fc_relu(%lhs: tensor<512x512xf32>, %rhs: tensor<512x512xf32>,
|
|
%bias: tensor<512x512xf32>, %output: tensor<512x512xf32>)
|
|
-> tensor<512x512xf32> {
|
|
// Matrix-matrix multiplication.
|
|
%matmul = linalg.matmul ins(%lhs, %rhs: tensor<512x512xf32>, tensor<512x512xf32>)
|
|
outs(%output: tensor<512x512xf32>) -> tensor<512x512xf32>
|
|
|
|
// Elementwise addition.
|
|
%biased = linalg.elementwise kind=#linalg.elementwise_kind<add>
|
|
ins(%matmul, %bias : tensor<512x512xf32>, tensor<512x512xf32>)
|
|
outs(%output : tensor<512x512xf32>) -> tensor<512x512xf32>
|
|
|
|
// Elementwise max with 0 (ReLU).
|
|
%c0f = arith.constant dense<0.0> : tensor<512x512xf32>
|
|
%relued = linalg.elementwise kind=#linalg.elementwise_kind<max_signed>
|
|
ins(%biased, %c0f : tensor<512x512xf32>, tensor<512x512xf32>)
|
|
outs(%output : tensor<512x512xf32>) -> tensor<512x512xf32>
|
|
func.return %relued : tensor<512x512xf32>
|
|
}
|
|
|
|
// CHECK: func @outlined
|
|
// CHECK: linalg.matmul
|
|
// CHECK: linalg.elementwise kind=#linalg.elementwise_kind<add>
|
|
|
|
// CHECK-LABEL: func @fc_relu
|
|
// CHECK: scf.forall
|
|
// CHECK: scf.forall
|
|
// CHECK: %[[SLICE4:.+]] = tensor.extract_slice
|
|
// CHECK: %[[SLICE5:.+]] = tensor.extract_slice
|
|
// CHECK: %[[SLICE6:.+]] = tensor.extract_slice
|
|
// CHECK: %[[SLICE7:.+]] = tensor.extract_slice
|
|
// CHECK: %[[SLICE8:.+]] = tensor.extract_slice
|
|
// CHECK: func.call @outlined(%[[SLICE4]], %[[SLICE5]], %[[SLICE6]], %[[SLICE7]], %[[SLICE8]])
|
|
// CHECK-NOT: linalg.matmul
|
|
// CHECK-NOT: linalg.elementwise
|
|
// CHECK: scf.forall.in_parallel
|
|
// CHECK: linalg.elementwise kind=#linalg.elementwise_kind<max_signed>
|
|
// CHECK: scf.forall.in_parallel
|
|
|
|
// Declaration of the "microkernel" function that we will be targeting.
|
|
func.func private @microkernel(
|
|
%lhs: tensor<4x512xf32>,
|
|
%rhs: tensor<512x4xf32>,
|
|
%bias: tensor<4x4xf32>,
|
|
%init: tensor<4x4xf32>,
|
|
%output: tensor<4x4xf32>) -> tensor<4x4xf32>
|
|
|
|
module attributes {transform.with_named_sequence} {
|
|
transform.named_sequence @__transform_main(
|
|
%arg0: !transform.any_op,
|
|
%arg1: !transform.op<"linalg.matmul">,
|
|
%arg2: !transform.op<"linalg.elementwise">) {
|
|
// Since the %arg2 handle is associated with both elementwise operations,
|
|
// we need to split it into two handles so we can target only the second
|
|
// elementwise operation.
|
|
%add, %max = transform.split_handle %arg2 : (!transform.op<"linalg.elementwise">)
|
|
-> (!transform.any_op, !transform.any_op)
|
|
|
|
// The actual tiling transformation takes tile sizes as attributes. It produces a
|
|
// handle to the loop generated during tiling.
|
|
%tiled, %loop = transform.structured.tile_using_forall %max tile_sizes [8, 32]
|
|
: (!transform.any_op) -> (!transform.any_op, !transform.any_op)
|
|
|
|
// We can now fuse the other operations into the loop. Here, we fuse
|
|
// operations one-by-one. This requires the operation that is being fused
|
|
// to define the value used within the loop, so the order of such fusions
|
|
// is important. We could also use "transform.merge_handles" to obtain
|
|
// a single handle to all operations and give it to `fuse_into_containing_op`
|
|
// that would take care of the ordering in this case.
|
|
%add_fused, %loop2 = transform.structured.fuse_into_containing_op %add into %loop
|
|
: (!transform.any_op, !transform.any_op) -> (!transform.any_op, !transform.any_op)
|
|
%matmul_fused, %loop3 = transform.structured.fuse_into_containing_op %arg1 into %loop2
|
|
: (!transform.op<"linalg.matmul">, !transform.any_op) -> (!transform.any_op, !transform.any_op)
|
|
|
|
// Tile again to get the desired size. Note that this time this tiles the
|
|
// "add" operation and fuses matmul into the loop, but doesn't affect the
|
|
// "max" operation. This illustrates the precise targeting with the transform
|
|
// dialect. Otherwise, it is difficult to differentiate "add" and "max", both
|
|
// of which having the same kind.
|
|
%tiled_second, %loop_second = transform.structured.tile_using_forall %add_fused tile_sizes [4, 4]
|
|
: (!transform.any_op) -> (!transform.any_op, !transform.any_op)
|
|
%matmul_fused_2, %loop_second_2 =
|
|
transform.structured.fuse_into_containing_op %matmul_fused into %loop_second
|
|
: (!transform.any_op, !transform.any_op) -> (!transform.any_op, !transform.any_op)
|
|
|
|
// Since outlining is currently only implemented for region-holding operations
|
|
// such as loops, use tiling to size 1 to materialize the outer loop that is
|
|
// going to be outlined.
|
|
%_0, %loop_third = transform.structured.tile_using_forall %tiled_second tile_sizes [1]
|
|
: (!transform.any_op) -> (!transform.any_op, !transform.any_op)
|
|
%_1, %outline_target = transform.structured.fuse_into_containing_op %matmul_fused_2 into %loop_third
|
|
: (!transform.any_op, !transform.any_op) -> (!transform.any_op, !transform.any_op)
|
|
%func, %call = transform.loop.outline %outline_target {func_name = "outlined"}
|
|
: (!transform.any_op) -> (!transform.any_op, !transform.op<"func.call">)
|
|
|
|
transform.yield
|
|
}
|
|
}
|