Skip to content

Commit

Permalink
Merge pull request #731 from pq-code-package/multi_simp
Browse files Browse the repository at this point in the history
Simplify configurations in multilevel example
  • Loading branch information
hanno-becker authored Feb 2, 2025
2 parents b6ad677 + 378f65c commit f205192
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 263 deletions.
15 changes: 9 additions & 6 deletions examples/monolithic_build_multilevel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ files. Moreover, it clears all `#define`s clauses set by mlkem-native at the end
inclusion in another compilation unit.

The manually written source file [mlkem_native_all.c](mlkem_native_all.c) includes
[mlkem_native_monobuild.c](mlkem_native_monobuild.c) three times, once for each of the three configuration files
[config_512.h](config_512.h), [config_768.h](config_768.h),
[config_1024.h](config_1024.h) for the different levels. For each inclusion, it sets `MLKEM_NATIVE_CONFIG_FILE`
[mlkem_native_monobuild.c](mlkem_native_monobuild.c) three times, each time using the fixed config
[multilevel_config.h](multilevel_config.h), but changing the security level (specified
by `MLKEM_K`) every time. For each inclusion, it sets `MLKEM_NATIVE_CONFIG_FILE`
appropriately first, and then includes the monobuild:
```C
/* Three instances of mlkem-native for all security levels */
Expand All @@ -21,19 +21,22 @@ appropriately first, and then includes the monobuild:
#define MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS

#define MLKEM_NATIVE_CONFIG_FILE "config_512.h"
#define MLKEM_K 2
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

/* Exclude level-independent code */
#undef MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MULTILEVEL_BUILD_NO_SHARED

#define MLKEM_NATIVE_CONFIG_FILE "config_1024.h"
#define MLKEM_K 3
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

#define MLKEM_NATIVE_CONFIG_FILE "config_768.h"
#define MLKEM_K 4
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#undef MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE
Expand Down
118 changes: 0 additions & 118 deletions examples/monolithic_build_multilevel/config_1024.h

This file was deleted.

135 changes: 0 additions & 135 deletions examples/monolithic_build_multilevel/config_512.h

This file was deleted.

9 changes: 6 additions & 3 deletions examples/monolithic_build_multilevel/mlkem_native_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
#define MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS

#define MLKEM_NATIVE_CONFIG_FILE "config_512.h"
#define MLKEM_K 2
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

/* Exclude level-independent code */
#undef MLKEM_NATIVE_MULTILEVEL_BUILD_WITH_SHARED
#define MLKEM_NATIVE_MULTILEVEL_BUILD_NO_SHARED

#define MLKEM_NATIVE_CONFIG_FILE "config_1024.h"
#define MLKEM_K 3
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE

#define MLKEM_NATIVE_CONFIG_FILE "config_768.h"
#define MLKEM_K 4
#define MLKEM_NATIVE_CONFIG_FILE "multilevel_config.h"
#undef MLKEM_NATIVE_MONOBUILD_KEEP_SHARED_HEADERS
#include "mlkem_native_monobuild.c"
#undef MLKEM_NATIVE_CONFIG_FILE
2 changes: 1 addition & 1 deletion scripts/simpasm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def find_header_footer(asm, filename):
def find_globals(asm):
global_symbols = []
for l in asm:
r = re.search("^\s*\.global\s+(.*)$", l)
r = re.search(r"^\s*\.global\s+(.*)$", l)
if r is None:
continue
global_symbols.append(r.group(1))
Expand Down

18 comments on commit f205192

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intel Xeon 4th gen (c7i)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 9305 cycles 9293 cycles 1.00
ML-KEM-512 encaps 10836 cycles 10795 cycles 1.00
ML-KEM-512 decaps 14796 cycles 14761 cycles 1.00
ML-KEM-768 keypair 15863 cycles 15953 cycles 0.99
ML-KEM-768 encaps 17162 cycles 17246 cycles 1.00
ML-KEM-768 decaps 22853 cycles 22934 cycles 1.00
ML-KEM-1024 keypair 21319 cycles 21315 cycles 1.00
ML-KEM-1024 encaps 23256 cycles 23268 cycles 1.00
ML-KEM-1024 decaps 30705 cycles 30732 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arm Cortex-A76 (Raspberry Pi 5) benchmarks

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 28941 cycles 28947 cycles 1.00
ML-KEM-512 encaps 34281 cycles 34270 cycles 1.00
ML-KEM-512 decaps 44766 cycles 44769 cycles 1.00
ML-KEM-768 keypair 49281 cycles 49281 cycles 1
ML-KEM-768 encaps 54588 cycles 54590 cycles 1.00
ML-KEM-768 decaps 69409 cycles 69408 cycles 1.00
ML-KEM-1024 keypair 71913 cycles 71910 cycles 1.00
ML-KEM-1024 encaps 80615 cycles 80612 cycles 1.00
ML-KEM-1024 decaps 100361 cycles 100356 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intel Xeon 4th gen (c7i) (no-opt)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 29649 cycles 29636 cycles 1.00
ML-KEM-512 encaps 35326 cycles 35300 cycles 1.00
ML-KEM-512 decaps 45910 cycles 45995 cycles 1.00
ML-KEM-768 keypair 47211 cycles 47126 cycles 1.00
ML-KEM-768 encaps 55622 cycles 55591 cycles 1.00
ML-KEM-768 decaps 67646 cycles 67579 cycles 1.00
ML-KEM-1024 keypair 71739 cycles 71804 cycles 1.00
ML-KEM-1024 encaps 82019 cycles 82219 cycles 1.00
ML-KEM-1024 decaps 99307 cycles 99455 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMD EPYC 4th gen (c7a)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 11276 cycles 11277 cycles 1.00
ML-KEM-512 encaps 12843 cycles 12825 cycles 1.00
ML-KEM-512 decaps 17668 cycles 17693 cycles 1.00
ML-KEM-768 keypair 19601 cycles 19622 cycles 1.00
ML-KEM-768 encaps 20582 cycles 20597 cycles 1.00
ML-KEM-768 decaps 27697 cycles 27681 cycles 1.00
ML-KEM-1024 keypair 26351 cycles 26376 cycles 1.00
ML-KEM-1024 encaps 28157 cycles 28163 cycles 1.00
ML-KEM-1024 decaps 37649 cycles 37645 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intel Xeon 3rd gen (c6i)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 15908 cycles 15918 cycles 1.00
ML-KEM-512 encaps 18024 cycles 18028 cycles 1.00
ML-KEM-512 decaps 24503 cycles 24511 cycles 1.00
ML-KEM-768 keypair 27351 cycles 27367 cycles 1.00
ML-KEM-768 encaps 28948 cycles 28959 cycles 1.00
ML-KEM-768 decaps 38371 cycles 38387 cycles 1.00
ML-KEM-1024 keypair 36924 cycles 36994 cycles 1.00
ML-KEM-1024 encaps 39879 cycles 39941 cycles 1.00
ML-KEM-1024 decaps 52323 cycles 52416 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMD EPYC 3rd gen (c6a)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 16968 cycles 16976 cycles 1.00
ML-KEM-512 encaps 18660 cycles 18670 cycles 1.00
ML-KEM-512 decaps 24053 cycles 24013 cycles 1.00
ML-KEM-768 keypair 28713 cycles 28762 cycles 1.00
ML-KEM-768 encaps 29885 cycles 29830 cycles 1.00
ML-KEM-768 decaps 37600 cycles 37565 cycles 1.00
ML-KEM-1024 keypair 41711 cycles 41952 cycles 0.99
ML-KEM-1024 encaps 43859 cycles 43967 cycles 1.00
ML-KEM-1024 decaps 54184 cycles 54155 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graviton4

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 17729 cycles 17724 cycles 1.00
ML-KEM-512 encaps 20974 cycles 20976 cycles 1.00
ML-KEM-512 decaps 27656 cycles 27652 cycles 1.00
ML-KEM-768 keypair 30514 cycles 30515 cycles 1.00
ML-KEM-768 encaps 33408 cycles 33406 cycles 1.00
ML-KEM-768 decaps 42990 cycles 42989 cycles 1.00
ML-KEM-1024 keypair 44137 cycles 44136 cycles 1.00
ML-KEM-1024 encaps 49440 cycles 49417 cycles 1.00
ML-KEM-1024 decaps 62366 cycles 62344 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMD EPYC 4th gen (c7a) (no-opt)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 36068 cycles 36077 cycles 1.00
ML-KEM-512 encaps 42300 cycles 42310 cycles 1.00
ML-KEM-512 decaps 55417 cycles 55439 cycles 1.00
ML-KEM-768 keypair 58471 cycles 58485 cycles 1.00
ML-KEM-768 encaps 66926 cycles 66962 cycles 1.00
ML-KEM-768 decaps 84172 cycles 84598 cycles 0.99
ML-KEM-1024 keypair 86479 cycles 86565 cycles 1.00
ML-KEM-1024 encaps 97191 cycles 97227 cycles 1.00
ML-KEM-1024 decaps 118867 cycles 118852 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graviton2

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 28948 cycles 28943 cycles 1.00
ML-KEM-512 encaps 34283 cycles 34277 cycles 1.00
ML-KEM-512 decaps 44784 cycles 44782 cycles 1.00
ML-KEM-768 keypair 49252 cycles 49252 cycles 1
ML-KEM-768 encaps 54606 cycles 54610 cycles 1.00
ML-KEM-768 decaps 69450 cycles 69446 cycles 1.00
ML-KEM-1024 keypair 71939 cycles 71912 cycles 1.00
ML-KEM-1024 encaps 80611 cycles 80593 cycles 1.00
ML-KEM-1024 decaps 100413 cycles 100446 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intel Xeon 3rd gen (c6i) (no-opt)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 46461 cycles 46502 cycles 1.00
ML-KEM-512 encaps 54610 cycles 54682 cycles 1.00
ML-KEM-512 decaps 70324 cycles 70417 cycles 1.00
ML-KEM-768 keypair 76718 cycles 76744 cycles 1.00
ML-KEM-768 encaps 87413 cycles 87371 cycles 1.00
ML-KEM-768 decaps 107834 cycles 107836 cycles 1.00
ML-KEM-1024 keypair 112127 cycles 112227 cycles 1.00
ML-KEM-1024 encaps 126181 cycles 126287 cycles 1.00
ML-KEM-1024 decaps 152297 cycles 152374 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graviton3

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 18928 cycles 18928 cycles 1
ML-KEM-512 encaps 22417 cycles 22415 cycles 1.00
ML-KEM-512 decaps 29689 cycles 29688 cycles 1.00
ML-KEM-768 keypair 32305 cycles 32297 cycles 1.00
ML-KEM-768 encaps 35802 cycles 35804 cycles 1.00
ML-KEM-768 decaps 46196 cycles 46198 cycles 1.00
ML-KEM-1024 keypair 46630 cycles 46627 cycles 1.00
ML-KEM-1024 encaps 52317 cycles 52313 cycles 1.00
ML-KEM-1024 decaps 66363 cycles 66363 cycles 1

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMD EPYC 3rd gen (c6a) (no-opt)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 39477 cycles 39485 cycles 1.00
ML-KEM-512 encaps 47507 cycles 47496 cycles 1.00
ML-KEM-512 decaps 61788 cycles 61771 cycles 1.00
ML-KEM-768 keypair 63993 cycles 63925 cycles 1.00
ML-KEM-768 encaps 75363 cycles 75259 cycles 1.00
ML-KEM-768 decaps 93779 cycles 93878 cycles 1.00
ML-KEM-1024 keypair 95495 cycles 95476 cycles 1.00
ML-KEM-1024 encaps 108988 cycles 108949 cycles 1.00
ML-KEM-1024 decaps 132517 cycles 132457 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graviton4 (no-opt)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 35498 cycles 35500 cycles 1.00
ML-KEM-512 encaps 40668 cycles 40671 cycles 1.00
ML-KEM-512 decaps 51619 cycles 51626 cycles 1.00
ML-KEM-768 keypair 58461 cycles 58468 cycles 1.00
ML-KEM-768 encaps 65223 cycles 65229 cycles 1.00
ML-KEM-768 decaps 80477 cycles 80480 cycles 1.00
ML-KEM-1024 keypair 88148 cycles 88187 cycles 1.00
ML-KEM-1024 encaps 96944 cycles 96961 cycles 1.00
ML-KEM-1024 decaps 116627 cycles 116642 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graviton3 (no-opt)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 38656 cycles 38650 cycles 1.00
ML-KEM-512 encaps 44348 cycles 44344 cycles 1.00
ML-KEM-512 decaps 56142 cycles 56133 cycles 1.00
ML-KEM-768 keypair 63869 cycles 63864 cycles 1.00
ML-KEM-768 encaps 70973 cycles 70977 cycles 1.00
ML-KEM-768 decaps 86861 cycles 86857 cycles 1.00
ML-KEM-1024 keypair 95393 cycles 95396 cycles 1.00
ML-KEM-1024 encaps 105316 cycles 105312 cycles 1.00
ML-KEM-1024 decaps 125680 cycles 125687 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graviton2 (no-opt)

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 58971 cycles 59001 cycles 1.00
ML-KEM-512 encaps 67322 cycles 67356 cycles 1.00
ML-KEM-512 decaps 86110 cycles 86143 cycles 1.00
ML-KEM-768 keypair 98360 cycles 98395 cycles 1.00
ML-KEM-768 encaps 109161 cycles 109191 cycles 1.00
ML-KEM-768 decaps 133934 cycles 133942 cycles 1.00
ML-KEM-1024 keypair 147095 cycles 147064 cycles 1.00
ML-KEM-1024 encaps 162142 cycles 162116 cycles 1.00
ML-KEM-1024 decaps 193712 cycles 193709 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arm Cortex-A55 (Snapdragon 888) benchmarks

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 58158 cycles 58115 cycles 1.00
ML-KEM-512 encaps 65022 cycles 64926 cycles 1.00
ML-KEM-512 decaps 83839 cycles 83794 cycles 1.00
ML-KEM-768 keypair 98885 cycles 98871 cycles 1.00
ML-KEM-768 encaps 109473 cycles 109577 cycles 1.00
ML-KEM-768 decaps 136942 cycles 136187 cycles 1.01
ML-KEM-1024 keypair 149812 cycles 149786 cycles 1.00
ML-KEM-1024 encaps 165652 cycles 165618 cycles 1.00
ML-KEM-1024 decaps 202100 cycles 202067 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bananapi bpi-f3 benchmarks

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 309316 cycles 309316 cycles 1
ML-KEM-512 encaps 413090 cycles 413078 cycles 1.00
ML-KEM-512 decaps 554909 cycles 554947 cycles 1.00
ML-KEM-768 keypair 506870 cycles 506892 cycles 1.00
ML-KEM-768 encaps 637024 cycles 637152 cycles 1.00
ML-KEM-768 decaps 819064 cycles 819201 cycles 1.00
ML-KEM-1024 keypair 733249 cycles 733290 cycles 1.00
ML-KEM-1024 encaps 893777 cycles 893808 cycles 1.00
ML-KEM-1024 decaps 1109753 cycles 1109652 cycles 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@oqs-bot
Copy link

@oqs-bot oqs-bot commented on f205192 Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arm Cortex-A72 (Raspberry Pi 4) benchmarks

Benchmark suite Current: f205192 Previous: b6ad677 Ratio
ML-KEM-512 keypair 51667 cycles 52707 cycles 0.98
ML-KEM-512 encaps 58993 cycles 59812 cycles 0.99
ML-KEM-512 decaps 75949 cycles 76956 cycles 0.99
ML-KEM-768 keypair 88094 cycles 87638 cycles 1.01
ML-KEM-768 encaps 95562 cycles 94948 cycles 1.01
ML-KEM-768 decaps 120510 cycles 118662 cycles 1.02
ML-KEM-1024 keypair 131384 cycles 131931 cycles 1.00
ML-KEM-1024 encaps 144003 cycles 144326 cycles 1.00
ML-KEM-1024 decaps 177386 cycles 175854 cycles 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.