Skip to content
Draft
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
168 changes: 168 additions & 0 deletions apptainer/build_multi_base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
# Generate IntelliPerf definition files from different base images

set -e

# Default values
BASE_IMAGE=""
OUTPUT_NAME=""
DEF_TEMPLATE="intelliperf.def"
SCRIPT_DIR=$(dirname $(realpath $0))

# Preset base images
declare -A PRESETS=(
["composable_kernel"]="rocm/composable_kernel:ck_ub24.04_rocm7.1.1_amd-staging"
["gemm"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["matrix_transpose1"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["vllm"]="rocm/vllm:rocm7.0.0_vllm_0.11.2_20251210"
["counting_sketch"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["global_reduction"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["silu"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["Dataset_hip"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["gpu-kernel-agent"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["point_to_voxel"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["diff_gaussian_rasterization"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["gsplat"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["histogram"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["reduction"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["causal_conv1d_fwd"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["element_multiply"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["matrix_transpose"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["rocm7.0-pytorch"]="rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["rocm7.1-pytorch"]="rocm/pytorch:rocm7.1_ubuntu22.04_py3.10_pytorch_release_2.8.0"
["composable-kernel"]="rocm/composable_kernel:ck_pytorch"
["rocm6.2-pytorch"]="rocm/pytorch:rocm6.2_ubuntu22.04_py3.10_pytorch_release_2.4.0"
["rocm7.0-ubuntu22"]="rocm/rocm-terminal:rocm7.0-ubuntu22.04"
["rocm7.1-ubuntu22"]="rocm/rocm-terminal:rocm7.1-ubuntu22.04"
["rocm7.0-vllm"]="rocm/vllm:rocm7.0.0_vllm_0.11.2_20251210"

)

# Help message
show_help() {
cat << EOF
Usage: $0 [OPTIONS]

Generate IntelliPerf Apptainer definition files from different base images.

OPTIONS:
-b, --base IMAGE Base Docker image (required)
-o, --output NAME Output .def filename (default: intelliperf-<preset>.def)
-t, --template FILE Template .def file (default: intelliperf.def)
-p, --preset NAME Use preset base image (see list below)
-l, --list List available presets
-h, --help Show this help message

PRESETS:
EOF
for preset in "${!PRESETS[@]}"; do
echo " $preset: ${PRESETS[$preset]}"
done | sort
echo ""
echo "EXAMPLES:"
echo " # Generate def file from rocm7.1-pytorch preset"
echo " $0 --preset rocm7.1-pytorch"
echo ""
echo " # Generate def file from custom base image"
echo " $0 --base rocm/pytorch:rocm7.2_ubuntu22.04_py3.10_pytorch_release_2.9.0 --output intelliperf-rocm72.def"
echo ""
echo " # Generate using intelliperf_ck.def template with different base"
echo " $0 --preset rocm7.1-pytorch --template intelliperf_ck.def --output intelliperf-ck-rocm71.def"
}

# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
-b|--base)
BASE_IMAGE="$2"
shift 2
;;
-o|--output)
OUTPUT_NAME="$2"
shift 2
;;
-t|--template)
DEF_TEMPLATE="$2"
shift 2
;;
-p|--preset)
PRESET_NAME="$2"
if [[ -z "${PRESETS[$PRESET_NAME]}" ]]; then
echo "Error: Unknown preset '$PRESET_NAME'"
echo "Use --list to see available presets"
exit 1
fi
BASE_IMAGE="${PRESETS[$PRESET_NAME]}"
# Set default output name based on preset if not specified
if [[ -z "$OUTPUT_NAME" ]]; then
OUTPUT_NAME="intelliperf-${PRESET_NAME}.def"
fi
shift 2
;;
-l|--list)
echo "Available presets:"
for preset in "${!PRESETS[@]}"; do
echo " $preset: ${PRESETS[$preset]}"
done | sort
exit 0
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done

# Validate required arguments
if [[ -z "$BASE_IMAGE" ]]; then
echo "Error: Base image is required (use --base or --preset)"
show_help
exit 1
fi

# Set default output name if not specified
if [[ -z "$OUTPUT_NAME" ]]; then
# Extract a sanitized name from the base image
SANITIZED=$(echo "$BASE_IMAGE" | sed 's/[\/:]/-/g')
OUTPUT_NAME="intelliperf-${SANITIZED}.def"
fi

# Check if template exists
if [[ ! -f "$SCRIPT_DIR/$DEF_TEMPLATE" ]]; then
echo "Error: Template file '$DEF_TEMPLATE' not found in $SCRIPT_DIR"
exit 1
fi

echo "=========================================="
echo "IntelliPerf Definition File Generator"
echo "=========================================="
echo "Base Image: $BASE_IMAGE"
echo "Template: $DEF_TEMPLATE"
echo "Output: $OUTPUT_NAME"
echo "=========================================="

# Replace the 'From:' line in the template and save to output
sed "s|^From:.*|From: ${BASE_IMAGE}|" "$SCRIPT_DIR/$DEF_TEMPLATE" > "$SCRIPT_DIR/$OUTPUT_NAME"

if [[ $? -eq 0 ]]; then
echo ""
echo "=========================================="
echo "Definition file generated successfully!"
echo "Saved to: $SCRIPT_DIR/$OUTPUT_NAME"
echo "=========================================="
echo ""
echo "To build the container:"
echo " apptainer build ${OUTPUT_NAME%.def}.sif $SCRIPT_DIR/$OUTPUT_NAME"
else
echo ""
echo "=========================================="
echo "Generation failed!"
echo "=========================================="
exit 1
fi
35 changes: 30 additions & 5 deletions apptainer/intelliperf.def
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ From: rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0
export ROCM_PATH=/opt/rocm
export OMPI_MCA_mtl="^ofi"
export OMPI_MCA_pml="ob1"

# Activate virtual environment
export VIRTUAL_ENV=/opt/intelliperf_venv
export PATH=/opt/intelliperf_venv/bin:$PATH

%post
/bin/bash -c "
Expand All @@ -22,13 +26,19 @@ From: rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0

# Install additional system dependencies
apt-get -y update
apt-get install -y software-properties-common git wget clang lld libzstd-dev libomp-dev vim libdwarf-dev gdb tmux
apt-get install -y software-properties-common git wget clang lld libzstd-dev libomp-dev vim libdwarf-dev gdb tmux cmake unzip python3-venv

# Upgrade pip
# Create virtual environment
python3 -m venv /opt/intelliperf_venv

# Activate virtual environment
. /opt/intelliperf_venv/bin/activate

# Upgrade pip in virtual environment
pip install --upgrade pip

# Install additional Python packages for intelliperf
pip install --no-cache-dir \
# Install additional Python packages for intelliperf in virtual environment
pip install --upgrade --ignore-installed --no-cache-dir \
astunparse==1.6.2 \
colorlover \
dash-bootstrap-components \
Expand Down Expand Up @@ -59,7 +69,22 @@ From: rocm/pytorch:rocm7.0_ubuntu22.04_py3.10_pytorch_release_2.8.0
litellm[proxy]
"

# Only install rocm-cmake if it doesn't exist
if [ ! -d "rocm-cmake" ]; then
git clone https://github.com/ROCm/rocm-cmake.git
cd rocm-cmake
mkdir build
cd build
cmake ..
cmake --build .
cmake --build . --target install
fi
%runscript
#!/bin/bash
# Activate virtual environment
if [ -f /opt/intelliperf_venv/bin/activate ]; then
. /opt/intelliperf_venv/bin/activate
fi

echo "Welcome to IntelliPerf with ROCm 7.0!"
source /opt/conda/bin/activate py_3.10
exec "$@"
Loading