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

Pipeline work #48

Merged
merged 14 commits into from
Dec 27, 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
61 changes: 2 additions & 59 deletions .github/actions/build-action/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runs:
using: composite
steps:
- name: Common SSH and Azure CLI Setup
uses: ./.github/actions/common-steps
uses: ./.github/actions/common-ssh-and-azure-steps
with:
VM_IP: ${{ inputs.VM_IP }}
SSH_PRIVATE_KEY: ${{ inputs.SSH_PRIVATE_KEY }}
Expand All @@ -44,61 +44,4 @@ runs:

- name: Build project
shell: bash
run: |
ssh -T -o ConnectTimeout=10 ${{ inputs.VM_USERNAME }}@${{ inputs.VM_IP }} << 'EOF'
set -e # Exit on error
cd ~/aperi-mech

compose_file=docker-compose.yml
service_name=aperi-mech-development
# Check if GPU build is enabled and code coverage is not enabled, overriding gpu flag if code coverage is enabled
if [ ${{ inputs.gpu }} == 'true' ] && [ ${{ inputs.code-coverage }} == 'false' ]; then
compose_file=docker-compose_nvidia_t4_gpu.yml
service_name=aperi-mech-gpu-development
fi
# Debugging
echo "On VM, Compose file: $compose_file"
echo "On VM, Service name: $service_name"

docker-compose -f $compose_file run --rm $service_name /bin/bash -c '
configure_flag=""
build_root=build
if [ ${{ inputs.with-protego }} == "true" ]; then
build_root=protego-mech/build
configure_flag=" --protego-mech"
fi
build_path="${build_root}/${{ inputs.build-type }}"
if [ ${{ inputs.gpu }} == "true" ]; then
configure_flag="${configure_flag} --gpu"
build_path="${build_path}_gpu"
fi

# Check if code coverage is enabled, overriding gpu flag if code coverage is enabled
if [ ${{ inputs.code-coverage }} == "true" ]; then
configure_flag="${configure_flag} --code-coverage"
build_path="${build_path}_cov"
fi
# Debugging
echo "In container, inputs.build-type: ${{ inputs.build-type }}"
echo "In container, inputs.gpu: ${{ inputs.gpu }}"
echo "In container, inputs.code-coverage: ${{ inputs.code-coverage }}"
echo "In container, configure_flag: $configure_flag"
echo "In container, build_path: $build_path"

cd ~/aperi-mech
echo "Setting up Spack environment..."
. ~/spack/share/spack/setup-env.sh
spack env activate aperi-mech

echo "Configuring project..."
# do_configure will set build type to Debug if code coverage is enabled
./do_configure --build-type ${{ inputs.build-type }} ${configure_flag}

echo "Building project..."
cd $build_path
make -j 4
if [ ${{ inputs.code-coverage }} == "true" ]; then
make coverage
fi
' || { echo "Build project step failed"; exit 1; }
EOF
run: python3 ./.github/actions/build-action/build.py --ip ${{ inputs.VM_IP }} --username ${{ inputs.VM_USERNAME }} --build-type ${{ inputs.build-type }} --gpu ${{ inputs.gpu }} --code-coverage ${{ inputs.code-coverage }} --protego ${{ inputs.with-protego }}
109 changes: 109 additions & 0 deletions .github/actions/build-action/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env python3

import argparse

import paramiko


def str_to_bool(value):
return value.lower() in ("true", "1", "t", "y", "yes")


def run_build(vm_ip, vm_username, gpu, build_type, code_coverage, with_protego):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Establish the SSH connection with increased timeout and keepalive options
ssh.connect(vm_ip, username=vm_username, timeout=60)
transport = ssh.get_transport()
transport.set_keepalive(30) # Send keepalive messages every 30 seconds

# Construct the compose file and service name
compose_file = "docker-compose.yml"
service_name = "aperi-mech-development"
if gpu and not code_coverage:
compose_file = "docker-compose_nvidia_t4_gpu.yml"
service_name = "aperi-mech-gpu-development"

# Construct the configure flag and build path
configure_flag = ""
build_root = "build"
if with_protego:
build_root = "protego-mech/build"
configure_flag += " --protego-mech"
build_path = f"{build_root}/{build_type}"
if gpu:
configure_flag += " --gpu"
build_path += "_gpu"

