Skip to content

Commit 3719228

Browse files
ssjiaSS-JIA
authored andcommitted
[ET-VK][ops] Add bitwise_or / logical_or operators
Pull Request resolved: #20382 Adds Vulkan support for `aten.bitwise_or.Tensor` and `aten.logical_or.default`, mirroring the existing `bitwise_and` / `logical_and` implementation. This is the first of two ops needed to collapse the Llama4-mini TISO en_US backbone export to a single Vulkan partition: the discrete-speech mask OR-s several bool tensors via `bitwise_or`, which previously had no Vulkan implementation and forced a CPU fallback that split the delegated graph. Implementation mirrors `bitwise_and`: a `X | Y` uint8 shader variant in `binary_op_buffer.yaml` / `binary_op_texture.yaml`, a `DEFINE_BINARY_OP_FN(bitwise_or)` dispatch with `VK_REGISTER_OP` for both `aten.bitwise_or.Tensor` and `aten.logical_or.default` in `BinaryOp.cpp`, and `register_bitwise_or` / `register_logical_or` `OpFeatures` (bool inputs) in `op_registry.py`. This change was authored with Claude. ghstack-source-id: 397529322 @exported-using-ghexport Differential Revision: [D108457794](https://our.internmc.facebook.com/intern/diff/D108457794/)
1 parent 0f3303f commit 3719228

5 files changed

Lines changed: 29 additions & 25 deletions

File tree

backends/vulkan/op_registry.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -294,28 +294,16 @@ def register_comparison_ops():
294294
# =============================================================================
295295

296296

297-
@update_features(exir_ops.edge.aten.bitwise_and.Tensor)
298-
def register_bitwise_and():
299-
return OpFeatures(
300-
inputs_storage=utils.ANY_STORAGE,
301-
inputs_dtypes=utils.BOOL_T,
302-
supports_resize=True,
303-
supports_highdim=True,
304-
)
305-
306-
307-
@update_features(exir_ops.edge.aten.bitwise_not.default)
308-
def register_bitwise_not():
309-
return OpFeatures(
310-
inputs_storage=utils.ANY_STORAGE,
311-
inputs_dtypes=utils.BOOL_T,
312-
supports_resize=True,
313-
supports_highdim=True,
314-
)
315-
316-
317-
@update_features(exir_ops.edge.aten.logical_and.default)
318-
def register_logical_and():
297+
@update_features(
298+
[
299+
exir_ops.edge.aten.bitwise_and.Tensor,
300+
exir_ops.edge.aten.bitwise_or.Tensor,
301+
exir_ops.edge.aten.bitwise_not.default,
302+
exir_ops.edge.aten.logical_and.default,
303+
exir_ops.edge.aten.logical_or.default,
304+
]
305+
)
306+
def register_bool_binary_ops():
319307
return OpFeatures(
320308
inputs_storage=utils.ANY_STORAGE,
321309
inputs_dtypes=utils.BOOL_T,

backends/vulkan/runtime/graph/ops/glsl/binary_op_buffer.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ binary_op_buffer:
5252
generate_variant_forall:
5353
DTYPE:
5454
- VALUE: uint8
55+
- NAME: binary_bitwise_or_buffer
56+
OPERATOR: X | Y
57+
generate_variant_forall:
58+
DTYPE:
59+
- VALUE: uint8

backends/vulkan/runtime/graph/ops/glsl/binary_op_texture.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ binary_op_texture:
5454
generate_variant_forall:
5555
DTYPE:
5656
- VALUE: uint8
57+
- NAME: binary_bitwise_or_texture3d
58+
OPERATOR: X | Y
59+
generate_variant_forall:
60+
DTYPE:
61+
- VALUE: uint8

backends/vulkan/runtime/graph/ops/impl/BinaryOp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ DEFINE_BINARY_OP_FN(le);
143143
DEFINE_BINARY_OP_FN(gt);
144144
DEFINE_BINARY_OP_FN(ge);
145145
DEFINE_BINARY_OP_FN(bitwise_and);
146+
DEFINE_BINARY_OP_FN(bitwise_or);
146147

147148
REGISTER_OPERATORS {
148149
VK_REGISTER_OP(aten.add.Tensor, add);
@@ -159,6 +160,8 @@ REGISTER_OPERATORS {
159160
VK_REGISTER_OP(aten.ge.Tensor, ge);
160161
VK_REGISTER_OP(aten.bitwise_and.Tensor, bitwise_and);
161162
VK_REGISTER_OP(aten.logical_and.default, bitwise_and);
163+
VK_REGISTER_OP(aten.bitwise_or.Tensor, bitwise_or);
164+
VK_REGISTER_OP(aten.logical_or.default, bitwise_or);
162165
}
163166

164167
} // namespace vkcompute

backends/vulkan/test/op_tests/cases.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,14 +2141,18 @@ def get_where_inputs():
21412141
return test_suite
21422142

21432143

2144-
@register_test_suite("aten.bitwise_and.Tensor")
2145-
def get_bitwise_and_inputs():
2144+
@register_test_suite(
2145+
["aten.bitwise_and.Tensor", "aten.bitwise_or.Tensor", "aten.logical_or.default"]
2146+
)
2147+
def get_bitwise_binary_inputs():
21462148
test_suite = VkTestSuite(
21472149
[
21482150
((M1, M2), (M1, M2)),
21492151
((S, S1, S2), (S, S1, S2)),
21502152
((XS, S, S1, S2), (XS, S, S1, S2)),
21512153
((1, M1), (1, M1)),
2154+
((1, M2), (M1, M2)),
2155+
((XS, 1, S1, 1), (1, S, 1, S2)),
21522156
]
21532157
)
21542158
test_suite.layouts = [
@@ -2160,7 +2164,6 @@ def get_bitwise_and_inputs():
21602164
"utils::kTexture3D",
21612165
]
21622166
test_suite.dtypes = ["at::kBool"]
2163-
test_suite.data_gen = "make_seq_tensor"
21642167
return test_suite
21652168

21662169

0 commit comments

Comments
 (0)