Skip to content
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 mx performance script #567

Merged
merged 7 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/booster-analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export LOG_DIR=${LOG_DIR:-"$BUG_REPORT_DIR-logs"}
mkdir -p $LOG_DIR

K_VERSION=$(cat $SCRIPT_DIR/../deps/k_release)
export PATH="$(nix build github:runtimeverification/k/v$K_VERSION#k.openssl.procps --no-link --print-build-logs --json | jq -r '.[].outputs | to_entries[].value')/bin:$PATH"
export PATH="$(nix build github:runtimeverification/k/v$K_VERSION#k.openssl.procps.secp256k1 --no-link --print-build-logs --json | jq -r '.[].outputs | to_entries[].value')/bin:$PATH"
PLUGIN_VERSION=$(cat $SCRIPT_DIR/../deps/blockchain-k-plugin_release)
export PLUGIN_DIR=$(nix build github:runtimeverification/blockchain-k-plugin/$PLUGIN_VERSION --no-link --json | jq -r '.[].outputs | to_entries[].value')

Expand Down
97 changes: 97 additions & 0 deletions scripts/performance-tests-mx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bash
set -euxo pipefail

# Disable the Python keyring, otherwise poetry sometimes asks for password. See
# https://github.com/pypa/pip/issues/7883
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring

MX_VERSION=${MX_VERSION:-'master'}

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

MASTER_COMMIT="$(git rev-parse origin/main)"
MASTER_COMMIT_SHORT="$(git rev-parse --short origin/main)"

FEATURE_BRANCH_NAME=${FEATURE_BRANCH_NAME:-"$(git rev-parse --abbrev-ref HEAD)"}
FEATURE_BRANCH_NAME="${FEATURE_BRANCH_NAME//\//-}"

PYTEST_PARALLEL=${PYTEST_PARALLEL:-3}

if [[ $FEATURE_BRANCH_NAME == "master" ]]; then
FEATURE_BRANCH_NAME="feature"
fi

# Create a temporary directory and store its name in a variable.
TEMPD=$(mktemp -d)

# Exit if the temp directory wasn't created successfully.
if [ ! -e "$TEMPD" ]; then
>&2 echo "Failed to create temp directory"
exit 1
fi

# Make sure the temp directory gets removed and kore-rpc-booster gets killed on script exit.
trap "exit 1" HUP INT PIPE QUIT TERM
trap 'rm -rf "$TEMPD" && killall kore-rpc-booster || echo "No zombie processes found"' EXIT

feature_shell() {
GC_DONT_GC=1 nix develop . --extra-experimental-features 'nix-command flakes' --override-input k-framework/booster-backend $SCRIPT_DIR/../ --command bash -c "$1"
}

master_shell() {
GC_DONT_GC=1 nix develop . --extra-experimental-features 'nix-command flakes' --override-input k-framework/booster-backend github:runtimeverification/hs-backend-booster/$MASTER_COMMIT --command bash -c "$1"
}

cd $TEMPD
git clone --depth 1 --branch $MX_VERSION https://github.com/runtimeverification/mx-backend.git
cd mx-backend

if [[ $MX_VERSION == "master" ]]; then
MX_VERSION=$(git name-rev --tags --name-only $(git rev-parse HEAD))
else
MX_VERSION="${MX_VERSION//\//-}"
fi

git submodule update --init --recursive --depth 1 kmxwasm/k-src/mx-semantics/

BUG_REPORT=''
POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
case $1 in
--bug-report)
mkdir -p $SCRIPT_DIR/bug-reports/mx-$MX_VERSION-$FEATURE_BRANCH_NAME
BUG_REPORT="--bug-report --bug-report-dir $SCRIPT_DIR/bug-reports/mx-$MX_VERSION-$FEATURE_BRANCH_NAME"
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters


feature_shell "poetry -C kmxwasm install && make -C kmxwasm kbuild-haskell"
Copy link
Contributor

@geo2a geo2a Apr 3, 2024

Choose a reason for hiding this comment

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

