@@ -97,6 +97,69 @@ func.func @sdpa_scale_dynamic_head_dim(%query: !torch.vtensor<[1,4,8,?],f32>, %k
9797
9898// -----
9999
100+ // CHECK: #map = affine_map<(d0, d1, d2) -> (0, d1, d2)>
101+ // CHECK: #map1 = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
102+ // CHECK-LABEL: @sdpa_bool_mask_key_seq_dynamic
103+ // CHECK: %[[MASK_IN:.*]] = torch_c.to_builtin_tensor %arg3 : !torch.vtensor<[1,1,?],i1> -> tensor<1x1x?xi1>
104+ // CHECK: %[[KEY:.*]] = torch_c.to_builtin_tensor %arg1 : !torch.vtensor<[16,?,128],f16> -> tensor<16x?x128xf16>
105+ // CHECK: %[[C1:.*]] = arith.constant 1 : index
106+ // CHECK: %[[KEY_SEQ:.*]] = tensor.dim %[[KEY]], %[[C1]] : tensor<16x?x128xf16>
107+ // CHECK: %[[EMPTY_MASK:.*]] = tensor.empty(%[[KEY_SEQ]]) : tensor<16x1x?xi1>
108+ // CHECK: %[[BCAST_MASK:.*]] = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]} ins(%[[MASK_IN]] : tensor<1x1x?xi1>) outs(%[[EMPTY_MASK]] : tensor<16x1x?xi1>)
109+ // CHECK: tm_tensor.attention ins(%{{.*}}, %{{.*}}, %{{.*}}, %[[BCAST_MASK]] : tensor<16x1x128xf16>, tensor<16x?x128xf16>, tensor<16x?x128xf16>, tensor<16x1x?xi1>)
110+ func.func @sdpa_bool_mask_key_seq_dynamic (%query: !torch.vtensor <[16 ,1 ,128 ],f16 >, %key: !torch.vtensor <[16 ,?,128 ],f16 >, %value: !torch.vtensor <[16 ,?,128 ],f16 >, %mask: !torch.vtensor <[1 ,1 ,?],i1 >) -> !torch.vtensor <[16 ,1 ,128 ],f16 > {
111+ %float0 = torch.constant.float 0.000000e+00
112+ %false = torch.constant.bool false
113+ %none = torch.constant.none
114+ %0 = torch.aten.scaled_dot_product_attention %query , %key , %value , %mask , %float0 , %false , %none , %false : !torch.vtensor <[16 ,1 ,128 ],f16 >, !torch.vtensor <[16 ,?,128 ],f16 >, !torch.vtensor <[16 ,?,128 ],f16 >, !torch.vtensor <[1 ,1 ,?],i1 >, !torch.float , !torch.bool , !torch.none , !torch.bool -> !torch.vtensor <[16 ,1 ,128 ],f16 >
115+ return %0 : !torch.vtensor <[16 ,1 ,128 ],f16 >
116+ }
117+
118+ // -----
119+
120+ // CHECK: #map = affine_map<(d0, d1, d2) -> (0, d1, d2)>
121+ // CHECK: #map1 = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
122+ // CHECK-LABEL: @sdpa_bool_mask_both_seq_dynamic
123+ // CHECK: %[[MASK_IN:.*]] = torch_c.to_builtin_tensor %arg3 : !torch.vtensor<[1,?,?],i1> -> tensor<1x?x?xi1>
124+ // CHECK: %[[KEY:.*]] = torch_c.to_builtin_tensor %arg1 : !torch.vtensor<[16,?,128],f16> -> tensor<16x?x128xf16>
125+ // CHECK: %[[QUERY:.*]] = torch_c.to_builtin_tensor %arg0 : !torch.vtensor<[16,?,128],f16> -> tensor<16x?x128xf16>
126+ // CHECK: %[[C1_A:.*]] = arith.constant 1 : index
127+ // CHECK: %[[QSEQ:.*]] = tensor.dim %[[QUERY]], %[[C1_A]] : tensor<16x?x128xf16>
128+ // CHECK: %[[C1_B:.*]] = arith.constant 1 : index
129+ // CHECK: %[[KSEQ:.*]] = tensor.dim %[[KEY]], %[[C1_B]] : tensor<16x?x128xf16>
130+ // CHECK: %[[EMPTY_MASK:.*]] = tensor.empty(%[[QSEQ]], %[[KSEQ]]) : tensor<16x?x?xi1>
131+ // CHECK: %[[BCAST_MASK:.*]] = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]} ins(%[[MASK_IN]] : tensor<1x?x?xi1>) outs(%[[EMPTY_MASK]] : tensor<16x?x?xi1>)
132+ // CHECK: tm_tensor.attention ins(%{{.*}}, %{{.*}}, %{{.*}}, %[[BCAST_MASK]] : tensor<16x?x128xf16>, tensor<16x?x128xf16>, tensor<16x?x128xf16>, tensor<16x?x?xi1>)
133+ func.func @sdpa_bool_mask_both_seq_dynamic (%query: !torch.vtensor <[16 ,?,128 ],f16 >, %key: !torch.vtensor <[16 ,?,128 ],f16 >, %value: !torch.vtensor <[16 ,?,128 ],f16 >, %mask: !torch.vtensor <[1 ,?,?],i1 >) -> !torch.vtensor <[16 ,?,128 ],f16 > {
134+ %float0 = torch.constant.float 0.000000e+00
135+ %false = torch.constant.bool false
136+ %none = torch.constant.none
137+ %0 = torch.aten.scaled_dot_product_attention %query , %key , %value , %mask , %float0 , %false , %none , %false : !torch.vtensor <[16 ,?,128 ],f16 >, !torch.vtensor <[16 ,?,128 ],f16 >, !torch.vtensor <[16 ,?,128 ],f16 >, !torch.vtensor <[1 ,?,?],i1 >, !torch.float , !torch.bool , !torch.none , !torch.bool -> !torch.vtensor <[16 ,?,128 ],f16 >
138+ return %0 : !torch.vtensor <[16 ,?,128 ],f16 >
139+ }
140+
141+ // -----
142+
143+ // CHECK: #map = affine_map<(d0, d1, d2, d3) -> (d0, 0, d2, 0)>
144+ // CHECK-LABEL: @sdpa_bool_mask_4d_static_ones
145+ // CHECK: %[[MASK_IN:.*]] = torch_c.to_builtin_tensor %arg3 : !torch.vtensor<[1,1,1,1],i1> -> tensor<1x1x1x1xi1>
146+ // CHECK: %[[KEY:.*]] = torch_c.to_builtin_tensor %arg1 : !torch.vtensor<[1,16,?,128],f16> -> tensor<1x16x?x128xf16>
147+ // CHECK: %[[C2:.*]] = arith.constant 2 : index
148+ // CHECK: %[[KSEQ:.*]] = tensor.dim %[[KEY]], %[[C2]] : tensor<1x16x?x128xf16>
149+ // CHECK: %[[EMPTY_MASK:.*]] = tensor.empty(%[[KSEQ]]) : tensor<1x16x1x?xi1>
150+ // CHECK: %[[BCAST_MASK:.*]] = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%[[MASK_IN]] : tensor<1x1x1x1xi1>) outs(%[[EMPTY_MASK]] : tensor<1x16x1x?xi1>)
151+ // CHECK: %[[COLLAPSED_MASK:.*]] = tensor.collapse_shape %[[BCAST_MASK]] {{.*}} : tensor<1x16x1x?xi1> into tensor<16x1x?xi1>
152+ // CHECK: tm_tensor.attention ins(%{{.*}}, %{{.*}}, %{{.*}}, %[[COLLAPSED_MASK]] : tensor<16x1x128xf16>, tensor<16x?x128xf16>, tensor<16x?x128xf16>, tensor<16x1x?xi1>)
153+ func.func @sdpa_bool_mask_4d_static_ones (%query: !torch.vtensor <[1 ,16 ,1 ,128 ],f16 >, %key: !torch.vtensor <[1 ,16 ,?,128 ],f16 >, %value: !torch.vtensor <[1 ,16 ,?,128 ],f16 >, %mask: !torch.vtensor <[1 ,1 ,1 ,1 ],i1 >) -> !torch.vtensor <[1 ,16 ,1 ,128 ],f16 > {
154+ %float0 = torch.constant.float 0.000000e+00
155+ %false = torch.constant.bool false
156+ %none = torch.constant.none
157+ %0 = torch.aten.scaled_dot_product_attention %query , %key , %value , %mask , %float0 , %false , %none , %false : !torch.vtensor <[1 ,16 ,1 ,128 ],f16 >, !torch.vtensor <[1 ,16 ,?,128 ],f16 >, !torch.vtensor <[1 ,16 ,?,128 ],f16 >, !torch.vtensor <[1 ,1 ,1 ,1 ],i1 >, !torch.float , !torch.bool , !torch.none , !torch.bool -> !torch.vtensor <[1 ,16 ,1 ,128 ],f16 >
158+ return %0 : !torch.vtensor <[1 ,16 ,1 ,128 ],f16 >
159+ }
160+
161+ // -----
162+
100163// CHECK-LABEL: @scatter_src_i64_index
101164// CHECK: tm_tensor.scatter {dimension_map = array<i64: 0, 1, 2>} unique_indices(false) ins(%{{.*}}, %{{.*}} : tensor<?xf32>, tensor<?x3xi64>) outs(%{{.*}} : tensor<10x8x6xf32>) {
102165// CHECK: ^bb0(%arg3: f32, %arg4: f32):
0 commit comments