counted-float 0.9.2__tar.gz → 0.9.4__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.
Files changed (94) hide show
  1. {counted_float-0.9.2 → counted_float-0.9.4}/PKG-INFO +47 -43
  2. {counted_float-0.9.2 → counted_float-0.9.4}/README.md +44 -41
  3. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/__init__.py +2 -4
  4. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/benchmarking/__init__.py +2 -4
  5. counted_float-0.9.4/counted_float/_core/benchmarking/flops/__init__.py +3 -0
  6. counted_float-0.9.4/counted_float/_core/benchmarking/flops/_array_generator.py +76 -0
  7. counted_float-0.9.4/counted_float/_core/benchmarking/flops/_flops_benchmark_suite.py +290 -0
  8. counted_float-0.9.4/counted_float/_core/benchmarking/flops/_flops_micro_benchmark.py +67 -0
  9. counted_float-0.9.4/counted_float/_core/benchmarking/micro/__init__.py +1 -0
  10. {counted_float-0.9.2/counted_float/_core/benchmarking → counted_float-0.9.4/counted_float/_core/benchmarking/micro}/_micro_benchmark.py +23 -28
  11. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/_builtin_data.py +26 -18
  12. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/_counted_float.py +60 -9
  13. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/_global_counter.py +6 -0
  14. counted_float-0.9.4/counted_float/_core/models/__init__.py +18 -0
  15. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/models/_flop_counts.py +2 -0
  16. counted_float-0.9.4/counted_float/_core/models/_flop_type.py +30 -0
  17. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/models/_flop_weights.py +6 -12
  18. counted_float-0.9.4/counted_float/_core/models/_flops_benchmark_meta_data.py +128 -0
  19. counted_float-0.9.2/counted_float/_core/models/_flops_benchmark_result.py → counted_float-0.9.4/counted_float/_core/models/_flops_benchmark_result_v1.py +7 -28
  20. counted_float-0.9.4/counted_float/_core/models/_flops_benchmark_result_v2.py +26 -0
  21. counted_float-0.9.4/counted_float/_core/models/_flops_benchmark_type.py +24 -0
  22. counted_float-0.9.4/counted_float/_core/models/_instruction_latencies.py +152 -0
  23. counted_float-0.9.4/counted_float/_core/models/_micro_benchmark_result.py +62 -0
  24. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/utils/__init__.py +1 -1
  25. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/utils/_latency.py +1 -1
  26. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/benchmarking/__init__.py +2 -2
  27. {counted_float-0.9.2/counted_float/data/benchmarks/arm/apple → counted_float-0.9.4/counted_float/data/arm/v8_x/benchmarks}/m3_max_macbook_pro_16.json +29 -11
  28. counted_float-0.9.4/counted_float/data/arm/v8_x/benchmarks/m3_max_macbook_pro_16_v2.json +151 -0
  29. {counted_float-0.9.2/counted_float/data/specs/arm → counted_float-0.9.4/counted_float/data/arm/v8_x/specs}/arm_v8_cortex_a76.json +34 -11
  30. counted_float-0.9.4/counted_float/data/arm/v8_x/specs/arm_v9_cortex_n1.json +75 -0
  31. counted_float-0.9.4/counted_float/data/arm/v8_x/specs/arm_v9_cortex_v1.json +75 -0
  32. {counted_float-0.9.2/counted_float/data/specs/arm → counted_float-0.9.4/counted_float/data/arm/v8_x/specs}/arm_v9_cortex_x1.json +34 -11
  33. counted_float-0.9.4/counted_float/data/arm/v9_0/specs/arm_v9_cortex_n2.json +75 -0
  34. counted_float-0.9.4/counted_float/data/arm/v9_0/specs/arm_v9_cortex_v2.json +75 -0
  35. {counted_float-0.9.2/counted_float/data/specs/arm → counted_float-0.9.4/counted_float/data/arm/v9_0/specs}/arm_v9_cortex_x2.json +34 -11
  36. {counted_float-0.9.2/counted_float/data/specs/arm → counted_float-0.9.4/counted_float/data/arm/v9_0/specs}/arm_v9_cortex_x3.json +34 -11
  37. counted_float-0.9.4/counted_float/data/arm/v9_2/specs/arm_v9_cortex_v3.json +75 -0
  38. counted_float-0.9.4/counted_float/data/arm/v9_2/specs/arm_v9_cortex_x4.json +75 -0
  39. counted_float-0.9.4/counted_float/data/arm/v9_2/specs/arm_v9_cortex_x925.json +75 -0
  40. counted_float-0.9.4/counted_float/data/x86/amd/2017_zen1/analysis_uops_info_zen1+.json +74 -0
  41. counted_float-0.9.4/counted_float/data/x86/amd/2017_zen1/benchmark_ryzen_1700x.json +121 -0
  42. counted_float-0.9.4/counted_float/data/x86/amd/2020_zen3/analysis_agner_fog_r7_5800x.json +75 -0
  43. counted_float-0.9.4/counted_float/data/x86/amd/2020_zen3/analysis_uops_info_zen3.json +74 -0
  44. counted_float-0.9.4/counted_float/data/x86/amd/2022_zen4/analysis_agner_fog_r9_7900x.json +75 -0
  45. counted_float-0.9.4/counted_float/data/x86/amd/2022_zen4/analysis_uops_info_zen4.json +74 -0
  46. counted_float-0.9.4/counted_float/data/x86/amd/2022_zen4/specs_amd.json +75 -0
  47. counted_float-0.9.4/counted_float/data/x86/amd/2024_zen5/analysis_agner_fog_r7_9800x3d.json +75 -0
  48. counted_float-0.9.4/counted_float/data/x86/amd/2024_zen5/specs_amd.json +75 -0
  49. counted_float-0.9.4/counted_float/data/x86/intel/2017_coffee_lake_gen_8/analysis_agner_fog_coffee_lake.json +76 -0
  50. counted_float-0.9.4/counted_float/data/x86/intel/2017_coffee_lake_gen_8/analysis_uops_info_coffee_lake.json +74 -0
  51. counted_float-0.9.4/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_agner_fog_ice_lake.json +75 -0
  52. counted_float-0.9.4/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_uops_info_ice_lake.json +74 -0
  53. counted_float-0.9.4/counted_float/data/x86/intel/2019_sunny_cove_gen_10/analysis_uops_info_tiger_lake.json +74 -0
  54. counted_float-0.9.4/counted_float/data/x86/intel/2021_golden_cove_gen_12/analysis_uops_info_alder_lake_p.json +74 -0
  55. counted_float-0.9.2/counted_float/data/benchmarks/x86/intel/gen12_i7_1265u.json → counted_float-0.9.4/counted_float/data/x86/intel/2021_golden_cove_gen_12/benchmark_core_i7_1265u.json +29 -11
  56. counted_float-0.9.4/counted_float/data/x86/intel/2021_golden_cove_gen_12/specs_intel.json +75 -0
  57. counted_float-0.9.4/counted_float/data/x86/intel/2022_raptor_cove_gen_13_14/specs_intel.json +76 -0
  58. counted_float-0.9.4/counted_float/data/x86/intel/2023_redwood_cove_ultra_1/specs_intel.json +75 -0
  59. {counted_float-0.9.2 → counted_float-0.9.4}/pyproject.toml +3 -2
  60. counted_float-0.9.2/counted_float/_core/benchmarking/_flops_benchmark_suite.py +0 -193
  61. counted_float-0.9.2/counted_float/_core/benchmarking/_flops_micro_benchmark.py +0 -59
  62. counted_float-0.9.2/counted_float/_core/benchmarking/_time_utils.py +0 -1
  63. counted_float-0.9.2/counted_float/_core/models/__init__.py +0 -13
  64. counted_float-0.9.2/counted_float/_core/models/_flop_type.py +0 -47
  65. counted_float-0.9.2/counted_float/_core/models/_fpu_instruction.py +0 -22
  66. counted_float-0.9.2/counted_float/_core/models/_fpu_specs.py +0 -98
  67. counted_float-0.9.2/counted_float/_core/models/_micro_benchmark_result.py +0 -41
  68. counted_float-0.9.2/counted_float/data/benchmarks/x86/intel/gen7_i5_7200u.json +0 -103
  69. counted_float-0.9.2/counted_float/data/specs/arm/arm_v7a_cortex_a9.json +0 -52
  70. counted_float-0.9.2/counted_float/data/specs/arm/arm_v8_cortex_a55.json +0 -52
  71. counted_float-0.9.2/counted_float/data/specs/x86/amd/zen3_r7_5800x.json +0 -54
  72. counted_float-0.9.2/counted_float/data/specs/x86/amd/zen4_r9_7900x.json +0 -54
  73. counted_float-0.9.2/counted_float/data/specs/x86/amd/zen5_r7_9800x3d.json +0 -54
  74. counted_float-0.9.2/counted_float/data/specs/x86/intel/gen09_coffee_lake.json +0 -57
  75. counted_float-0.9.2/counted_float/data/specs/x86/intel/gen10_cannon_lake.json +0 -57
  76. counted_float-0.9.2/counted_float/data/specs/x86/intel/gen11_tiger_lake.json +0 -57
  77. {counted_float-0.9.2 → counted_float-0.9.4}/.gitignore +0 -0
  78. {counted_float-0.9.2 → counted_float-0.9.4}/LICENSE +0 -0
  79. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/__init__.py +0 -0
  80. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/_cli.py +0 -0
  81. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/compatibility/__init__.py +0 -0
  82. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/compatibility/_numba.py +0 -0
  83. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/compatibility/_strenum.py +0 -0
  84. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/__init__.py +0 -0
  85. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/_context_managers.py +0 -0
  86. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/config/__init__.py +0 -0
  87. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/config/_config.py +0 -0
  88. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/counting/config/_defaults.py +0 -0
  89. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/models/_base.py +0 -0
  90. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/utils/_formatting.py +0 -0
  91. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/utils/_geo_mean.py +0 -0
  92. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/utils/_missing_data.py +0 -0
  93. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/_core/utils/_timer.py +0 -0
  94. {counted_float-0.9.2 → counted_float-0.9.4}/counted_float/config/__init__.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: counted-float
