Skip to content

Commit

Permalink
Crypto: Benchmarks: Accept input size as a runtime argument from user…
Browse files Browse the repository at this point in the history
… (#1057)

* Crypto: Benchmarks: Accept input size as a runtime argument from the user

-- User can provide input size as a runtime argument like:
   -b 64 or --block_size=64
-- if this is not provided, it will use the default blocksizes from a list.
-- This change is not enabled for Rsa, and EC benchmarks
-- Also not all block sizes may work for IPP Benchmarks
-- Fixed help option

Signed-off-by: Pranoy Jayaraj <[email protected]>
  • Loading branch information
pjayaraj-amd authored and GitHub Enterprise committed Oct 30, 2024
1 parent 7e5e450 commit cf28a98
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 33 deletions.
10 changes: 7 additions & 3 deletions bench/cipher/bench_cipher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@ BENCH_CHACHA20_POLY1305_DECRYPT_256(benchmark::State& state)
int
AddBenchmarks()
{
/* check if custom block size is provided by user */
if (block_size != 0) {
std::cout << "Custom block size selected:" << block_size << std::endl;
blocksizes.resize(1);
blocksizes[0] = block_size;
}
/* IPPCP doesnt have Chacha20 stream cipher variant yet */
if (!useipp) {
BENCHMARK(BENCH_CHACHA20_ENCRYPT_256)->ArgsProduct({ blocksizes });
Expand Down Expand Up @@ -638,7 +644,7 @@ AddBenchmarks()
int
main(int argc, char** argv)
{
parseArgs(&argc, argv);
parseArgs(argc, argv);
#ifndef USE_IPP
if (useipp) {
alcp::testing::utils::printErrors(
Expand All @@ -653,8 +659,6 @@ main(int argc, char** argv)
#endif
AddBenchmarks();
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
return 1;
::benchmark::RunSpecifiedBenchmarks();

return 0;
Expand Down
4 changes: 1 addition & 3 deletions bench/cmac/bench_cmac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
int
main(int argc, char** argv)
{
parseArgs(&argc, argv);
parseArgs(argc, argv);
#ifndef USE_IPP
if (useipp) {
std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
Expand All @@ -48,8 +48,6 @@ main(int argc, char** argv)
#endif
AddBenchmarks_Cmac();
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
return 1;
::benchmark::RunSpecifiedBenchmarks();
return 0;
}
6 changes: 6 additions & 0 deletions bench/cmac/include/benchmarks_cmac.hh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ BENCH_CMAC_AES_256(benchmark::State& state)
int
AddBenchmarks_Cmac()
{
/* check if custom block size is provided by user */
if (block_size != 0) {
std::cout << "Custom block size selected:" << block_size << std::endl;
cmac_block_sizes.resize(1);
cmac_block_sizes[0] = block_size;
}
BENCHMARK(BENCH_CMAC_AES_128)->ArgsProduct({ cmac_block_sizes });
BENCHMARK(BENCH_CMAC_AES_192)->ArgsProduct({ cmac_block_sizes });
BENCHMARK(BENCH_CMAC_AES_256)->ArgsProduct({ cmac_block_sizes });
Expand Down
4 changes: 1 addition & 3 deletions bench/digest/bench_digest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
int
main(int argc, char** argv)
{
parseArgs(&argc, argv);
parseArgs(argc, argv);
#ifndef USE_IPP
if (useipp) {
std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
Expand All @@ -48,8 +48,6 @@ main(int argc, char** argv)
#endif
AddBenchmarks();
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
return 1;
::benchmark::RunSpecifiedBenchmarks();
return 0;
}
6 changes: 6 additions & 0 deletions bench/digest/include/benchmarks_digest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ BENCH_SHAKE_256(benchmark::State& state)
int
AddBenchmarks()
{
/* check if custom block size is provided by user */
if (block_size != 0) {
std::cout << "Custom block size selected:" << block_size << std::endl;
digest_block_sizes.resize(1);
digest_block_sizes[0] = block_size;
}
BENCHMARK(BENCH_SHA2_224)->ArgsProduct({ digest_block_sizes });
BENCHMARK(BENCH_SHA2_256)->ArgsProduct({ digest_block_sizes });
BENCHMARK(BENCH_SHA2_384)->ArgsProduct({ digest_block_sizes });
Expand Down
2 changes: 1 addition & 1 deletion bench/ecdh/bench_ecdh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
int
main(int argc, char** argv)
{
parseArgs(&argc, argv);
parseArgs(argc, argv);
#ifndef USE_IPP
if (useipp) {
std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
Expand Down
4 changes: 1 addition & 3 deletions bench/hmac/bench_hmac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
int
main(int argc, char** argv)
{
parseArgs(&argc, argv);
parseArgs(argc, argv);
#ifndef USE_IPP
if (useipp) {
std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
Expand All @@ -48,8 +48,6 @@ main(int argc, char** argv)
#endif
AddBenchmarks();
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
return 1;
::benchmark::RunSpecifiedBenchmarks();
return 0;
}
6 changes: 6 additions & 0 deletions bench/hmac/include/benchmarks_hmac.hh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ BENCH_HMAC_SHA3_512(benchmark::State& state)
int
AddBenchmarks()
{
/* check if custom block size is provided by user */
if (block_size != 0) {
std::cout << "Custom block size selected:" << block_size << std::endl;
hmac_block_sizes.resize(1);
hmac_block_sizes[0] = block_size;
}
BENCHMARK(BENCH_HMAC_SHA2_224)->ArgsProduct({ hmac_block_sizes });
BENCHMARK(BENCH_HMAC_SHA2_256)->ArgsProduct({ hmac_block_sizes });
BENCHMARK(BENCH_HMAC_SHA2_384)->ArgsProduct({ hmac_block_sizes });
Expand Down
4 changes: 1 addition & 3 deletions bench/poly1305/bench_poly1305.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
int
main(int argc, char** argv)
{
parseArgs(&argc, argv);
parseArgs(argc, argv);
#ifndef USE_OSSL
if (useossl) {
std::cout << RED << "Error OpenSSL not found defaulting to ALCP"
Expand All @@ -42,8 +42,6 @@ main(int argc, char** argv)
#endif
AddBenchmarks_Poly1305();
::benchmark::Initialize(&argc, argv);
if (::benchmark::ReportUnrecognizedArguments(argc, argv))
return 1;
::benchmark::RunSpecifiedBenchmarks();
return 0;
}
6 changes: 6 additions & 0 deletions bench/poly1305/include/bench_poly1305.hh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ BENCH_POLY1305(benchmark::State& state)
int
AddBenchmarks_Poly1305()
{
/* check if custom block size is provided by user */
if (block_size != 0) {
std::cout << "Custom block size selected:" << block_size << std::endl;
poly1305_blocksizes.resize(1);
poly1305_blocksizes[0] = block_size;
}
/* ippcp doesnt have poly1305 mac implementations yet */
if (!useipp)
BENCHMARK(BENCH_POLY1305)->ArgsProduct({ poly1305_blocksizes });
Expand Down
2 changes: 1 addition & 1 deletion bench/rsa/bench_rsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
int
main(int argc, char** argv)
{
parseArgs(&argc, argv);
parseArgs(argc, argv);
#ifndef USE_IPP
if (useipp) {
std::cout << RED << "Error IPP not found defaulting to ALCP" << RESET
Expand Down
41 changes: 25 additions & 16 deletions tests/common/include/gbench_base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,47 @@
#include <iostream>
#include <string>

static int verbose = 0;
static bool useipp = false;
static bool useossl = false;
/*default blk size*/
static int block_size = 0;

void
parseArgs(int* argc, char** argv)
parseArgs(int argc, char** argv)
{
std::string currentArg;
const int _argc = *argc;
if (*argc > 1) {
for (int i = 1; i < _argc; i++) {
std::string temp;

if (argc > 1) {
for (int i = 1; i < argc; i++) {
currentArg = std::string(argv[i]);
if ((currentArg == std::string("--help"))
|| (currentArg == std::string("-h"))) {
std::cout << std::endl
<< "Additional help for microbenches" << std::endl;
std::cout << "Append these after gtest arguments only"
std::cout << "--use-ipp or -i for benching IPPCP" << std::endl;
std::cout << "--use-ossl or -o for benching OpenSSL"
<< std::endl;
std::cout << "--verbose or -v per line status." << std::endl;
std::cout << "--use-ipp or -i force IPP use in testing."
std::cout << "-b <Custom block size> for providing custom "
"input size to benchmark"
<< std::endl;
} else if ((currentArg == std::string("--verbose"))
|| (currentArg == std::string("-v"))) {
verbose = 1;
*argc -= 1;
exit(-1);
} else if ((currentArg == std::string("--blocksize"))
|| (currentArg == std::string("-b"))) {
/* now extract the verbose level integer */
if (((currentArg.find(std::string("--blocksize"))
!= currentArg.npos)
|| (currentArg.find(std::string("-b")) != currentArg.npos))
&& (i + 1 < argc)) {
std::string nextArg = std::string(argv[i + 1]);
// Skip the next iteration
i++;
block_size = std::stoi(nextArg);
}
} else if ((currentArg == std::string("--use-ipp"))
|| (currentArg == std::string("-i"))) {
useipp = true;
*argc -= 1;
} else if ((currentArg == std::string("--use-ossl"))
|| (currentArg == std::string("-o"))) {
useossl = true;
*argc -= 1;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/common/include/gtest_common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ parseArgs(int argc, char** argv)
std::cout << "--replay-blackbox or -r replay blackbox with "
"log file"
<< std::endl;
exit(-1);
} else if ((currentArg == std::string("--verbose"))
|| (currentArg == std::string("-v"))) {
/* now extract the verbose level integer */
Expand Down

0 comments on commit cf28a98

Please sign in to comment.