77from benchmark .performance_utils import Benchmark , generate_tensor_input
88
99
10+ def _polar_baseline (abs , angle ):
11+ if abs .dtype == torch .bfloat16 :
12+ return torch .polar (abs .to (torch .float32 ), angle .to (torch .float32 ))
13+ return torch .polar (abs , angle )
14+
15+
16+ def _bitwise_or_baseline (a , b ):
17+ if a .dtype == torch .bfloat16 :
18+ return torch .bitwise_or (a .view (torch .int16 ), b .view (torch .int16 )).view (
19+ torch .bfloat16
20+ )
21+ return torch .bitwise_or (a , b )
22+
23+
24+ def _bitwise_or_inplace_baseline (a , b ):
25+ if a .dtype == torch .bfloat16 :
26+ a .view (torch .int16 ).bitwise_or_ (b .view (torch .int16 ))
27+ return a
28+ return a .bitwise_or_ (b )
29+
30+
1031class BinaryPointwiseBenchmark (Benchmark ):
1132 """
1233 Base class for benchmarking binary pointwise operations.
@@ -47,11 +68,11 @@ def get_tflops(self, op, *args, **kwargs):
4768 ("mul" , torch .mul , FLOAT_DTYPES ),
4869 ("sub" , torch .sub , FLOAT_DTYPES ),
4970 ("pow" , torch .pow , FLOAT_DTYPES ),
50- ("polar" , torch . polar , [torch .float32 ]),
71+ ("polar" , _polar_baseline , [torch .float32 , torch . bfloat16 ]),
5172 ("floor_divide" , torch .floor_divide , INT_DTYPES ),
5273 ("remainder" , torch .remainder , INT_DTYPES ),
5374 ("logical_or" , torch .logical_or , INT_DTYPES + BOOL_DTYPES ),
54- ("logical_and" , torch .logical_and , INT_DTYPES + BOOL_DTYPES ),
75+ ("logical_and" , torch .logical_and , FLOAT_DTYPES + INT_DTYPES + BOOL_DTYPES ),
5576 ("logical_xor" , torch .logical_xor , INT_DTYPES + BOOL_DTYPES ),
5677 # Comparison operations
5778 ("eq" , torch .eq , FLOAT_DTYPES ),
@@ -66,7 +87,7 @@ def get_tflops(self, op, *args, **kwargs):
6687 ("minimum" , torch .minimum , FLOAT_DTYPES ),
6788 # Bitwise operations
6889 ("bitwise_and" , torch .bitwise_and , INT_DTYPES + BOOL_DTYPES ),
69- ("bitwise_or" , torch . bitwise_or , INT_DTYPES + BOOL_DTYPES ),
90+ ("bitwise_or" , _bitwise_or_baseline , INT_DTYPES + BOOL_DTYPES + [ torch . bfloat16 ] ),
7091 # Numerical Checks
7192 ("isclose" , torch .isclose , FLOAT_DTYPES + INT_DTYPES ),
7293 ("allclose" , torch .allclose , FLOAT_DTYPES + INT_DTYPES ),
@@ -97,10 +118,10 @@ def test_general_binary_pointwise_perf(op_name, torch_op, dtypes):
97118 ("floor_divide_" , lambda a , b : a .floor_divide_ (b ), INT_DTYPES ),
98119 ("remainder_" , lambda a , b : a .remainder_ (b ), INT_DTYPES ),
99120 ("logical_or_" , lambda a , b : a .logical_or_ (b ), INT_DTYPES + BOOL_DTYPES ),
100- ("logical_and_" , lambda a , b : a .logical_and_ (b ), INT_DTYPES + BOOL_DTYPES ),
121+ ("logical_and_" , lambda a , b : a .logical_and_ (b ), FLOAT_DTYPES + INT_DTYPES + BOOL_DTYPES ),
101122 # Bitwise operations
102123 ("bitwise_and_" , lambda a , b : a .bitwise_and_ (b ), INT_DTYPES + BOOL_DTYPES ),
103- ("bitwise_or_" , lambda a , b : a . bitwise_or_ ( b ), INT_DTYPES + BOOL_DTYPES ),
124+ ("bitwise_or_" , _bitwise_or_inplace_baseline , INT_DTYPES + BOOL_DTYPES + [ torch . bfloat16 ] ),
104125 ]
105126 ],
106127)
0 commit comments