counted-float 0.9.6__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {counted_float-0.9.6 → counted_float-1.0.0}/PKG-INFO +128 -92
- {counted_float-0.9.6 → counted_float-1.0.0}/README.md +127 -91
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/_cli.py +7 -1
- counted_float-1.0.0/counted_float/_core/benchmarking/__init__.py +37 -0
- counted_float-1.0.0/counted_float/_core/benchmarking/counted_float/__init__.py +1 -0
- counted_float-1.0.0/counted_float/_core/benchmarking/counted_float/_counted_float_benchmark.py +83 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/benchmarking/micro/_micro_benchmark.py +2 -2
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/_builtin_data.py +12 -7
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/config/_defaults.py +13 -8
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_flop_weights.py +20 -8
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/utils/__init__.py +1 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/utils/_missing_data.py +1 -5
- counted_float-1.0.0/counted_float/_core/utils/_rounding.py +66 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/benchmarking/__init__.py +2 -1
- {counted_float-0.9.6 → counted_float-1.0.0}/pyproject.toml +1 -1
- counted_float-0.9.6/counted_float/_core/benchmarking/__init__.py +0 -11
- {counted_float-0.9.6 → counted_float-1.0.0}/.gitignore +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/LICENSE +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/_array_generator.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/_flops_benchmark_suite.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/benchmarking/flops/_flops_micro_benchmark.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/benchmarking/micro/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/compatibility/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/compatibility/_numba.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/_context_managers.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/_counted_float.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/_global_counter.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/config/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/counting/config/_config.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_base.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_flop_counts.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_flop_type.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_flops_benchmark_meta_data.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_flops_benchmark_result.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_flops_benchmark_type.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_instruction_latencies.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/models/_micro_benchmark_result.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/utils/_cpu_freq.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/utils/_formatting.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/utils/_geo_mean.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/utils/_latency.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/_core/utils/_timer.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/config/__init__.py +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/apple_m3_max_mbp16.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/apple_m3_mba15.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/ec2_m6g_xlarge_graviton_2_neoverse_n1.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/ec2_m7g_xlarge_graviton_3_neoverse_v1.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/benchmarks/gh_apple_m1.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v8_cortex_a76.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v9_cortex_x1.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v9_neoverse_n1.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v8_x/specs/arm_v9_neoverse_v1.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_0/benchmarks/ec2_m8g_xlarge_graviton_4_neoverse_v2.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_0/benchmarks/gh_azure_cobalt_100_neoverse_n2.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_cortex_x2.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_cortex_x3.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_neoverse_n2.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_0/specs/arm_v9_neoverse_v2.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_2/benchmarks/apple_m4_pro_mbp16.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_2/specs/arm_v9_cortex_x4.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_2/specs/arm_v9_cortex_x925.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/arm/v9_2/specs/arm_v9_neoverse_v3.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2017_zen1/analysis_uops_info_zen1+.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2017_zen1/benchmark_ryzen_1700x.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/analysis_agner_fog_r7_5800x.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/analysis_uops_info_zen3.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/benchmark_gh_amd_epyc_7763_linux.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2020_zen3/benchmark_gh_amd_epyc_7763_windows.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/analysis_agner_fog_r9_7900x.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/analysis_uops_info_zen4.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/benchmark_ec2_m7a_xlarge_zen4.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2022_zen4/specs_amd.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2024_zen5/analysis_agner_fog_r7_9800x3d.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2024_zen5/benchmark_ec2_m8a_xlarge_zen5.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/amd/2024_zen5/specs_amd.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2017_coffee_lake_gen_8/analysis_agner_fog_coffee_lake.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2017_coffee_lake_gen_8/analysis_uops_info_coffee_lake.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2017_coffee_lake_gen_8/benchmark_gh_intel_i7_8700B_macos.json +0 -0
- /counted_float-0.9.6/counted_float/data/x86/intel/2017_coffee_lake_gen_8/benchmark_gh_intel_i7_8550U_windows.json → /counted_float-1.0.0/counted_float/data/x86/intel/2017_coffee_lake_gen_8/benchmark_intel_i7_8550U_windows.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_agner_fog_ice_lake.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_uops_info_ice_lake.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_uops_info_tiger_lake.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2019_sunny_cove_gen_10/benchmark_ec2_m6i_xlarge_ice_lake.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2021_golden_cove_gen_12/analysis_uops_info_alder_lake_p.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2021_golden_cove_gen_12/benchmark_ec2_m7i_xlarge_sapphire_rapids.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2021_golden_cove_gen_12/specs_intel.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2022_raptor_cove_gen_13_14/benchmark_ec2_i7i_xlarge_emerald_rapids.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2022_raptor_cove_gen_13_14/specs_intel.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2023_redwood_cove_ultra_1/benchmark_ec2_m8i_xlarge_granite_rapids.json +0 -0
- {counted_float-0.9.6 → counted_float-1.0.0}/counted_float/data/x86/intel/2023_redwood_cove_ultra_1/specs_intel.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: counted-float
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Count floating-point operations in Python code & benchmark relative flop costs.
|
|
5
5
|
Project-URL: Source, https://github.com/bertpl/counted-float
|
|
6
6
|
Project-URL: ChangeLog, https://github.com/bertpl/counted-float/blob/develop/CHANGELOG.md
|
|
@@ -21,9 +21,9 @@ Description-Content-Type: text/markdown
|
|
|
21
21
|
|
|
22
22
|
<!--START_SECTION:images-->
|
|
23
23
|