3
- Version: 0.9.2
3
+ Version: 0.9.4
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
- Project-URL: ChangeLog, https://github.com/bertpl/counted-float/blob/develop/RELEASE_NOTES.md
6
+ Project-URL: ChangeLog, https://github.com/bertpl/counted-float/blob/develop/CHANGELOG.md
7
7
  Project-URL: Issues, https://github.com/bertpl/counted-float/issues
8
8
  Project-URL: Roadmap, https://github.com/bertpl/counted-float/milestones
9
9
  License-File: LICENSE
@@ -11,6 +11,7 @@ Requires-Python: >=3.10
11
11
  Requires-Dist: backports-strenum>=1.3.1
12
12
  Requires-Dist: numpy>=1.20
13
13
  Requires-Dist: psutil>=5.0
14
+ Requires-Dist: py-cpuinfo>=9.0.0
14
15
  Requires-Dist: pydantic>=2.0.0
15
16
  Requires-Dist: rich>=13.0.0
16
17
  Provides-Extra: cli
@@ -21,9 +22,9 @@ Description-Content-Type: text/markdown
21
22
 
22
23
  <!--START_SECTION:images-->
23
24
  ![shields.io-python-versions](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)
24
- ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v0.9.2/badge-test-count.svg)
25
- ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v0.9.2/badge-coverage.svg)
26
- ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v0.9.2/splash.webp)
25
+ ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v0.9.4/badge-test-count.svg)
26
+ ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v0.9.4/badge-coverage.svg)
27
+ ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v0.9.4/splash.webp)
27
28
  <!--END_SECTION:images-->