run_coverage = ""
if code_coverage:
configure_flag += " --code-coverage"
build_path += "_cov"
run_coverage = "make coverage"

# Construct the command to run on the VM
commands = f"""
set -e
cd ~/aperi-mech

docker-compose -f {compose_file} run --rm {service_name} /bin/bash -c '
cd ~/aperi-mech
. ~/spack/share/spack/setup-env.sh
spack env activate aperi-mech

./do_configure --build-type {build_type} {configure_flag}

cd {build_path}
make -j 4

{run_coverage}

' || {{ echo "Build project step failed"; exit 1; }}
"""

print("Executing the following commands on the VM:")
print(commands)

stdin, stdout, stderr = ssh.exec_command(commands, get_pty=True)
for line in stdout:
print(line.strip())
for line in stderr:
print(line.strip())

ssh.close()


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run build on remote VM")
parser.add_argument("--ip", default="127.0.0.1", help="IP address of the VM")
parser.add_argument("--username", default="azureuser", help="Username for the VM")
parser.add_argument("--gpu", default="false", help="GPU flag (true/false)")
parser.add_argument(
"--build_type",
"--build-type",
dest="build_type",
default="Release",
help="Build type",
)
parser.add_argument(
"--code_coverage",
"--code-coverage",
dest="code_coverage",
default="false",
help="Code coverage flag (true/false)",
)
parser.add_argument(
"--protego", default="false", help="With Protego flag (true/false)"
)

args = parser.parse_args()

run_build(
args.ip,
args.username,
str_to_bool(args.gpu),
args.build_type,
str_to_bool(args.code_coverage),
str_to_bool(args.protego),
)
15 changes: 15 additions & 0 deletions .github/actions/common-runner-config-steps/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Common Runner Config Steps
description: Setup python on the runner and install dependencies
runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.x

- name: Install Dependencies
shell: bash
run: |
python -m pip install --upgrade pip
pip install paramiko
45 changes: 1 addition & 44 deletions .github/actions/run-aperi-mech-performance-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,4 @@ runs:

- name: Run aperi-mech performance tests
shell: bash
run: |
ssh -T -o ConnectTimeout=10 ${{ inputs.VM_USERNAME }}@${{ inputs.VM_IP }} << 'EOF'
set -e # Exit on error
cd ~/aperi-mech

compose_file=docker-compose.yml
service_name=aperi-mech-development
if [ ${{ inputs.gpu }} == 'true' ]; then
compose_file=docker-compose_nvidia_t4_gpu.yml
service_name=aperi-mech-gpu-development
fi
# Debugging
echo "On VM, Compose file: $compose_file"
echo "On VM, Service name: $service_name"

docker-compose -f $compose_file run --rm $service_name /bin/bash -c '
test_flags="--release"
if [ ${{ inputs.gpu }} == "true" ]; then
test_flags="$test_flags --gpu"
else
test_flags="$test_flags --cpu"
fi
if [ ${{ inputs.parallel }} == "true" ]; then
test_flags="$test_flags --parallel"
else
test_flags="$test_flags --serial"
fi
# Debugging
echo "In container, inputs.gpu: ${{ inputs.gpu }}"
echo "In container, inputs.parallel: ${{ inputs.parallel }}"
echo "In container, test_flags: $test_flags"

echo "Setting up Spack environment..."
. ~/spack/share/spack/setup-env.sh
spack env activate aperi-mech

echo "Running aperi-mech performance tests..."
cd ~/aperi-mech/test/
./run_regression_tests.py --directory ./performance_tests/aperi-mech --build-dir ~/aperi-mech/build/ $test_flags --write-json --no-preclean
./run_regression_tests.py --directory ./performance_tests/aperi-mech --build-dir ~/aperi-mech/build/ $test_flags --clean-logs
./run_regression_tests.py --directory ./performance_tests/aperi-mech --build-dir ~/aperi-mech/build/ $test_flags --clean-results

