-
Notifications
You must be signed in to change notification settings - Fork 837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CUDA support #7436
Merged
Merged
Add CUDA support #7436
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6a9452c
First attempt
5ff728d
Fix compilation issues
7d06271
Need more functions/variables defined in __device__
6035af9
Redirect the AesEncrypt_C call to device
72da9d5
Uncomment BUILD_CUDA condition check
09b8850
Try using a unique name
8df2b25
Fix function declarations
2494103
Force CC=nvcc with CUDA
ec49558
Don't let C++ mangle function names
22241e6
Add larger parallelization
54748ca
first example of the benchmark comparison tool
bc27d53
Add in memory copy to device
109f039
Fix issues with `make check`
d423859
Correct key sizing and location
d6691ef
Fix block encryption
079f72f
Fix merge order
5ae27bc
Remove debugging code
903e809
`nvcc` does not support '-Wall' nor '-Wno-unused'
236085c
Add in README.md
feacac2
Clean up script to output color coded data
221a41b
Fix Asymmetric cipher comparisons
b776f97
Add in standard output parsing in addition to the CSV
91bf456
Addressing PR comments
aa9392e
Revert unnecessary change
c76d6d1
Add option to output results in a CSV
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
#!/bin/bash | ||
# This script is designed to compare the output of wolfcrypt/benchmark test | ||
# application. If the file has an extension ".csv", then it will parse the | ||
# comma separated format, otherwise it will use the standard output format. The | ||
# green colored output field is the better result. | ||
# Usage: benchmark_compare.sh <first file> <second file> | ||
# You can define a few variables to set options: | ||
# THRESHOLD - set the threshold for equality between two results | ||
# OUTPUT_CSV - set to "1" to print CSV | ||
|
||
FIRST_FILE=$1 | ||
SECOND_FILE=$2 | ||
THRESHOLD=${THRESHOLD:-"10"} | ||
OUTPUT_CSV=${OUTPUT_CSV:-"0"} | ||
|
||
declare -A symStats | ||
declare -A asymStats | ||
|
||
function getAlgo() { # getAlgo <asCSV> <mode> <line> | ||
if [ "$asCSV" = 1 ]; then | ||
declare -a fields | ||
IFS=',' read -ra fields <<< "$line" | ||
if [ "$mode" = 1 ]; then | ||
echo "${fields[0]}" | ||
else | ||
if [ "${fields[2]}" = "" ]; then | ||
echo "${fields[0]}" | ||
else | ||
echo "${fields[0]}-${fields[2]}" | ||
fi | ||
fi | ||
else | ||
if [ "$mode" = 1 ]; then | ||
echo "$line" | sed 's/ *[0-9]* MiB.*//g' | ||
else | ||
if [[ $line == "scrypt"* ]]; then | ||
echo "scrypt" | ||
else | ||
echo "$line" | sed 's/ *[0-9]* ops.*//g' | sed 's/ \+[0-9]\+ \+/-/g' | ||
fi | ||
fi | ||
fi | ||
} | ||
|
||
function getValue() { # getValue <asCSV> <mode> <line> | ||
if [ "$asCSV" = 1 ]; then | ||
declare -a fields | ||
IFS=',' read -ra fields <<< "$line" | ||
if [ "$mode" = 1 ]; then | ||
echo "${fields[1]}" | ||
else | ||
echo "${fields[4]}" | ||
fi | ||
else | ||
if [ "$mode" = 1 ]; then | ||
echo "$line" | sed 's/.*seconds, *//g' | sed 's/ *MiB\/s.*//g' | ||
else | ||
echo "$line" | sed 's/.* ms, *//g' | sed 's/ ops\/sec.*//g' | ||
fi | ||
fi | ||
} | ||
|
||
asCSV=0 | ||
mode=0 | ||
while IFS= read -r line; do | ||
if [[ $FIRST_FILE == *".csv" ]]; then | ||
asCSV=1 | ||
if [[ $line == *"Symmetric Ciphers"* ]]; then | ||
mode=1 | ||
read | ||
read | ||
elif [[ $line == *"Asymmetric Ciphers"* ]]; then | ||
mode=2 | ||
read | ||
read | ||
elif [[ $line == "" ]]; then | ||
mode=0 | ||
fi | ||
else | ||
asCSV=0 | ||
if [[ $line == *"MiB/s"* ]]; then | ||
mode=1 | ||
elif [[ $line == *"ops/sec"* ]]; then | ||
mode=2 | ||
else | ||
mode=0 | ||
fi | ||
fi | ||
if [ "$mode" -ne 0 ]; then | ||
ALGO=`getAlgo "$asCSV" "$mode" "$line"` | ||
VALUE=`getValue "$asCSV" "$mode" "$line"` | ||
|
||
if [ "$mode" = "1" ]; then | ||
symStats["${ALGO}"]=${VALUE} | ||
elif [ "$mode" = "2" ]; then | ||
asymStats["${ALGO}"]=${VALUE} | ||
fi | ||
fi | ||
done < ${FIRST_FILE} | ||
|
||
RED='\033[0;31m' | ||
GRN='\033[0;32m' | ||
NC='\033[0m' # No Color | ||
function printData() { # printData <ALGO> <val1> <val2> | ||
ALGO=$1 | ||
VAL1=$2 | ||
VAL2=$3 | ||
if (( $(echo "sqrt( (${VAL1} - ${VAL2})^2 ) < ${THRESHOLD}" | bc -l) )); then | ||
# take absolute value and check if less than a threshold | ||
echo "${ALGO},${GRN}${VAL1}${NC},=,${GRN}${VAL2}${NC}\n" | ||
elif (( $(echo "${VAL1} > ${VAL2}" | bc -l) )); then | ||
echo "${ALGO},${GRN}${VAL1}${NC},>,${VAL2}\n" | ||
else | ||
echo "${ALGO},${VAL1},<,${GRN}${VAL2}${NC}\n" | ||
fi | ||
} | ||
|
||
asCSV=0 | ||
mode=0 | ||
while IFS= read -r line; do | ||
if [[ $SECOND_FILE == *".csv" ]]; then | ||
asCSV=1 | ||
if [[ $line == *"Symmetric Ciphers"* ]]; then | ||
RES+="ALGO,${FIRST_FILE},diff(MB/s),${SECOND_FILE}\n" | ||
mode=1 | ||
read | ||
read | ||
elif [[ $line == *"Asymmetric Ciphers"* ]]; then | ||
RES+="\nALGO,${FIRST_FILE},diff(ops/sec),${SECOND_FILE}\n" | ||
mode=2 | ||
read | ||
read | ||
elif [[ $line == "" ]]; then | ||
mode=0 | ||
fi | ||
else | ||
asCSV=0 | ||
if [[ $line == *"MiB/s"* ]]; then | ||
mode=1 | ||
elif [[ $line == *"ops/sec"* ]]; then | ||
mode=2 | ||
else | ||
mode=0 | ||
fi | ||
fi | ||
if [ "$mode" -ne 0 ]; then | ||
if [[ $line == *","* ]]; then | ||
ALGO=`getAlgo "$asCSV" "$mode" "$line"` | ||
VALUE=`getValue "$asCSV" "$mode" "$line"` | ||
|
||
if [ "$mode" = "1" ]; then | ||
RES+=`printData "${ALGO}" "${symStats["${ALGO}"]}" "${VALUE}"` | ||
elif [ "$mode" = "2" ]; then | ||
RES+=`printData "${ALGO}" "${asymStats["${ALGO}"]}" "${VALUE}"` | ||
fi | ||
fi | ||
fi | ||
done < ${SECOND_FILE} | ||
|
||
if [ "${OUTPUT_CSV}" = "1" ]; then | ||
echo -e "$RES" | ||
else | ||
echo -e "$RES" | column -t -s ',' -L | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
You will need to have the CUDA libraries and toolchains installed to be able to use this. For the simplest | ||
setup, I used the 'nvidia/cuda:12.3.2-devel-ubuntu22.04' container with the '--gpus=all' flag. Note that | ||
Docker must be set up to allow passing through the CUDA instructions to the host. The container only needs | ||
'automake' and 'libtool' installed: `apt update && apt install -y automake libtool`. | ||
|
||
This code was tested with the following: | ||
./configure --enable-all --disable-shared --disable-crl-monitor --enable-cuda CC=nvcc && make check | ||
|
||
There are still things that can be done to optimize, but the basic functionality is there. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to add this file to scripts/include.am.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Already done locally. Didn't want to trigger another build