|
|
24
|
-

|
|
25
|
+

|
|
26
|
+

|
|
27
27
|
<!--END_SECTION:images-->
|
|
28
28
|
|
|
29
29
|
# counted-float
|
|
@@ -162,30 +162,33 @@ rationale behind choice of data sources and methodology.
|
|
|
162
162
|
>>> get_active_flop_weights().show()
|
|
163
163
|
|
|
164
164
|
{
|
|
165
|
-
FlopType.
|
|
166
|
-
FlopType.
|
|
167
|
-
FlopType.
|
|
168
|
-
FlopType.
|
|
169
|
-
FlopType.
|
|
170
|
-
FlopType.
|
|
171
|
-
FlopType.
|
|
172
|
-
FlopType.
|
|
173
|
-
FlopType.
|
|
174
|
-
FlopType.DIV [x/y] :
|
|
175
|
-
FlopType.SQRT [sqrt(x)] :
|
|
176
|
-
FlopType.
|
|
177
|
-
FlopType.EXP [e^x] :
|
|
178
|
-
FlopType.
|
|
179
|
-
FlopType.
|
|
180
|
-
FlopType.
|
|
181
|
-
FlopType.
|
|
182
|
-
FlopType.
|
|
183
|
-
FlopType.
|
|
184
|
-
FlopType.
|
|
185
|
-
FlopType.
|
|
186
|
-
FlopType.
|
|
165
|
+
FlopType.MINUS [-x] : 0.45000
|
|
166
|
+
FlopType.ABS [abs(x)] : 0.70000
|
|
167
|
+
FlopType.ADD [x+y] : 1.00000
|
|
168
|
+
FlopType.COMP [x<=y] : 1.00000
|
|
169
|
+
FlopType.SUB [x-y] : 1.00000
|
|
170
|
+
FlopType.MUL [x*y] : 1.40000
|
|
171
|
+
FlopType.RND [round] : 1.80000
|
|
172
|
+
FlopType.F2I [float->int] : 2.00000
|
|
173
|
+
FlopType.I2F [int->float] : 2.00000
|
|
174
|
+
FlopType.DIV [x/y] : 5.50000
|
|
175
|
+
FlopType.SQRT [sqrt(x)] : 7.50000
|
|
176
|
+
FlopType.EXP2 [2^x] : 16.00000
|
|
177
|
+
FlopType.EXP [e^x] : 18.00000
|
|
178
|
+
FlopType.LOG [log(x)] : 20.00000
|
|
179
|
+
FlopType.LOG2 [log2(x)] : 22.00000
|
|
180
|
+
FlopType.EXP10 [10^x] : 24.00000
|
|
181
|
+
FlopType.LOG10 [log10(x)] : 24.00000
|
|
182
|
+
FlopType.COS [cos(x)] : 30.00000
|
|
183
|
+
FlopType.SIN [sin(x)] : 30.00000
|
|
184
|
+
FlopType.POW [x^y] : 40.00000
|
|
185
|
+
FlopType.TAN [tan(x)] : 40.00000
|
|
186
|
+
FlopType.CBRT [cbrt(x)] : 45.00000
|
|
187
187
|
}
|
|
188
188
|
```
|
|
189
|
+
Note that these weights are rounded up to the ~10% closest semi-round number, reflecting a balance between accuracy and readability,
|
|
190
|
+
while conveying the message that these weights should be used as approximations only. See further down for the different rounding modes.
|
|
191
|
+
|
|
189
192
|
These weights will be used by default when extracting total weighted flop costs:
|
|
190
193
|
|
|
191
194
|
```python
|
|
@@ -202,7 +205,7 @@ with FlopCountingContext() as ctx:
|
|
|
202
205
|
_ = math.log2(cf2)
|
|
203
206
|
|
|
204
207
|
flop_counts = ctx.flop_counts()
|
|
205
|
-
total_cost = flop_counts.total_weighted_cost() # 1 +
|
|
208
|
+
total_cost = flop_counts.total_weighted_cost() # 1 + 40 + 22 = 63
|
|
206
209
|
```
|
|
207
210
|
Note that the `total_weighted_cost` method will use the default flop weights as returned by `get_flop_weights()`. This can be
|
|
208
211
|
overridden by either configuring different flop weights (see next section) or by setting the `weights` argument of the `total_weighted_cost()` method.
|
|
@@ -229,33 +232,38 @@ Built-in flop weights can be inspected using the following functions:
|
|
|
229
232
|
```python
|
|
230
233
|
from counted_float.config import get_default_consensus_flop_weights
|
|
231
234
|
|
|
232
|
-
>>> get_default_consensus_flop_weights(
|
|
235
|
+
>>> get_default_consensus_flop_weights(rounding_mode=None).show()
|
|
233
236
|
|
|
234
237
|
{
|
|
235
|
-
FlopType.
|
|
236
|
-
FlopType.
|
|
237
|
-
FlopType.COMP [x<=y] :
|
|
238
|
-
FlopType.
|
|
239
|
-
FlopType.F2I [float->int] : 1.99099
|
|
240
|
-
FlopType.I2F [int->float] : 1.84601
|
|
238
|
+
FlopType.MINUS [-x] : 0.46773
|
|
239
|
+
FlopType.ABS [abs(x)] : 0.70012
|
|
240
|
+
FlopType.COMP [x<=y] : 0.96923
|
|
241
|
+
FlopType.SUB [x-y] : 0.99846
|
|
241
242
|
FlopType.ADD [x+y] : 1.00000
|
|
242
|
-
FlopType.
|
|
243
|
-
FlopType.
|
|
244
|
-
FlopType.
|
|
245
|
-
FlopType.
|
|
246
|
-
FlopType.
|
|
247
|
-
FlopType.
|
|
248
|
-
FlopType.EXP2 [2^x] :
|
|
249
|
-
FlopType.
|
|
250
|
-
FlopType.LOG [log(x)] :
|
|
251
|
-
FlopType.LOG2 [log2(x)] :
|
|
252
|
-
FlopType.
|
|
253
|
-
FlopType.
|
|
254
|
-
FlopType.SIN [sin(x)] :
|
|
255
|
-
FlopType.COS [cos(x)] :
|
|
256
|
-
FlopType.
|
|
243
|
+
FlopType.MUL [x*y] : 1.39950
|
|
244
|
+
FlopType.RND [round] : 1.77232
|
|
245
|
+
FlopType.F2I [float->int] : 1.91485
|
|
246
|
+
FlopType.I2F [int->float] : 1.92200
|
|
247
|
+
FlopType.DIV [x/y] : 5.53105
|
|
248
|
+
FlopType.SQRT [sqrt(x)] : 7.35657
|
|
249
|
+
FlopType.EXP2 [2^x] : 15.85687
|
|
250
|
+
FlopType.EXP [e^x] : 17.51909
|
|
251
|
+
FlopType.LOG [log(x)] : 19.00419
|
|
252
|
+
FlopType.LOG2 [log2(x)] : 22.38002
|
|
253
|
+
FlopType.EXP10 [10^x] : 23.02693
|
|
254
|
+
FlopType.LOG10 [log10(x)] : 24.65718
|
|
255
|
+
FlopType.SIN [sin(x)] : 30.40612
|
|
256
|
+
FlopType.COS [cos(x)] : 31.39434
|
|
257
|
+
FlopType.POW [x^y] : 41.81031
|
|
258
|
+
FlopType.TAN [tan(x)] : 42.15636
|
|
259
|
+
FlopType.CBRT [cbrt(x)] : 44.32376
|
|
257
260
|
}
|
|
258
261
|
```
|
|
262
|
+
There are 3 rounding modes:
|
|
263
|
+
- `None` -> no rounding
|
|
264
|
+
- `"nearest_int"` -> round up/down to nearest integer, with a minimum of 1
|
|
265
|
+
- `"10%"` -> round to nearest semi-round number within ~10% (default)
|
|
266
|
+
|
|
259
267
|
|
|
260
268
|
The default weights that are configured out-of-the-box in the package are the integer-rounded `consensus` weights.
|
|
261
269
|
|
|
@@ -270,28 +278,28 @@ from counted_float.config import get_builtin_flop_weights
|
|
|
270
278
|
>>> get_builtin_flop_weights(key_filter="arm").show()
|
|
271
279
|
|
|
272
280
|
{
|
|
273
|
-
FlopType.
|
|
274
|
-
FlopType.MINUS [-x] : 0.
|
|
275
|
-
FlopType.COMP [x<=y] : 1.03987
|
|
276
|
-
FlopType.RND [round] : 1.35111
|
|
277
|
-
FlopType.F2I [float->int] : 1.52648
|
|
278
|
-
FlopType.I2F [int->float] : 1.63320
|
|
281
|
+
FlopType.COMP [x<=y] : 0.65000
|
|
282
|
+
FlopType.MINUS [-x] : 0.90000
|
|
279
283
|
FlopType.ADD [x+y] : 1.00000
|
|
280
|
-
FlopType.SUB [x-y] : 1.
|
|
281
|
-
FlopType.
|
|
282
|
-
FlopType.
|
|
283
|
-
FlopType.
|
|
284
|
-
FlopType.
|
|
285
|
-
FlopType.
|
|
286
|
-
FlopType.
|
|
287
|
-
FlopType.
|
|
288
|
-
FlopType.
|
|
289
|
-
FlopType.
|
|
290
|
-
FlopType.
|
|
291
|
-
FlopType.
|
|
292
|
-
FlopType.
|
|
293
|
-
FlopType.
|
|
294
|
-
FlopType.
|
|
284
|
+
FlopType.SUB [x-y] : 1.00000
|
|
285
|
+
FlopType.ABS [abs(x)] : 1.10000
|
|
286
|
+
FlopType.F2I [float->int] : 1.50000
|
|
287
|
+
FlopType.MUL [x*y] : 1.50000
|
|
288
|
+
FlopType.I2F [int->float] : 1.60000
|
|
289
|
+
FlopType.RND [round] : 1.60000
|
|
290
|
+
FlopType.DIV [x/y] : 6.00000
|
|
291
|
+
FlopType.SQRT [sqrt(x)] : 7.50000
|
|
292
|
+
FlopType.EXP2 [2^x] : 16.00000
|
|
293
|
+
FlopType.EXP [e^x] : 18.00000
|
|
294
|
+
FlopType.LOG [log(x)] : 20.00000
|
|
295
|
+
FlopType.LOG2 [log2(x)] : 20.00000
|
|
296
|
+
FlopType.EXP10 [10^x] : 24.00000
|
|
297
|
+
FlopType.LOG10 [log10(x)] : 24.00000
|
|
298
|
+
FlopType.COS [cos(x)] : 33.00000
|
|
299
|
+
FlopType.SIN [sin(x)] : 33.00000
|
|
300
|
+
FlopType.POW [x^y] : 40.00000
|
|
301
|
+
FlopType.CBRT [cbrt(x)] : 45.00000
|
|
302
|
+
FlopType.TAN [tan(x)] : 45.00000
|
|
295
303
|
}
|
|
296
304
|
```
|
|
297
305
|
|
|
@@ -335,29 +343,29 @@ div : wwwwwwwwwwwwwww.........................
|
|
|
335
343
|
div_div : wwwwwwwwwwwwwww......................... [ 5.00 µs ± 0.2% | 20.3K cpu cycles ± 0.2% ] / 1000 iterations
|
|
336
344
|
lte_addsub : wwwwwwwwwwwwwww......................... [ 1.71 µs ± 0.2% | 6.94K cpu cycles ± 0.2% ] / 1000 iterations
|
|
337
345
|
|
|
338
|
-
>>> results.flop_weights.show()
|
|
346
|
+
>>> results.flop_weights().show()
|
|
339
347
|
|
|
340
348
|
{
|
|
341
|
-
FlopType.ABS [abs(x)] : 0.
|
|
342
|
-
FlopType.MINUS [-x] : 0.
|
|
343
|
-
FlopType.
|
|
344
|
-
FlopType.RND [round] : 1.24118
|
|
349
|
+
FlopType.ABS [abs(x)] : 0.89904
|
|
350
|
+
FlopType.MINUS [-x] : 0.90935
|
|
351
|
+
FlopType.SUB [x-y] : 0.99676
|
|
345
352
|
FlopType.ADD [x+y] : 1.00000
|
|
346
|
-
FlopType.
|
|
347
|
-
FlopType.MUL [x*y] : 1.
|
|
348
|
-
FlopType.
|
|
349
|
-
FlopType.
|
|
350
|
-
FlopType.
|
|
351
|
-
FlopType.
|
|
352
|
-
FlopType.
|
|
353
|
-
FlopType.
|
|
354
|
-
FlopType.LOG [log(x)] : 17.
|
|
355
|
-
FlopType.LOG2 [log2(x)] : 18.
|
|
356
|
-
FlopType.
|
|
357
|
-
FlopType.
|
|
358
|
-
FlopType.
|
|
359
|
-
FlopType.
|
|
360
|
-
FlopType.
|
|
353
|
+
FlopType.RND [round] : 1.24397
|
|
354
|
+
FlopType.MUL [x*y] : 1.55516
|
|
355
|
+
FlopType.COMP [x<=y] : 1.69018
|
|
356
|
+
FlopType.DIV [x/y] : 4.12333
|
|
357
|
+
FlopType.SQRT [sqrt(x)] : 5.42419
|
|
358
|
+
FlopType.EXP2 [2^x] : 16.95266
|
|
359
|
+
FlopType.LOG10 [log10(x)] : 17.60079
|
|
360
|
+
FlopType.EXP [e^x] : 17.76250
|
|
361
|
+
FlopType.LOG [log(x)] : 17.86149
|
|
362
|
+
FlopType.LOG2 [log2(x)] : 18.42380
|
|
363
|
+
FlopType.EXP10 [10^x] : 21.50729
|
|
364
|
+
FlopType.SIN [sin(x)] : 29.31571
|
|
365
|
+
FlopType.COS [cos(x)] : 29.56218
|
|
366
|
+
FlopType.TAN [tan(x)] : 32.88570
|
|
367
|
+
FlopType.POW [x^y] : 39.35018
|
|
368
|
+
FlopType.CBRT [cbrt(x)] : 40.16857
|
|
361
369
|
FlopType.F2I [float->int] : nan
|
|
362
370
|
FlopType.I2F [int->float] : nan
|
|
363
371
|
}
|
|
@@ -459,10 +467,38 @@ ALL 0.47 0.70
|
|
|
459
467
|
|
|
460
468
|
```
|
|
461
469
|
|
|
462
|
-
|
|
470
|
+
## 4.2. Test performance of `CountedFloat` vs `float`
|
|
471
|
+
|
|
472
|
+
```
|
|
473
|
+
[~] counted_float benchmark-counted-float
|
|
474
|
+
```
|
|
475
|
+
See next section for results.
|
|
476
|
+
|
|
477
|
+
# 5. Performance impact
|
|
478
|
+
|
|
479
|
+
Obviously, using `CountedFloat` instead of regular `float` will have a performance impact due to the overhead of counting operations.
|
|
480
|
+
It is not advised to use `CountedFloat` for production code, but just for research code for which you want to estimate the floating-point operation count.
|
|
481
|
+
|
|
482
|
+
Micro-benchmarking of a bisection algorithm using `counted_float benchmark-counted-float` teaches us this:
|
|
483
|
+
```
|
|
484
|
+
------------------------------------------------------------------------------------------------------------------------
|
|
485
|
+
Running CountedFloat benchmark...
|
|
486
|
+
|
|
487
|
+
float : wwwwwwwwwwwwwww................................... [ 12.34 µs ± 1.2% | 50.1K cpu cycles ± 1.2% ] / execution
|
|
488
|
+
CountedFloat : wwwwwwwwwwwwwww................................... [ 459.95 µs ± 0.2% | 1.87M cpu cycles ± 0.2% ] / execution
|
|
489
|
+
------------------------------------------------------------------------------------------------------------------------
|
|
490
|
+
|
|
491
|
+
CountedFloat Benchmark Results:
|
|
492
|
+
Bisection using float : 12.34 µs / execution
|
|
493
|
+
Bisection using CountedFloat : 459.95 µs / execution
|
|
494
|
+
|
|
495
|
+
CountedFloat is 37.3x slower than float
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
# 6. Known limitations
|
|
463
499
|
|
|
464
500
|
- currently any non-Python-built-in math operations are not counted (e.g. `numpy`)
|
|
465
|
-
- not all Python built-in math operations are counted (e.g.
|
|
501
|
+
- not all Python built-in math operations are counted (e.g. hyperbolic functions)
|
|
466
502
|
- flop weights should be taken with a grain of salt and should only provide relative ballpark estimates w.r.t computational complexity. Production implementations in a compiled language could have vastly differing performance depending on cpu cache sizes, branch prediction misses, compiler optimizations using vector operations (AVX etc...), etc...
|
|
467
503
|
|
|
468
504
|
# Appendix A - Flop counting / analysis details
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<!--START_SECTION:images-->
|
|
2
2
|

|
|
3
|
-

|
|
4
|
+

|
|
5
|
+

|
|
6
6
|
<!--END_SECTION:images-->
|
|
7
7
|
|
|
8
8
|
# counted-float
|
|
@@ -141,30 +141,33 @@ rationale behind choice of data sources and methodology.
|
|
|
141
141
|
>>> get_active_flop_weights().show()
|
|
142
142
|
|
|
143
143
|
{
|
|
144
|
-
FlopType.
|
|
145
|
-
FlopType.
|
|
146
|
-
FlopType.
|
|
147
|
-
FlopType.
|
|
148
|
-
FlopType.
|
|
149
|
-
FlopType.
|
|
150
|
-
FlopType.
|
|
151
|
-
FlopType.
|
|
152
|
-
FlopType.
|
|
153
|
-
FlopType.DIV [x/y] :
|
|
154
|
-
FlopType.SQRT [sqrt(x)] :
|
|
155
|
-
FlopType.
|
|
156
|
-
FlopType.EXP [e^x] :
|
|
157
|
-
FlopType.
|
|
158
|
-
FlopType.
|
|
159
|
-
FlopType.
|
|
160
|
-
FlopType.
|
|
161
|
-
FlopType.
|
|
162
|
-
FlopType.
|
|
163
|
-
FlopType.
|
|
164
|
-
FlopType.
|
|
165
|
-
FlopType.
|
|
144
|
+
FlopType.MINUS [-x] : 0.45000
|
|
145
|
+
FlopType.ABS [abs(x)] : 0.70000
|
|
146
|
+
FlopType.ADD [x+y] : 1.00000
|
|
147
|
+
FlopType.COMP [x<=y] : 1.00000
|
|
148
|
+
FlopType.SUB [x-y] : 1.00000
|
|
149
|
+
FlopType.MUL [x*y] : 1.40000
|
|
150
|
+
FlopType.RND [round] : 1.80000
|
|
151
|
+
FlopType.F2I [float->int] : 2.00000
|
|
152
|
+
FlopType.I2F [int->float] : 2.00000
|
|
153
|
+
FlopType.DIV [x/y] : 5.50000
|
|
154
|
+
FlopType.SQRT [sqrt(x)] : 7.50000
|
|
155
|
+
FlopType.EXP2 [2^x] : 16.00000
|
|
156
|
+
FlopType.EXP [e^x] : 18.00000
|
|
157
|
+
FlopType.LOG [log(x)] : 20.00000
|
|
158
|
+
FlopType.LOG2 [log2(x)] : 22.00000
|
|
159
|
+
FlopType.EXP10 [10^x] : 24.00000
|
|
160
|
+
FlopType.LOG10 [log10(x)] : 24.00000
|
|
161
|
+
FlopType.COS [cos(x)] : 30.00000
|
|
162
|
+
FlopType.SIN [sin(x)] : 30.00000
|
|
163
|
+
FlopType.POW [x^y] : 40.00000
|
|
164
|
+
FlopType.TAN [tan(x)] : 40.00000
|
|
165
|
+
FlopType.CBRT [cbrt(x)] : 45.00000
|
|
166
166
|
}
|
|
167
167
|
```
|
|
168
|
+
Note that these weights are rounded up to the ~10% closest semi-round number, reflecting a balance between accuracy and readability,
|
|
169
|
+
while conveying the message that these weights should be used as approximations only. See further down for the different rounding modes.
|
|
170
|
+
|
|
168
171
|
These weights will be used by default when extracting total weighted flop costs:
|
|
169
172
|
|
|
170
173
|
```python
|
|
@@ -181,7 +184,7 @@ with FlopCountingContext() as ctx:
|
|
|
181
184
|
_ = math.log2(cf2)
|
|
182
185
|
|
|
183
186
|
flop_counts = ctx.flop_counts()
|
|
184
|
-
total_cost = flop_counts.total_weighted_cost() # 1 +
|
|
187
|
+
total_cost = flop_counts.total_weighted_cost() # 1 + 40 + 22 = 63
|
|
185
188
|
```
|
|
186
189
|
Note that the `total_weighted_cost` method will use the default flop weights as returned by `get_flop_weights()`. This can be
|
|
187
190
|
overridden by either configuring different flop weights (see next section) or by setting the `weights` argument of the `total_weighted_cost()` method.
|
|
@@ -208,33 +211,38 @@ Built-in flop weights can be inspected using the following functions:
|
|
|
208
211
|
```python
|
|
209
212
|
from counted_float.config import get_default_consensus_flop_weights
|
|
210
213
|
|
|
211
|
-
>>> get_default_consensus_flop_weights(
|
|
214
|
+
>>> get_default_consensus_flop_weights(rounding_mode=None).show()
|
|
212
215
|
|
|
213
216
|
{
|
|
214
|
-
FlopType.
|
|
215
|
-
FlopType.
|
|
216
|
-
FlopType.COMP [x<=y] :
|
|
217
|
-
FlopType.
|
|
218
|
-
FlopType.F2I [float->int] : 1.99099
|
|
219
|
-
FlopType.I2F [int->float] : 1.84601
|
|
217
|
+
FlopType.MINUS [-x] : 0.46773
|
|
218
|
+
FlopType.ABS [abs(x)] : 0.70012
|
|
219
|
+
FlopType.COMP [x<=y] : 0.96923
|
|
220
|
+
FlopType.SUB [x-y] : 0.99846
|
|
220
221
|
FlopType.ADD [x+y] : 1.00000
|
|
221
|
-
FlopType.
|
|
222
|
-
FlopType.
|
|
223
|
-
FlopType.
|
|
224
|
-
FlopType.
|
|
225
|
-
FlopType.
|
|
226
|
-
FlopType.
|
|
227
|
-
FlopType.EXP2 [2^x] :
|
|
228
|
-
FlopType.
|
|
229
|
-
FlopType.LOG [log(x)] :
|
|
230
|
-
FlopType.LOG2 [log2(x)] :
|
|
231
|
-
FlopType.
|
|
232
|
-
FlopType.
|
|
233
|
-
FlopType.SIN [sin(x)] :
|
|
234
|
-
FlopType.COS [cos(x)] :
|
|
235
|
-
FlopType.
|
|
222
|
+
FlopType.MUL [x*y] : 1.39950
|
|
223
|
+
FlopType.RND [round] : 1.77232
|
|
224
|
+
FlopType.F2I [float->int] : 1.91485
|
|
225
|
+
FlopType.I2F [int->float] : 1.92200
|
|
226
|
+
FlopType.DIV [x/y] : 5.53105
|
|
227
|
+
FlopType.SQRT [sqrt(x)] : 7.35657
|
|
228
|
+
FlopType.EXP2 [2^x] : 15.85687
|
|
229
|
+
FlopType.EXP [e^x] : 17.51909
|
|
230
|
+
FlopType.LOG [log(x)] : 19.00419
|
|
231
|
+
FlopType.LOG2 [log2(x)] : 22.38002
|
|
232
|
+
FlopType.EXP10 [10^x] : 23.02693
|
|
233
|
+
FlopType.LOG10 [log10(x)] : 24.65718
|
|
234
|
+
FlopType.SIN [sin(x)] : 30.40612
|
|
235
|
+
FlopType.COS [cos(x)] : 31.39434
|
|
236
|
+
FlopType.POW [x^y] : 41.81031
|
|
237
|
+
FlopType.TAN [tan(x)] : 42.15636
|
|
238
|
+
FlopType.CBRT [cbrt(x)] : 44.32376
|
|
236
239
|
}
|
|
237
240
|
```
|
|
241
|
+
There are 3 rounding modes:
|
|
242
|
+
- `None` -> no rounding
|
|
243
|
+
- `"nearest_int"` -> round up/down to nearest integer, with a minimum of 1
|
|
244
|
+
- `"10%"` -> round to nearest semi-round number within ~10% (default)
|
|
245
|
+
|
|
238
246
|
|
|
239
247
|
The default weights that are configured out-of-the-box in the package are the integer-rounded `consensus` weights.
|
|
240
248
|
|
|
@@ -249,28 +257,28 @@ from counted_float.config import get_builtin_flop_weights
|
|
|
249
257
|
>>> get_builtin_flop_weights(key_filter="arm").show()
|
|
250
258
|
|
|
251
259
|
{
|
|
252
|
-
FlopType.
|
|
253
|
-
FlopType.MINUS [-x] : 0.
|
|
254
|
-
FlopType.COMP [x<=y] : 1.03987
|
|
255
|
-
FlopType.RND [round] : 1.35111
|
|
256
|
-
FlopType.F2I [float->int] : 1.52648
|
|
257
|
-
FlopType.I2F [int->float] : 1.63320
|
|
260
|
+
FlopType.COMP [x<=y] : 0.65000
|
|
261
|
+
FlopType.MINUS [-x] : 0.90000
|
|
258
262
|
FlopType.ADD [x+y] : 1.00000
|
|
259
|
-
FlopType.SUB [x-y] : 1.
|
|
260
|
-
FlopType.
|
|
261
|
-
FlopType.
|
|
262
|
-
FlopType.
|
|
263
|
-
FlopType.
|
|
264
|
-
FlopType.
|
|
265
|
-
FlopType.
|
|
266
|
-
FlopType.
|
|
267
|
-
FlopType.
|
|
268
|
-
FlopType.
|
|
269
|
-
FlopType.
|
|
270
|
-
FlopType.
|
|
271
|
-
FlopType.
|
|
272
|
-
FlopType.
|
|
273
|
-
FlopType.
|
|
263
|
+
FlopType.SUB [x-y] : 1.00000
|
|
264
|
+
FlopType.ABS [abs(x)] : 1.10000
|
|
265
|
+
FlopType.F2I [float->int] : 1.50000
|
|
266
|
+
FlopType.MUL [x*y] : 1.50000
|
|
267
|
+
FlopType.I2F [int->float] : 1.60000
|
|
268
|
+
FlopType.RND [round] : 1.60000
|
|
269
|
+
FlopType.DIV [x/y] : 6.00000
|
|
270
|
+
FlopType.SQRT [sqrt(x)] : 7.50000
|
|
271
|
+
FlopType.EXP2 [2^x] : 16.00000
|
|
272
|
+
FlopType.EXP [e^x] : 18.00000
|
|
273
|
+
FlopType.LOG [log(x)] : 20.00000
|
|
274
|
+
FlopType.LOG2 [log2(x)] : 20.00000
|
|
275
|
+
FlopType.EXP10 [10^x] : 24.00000
|
|
276
|
+
FlopType.LOG10 [log10(x)] : 24.00000
|
|
277
|
+
FlopType.COS [cos(x)] : 33.00000
|
|
278
|
+
FlopType.SIN [sin(x)] : 33.00000
|
|
279
|
+
FlopType.POW [x^y] : 40.00000
|
|
280
|
+
FlopType.CBRT [cbrt(x)] : 45.00000
|
|
281
|
+
FlopType.TAN [tan(x)] : 45.00000
|
|
274
282
|
}
|
|
275
283
|
```
|
|
276
284
|
|
|
@@ -314,29 +322,29 @@ div : wwwwwwwwwwwwwww.........................
|
|
|
314
322
|
div_div : wwwwwwwwwwwwwww......................... [ 5.00 µs ± 0.2% | 20.3K cpu cycles ± 0.2% ] / 1000 iterations
|
|
315
323
|
lte_addsub : wwwwwwwwwwwwwww......................... [ 1.71 µs ± 0.2% | 6.94K cpu cycles ± 0.2% ] / 1000 iterations
|
|
316
324
|
|
|
317
|
-
>>> results.flop_weights.show()
|
|
325
|
+
>>> results.flop_weights().show()
|
|
318
326
|
|
|
319
327
|
{
|
|
320
|
-
FlopType.ABS [abs(x)] : 0.
|
|
321
|
-
FlopType.MINUS [-x] : 0.
|
|
322
|
-
FlopType.
|
|
323
|
-
FlopType.RND [round] : 1.24118
|
|
328
|
+
FlopType.ABS [abs(x)] : 0.89904
|
|
329
|
+
FlopType.MINUS [-x] : 0.90935
|
|
330
|
+
FlopType.SUB [x-y] : 0.99676
|
|
324
331
|
FlopType.ADD [x+y] : 1.00000
|
|
325
|
-
FlopType.
|
|
326
|
-
FlopType.MUL [x*y] : 1.
|
|
327
|
-
FlopType.
|
|
328
|
-
FlopType.
|
|
329
|
-
FlopType.
|
|
330
|
-
FlopType.
|
|
331
|
-
FlopType.
|
|
332
|
-
FlopType.
|
|
333
|
-
FlopType.LOG [log(x)] : 17.
|
|
334
|
-
FlopType.LOG2 [log2(x)] : 18.
|
|
335
|
-
FlopType.
|
|
336
|
-
FlopType.
|
|
337
|
-
FlopType.
|
|
338
|
-
FlopType.
|
|
339
|
-
FlopType.
|
|
332
|
+
FlopType.RND [round] : 1.24397
|
|
333
|
+
FlopType.MUL [x*y] : 1.55516
|
|
334
|
+
FlopType.COMP [x<=y] : 1.69018
|
|
335
|
+
FlopType.DIV [x/y] : 4.12333
|
|
336
|
+
FlopType.SQRT [sqrt(x)] : 5.42419
|
|
337
|
+
FlopType.EXP2 [2^x] : 16.95266
|
|
338
|
+
FlopType.LOG10 [log10(x)] : 17.60079
|
|
339
|
+
FlopType.EXP [e^x] : 17.76250
|
|
340
|
+
FlopType.LOG [log(x)] : 17.86149
|
|
341
|
+
FlopType.LOG2 [log2(x)] : 18.42380
|
|
342
|
+
FlopType.EXP10 [10^x] : 21.50729
|
|
343
|
+
FlopType.SIN [sin(x)] : 29.31571
|
|
344
|
+
FlopType.COS [cos(x)] : 29.56218
|
|
345
|
+
FlopType.TAN [tan(x)] : 32.88570
|
|
346
|
+
FlopType.POW [x^y] : 39.35018
|
|
347
|
+
FlopType.CBRT [cbrt(x)] : 40.16857
|
|
340
348
|
FlopType.F2I [float->int] : nan
|
|
341
349
|
FlopType.I2F [int->float] : nan
|
|
342
350
|
}
|
|
@@ -438,10 +446,38 @@ ALL 0.47 0.70
|
|
|
438
446
|
|
|
439
447
|
```
|
|
440
448
|
|
|
441
|
-
|
|
449
|
+
## 4.2. Test performance of `CountedFloat` vs `float`
|
|
450
|
+
|
|
451
|
+
```
|
|
452
|
+
[~] counted_float benchmark-counted-float
|
|
453
|
+
```
|
|
454
|
+
See next section for results.
|
|
455
|
+
|
|
456
|
+
# 5. Performance impact
|
|
457
|
+
|
|
458
|
+
Obviously, using `CountedFloat` instead of regular `float` will have a performance impact due to the overhead of counting operations.
|
|
459
|
+
It is not advised to use `CountedFloat` for production code, but just for research code for which you want to estimate the floating-point operation count.
|
|
460
|
+
|
|
461
|
+
Micro-benchmarking of a bisection algorithm using `counted_float benchmark-counted-float` teaches us this:
|
|
462
|
+
```
|
|
463
|
+
------------------------------------------------------------------------------------------------------------------------
|
|
464
|
+
Running CountedFloat benchmark...
|
|
465
|
+
|
|
466
|
+
float : wwwwwwwwwwwwwww................................... [ 12.34 µs ± 1.2% | 50.1K cpu cycles ± 1.2% ] / execution
|
|
467
|
+
CountedFloat : wwwwwwwwwwwwwww................................... [ 459.95 µs ± 0.2% | 1.87M cpu cycles ± 0.2% ] / execution
|
|
468
|
+
------------------------------------------------------------------------------------------------------------------------
|
|
469
|
+
|
|
470
|
+
CountedFloat Benchmark Results:
|
|
471
|
+
Bisection using float : 12.34 µs / execution
|
|
472
|
+
Bisection using CountedFloat : 459.95 µs / execution
|
|
473
|
+
|
|
474
|
+
CountedFloat is 37.3x slower than float
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
# 6. Known limitations
|
|
442
478
|
|
|
443
479
|
- currently any non-Python-built-in math operations are not counted (e.g. `numpy`)
|
|
444
|
-
- not all Python built-in math operations are counted (e.g.
|
|
480
|
+
- not all Python built-in math operations are counted (e.g. hyperbolic functions)
|
|
445
481
|
- flop weights should be taken with a grain of salt and should only provide relative ballpark estimates w.r.t computational complexity. Production implementations in a compiled language could have vastly differing performance depending on cpu cache sizes, branch prediction misses, compiler optimizations using vector operations (AVX etc...), etc...
|
|
446
482
|
|
|
447
483
|
# Appendix A - Flop counting / analysis details
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import click
|
|
2
2
|
|
|
3
3
|
from counted_float import BuiltInData
|
|
4
|
-
from counted_float.benchmarking import run_flops_benchmark
|
|
4
|
+
from counted_float._core.benchmarking import run_counted_float_benchmark, run_flops_benchmark
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
# -------------------------------------------------------------------------
|
|
@@ -22,3 +22,9 @@ def benchmark():
|
|
|
22
22
|
@click.option("--key_filter", default="", help="Optional key filter for built-in data")
|
|
23
23
|
def show_data(key_filter: str):
|
|
24
24
|
BuiltInData.show(key_filter=key_filter)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@cli.command(short_help="run benchmark of float vs CountedFloat performance")
|
|
28
|
+
def benchmark_counted_float():
|
|
29
|
+
result = run_counted_float_benchmark()
|
|
30
|
+
result.show()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from .counted_float import BenchmarkCountedFloat, BenchmarkFloat, CountedFloatBenchmarkResults
|
|
2
|
+
from .flops import FlopsBenchmarkResults, FlopsBenchmarkSuite
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def run_flops_benchmark(n_seconds_per_run_target: float = 0.1) -> FlopsBenchmarkResults:
|
|
6
|
+
"""Run the flops benchmark suite with default settings returns a FlopsBenchmarkResults object."""
|
|
7
|
+
|
|
8
|
+
benchmark_results = FlopsBenchmarkSuite().run(n_seconds_per_run_target=n_seconds_per_run_target)
|
|
9
|
+
|
|
10
|
+
print()
|
|
11
|
+
|
|
12
|
+
return benchmark_results
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def run_counted_float_benchmark(t_target_sec: float = 0.1) -> CountedFloatBenchmarkResults:
|
|
16
|
+
"""Run benchmark to compare performance of float vs CountedFloat."""
|
|
17
|
+
print("-" * 120)
|
|
18
|
+
print("Running CountedFloat benchmark...")
|
|
19
|
+
print()
|
|
20
|
+
|
|
21
|
+
result_float = BenchmarkFloat().run_many(
|
|
22
|
+
n_runs_total=50,
|
|
23
|
+
n_runs_warmup=15,
|
|
24
|
+
n_seconds_per_run_target=t_target_sec,
|
|
25
|
+
)
|
|
26
|
+
result_counted_float = BenchmarkCountedFloat().run_many(
|
|
27
|
+
n_runs_total=50,
|
|
28
|
+
n_runs_warmup=15,
|
|
29
|
+
n_seconds_per_run_target=t_target_sec,
|
|
30
|
+
)
|
|
31
|
+
print("-" * 120)
|
|
32
|
+
print()
|
|
33
|
+
|
|
34
|
+
return CountedFloatBenchmarkResults(
|
|
35
|
+
float_time_nsec=result_float.summary_stats_nsecs_per_exec().q50,
|
|
36
|
+
counted_float_time_nsec=result_counted_float.summary_stats_nsecs_per_exec().q50,
|
|
37
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ._counted_float_benchmark import BenchmarkCountedFloat, BenchmarkFloat, CountedFloatBenchmarkResults
|