Example
storylm0_prefill.kina
let prefill = fn(
token_ids: tensor<I64, [1, 3], @host>,
token_embedding: tensor<F32, [8, 4], @host>,
causal_mask: tensor<F32, [1, 1, 3, 3], @host>,
attention_scale: tensor<F32, [1, 1, 1, 1], @host>,
wq: tensor<F32, [4, 4], @host>,
wk: tensor<F32, [4, 4], @host>,
wv: tensor<F32, [4, 4], @host>,
wo: tensor<F32, [4, 4], @host>,
lm_head: tensor<F32, [4, 8], @host>
) -> (
tensor<F32, [1, 2, 2, 3], @host>,
tensor<F32, [1, 2, 3, 2], @host>,
tensor<F32, [1, 3, 8], @host>
) {
let x = token_embedding.gather(token_ids) in
let wq_b = wq.broadcast([1, 4, 4]) in
let wk_b = wk.broadcast([1, 4, 4]) in
let wv_b = wv.broadcast([1, 4, 4]) in
let wo_b = wo.broadcast([1, 4, 4]) in
let lm_b = lm_head.broadcast([1, 4, 8]) in
let q_flat = x @ wq_b in
let k_flat = x @ wk_b in
let v_flat = x @ wv_b in
let q = q_flat.reshape([1, 3, 2, 2]).transpose([0, 2, 1, 3]) in
let k_t = k_flat.reshape([1, 3, 2, 2]).transpose([0, 2, 3, 1]) in
let v = v_flat.reshape([1, 3, 2, 2]).transpose([0, 2, 1, 3]) in
let scores = q @ k_t in
let scale_b = attention_scale.broadcast([1, 2, 3, 3]) in
let mask_b = causal_mask.broadcast([1, 2, 3, 3]) in
let probs = ((scores * scale_b) + mask_b).softmax(axis=3) in
let context = probs @ v in
let merged = context.transpose([0, 2, 1, 3]).reshape([1, 3, 4]) in
let residual = x + (merged @ wo_b) in
let logits = residual @ lm_b in
(k_t, v, logits)
} in
let last_logits = fn(logits: tensor<F32, [1, 3, 8], @host>) -> tensor<F32, [1, 1, 8], @host> {
let last = logits.slice(axis=1, start=2, stop=3) in
last
} in
let decode_s3 = fn(
token_ids: tensor<I64, [1, 1], @host>,
token_embedding: tensor<F32, [8, 4], @host>,
k_past: tensor<F32, [1, 2, 2, 3], @host>,
v_past: tensor<F32, [1, 2, 3, 2], @host>,
attention_scale: tensor<F32, [1, 1, 1, 1], @host>,
wq: tensor<F32, [4, 4], @host>,
wk: tensor<F32, [4, 4], @host>,
wv: tensor<F32, [4, 4], @host>,
wo: tensor<F32, [4, 4], @host>,
lm_head: tensor<F32, [4, 8], @host>
) -> (
tensor<F32, [1, 2, 2, 4], @host>,
tensor<F32, [1, 2, 4, 2], @host>,
tensor<F32, [1, 1, 8], @host>
) {
let x = token_embedding.gather(token_ids) in
let wq_b = wq.broadcast([1, 4, 4]) in
let wk_b = wk.broadcast([1, 4, 4]) in
let wv_b = wv.broadcast([1, 4, 4]) in
let wo_b = wo.broadcast([1, 4, 4]) in
let lm_b = lm_head.broadcast([1, 4, 8]) in
let q_flat = x @ wq_b in
let k_flat = x @ wk_b in
let v_flat = x @ wv_b in
let q = q_flat.reshape([1, 1, 2, 2]).transpose([0, 2, 1, 3]) in
let k_new = k_flat.reshape([1, 1, 2, 2]).transpose([0, 2, 3, 1]) in
let v_new = v_flat.reshape([1, 1, 2, 2]).transpose([0, 2, 1, 3]) in
let k_next = k_past.concat(axis=3, k_new) in
let v_next = v_past.concat(axis=2, v_new) in
let scores = q @ k_next in
let scale_b = attention_scale.broadcast([1, 2, 1, 4]) in
let probs = (scores * scale_b).softmax(axis=3) in
let context = probs @ v_next in
let merged = context.transpose([0, 2, 1, 3]).reshape([1, 1, 4]) in
let residual = x + (merged @ wo_b) in
let logits = residual @ lm_b in
(k_next, v_next, logits)
} in
let greedy_one = fn(logits: tensor<F32, [1, 1, 8], @host>) -> tensor<I64, [1, 1], @host> {
let tokens = logits.reduce(op=argmax, axis=2) in
tokens
} in
let token_ids = tensor<I64, [1, 3], @host> in
let token_embedding = tensor<F32, [8, 4], @host> in
let causal_mask = tensor<F32, [1, 1, 3, 3], @host> in
let attention_scale = tensor<F32, [1, 1, 1, 1], @host> in
let wq = tensor<F32, [4, 4], @host> in
let wk = tensor<F32, [4, 4], @host> in
let wv = tensor<F32, [4, 4], @host> in
let wo = tensor<F32, [4, 4], @host> in
let lm_head = tensor<F32, [4, 8], @host> in
prefill(token_ids, token_embedding, causal_mask, attention_scale, wq, wk, wv, wo, lm_head)
module {
func.func @fn_val_0(%1: tensor<1x32x64xf32>, %2: tensor<1x1x64xf32>) -> tensor<1x32x64xf32> attributes {llvm.emit_c_interface} {
%3 = tensor.empty() : tensor<1x32x64xf32>
%4 = linalg.mul ins(%1, %1 : tensor<1x32x64xf32>, tensor<1x32x64xf32>) outs(%3 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
%7 = arith.constant 0.000000e+00 : f32
%5 = tensor.empty() : tensor<1x32x1xf32>
%6 = linalg.fill ins(%7 : f32) outs(%5 : tensor<1x32x1xf32>) -> tensor<1x32x1xf32>
%8 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, 0)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%4 : tensor<1x32x64xf32>) outs(%6 : tensor<1x32x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%9 = arith.addf %a0, %a1 : f32
linalg.yield %9 : f32
} -> tensor<1x32x1xf32>
%10 = arith.constant dense<0.000000e+00> : tensor<1x1x1xf32>
%11 = tensor.empty() : tensor<1x32x1xf32>
%12 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, 0, 0)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%10 : tensor<1x1x1xf32>) outs(%11 : tensor<1x32x1xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x1xf32>
%13 = tensor.empty() : tensor<1x32x1xf32>
%14 = linalg.mul ins(%8, %12 : tensor<1x32x1xf32>, tensor<1x32x1xf32>) outs(%13 : tensor<1x32x1xf32>) -> tensor<1x32x1xf32>
%15 = arith.constant dense<0.000000e+00> : tensor<1x1x1xf32>
%16 = tensor.empty() : tensor<1x32x1xf32>
%17 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, 0, 0)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%15 : tensor<1x1x1xf32>) outs(%16 : tensor<1x32x1xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x1xf32>
%18 = tensor.empty() : tensor<1x32x1xf32>
%19 = linalg.add ins(%14, %17 : tensor<1x32x1xf32>, tensor<1x32x1xf32>) outs(%18 : tensor<1x32x1xf32>) -> tensor<1x32x1xf32>
%23 = tensor.empty() : tensor<1x32x1xf32>
%24 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%19 : tensor<1x32x1xf32>) outs(%23 : tensor<1x32x1xf32>) {
^bb0(%x: f32, %_: f32):
%20 = math.sqrt %x : f32
%21 = arith.constant 1.000000e+00 : f32
%22 = arith.divf %21, %20 : f32
linalg.yield %22 : f32
} -> tensor<1x32x1xf32>
%25 = tensor.empty() : tensor<1x32x64xf32>
%26 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, d1, 0)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%24 : tensor<1x32x1xf32>) outs(%25 : tensor<1x32x64xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x64xf32>
%27 = tensor.empty() : tensor<1x32x64xf32>
%28 = linalg.mul ins(%1, %26 : tensor<1x32x64xf32>, tensor<1x32x64xf32>) outs(%27 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
%29 = tensor.empty() : tensor<1x32x64xf32>
%30 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, 0, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%2 : tensor<1x1x64xf32>) outs(%29 : tensor<1x32x64xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x64xf32>
%31 = tensor.empty() : tensor<1x32x64xf32>
%32 = linalg.mul ins(%28, %30 : tensor<1x32x64xf32>, tensor<1x32x64xf32>) outs(%31 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
return %32 : tensor<1x32x64xf32>
}
func.func @fn_val_33(%34: tensor<1x32x64xf32>, %35: tensor<1x64x128xf32>, %36: tensor<1x128x64xf32>) -> tensor<1x32x64xf32> attributes {llvm.emit_c_interface} {
%37 = arith.constant dense<0.000000e+00> : tensor<1x32x128xf32>
%38 = linalg.batch_matmul ins(%34, %35 : tensor<1x32x64xf32>, tensor<1x64x128xf32>) outs(%37 : tensor<1x32x128xf32>) -> tensor<1x32x128xf32>
%44 = tensor.empty() : tensor<1x32x128xf32>
%45 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%38 : tensor<1x32x128xf32>) outs(%44 : tensor<1x32x128xf32>) {
^bb0(%a0: f32, %a1: f32):
%39 = arith.constant 1.000000e+00 : f32
%40 = arith.negf %a0 : f32
%41 = math.exp %40 : f32
%42 = arith.addf %39, %41 : f32
%43 = arith.divf %39, %42 : f32
linalg.yield %43 : f32
} -> tensor<1x32x128xf32>
%46 = tensor.empty() : tensor<1x32x128xf32>
%47 = linalg.mul ins(%38, %45 : tensor<1x32x128xf32>, tensor<1x32x128xf32>) outs(%46 : tensor<1x32x128xf32>) -> tensor<1x32x128xf32>
%48 = arith.constant dense<0.000000e+00> : tensor<1x32x64xf32>
%49 = linalg.batch_matmul ins(%47, %36 : tensor<1x32x128xf32>, tensor<1x128x64xf32>) outs(%48 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
return %49 : tensor<1x32x64xf32>
}
func.func @fn_val_50(%51: tensor<1x32x64xf32>, %52: tensor<1x64x64xf32>, %53: tensor<1x64x64xf32>, %54: tensor<1x64x64xf32>, %55: tensor<1x64x64xf32>) -> tensor<1x32x64xf32> attributes {llvm.emit_c_interface} {
%56 = arith.constant dense<0.000000e+00> : tensor<1x32x64xf32>
%57 = linalg.batch_matmul ins(%51, %52 : tensor<1x32x64xf32>, tensor<1x64x64xf32>) outs(%56 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
%58 = arith.constant dense<0.000000e+00> : tensor<1x32x64xf32>
%59 = linalg.batch_matmul ins(%51, %53 : tensor<1x32x64xf32>, tensor<1x64x64xf32>) outs(%58 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
%60 = arith.constant dense<0.000000e+00> : tensor<1x32x64xf32>
%61 = linalg.batch_matmul ins(%51, %54 : tensor<1x32x64xf32>, tensor<1x64x64xf32>) outs(%60 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
%62 = tensor.empty() : tensor<1x64x32xf32>
%63 = linalg.transpose ins(%59 : tensor<1x32x64xf32>) outs(%62 : tensor<1x64x32xf32>) permutation = [0, 2, 1]
%64 = arith.constant dense<0.000000e+00> : tensor<1x32x32xf32>
%65 = linalg.batch_matmul ins(%57, %63 : tensor<1x32x64xf32>, tensor<1x64x32xf32>) outs(%64 : tensor<1x32x32xf32>) -> tensor<1x32x32xf32>
%66 = arith.constant dense<0.000000e+00> : tensor<1x1x1xf32>
%67 = tensor.empty() : tensor<1x32x32xf32>
%68 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, 0, 0)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%66 : tensor<1x1x1xf32>) outs(%67 : tensor<1x32x32xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x32xf32>
%69 = tensor.empty() : tensor<1x32x32xf32>
%70 = linalg.mul ins(%65, %68 : tensor<1x32x32xf32>, tensor<1x32x32xf32>) outs(%69 : tensor<1x32x32xf32>) -> tensor<1x32x32xf32>
%73 = arith.constant 0xFF800000 : f32
%71 = tensor.empty() : tensor<1x32x1xf32>
%72 = linalg.fill ins(%73 : f32) outs(%71 : tensor<1x32x1xf32>) -> tensor<1x32x1xf32>
%74 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, 0)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%70 : tensor<1x32x32xf32>) outs(%72 : tensor<1x32x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%75 = arith.maximumf %a0, %a1 : f32
linalg.yield %75 : f32
} -> tensor<1x32x1xf32>
%76 = tensor.empty() : tensor<1x32x32xf32>
%77 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, d1, 0)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%74 : tensor<1x32x1xf32>) outs(%76 : tensor<1x32x32xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x32xf32>
%78 = tensor.empty() : tensor<1x32x32xf32>
%79 = linalg.sub ins(%70, %77 : tensor<1x32x32xf32>, tensor<1x32x32xf32>) outs(%78 : tensor<1x32x32xf32>) -> tensor<1x32x32xf32>
%80 = tensor.empty() : tensor<1x32x32xf32>
%81 = linalg.exp ins(%79 : tensor<1x32x32xf32>) outs(%80 : tensor<1x32x32xf32>) -> tensor<1x32x32xf32>
%84 = arith.constant 0xFF800000 : f32
%82 = tensor.empty() : tensor<1x32x1xf32>
%83 = linalg.fill ins(%84 : f32) outs(%82 : tensor<1x32x1xf32>) -> tensor<1x32x1xf32>
%85 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, 0)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%70 : tensor<1x32x32xf32>) outs(%83 : tensor<1x32x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%86 = arith.maximumf %a0, %a1 : f32
linalg.yield %86 : f32
} -> tensor<1x32x1xf32>
%87 = tensor.empty() : tensor<1x32x32xf32>
%88 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, d1, 0)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%85 : tensor<1x32x1xf32>) outs(%87 : tensor<1x32x32xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x32xf32>
%89 = tensor.empty() : tensor<1x32x32xf32>
%90 = linalg.sub ins(%70, %88 : tensor<1x32x32xf32>, tensor<1x32x32xf32>) outs(%89 : tensor<1x32x32xf32>) -> tensor<1x32x32xf32>
%91 = tensor.empty() : tensor<1x32x32xf32>
%92 = linalg.exp ins(%90 : tensor<1x32x32xf32>) outs(%91 : tensor<1x32x32xf32>) -> tensor<1x32x32xf32>
%95 = arith.constant 0.000000e+00 : f32
%93 = tensor.empty() : tensor<1x32x1xf32>
%94 = linalg.fill ins(%95 : f32) outs(%93 : tensor<1x32x1xf32>) -> tensor<1x32x1xf32>
%96 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, 0)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%92 : tensor<1x32x32xf32>) outs(%94 : tensor<1x32x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%97 = arith.addf %a0, %a1 : f32
linalg.yield %97 : f32
} -> tensor<1x32x1xf32>
%98 = tensor.empty() : tensor<1x32x32xf32>
%99 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (0, d1, 0)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%96 : tensor<1x32x1xf32>) outs(%98 : tensor<1x32x32xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x32x32xf32>
%100 = tensor.empty() : tensor<1x32x32xf32>
%101 = linalg.div ins(%81, %99 : tensor<1x32x32xf32>, tensor<1x32x32xf32>) outs(%100 : tensor<1x32x32xf32>) -> tensor<1x32x32xf32>
%102 = arith.constant dense<0.000000e+00> : tensor<1x32x64xf32>
%103 = linalg.batch_matmul ins(%101, %61 : tensor<1x32x32xf32>, tensor<1x32x64xf32>) outs(%102 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
%104 = arith.constant dense<0.000000e+00> : tensor<1x32x64xf32>
%105 = linalg.batch_matmul ins(%103, %55 : tensor<1x32x64xf32>, tensor<1x64x64xf32>) outs(%104 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
return %105 : tensor<1x32x64xf32>
}
func.func @fn_val_106(%107: tensor<1x32x64xf32>, %108: tensor<1x1x64xf32>, %109: tensor<1x64x64xf32>, %110: tensor<1x64x64xf32>, %111: tensor<1x64x64xf32>, %112: tensor<1x64x64xf32>, %113: tensor<1x1x64xf32>, %114: tensor<1x64x128xf32>, %115: tensor<1x128x64xf32>) -> tensor<1x32x64xf32> attributes {llvm.emit_c_interface} {
%116 = func.call @fn_val_0(%107, %108) : (tensor<1x32x64xf32>, tensor<1x1x64xf32>) -> tensor<1x32x64xf32>
%117 = func.call @fn_val_50(%116, %109, %110, %111, %112) : (tensor<1x32x64xf32>, tensor<1x64x64xf32>, tensor<1x64x64xf32>, tensor<1x64x64xf32>, tensor<1x64x64xf32>) -> tensor<1x32x64xf32>
%118 = tensor.empty() : tensor<1x32x64xf32>
%119 = linalg.add ins(%107, %117 : tensor<1x32x64xf32>, tensor<1x32x64xf32>) outs(%118 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
%120 = func.call @fn_val_0(%119, %113) : (tensor<1x32x64xf32>, tensor<1x1x64xf32>) -> tensor<1x32x64xf32>
%121 = func.call @fn_val_33(%120, %114, %115) : (tensor<1x32x64xf32>, tensor<1x64x128xf32>, tensor<1x128x64xf32>) -> tensor<1x32x64xf32>
%122 = tensor.empty() : tensor<1x32x64xf32>
%123 = linalg.add ins(%119, %121 : tensor<1x32x64xf32>, tensor<1x32x64xf32>) outs(%122 : tensor<1x32x64xf32>) -> tensor<1x32x64xf32>
return %123 : tensor<1x32x64xf32>
}
func.func @fn_val_124(%125: tensor<1x3xi64>, %126: tensor<8x4xf32>, %127: tensor<1x1x3x3xf32>, %128: tensor<1x1x1x1xf32>, %129: tensor<4x4xf32>, %130: tensor<4x4xf32>, %131: tensor<4x4xf32>, %132: tensor<4x4xf32>, %133: tensor<4x8xf32>) -> (tensor<1x2x2x3xf32>, tensor<1x2x3x2xf32>, tensor<1x3x8xf32>) attributes {llvm.emit_c_interface} {
%134 = arith.constant 0 : i64
%135 = arith.constant 8 : i64
%136 = tensor.empty() : tensor<1x3xi64>
%137 = linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
iterator_types = ["parallel", "parallel"]
} ins(%125 : tensor<1x3xi64>) outs(%136 : tensor<1x3xi64>) {
^bb0(%candidate: i64, %_: i64):
%138 = arith.cmpi sge, %candidate, %134 : i64
%139 = arith.cmpi slt, %candidate, %135 : i64
%140 = arith.andi %138, %139 : i1
cf.assert %140, "gather index out of bounds"
linalg.yield %candidate : i64
} -> tensor<1x3xi64>
%141 = tensor.empty() : tensor<1x3x4xf32>
%142 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%137 : tensor<1x3xi64>) outs(%141 : tensor<1x3x4xf32>) {
^bb0(%idx: i64, %_: f32):
%143 = arith.index_cast %idx : i64 to index
%144 = linalg.index 2 : index
%145 = tensor.extract %126[%143, %144] : tensor<8x4xf32>
linalg.yield %145 : f32
} -> tensor<1x3x4xf32>
%146 = tensor.empty() : tensor<1x4x4xf32>
%147 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%129 : tensor<4x4xf32>) outs(%146 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%148 = tensor.empty() : tensor<1x4x4xf32>
%149 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%130 : tensor<4x4xf32>) outs(%148 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%150 = tensor.empty() : tensor<1x4x4xf32>
%151 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%131 : tensor<4x4xf32>) outs(%150 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%152 = tensor.empty() : tensor<1x4x4xf32>
%153 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%132 : tensor<4x4xf32>) outs(%152 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%154 = tensor.empty() : tensor<1x4x8xf32>
%155 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%133 : tensor<4x8xf32>) outs(%154 : tensor<1x4x8xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x8xf32>
%156 = arith.constant dense<0.000000e+00> : tensor<1x3x4xf32>
%157 = linalg.batch_matmul ins(%142, %147 : tensor<1x3x4xf32>, tensor<1x4x4xf32>) outs(%156 : tensor<1x3x4xf32>) -> tensor<1x3x4xf32>
%158 = arith.constant dense<0.000000e+00> : tensor<1x3x4xf32>
%159 = linalg.batch_matmul ins(%142, %149 : tensor<1x3x4xf32>, tensor<1x4x4xf32>) outs(%158 : tensor<1x3x4xf32>) -> tensor<1x3x4xf32>
%160 = arith.constant dense<0.000000e+00> : tensor<1x3x4xf32>
%161 = linalg.batch_matmul ins(%142, %151 : tensor<1x3x4xf32>, tensor<1x4x4xf32>) outs(%160 : tensor<1x3x4xf32>) -> tensor<1x3x4xf32>
%162 = arith.constant dense<[1, 3, 2, 2]> : tensor<4xi32>
%163 = tensor.reshape %157(%162) : (tensor<1x3x4xf32>, tensor<4xi32>) -> tensor<1x3x2x2xf32>
%164 = tensor.empty() : tensor<1x2x3x2xf32>
%165 = linalg.transpose ins(%163 : tensor<1x3x2x2xf32>) outs(%164 : tensor<1x2x3x2xf32>) permutation = [0, 2, 1, 3]
%166 = arith.constant dense<[1, 3, 2, 2]> : tensor<4xi32>
%167 = tensor.reshape %159(%166) : (tensor<1x3x4xf32>, tensor<4xi32>) -> tensor<1x3x2x2xf32>
%168 = tensor.empty() : tensor<1x2x2x3xf32>
%169 = linalg.transpose ins(%167 : tensor<1x3x2x2xf32>) outs(%168 : tensor<1x2x2x3xf32>) permutation = [0, 2, 3, 1]
%170 = arith.constant dense<[1, 3, 2, 2]> : tensor<4xi32>
%171 = tensor.reshape %161(%170) : (tensor<1x3x4xf32>, tensor<4xi32>) -> tensor<1x3x2x2xf32>
%172 = tensor.empty() : tensor<1x2x3x2xf32>
%173 = linalg.transpose ins(%171 : tensor<1x3x2x2xf32>) outs(%172 : tensor<1x2x3x2xf32>) permutation = [0, 2, 1, 3]
%174 = tensor.collapse_shape %165 [[0, 1], [2], [3]] : tensor<1x2x3x2xf32> into tensor<2x3x2xf32>
%175 = tensor.collapse_shape %169 [[0, 1], [2], [3]] : tensor<1x2x2x3xf32> into tensor<2x2x3xf32>
%176 = arith.constant dense<0.000000e+00> : tensor<2x3x3xf32>
%177 = linalg.batch_matmul ins(%174, %175 : tensor<2x3x2xf32>, tensor<2x2x3xf32>) outs(%176 : tensor<2x3x3xf32>) -> tensor<2x3x3xf32>
%178 = tensor.expand_shape %177 [[0, 1], [2], [3]] : tensor<2x3x3xf32> into tensor<1x2x3x3xf32>
%179 = tensor.empty() : tensor<1x2x3x3xf32>
%180 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, 0, 0, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%128 : tensor<1x1x1x1xf32>) outs(%179 : tensor<1x2x3x3xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x3x3xf32>
%181 = tensor.empty() : tensor<1x2x3x3xf32>
%182 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, 0, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%127 : tensor<1x1x3x3xf32>) outs(%181 : tensor<1x2x3x3xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x3x3xf32>
%183 = tensor.empty() : tensor<1x2x3x3xf32>
%184 = linalg.mul ins(%178, %180 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%183 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%185 = tensor.empty() : tensor<1x2x3x3xf32>
%186 = linalg.add ins(%184, %182 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%185 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%187 = tensor.empty() : tensor<1x2x3x3xf32>
%188 = linalg.mul ins(%178, %180 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%187 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%189 = tensor.empty() : tensor<1x2x3x3xf32>
%190 = linalg.add ins(%188, %182 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%189 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%193 = arith.constant 0xFF800000 : f32
%191 = tensor.empty() : tensor<1x2x3x1xf32>
%192 = linalg.fill ins(%193 : f32) outs(%191 : tensor<1x2x3x1xf32>) -> tensor<1x2x3x1xf32>
%194 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)>],
iterator_types = ["parallel", "parallel", "parallel", "reduction"]
} ins(%190 : tensor<1x2x3x3xf32>) outs(%192 : tensor<1x2x3x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%195 = arith.maximumf %a0, %a1 : f32
linalg.yield %195 : f32
} -> tensor<1x2x3x1xf32>
%196 = tensor.empty() : tensor<1x2x3x3xf32>
%197 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, d1, d2, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%194 : tensor<1x2x3x1xf32>) outs(%196 : tensor<1x2x3x3xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x3x3xf32>
%198 = tensor.empty() : tensor<1x2x3x3xf32>
%199 = linalg.sub ins(%186, %197 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%198 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%200 = tensor.empty() : tensor<1x2x3x3xf32>
%201 = linalg.exp ins(%199 : tensor<1x2x3x3xf32>) outs(%200 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%202 = tensor.empty() : tensor<1x2x3x3xf32>
%203 = linalg.mul ins(%178, %180 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%202 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%204 = tensor.empty() : tensor<1x2x3x3xf32>
%205 = linalg.add ins(%203, %182 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%204 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%206 = tensor.empty() : tensor<1x2x3x3xf32>
%207 = linalg.mul ins(%178, %180 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%206 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%208 = tensor.empty() : tensor<1x2x3x3xf32>
%209 = linalg.add ins(%207, %182 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%208 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%212 = arith.constant 0xFF800000 : f32
%210 = tensor.empty() : tensor<1x2x3x1xf32>
%211 = linalg.fill ins(%212 : f32) outs(%210 : tensor<1x2x3x1xf32>) -> tensor<1x2x3x1xf32>
%213 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)>],
iterator_types = ["parallel", "parallel", "parallel", "reduction"]
} ins(%209 : tensor<1x2x3x3xf32>) outs(%211 : tensor<1x2x3x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%214 = arith.maximumf %a0, %a1 : f32
linalg.yield %214 : f32
} -> tensor<1x2x3x1xf32>
%215 = tensor.empty() : tensor<1x2x3x3xf32>
%216 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, d1, d2, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%213 : tensor<1x2x3x1xf32>) outs(%215 : tensor<1x2x3x3xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x3x3xf32>
%217 = tensor.empty() : tensor<1x2x3x3xf32>
%218 = linalg.sub ins(%205, %216 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%217 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%219 = tensor.empty() : tensor<1x2x3x3xf32>
%220 = linalg.exp ins(%218 : tensor<1x2x3x3xf32>) outs(%219 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%223 = arith.constant 0.000000e+00 : f32
%221 = tensor.empty() : tensor<1x2x3x1xf32>
%222 = linalg.fill ins(%223 : f32) outs(%221 : tensor<1x2x3x1xf32>) -> tensor<1x2x3x1xf32>
%224 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)>],
iterator_types = ["parallel", "parallel", "parallel", "reduction"]
} ins(%220 : tensor<1x2x3x3xf32>) outs(%222 : tensor<1x2x3x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%225 = arith.addf %a0, %a1 : f32
linalg.yield %225 : f32
} -> tensor<1x2x3x1xf32>
%226 = tensor.empty() : tensor<1x2x3x3xf32>
%227 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, d1, d2, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%224 : tensor<1x2x3x1xf32>) outs(%226 : tensor<1x2x3x3xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x3x3xf32>
%228 = tensor.empty() : tensor<1x2x3x3xf32>
%229 = linalg.div ins(%201, %227 : tensor<1x2x3x3xf32>, tensor<1x2x3x3xf32>) outs(%228 : tensor<1x2x3x3xf32>) -> tensor<1x2x3x3xf32>
%230 = tensor.collapse_shape %229 [[0, 1], [2], [3]] : tensor<1x2x3x3xf32> into tensor<2x3x3xf32>
%231 = tensor.collapse_shape %173 [[0, 1], [2], [3]] : tensor<1x2x3x2xf32> into tensor<2x3x2xf32>
%232 = arith.constant dense<0.000000e+00> : tensor<2x3x2xf32>
%233 = linalg.batch_matmul ins(%230, %231 : tensor<2x3x3xf32>, tensor<2x3x2xf32>) outs(%232 : tensor<2x3x2xf32>) -> tensor<2x3x2xf32>
%234 = tensor.expand_shape %233 [[0, 1], [2], [3]] : tensor<2x3x2xf32> into tensor<1x2x3x2xf32>
%235 = tensor.empty() : tensor<1x3x2x2xf32>
%236 = linalg.transpose ins(%234 : tensor<1x2x3x2xf32>) outs(%235 : tensor<1x3x2x2xf32>) permutation = [0, 2, 1, 3]
%237 = arith.constant dense<[1, 3, 4]> : tensor<3xi32>
%238 = tensor.reshape %236(%237) : (tensor<1x3x2x2xf32>, tensor<3xi32>) -> tensor<1x3x4xf32>
%239 = arith.constant dense<0.000000e+00> : tensor<1x3x4xf32>
%240 = linalg.batch_matmul ins(%238, %153 : tensor<1x3x4xf32>, tensor<1x4x4xf32>) outs(%239 : tensor<1x3x4xf32>) -> tensor<1x3x4xf32>
%241 = tensor.empty() : tensor<1x3x4xf32>
%242 = linalg.add ins(%142, %240 : tensor<1x3x4xf32>, tensor<1x3x4xf32>) outs(%241 : tensor<1x3x4xf32>) -> tensor<1x3x4xf32>
%243 = arith.constant dense<0.000000e+00> : tensor<1x3x8xf32>
%244 = linalg.batch_matmul ins(%242, %155 : tensor<1x3x4xf32>, tensor<1x4x8xf32>) outs(%243 : tensor<1x3x8xf32>) -> tensor<1x3x8xf32>
return %169, %173, %244 : tensor<1x2x2x3xf32>, tensor<1x2x3x2xf32>, tensor<1x3x8xf32>
}
func.func @fn_val_245(%246: tensor<1x3x8xf32>) -> tensor<1x1x8xf32> attributes {llvm.emit_c_interface} {
%247 = tensor.extract_slice %246[0, 2, 0][1, 1, 8][1, 1, 1] : tensor<1x3x8xf32> to tensor<1x1x8xf32>
return %247 : tensor<1x1x8xf32>
}
func.func @fn_val_248(%249: tensor<1x1xi64>, %250: tensor<8x4xf32>, %251: tensor<1x2x2x3xf32>, %252: tensor<1x2x3x2xf32>, %253: tensor<1x1x1x1xf32>, %254: tensor<4x4xf32>, %255: tensor<4x4xf32>, %256: tensor<4x4xf32>, %257: tensor<4x4xf32>, %258: tensor<4x8xf32>) -> (tensor<1x2x2x4xf32>, tensor<1x2x4x2xf32>, tensor<1x1x8xf32>) attributes {llvm.emit_c_interface} {
%259 = arith.constant 0 : i64
%260 = arith.constant 8 : i64
%261 = tensor.empty() : tensor<1x1xi64>
%262 = linalg.generic {
indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>, affine_map<(d0, d1) -> (d0, d1)>],
iterator_types = ["parallel", "parallel"]
} ins(%249 : tensor<1x1xi64>) outs(%261 : tensor<1x1xi64>) {
^bb0(%candidate: i64, %_: i64):
%263 = arith.cmpi sge, %candidate, %259 : i64
%264 = arith.cmpi slt, %candidate, %260 : i64
%265 = arith.andi %263, %264 : i1
cf.assert %265, "gather index out of bounds"
linalg.yield %candidate : i64
} -> tensor<1x1xi64>
%266 = tensor.empty() : tensor<1x1x4xf32>
%267 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%262 : tensor<1x1xi64>) outs(%266 : tensor<1x1x4xf32>) {
^bb0(%idx: i64, %_: f32):
%268 = arith.index_cast %idx : i64 to index
%269 = linalg.index 2 : index
%270 = tensor.extract %250[%268, %269] : tensor<8x4xf32>
linalg.yield %270 : f32
} -> tensor<1x1x4xf32>
%271 = tensor.empty() : tensor<1x4x4xf32>
%272 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%254 : tensor<4x4xf32>) outs(%271 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%273 = tensor.empty() : tensor<1x4x4xf32>
%274 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%255 : tensor<4x4xf32>) outs(%273 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%275 = tensor.empty() : tensor<1x4x4xf32>
%276 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%256 : tensor<4x4xf32>) outs(%275 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%277 = tensor.empty() : tensor<1x4x4xf32>
%278 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%257 : tensor<4x4xf32>) outs(%277 : tensor<1x4x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x4xf32>
%279 = tensor.empty() : tensor<1x4x8xf32>
%280 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>],
iterator_types = ["parallel", "parallel", "parallel"]
} ins(%258 : tensor<4x8xf32>) outs(%279 : tensor<1x4x8xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x4x8xf32>
%281 = arith.constant dense<0.000000e+00> : tensor<1x1x4xf32>
%282 = linalg.batch_matmul ins(%267, %272 : tensor<1x1x4xf32>, tensor<1x4x4xf32>) outs(%281 : tensor<1x1x4xf32>) -> tensor<1x1x4xf32>
%283 = arith.constant dense<0.000000e+00> : tensor<1x1x4xf32>
%284 = linalg.batch_matmul ins(%267, %274 : tensor<1x1x4xf32>, tensor<1x4x4xf32>) outs(%283 : tensor<1x1x4xf32>) -> tensor<1x1x4xf32>
%285 = arith.constant dense<0.000000e+00> : tensor<1x1x4xf32>
%286 = linalg.batch_matmul ins(%267, %276 : tensor<1x1x4xf32>, tensor<1x4x4xf32>) outs(%285 : tensor<1x1x4xf32>) -> tensor<1x1x4xf32>
%287 = arith.constant dense<[1, 1, 2, 2]> : tensor<4xi32>
%288 = tensor.reshape %282(%287) : (tensor<1x1x4xf32>, tensor<4xi32>) -> tensor<1x1x2x2xf32>
%289 = tensor.empty() : tensor<1x2x1x2xf32>
%290 = linalg.transpose ins(%288 : tensor<1x1x2x2xf32>) outs(%289 : tensor<1x2x1x2xf32>) permutation = [0, 2, 1, 3]
%291 = arith.constant dense<[1, 1, 2, 2]> : tensor<4xi32>
%292 = tensor.reshape %284(%291) : (tensor<1x1x4xf32>, tensor<4xi32>) -> tensor<1x1x2x2xf32>
%293 = tensor.empty() : tensor<1x2x2x1xf32>
%294 = linalg.transpose ins(%292 : tensor<1x1x2x2xf32>) outs(%293 : tensor<1x2x2x1xf32>) permutation = [0, 2, 3, 1]
%295 = arith.constant dense<[1, 1, 2, 2]> : tensor<4xi32>
%296 = tensor.reshape %286(%295) : (tensor<1x1x4xf32>, tensor<4xi32>) -> tensor<1x1x2x2xf32>
%297 = tensor.empty() : tensor<1x2x1x2xf32>
%298 = linalg.transpose ins(%296 : tensor<1x1x2x2xf32>) outs(%297 : tensor<1x2x1x2xf32>) permutation = [0, 2, 1, 3]
%299 = tensor.empty() : tensor<1x2x2x4xf32>
%300 = tensor.insert_slice %251 into %299[0, 0, 0, 0] [1, 2, 2, 3] [1, 1, 1, 1] : tensor<1x2x2x3xf32> into tensor<1x2x2x4xf32>
%301 = tensor.insert_slice %294 into %300[0, 0, 0, 3] [1, 2, 2, 1] [1, 1, 1, 1] : tensor<1x2x2x1xf32> into tensor<1x2x2x4xf32>
%302 = tensor.empty() : tensor<1x2x4x2xf32>
%303 = tensor.insert_slice %252 into %302[0, 0, 0, 0] [1, 2, 3, 2] [1, 1, 1, 1] : tensor<1x2x3x2xf32> into tensor<1x2x4x2xf32>
%304 = tensor.insert_slice %298 into %303[0, 0, 3, 0] [1, 2, 1, 2] [1, 1, 1, 1] : tensor<1x2x1x2xf32> into tensor<1x2x4x2xf32>
%305 = tensor.collapse_shape %290 [[0, 1], [2], [3]] : tensor<1x2x1x2xf32> into tensor<2x1x2xf32>
%306 = tensor.collapse_shape %301 [[0, 1], [2], [3]] : tensor<1x2x2x4xf32> into tensor<2x2x4xf32>
%307 = arith.constant dense<0.000000e+00> : tensor<2x1x4xf32>
%308 = linalg.batch_matmul ins(%305, %306 : tensor<2x1x2xf32>, tensor<2x2x4xf32>) outs(%307 : tensor<2x1x4xf32>) -> tensor<2x1x4xf32>
%309 = tensor.expand_shape %308 [[0, 1], [2], [3]] : tensor<2x1x4xf32> into tensor<1x2x1x4xf32>
%310 = tensor.empty() : tensor<1x2x1x4xf32>
%311 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, 0, 0, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%253 : tensor<1x1x1x1xf32>) outs(%310 : tensor<1x2x1x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x1x4xf32>
%312 = tensor.empty() : tensor<1x2x1x4xf32>
%313 = linalg.mul ins(%309, %311 : tensor<1x2x1x4xf32>, tensor<1x2x1x4xf32>) outs(%312 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%314 = tensor.empty() : tensor<1x2x1x4xf32>
%315 = linalg.mul ins(%309, %311 : tensor<1x2x1x4xf32>, tensor<1x2x1x4xf32>) outs(%314 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%318 = arith.constant 0xFF800000 : f32
%316 = tensor.empty() : tensor<1x2x1x1xf32>
%317 = linalg.fill ins(%318 : f32) outs(%316 : tensor<1x2x1x1xf32>) -> tensor<1x2x1x1xf32>
%319 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)>],
iterator_types = ["parallel", "parallel", "parallel", "reduction"]
} ins(%315 : tensor<1x2x1x4xf32>) outs(%317 : tensor<1x2x1x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%320 = arith.maximumf %a0, %a1 : f32
linalg.yield %320 : f32
} -> tensor<1x2x1x1xf32>
%321 = tensor.empty() : tensor<1x2x1x4xf32>
%322 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, d1, 0, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%319 : tensor<1x2x1x1xf32>) outs(%321 : tensor<1x2x1x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x1x4xf32>
%323 = tensor.empty() : tensor<1x2x1x4xf32>
%324 = linalg.sub ins(%313, %322 : tensor<1x2x1x4xf32>, tensor<1x2x1x4xf32>) outs(%323 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%325 = tensor.empty() : tensor<1x2x1x4xf32>
%326 = linalg.exp ins(%324 : tensor<1x2x1x4xf32>) outs(%325 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%327 = tensor.empty() : tensor<1x2x1x4xf32>
%328 = linalg.mul ins(%309, %311 : tensor<1x2x1x4xf32>, tensor<1x2x1x4xf32>) outs(%327 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%329 = tensor.empty() : tensor<1x2x1x4xf32>
%330 = linalg.mul ins(%309, %311 : tensor<1x2x1x4xf32>, tensor<1x2x1x4xf32>) outs(%329 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%333 = arith.constant 0xFF800000 : f32
%331 = tensor.empty() : tensor<1x2x1x1xf32>
%332 = linalg.fill ins(%333 : f32) outs(%331 : tensor<1x2x1x1xf32>) -> tensor<1x2x1x1xf32>
%334 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)>],
iterator_types = ["parallel", "parallel", "parallel", "reduction"]
} ins(%330 : tensor<1x2x1x4xf32>) outs(%332 : tensor<1x2x1x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%335 = arith.maximumf %a0, %a1 : f32
linalg.yield %335 : f32
} -> tensor<1x2x1x1xf32>
%336 = tensor.empty() : tensor<1x2x1x4xf32>
%337 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, d1, 0, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%334 : tensor<1x2x1x1xf32>) outs(%336 : tensor<1x2x1x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x1x4xf32>
%338 = tensor.empty() : tensor<1x2x1x4xf32>
%339 = linalg.sub ins(%328, %337 : tensor<1x2x1x4xf32>, tensor<1x2x1x4xf32>) outs(%338 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%340 = tensor.empty() : tensor<1x2x1x4xf32>
%341 = linalg.exp ins(%339 : tensor<1x2x1x4xf32>) outs(%340 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%344 = arith.constant 0.000000e+00 : f32
%342 = tensor.empty() : tensor<1x2x1x1xf32>
%343 = linalg.fill ins(%344 : f32) outs(%342 : tensor<1x2x1x1xf32>) -> tensor<1x2x1x1xf32>
%345 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)>],
iterator_types = ["parallel", "parallel", "parallel", "reduction"]
} ins(%341 : tensor<1x2x1x4xf32>) outs(%343 : tensor<1x2x1x1xf32>) {
^bb0(%a0: f32, %a1: f32):
%346 = arith.addf %a0, %a1 : f32
linalg.yield %346 : f32
} -> tensor<1x2x1x1xf32>
%347 = tensor.empty() : tensor<1x2x1x4xf32>
%348 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2, d3) -> (0, d1, 0, 0)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>],
iterator_types = ["parallel", "parallel", "parallel", "parallel"]
} ins(%345 : tensor<1x2x1x1xf32>) outs(%347 : tensor<1x2x1x4xf32>) {
^bb0(%a0: f32, %a1: f32):
linalg.yield %a0 : f32
} -> tensor<1x2x1x4xf32>
%349 = tensor.empty() : tensor<1x2x1x4xf32>
%350 = linalg.div ins(%326, %348 : tensor<1x2x1x4xf32>, tensor<1x2x1x4xf32>) outs(%349 : tensor<1x2x1x4xf32>) -> tensor<1x2x1x4xf32>
%351 = tensor.collapse_shape %350 [[0, 1], [2], [3]] : tensor<1x2x1x4xf32> into tensor<2x1x4xf32>
%352 = tensor.collapse_shape %304 [[0, 1], [2], [3]] : tensor<1x2x4x2xf32> into tensor<2x4x2xf32>
%353 = arith.constant dense<0.000000e+00> : tensor<2x1x2xf32>
%354 = linalg.batch_matmul ins(%351, %352 : tensor<2x1x4xf32>, tensor<2x4x2xf32>) outs(%353 : tensor<2x1x2xf32>) -> tensor<2x1x2xf32>
%355 = tensor.expand_shape %354 [[0, 1], [2], [3]] : tensor<2x1x2xf32> into tensor<1x2x1x2xf32>
%356 = tensor.empty() : tensor<1x1x2x2xf32>
%357 = linalg.transpose ins(%355 : tensor<1x2x1x2xf32>) outs(%356 : tensor<1x1x2x2xf32>) permutation = [0, 2, 1, 3]
%358 = arith.constant dense<[1, 1, 4]> : tensor<3xi32>
%359 = tensor.reshape %357(%358) : (tensor<1x1x2x2xf32>, tensor<3xi32>) -> tensor<1x1x4xf32>
%360 = arith.constant dense<0.000000e+00> : tensor<1x1x4xf32>
%361 = linalg.batch_matmul ins(%359, %278 : tensor<1x1x4xf32>, tensor<1x4x4xf32>) outs(%360 : tensor<1x1x4xf32>) -> tensor<1x1x4xf32>
%362 = tensor.empty() : tensor<1x1x4xf32>
%363 = linalg.add ins(%267, %361 : tensor<1x1x4xf32>, tensor<1x1x4xf32>) outs(%362 : tensor<1x1x4xf32>) -> tensor<1x1x4xf32>
%364 = arith.constant dense<0.000000e+00> : tensor<1x1x8xf32>
%365 = linalg.batch_matmul ins(%363, %280 : tensor<1x1x4xf32>, tensor<1x4x8xf32>) outs(%364 : tensor<1x1x8xf32>) -> tensor<1x1x8xf32>
return %301, %304, %365 : tensor<1x2x2x4xf32>, tensor<1x2x4x2xf32>, tensor<1x1x8xf32>
}
func.func @fn_val_366(%367: tensor<1x1x8xf32>) -> tensor<1x1xi64> attributes {llvm.emit_c_interface} {
%368 = arith.constant 0xFF800000 : f32
%369 = arith.constant 0 : i64
%370 = tensor.empty() : tensor<1x1xf32>
%371 = linalg.fill ins(%368 : f32) outs(%370 : tensor<1x1xf32>) -> tensor<1x1xf32>
%372 = tensor.empty() : tensor<1x1xi64>
%373 = linalg.fill ins(%369 : i64) outs(%372 : tensor<1x1xi64>) -> tensor<1x1xi64>
%374, %375 = linalg.generic {
indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>],
iterator_types = ["parallel", "parallel", "reduction"]
} ins(%367 : tensor<1x1x8xf32>) outs(%371, %373 : tensor<1x1xf32>, tensor<1x1xi64>) {
^bb0(%a0: f32, %a1: f32, %a2: i64):
%376 = arith.cmpf ogt, %a0, %a1 : f32
%377 = arith.select %376, %a0, %a1 : f32
%378 = linalg.index 2 : index
%379 = arith.index_cast %378 : index to i64
%380 = arith.select %376, %379, %a2 : i64
linalg.yield %377, %380 : f32, i64
} -> (tensor<1x1xf32>, tensor<1x1xi64>)
return %375 : tensor<1x1xi64>
}
func.func @main() -> (tensor<1x2x2x3xf32>, tensor<1x2x3x2xf32>, tensor<1x3x8xf32>) {
%381 = arith.constant dense<0> : tensor<1x3xi64>
%382 = arith.constant dense<0.000000e+00> : tensor<8x4xf32>
%383 = arith.constant dense<0.000000e+00> : tensor<1x1x3x3xf32>
%384 = arith.constant dense<0.000000e+00> : tensor<1x1x1x1xf32>
%385 = arith.constant dense<0.000000e+00> : tensor<4x4xf32>
%386 = arith.constant dense<0.000000e+00> : tensor<4x4xf32>
%387 = arith.constant dense<0.000000e+00> : tensor<4x4xf32>
%388 = arith.constant dense<0.000000e+00> : tensor<4x4xf32>
%389 = arith.constant dense<0.000000e+00> : tensor<4x8xf32>
%390, %391, %392 = func.call @fn_val_124(%381, %382, %383, %384, %385, %386, %387, %388, %389) : (tensor<1x3xi64>, tensor<8x4xf32>, tensor<1x1x3x3xf32>, tensor<1x1x1x1xf32>, tensor<4x4xf32>, tensor<4x4xf32>, tensor<4x4xf32>, tensor<4x4xf32>, tensor<4x8xf32>) -> (tensor<1x2x2x3xf32>, tensor<1x2x3x2xf32>, tensor<1x3x8xf32>)
return %390, %391, %392 : tensor<1x2x2x3xf32>, tensor<1x2x3x2xf32>, tensor<1x3x8xf32>
}
}