2020-07-07 07:28:26 +08:00
|
|
|
// RUN: mlir-hlo-opt %s -lhlo-legalize-to-gpu -split-input-file | FileCheck %s
|
|
|
|
|
|
|
|
func @reduce(%arg: memref<100x10xf32>,
|
|
|
|
%init: memref<f32>,
|
|
|
|
%result: memref<100xf32>) {
|
2020-07-09 01:05:32 +08:00
|
|
|
"lmhlo.reduce"(%arg, %init, %result) ( {
|
2020-07-07 07:28:26 +08:00
|
|
|
^bb0(%lhs: memref<f32>, %rhs: memref<f32>, %res: memref<f32>):
|
2020-07-09 01:05:32 +08:00
|
|
|
"lmhlo.add"(%lhs, %rhs, %res)
|
2020-07-07 07:28:26 +08:00
|
|
|
: (memref<f32>, memref<f32>, memref<f32>) -> ()
|
2020-07-09 01:05:32 +08:00
|
|
|
"lmhlo.terminator"() : () -> ()
|
2020-07-07 07:28:26 +08:00
|
|
|
} ) {dimensions = dense<[1]> : tensor<1xi64>}
|
|
|
|
: (memref<100x10xf32>, memref<f32>, memref<100xf32>) -> ()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-05 05:41:18 +08:00
|
|
|
// CHECK-DAG: #[[$MAP:.*]] = affine_map<()[s0] -> (s0)>
|
|
|
|
|
|
|
|
// CHECK: func @reduce(%[[ARG0:.*]]: memref<100x10xf32>, %[[ARG1:.*]]: memref<f32>, %[[ARG2:.*]]: memref<100xf32>) {
|
2020-07-07 07:28:26 +08:00
|
|
|
// CHECK-DAG: %[[C100:.*]] = constant 100 : index
|
|
|
|
// CHECK-DAG: %[[C1:.*]] = constant 1 : index
|
2021-02-05 05:41:18 +08:00
|
|
|
// CHECK: gpu.launch blocks({{.*}}, {{.*}}, {{.*}}) in ({{.*}} = %[[C1]], {{.*}} = %[[C1]], {{.*}} = %[[C1]]) threads(%[[IDX:.*]], {{.*}}, {{.*}}) in ({{.*}} = %[[C100]], {{.*}} = %[[C1]], {{.*}} = %[[C1]]) {
|
2021-03-17 04:31:59 +08:00
|
|
|
// CHECK: %[[ACC:.*]] = memref.load %[[ARG1]][] : memref<f32>
|
2021-02-05 05:41:18 +08:00
|
|
|
// CHECK: store %[[ACC]], %[[ARG2]][%[[IDX:.*]]] : memref<100xf32>
|
|
|
|
// CHECK-DAG: %[[LB:.*]] = constant 0 : index
|
|
|
|
// CHECK-DAG: %[[UB:.*]] = constant 10 : index
|
|
|
|
// CHECK-DAG: %[[STEP:.*]] = constant 1 : index
|
|
|
|
// CHECK: scf.for %[[IDX1:.*]] = %[[LB]] to %[[UB]] step %[[STEP]] {
|
2021-03-17 04:31:59 +08:00
|
|
|
// CHECK: %[[LHS:.*]] = memref.subview %[[ARG2]][%[[IDX]]] [1] [1] : memref<100xf32> to memref<f32, #[[$MAP]]>
|
|
|
|
// CHECK: %[[RHS:.*]] = memref.subview %[[ARG0]][%[[IDX]], %[[IDX1]]] [1, 1] [1, 1] : memref<100x10xf32> to memref<f32, #[[$MAP]]>
|
2021-02-05 05:41:18 +08:00
|
|
|
// CHECK: "lmhlo.add"(%[[LHS]], %[[RHS]], %[[LHS]]) : (memref<f32, {{.*}}>, memref<f32, {{.*}}>, memref<f32, {{.*}}>) -> ()
|
|
|
|
// CHECK: }
|
|
|
|
// CHECK: gpu.terminator
|
|
|
|
// CHECK: }
|
|
|
|
// CHECK: return
|