File size: 3,547 Bytes
8c1fe04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module {
  tt.func public @triton__0d1d2d3d4de5de(%arg0: !tt.ptr<f32, 1> {tt.divisibility = 16 : i32}, %arg1: !tt.ptr<bf16, 1> {tt.divisibility = 16 : i32}, %arg2: !tt.ptr<f32, 1> {tt.divisibility = 16 : i32}, %arg3: !tt.ptr<bf16, 1> {tt.divisibility = 16 : i32}, %arg4: i32 {tt.divisibility = 16 : i32, tt.max_divisibility = 16 : i32}, %arg5: i32 {tt.divisibility = 16 : i32, tt.max_divisibility = 16 : i32}) attributes {noinline = false} {
    %c256_i32 = arith.constant 256 : i32
    %cst = arith.constant dense<0.000000e+00> : tensor<256xbf16>
    %cst_0 = arith.constant 0.000000e+00 : f32
    %cst_1 = arith.constant 2.560000e+02 : f32
    %cst_2 = arith.constant 9.99999974E-6 : f32
    %cst_3 = arith.constant dense<0.000000e+00> : tensor<256xf32>
    %cst_4 = arith.constant dense<256> : tensor<256xi32>
    %0 = tt.get_program_id x : i32
    %1 = tt.make_range {end = 256 : i32, start = 0 : i32} : tensor<256xi32>
    %2 = arith.cmpi slt, %1, %cst_4 : tensor<256xi32>
    %3 = arith.muli %0, %c256_i32 : i32
    %4 = tt.splat %3 : (i32) -> tensor<256xi32>
    %5 = arith.addi %1, %4 : tensor<256xi32>
    %6 = tt.splat %arg0 : (!tt.ptr<f32, 1>) -> tensor<256x!tt.ptr<f32, 1>>
    %7 = tt.addptr %6, %5 : tensor<256x!tt.ptr<f32, 1>>, tensor<256xi32>
    %8 = tt.load %7, %2, %cst_3 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : tensor<256xf32>
    %9 = tt.splat %arg1 : (!tt.ptr<bf16, 1>) -> tensor<256x!tt.ptr<bf16, 1>>
    %10 = tt.addptr %9, %5 : tensor<256x!tt.ptr<bf16, 1>>, tensor<256xi32>
    %11 = tt.load %10, %2, %cst {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : tensor<256xbf16>
    %12 = arith.extf %11 : tensor<256xbf16> to tensor<256xf32>
    %13 = tt.splat %arg2 : (!tt.ptr<f32, 1>) -> tensor<256x!tt.ptr<f32, 1>>
    %14 = tt.addptr %13, %1 : tensor<256x!tt.ptr<f32, 1>>, tensor<256xi32>
    %15 = tt.load %14, %2, %cst_3 {cache = 1 : i32, evict = 3 : i32, isVolatile = false} : tensor<256xf32>
    %16 = arith.addf %8, %12 : tensor<256xf32>
    %17 = arith.select %2, %16, %cst_3 : tensor<256xi1>, tensor<256xf32>
    %18 = "tt.reduce"(%17) <{axis = 0 : i32}> ({
    ^bb0(%arg6: f32, %arg7: f32):
      %36 = arith.addf %arg6, %arg7 : f32
      tt.reduce.return %36 : f32
    }) : (tensor<256xf32>) -> f32
    %19 = arith.addf %18, %cst_0 : f32
    %20 = arith.divf %19, %cst_1 : f32
    %21 = tt.splat %20 : (f32) -> tensor<256xf32>
    %22 = arith.subf %16, %21 : tensor<256xf32>
    %23 = arith.mulf %22, %22 : tensor<256xf32>
    %24 = arith.select %2, %23, %cst_3 : tensor<256xi1>, tensor<256xf32>
    %25 = "tt.reduce"(%24) <{axis = 0 : i32}> ({
    ^bb0(%arg6: f32, %arg7: f32):
      %36 = arith.addf %arg6, %arg7 : f32
      tt.reduce.return %36 : f32
    }) : (tensor<256xf32>) -> f32
    %26 = arith.addf %25, %cst_0 : f32
    %27 = arith.divf %26, %cst_1 : f32
    %28 = arith.addf %27, %cst_2 : f32
    %29 = tt.extern_elementwise %28 {libname = "libdevice", libpath = "/usr/local/lib/python3.10/dist-packages/triton/language/../third_party/cuda/lib/libdevice.10.bc", pure = true, symbol = "__nv_rsqrtf"} : (f32) -> f32
    %30 = tt.splat %29 : (f32) -> tensor<256xf32>
    %31 = arith.mulf %22, %30 : tensor<256xf32>
    %32 = arith.mulf %31, %15 : tensor<256xf32>
    %33 = tt.splat %arg3 : (!tt.ptr<bf16, 1>) -> tensor<256x!tt.ptr<bf16, 1>>
    %34 = tt.addptr %33, %5 : tensor<256x!tt.ptr<bf16, 1>>, tensor<256xi32>
    %35 = arith.truncf %32 : tensor<256xf32> to tensor<256xbf16>
    tt.store %34, %35, %2 {cache = 1 : i32, evict = 1 : i32} : tensor<256xbf16>
    tt.return
  }
}