|
| 1 | +// RUN: heir-opt --annotate-level="level-budget=5" %s | FileCheck %s --check-prefix=CHECK-B5 |
| 2 | + |
| 3 | +module { |
| 4 | + // Part 1: No loop, at least three levels |
| 5 | + func.func @no_loop(%arg0: !secret.secret<tensor<16xf32>>) -> !secret.secret<tensor<16xf32>> { |
| 6 | + %0 = secret.generic(%arg0 : !secret.secret<tensor<16xf32>>) { |
| 7 | + ^body(%val: tensor<16xf32>): |
| 8 | + // CHECK-B5: mgmt.modreduce |
| 9 | + // CHECK-B5-SAME: {mgmt.level = 1 : index} |
| 10 | + %1 = mgmt.modreduce %val : tensor<16xf32> |
| 11 | + |
| 12 | + // CHECK-B5: mgmt.modreduce |
| 13 | + // CHECK-B5-SAME: {mgmt.level = 2 : index} |
| 14 | + %2 = mgmt.modreduce %1 : tensor<16xf32> |
| 15 | + |
| 16 | + // CHECK-B5: mgmt.modreduce |
| 17 | + // CHECK-B5-SAME: {mgmt.level = 3 : index} |
| 18 | + %3 = mgmt.modreduce %2 : tensor<16xf32> |
| 19 | + |
| 20 | + secret.yield %3 : tensor<16xf32> |
| 21 | + } -> !secret.secret<tensor<16xf32>> |
| 22 | + return %0 : !secret.secret<tensor<16xf32>> |
| 23 | + } |
| 24 | + |
| 25 | + // Part 2: Loop that converges |
| 26 | + func.func @loop_converges(%arg0: !secret.secret<tensor<16xf32>>) -> !secret.secret<tensor<16xf32>> { |
| 27 | + %cst = arith.constant dense<0.000000e+00> : tensor<16xf32> |
| 28 | + %c0 = arith.constant 0 : index |
| 29 | + %c10 = arith.constant 10 : index |
| 30 | + %c1 = arith.constant 1 : index |
| 31 | + %cst_0 = arith.constant dense<1.100000e+00> : tensor<16xf32> |
| 32 | + |
| 33 | + %0 = secret.generic(%arg0 : !secret.secret<tensor<16xf32>>) { |
| 34 | + ^body(%val: tensor<16xf32>): |
| 35 | + %1 = scf.for %arg1 = %c0 to %c10 step %c1 iter_args(%arg2 = %cst) -> (tensor<16xf32>) { |
| 36 | + %2 = arith.mulf %val, %cst_0 : tensor<16xf32> |
| 37 | + // CHECK-B5: mgmt.modreduce |
| 38 | + // CHECK-B5-SAME: {mgmt.level = 1 : index} |
| 39 | + %3 = mgmt.modreduce %2 : tensor<16xf32> |
| 40 | + |
| 41 | + // CHECK-B5: arith.addf |
| 42 | + // CHECK-B5-SAME: {mgmt.level = 1 : index} |
| 43 | + %4 = arith.addf %arg2, %3 : tensor<16xf32> |
| 44 | + scf.yield %4 : tensor<16xf32> |
| 45 | + } |
| 46 | + secret.yield %1 : tensor<16xf32> |
| 47 | + } -> !secret.secret<tensor<16xf32>> |
| 48 | + return %0 : !secret.secret<tensor<16xf32>> |
| 49 | + } |
| 50 | + |
| 51 | + // Part 3: Loop that does not converge (grows to 10) |
| 52 | + func.func @loop_diverges(%arg0: !secret.secret<tensor<16xf32>>) -> !secret.secret<tensor<16xf32>> { |
| 53 | + %c0 = arith.constant 0 : index |
| 54 | + %c10 = arith.constant 10 : index |
| 55 | + %c1 = arith.constant 1 : index |
| 56 | + |
| 57 | + %0 = secret.generic(%arg0 : !secret.secret<tensor<16xf32>>) { |
| 58 | + ^body(%val: tensor<16xf32>): |
| 59 | + // CHECK-B5: scf.for |
| 60 | + %1 = scf.for %arg1 = %c0 to %c10 step %c1 iter_args(%arg2 = %val) -> (tensor<16xf32>) { |
| 61 | + // CHECK-B5: mgmt.modreduce |
| 62 | + // CHECK-B5-SAME: {mgmt.level = "invalid"} |
| 63 | + %2 = mgmt.modreduce %arg2 : tensor<16xf32> |
| 64 | + scf.yield %2 : tensor<16xf32> |
| 65 | + } |
| 66 | + secret.yield %1 : tensor<16xf32> |
| 67 | + } -> !secret.secret<tensor<16xf32>> |
| 68 | + return %0 : !secret.secret<tensor<16xf32>> |
| 69 | + } |
| 70 | +} |
0 commit comments