28
29
 
29
30
  # counted-float
@@ -148,7 +149,10 @@ counts.total_count() # 2
148
149
  ## 2.3. Weighted FLOP counting
149
150
 
150
151
  The `counted_float` package contains a set of default, built-in FLOP weights, based on both empirical measurements
151
- and theoretical estimates of the relative cost of different floating point operations.
152
+ and theoretical estimates of the relative cost of different floating point operations.
153
+
154
+ See [fpu_data_sources.md](https://github.com/bertpl/counted-float/tree/develop/docs/analysis_methodology.md) for
155
+ rationale behind choice of data sources and methodology.
152
156
 
153
157
  ```
154
158
  >>> from counted_float.config import get_flop_weights
@@ -161,7 +165,7 @@ and theoretical estimates of the relative cost of different floating point opera
161
165
  FlopType.GTE [x>=y] : 1
162
166
  FlopType.LTE [x<=y] : 1
163
167
  FlopType.CMP_ZERO [x>=0] : 1
164
- FlopType.RND [round(x)] : 1
168
+ FlopType.RND [round(x,0)] : 1
165
169
  FlopType.ADD [x+y] : 1
166
170
  FlopType.SUB [x-y] : 1
167
171
  FlopType.MUL [x*y] : 1
@@ -224,7 +228,7 @@ from counted_float.config import get_default_empirical_flop_weights, get_default
224
228
  FlopType.GTE [x>=y] : 0.94684
225
229
  FlopType.LTE [x<=y] : 0.93101
226
230
  FlopType.CMP_ZERO [x>=0] : 0.82204
227
- FlopType.RND [round(x)] : 0.96944
231
+ FlopType.RND [round(x,0)] : 0.96944
228
232
  FlopType.ADD [x+y] : 0.89296
229
233
  FlopType.SUB [x-y] : 1.14383
230
234
  FlopType.MUL [x*y] : 1.04677
@@ -255,7 +259,7 @@ from counted_float.config import get_builtin_flop_weights
255
259
  FlopType.GTE [x>=y] : 0.89744
256
260
  FlopType.LTE [x<=y] : 0.89744
257
261
  FlopType.CMP_ZERO [x>=0] : 0.84762
258
- FlopType.RND [round(x)] : 2.63592
262
+ FlopType.RND [round(x,0)] : 2.63592
259
263
  FlopType.ADD [x+y] : 0.86616
260
264
  FlopType.SUB [x-y] : 1.10411
261
265
  FlopType.MUL [x*y] : 1.16515
@@ -281,43 +285,43 @@ floating point operations as follows:
281
285
  >>> from counted_float.benchmarking import run_flops_benchmark
282
286
  >>> results = run_flops_benchmark()
283
287
 
284
- Running FLOPS benchmarks using counted-float 0.9.2 ...
285
-
286
- baseline : wwwwwwwwww.................... ( 187.03 ns = 759 cpu cycles) ± 0.6% / 1000 iterations
287
- FlopType.ABS [abs(x)] : wwwwwwwwww.................... ( 303.31 ns = 1.23K cpu cycles) ± 1.7% / 1000 iterations
288
- FlopType.CMP_ZERO [x>=0] : wwwwwwwwww.................... ( 302.19 ns = 1.23K cpu cycles) ± 3.0% / 1000 iterations
289
- FlopType.RND [round(x)] : wwwwwwwwww.................... ( 305.95 ns = 1.24K cpu cycles) ± 4.8% / 1000 iterations
290
- FlopType.MINUS [-x] : wwwwwwwwww.................... ( 306.31 ns = 1.24K cpu cycles) ± 2.6% / 1000 iterations
291
- FlopType.EQUALS [x==y] : wwwwwwwwww.................... ( 320.59 ns = 1.30K cpu cycles) ± 3.9% / 1000 iterations
292
- FlopType.GTE [x>=y] : wwwwwwwwww.................... ( 331.51 ns = 1.34K cpu cycles) ± 2.9% / 1000 iterations
293
- FlopType.LTE [x<=y] : wwwwwwwwww.................... ( 333.81 ns = 1.35K cpu cycles) ± 1.0% / 1000 iterations
294
- FlopType.ADD [x+y] : wwwwwwwwww.................... ( 315.84 ns = 1.28K cpu cycles) ± 3.2% / 1000 iterations
295
- FlopType.SUB [x-y] : wwwwwwwwww.................... ( 335.49 ns = 1.36K cpu cycles) ± 3.8% / 1000 iterations
296
- FlopType.MUL [x*y] : wwwwwwwwww.................... ( 325.65 ns = 1.32K cpu cycles) ± 3.0% / 1000 iterations
297
- FlopType.SQRT [sqrt(x)] : wwwwwwwwww.................... ( 443.30 ns = 1.80K cpu cycles) ± 2.6% / 1000 iterations
298
- FlopType.DIV [x/y] : wwwwwwwwww.................... ( 491.51 ns = 1.99K cpu cycles) ± 1.1% / 1000 iterations
299
- FlopType.POW2 [2^x] : wwwwwwwwww.................... ( 1.79 µs = 7.28K cpu cycles) ± 0.3% / 1000 iterations
300
- FlopType.LOG2 [log2(x)] : wwwwwwwwww.................... ( 2.17 µs = 8.80K cpu cycles) ± 0.8% / 1000 iterations
301
- FlopType.POW [x^y] : wwwwwwwwww.................... ( 6.32 µs = 25.6K cpu cycles) ± 0.7% / 1000 iterations
288
+ Running FLOPS benchmarks using counted-float 0.9.4 ...
289
+
290
+ baseline : wwwwwwwwww.................... [ 177.53 ns ± 2.0% | 720 cpu cycles ± 2.0% ] / 1000 iterations
291
+ FlopType.ABS [abs(x)] : wwwwwwwwww.................... [ 286.71 ns ± 5.7% | 1.16K cpu cycles ± 5.7% ] / 1000 iterations
292
+ FlopType.CMP_ZERO [x>=0] : wwwwwwwwww.................... [ 294.71 ns ± 3.6% | 1.20K cpu cycles ± 3.6% ] / 1000 iterations
293
+ FlopType.RND [round(x,0)] : wwwwwwwwww.................... [ 291.74 ns ± 6.1% | 1.18K cpu cycles ± 6.1% ] / 1000 iterations
294
+ FlopType.MINUS [-x] : wwwwwwwwww.................... [ 291.81 ns ± 5.8% | 1.18K cpu cycles ± 5.8% ] / 1000 iterations
295
+ FlopType.EQUALS [x==y] : wwwwwwwwww.................... [ 297.70 ns ± 4.2% | 1.21K cpu cycles ± 4.2% ] / 1000 iterations
296
+ FlopType.GTE [x>=y] : wwwwwwwwww.................... [ 301.59 ns ± 3.2% | 1.22K cpu cycles ± 3.2% ] / 1000 iterations
297
+ FlopType.LTE [x<=y] : wwwwwwwwww.................... [ 295.77 ns ± 2.2% | 1.20K cpu cycles ± 2.2% ] / 1000 iterations
298
+ FlopType.ADD [x+y] : wwwwwwwwww.................... [ 289.49 ns ± 2.6% | 1.17K cpu cycles ± 2.6% ] / 1000 iterations
299
+ FlopType.SUB [x-y] : wwwwwwwwww.................... [ 289.85 ns ± 1.7% | 1.18K cpu cycles ± 1.7% ] / 1000 iterations
300
+ FlopType.MUL [x*y] : wwwwwwwwww.................... [ 305.46 ns ± 2.8% | 1.24K cpu cycles ± 2.8% ] / 1000 iterations
301
+ FlopType.SQRT [sqrt(x)] : wwwwwwwwww.................... [ 435.30 ns ± 0.5% | 1.77K cpu cycles ± 0.5% ] / 1000 iterations
302
+ FlopType.DIV [x/y] : wwwwwwwwww.................... [ 479.90 ns ± 1.2% | 1.95K cpu cycles ± 1.2% ] / 1000 iterations
303
+ FlopType.POW2 [2^x] : wwwwwwwwww.................... [ 1.78 µs ± 0.1% | 7.22K cpu cycles ± 0.1% ] / 1000 iterations
304
+ FlopType.LOG2 [log2(x)] : wwwwwwwwww.................... [ 2.17 µs ± 0.6% | 8.80K cpu cycles ± 0.6% ] / 1000 iterations
305
+ FlopType.POW [x^y] : wwwwwwwwww.................... [ 6.14 µs ± 0.4% | 24.9K cpu cycles ± 0.4% ] / 1000 iterations
302
306
 
303
307
  >>> results.flop_weights.show()
304
308
 
305
309
  {
306
- FlopType.ABS [abs(x)] : 0.84769
307
- FlopType.MINUS [-x] : 0.86954
308
- FlopType.EQUALS [x==y] : 0.97369
309
- FlopType.GTE [x>=y] : 1.05327
310
- FlopType.LTE [x<=y] : 1.07007
311
- FlopType.CMP_ZERO [x>=0] : 0.83957
312
- FlopType.RND [round(x)] : 0.86695
313
- FlopType.ADD [x+y] : 0.93905
314
- FlopType.SUB [x-y] : 1.08227
315
- FlopType.MUL [x*y] : 1.01055
316
- FlopType.DIV [x/y] : 2.21970
317
- FlopType.SQRT [sqrt(x)] : 1.86822
318
- FlopType.POW2 [2^x] : 11.72183
319
- FlopType.LOG2 [log2(x)] : 14.45542
320
- FlopType.POW [x^y] : 44.68266
310
+ FlopType.ABS [abs(x)] : 0.97517
311
+ FlopType.MINUS [-x] : 1.02074
312
+ FlopType.EQUALS [x==y] : 1.07339
313
+ FlopType.GTE [x>=y] : 1.10812
314
+ FlopType.LTE [x<=y] : 1.05609
315
+ FlopType.CMP_ZERO [x>=0] : 1.04665
316
+ FlopType.RND [round(x,0)] : 1.02017
317
+ FlopType.ADD [x+y] : 1.00000
318
+ FlopType.SUB [x-y] : 1.00328
319
+ FlopType.MUL [x*y] : 1.14268
320
+ FlopType.DIV [x/y] : 2.70079
321
+ FlopType.SQRT [sqrt(x)] : 2.30238
322
+ FlopType.POW2 [2^x] : 14.30722
323
+ FlopType.LOG2 [log2(x)] : 17.79592
324
+ FlopType.POW [x^y] : 53.26393
321
325
  }
322
326
  ```
323
327
 
@@ -332,7 +336,7 @@ uv tool install git+https://github.com/bertpl/counted-float@develop[numba,cli]
332
336
  ```
333
337
  This installs the `counted_float` command-line tool, which can be used to e.g. run flops benchmarks.
334
338
 
335
- ## 4.1 Running benchmarks
339
+ ## 4.1. Running benchmarks
336
340
 
337
341
  ```
338
342
  counted_float benchmark
@@ -1,8 +1,8 @@
1
1
  <!--START_SECTION:images-->
2
2
  ![shields.io-python-versions](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)
3
- ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v0.9.2/badge-test-count.svg)
4
- ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v0.9.2/badge-coverage.svg)
5
- ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v0.9.2/splash.webp)
3
+ ![genbadge-test-count](https://bertpl.github.io/counted-float/version_artifacts/v0.9.4/badge-test-count.svg)
4
+ ![genbadge-test-coverage](https://bertpl.github.io/counted-float/version_artifacts/v0.9.4/badge-coverage.svg)
5
+ ![counted_float logo](https://bertpl.github.io/counted-float/version_artifacts/v0.9.4/splash.webp)
6
6
  <!--END_SECTION:images-->
7
7
 
8
8
  # counted-float
@@ -127,7 +127,10 @@ counts.total_count() # 2
127
127
  ## 2.3. Weighted FLOP counting
128
128
 
129
129
  The `counted_float` package contains a set of default, built-in FLOP weights, based on both empirical measurements
130
- and theoretical estimates of the relative cost of different floating point operations.
130
+ and theoretical estimates of the relative cost of different floating point operations.
131
+
132
+ See [fpu_data_sources.md](https://github.com/bertpl/counted-float/tree/develop/docs/analysis_methodology.md) for
133
+ rationale behind choice of data sources and methodology.
131
134
 
132
135
  ```
133
136
  >>> from counted_float.config import get_flop_weights
@@ -140,7 +143,7 @@ and theoretical estimates of the relative cost of different floating point opera
140
143
  FlopType.GTE [x>=y] : 1
141
144
  FlopType.LTE [x<=y] : 1
142
145
  FlopType.CMP_ZERO [x>=0] : 1
143
- FlopType.RND [round(x)] : 1
146
+ FlopType.RND [round(x,0)] : 1
144
147
  FlopType.ADD [x+y] : 1
145
148
  FlopType.SUB [x-y] : 1
146
149
  FlopType.MUL [x*y] : 1
@@ -203,7 +206,7 @@ from counted_float.config import get_default_empirical_flop_weights, get_default
203
206
  FlopType.GTE [x>=y] : 0.94684
204
207
  FlopType.LTE [x<=y] : 0.93101
205
208
  FlopType.CMP_ZERO [x>=0] : 0.82204
206
- FlopType.RND [round(x)] : 0.96944
209
+ FlopType.RND [round(x,0)] : 0.96944
207
210
  FlopType.ADD [x+y] : 0.89296
208
211
  FlopType.SUB [x-y] : 1.14383
209
212
  FlopType.MUL [x*y] : 1.04677
@@ -234,7 +237,7 @@ from counted_float.config import get_builtin_flop_weights
234
237
  FlopType.GTE [x>=y] : 0.89744
235
238
  FlopType.LTE [x<=y] : 0.89744
236
239
  FlopType.CMP_ZERO [x>=0] : 0.84762
237
- FlopType.RND [round(x)] : 2.63592
240
+ FlopType.RND [round(x,0)] : 2.63592
238
241
  FlopType.ADD [x+y] : 0.86616
239
242
  FlopType.SUB [x-y] : 1.10411
240
243
  FlopType.MUL [x*y] : 1.16515
@@ -260,43 +263,43 @@ floating point operations as follows:
260
263
  >>> from counted_float.benchmarking import run_flops_benchmark
261
264
  >>> results = run_flops_benchmark()
262
265
 
263
- Running FLOPS benchmarks using counted-float 0.9.2 ...
264
-
265
- baseline : wwwwwwwwww.................... ( 187.03 ns = 759 cpu cycles) ± 0.6% / 1000 iterations
266
- FlopType.ABS [abs(x)] : wwwwwwwwww.................... ( 303.31 ns = 1.23K cpu cycles) ± 1.7% / 1000 iterations
267
- FlopType.CMP_ZERO [x>=0] : wwwwwwwwww.................... ( 302.19 ns = 1.23K cpu cycles) ± 3.0% / 1000 iterations
268
- FlopType.RND [round(x)] : wwwwwwwwww.................... ( 305.95 ns = 1.24K cpu cycles) ± 4.8% / 1000 iterations
269
- FlopType.MINUS [-x] : wwwwwwwwww.................... ( 306.31 ns = 1.24K cpu cycles) ± 2.6% / 1000 iterations
270
- FlopType.EQUALS [x==y] : wwwwwwwwww.................... ( 320.59 ns = 1.30K cpu cycles) ± 3.9% / 1000 iterations
271
- FlopType.GTE [x>=y] : wwwwwwwwww.................... ( 331.51 ns = 1.34K cpu cycles) ± 2.9% / 1000 iterations
272
- FlopType.LTE [x<=y] : wwwwwwwwww.................... ( 333.81 ns = 1.35K cpu cycles) ± 1.0% / 1000 iterations
273
- FlopType.ADD [x+y] : wwwwwwwwww.................... ( 315.84 ns = 1.28K cpu cycles) ± 3.2% / 1000 iterations
274
- FlopType.SUB [x-y] : wwwwwwwwww.................... ( 335.49 ns = 1.36K cpu cycles) ± 3.8% / 1000 iterations
275
- FlopType.MUL [x*y] : wwwwwwwwww.................... ( 325.65 ns = 1.32K cpu cycles) ± 3.0% / 1000 iterations
276
- FlopType.SQRT [sqrt(x)] : wwwwwwwwww.................... ( 443.30 ns = 1.80K cpu cycles) ± 2.6% / 1000 iterations
277
- FlopType.DIV [x/y] : wwwwwwwwww.................... ( 491.51 ns = 1.99K cpu cycles) ± 1.1% / 1000 iterations
278
- FlopType.POW2 [2^x] : wwwwwwwwww.................... ( 1.79 µs = 7.28K cpu cycles) ± 0.3% / 1000 iterations
279
- FlopType.LOG2 [log2(x)] : wwwwwwwwww.................... ( 2.17 µs = 8.80K cpu cycles) ± 0.8% / 1000 iterations
280
- FlopType.POW [x^y] : wwwwwwwwww.................... ( 6.32 µs = 25.6K cpu cycles) ± 0.7% / 1000 iterations
266
+ Running FLOPS benchmarks using counted-float 0.9.4 ...
267
+
268
+ baseline : wwwwwwwwww.................... [ 177.53 ns ± 2.0% | 720 cpu cycles ± 2.0% ] / 1000 iterations
269
+ FlopType.ABS [abs(x)] : wwwwwwwwww.................... [ 286.71 ns ± 5.7% | 1.16K cpu cycles ± 5.7% ] / 1000 iterations
270
+ FlopType.CMP_ZERO [x>=0] : wwwwwwwwww.................... [ 294.71 ns ± 3.6% | 1.20K cpu cycles ± 3.6% ] / 1000 iterations
271
+ FlopType.RND [round(x,0)] : wwwwwwwwww.................... [ 291.74 ns ± 6.1% | 1.18K cpu cycles ± 6.1% ] / 1000 iterations
272
+ FlopType.MINUS [-x] : wwwwwwwwww.................... [ 291.81 ns ± 5.8% | 1.18K cpu cycles ± 5.8% ] / 1000 iterations
273
+ FlopType.EQUALS [x==y] : wwwwwwwwww.................... [ 297.70 ns ± 4.2% | 1.21K cpu cycles ± 4.2% ] / 1000 iterations
274
+ FlopType.GTE [x>=y] : wwwwwwwwww.................... [ 301.59 ns ± 3.2% | 1.22K cpu cycles ± 3.2% ] / 1000 iterations
275
+ FlopType.LTE [x<=y] : wwwwwwwwww.................... [ 295.77 ns ± 2.2% | 1.20K cpu cycles ± 2.2% ] / 1000 iterations
276
+ FlopType.ADD [x+y] : wwwwwwwwww.................... [ 289.49 ns ± 2.6% | 1.17K cpu cycles ± 2.6% ] / 1000 iterations
277
+ FlopType.SUB [x-y] : wwwwwwwwww.................... [ 289.85 ns ± 1.7% | 1.18K cpu cycles ± 1.7% ] / 1000 iterations
278
+ FlopType.MUL [x*y] : wwwwwwwwww.................... [ 305.46 ns ± 2.8% | 1.24K cpu cycles ± 2.8% ] / 1000 iterations
279
+ FlopType.SQRT [sqrt(x)] : wwwwwwwwww.................... [ 435.30 ns ± 0.5% | 1.77K cpu cycles ± 0.5% ] / 1000 iterations
280
+ FlopType.DIV [x/y] : wwwwwwwwww.................... [ 479.90 ns ± 1.2% | 1.95K cpu cycles ± 1.2% ] / 1000 iterations
281
+ FlopType.POW2 [2^x] : wwwwwwwwww.................... [ 1.78 µs ± 0.1% | 7.22K cpu cycles ± 0.1% ] / 1000 iterations
282
+ FlopType.LOG2 [log2(x)] : wwwwwwwwww.................... [ 2.17 µs ± 0.6% | 8.80K cpu cycles ± 0.6% ] / 1000 iterations
283
+ FlopType.POW [x^y] : wwwwwwwwww.................... [ 6.14 µs ± 0.4% | 24.9K cpu cycles ± 0.4% ] / 1000 iterations
281
284
 
282
285
  >>> results.flop_weights.show()
283
286
 
284
287
  {
285
- FlopType.ABS [abs(x)] : 0.84769
286
- FlopType.MINUS [-x] : 0.86954
287
- FlopType.EQUALS [x==y] : 0.97369
288
- FlopType.GTE [x>=y] : 1.05327
289
- FlopType.LTE [x<=y] : 1.07007
290
- FlopType.CMP_ZERO [x>=0] : 0.83957
291
- FlopType.RND [round(x)] : 0.86695
292
- FlopType.ADD [x+y] : 0.93905
293
- FlopType.SUB [x-y] : 1.08227
294
- FlopType.MUL [x*y] : 1.01055
295
- FlopType.DIV [x/y] : 2.21970
296
- FlopType.SQRT [sqrt(x)] : 1.86822
297
- FlopType.POW2 [2^x] : 11.72183
298
- FlopType.LOG2 [log2(x)] : 14.45542
299
- FlopType.POW [x^y] : 44.68266
288
+ FlopType.ABS [abs(x)] : 0.97517
289
+ FlopType.MINUS [-x] : 1.02074
290
+ FlopType.EQUALS [x==y] : 1.07339
291
+ FlopType.GTE [x>=y] : 1.10812
292
+ FlopType.LTE [x<=y] : 1.05609
293
+ FlopType.CMP_ZERO [x>=0] : 1.04665
294
+ FlopType.RND [round(x,0)] : 1.02017
295
+ FlopType.ADD [x+y] : 1.00000
296
+ FlopType.SUB [x-y] : 1.00328
297
+ FlopType.MUL [x*y] : 1.14268
298
+ FlopType.DIV [x/y] : 2.70079
299
+ FlopType.SQRT [sqrt(x)] : 2.30238
300
+ FlopType.POW2 [2^x] : 14.30722
301
+ FlopType.LOG2 [log2(x)] : 17.79592
302
+ FlopType.POW [x^y] : 53.26393
300
303
  }
301
304
  ```
302
305
 
@@ -311,7 +314,7 @@ uv tool install git+https://github.com/bertpl/counted-float@develop[numba,cli]
311
314
  ```
312
315
  This installs the `counted_float` command-line tool, which can be used to e.g. run flops benchmarks.
313
316
 
314
- ## 4.1 Running benchmarks
317
+ ## 4.1. Running benchmarks
315
318
 
316
319
  ```
317
320
  counted_float benchmark
@@ -5,10 +5,9 @@ from ._core.counting import BuiltInData, CountedFloat, FlopCountingContext, Paus
5
5
  from ._core.models import (
6
6
  FlopCounts,
7
7
  FlopsBenchmarkDurations,
8
- FlopsBenchmarkResults,
8
+ FlopsBenchmarkResults_V1,
9
9
  FlopType,
10
10
  FlopWeights,
11
- FPUInstruction,
12
11
  Quantiles,
13
12
  SystemInfo,
14
13
  )
@@ -20,10 +19,9 @@ __all__ = [
20
19
  "FlopCountingContext",
21
20
  "FlopCounts",
22
21
  "FlopsBenchmarkDurations",
23
- "FlopsBenchmarkResults",
22
+ "FlopsBenchmarkResults_V1",
24
23
  "FlopType",
25
24
  "FlopWeights",
26
- "FPUInstruction",
27
25
  "PauseFlopCounting",
28
26
  "Quantiles",
29
27
  "SystemInfo",
@@ -1,11 +1,9 @@
1
1
  from importlib.metadata import version
2
2
 
3
- from counted_float._core.models import FlopsBenchmarkResults
3
+ from .flops import FlopsBenchmarkResults_V2, FlopsBenchmarkSuite
4
4
 
5
- from ._flops_benchmark_suite import FlopsBenchmarkSuite
6
5
 
7
-
8
- def run_flops_benchmark() -> FlopsBenchmarkResults:
6
+ def run_flops_benchmark() -> FlopsBenchmarkResults_V2:
9
7
  """Run the flops benchmark suite with default settings returns a FlopsBenchmarkResults object."""
10
8
 
11
9
  print()
@@ -0,0 +1,3 @@
1
+ from ._array_generator import ArrayGenerator
2
+ from ._flops_benchmark_suite import FlopsBenchmarkResults_V2, FlopsBenchmarkSuite
3
+ from ._flops_micro_benchmark import FlopsMicroBenchmark
@@ -0,0 +1,76 @@
1
+ from __future__ import annotations
2
+
3
+ import random
4
+ from abc import ABC, abstractmethod
5
+
6
+ import numpy as np
7
+
8
+
9
+ # =================================================================================================
10
+ # Base class
11
+ # =================================================================================================
12
+ class ArrayGenerator(ABC):
13
+ # -------------------------------------------------------------------------
14
+ # API
15
+ # -------------------------------------------------------------------------
16
+ @abstractmethod
17
+ def new_array(self, size: int) -> np.ndarray:
18
+ """Generates random 1D numpy array of requested size"""
19
+ raise NotImplementedError
20
+
21
+ # -------------------------------------------------------------------------
22
+ # Factory Methods
23
+ # -------------------------------------------------------------------------
24
+ @classmethod
25
+ def lin_range(cls, min_value: float, max_value: float) -> ArrayGenerator:
26
+ return ArrayGeneratorLinear(min_value, max_value)
27
+
28
+ @classmethod
29
+ def log_range(cls, min_value: float, max_value: float) -> ArrayGenerator:
30
+ return ArrayGeneratorLog(min_value, max_value)
31
+
32
+
33
+ # =================================================================================================
34
+ # Implementations
35
+ # =================================================================================================
36
+ class ArrayGeneratorLinear(ArrayGenerator):
37
+ def __init__(self, min_value: float, max_value: float):
38
+ """Array generator, where values are in interval [min_value, max_value] with avg. equal to mid-point."""
39
+ self.min_value = min_value
40
+ self.max_value = max_value
41
+
42
+ def new_array(self, size: int) -> np.ndarray:
43
+ uniform_values = 0.5 * (1.0 + _random_balanced_values(size)) # uniform random values in [0,1]
44
+ return self.min_value + uniform_values * (self.max_value - self.min_value)
45
+
46
+
47
+ class ArrayGeneratorLog(ArrayGenerator):
48
+ def __init__(self, min_value: float, max_value: float):
49
+ """Array generator, where values are in interval [min_value, max_value] with geomean of values eq. to geo-mid"""
50
+ self.min_value = min_value
51
+ self.max_value = max_value
52
+
53
+ def new_array(self, size: int) -> np.ndarray:
54
+ uniform_values = 0.5 * (1.0 + _random_balanced_values(size)) # uniform random values in [0,1]
55
+ return self.min_value * (self.max_value / self.min_value) ** uniform_values
56
+
57
+
58
+ # =================================================================================================
59
+ # Helpers
60
+ # =================================================================================================
61
+ def _random_balanced_values(size: int) -> np.ndarray:
62
+ """
63
+ Returns random values in [-1,1], such that...
64
+ - mean value == 0.0
65
+ - cumulative sum of any arbitrary first n values also lies within [-1,1]
66
+ """
67
+ cumsum = 0.0
68
+ lst = []
69
+ for i in range(size - 1):
70
+ next_min_value = max(-1.0, -1.0 - cumsum)
71
+ next_max_value = min(1.0, 1.0 - cumsum)
72
+ next_value = random.uniform(next_min_value, next_max_value)
73
+ lst.append(next_value)
74
+ cumsum += next_value
75
+ lst.append(-cumsum)
76
+ return np.array(lst)