File size: 5,769 Bytes
afafe68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
module {
  tt.func public @triton__0d1d2d3d4d5d6d7de8(%arg0: !tt.ptr<f32, 1> {tt.divisibility = 16 : i32}, %arg1: !tt.ptr<i64, 1> {tt.divisibility = 16 : i32}, %arg2: !tt.ptr<f32, 1> {tt.divisibility = 16 : i32}, %arg3: !tt.ptr<f32, 1> {tt.divisibility = 16 : i32}, %arg4: !tt.ptr<bf16, 1> {tt.divisibility = 16 : i32}, %arg5: !tt.ptr<bf16, 1> {tt.divisibility = 16 : i32}, %arg6: !tt.ptr<bf16, 1> {tt.divisibility = 16 : i32}, %arg7: i64 {tt.divisibility = 16 : i32, tt.max_divisibility = 16 : i32}, %arg8: i64) attributes {noinline = false} {
    %cst = arith.constant dense<0.000000e+00> : tensor<1x2048xbf16>
    %cst_0 = arith.constant dense<0.000000e+00> : tensor<1x1xf32>
    %c50257_i64 = arith.constant 50257 : i64
    %c50257_i32 = arith.constant 50257 : i32
    %c2048_i32 = arith.constant 2048 : i32
    %c0_i32 = arith.constant 0 : i32
    %cst_1 = arith.constant dense<50257> : tensor<1x2048xi64>
    %cst_2 = arith.constant dense<-1> : tensor<1x1xi64>
    %cst_3 = arith.constant dense<0.000000e+00> : tensor<1x2048xf32>
    %0 = tt.get_program_id x : i32
    %1 = arith.extsi %0 : i32 to i64
    %2 = tt.make_range {end = 2048 : i32, start = 0 : i32} : tensor<2048xi32>
    %3 = tt.expand_dims %2 {axis = 0 : i32} : (tensor<2048xi32>) -> tensor<1x2048xi32>
    %4 = arith.extsi %3 : tensor<1x2048xi32> to tensor<1x2048xi64>
    %5 = tt.addptr %arg1, %1 : !tt.ptr<i64, 1>, i64
    %6 = tt.splat %5 : (!tt.ptr<i64, 1>) -> tensor<1x1x!tt.ptr<i64, 1>>
    %7 = tt.load %6 {cache = 1 : i32, evict = 3 : i32, isVolatile = false} : tensor<1x1xi64>
    %8 = tt.addptr %arg2, %c0_i32 : !tt.ptr<f32, 1>, i32
    %9 = tt.load %8 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : f32
    %10 = tt.addptr %arg3, %c0_i32 : !tt.ptr<f32, 1>, i32
    %11 = tt.load %10 {cache = 1 : i32, evict = 1 : i32, isVolatile = false} : f32
    %12 = arith.muli %1, %c50257_i64 : i64
    %13 = tt.splat %12 : (i64) -> tensor<1x2048xi64>
    %14 = tt.splat %arg0 : (!tt.ptr<f32, 1>) -> tensor<1x2048x!tt.ptr<f32, 1>>
    %15 = arith.cmpi ne, %7, %cst_2 : tensor<1x1xi64>
    %16 = arith.divf %9, %11 : f32
    %17 = tt.splat %16 : (f32) -> tensor<1x1xf32>
    %18 = arith.select %15, %17, %cst_0 : tensor<1x1xi1>, tensor<1x1xf32>
    %19 = tt.broadcast %18 : (tensor<1x1xf32>) -> tensor<1x2048xf32>
    %20 = scf.for %arg9 = %c0_i32 to %c50257_i32 step %c2048_i32 iter_args(%arg10 = %cst_3) -> (tensor<1x2048xf32>)  : i32 {
      %35 = arith.extsi %arg9 : i32 to i64
      %36 = tt.splat %35 : (i64) -> tensor<1x2048xi64>
      %37 = arith.addi %36, %4 : tensor<1x2048xi64>
      %38 = arith.cmpi slt, %37, %cst_1 : tensor<1x2048xi64>
      %39 = arith.addi %37, %13 : tensor<1x2048xi64>
      %40 = tt.addptr %14, %39 : tensor<1x2048x!tt.ptr<f32, 1>>, tensor<1x2048xi64>
      %41 = tt.load %40, %38, %cst_3 {cache = 1 : i32, evict = 3 : i32, isVolatile = false} : tensor<1x2048xf32>
      %42 = arith.mulf %41, %19 : tensor<1x2048xf32>
      %43 = arith.addf %arg10, %42 : tensor<1x2048xf32>
      %44 = arith.select %38, %43, %arg10 : tensor<1x2048xi1>, tensor<1x2048xf32>
      scf.yield %44 : tensor<1x2048xf32>
    }
    %21 = "tt.reduce"(%20) <{axis = 1 : i32}> ({
    ^bb0(%arg9: f32, %arg10: f32):
      %35 = arith.addf %arg9, %arg10 : f32
      tt.reduce.return %35 : f32
    }) : (tensor<1x2048xf32>) -> tensor<1xf32>
    %22 = tt.expand_dims %21 {axis = 1 : i32} : (tensor<1xf32>) -> tensor<1x1xf32>
    %23 = arith.muli %1, %c50257_i64 : i64
    %24 = tt.splat %23 : (i64) -> tensor<1x2048xi64>
    %25 = tt.splat %arg4 : (!tt.ptr<bf16, 1>) -> tensor<1x2048x!tt.ptr<bf16, 1>>
    %26 = tt.splat %arg0 : (!tt.ptr<f32, 1>) -> tensor<1x2048x!tt.ptr<f32, 1>>
    %27 = tt.splat %arg5 : (!tt.ptr<bf16, 1>) -> tensor<1x2048x!tt.ptr<bf16, 1>>
    %28 = arith.cmpi ne, %7, %cst_2 : tensor<1x1xi64>
    %29 = arith.divf %9, %11 : f32
    %30 = tt.splat %29 : (f32) -> tensor<1x1xf32>
    %31 = arith.select %28, %30, %cst_0 : tensor<1x1xi1>, tensor<1x1xf32>
    %32 = tt.broadcast %31 : (tensor<1x1xf32>) -> tensor<1x2048xf32>
    %33 = tt.broadcast %22 : (tensor<1x1xf32>) -> tensor<1x2048xf32>
    %34 = tt.splat %arg6 : (!tt.ptr<bf16, 1>) -> tensor<1x2048x!tt.ptr<bf16, 1>>
    scf.for %arg9 = %c0_i32 to %c50257_i32 step %c2048_i32  : i32 {
      %35 = arith.extsi %arg9 : i32 to i64
      %36 = tt.splat %35 : (i64) -> tensor<1x2048xi64>
      %37 = arith.addi %36, %4 : tensor<1x2048xi64>
      %38 = arith.cmpi slt, %37, %cst_1 : tensor<1x2048xi64>
      %39 = arith.addi %37, %24 : tensor<1x2048xi64>
      %40 = tt.addptr %25, %39 : tensor<1x2048x!tt.ptr<bf16, 1>>, tensor<1x2048xi64>
      %41 = tt.load %40, %38, %cst {cache = 1 : i32, evict = 2 : i32, isVolatile = false} : tensor<1x2048xbf16>
      %42 = arith.extf %41 : tensor<1x2048xbf16> to tensor<1x2048xf32>
      %43 = tt.addptr %26, %39 : tensor<1x2048x!tt.ptr<f32, 1>>, tensor<1x2048xi64>
      %44 = tt.load %43, %38, %cst_3 {cache = 1 : i32, evict = 2 : i32, isVolatile = false} : tensor<1x2048xf32>
      %45 = tt.addptr %27, %39 : tensor<1x2048x!tt.ptr<bf16, 1>>, tensor<1x2048xi64>
      %46 = tt.load %45, %38, %cst {cache = 1 : i32, evict = 2 : i32, isVolatile = false} : tensor<1x2048xbf16>
      %47 = arith.extf %46 : tensor<1x2048xbf16> to tensor<1x2048xf32>
      %48 = arith.mulf %44, %32 : tensor<1x2048xf32>
      %49 = math.exp %47 : tensor<1x2048xf32>
      %50 = arith.mulf %49, %33 : tensor<1x2048xf32>
      %51 = arith.subf %48, %50 : tensor<1x2048xf32>
      %52 = arith.addf %42, %51 : tensor<1x2048xf32>
      %53 = tt.addptr %34, %39 : tensor<1x2048x!tt.ptr<bf16, 1>>, tensor<1x2048xi64>
      %54 = arith.truncf %52 : tensor<1x2048xf32> to tensor<1x2048xbf16>
      tt.store %53, %54, %38 {cache = 1 : i32, evict = 1 : i32} : tensor<1x2048xbf16>
    }
    tt.return
  }
}