Do we need to execute the same command in master_shell?

Also, will the LLVM backend shared library be built by make -C kmxwasm kbuild-haskell? @virgil-serbanuta @bbyalcinkaya could you have a look at this PR and make sure the script does what you'd expect?

Copy link
Contributor Author

@goodlyrottenapple goodlyrottenapple Apr 3, 2024

Choose a reason for hiding this comment

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

yes, master shell is used to compare our feature branch change to the current version of booster in mx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these steps are copied from the CI run in the mx repo:
https://github.com/runtimeverification/mx-backend/blob/872626e6a658bdbdc7914e5c1c01d19cffc3f11c/.github/workflows/test.yml#L96-L118
so hopefully should do the same thing....

Copy link
Member

Choose a reason for hiding this comment

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

I would guess that the poetry install and make kbuild-haskell are independent of the booster version, so we wouldn't have to repeat that command (we don't at the moment).
Better to have this confirmed by @virgil-serbanuta or @bbyalcinkaya , though.

Choose a reason for hiding this comment

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

The kasmer tool builds the semantics at start (for the Haskell backend, for the LLVM backend, and, if --booster is passed to the tool, it also builds the llvm library). Tests do something similar. make -C kmxwasm kbuild-haskell should not be needed unless you need to run things outside our tool (or, perhaps, you just want to check that it compiles).

Choose a reason for hiding this comment

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

FWIW, we will probably add the option to use an already-built semantics soon, we can try to do that sooner if you need it.

Copy link
Member

Choose a reason for hiding this comment

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

image



mkdir -p $SCRIPT_DIR/logs

feature_shell "make -C kmxwasm test-booster TEST_ARGS='$BUG_REPORT' && make -C kmxwasm test-integration TEST_ARGS='$BUG_REPORT' | tee $SCRIPT_DIR/logs/mx-$MX_VERSION-$FEATURE_BRANCH_NAME.log"
killall kore-rpc-booster || echo "No zombie processes found"

if [ -z "$BUG_REPORT" ]; then
if [ ! -e "$SCRIPT_DIR/logs/mx-$MX_VERSION-master-$MASTER_COMMIT_SHORT.log" ]; then
master_shell "make -C kmxwasm test-booster && make -C kmxwasm test-integration | tee $SCRIPT_DIR/logs/mx-$MX_VERSION-master-$MASTER_COMMIT_SHORT.log"
killall kore-rpc-booster || echo "No zombie processes found"
fi

cd $SCRIPT_DIR
python3 compare.py logs/mx-$MX_VERSION-$FEATURE_BRANCH_NAME.log logs/mx-$MX_VERSION-master-$MASTER_COMMIT_SHORT.log > logs/mx-$MX_VERSION-master-$MASTER_COMMIT_SHORT-$FEATURE_BRANCH_NAME-compare
fi
4 changes: 3 additions & 1 deletion scripts/run-with-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ client=${CLIENT:-$booster/.build/booster/bin/kore-rpc-client}
log_dir=${LOG_DIR:-.}

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
# needed for the MX backend otherwise llvm-backend-matching crashes
export K_OPTS="$K_OPTS -Xmx16384m"

nix_shell() {
GC_DONT_GC=1 nix develop $SCRIPT_DIR/..#cabal --extra-experimental-features 'nix-command flakes' --command bash -c "$1"
Expand Down Expand Up @@ -72,7 +74,7 @@ if [ -z "${LLVM_LIB}" ]; then
#generate matching data
(cd $TEMPD && mkdir -p dt && llvm-kompile-matching llvm-definition.kore qbaL ./dt 1/2)
# find library dependencies and source files
for lib in libff libcryptopp libsecp256k1; do
for lib in libff libcryptopp blake2; do
LIBFILE=$(find ${PLUGIN_DIR} -name "${lib}.a" | head -1)
[ -z "$LIBFILE" ] && (echo "[Error] Unable to locate ${lib}.a"; exit 1)
PLUGIN_LIBS+="$LIBFILE "
Expand Down