2020-03-30 06:35:38 +08:00
|
|
|
// RUN: mlir-opt -allow-unregistered-dialect %s | FileCheck %s
|
2019-04-29 18:00:25 +08:00
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
module attributes {gpu.container_module} {
|
|
|
|
|
|
|
|
// CHECK-LABEL:func @no_args(%{{.*}}: index)
|
|
|
|
func @no_args(%sz : index) {
|
|
|
|
// CHECK: gpu.launch blocks(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}) threads(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}})
|
|
|
|
gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %sz, %grid_y = %sz, %grid_z = %sz)
|
|
|
|
threads(%tx, %ty, %tz) in (%block_x = %sz, %block_y = %sz, %block_z = %sz) {
|
Add 'gpu.terminator' operation.
Summary:
The 'gpu.terminator' operation is used as the terminator for the
regions of gpu.launch. This is to disambugaute them from the
return operation on 'gpu.func' functions.
This is a breaking change and users of the gpu dialect will need
to adapt their code when producting 'gpu.launch' operations.
Reviewers: nicolasvasilache
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73620
2020-01-29 20:59:36 +08:00
|
|
|
// CHECK: gpu.terminator
|
|
|
|
gpu.terminator
|
2019-10-08 19:29:58 +08:00
|
|
|
}
|
|
|
|
return
|
2019-05-06 17:30:50 +08:00
|
|
|
}
|
2019-04-29 18:00:25 +08:00
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
// CHECK-LABEL:func @args(%{{.*}}: index, %{{.*}}: index, %{{.*}}: f32, %{{.*}}: memref<?xf32, 1>) {
|
|
|
|
func @args(%blk : index, %thrd : index, %float : f32, %data : memref<?xf32,1>) {
|
2020-01-31 17:29:29 +08:00
|
|
|
// CHECK: gpu.launch blocks(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}) threads(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}})
|
2019-10-08 19:29:58 +08:00
|
|
|
gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %blk, %grid_y = %blk, %grid_z = %blk)
|
2020-01-31 17:29:29 +08:00
|
|
|
threads(%tx, %ty, %tz) in (%block_x = %thrd, %block_y = %thrd, %block_z = %thrd) {
|
|
|
|
"use"(%float) : (f32) -> ()
|
|
|
|
"use"(%data) : (memref<?xf32,1>) -> ()
|
Add 'gpu.terminator' operation.
Summary:
The 'gpu.terminator' operation is used as the terminator for the
regions of gpu.launch. This is to disambugaute them from the
return operation on 'gpu.func' functions.
This is a breaking change and users of the gpu dialect will need
to adapt their code when producting 'gpu.launch' operations.
Reviewers: nicolasvasilache
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73620
2020-01-29 20:59:36 +08:00
|
|
|
// CHECK: gpu.terminator
|
|
|
|
gpu.terminator
|
2019-10-08 19:29:58 +08:00
|
|
|
}
|
|
|
|
return
|
2019-05-06 17:30:50 +08:00
|
|
|
}
|
2019-05-06 20:01:12 +08:00
|
|
|
|
Create a gpu.module operation for the GPU Dialect.
Summary:
This is based on the use of code constantly checking for an attribute on
a model and instead represents the distinct operaion with a different
op. Instead, this op can be used to provide better filtering.
Reverts "Revert "[mlir] Create a gpu.module operation for the GPU Dialect.""
This reverts commit ac446302ca4145cdc89f377c0c364c29ee303be5 after
fixing internal Google issues.
This additionally updates ROCDL lowering to use the new gpu.module.
Reviewers: herhut, mravishankar, antiagainst, nicolasvasilache
Subscribers: jholewinski, mgorny, mehdi_amini, jpienaar, burmako, shauheen, csigg, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, llvm-commits, mravishankar, rriddle, antiagainst, bkramer
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72921
2020-01-17 22:18:23 +08:00
|
|
|
gpu.module @kernels {
|
2020-04-21 15:11:10 +08:00
|
|
|
gpu.func @kernel_1(%arg0 : f32, %arg1 : memref<?xf32, 1>) kernel {
|
2019-10-08 19:29:58 +08:00
|
|
|
%tIdX = "gpu.thread_id"() {dimension = "x"} : () -> (index)
|
|
|
|
%tIdY = "gpu.thread_id"() {dimension = "y"} : () -> (index)
|
|
|
|
%tIdZ = "gpu.thread_id"() {dimension = "z"} : () -> (index)
|
2019-05-07 16:27:54 +08:00
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
%bDimX = "gpu.block_dim"() {dimension = "x"} : () -> (index)
|
|
|
|
%bDimY = "gpu.block_dim"() {dimension = "y"} : () -> (index)
|
|
|
|
%bDimZ = "gpu.block_dim"() {dimension = "z"} : () -> (index)
|
2019-05-07 16:27:54 +08:00
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
%bIdX = "gpu.block_id"() {dimension = "x"} : () -> (index)
|
|
|
|
%bIdY = "gpu.block_id"() {dimension = "y"} : () -> (index)
|
|
|
|
%bIdZ = "gpu.block_id"() {dimension = "z"} : () -> (index)
|
2019-05-07 16:27:54 +08:00
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
%gDimX = "gpu.grid_dim"() {dimension = "x"} : () -> (index)
|
|
|
|
%gDimY = "gpu.grid_dim"() {dimension = "y"} : () -> (index)
|
|
|
|
%gDimZ = "gpu.grid_dim"() {dimension = "z"} : () -> (index)
|
2019-05-07 16:27:54 +08:00
|
|
|
|
2020-06-05 01:45:53 +08:00
|
|
|
%sgId = gpu.subgroup_id : index
|
|
|
|
%numSg = gpu.num_subgroups : index
|
|
|
|
%SgSi = gpu.subgroup_size : index
|
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
%one = constant 1.0 : f32
|
2019-10-17 01:43:12 +08:00
|
|
|
%sum = "gpu.all_reduce"(%one) ({}) {op = "add"} : (f32) -> (f32)
|
2019-09-26 15:17:13 +08:00
|
|
|
|
2019-12-20 18:52:21 +08:00
|
|
|
%width = constant 7 : i32
|
|
|
|
%offset = constant 3 : i32
|
|
|
|
// CHECK: gpu.shuffle %{{.*}}, %{{.*}}, %{{.*}} xor : f32
|
|
|
|
%shfl, %pred = gpu.shuffle %arg0, %offset, %width xor : f32
|
|
|
|
|
2019-10-18 15:30:14 +08:00
|
|
|
"gpu.barrier"() : () -> ()
|
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
"some_op"(%bIdX, %tIdX) : (index, index) -> ()
|
|
|
|
%42 = load %arg1[%bIdX] : memref<?xf32, 1>
|
2019-12-17 04:12:20 +08:00
|
|
|
gpu.return
|
2019-10-08 19:29:58 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 15:11:10 +08:00
|
|
|
gpu.func @kernel_2(%arg0: f32, %arg1: memref<?xf32, 1>) kernel {
|
2019-12-17 04:12:20 +08:00
|
|
|
gpu.return
|
|
|
|
}
|
2019-10-08 19:29:58 +08:00
|
|
|
}
|
2019-05-06 20:01:12 +08:00
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
func @foo() {
|
|
|
|
%0 = "op"() : () -> (f32)
|
|
|
|
%1 = "op"() : () -> (memref<?xf32, 1>)
|
|
|
|
// CHECK: %{{.*}} = constant 8
|
|
|
|
%cst = constant 8 : index
|
2019-06-18 03:47:09 +08:00
|
|
|
|
2020-04-21 18:16:41 +08:00
|
|
|
// CHECK: "gpu.launch_func"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {kernel = @kernels::@kernel_1} : (index, index, index, index, index, index, f32, memref<?xf32, 1>) -> ()
|
2019-10-08 19:29:58 +08:00
|
|
|
"gpu.launch_func"(%cst, %cst, %cst, %cst, %cst, %cst, %0, %1)
|
2020-04-21 18:16:41 +08:00
|
|
|
{ kernel = @kernels::@kernel_1}
|
2019-10-08 19:29:58 +08:00
|
|
|
: (index, index, index, index, index, index, f32, memref<?xf32, 1>) -> ()
|
2019-05-06 20:01:12 +08:00
|
|
|
|
2020-04-21 18:16:41 +08:00
|
|
|
// CHECK: "gpu.launch_func"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {kernel = @kernels::@kernel_2} : (index, index, index, index, index, index, f32, memref<?xf32, 1>) -> ()
|
2019-10-08 19:29:58 +08:00
|
|
|
"gpu.launch_func"(%cst, %cst, %cst, %cst, %cst, %cst, %0, %1)
|
2020-04-21 18:16:41 +08:00
|
|
|
{ kernel = @kernels::@kernel_2}
|
2019-10-08 19:29:58 +08:00
|
|
|
: (index, index, index, index, index, index, f32, memref<?xf32, 1>) -> ()
|
2019-06-18 03:47:09 +08:00
|
|
|
|
2019-10-08 19:29:58 +08:00
|
|
|
return
|
|
|
|
}
|
2019-06-18 03:47:09 +08:00
|
|
|
|
2020-04-21 18:05:17 +08:00
|
|
|
gpu.module @gpu_funcs {
|
Add 'gpu.terminator' operation.
Summary:
The 'gpu.terminator' operation is used as the terminator for the
regions of gpu.launch. This is to disambugaute them from the
return operation on 'gpu.func' functions.
This is a breaking change and users of the gpu dialect will need
to adapt their code when producting 'gpu.launch' operations.
Reviewers: nicolasvasilache
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73620
2020-01-29 20:59:36 +08:00
|
|
|
// CHECK-LABEL: gpu.func @kernel_1({{.*}}: f32)
|
2019-11-25 23:59:52 +08:00
|
|
|
// CHECK: workgroup
|
|
|
|
// CHECK: private
|
|
|
|
// CHECK: attributes
|
Add 'gpu.terminator' operation.
Summary:
The 'gpu.terminator' operation is used as the terminator for the
regions of gpu.launch. This is to disambugaute them from the
return operation on 'gpu.func' functions.
This is a breaking change and users of the gpu dialect will need
to adapt their code when producting 'gpu.launch' operations.
Reviewers: nicolasvasilache
Subscribers: mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73620
2020-01-29 20:59:36 +08:00
|
|
|
gpu.func @kernel_1(%arg0: f32)
|
2019-11-25 23:59:52 +08:00
|
|
|
workgroup(%arg1: memref<42xf32, 3>)
|
|
|
|
private(%arg2: memref<2xf32, 5>, %arg3: memref<1xf32, 5>)
|
|
|
|
kernel
|
|
|
|
attributes {foo="bar"} {
|
|
|
|
"use"(%arg1) : (memref<42xf32, 3>) -> ()
|
|
|
|
"use"(%arg2) : (memref<2xf32, 5>) -> ()
|
|
|
|
"use"(%arg3) : (memref<1xf32, 5>) -> ()
|
|
|
|
gpu.return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: gpu.func @no_attribution
|
|
|
|
// CHECK: {
|
|
|
|
gpu.func @no_attribution(%arg0: f32) {
|
|
|
|
gpu.return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @no_attribution_attrs
|
|
|
|
// CHECK: attributes
|
|
|
|
// CHECK: {
|
|
|
|
gpu.func @no_attribution_attrs(%arg0: f32) attributes {foo="bar"} {
|
|
|
|
gpu.return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @workgroup_only
|
|
|
|
// CHECK: workgroup({{.*}}: {{.*}})
|
|
|
|
// CHECK: {
|
|
|
|
gpu.func @workgroup_only() workgroup(%arg0: memref<42xf32, 3>) {
|
|
|
|
gpu.return
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: @private_only
|
|
|
|
// CHECK: private({{.*}}: {{.*}})
|
|
|
|
// CHECK: {
|
|
|
|
gpu.func @private_only() private(%arg0: memref<2xf32, 5>) {
|
|
|
|
gpu.return
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @empty_attribution
|
|
|
|
// CHECK: {
|
|
|
|
gpu.func @empty_attribution(%arg0: f32) workgroup() private() {
|
|
|
|
gpu.return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-01 23:48:23 +08:00
|
|
|
gpu.module @explicit_attributions {
|
|
|
|
// CHECK-LABEL: gpu.func @kernel_1({{.*}}: f32, {{.*}}: memref<?xf32>) workgroup({{.*}}: memref<5xf32, 3>) private({{.*}}: memref<5xf32, 5>)
|
|
|
|
"gpu.func"() ( {
|
|
|
|
^bb0(%arg0: f32, %arg1: memref<?xf32>, %arg2: memref<5xf32, 3>, %arg3: memref<5xf32, 5>):
|
|
|
|
"gpu.return"() : () -> ()
|
|
|
|
} ) {gpu.kernel, sym_name = "kernel_1", type = (f32, memref<?xf32>) -> (), workgroup_attributions = 1: i64} : () -> ()
|
|
|
|
}
|
2020-10-08 19:43:18 +08:00
|
|
|
|
|
|
|
func @async_token(%arg0 : !gpu.async.token) -> !gpu.async.token {
|
|
|
|
// CHECK-LABEL: func @async_token({{.*}}: !gpu.async.token)
|
|
|
|
// CHECK: return {{.*}} : !gpu.async.token
|
|
|
|
return %arg0 : !gpu.async.token
|
|
|
|
}
|
2020-10-13 23:21:59 +08:00
|
|
|
|
|
|
|
func @async_wait() {
|
|
|
|
// CHECK-LABEL: func @async_wait
|
|
|
|
// CHECK: %[[t0:.*]] = gpu.wait async
|
|
|
|
%0 = gpu.wait async
|
|
|
|
// CHECK: %[[t1:.*]] = gpu.wait async [%[[t0]]]
|
|
|
|
%1 = gpu.wait async [%0]
|
|
|
|
// CHECK: %{{.*}} = gpu.wait async [%[[t0]], %[[t1]]]
|
|
|
|
%2 = gpu.wait async [%0, %1]
|
|
|
|
// CHECK: gpu.wait [%[[t0]], %[[t1]]]
|
|
|
|
// CHECK-NOT: async
|
|
|
|
gpu.wait [%0, %1]
|
|
|
|
// CHECK: gpu.wait
|
|
|
|
// CHECK-NOT: async
|
|
|
|
gpu.wait // Valid, but a no-op.
|
|
|
|
return
|
|
|
|
}
|
2019-05-06 20:01:12 +08:00
|
|
|
}
|