' || { echo "Performance test step failed"; exit 1; }
EOF
run: python3 ./.github/actions/run-aperi-mech-performance-tests/run_aperi-mech_performance_tests.py --ip ${{ inputs.VM_IP }} --username ${{ inputs.VM_USERNAME }} --gpu ${{ inputs.gpu }} --parallel ${{ inputs.parallel }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import argparse

import paramiko


def str_to_bool(value):
return value.lower() in ("true", "1", "t", "y", "yes")


def run_aperi_mech_performance_tests(vm_ip, vm_username, gpu, parallel):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(vm_ip, username=vm_username)

# Convert string inputs to boolean
gpu = str_to_bool(gpu)
parallel = str_to_bool(parallel)

# Construct the compose file and service name
compose_file = "docker-compose.yml"
service_name = "aperi-mech-development"
if gpu:
compose_file = "docker-compose_nvidia_t4_gpu.yml"
service_name = "aperi-mech-gpu-development"

# Construct the test flags
test_flags = "--release"
if gpu:
test_flags += " --gpu"
else:
test_flags += " --cpu"
if parallel:
test_flags += " --parallel"
else:
test_flags += " --serial"

# Construct the command to run on the VM
commands = f"""
set -e
cd ~/aperi-mech

docker-compose -f {compose_file} run --rm {service_name} /bin/bash -c '
echo "Setting up Spack environment..."
. ~/spack/share/spack/setup-env.sh
spack env activate aperi-mech

echo "Running aperi-mech performance tests..."
cd ~/aperi-mech/test/
./run_regression_tests.py --directory ./performance_tests/aperi-mech --build-dir ~/aperi-mech/build/ {test_flags} --write-json --no-preclean
./run_regression_tests.py --directory ./performance_tests/aperi-mech --build-dir ~/aperi-mech/build/ {test_flags} --clean-logs
./run_regression_tests.py --directory ./performance_tests/aperi-mech --build-dir ~/aperi-mech/build/ {test_flags} --clean-results
' || {{ echo "Performance test step failed"; exit 1; }}
"""

print("Executing the following commands on the VM:")
print(commands)

stdin, stdout, stderr = ssh.exec_command(commands)
for line in stdout:
print(line.strip())
for line in stderr:
print(line.strip())

ssh.close()


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run performance tests on remote VM")
parser.add_argument("--ip", default="127.0.0.1", help="IP address of the VM")
parser.add_argument("--username", default="azureuser", help="Username for the VM")
parser.add_argument("--gpu", default="false", help="GPU flag (true/false)")
parser.add_argument(
"--parallel", default="false", help="Parallel flag (true/false)"
)

args = parser.parse_args()

run_aperi_mech_performance_tests(args.ip, args.username, args.gpu, args.parallel)
36 changes: 1 addition & 35 deletions .github/actions/run-gtest-performance-tests/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,4 @@ runs:

- name: Run gtest performance tests
shell: bash
run: |
ssh -T -o ConnectTimeout=10 ${{ inputs.VM_USERNAME }}@${{ inputs.VM_IP }} << 'EOF'
set -e # Exit on error
cd ~/aperi-mech

compose_file=docker-compose.yml
service_name=aperi-mech-development
if [ ${{ inputs.gpu }} == 'true' ]; then
compose_file=docker-compose_nvidia_t4_gpu.yml
service_name=aperi-mech-gpu-development
fi
# Debugging
echo "On VM, Compose file: $compose_file"
echo "On VM, Service name: $service_name"

docker-compose -f $compose_file run --rm $service_name /bin/bash -c '
build_path=~/aperi-mech/build/${{ inputs.build-type }}
if [ ${{ inputs.gpu }} == "true" ]; then
build_path=~/aperi-mech/build/${{ inputs.build-type }}_gpu
fi
# Debugging
echo "In container, inputs.build-type: ${{ inputs.build-type }}"
echo "In container, inputs.gpu: ${{ inputs.gpu }}"
echo "In container, build_path: $build_path"

cd $build_path
echo "Setting up Spack environment..."
. ~/spack/share/spack/setup-env.sh
spack env activate aperi-mech

echo "Running gtest performance tests..."
./performance_tests

' || { echo "Gtest performance test step failed"; exit 1; }
EOF
run: python3 ./.github/actions/run-gtest-performance-tests/run_gtest_performance_tests.py --ip ${{ inputs.VM_IP }} --username ${{ inputs.VM_USERNAME }} --gpu ${{ inputs.gpu }} --build-type ${{ inputs.build-type }}
Loading
Loading