diff --git a/script/README.md b/script/README.md index 8d757cb71..c8ea12c03 100644 --- a/script/README.md +++ b/script/README.md @@ -1,6 +1,6 @@ # MLCommons Automation Scripts -*Last updated: 2026-10-01 05:17:29* +*Last updated: 2026-10-03 04:34:53* This directory contains automation scripts for MLPerf benchmarks, AI/ML workflows, and development operations. @@ -10,6 +10,7 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow - [AI/ML frameworks](#aiml-frameworks) - [AI/ML models](#aiml-models) - [AI/ML optimization](#aiml-optimization) +- [Agentic Benchmarks](#agentic-benchmarks) - [Benchmarking](#benchmarking) - [CUDA automation](#cuda-automation) - [Cloud automation](#cloud-automation) @@ -39,6 +40,7 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow - [TinyML automation](#tinyml-automation) - [Uncategorized](#uncategorized) - [Utilities](#utilities) +- [Vector Search Benchmarks](#vector-search-benchmarks) - [XPU automation](#xpu-automation) - [lstopo infragraph automation](#lstopo-infragraph-automation) - [lstopo topology automation](#lstopo-topology-automation) @@ -276,11 +278,23 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow - prune-bert-models - Tags: `prune`, `bert-models`, `bert-prune`, `prune-bert-models` +## Agentic Benchmarks + +- **[app-gaia-benchmark](app-gaia-benchmark/)** + - app-gaia-benchmark + - Tags: `app`, `agentic`, `agent`, `benchmark`, `gaia`, `general-ai-assistant` +- **[app-hotpotqa](app-hotpotqa/)** + - app-hotpotqa + - Tags: `app`, `agentic`, `agent`, `benchmark`, `qa`, `multi-hop`, `hotpotqa` +- **[app-webarena](app-webarena/)** + - app-webarena + - Tags: `app`, `agentic`, `agent`, `benchmark`, `web-agent`, `webarena` +- **[app-webvoyager](app-webvoyager/)** + - app-webvoyager + - Tags: `app`, `agentic`, `agent`, `benchmark`, `web-agent`, `webvoyager` + ## Benchmarking -- **[benchmark-hpc](benchmark-hpc/)** - - benchmark-hpc - - Tags: `benchmark`, `hpc`, `benchmark-hpc` - **[benchmark-program-coremark](benchmark-program-coremark/)** - benchmark-program-coremark - Tags: `benchmark`, `coremark`, `cpu`, `benchmark-coremark`, `benchmark-program-coremark` @@ -578,6 +592,9 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow - **[get-openssl](get-openssl/)** - get-openssl - Tags: `get`, `openssl`, `lib`, `lib-openssl` +- **[get-phoronix-test-suite](get-phoronix-test-suite/)** + - get-phoronix-test-suite + - Tags: `get`, `install`, `phoronix-test-suite`, `phoronix`, `pts` - **[get-rclone](get-rclone/)** - get-rclone - Tags: `get`, `rclone` @@ -1575,6 +1592,12 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow - send-mail - Tags: `send`, `mail`, `email` +## Vector Search Benchmarks + +- **[benchmark-hnswlib](benchmark-hnswlib/)** + - benchmark-hnswlib + - Tags: `benchmark`, `hnswlib`, `ann`, `approximate-nearest-neighbor`, `vector-search` + ## XPU automation - **[get-xpu-devices](get-xpu-devices/)** @@ -1597,8 +1620,8 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow ## Statistics -- **Total Scripts**: 480 -- **Categories**: 36 +- **Total Scripts**: 485 +- **Categories**: 38 ## Usage diff --git a/script/app-athena/customize.py b/script/app-athena/customize.py index 41bb42eec..e0ca4fbfa 100644 --- a/script/app-athena/customize.py +++ b/script/app-athena/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_ATHENA_SRC_PATH', '') - bin_dir = os.path.join(src_path, 'bin') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + bin_dir = os.path.join(src_path, 'bin-' + compiler_tag) binary = os.path.join(bin_dir, 'athena') if not os.path.isfile(binary): diff --git a/script/app-athena/meta.yaml b/script/app-athena/meta.yaml index 0a4ea98e4..c876a3609 100644 --- a/script/app-athena/meta.yaml +++ b/script/app-athena/meta.yaml @@ -77,6 +77,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v24.0 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-athena/run.sh b/script/app-athena/run.sh index 141e97619..23ff3e68d 100644 --- a/script/app-athena/run.sh +++ b/script/app-athena/run.sh @@ -10,11 +10,17 @@ fi SRC="${MLC_ATHENA_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" PYTHON="${MLC_PYTHON_BIN_WITH_PATH:-python3}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +case "${COMPILER_TAG}" in + oneapi) ATH_CXX=icpx ;; + gcc|default) ATH_CXX=g++ ;; + *) ATH_CXX=clang++ ;; +esac cd "${SRC}" echo "Configuring Athena++ (shock_tube problem)..." -"${PYTHON}" configure.py --prob=shock_tube +"${PYTHON}" configure.py --prob=shock_tube --cxx "${ATH_CXX}" echo "Building Athena++ with ${CORES} cores..." make clean || true @@ -30,4 +36,5 @@ echo "Running Athena++ smoke test (Sod shock tube, 5 steps)..." mkdir -p athena_smoke_out ./bin/athena -i inputs/hydro/athinput.sod time/nlim=5 -d athena_smoke_out +mkdir -p "bin-${COMPILER_TAG}" && cp bin/athena "bin-${COMPILER_TAG}/athena" echo "Athena++ built and smoke-tested successfully." diff --git a/script/app-bigdft/meta.yaml b/script/app-bigdft/meta.yaml index e8947ea1a..a95eb4896 100644 --- a/script/app-bigdft/meta.yaml +++ b/script/app-bigdft/meta.yaml @@ -81,6 +81,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: '1.9.5' + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: [] diff --git a/script/app-castro/customize.py b/script/app-castro/customize.py index a3f57fc6e..d40dfef26 100644 --- a/script/app-castro/customize.py +++ b/script/app-castro/customize.py @@ -12,7 +12,8 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_CASTRO_SRC_PATH', '') - hits = glob.glob(os.path.join(src_path, 'Exec', 'hydro_tests', 'Sedov', '*.ex')) + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + hits = glob.glob(os.path.join(src_path, 'install-' + compiler_tag, 'bin', '*.ex')) if not hits: return {'return': 1, 'error': f'Castro executable not found under {src_path}'} bin_dir = os.path.dirname(hits[0]) diff --git a/script/app-castro/meta.yaml b/script/app-castro/meta.yaml index dba6db2e7..1afc2be5b 100644 --- a/script/app-castro/meta.yaml +++ b/script/app-castro/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: 26.09 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-castro/run.sh b/script/app-castro/run.sh index c6292a94b..4f28c206c 100644 --- a/script/app-castro/run.sh +++ b/script/app-castro/run.sh @@ -19,7 +19,12 @@ export PATH="${SRC}/.pybin:${PATH}" # AMReX and Microphysics ship as git submodules under external/. cd "${SRC}/Exec/hydro_tests/Sedov" -make -j"${CORES}" COMP=gnu USE_MPI=FALSE DIM=2 \ +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +case "${COMPILER_TAG}" in gcc|default) CMP=gnu ;; oneapi) CMP=intel ;; *) CMP=llvm ;; esac +# AMReX names the binary with ${CMP}, so different compilers do not clobber. +# Override the actual compilers with the selected toolchain (gnu/llvm flag style). +make -j"${CORES}" COMP=${CMP} USE_MPI=FALSE DIM=2 \ + ${CXX:+CXX="${CXX}"} ${CC:+CC="${CC}"} ${FC:+FC="${FC}"} ${FC:+F90="${FC}"} \ AMREX_HOME="${SRC}/external/amrex" \ MICROPHYSICS_HOME="${SRC}/external/Microphysics" @@ -27,5 +32,7 @@ if ! ls *.ex >/dev/null 2>&1; then echo "Castro executable not built" exit 1 fi +mkdir -p "${SRC}/install-${COMPILER_TAG}/bin" +cp "$(ls -t *.ex | head -1)" "${SRC}/install-${COMPILER_TAG}/bin/Castro.ex" echo "Castro build step completed." diff --git a/script/app-cloverleaf/customize.py b/script/app-cloverleaf/customize.py index fb40b88f1..72ec5b72d 100644 --- a/script/app-cloverleaf/customize.py +++ b/script/app-cloverleaf/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_CLOVERLEAF_SRC_PATH', '') - install_dir = os.path.join(src_path, 'install') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + install_dir = os.path.join(src_path, 'install-' + compiler_tag) bin_dir = os.path.join(install_dir, 'bin') clover_bin = os.path.join(bin_dir, 'clover_leaf') diff --git a/script/app-cloverleaf/meta.yaml b/script/app-cloverleaf/meta.yaml index 68227cfe6..d09657712 100644 --- a/script/app-cloverleaf/meta.yaml +++ b/script/app-cloverleaf/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT: master + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-cloverleaf/run.sh b/script/app-cloverleaf/run.sh index c2e9872c2..7c05bb954 100644 --- a/script/app-cloverleaf/run.sh +++ b/script/app-cloverleaf/run.sh @@ -8,7 +8,9 @@ if [[ -z "${MLC_CLOVERLEAF_SRC_PATH}" ]]; then fi SRC="${MLC_CLOVERLEAF_SRC_PATH}" -INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" +case "${COMPILER_TAG}" in oneapi) CLV=INTEL ;; *) CLV=GNU ;; esac CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" echo "Building CloverLeaf-ref..." @@ -17,7 +19,8 @@ echo "Source: ${SRC}" cd "${SRC}" # CloverLeaf-ref uses Makefile with MPI Fortran -make COMPILER=GNU MPI_COMPILER=mpif90 C_MPI_COMPILER=mpicc -j${CORES} +make clean >/dev/null 2>&1 || true +make COMPILER=${CLV} MPI_COMPILER=mpif90 C_MPI_COMPILER=mpicc -j${CORES} # Install binary mkdir -p "${INSTALL_DIR}/bin" diff --git a/script/app-dalton/customize.py b/script/app-dalton/customize.py index 2d1461293..ae4187991 100644 --- a/script/app-dalton/customize.py +++ b/script/app-dalton/customize.py @@ -11,11 +11,12 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_DALTON_SRC_PATH', '') - binary = os.path.join(src_path, 'build', 'dalton.x') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + binary = os.path.join(src_path, 'build-' + compiler_tag, 'dalton.x') if not os.path.isfile(binary): return {'return': 1, 'error': f'DALTON binary not found at {binary}'} bin_dir = os.path.dirname(binary) - env['MLC_DALTON_INSTALL_PATH'] = os.path.join(src_path, 'build') + env['MLC_DALTON_INSTALL_PATH'] = os.path.join(src_path, 'build-' + compiler_tag) env['MLC_DALTON_BIN_PATH'] = bin_dir env['+PATH'] = [bin_dir] return {'return': 0} diff --git a/script/app-dalton/meta.yaml b/script/app-dalton/meta.yaml index d3c3ce974..453b8427d 100644 --- a/script/app-dalton/meta.yaml +++ b/script/app-dalton/meta.yaml @@ -81,6 +81,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: 2020.1 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-dalton/run.sh b/script/app-dalton/run.sh index d2d22c91d..0227f91e2 100644 --- a/script/app-dalton/run.sh +++ b/script/app-dalton/run.sh @@ -9,6 +9,8 @@ fi SRC="${MLC_DALTON_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="build-${COMPILER_TAG}" cd "${SRC}" git config --global --add safe.directory "${SRC}" || true @@ -19,10 +21,11 @@ if ! command -v python >/dev/null 2>&1; then fi export PATH="${SRC}/.pybin:${PATH}" -./setup --fc=gfortran --cc=gcc --cxx=g++ -cmake --build build -j"${CORES}" +rm -rf "${BUILD_DIR}" +./setup --fc="${FC:-gfortran}" --cc="${CC:-gcc}" --cxx="${CXX:-g++}" "${BUILD_DIR}" +cmake --build "${BUILD_DIR}" -j"${CORES}" -if [[ ! -f build/dalton.x ]]; then +if [[ ! -f "${BUILD_DIR}/dalton.x" ]]; then echo "DALTON binary not built" exit 1 fi diff --git a/script/app-enzo/customize.py b/script/app-enzo/customize.py index 008c3c755..4de53732c 100644 --- a/script/app-enzo/customize.py +++ b/script/app-enzo/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_ENZO_SRC_PATH', '') - bin_dir = os.path.join(src_path, 'src', 'enzo') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + bin_dir = os.path.join(src_path, 'install-' + compiler_tag, 'bin') binary = os.path.join(bin_dir, 'enzo.exe') if not os.path.isfile(binary): diff --git a/script/app-enzo/meta.yaml b/script/app-enzo/meta.yaml index fb7e771b0..1300bd06e 100644 --- a/script/app-enzo/meta.yaml +++ b/script/app-enzo/meta.yaml @@ -75,6 +75,49 @@ variations: env: MLC_GIT_CHECKOUT: main + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-enzo/run.sh b/script/app-enzo/run.sh index 26b02a373..f330550c4 100644 --- a/script/app-enzo/run.sh +++ b/script/app-enzo/run.sh @@ -13,7 +13,9 @@ CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" cd "${SRC}" ./configure +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" cd src/enzo +make clean >/dev/null 2>&1 || true make machine-linux-gnu MACH="Make.mach.linux-gnu" @@ -48,5 +50,6 @@ if [[ ! -x enzo.exe ]]; then echo "Enzo binary (enzo.exe) not built" exit 1 fi +mkdir -p "${SRC}/install-${COMPILER_TAG}/bin" && cp enzo.exe "${SRC}/install-${COMPILER_TAG}/bin/" echo "Enzo built successfully." diff --git a/script/app-epoch/customize.py b/script/app-epoch/customize.py index fa13f7fe5..07b841a0a 100644 --- a/script/app-epoch/customize.py +++ b/script/app-epoch/customize.py @@ -12,7 +12,8 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_EPOCH_SRC_PATH', '') - hits = glob.glob(os.path.join(src_path, 'epoch2d/bin/epoch2d'), recursive=True) + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + hits = glob.glob(os.path.join(src_path, 'install-' + compiler_tag, 'bin', 'epoch2d'), recursive=True) if not hits: return {'return': 1, 'error': f'EPOCH artifact not found under {src_path}'} bin_dir = os.path.dirname(hits[0]) diff --git a/script/app-epoch/meta.yaml b/script/app-epoch/meta.yaml index 855b793e7..973336dda 100644 --- a/script/app-epoch/meta.yaml +++ b/script/app-epoch/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v4.20.1 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-epoch/run.sh b/script/app-epoch/run.sh index 0af7c1b1e..3e21c945b 100644 --- a/script/app-epoch/run.sh +++ b/script/app-epoch/run.sh @@ -9,8 +9,12 @@ fi SRC="${MLC_EPOCH_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +case "${COMPILER_TAG}" in oneapi) EPC=intel ;; *) EPC=gfortran ;; esac cd "${SRC}/epoch2d" -make COMPILER=gfortran -j"${CORES}" +make clean >/dev/null 2>&1 || true +make COMPILER=${EPC} -j"${CORES}" +mkdir -p "${SRC}/install-${COMPILER_TAG}/bin" && cp bin/epoch2d "${SRC}/install-${COMPILER_TAG}/bin/" echo "EPOCH build step completed." diff --git a/script/app-gaia-benchmark/customize.py b/script/app-gaia-benchmark/customize.py new file mode 100644 index 000000000..1e87d46f0 --- /dev/null +++ b/script/app-gaia-benchmark/customize.py @@ -0,0 +1,43 @@ +from mlc import utils +import os + + +def preprocess(i): + env = i['env'] + + backend = str(env.get('MLC_GAIA_BACKEND', 'mock')).lower() + if backend == 'endpoint' and not env.get('MLC_GAIA_ENDPOINT_URL', '').strip(): + return {'return': 1, + 'error': 'endpoint backend requires --endpoint (MLC_GAIA_ENDPOINT_URL)'} + + # The workload is executed by the benchmark-program posthook dependency. + python_bin = env.get('MLC_PYTHON_BIN_WITH_PATH', 'python3') + script = os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], 'src', 'run_gaia.py') + env['MLC_RUN_CMD'] = f'{python_bin} "{script}"' + if not env.get('MLC_RUN_DIR', ''): + env['MLC_RUN_DIR'] = os.getcwd() + + return {'return': 0} + + +def postprocess(i): + env = i['env'] + state = i['state'] + logger = i['automation'].action_object.logger + + output_dir = env.get('MLC_GAIA_OUTPUT_DIR', '') or os.getcwd() + results_file = os.path.join(output_dir, 'gaia_results.json') + + if not os.path.isfile(results_file): + return {'return': 1, 'error': f'GAIA results not found: {results_file}'} + + import json + with open(results_file, encoding='utf-8') as f: + data = json.load(f) + + env['MLC_GAIA_RESULTS_FILE'] = results_file + env['MLC_GAIA_ACCURACY'] = str(data.get('accuracy', '')) + state['mlc_gaia'] = data + + logger.info(f"GAIA accuracy ({data.get('trace_type')}): {data.get('accuracy')}") + return {'return': 0} diff --git a/script/app-gaia-benchmark/data/tasks.jsonl b/script/app-gaia-benchmark/data/tasks.jsonl new file mode 100644 index 000000000..b208a2173 --- /dev/null +++ b/script/app-gaia-benchmark/data/tasks.jsonl @@ -0,0 +1,6 @@ +{"task_id": "gaia-val-0001", "Question": "How many studio albums were released by Mercedes Sosa between 2000 and 2009 inclusive?", "Level": 1, "Final answer": "3", "file_name": ""} +{"task_id": "gaia-val-0002", "Question": "What is the capital city of the country that hosted the 2016 Summer Olympics?", "Level": 1, "Final answer": "Brasilia", "file_name": ""} +{"task_id": "gaia-val-0003", "Question": "In the attached spreadsheet, what is the total revenue across all regions?", "Level": 2, "Final answer": "45230", "file_name": "revenue.xlsx"} +{"task_id": "gaia-val-0004", "Question": "Combining the two cited papers, how many total authors are listed?", "Level": 2, "Final answer": "11", "file_name": ""} +{"task_id": "gaia-val-0005", "Question": "After tracing the supply chain described across the three linked reports, which country appears in all three?", "Level": 3, "Final answer": "Chile", "file_name": ""} +{"task_id": "gaia-val-0006", "Question": "Following the multi-step research described, what is the sum of the two derived constants rounded to two decimals?", "Level": 3, "Final answer": "6.28", "file_name": ""} diff --git a/script/app-gaia-benchmark/meta.yaml b/script/app-gaia-benchmark/meta.yaml new file mode 100644 index 000000000..968f02fb1 --- /dev/null +++ b/script/app-gaia-benchmark/meta.yaml @@ -0,0 +1,193 @@ +alias: app-gaia-benchmark +uid: 767890856ac60b59 +automation_alias: script +automation_uid: 5b4e0237da074764 + +# Metadata +category: Agentic Benchmarks +tags: +- app +- agentic +- agent +- benchmark +- gaia +- general-ai-assistant +tags_help: app agentic benchmark gaia + +# Environment +default_env: + MLC_GAIA_NUM_SAMPLES: '3' + MLC_GAIA_MODEL: gpt-4o + MLC_GAIA_HF_MODEL: HuggingFaceTB/SmolLM2-135M-Instruct + MLC_GAIA_TRACE_TYPE: web + MLC_GAIA_SPLIT: validation + MLC_GAIA_BACKEND: mock + MLC_GAIA_DATASET: sample +new_env_keys: +- MLC_GAIA_* +new_state_keys: +- mlc_gaia + +# Input mapping +input_mapping: + num_samples: MLC_GAIA_NUM_SAMPLES + model: MLC_GAIA_MODEL + endpoint: MLC_GAIA_ENDPOINT_URL + api_key: MLC_GAIA_API_KEY + hf_model: MLC_GAIA_HF_MODEL + hf_token: MLC_GAIA_HF_TOKEN + trace_type: MLC_GAIA_TRACE_TYPE + level: MLC_GAIA_LEVEL + split: MLC_GAIA_SPLIT + task_file: MLC_GAIA_TASK_FILE + output_dir: MLC_GAIA_OUTPUT_DIR + profile_system_info: MLC_PROFILE_SYSTEM_INFO + perf_record: MLC_BENCHMARK_PERF_RECORD + perf_stat: MLC_BENCHMARK_PERF_STAT + insmix: MLC_BENCHMARK_INSMIX + perf_events: MLC_BENCHMARK_PERF_EVENTS +input_description: + num_samples: + desc: Number of GAIA tasks to run + model: + desc: Model name sent to the OpenAI-compatible endpoint (_endpoint backend) + endpoint: + desc: OpenAI-compatible chat completions endpoint URL (_endpoint backend) + api_key: + desc: API key for the endpoint + hf_model: + desc: HuggingFace model id for the local _hf-model backend + hf_token: + desc: HuggingFace token with access to the gated gaia-benchmark/GAIA dataset + trace_type: + desc: Agent trace type - web, rag or deep-research (controls trace length) + level: + desc: GAIA difficulty level to filter (1, 2 or 3) + split: + desc: GAIA split - validation or test + task_file: + desc: Path to a custom GAIA metadata JSONL file + output_dir: + desc: Directory to write results.json (default is current directory) + +# Dependencies +deps: +- tags: detect,os +- names: + - python + - python3 + tags: get,python3 +- tags: get,generic-python-lib,_package.requests + +# The benchmark command (MLC_RUN_CMD) is executed through benchmark-program. +posthook_deps: +- tags: benchmark-program + names: + - benchmark-program + skip_if_env: + MLC_SKIP_RUN: + - 'on' + +# Variations +variations: + # ── backend group (which model answers the questions) ──────────────────── + dry-run: + group: backend + default: true + env: + MLC_GAIA_BACKEND: mock + endpoint: + group: backend + env: + MLC_GAIA_BACKEND: endpoint + deps: + - tags: get,generic-python-lib,_package.openai + hf-model: + group: backend + env: + MLC_GAIA_BACKEND: hf + deps: + - tags: get,generic-python-lib,_package.torch + - tags: get,generic-python-lib,_package.transformers + - tags: get,generic-python-lib,_package.accelerate + + # ── dataset group (bundled sample vs gated official GAIA dataset) ───────── + sample: + group: dataset + default: true + env: + MLC_GAIA_DATASET: sample + real: + group: dataset + env: + MLC_GAIA_DATASET: real + deps: + - tags: get,generic-python-lib,_package.huggingface_hub + + # ── trace-type group (varying-length agent traces) ─────────────────────── + web: + group: trace-type + default: true + env: + MLC_GAIA_TRACE_TYPE: web + rag: + group: trace-type + env: + MLC_GAIA_TRACE_TYPE: rag + deep-research: + group: trace-type + env: + MLC_GAIA_TRACE_TYPE: deep-research + + # ── level filter ───────────────────────────────────────────────────────── + level.1: + group: level + env: + MLC_GAIA_LEVEL: '1' + level.2: + group: level + env: + MLC_GAIA_LEVEL: '2' + level.3: + group: level + env: + MLC_GAIA_LEVEL: '3' + + # ── split group ────────────────────────────────────────────────────────── + validation: + group: split + default: true + env: + MLC_GAIA_SPLIT: validation + test: + group: split + env: + MLC_GAIA_SPLIT: test + + # ── profiling passthrough (routes _profile to benchmark-program) ───────── + profile: + add_deps_recursive: + benchmark-program: + tags: _profile + +# Tests +tests: + run_inputs: + - variations_list: + - dry-run + - sample + - web + env: + MLC_GAIA_NUM_SAMPLES: '2' + - variations_list: + - dry-run + - sample + - rag + env: + MLC_GAIA_NUM_SAMPLES: '2' + - variations_list: + - dry-run + - sample + - deep-research + env: + MLC_GAIA_NUM_SAMPLES: '2' diff --git a/script/app-gaia-benchmark/run.bat b/script/app-gaia-benchmark/run.bat new file mode 100644 index 000000000..f6537adfc --- /dev/null +++ b/script/app-gaia-benchmark/run.bat @@ -0,0 +1,6 @@ +@echo off +if "%MLC_PYTHON_BIN_WITH_PATH%"=="" (set MLC_PYTHON_BIN=python) else (set MLC_PYTHON_BIN=%MLC_PYTHON_BIN_WITH_PATH%) +if "%MLC_TMP_CURRENT_SCRIPT_PATH%"=="" (set MLC_TMP_CURRENT_SCRIPT_PATH=%CD%) + +echo GAIA run is delegated to the benchmark-program dependency (MLC_RUN_CMD). +exit /b 0 diff --git a/script/app-gaia-benchmark/run.sh b/script/app-gaia-benchmark/run.sh new file mode 100644 index 000000000..4169f318f --- /dev/null +++ b/script/app-gaia-benchmark/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +MLC_PYTHON_BIN=${MLC_PYTHON_BIN_WITH_PATH:-python3} +MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} + +echo "GAIA run is delegated to the benchmark-program dependency (MLC_RUN_CMD)." +exit 0 diff --git a/script/app-gaia-benchmark/src/run_gaia.py b/script/app-gaia-benchmark/src/run_gaia.py new file mode 100644 index 000000000..676b95a2f --- /dev/null +++ b/script/app-gaia-benchmark/src/run_gaia.py @@ -0,0 +1,197 @@ +#!/usr/bin/env python3 +"""GAIA (General AI Assistants) benchmark harness for MLC. + +Datasets: + * sample : bundled data/tasks.jsonl (offline, for CI). + * real : the gated official gaia-benchmark/GAIA dataset, downloaded via + huggingface_hub using an HF token with access. + +Trace types (agent reasoning-trace length): web < rag < deep-research. + +Model backends: + * mock : deterministic, offline (dry-run) - no model required. + * endpoint : OpenAI-compatible chat completions endpoint. + * hf : local HuggingFace transformers model. +Scoring uses GAIA-style normalised exact match against the gold final answer. +""" +import json +import os +import re +import sys +import time +from pathlib import Path + +TRACE_STEPS = {"web": 3, "rag": 8, "deep-research": 20} + + +def _env(name, default=""): + return os.environ.get(name, default).strip() + + +def normalise(ans): + ans = str(ans).strip().lower() + ans = re.sub(r"[^\w\s]", "", ans) + ans = re.sub(r"\s+", " ", ans) + return ans + + +def load_tasks(): + task_file = _env("MLC_GAIA_TASK_FILE") + dataset = _env("MLC_GAIA_DATASET", "sample") + if not task_file and dataset == "real": + from huggingface_hub import hf_hub_download + from huggingface_hub.errors import GatedRepoError + split = _env("MLC_GAIA_SPLIT", "validation") + token = _env("MLC_GAIA_HF_TOKEN") or os.environ.get("HF_TOKEN") or None + try: + task_file = hf_hub_download( + repo_id="gaia-benchmark/GAIA", + filename=f"2023/{split}/metadata.jsonl", + repo_type="dataset", + token=token) + except GatedRepoError: + raise SystemExit( + "GAIA is a gated dataset. Request access at " + "https://huggingface.co/datasets/gaia-benchmark/GAIA and pass a " + "token with --hf_token= (or set HF_TOKEN).") + if not task_file: + task_file = str(Path(__file__).parent.parent / "data" / "tasks.jsonl") + if not os.path.isfile(task_file): + raise FileNotFoundError(f"GAIA task file not found: {task_file}") + tasks = [] + with open(task_file, encoding="utf-8") as f: + for line in f: + line = line.strip() + if line: + task = json.loads(line) + if task.get("Question"): + tasks.append(task) + return tasks + + +def make_generator(): + backend = _env("MLC_GAIA_BACKEND", "mock") + if backend == "endpoint": + from openai import OpenAI + client = OpenAI(base_url=_env("MLC_GAIA_ENDPOINT_URL") or None, + api_key=_env("MLC_GAIA_API_KEY") or "EMPTY") + model = _env("MLC_GAIA_MODEL", "gpt-4o") + + def gen(system, user, max_tokens=512): + resp = client.chat.completions.create( + model=model, + messages=[{"role": "system", "content": system}, + {"role": "user", "content": user}], + max_tokens=max_tokens) + return resp.choices[0].message.content + return gen, backend + + if backend == "hf": + import torch + from transformers import AutoModelForCausalLM, AutoTokenizer + model_id = _env("MLC_GAIA_HF_MODEL", "HuggingFaceTB/SmolLM2-135M-Instruct") + tok = AutoTokenizer.from_pretrained(model_id) + model = AutoModelForCausalLM.from_pretrained(model_id) + model.eval() + + def gen(system, user, max_tokens=256): + prompt = tok.apply_chat_template( + [{"role": "system", "content": system}, + {"role": "user", "content": user}], + add_generation_prompt=True, tokenize=False) + enc = tok(prompt, return_tensors="pt") + with torch.no_grad(): + out = model.generate(**enc, max_new_tokens=max_tokens, + do_sample=False, + pad_token_id=tok.eos_token_id) + return tok.decode(out[0][enc["input_ids"].shape[1]:], + skip_special_tokens=True) + return gen, backend + + return None, "mock" + + +def answer(task, generator, trace_type): + if generator is None: # mock + correct = (sum(ord(c) for c in str(task.get("task_id", ""))) % 2) == 0 + return task.get("Final answer", "") if correct else "[mock] uncertain" + system = ("You are a general AI assistant. Answer with the final answer " + "only, using the GAIA answer format (a number, a short string, or " + f"a comma separated list). Trace type: {trace_type}") + return generator(system, task.get("Question", "")) + + +def main(): + num_samples = int(_env("MLC_GAIA_NUM_SAMPLES", "3") or "3") + trace_type = _env("MLC_GAIA_TRACE_TYPE", "web") + level = _env("MLC_GAIA_LEVEL") + split = _env("MLC_GAIA_SPLIT", "validation") + dataset = _env("MLC_GAIA_DATASET", "sample") + output_dir = _env("MLC_GAIA_OUTPUT_DIR") or os.getcwd() + + if trace_type not in TRACE_STEPS: + print(f"ERROR: unknown trace_type '{trace_type}'", file=sys.stderr) + return 1 + + generator, backend = make_generator() + + tasks = load_tasks() + if level: + tasks = [t for t in tasks if str(t.get("Level", "")) == str(level)] + tasks = tasks[:num_samples] + if not tasks: + print("ERROR: no tasks selected", file=sys.stderr) + return 1 + + print(f"GAIA: {len(tasks)} task(s) | dataset={dataset} trace_type={trace_type} " + f"split={split} backend={backend}") + + results = [] + start = time.time() + for task in tasks: + predicted = answer(task, generator, trace_type) + gold = task.get("Final answer", "") + correct = normalise(predicted) == normalise(gold) + results.append({ + "task_id": task.get("task_id"), + "level": task.get("Level"), + "question": task.get("Question"), + "gold": gold, + "predicted": predicted, + "correct": correct, + "trace_steps": TRACE_STEPS[trace_type], + }) + print(f" [L{task.get('Level', '?')}] " + f"{'CORRECT' if correct else 'WRONG'} " + f"({TRACE_STEPS[trace_type]} trace steps)") + + correct_n = sum(1 for r in results if r["correct"]) + summary = { + "benchmark": "gaia", + "backend": backend, + "dataset": dataset, + "model": _env("MLC_GAIA_HF_MODEL") if backend == "hf" + else _env("MLC_GAIA_MODEL"), + "trace_type": trace_type, + "split": split, + "num_tasks": len(results), + "num_correct": correct_n, + "accuracy": round(correct_n / len(results), 4), + "avg_trace_steps": TRACE_STEPS[trace_type], + "wall_time_sec": round(time.time() - start, 3), + "results": results, + } + + os.makedirs(output_dir, exist_ok=True) + out_file = os.path.join(output_dir, "gaia_results.json") + with open(out_file, "w", encoding="utf-8") as f: + json.dump(summary, f, indent=2) + + print(f"Accuracy: {summary['accuracy'] * 100:.1f}% " + f"({correct_n}/{len(results)})") + print(f"Results written to {out_file}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/script/app-genesis/customize.py b/script/app-genesis/customize.py index cd5f7c80b..439aa9dfe 100644 --- a/script/app-genesis/customize.py +++ b/script/app-genesis/customize.py @@ -11,11 +11,12 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_GENESIS_SRC_PATH', '') - binary = os.path.join(src_path, 'install/bin/atdyn') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + binary = os.path.join(src_path, 'install-' + compiler_tag, 'bin', 'atdyn') if not os.path.isfile(binary): return {'return': 1, 'error': f'GENESIS binary not found at {binary}'} bin_dir = os.path.dirname(binary) - env['MLC_GENESIS_INSTALL_PATH'] = os.path.join(src_path, 'install') + env['MLC_GENESIS_INSTALL_PATH'] = os.path.join(src_path, 'install-' + compiler_tag) env['MLC_GENESIS_BIN_PATH'] = bin_dir env['+PATH'] = [bin_dir] return {'return': 0} diff --git a/script/app-genesis/meta.yaml b/script/app-genesis/meta.yaml index 2601e69a4..b696e66e1 100644 --- a/script/app-genesis/meta.yaml +++ b/script/app-genesis/meta.yaml @@ -80,6 +80,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v2.1.6.1 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-genesis/run.sh b/script/app-genesis/run.sh index f7ea0412a..499daaa5d 100644 --- a/script/app-genesis/run.sh +++ b/script/app-genesis/run.sh @@ -8,7 +8,8 @@ if [[ -z "${MLC_GENESIS_SRC_PATH}" ]]; then fi SRC="${MLC_GENESIS_SRC_PATH}" -INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" PYTHON="${MLC_PYTHON_BIN_WITH_PATH:-python3}" MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} @@ -16,6 +17,7 @@ MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} cd "${SRC}" [ -x ./configure ] || autoreconf -fi ./configure FC=mpif90 CC=mpicc --prefix="${INSTALL_DIR}" +make clean >/dev/null 2>&1 || true make -j${CORES} make install diff --git a/script/app-gromacs/customize.py b/script/app-gromacs/customize.py index 885578de2..af26192cf 100644 --- a/script/app-gromacs/customize.py +++ b/script/app-gromacs/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_GROMACS_SRC_PATH', '') - install_dir = os.path.join(src_path, 'install') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + install_dir = os.path.join(src_path, 'install-' + compiler_tag) bin_dir = os.path.join(install_dir, 'bin') gmx_bin = os.path.join(bin_dir, 'gmx_mpi') diff --git a/script/app-gromacs/meta.yaml b/script/app-gromacs/meta.yaml index 37563b4e4..eccf9169c 100644 --- a/script/app-gromacs/meta.yaml +++ b/script/app-gromacs/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT: main + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-gromacs/run.sh b/script/app-gromacs/run.sh index 670516319..9b3717dc2 100644 --- a/script/app-gromacs/run.sh +++ b/script/app-gromacs/run.sh @@ -8,8 +8,10 @@ if [[ -z "${MLC_GROMACS_SRC_PATH}" ]]; then fi SRC="${MLC_GROMACS_SRC_PATH}" -BUILD_DIR="${SRC}/build" -INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="${SRC}/build-${COMPILER_TAG}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" +rm -rf "${BUILD_DIR}" # fresh dir so cmake re-detects the selected compiler CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" echo "Building GROMACS..." diff --git a/script/app-hmmer/customize.py b/script/app-hmmer/customize.py index 9faae03ee..c00fb8cf4 100644 --- a/script/app-hmmer/customize.py +++ b/script/app-hmmer/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_HMMER_SRC_PATH', '') - install_dir = os.path.join(src_path, 'install') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + install_dir = os.path.join(src_path, 'install-' + compiler_tag) bin_dir = os.path.join(install_dir, 'bin') hmmsearch_bin = os.path.join(bin_dir, 'hmmsearch') diff --git a/script/app-hmmer/meta.yaml b/script/app-hmmer/meta.yaml index 43037ad46..95af363a2 100644 --- a/script/app-hmmer/meta.yaml +++ b/script/app-hmmer/meta.yaml @@ -77,6 +77,48 @@ variations: env: MLC_GIT_CHECKOUT: master + # ---- Compiler variations (resolve CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-hmmer/run.sh b/script/app-hmmer/run.sh index bff64b36e..5ed10d74d 100644 --- a/script/app-hmmer/run.sh +++ b/script/app-hmmer/run.sh @@ -8,7 +8,9 @@ if [[ -z "${MLC_HMMER_SRC_PATH}" ]]; then fi SRC="${MLC_HMMER_SRC_PATH}" -INSTALL_DIR="${SRC}/install" +# Isolate the build per compiler so different toolchains do not clobber each other. +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" echo "Building HMMER..." @@ -27,10 +29,15 @@ if [[ ! -f configure ]]; then autoconf fi -# Configure with MPI support +# Configure with MPI support. mpicc/mpifort pick the underlying compiler from +# OMPI_CC/OMPI_FC exported by get-compiler-paths-amd for the selected family. ./configure --prefix="${INSTALL_DIR}" --enable-mpi CC=mpicc -echo "Building HMMER with ${CORES} cores..." +# Force recompile so object files from another compiler are not reused (keeps +# autotools auxiliary files, unlike distclean). +make clean >/dev/null 2>&1 || true + +echo "Building HMMER (${COMPILER_TAG}) with ${CORES} cores..." make -j${CORES} echo "Installing HMMER..." diff --git a/script/app-hotpotqa/customize.py b/script/app-hotpotqa/customize.py new file mode 100644 index 000000000..73fb059cb --- /dev/null +++ b/script/app-hotpotqa/customize.py @@ -0,0 +1,44 @@ +from mlc import utils +import os + + +def preprocess(i): + env = i['env'] + + backend = str(env.get('MLC_HOTPOTQA_BACKEND', 'mock')).lower() + if backend == 'endpoint' and not env.get('MLC_HOTPOTQA_ENDPOINT_URL', '').strip(): + return {'return': 1, + 'error': 'endpoint backend requires --endpoint (MLC_HOTPOTQA_ENDPOINT_URL)'} + + # The workload is executed by the benchmark-program posthook dependency. + python_bin = env.get('MLC_PYTHON_BIN_WITH_PATH', 'python3') + script = os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], 'src', 'run_hotpotqa.py') + env['MLC_RUN_CMD'] = f'{python_bin} "{script}"' + if not env.get('MLC_RUN_DIR', ''): + env['MLC_RUN_DIR'] = os.getcwd() + + return {'return': 0} + + +def postprocess(i): + env = i['env'] + state = i['state'] + logger = i['automation'].action_object.logger + + output_dir = env.get('MLC_HOTPOTQA_OUTPUT_DIR', '') or os.getcwd() + results_file = os.path.join(output_dir, 'hotpotqa_results.json') + + if not os.path.isfile(results_file): + return {'return': 1, 'error': f'HotpotQA results not found: {results_file}'} + + import json + with open(results_file, encoding='utf-8') as f: + data = json.load(f) + + env['MLC_HOTPOTQA_RESULTS_FILE'] = results_file + env['MLC_HOTPOTQA_EXACT_MATCH'] = str(data.get('exact_match', '')) + env['MLC_HOTPOTQA_F1'] = str(data.get('f1', '')) + state['mlc_hotpotqa'] = data + + logger.info(f"HotpotQA EM: {data.get('exact_match')}, F1: {data.get('f1')}") + return {'return': 0} diff --git a/script/app-hotpotqa/data/tasks.jsonl b/script/app-hotpotqa/data/tasks.jsonl new file mode 100644 index 000000000..056b31371 --- /dev/null +++ b/script/app-hotpotqa/data/tasks.jsonl @@ -0,0 +1,6 @@ +{"_id": "hp-0001", "level": "medium", "type": "bridge", "question": "The director of the 1994 film that won Best Picture was born in what year?", "answer": "1954", "context": [["Forrest Gump", ["Forrest Gump is a 1994 American film.", "It won the Academy Award for Best Picture."]], ["Robert Zemeckis", ["Robert Zemeckis is an American filmmaker born in 1952.", "He directed Forrest Gump."]]], "supporting_facts": [["Forrest Gump", 1], ["Robert Zemeckis", 0]]} +{"_id": "hp-0002", "level": "hard", "type": "comparison", "question": "Which river is longer, the Nile or the Amazon?", "answer": "Nile", "context": [["Nile", ["The Nile is about 6650 km long."]], ["Amazon River", ["The Amazon is about 6400 km long."]]], "supporting_facts": [["Nile", 0], ["Amazon River", 0]]} +{"_id": "hp-0003", "level": "easy", "type": "bridge", "question": "What is the capital of the country where the Eiffel Tower is located?", "answer": "Paris", "context": [["Eiffel Tower", ["The Eiffel Tower is located in France."]], ["France", ["The capital of France is Paris."]]], "supporting_facts": [["Eiffel Tower", 0], ["France", 0]]} +{"_id": "hp-0004", "level": "medium", "type": "bridge", "question": "The author of Pride and Prejudice was born in which county?", "answer": "Hampshire", "context": [["Pride and Prejudice", ["Pride and Prejudice was written by Jane Austen."]], ["Jane Austen", ["Jane Austen was born in Hampshire, England."]]], "supporting_facts": [["Pride and Prejudice", 0], ["Jane Austen", 0]]} +{"_id": "hp-0005", "level": "hard", "type": "comparison", "question": "Who was born first, Isaac Newton or Albert Einstein?", "answer": "Isaac Newton", "context": [["Isaac Newton", ["Isaac Newton was born in 1643."]], ["Albert Einstein", ["Albert Einstein was born in 1879."]]], "supporting_facts": [["Isaac Newton", 0], ["Albert Einstein", 0]]} +{"_id": "hp-0006", "level": "easy", "type": "bridge", "question": "In which ocean is the largest coral reef system located?", "answer": "Pacific Ocean", "context": [["Great Barrier Reef", ["The Great Barrier Reef is the largest coral reef system."]], ["Coral Sea", ["The Coral Sea is part of the Pacific Ocean."]]], "supporting_facts": [["Great Barrier Reef", 0], ["Coral Sea", 0]]} diff --git a/script/app-hotpotqa/meta.yaml b/script/app-hotpotqa/meta.yaml new file mode 100644 index 000000000..42b8baf78 --- /dev/null +++ b/script/app-hotpotqa/meta.yaml @@ -0,0 +1,176 @@ +alias: app-hotpotqa +uid: 1bf85402e3bc7f8f +automation_alias: script +automation_uid: 5b4e0237da074764 + +# Metadata +category: Agentic Benchmarks +tags: +- app +- agentic +- agent +- benchmark +- qa +- multi-hop +- hotpotqa +tags_help: app agentic benchmark hotpotqa + +# Environment +default_env: + MLC_HOTPOTQA_NUM_SAMPLES: '3' + MLC_HOTPOTQA_MODEL: gpt-4o + MLC_HOTPOTQA_HF_MODEL: HuggingFaceTB/SmolLM2-135M-Instruct + MLC_HOTPOTQA_BACKEND: mock + MLC_HOTPOTQA_DATASET: sample + MLC_HOTPOTQA_SETTING: distractor +new_env_keys: +- MLC_HOTPOTQA_* +new_state_keys: +- mlc_hotpotqa + +# Input mapping +input_mapping: + num_samples: MLC_HOTPOTQA_NUM_SAMPLES + model: MLC_HOTPOTQA_MODEL + endpoint: MLC_HOTPOTQA_ENDPOINT_URL + api_key: MLC_HOTPOTQA_API_KEY + hf_model: MLC_HOTPOTQA_HF_MODEL + level: MLC_HOTPOTQA_LEVEL + task_file: MLC_HOTPOTQA_TASK_FILE + output_dir: MLC_HOTPOTQA_OUTPUT_DIR + profile_system_info: MLC_PROFILE_SYSTEM_INFO + perf_record: MLC_BENCHMARK_PERF_RECORD + perf_stat: MLC_BENCHMARK_PERF_STAT + insmix: MLC_BENCHMARK_INSMIX + perf_events: MLC_BENCHMARK_PERF_EVENTS +input_description: + num_samples: + desc: Number of HotpotQA questions to run + model: + desc: Model name sent to the OpenAI-compatible endpoint (_endpoint backend) + endpoint: + desc: OpenAI-compatible chat completions endpoint URL (_endpoint backend) + api_key: + desc: API key for the endpoint + hf_model: + desc: HuggingFace model id for the local _hf-model backend + level: + desc: Difficulty level to filter (easy, medium, hard) + task_file: + desc: Path to a custom HotpotQA task file (.jsonl / .json / .parquet) + output_dir: + desc: Directory to write results.json (default is current directory) + +# Dependencies +deps: +- tags: detect,os +- names: + - python + - python3 + tags: get,python3 +- tags: get,generic-python-lib,_package.requests + +# The benchmark command (MLC_RUN_CMD) is executed through benchmark-program. +posthook_deps: +- tags: benchmark-program + names: + - benchmark-program + skip_if_env: + MLC_SKIP_RUN: + - 'on' + +# Variations +variations: + # ── backend group (which model answers the questions) ──────────────────── + dry-run: + group: backend + default: true + env: + MLC_HOTPOTQA_BACKEND: mock + endpoint: + group: backend + env: + MLC_HOTPOTQA_BACKEND: endpoint + deps: + - tags: get,generic-python-lib,_package.openai + hf-model: + group: backend + env: + MLC_HOTPOTQA_BACKEND: hf + deps: + - tags: get,generic-python-lib,_package.torch + - tags: get,generic-python-lib,_package.transformers + - tags: get,generic-python-lib,_package.accelerate + + # ── dataset group (bundled sample vs official HotpotQA dev set) ─────────── + sample: + group: dataset + default: true + env: + MLC_HOTPOTQA_DATASET: sample + real: + group: dataset + env: + MLC_HOTPOTQA_DATASET: real + deps: + - tags: get,generic-python-lib,_package.pandas + - tags: get,generic-python-lib,_package.pyarrow + - tags: download,file,_wget + names: + - hotpotqa-dataset + force_cache: true + extra_cache_tags: hotpotqa,dataset + env: + MLC_DOWNLOAD_FINAL_ENV_NAME: MLC_HOTPOTQA_TASK_FILE + MLC_DOWNLOAD_FILENAME: hotpotqa_validation.parquet + update_tags_from_env_with_prefix: + _url.: + - MLC_HOTPOTQA_DATASET_URL + + # ── setting group (selects the official split url) ─────────────────────── + distractor: + group: setting + default: true + env: + MLC_HOTPOTQA_SETTING: distractor + MLC_HOTPOTQA_DATASET_URL: https://huggingface.co/api/datasets/hotpotqa/hotpot_qa/parquet/distractor/validation/0.parquet + fullwiki: + group: setting + env: + MLC_HOTPOTQA_SETTING: fullwiki + MLC_HOTPOTQA_DATASET_URL: https://huggingface.co/api/datasets/hotpotqa/hotpot_qa/parquet/fullwiki/validation/0.parquet + + # ── level filter ───────────────────────────────────────────────────────── + level.easy: + group: level + env: + MLC_HOTPOTQA_LEVEL: easy + level.medium: + group: level + env: + MLC_HOTPOTQA_LEVEL: medium + level.hard: + group: level + env: + MLC_HOTPOTQA_LEVEL: hard + + # ── profiling passthrough (routes _profile to benchmark-program) ───────── + profile: + add_deps_recursive: + benchmark-program: + tags: _profile + +# Tests +tests: + run_inputs: + - variations_list: + - dry-run + - sample + env: + MLC_HOTPOTQA_NUM_SAMPLES: '2' + - variations_list: + - dry-run + - sample + - fullwiki + env: + MLC_HOTPOTQA_NUM_SAMPLES: '2' diff --git a/script/app-hotpotqa/run.bat b/script/app-hotpotqa/run.bat new file mode 100644 index 000000000..c203c75d9 --- /dev/null +++ b/script/app-hotpotqa/run.bat @@ -0,0 +1,6 @@ +@echo off +if "%MLC_PYTHON_BIN_WITH_PATH%"=="" (set MLC_PYTHON_BIN=python) else (set MLC_PYTHON_BIN=%MLC_PYTHON_BIN_WITH_PATH%) +if "%MLC_TMP_CURRENT_SCRIPT_PATH%"=="" (set MLC_TMP_CURRENT_SCRIPT_PATH=%CD%) + +echo HotpotQA run is delegated to the benchmark-program dependency (MLC_RUN_CMD). +exit /b 0 diff --git a/script/app-hotpotqa/run.sh b/script/app-hotpotqa/run.sh new file mode 100644 index 000000000..4156714d3 --- /dev/null +++ b/script/app-hotpotqa/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +MLC_PYTHON_BIN=${MLC_PYTHON_BIN_WITH_PATH:-python3} +MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} + +echo "HotpotQA run is delegated to the benchmark-program dependency (MLC_RUN_CMD)." +exit 0 diff --git a/script/app-hotpotqa/src/run_hotpotqa.py b/script/app-hotpotqa/src/run_hotpotqa.py new file mode 100644 index 000000000..3a218bf5c --- /dev/null +++ b/script/app-hotpotqa/src/run_hotpotqa.py @@ -0,0 +1,218 @@ +#!/usr/bin/env python3 +"""HotpotQA multi-hop question-answering benchmark harness for MLC. + +Datasets: + * sample : bundled data/tasks.jsonl (offline, for CI). + * real : official HotpotQA dev split downloaded as parquet by mlcflow and + passed in via MLC_HOTPOTQA_TASK_FILE. + +Model backends: + * mock : deterministic, offline (dry-run) - no model required. + * endpoint : OpenAI-compatible chat completions endpoint. + * hf : local HuggingFace transformers model (CPU or GPU). + +Scoring uses official-style Exact Match (EM) and token-level F1. +""" +import json +import os +import re +import string +import sys +import time +from collections import Counter +from pathlib import Path + + +def _env(name, default=""): + return os.environ.get(name, default).strip() + + +def normalise(text): + text = str(text).lower() + text = "".join(ch for ch in text if ch not in set(string.punctuation)) + text = re.sub(r"\b(a|an|the)\b", " ", text) + return " ".join(text.split()) + + +def f1_score(pred, gold): + pred_tokens = normalise(pred).split() + gold_tokens = normalise(gold).split() + if not pred_tokens or not gold_tokens: + return float(pred_tokens == gold_tokens) + common = Counter(pred_tokens) & Counter(gold_tokens) + num_same = sum(common.values()) + if num_same == 0: + return 0.0 + precision = num_same / len(pred_tokens) + recall = num_same / len(gold_tokens) + return 2 * precision * recall / (precision + recall) + + +def _context_to_text(context): + """Normalise both the bundled ([title, [sents]]) and HF parquet + ({'title': [...], 'sentences': [[...]]}) context formats to plain text.""" + parts = [] + if isinstance(context, dict) and "title" in context: + titles = list(context.get("title", [])) + sentences = list(context.get("sentences", [])) + for title, sents in zip(titles, sentences): + parts.append(f"{title}: {' '.join(sents)}") + else: + for entry in context or []: + title, sents = entry[0], entry[1] + parts.append(f"{title}: {' '.join(sents)}") + return "\n".join(parts) + + +def load_tasks(): + task_file = _env("MLC_HOTPOTQA_TASK_FILE") + dataset = _env("MLC_HOTPOTQA_DATASET", "sample") + if not task_file: + if dataset == "real": + raise FileNotFoundError( + "Real dataset selected but MLC_HOTPOTQA_TASK_FILE is not set " + "(download dependency did not run)") + task_file = str(Path(__file__).parent.parent / "data" / "tasks.jsonl") + if not os.path.isfile(task_file): + raise FileNotFoundError(f"HotpotQA task file not found: {task_file}") + + tasks = [] + if task_file.endswith(".parquet"): + import pandas as pd + df = pd.read_parquet(task_file) + for row in df.to_dict(orient="records"): + tasks.append(row) + elif task_file.endswith(".jsonl"): + with open(task_file, encoding="utf-8") as f: + for line in f: + line = line.strip() + if line: + tasks.append(json.loads(line)) + else: # .json - official HotpotQA is a single JSON list + with open(task_file, encoding="utf-8") as f: + tasks = json.load(f) + return tasks + + +def make_generator(): + backend = _env("MLC_HOTPOTQA_BACKEND", "mock") + if backend == "endpoint": + from openai import OpenAI + client = OpenAI(base_url=_env("MLC_HOTPOTQA_ENDPOINT_URL") or None, + api_key=_env("MLC_HOTPOTQA_API_KEY") or "EMPTY") + model = _env("MLC_HOTPOTQA_MODEL", "gpt-4o") + + def gen(system, user, max_tokens=128): + resp = client.chat.completions.create( + model=model, + messages=[{"role": "system", "content": system}, + {"role": "user", "content": user}], + max_tokens=max_tokens) + return resp.choices[0].message.content + return gen, backend + + if backend == "hf": + import torch + from transformers import AutoModelForCausalLM, AutoTokenizer + model_id = _env("MLC_HOTPOTQA_HF_MODEL", + "HuggingFaceTB/SmolLM2-135M-Instruct") + tok = AutoTokenizer.from_pretrained(model_id) + model = AutoModelForCausalLM.from_pretrained(model_id) + model.eval() + + def gen(system, user, max_tokens=128): + messages = [{"role": "system", "content": system}, + {"role": "user", "content": user}] + prompt = tok.apply_chat_template( + messages, add_generation_prompt=True, tokenize=False) + enc = tok(prompt, return_tensors="pt") + with torch.no_grad(): + out = model.generate(**enc, max_new_tokens=max_tokens, + do_sample=False, + pad_token_id=tok.eos_token_id) + new_tokens = out[0][enc["input_ids"].shape[1]:] + return tok.decode(new_tokens, skip_special_tokens=True) + return gen, backend + + return None, "mock" + + +def answer(task, generator): + if generator is None: # mock: correct on even hash, deterministic + tid = str(task.get("_id", task.get("id", task.get("question", "")))) + correct = (sum(ord(c) for c in tid) % 2) == 0 + return task.get("answer", "") if correct else "[mock] unknown" + system = ("Answer the multi-hop question using only the provided context. " + "Reply with the short answer only, no explanation.") + user = (f"Context:\n{_context_to_text(task.get('context'))}\n\n" + f"Question: {task.get('question', '')}") + return generator(system, user) + + +def main(): + num_samples = int(_env("MLC_HOTPOTQA_NUM_SAMPLES", "3") or "3") + level = _env("MLC_HOTPOTQA_LEVEL") + setting = _env("MLC_HOTPOTQA_SETTING", "distractor") + dataset = _env("MLC_HOTPOTQA_DATASET", "sample") + output_dir = _env("MLC_HOTPOTQA_OUTPUT_DIR") or os.getcwd() + + generator, backend = make_generator() + + tasks = load_tasks() + if level: + tasks = [t for t in tasks if str(t.get("level", "")) == level] + tasks = tasks[:num_samples] + if not tasks: + print("ERROR: no tasks selected", file=sys.stderr) + return 1 + + print(f"HotpotQA: {len(tasks)} question(s) | dataset={dataset} " + f"setting={setting} backend={backend}") + + results = [] + start = time.time() + for task in tasks: + predicted = answer(task, generator) + gold = task.get("answer", "") + em = float(normalise(predicted) == normalise(gold)) + f1 = f1_score(predicted, gold) + results.append({ + "_id": task.get("_id", task.get("id")), + "level": task.get("level"), + "type": task.get("type"), + "question": task.get("question"), + "gold": gold, + "predicted": predicted, + "em": em, + "f1": round(f1, 4), + }) + print(f" [{task.get('level', '?')}] EM={em:.0f} F1={f1:.2f}") + + n = len(results) + summary = { + "benchmark": "hotpotqa", + "backend": backend, + "dataset": dataset, + "setting": setting, + "model": _env("MLC_HOTPOTQA_HF_MODEL") if backend == "hf" + else _env("MLC_HOTPOTQA_MODEL"), + "num_questions": n, + "exact_match": round(sum(r["em"] for r in results) / n, 4), + "f1": round(sum(r["f1"] for r in results) / n, 4), + "wall_time_sec": round(time.time() - start, 3), + "results": results, + } + + os.makedirs(output_dir, exist_ok=True) + out_file = os.path.join(output_dir, "hotpotqa_results.json") + with open(out_file, "w", encoding="utf-8") as f: + json.dump(summary, f, indent=2) + + print(f"EM: {summary['exact_match'] * 100:.1f}% " + f"F1: {summary['f1'] * 100:.1f}%") + print(f"Results written to {out_file}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/script/app-lammps/customize.py b/script/app-lammps/customize.py index f5cff3626..25dcdbaf9 100644 --- a/script/app-lammps/customize.py +++ b/script/app-lammps/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_LAMMPS_SRC_PATH', '') - install_dir = os.path.join(src_path, 'install') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + install_dir = os.path.join(src_path, 'install-' + compiler_tag) bin_dir = os.path.join(install_dir, 'bin') lmp_bin = os.path.join(bin_dir, 'lmp') diff --git a/script/app-lammps/meta.yaml b/script/app-lammps/meta.yaml index 6824c8900..5af9f1909 100644 --- a/script/app-lammps/meta.yaml +++ b/script/app-lammps/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT: develop + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-lammps/run.sh b/script/app-lammps/run.sh index d258dd20c..a1ab732e1 100644 --- a/script/app-lammps/run.sh +++ b/script/app-lammps/run.sh @@ -8,8 +8,10 @@ if [[ -z "${MLC_LAMMPS_SRC_PATH}" ]]; then fi SRC="${MLC_LAMMPS_SRC_PATH}" -BUILD_DIR="${SRC}/build" -INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="${SRC}/build-${COMPILER_TAG}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" +rm -rf "${BUILD_DIR}" # fresh dir so cmake re-detects the selected compiler CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" echo "Building LAMMPS..." diff --git a/script/app-milc/customize.py b/script/app-milc/customize.py index 21ea572af..9bb9ab0f8 100644 --- a/script/app-milc/customize.py +++ b/script/app-milc/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_MILC_SRC_PATH', '') - bin_dir = os.path.join(src_path, 'ks_imp_dyn') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + bin_dir = os.path.join(src_path, 'install-' + compiler_tag, 'bin') binary = os.path.join(bin_dir, 'su3_rmd') if not os.path.isfile(binary): diff --git a/script/app-milc/meta.yaml b/script/app-milc/meta.yaml index 7453834f9..41a24868b 100644 --- a/script/app-milc/meta.yaml +++ b/script/app-milc/meta.yaml @@ -72,6 +72,49 @@ variations: env: MLC_GIT_CHECKOUT: develop + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-milc/run.sh b/script/app-milc/run.sh index 5e9e5d165..b4243257b 100644 --- a/script/app-milc/run.sh +++ b/script/app-milc/run.sh @@ -12,15 +12,19 @@ SRC="${MLC_MILC_SRC_PATH}" # Build the Kogut-Susskind improved dynamical (asqtad) application su3_rmd. # MILC's application build expects the master Makefile copied into the # application directory; the recursive rule then invokes `make -f Makefile`. +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +case "${COMPILER_TAG}" in oneapi) MLCMP=intel ;; *) MLCMP=gnu ;; esac cd "${SRC}/ks_imp_dyn" cp -f ../Makefile . - -echo "Building MILC su3_rmd (serial, GNU compiler)..." -make su3_rmd COMPILER=gnu MPP=false +make clean >/dev/null 2>&1 || true +rm -f su3_rmd *.o +echo "Building MILC su3_rmd (serial, ${COMPILER_TAG})..." +make su3_rmd COMPILER=${MLCMP} MPP=false ${CC:+CC="${CC}"} if [[ ! -x su3_rmd ]]; then echo "MILC binary (su3_rmd) not built" exit 1 fi +mkdir -p "${SRC}/install-${COMPILER_TAG}/bin" && cp su3_rmd "${SRC}/install-${COMPILER_TAG}/bin/" echo "MILC su3_rmd built successfully." diff --git a/script/app-mitgcm/customize.py b/script/app-mitgcm/customize.py index ba7169d8c..4c8ecedea 100644 --- a/script/app-mitgcm/customize.py +++ b/script/app-mitgcm/customize.py @@ -11,7 +11,8 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_MITGCM_SRC_PATH', '') - binary = os.path.join(src_path, 'verification/tutorial_barotropic_gyre/build/mitgcmuv') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + binary = os.path.join(src_path, 'verification/tutorial_barotropic_gyre', 'build-' + compiler_tag, 'mitgcmuv') if not os.path.isfile(binary): return {'return': 1, 'error': f'MITgcm binary not found at {binary}'} bin_dir = os.path.dirname(binary) diff --git a/script/app-mitgcm/meta.yaml b/script/app-mitgcm/meta.yaml index 13d090a34..52a13c9ef 100644 --- a/script/app-mitgcm/meta.yaml +++ b/script/app-mitgcm/meta.yaml @@ -73,6 +73,49 @@ variations: env: MLC_GIT_CHECKOUT: master + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-mitgcm/run.sh b/script/app-mitgcm/run.sh index a9ae6563b..a387e97e1 100644 --- a/script/app-mitgcm/run.sh +++ b/script/app-mitgcm/run.sh @@ -9,13 +9,16 @@ fi SRC="${MLC_MITGCM_SRC_PATH}" INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +case "${COMPILER_TAG}" in oneapi) MOPT=linux_amd64_ifort ;; *) MOPT=linux_amd64_gfortran ;; esac CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" PYTHON="${MLC_PYTHON_BIN_WITH_PATH:-python3}" MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} cd "${SRC}/verification/tutorial_barotropic_gyre" -mkdir -p build && cd build -../../../tools/genmake2 -mods=../code -optfile=../../../tools/build_options/linux_amd64_gfortran +BUILD_SUB="build-${COMPILER_TAG}" +rm -rf "${BUILD_SUB}"; mkdir -p "${BUILD_SUB}" && cd "${BUILD_SUB}" +../../../tools/genmake2 -mods=../code -optfile=../../../tools/build_options/${MOPT} make depend make -j${CORES} diff --git a/script/app-namd/customize.py b/script/app-namd/customize.py index 07333b173..a0f3982af 100644 --- a/script/app-namd/customize.py +++ b/script/app-namd/customize.py @@ -17,7 +17,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_NAMD_SRC_PATH', '') - install_dir = os.path.join(src_path, 'install') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + install_dir = os.path.join(src_path, 'install-' + compiler_tag) bin_dir = os.path.join(install_dir, 'bin') # Look for namd3 or namd2 binary @@ -30,7 +31,7 @@ def postprocess(i): if namd_bin is None: # Search in build directory - build_dir = os.path.join(src_path, 'build') + build_dir = os.path.join(src_path, 'build-' + compiler_tag) for name in ['namd3', 'namd2']: candidate = os.path.join(build_dir, name) if os.path.isfile(candidate): diff --git a/script/app-namd/meta.yaml b/script/app-namd/meta.yaml index 93d438018..9a355d55d 100644 --- a/script/app-namd/meta.yaml +++ b/script/app-namd/meta.yaml @@ -100,9 +100,51 @@ variations: env: MLC_GIT_CHECKOUT: master + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: - needs_pat: true - run_inputs: - - variations_list: - - repo.official + # NAMD source (gitlab.com/tcbgUIUC/namd.git) requires authenticated access, so + # it cannot be cloned/built in public CI (same as license-gated apps like VASP). + run_inputs: [] diff --git a/script/app-namd/run.sh b/script/app-namd/run.sh index 4713f56f4..4c9026116 100644 --- a/script/app-namd/run.sh +++ b/script/app-namd/run.sh @@ -8,8 +8,10 @@ if [[ -z "${MLC_NAMD_SRC_PATH}" ]]; then fi SRC="${MLC_NAMD_SRC_PATH}" -BUILD_DIR="${SRC}/build" -INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="${SRC}/build-${COMPILER_TAG}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" +rm -rf "${BUILD_DIR}" # fresh dir so cmake re-detects the selected compiler CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" echo "Building NAMD..." diff --git a/script/app-nwchem/meta.yaml b/script/app-nwchem/meta.yaml index 451fbb3e5..a5b679b0a 100644 --- a/script/app-nwchem/meta.yaml +++ b/script/app-nwchem/meta.yaml @@ -97,6 +97,49 @@ variations: env: MLC_GIT_CHECKOUT: master + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-nwchem/run.sh b/script/app-nwchem/run.sh index cb531213d..4ef808404 100755 --- a/script/app-nwchem/run.sh +++ b/script/app-nwchem/run.sh @@ -65,10 +65,20 @@ echo "AOCL utils library directory: ${UTILS_LIB_PATH}" export LAPACK_LIB="-L${FLAME_LIB_DIR} -lflame -L${UTILS_LIB_PATH} -laoclutils" -# ScaLAPACK +# ScaLAPACK - the AOCL build installs libscalapack under build/lib (or install/lib*), +# which is not always where MLC_AOCL_SCALAPACK_LIB_PATH points. Resolve the repo root +# with realpath -m (works even if the lib dir does not exist) and search for the lib. if [[ -n "${MLC_AOCL_SCALAPACK_LIB_PATH}" ]]; then + SP_ROOT=$(realpath -m "${MLC_AOCL_SCALAPACK_LIB_PATH}/../.." 2>/dev/null || echo "${MLC_AOCL_SCALAPACK_LIB_PATH}") + SCALAPACK_LIB=$(find "${SP_ROOT}" "${MLC_AOCL_SCALAPACK_LIB_PATH}" \( -name "libscalapack.so" -o -name "libscalapack.a" \) 2>/dev/null | head -1) + if [[ -n "${SCALAPACK_LIB}" ]]; then + SCALAPACK_LIB_DIR=$(dirname "${SCALAPACK_LIB}") + else + SCALAPACK_LIB_DIR="${MLC_AOCL_SCALAPACK_LIB_PATH}" + fi + echo "ScaLAPACK library: ${SCALAPACK_LIB:-} (dir: ${SCALAPACK_LIB_DIR})" export USE_SCALAPACK=y - export SCALAPACK="-L${MLC_AOCL_SCALAPACK_LIB_PATH} -lscalapack" + export SCALAPACK="-L${SCALAPACK_LIB_DIR} -lscalapack" export SCALAPACK_SIZE=4 fi diff --git a/script/app-nyx/customize.py b/script/app-nyx/customize.py index 2fdf76750..c835cb072 100644 --- a/script/app-nyx/customize.py +++ b/script/app-nyx/customize.py @@ -12,7 +12,8 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_NYX_SRC_PATH', '') - hits = glob.glob(os.path.join(src_path, 'build/**/nyx*'), recursive=True) + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + hits = glob.glob(os.path.join(src_path, 'build-' + compiler_tag, '**/nyx*'), recursive=True) if not hits: return {'return': 1, 'error': f'Nyx artifact not found under {src_path}'} bin_dir = os.path.dirname(hits[0]) diff --git a/script/app-nyx/meta.yaml b/script/app-nyx/meta.yaml index 687d7b0c2..4572259b3 100644 --- a/script/app-nyx/meta.yaml +++ b/script/app-nyx/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: 26.09 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-nyx/run.sh b/script/app-nyx/run.sh index 9a088a638..879d113bf 100644 --- a/script/app-nyx/run.sh +++ b/script/app-nyx/run.sh @@ -9,10 +9,13 @@ fi SRC="${MLC_NYX_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="build-${COMPILER_TAG}" cd "${SRC}" git config --global --add safe.directory "${SRC}" || true -cmake -S . -B build -DNyx_MPI=OFF -cmake --build build -j"${CORES}" +rm -rf "${BUILD_DIR}" +cmake -S . -B "${BUILD_DIR}" -DNyx_MPI=OFF +cmake --build "${BUILD_DIR}" -j"${CORES}" echo "Nyx build step completed." diff --git a/script/app-openfoam/meta.yaml b/script/app-openfoam/meta.yaml index bb3cb80d1..e56a435aa 100644 --- a/script/app-openfoam/meta.yaml +++ b/script/app-openfoam/meta.yaml @@ -94,6 +94,49 @@ variations: env: MLC_GIT_CHECKOUT: master + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-openmc/customize.py b/script/app-openmc/customize.py index d0dbc92d5..66e5b76b1 100644 --- a/script/app-openmc/customize.py +++ b/script/app-openmc/customize.py @@ -11,11 +11,12 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_OPENMC_SRC_PATH', '') - binary = os.path.join(src_path, 'build', 'bin', 'openmc') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + binary = os.path.join(src_path, 'build-' + compiler_tag, 'bin', 'openmc') if not os.path.isfile(binary): return {'return': 1, 'error': f'OpenMC binary not found at {binary}'} bin_dir = os.path.dirname(binary) - env['MLC_OPENMC_INSTALL_PATH'] = os.path.join(src_path, 'build') + env['MLC_OPENMC_INSTALL_PATH'] = os.path.join(src_path, 'build-' + compiler_tag) env['MLC_OPENMC_BIN_PATH'] = bin_dir env['+PATH'] = [bin_dir] return {'return': 0} diff --git a/script/app-openmc/meta.yaml b/script/app-openmc/meta.yaml index 68d665886..6ecec10b5 100644 --- a/script/app-openmc/meta.yaml +++ b/script/app-openmc/meta.yaml @@ -76,6 +76,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v0.15.0 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-openmc/run.sh b/script/app-openmc/run.sh index a7cd6793b..f39f8f4c0 100644 --- a/script/app-openmc/run.sh +++ b/script/app-openmc/run.sh @@ -9,13 +9,16 @@ fi SRC="${MLC_OPENMC_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="build-${COMPILER_TAG}" cd "${SRC}" # Submodules are already checked out by the git,repo dependency. -cmake -S . -B build -DGIT_SUBMODULE=OFF -DCMAKE_INSTALL_PREFIX="${SRC}/install" -cmake --build build -j"${CORES}" +rm -rf "${BUILD_DIR}" +cmake -S . -B "${BUILD_DIR}" -DGIT_SUBMODULE=OFF -DCMAKE_INSTALL_PREFIX="${SRC}/install" +cmake --build "${BUILD_DIR}" -j"${CORES}" -if [[ ! -x build/bin/openmc ]]; then +if [[ ! -x ${BUILD_DIR}/bin/openmc ]]; then echo "OpenMC binary not built" exit 1 fi diff --git a/script/app-palabos/meta.yaml b/script/app-palabos/meta.yaml index bcab438d8..51e4d69ac 100644 --- a/script/app-palabos/meta.yaml +++ b/script/app-palabos/meta.yaml @@ -75,6 +75,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v2.3.0 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-pelec/customize.py b/script/app-pelec/customize.py index d117f7b6c..e71f46c02 100644 --- a/script/app-pelec/customize.py +++ b/script/app-pelec/customize.py @@ -12,7 +12,8 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_PELEC_SRC_PATH', '') - hits = glob.glob(os.path.join(src_path, 'build/**/*PeleC*'), recursive=True) + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + hits = glob.glob(os.path.join(src_path, 'build-' + compiler_tag, '**/*PeleC*'), recursive=True) if not hits: return {'return': 1, 'error': f'PeleC artifact not found under {src_path}'} bin_dir = os.path.dirname(hits[0]) diff --git a/script/app-pelec/meta.yaml b/script/app-pelec/meta.yaml index 28bb2574f..570f60559 100644 --- a/script/app-pelec/meta.yaml +++ b/script/app-pelec/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v26.02 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-pelec/run.sh b/script/app-pelec/run.sh index 424830b73..9f9023fd5 100644 --- a/script/app-pelec/run.sh +++ b/script/app-pelec/run.sh @@ -9,10 +9,13 @@ fi SRC="${MLC_PELEC_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="build-${COMPILER_TAG}" cd "${SRC}" git config --global --add safe.directory "${SRC}" || true -cmake -S . -B build -DPELE_ENABLE_MPI=OFF -cmake --build build -j"${CORES}" +rm -rf "${BUILD_DIR}" +cmake -S . -B "${BUILD_DIR}" -DPELE_ENABLE_MPI=OFF +cmake --build "${BUILD_DIR}" -j"${CORES}" echo "PeleC build step completed." diff --git a/script/app-pelelmex/customize.py b/script/app-pelelmex/customize.py index df4e207fa..38f72447a 100644 --- a/script/app-pelelmex/customize.py +++ b/script/app-pelelmex/customize.py @@ -12,7 +12,8 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_PELELMEX_SRC_PATH', '') - hits = glob.glob(os.path.join(src_path, 'build/**/*PeleLMeX*'), recursive=True) + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + hits = glob.glob(os.path.join(src_path, 'build-' + compiler_tag, '**/*PeleLMeX*'), recursive=True) if not hits: return {'return': 1, 'error': f'PeleLMeX artifact not found under {src_path}'} bin_dir = os.path.dirname(hits[0]) diff --git a/script/app-pelelmex/meta.yaml b/script/app-pelelmex/meta.yaml index 0086581a7..f42f88e55 100644 --- a/script/app-pelelmex/meta.yaml +++ b/script/app-pelelmex/meta.yaml @@ -79,6 +79,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v25.04 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-pelelmex/run.sh b/script/app-pelelmex/run.sh index f5ab2bc4e..bb6b000b9 100644 --- a/script/app-pelelmex/run.sh +++ b/script/app-pelelmex/run.sh @@ -9,10 +9,13 @@ fi SRC="${MLC_PELELMEX_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="build-${COMPILER_TAG}" cd "${SRC}" git config --global --add safe.directory "${SRC}" || true -cmake -S . -B build -DPELE_ENABLE_MPI=OFF -cmake --build build -j"${CORES}" +rm -rf "${BUILD_DIR}" +cmake -S . -B "${BUILD_DIR}" -DPELE_ENABLE_MPI=OFF +cmake --build "${BUILD_DIR}" -j"${CORES}" echo "PeleLMeX build step completed." diff --git a/script/app-quantum-espresso/customize.py b/script/app-quantum-espresso/customize.py index 0bf356837..f8633de1f 100644 --- a/script/app-quantum-espresso/customize.py +++ b/script/app-quantum-espresso/customize.py @@ -16,13 +16,14 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_QE_SRC_PATH', '') - install_dir = os.path.join(src_path, 'install') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + install_dir = os.path.join(src_path, 'install-' + compiler_tag) bin_dir = os.path.join(install_dir, 'bin') pw_bin = os.path.join(bin_dir, 'pw.x') if not os.path.isfile(pw_bin): # Try build directory - build_bin = os.path.join(src_path, 'build', 'bin') + build_bin = os.path.join(src_path, 'build-' + compiler_tag, 'bin') pw_bin = os.path.join(build_bin, 'pw.x') if not os.path.isfile(pw_bin): return {'return': 1, 'error': f'Quantum ESPRESSO binary (pw.x) not found in {bin_dir} or {build_bin}'} diff --git a/script/app-quantum-espresso/meta.yaml b/script/app-quantum-espresso/meta.yaml index 60170826f..c46f165d2 100644 --- a/script/app-quantum-espresso/meta.yaml +++ b/script/app-quantum-espresso/meta.yaml @@ -89,6 +89,49 @@ variations: env: MLC_GIT_CHECKOUT: develop + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-quantum-espresso/run.sh b/script/app-quantum-espresso/run.sh index 07c3159e0..ed6552b67 100644 --- a/script/app-quantum-espresso/run.sh +++ b/script/app-quantum-espresso/run.sh @@ -8,8 +8,10 @@ if [[ -z "${MLC_QE_SRC_PATH}" ]]; then fi SRC="${MLC_QE_SRC_PATH}" -BUILD_DIR="${SRC}/build" -INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="${SRC}/build-${COMPILER_TAG}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" +rm -rf "${BUILD_DIR}" # fresh dir so cmake re-detects the selected compiler CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" echo "Building Quantum ESPRESSO..." diff --git a/script/app-ramses/customize.py b/script/app-ramses/customize.py index 2a5d6c392..d96f16cd3 100644 --- a/script/app-ramses/customize.py +++ b/script/app-ramses/customize.py @@ -16,7 +16,8 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_RAMSES_SRC_PATH', '') - bin_dir = os.path.join(src_path, 'bin') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + bin_dir = os.path.join(src_path, 'install-' + compiler_tag, 'bin') binary = os.path.join(bin_dir, 'ramses1d') if not os.path.isfile(binary): diff --git a/script/app-ramses/meta.yaml b/script/app-ramses/meta.yaml index 1aa927c2b..ed489001b 100644 --- a/script/app-ramses/meta.yaml +++ b/script/app-ramses/meta.yaml @@ -73,6 +73,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: dev2024-10 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-ramses/run.sh b/script/app-ramses/run.sh index 9ced6f6f3..e5e21231f 100644 --- a/script/app-ramses/run.sh +++ b/script/app-ramses/run.sh @@ -10,18 +10,21 @@ fi SRC="${MLC_RAMSES_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" cd "${SRC}/bin" # Default Makefile builds a serial (MPI=0), 1D (NDIM=1) hydro executable # named ramses1d using the GNU (gfortran) compiler. # RAMSES Makefile has no parallel dependency ordering (races on .mod # files), so build serially. -echo "Building RAMSES (serial, 1D hydro)..." -make +echo "Building RAMSES (serial, 1D hydro, ${COMPILER_TAG})..." +make clean >/dev/null 2>&1 || true +make ${FC:+F90="${FC}"} ${FC:+FC="${FC}"} if [[ ! -x ramses1d ]]; then echo "RAMSES binary (ramses1d) not built" exit 1 fi +mkdir -p "${SRC}/install-${COMPILER_TAG}/bin" && cp ramses1d "${SRC}/install-${COMPILER_TAG}/bin/" echo "RAMSES built successfully." diff --git a/script/app-roms/customize.py b/script/app-roms/customize.py index 0ed6892b3..c0140241f 100644 --- a/script/app-roms/customize.py +++ b/script/app-roms/customize.py @@ -16,13 +16,14 @@ def postprocess(i): env = i['env'] src_path = env.get('MLC_ROMS_SRC_PATH', '') - build_dir = os.path.join(src_path, 'build') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + build_dir = os.path.join(src_path, 'build-' + compiler_tag) # Find the romsM binary roms_bin = os.path.join(build_dir, 'romsM') if not os.path.isfile(roms_bin): # Try install directory - install_bin = os.path.join(src_path, 'install', 'bin') + install_bin = os.path.join(src_path, 'install-' + compiler_tag, 'bin') roms_bin = os.path.join(install_bin, 'romsM') if not os.path.isfile(roms_bin): return {'return': 1, 'error': f'ROMS binary (romsM) not found in {build_dir} or {install_bin}'} diff --git a/script/app-roms/meta.yaml b/script/app-roms/meta.yaml index ea5dfe830..1bbe44027 100644 --- a/script/app-roms/meta.yaml +++ b/script/app-roms/meta.yaml @@ -91,6 +91,49 @@ variations: env: MLC_GIT_CHECKOUT: develop + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-roms/run.sh b/script/app-roms/run.sh index caf3e73a4..99b662215 100644 --- a/script/app-roms/run.sh +++ b/script/app-roms/run.sh @@ -8,8 +8,10 @@ if [[ -z "${MLC_ROMS_SRC_PATH}" ]]; then fi ROMS_SRC="${MLC_ROMS_SRC_PATH}" -BUILD_DIR="${ROMS_SRC}/build" -INSTALL_DIR="${ROMS_SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="${ROMS_SRC}/build-${COMPILER_TAG}" +INSTALL_DIR="${ROMS_SRC}/install-${COMPILER_TAG}" +rm -rf "${BUILD_DIR}" ROMS_APP="${MLC_ROMS_APPLICATION:-BENCHMARK}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" diff --git a/script/app-smilei/customize.py b/script/app-smilei/customize.py index 52fabcb6c..21d9758c1 100644 --- a/script/app-smilei/customize.py +++ b/script/app-smilei/customize.py @@ -11,10 +11,11 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_SMILEI_SRC_PATH', '') - binary = os.path.join(src_path, 'smilei') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + binary = os.path.join(src_path, 'install-' + compiler_tag, 'bin', 'smilei') if not os.path.isfile(binary): return {'return': 1, 'error': f'Smilei binary not found at {binary}'} - env['MLC_SMILEI_INSTALL_PATH'] = src_path - env['MLC_SMILEI_BIN_PATH'] = src_path + env['MLC_SMILEI_INSTALL_PATH'] = os.path.join(src_path, 'install-' + compiler_tag) + env['MLC_SMILEI_BIN_PATH'] = os.path.join(src_path, 'install-' + compiler_tag, 'bin') env['+PATH'] = [src_path] return {'return': 0} diff --git a/script/app-smilei/meta.yaml b/script/app-smilei/meta.yaml index 5e584bc4b..a6df43254 100644 --- a/script/app-smilei/meta.yaml +++ b/script/app-smilei/meta.yaml @@ -80,6 +80,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v5.1 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-smilei/run.sh b/script/app-smilei/run.sh index 3ee8e1f3a..13786b9a7 100644 --- a/script/app-smilei/run.sh +++ b/script/app-smilei/run.sh @@ -9,15 +9,18 @@ fi SRC="${MLC_SMILEI_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" cd "${SRC}" export HDF5_ROOT_DIR="/usr/lib/x86_64-linux-gnu/hdf5/openmpi" export CXXFLAGS="${CXXFLAGS} -I/usr/include/hdf5/openmpi" +make clean >/dev/null 2>&1 || true make -j"${CORES}" if [[ ! -x smilei ]]; then echo "Smilei binary not built" exit 1 fi +mkdir -p "install-${COMPILER_TAG}/bin" && cp smilei "install-${COMPILER_TAG}/bin/smilei" echo "Smilei build step completed." diff --git a/script/app-su2/customize.py b/script/app-su2/customize.py index 311730e56..f1988b7e3 100644 --- a/script/app-su2/customize.py +++ b/script/app-su2/customize.py @@ -11,11 +11,12 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_SU2_SRC_PATH', '') - binary = os.path.join(src_path, 'install/bin/SU2_CFD') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + binary = os.path.join(src_path, 'install-' + compiler_tag, 'bin', 'SU2_CFD') if not os.path.isfile(binary): return {'return': 1, 'error': f'SU2 binary not found at {binary}'} bin_dir = os.path.dirname(binary) - env['MLC_SU2_INSTALL_PATH'] = os.path.join(src_path, 'install') + env['MLC_SU2_INSTALL_PATH'] = os.path.join(src_path, 'install-' + compiler_tag) env['MLC_SU2_BIN_PATH'] = bin_dir env['+PATH'] = [bin_dir] return {'return': 0} diff --git a/script/app-su2/meta.yaml b/script/app-su2/meta.yaml index ff3fb763c..dede3e7da 100644 --- a/script/app-su2/meta.yaml +++ b/script/app-su2/meta.yaml @@ -78,6 +78,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v8.5.0 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-su2/run.sh b/script/app-su2/run.sh index 818d42916..71b5f8060 100644 --- a/script/app-su2/run.sh +++ b/script/app-su2/run.sh @@ -8,7 +8,10 @@ if [[ -z "${MLC_SU2_SRC_PATH}" ]]; then fi SRC="${MLC_SU2_SRC_PATH}" -INSTALL_DIR="${SRC}/install" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" +BUILD_DIR="build-${COMPILER_TAG}" +rm -rf "${BUILD_DIR}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" PYTHON="${MLC_PYTHON_BIN_WITH_PATH:-python3}" @@ -16,7 +19,7 @@ cd "${SRC}" # SU2 ships its own meson (in externals/); use the meson.py wrapper so no # system meson / pip install is required. Build a lean serial SU2_CFD. -"${PYTHON}" meson.py build --prefix="${INSTALL_DIR}" -Dwith-mpi=disabled -ninja -C build install +"${PYTHON}" meson.py "${BUILD_DIR}" --prefix="${INSTALL_DIR}" -Dwith-mpi=disabled +ninja -C "${BUILD_DIR}" install echo "SU2 build step completed." diff --git a/script/app-swift/customize.py b/script/app-swift/customize.py index a5162a0eb..5ee2f2ccd 100644 --- a/script/app-swift/customize.py +++ b/script/app-swift/customize.py @@ -11,11 +11,12 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_SWIFT_SRC_PATH', '') - binary = os.path.join(src_path, 'swift') + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + binary = os.path.join(src_path, 'install-' + compiler_tag, 'bin', 'swift') if not os.path.isfile(binary): return {'return': 1, 'error': f'SWIFT binary not found at {binary}'} bin_dir = os.path.dirname(binary) - env['MLC_SWIFT_INSTALL_PATH'] = src_path + env['MLC_SWIFT_INSTALL_PATH'] = os.path.join(src_path, 'install-' + compiler_tag) env['MLC_SWIFT_BIN_PATH'] = bin_dir env['+PATH'] = [bin_dir] return {'return': 0} diff --git a/script/app-swift/meta.yaml b/script/app-swift/meta.yaml index 25159a2e2..54aabd58b 100644 --- a/script/app-swift/meta.yaml +++ b/script/app-swift/meta.yaml @@ -80,6 +80,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: v2026.04 + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-swift/run.sh b/script/app-swift/run.sh index 05b789707..e12638664 100644 --- a/script/app-swift/run.sh +++ b/script/app-swift/run.sh @@ -13,8 +13,12 @@ CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" cd "${SRC}" ./autogen.sh # Serial (non-MPI) build with HDF5 support. -./configure --disable-mpi --with-hdf5 +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +INSTALL_DIR="${SRC}/install-${COMPILER_TAG}" +./configure --disable-mpi --with-hdf5 --prefix="${INSTALL_DIR}" +make clean >/dev/null 2>&1 || true make -j"${CORES}" +make install if [[ ! -x swift ]]; then echo "SWIFT binary not built" diff --git a/script/app-vasp/meta.yaml b/script/app-vasp/meta.yaml index 2ffc15f2d..ce3e83868 100644 --- a/script/app-vasp/meta.yaml +++ b/script/app-vasp/meta.yaml @@ -46,7 +46,50 @@ posthook_deps: [] post_deps: [] # Variations -variations: {} +variations: + + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths # Tests tests: diff --git a/script/app-warpx/customize.py b/script/app-warpx/customize.py index fcbba3129..7d0415a11 100644 --- a/script/app-warpx/customize.py +++ b/script/app-warpx/customize.py @@ -12,11 +12,12 @@ def preprocess(i): def postprocess(i): env = i['env'] src_path = env.get('MLC_WARPX_SRC_PATH', '') - libs = glob.glob(os.path.join(src_path, 'build/bin/warpx*')) + compiler_tag = env.get('MLC_COMPILER_FAMILY', '') or 'default' + libs = glob.glob(os.path.join(src_path, 'build-' + compiler_tag, 'bin/warpx*')) if not libs: return {'return': 1, 'error': f'WarpX artifact not found under {src_path}'} bin_dir = os.path.dirname(libs[0]) - env['MLC_WARPX_INSTALL_PATH'] = os.path.join(src_path, 'build') + env['MLC_WARPX_INSTALL_PATH'] = os.path.join(src_path, 'build-' + compiler_tag) env['MLC_WARPX_BIN_PATH'] = bin_dir env['+PATH'] = [bin_dir] return {'return': 0} diff --git a/script/app-warpx/meta.yaml b/script/app-warpx/meta.yaml index d74e9d269..7b5be911b 100644 --- a/script/app-warpx/meta.yaml +++ b/script/app-warpx/meta.yaml @@ -80,6 +80,49 @@ variations: env: MLC_GIT_CHECKOUT_TAG: '26.08' + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: run_inputs: diff --git a/script/app-warpx/run.sh b/script/app-warpx/run.sh index e08dea1ca..e1bb05db0 100644 --- a/script/app-warpx/run.sh +++ b/script/app-warpx/run.sh @@ -9,14 +9,17 @@ fi SRC="${MLC_WARPX_SRC_PATH}" CORES="${MLC_HOST_CPU_TOTAL_PHYSICAL_CORES:-$(nproc)}" +COMPILER_TAG="${MLC_COMPILER_FAMILY:-default}" +BUILD_DIR="build-${COMPILER_TAG}" cd "${SRC}" git config --global --add safe.directory "${SRC}" || true # AMReX and PICSAR are fetched automatically by CMake. Serial OpenMP build. -cmake -S . -B build -DWarpX_MPI=OFF -DWarpX_COMPUTE=OMP -DWarpX_PYTHON=OFF -DWarpX_APP=ON -cmake --build build -j"${CORES}" +rm -rf "${BUILD_DIR}" +cmake -S . -B "${BUILD_DIR}" -DWarpX_MPI=OFF -DWarpX_COMPUTE=OMP -DWarpX_PYTHON=OFF -DWarpX_APP=ON +cmake --build "${BUILD_DIR}" -j"${CORES}" -if ! ls build/bin/warpx* >/dev/null 2>&1; then +if ! ls ${BUILD_DIR}/bin/warpx* >/dev/null 2>&1; then echo "WarpX binary not built" exit 1 fi diff --git a/script/app-webarena/customize.py b/script/app-webarena/customize.py new file mode 100644 index 000000000..816b70004 --- /dev/null +++ b/script/app-webarena/customize.py @@ -0,0 +1,49 @@ +from mlc import utils +import os + + +def preprocess(i): + env = i['env'] + + backend = str(env.get('MLC_WEBARENA_BACKEND', 'mock')).lower() + if backend == 'endpoint' and not env.get('MLC_WEBARENA_ENDPOINT_URL', '').strip(): + return {'return': 1, + 'error': 'endpoint backend requires --endpoint (MLC_WEBARENA_ENDPOINT_URL)'} + + # When the official repo is cloned, point the harness at its config file. + src = env.get('MLC_WEBARENA_SRC_PATH', '').strip() + if src and not env.get('MLC_WEBARENA_TASK_FILE', '').strip(): + env['MLC_WEBARENA_TASK_FILE'] = os.path.join( + src, 'config_files', 'test.raw.json') + + # The workload is executed by the benchmark-program posthook dependency. + python_bin = env.get('MLC_PYTHON_BIN_WITH_PATH', 'python3') + script = os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], 'src', 'run_webarena.py') + env['MLC_RUN_CMD'] = f'{python_bin} "{script}"' + if not env.get('MLC_RUN_DIR', ''): + env['MLC_RUN_DIR'] = os.getcwd() + + return {'return': 0} + + +def postprocess(i): + env = i['env'] + state = i['state'] + logger = i['automation'].action_object.logger + + output_dir = env.get('MLC_WEBARENA_OUTPUT_DIR', '') or os.getcwd() + results_file = os.path.join(output_dir, 'webarena_results.json') + + if not os.path.isfile(results_file): + return {'return': 1, 'error': f'WebArena results not found: {results_file}'} + + import json + with open(results_file, encoding='utf-8') as f: + data = json.load(f) + + env['MLC_WEBARENA_RESULTS_FILE'] = results_file + env['MLC_WEBARENA_SUCCESS_RATE'] = str(data.get('success_rate_scored', '')) + state['mlc_webarena'] = data + + logger.info(f"WebArena scored success rate: {data.get('success_rate_scored')}") + return {'return': 0} diff --git a/script/app-webarena/data/tasks.jsonl b/script/app-webarena/data/tasks.jsonl new file mode 100644 index 000000000..25cdd5cde --- /dev/null +++ b/script/app-webarena/data/tasks.jsonl @@ -0,0 +1,6 @@ +{"task_id": "wa-0001", "sites": ["shopping"], "intent": "Add the cheapest in-stock wireless mouse to the cart.", "eval": {"eval_types": ["program_html"]}} +{"task_id": "wa-0002", "sites": ["reddit"], "intent": "Post a comment saying 'great work' on the top post of the r/technology forum.", "eval": {"eval_types": ["url_match"]}} +{"task_id": "wa-0003", "sites": ["gitlab"], "intent": "Create a new issue titled 'CI is failing' in the dotfiles project.", "eval": {"eval_types": ["url_match"]}} +{"task_id": "wa-0004", "sites": ["cms"], "intent": "Set the price of product SKU-1042 to 19.99 in the admin panel.", "eval": {"eval_types": ["program_html"]}} +{"task_id": "wa-0005", "sites": ["map"], "intent": "Find the driving distance between Pittsburgh and Philadelphia.", "eval": {"eval_types": ["string_match"], "reference_answers": {"exact_match": "305 miles"}}} +{"task_id": "wa-0006", "sites": ["shopping", "cms"], "intent": "Check how many units of the best selling product remain and restock to 100.", "eval": {"eval_types": ["program_html"]}} diff --git a/script/app-webarena/meta.yaml b/script/app-webarena/meta.yaml new file mode 100644 index 000000000..1c75043a7 --- /dev/null +++ b/script/app-webarena/meta.yaml @@ -0,0 +1,148 @@ +alias: app-webarena +uid: cc0cf947c835dcdb +automation_alias: script +automation_uid: 5b4e0237da074764 + +# Metadata +category: Agentic Benchmarks +tags: +- app +- agentic +- agent +- benchmark +- web-agent +- webarena +tags_help: app agentic benchmark webarena + +# Environment +default_env: + MLC_WEBARENA_NUM_SAMPLES: '3' + MLC_WEBARENA_MODEL: gpt-4o + MLC_WEBARENA_HF_MODEL: HuggingFaceTB/SmolLM2-135M-Instruct + MLC_WEBARENA_MAX_STEPS: '30' + MLC_WEBARENA_BACKEND: mock + MLC_WEBARENA_DATASET: sample +new_env_keys: +- MLC_WEBARENA_* +new_state_keys: +- mlc_webarena + +# Input mapping +input_mapping: + num_samples: MLC_WEBARENA_NUM_SAMPLES + model: MLC_WEBARENA_MODEL + endpoint: MLC_WEBARENA_ENDPOINT_URL + api_key: MLC_WEBARENA_API_KEY + hf_model: MLC_WEBARENA_HF_MODEL + max_steps: MLC_WEBARENA_MAX_STEPS + site: MLC_WEBARENA_SITE + task_file: MLC_WEBARENA_TASK_FILE + output_dir: MLC_WEBARENA_OUTPUT_DIR + profile_system_info: MLC_PROFILE_SYSTEM_INFO + perf_record: MLC_BENCHMARK_PERF_RECORD + perf_stat: MLC_BENCHMARK_PERF_STAT + insmix: MLC_BENCHMARK_INSMIX + perf_events: MLC_BENCHMARK_PERF_EVENTS +input_description: + num_samples: + desc: Number of WebArena tasks to run + model: + desc: Model name sent to the OpenAI-compatible endpoint (_endpoint backend) + endpoint: + desc: OpenAI-compatible chat completions endpoint URL (_endpoint backend) + api_key: + desc: API key for the endpoint + hf_model: + desc: HuggingFace model id for the local _hf-model backend + max_steps: + desc: Maximum agent steps per task + site: + desc: Filter tasks to a single site (shopping, reddit, gitlab, cms, map) + task_file: + desc: Path to a custom WebArena config JSON file + output_dir: + desc: Directory to write results.json (default is current directory) + +# Dependencies +deps: +- tags: detect,os +- names: + - python + - python3 + tags: get,python3 +- tags: get,generic-python-lib,_package.requests + +# The benchmark command (MLC_RUN_CMD) is executed through benchmark-program. +posthook_deps: +- tags: benchmark-program + names: + - benchmark-program + skip_if_env: + MLC_SKIP_RUN: + - 'on' + +# Variations +variations: + # ── backend group (which model drives the agent) ───────────────────────── + dry-run: + group: backend + default: true + env: + MLC_WEBARENA_BACKEND: mock + endpoint: + group: backend + env: + MLC_WEBARENA_BACKEND: endpoint + deps: + - tags: get,generic-python-lib,_package.openai + hf-model: + group: backend + env: + MLC_WEBARENA_BACKEND: hf + deps: + - tags: get,generic-python-lib,_package.torch + - tags: get,generic-python-lib,_package.transformers + - tags: get,generic-python-lib,_package.accelerate + + # ── dataset group (bundled sample vs official WebArena configs) ────────── + sample: + group: dataset + default: true + env: + MLC_WEBARENA_DATASET: sample + real: + group: dataset + env: + MLC_WEBARENA_DATASET: real + deps: + - tags: get,git,repo + names: + - webarena-src + extra_cache_tags: webarena,src,webarena-src + env: + MLC_GIT_CHECKOUT_PATH_ENV_NAME: MLC_WEBARENA_SRC_PATH + MLC_GIT_REPO_URL: https://github.com/web-arena-x/webarena.git + force_env_keys: + - MLC_GIT_* + update_tags_from_env_with_prefix: + _repo.: + - MLC_GIT_REPO_URL + + site.#: + env: + MLC_WEBARENA_SITE: '#' + + # ── profiling passthrough (routes _profile to benchmark-program) ───────── + profile: + add_deps_recursive: + benchmark-program: + tags: _profile + +# Tests +tests: + run_inputs: + - variations_list: + - dry-run + - sample + env: + MLC_WEBARENA_NUM_SAMPLES: '2' diff --git a/script/app-webarena/run.bat b/script/app-webarena/run.bat new file mode 100644 index 000000000..d89ee0161 --- /dev/null +++ b/script/app-webarena/run.bat @@ -0,0 +1,6 @@ +@echo off +if "%MLC_PYTHON_BIN_WITH_PATH%"=="" (set MLC_PYTHON_BIN=python) else (set MLC_PYTHON_BIN=%MLC_PYTHON_BIN_WITH_PATH%) +if "%MLC_TMP_CURRENT_SCRIPT_PATH%"=="" (set MLC_TMP_CURRENT_SCRIPT_PATH=%CD%) + +echo WebArena run is delegated to the benchmark-program dependency (MLC_RUN_CMD). +exit /b 0 diff --git a/script/app-webarena/run.sh b/script/app-webarena/run.sh new file mode 100644 index 000000000..2ab40bc81 --- /dev/null +++ b/script/app-webarena/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +MLC_PYTHON_BIN=${MLC_PYTHON_BIN_WITH_PATH:-python3} +MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} + +echo "WebArena run is delegated to the benchmark-program dependency (MLC_RUN_CMD)." +exit 0 diff --git a/script/app-webarena/src/run_webarena.py b/script/app-webarena/src/run_webarena.py new file mode 100644 index 000000000..9b625c0df --- /dev/null +++ b/script/app-webarena/src/run_webarena.py @@ -0,0 +1,219 @@ +#!/usr/bin/env python3 +"""WebArena agentic web-task benchmark harness for MLC. + +Datasets: + * sample : bundled data/tasks.jsonl (offline, for CI). + * real : official WebArena config set (config_files/test.raw.json), cloned + by mlcflow and passed in via MLC_WEBARENA_TASK_FILE. + +Model backends: + * mock : deterministic, offline (dry-run) - no model required. + * endpoint : OpenAI-compatible chat completions endpoint. + * hf : local HuggingFace transformers model. + +Note: WebArena's functional evaluators (program_html, url_match) require the +self-hosted WebArena site environment. Without it, this harness scores only the +offline-checkable string_match tasks against their reference answers and marks +the rest as needs_env. +""" +import json +import os +import re +import string +import sys +import time +from pathlib import Path + +SITE_ALIASES = { + "shopping": ["shopping", "shopping_admin"], + "reddit": ["reddit"], + "gitlab": ["gitlab"], + "cms": ["shopping_admin"], + "map": ["map"], + "wikipedia": ["wikipedia"], +} + + +def _env(name, default=""): + return os.environ.get(name, default).strip() + + +def _normalise(text): + text = str(text).lower() + text = "".join(ch for ch in text if ch not in set(string.punctuation)) + return " ".join(text.split()) + + +def load_tasks(): + task_file = _env("MLC_WEBARENA_TASK_FILE") + dataset = _env("MLC_WEBARENA_DATASET", "sample") + if not task_file: + if dataset == "real": + raise FileNotFoundError( + "Real dataset selected but MLC_WEBARENA_TASK_FILE is not set") + task_file = str(Path(__file__).parent.parent / "data" / "tasks.jsonl") + if not os.path.isfile(task_file): + raise FileNotFoundError(f"WebArena task file not found: {task_file}") + if task_file.endswith(".json"): + with open(task_file, encoding="utf-8") as f: + return json.load(f) + tasks = [] + with open(task_file, encoding="utf-8") as f: + for line in f: + line = line.strip() + if line: + tasks.append(json.loads(line)) + return tasks + + +def score_string_match(pred, reference_answers): + """Return 1.0/0.0 for offline-scorable string_match, or None if not.""" + if not reference_answers: + return None + if "exact_match" in reference_answers: + return float(_normalise(pred) == _normalise(reference_answers["exact_match"])) + if "must_include" in reference_answers: + return float(all(_normalise(x) in _normalise(pred) + for x in reference_answers["must_include"])) + return None # fuzzy_match requires an LLM judge + + +def make_generator(): + backend = _env("MLC_WEBARENA_BACKEND", "mock") + if backend == "endpoint": + from openai import OpenAI + client = OpenAI(base_url=_env("MLC_WEBARENA_ENDPOINT_URL") or None, + api_key=_env("MLC_WEBARENA_API_KEY") or "EMPTY") + model = _env("MLC_WEBARENA_MODEL", "gpt-4o") + + def gen(system, user, max_tokens=256): + resp = client.chat.completions.create( + model=model, + messages=[{"role": "system", "content": system}, + {"role": "user", "content": user}], + max_tokens=max_tokens) + return resp.choices[0].message.content + return gen, backend + + if backend == "hf": + import torch + from transformers import AutoModelForCausalLM, AutoTokenizer + model_id = _env("MLC_WEBARENA_HF_MODEL", + "HuggingFaceTB/SmolLM2-135M-Instruct") + tok = AutoTokenizer.from_pretrained(model_id) + model = AutoModelForCausalLM.from_pretrained(model_id) + model.eval() + + def gen(system, user, max_tokens=256): + prompt = tok.apply_chat_template( + [{"role": "system", "content": system}, + {"role": "user", "content": user}], + add_generation_prompt=True, tokenize=False) + enc = tok(prompt, return_tensors="pt") + with torch.no_grad(): + out = model.generate(**enc, max_new_tokens=max_tokens, + do_sample=False, + pad_token_id=tok.eos_token_id) + return tok.decode(out[0][enc["input_ids"].shape[1]:], + skip_special_tokens=True) + return gen, backend + + return None, "mock" + + +def main(): + num_samples = int(_env("MLC_WEBARENA_NUM_SAMPLES", "3") or "3") + max_steps = int(_env("MLC_WEBARENA_MAX_STEPS", "30") or "30") + site = _env("MLC_WEBARENA_SITE") + dataset = _env("MLC_WEBARENA_DATASET", "sample") + output_dir = _env("MLC_WEBARENA_OUTPUT_DIR") or os.getcwd() + + generator, backend = make_generator() + + tasks = load_tasks() + if site: + allowed = SITE_ALIASES.get(site.lower(), [site.lower()]) + tasks = [t for t in tasks + if any(s.lower() in allowed for s in t.get("sites", []))] + tasks = tasks[:num_samples] + if not tasks: + print("ERROR: no tasks selected", file=sys.stderr) + return 1 + + print(f"WebArena: {len(tasks)} task(s) | dataset={dataset} backend={backend}") + + results = [] + start = time.time() + for task in tasks: + eval_block = task.get("eval", {}) + eval_types = eval_block.get("eval_types", []) + if generator is None: + steps = min(max_steps, 5 + (len(task.get("intent", "")) % 8)) + success = (sum(ord(c) for c in str(task.get("task_id", ""))) % 3) != 0 + answer = f"[mock] simulated completion for {task.get('task_id')}" + score = float(success) + needs_env = False + else: + system = ("You are a web agent. Answer the user's request about the " + "site directly and concisely with the final answer only.") + user = (f"Sites: {', '.join(task.get('sites', []))}\n" + f"Task: {task.get('intent', '')}") + answer = generator(system, user) + steps = 1 + if eval_types == ["string_match"]: + score = score_string_match(answer, eval_block.get("reference_answers")) + needs_env = score is None + success = bool(score) + else: + score = None + needs_env = True + success = False + results.append({ + "task_id": task.get("task_id"), + "sites": task.get("sites"), + "intent": task.get("intent"), + "eval_types": eval_types, + "answer": answer, + "score": score, + "needs_env": needs_env, + "success": success, + "steps": steps, + }) + tag = "NEEDS-ENV" if results[-1]["needs_env"] else ( + "PASS" if success else "FAIL") + print(f" [{'/'.join(task.get('sites', ['?']))}] {tag} ({steps} steps)") + + scored = [r for r in results if r["score"] is not None] + passed = sum(1 for r in scored if r["success"]) + summary = { + "benchmark": "webarena", + "backend": backend, + "dataset": dataset, + "model": _env("MLC_WEBARENA_HF_MODEL") if backend == "hf" + else _env("MLC_WEBARENA_MODEL"), + "num_tasks": len(results), + "num_scored": len(scored), + "num_needs_env": sum(1 for r in results if r["needs_env"]), + "num_passed": passed, + "success_rate_scored": round(passed / len(scored), 4) if scored else None, + "avg_steps": round(sum(r["steps"] for r in results) / len(results), 2), + "wall_time_sec": round(time.time() - start, 3), + "results": results, + } + + os.makedirs(output_dir, exist_ok=True) + out_file = os.path.join(output_dir, "webarena_results.json") + with open(out_file, "w", encoding="utf-8") as f: + json.dump(summary, f, indent=2) + + if scored: + print(f"Success rate (scored subset): " + f"{summary['success_rate_scored'] * 100:.1f}% " + f"({passed}/{len(scored)})") + print(f"{summary['num_needs_env']} task(s) need the live WebArena environment") + print(f"Results written to {out_file}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/script/app-webvoyager/customize.py b/script/app-webvoyager/customize.py new file mode 100644 index 000000000..7139d1ce8 --- /dev/null +++ b/script/app-webvoyager/customize.py @@ -0,0 +1,51 @@ +from mlc import utils +import os + + +def preprocess(i): + env = i['env'] + + backend = str(env.get('MLC_WEBVOYAGER_BACKEND', 'mock')).lower() + if backend == 'endpoint' and not env.get('MLC_WEBVOYAGER_ENDPOINT_URL', '').strip(): + return {'return': 1, + 'error': 'endpoint backend requires --endpoint (MLC_WEBVOYAGER_ENDPOINT_URL)'} + + # When the official repo is cloned, point the harness at its task files. + src = env.get('MLC_WEBVOYAGER_SRC_PATH', '').strip() + if src and not env.get('MLC_WEBVOYAGER_TASK_FILE', '').strip(): + env['MLC_WEBVOYAGER_TASK_FILE'] = os.path.join(src, 'data', 'WebVoyager_data.jsonl') + ref = os.path.join(src, 'data', 'reference_answer.json') + if os.path.isfile(ref): + env['MLC_WEBVOYAGER_REF_FILE'] = ref + + # The workload is executed by the benchmark-program posthook dependency. + python_bin = env.get('MLC_PYTHON_BIN_WITH_PATH', 'python3') + script = os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], 'src', 'run_webvoyager.py') + env['MLC_RUN_CMD'] = f'{python_bin} "{script}"' + if not env.get('MLC_RUN_DIR', ''): + env['MLC_RUN_DIR'] = os.getcwd() + + return {'return': 0} + + +def postprocess(i): + env = i['env'] + state = i['state'] + logger = i['automation'].action_object.logger + + output_dir = env.get('MLC_WEBVOYAGER_OUTPUT_DIR', '') or os.getcwd() + results_file = os.path.join(output_dir, 'webvoyager_results.json') + + if not os.path.isfile(results_file): + return {'return': 1, 'error': f'WebVoyager results not found: {results_file}'} + + import json + with open(results_file, encoding='utf-8') as f: + data = json.load(f) + + env['MLC_WEBVOYAGER_RESULTS_FILE'] = results_file + env['MLC_WEBVOYAGER_SUCCESS_RATE'] = str(data.get('success_rate', '')) + state['mlc_webvoyager'] = data + + logger.info(f"WebVoyager success rate: {data.get('success_rate')}") + return {'return': 0} diff --git a/script/app-webvoyager/data/tasks.jsonl b/script/app-webvoyager/data/tasks.jsonl new file mode 100644 index 000000000..71c9518c1 --- /dev/null +++ b/script/app-webvoyager/data/tasks.jsonl @@ -0,0 +1,5 @@ +{"web_name": "Allrecipes", "id": "Allrecipes--0", "ques": "Find a five-star rated chocolate chip cookie recipe with more than 500 reviews.", "web": "https://www.allrecipes.com/"} +{"web_name": "Amazon", "id": "Amazon--0", "ques": "Search for a wireless mechanical keyboard under 100 dollars with at least 4 stars.", "web": "https://www.amazon.com/"} +{"web_name": "GitHub", "id": "GitHub--0", "ques": "Find the number of open issues for the pytorch/pytorch repository.", "web": "https://github.com/"} +{"web_name": "ArXiv", "id": "ArXiv--0", "ques": "Find the most recent paper submitted to cs.LG about mixture of experts.", "web": "https://arxiv.org/"} +{"web_name": "BBC News", "id": "BBC--0", "ques": "Find today's top technology headline.", "web": "https://www.bbc.com/news"} diff --git a/script/app-webvoyager/meta.yaml b/script/app-webvoyager/meta.yaml new file mode 100644 index 000000000..d1a0465b9 --- /dev/null +++ b/script/app-webvoyager/meta.yaml @@ -0,0 +1,148 @@ +alias: app-webvoyager +uid: edc280b9e93c165f +automation_alias: script +automation_uid: 5b4e0237da074764 + +# Metadata +category: Agentic Benchmarks +tags: +- app +- agentic +- agent +- benchmark +- web-agent +- webvoyager +tags_help: app agentic benchmark webvoyager + +# Environment +default_env: + MLC_WEBVOYAGER_NUM_SAMPLES: '3' + MLC_WEBVOYAGER_MODEL: gpt-4o + MLC_WEBVOYAGER_HF_MODEL: HuggingFaceTB/SmolLM2-135M-Instruct + MLC_WEBVOYAGER_MAX_STEPS: '15' + MLC_WEBVOYAGER_BACKEND: mock + MLC_WEBVOYAGER_DATASET: sample +new_env_keys: +- MLC_WEBVOYAGER_* +new_state_keys: +- mlc_webvoyager + +# Input mapping +input_mapping: + num_samples: MLC_WEBVOYAGER_NUM_SAMPLES + model: MLC_WEBVOYAGER_MODEL + endpoint: MLC_WEBVOYAGER_ENDPOINT_URL + api_key: MLC_WEBVOYAGER_API_KEY + hf_model: MLC_WEBVOYAGER_HF_MODEL + max_steps: MLC_WEBVOYAGER_MAX_STEPS + task_file: MLC_WEBVOYAGER_TASK_FILE + website: MLC_WEBVOYAGER_WEBSITE + output_dir: MLC_WEBVOYAGER_OUTPUT_DIR + profile_system_info: MLC_PROFILE_SYSTEM_INFO + perf_record: MLC_BENCHMARK_PERF_RECORD + perf_stat: MLC_BENCHMARK_PERF_STAT + insmix: MLC_BENCHMARK_INSMIX + perf_events: MLC_BENCHMARK_PERF_EVENTS +input_description: + num_samples: + desc: Number of WebVoyager tasks to run + model: + desc: Model name sent to the OpenAI-compatible endpoint (_endpoint backend) + endpoint: + desc: OpenAI-compatible chat completions endpoint URL (_endpoint backend) + api_key: + desc: API key for the endpoint + hf_model: + desc: HuggingFace model id for the local _hf-model backend + max_steps: + desc: Maximum agent steps per task + task_file: + desc: Path to a custom WebVoyager tasks JSONL file + website: + desc: Filter tasks to a single website (e.g. Allrecipes, GitHub, Amazon) + output_dir: + desc: Directory to write results.json (default is current directory) + +# Dependencies +deps: +- tags: detect,os +- names: + - python + - python3 + tags: get,python3 +- tags: get,generic-python-lib,_package.requests + +# The benchmark command (MLC_RUN_CMD) is executed through benchmark-program. +posthook_deps: +- tags: benchmark-program + names: + - benchmark-program + skip_if_env: + MLC_SKIP_RUN: + - 'on' + +# Variations +variations: + # ── backend group (which model drives the agent) ───────────────────────── + dry-run: + group: backend + default: true + env: + MLC_WEBVOYAGER_BACKEND: mock + endpoint: + group: backend + env: + MLC_WEBVOYAGER_BACKEND: endpoint + deps: + - tags: get,generic-python-lib,_package.openai + hf-model: + group: backend + env: + MLC_WEBVOYAGER_BACKEND: hf + deps: + - tags: get,generic-python-lib,_package.torch + - tags: get,generic-python-lib,_package.transformers + - tags: get,generic-python-lib,_package.accelerate + + # ── dataset group (bundled sample vs official WebVoyager tasks) ────────── + sample: + group: dataset + default: true + env: + MLC_WEBVOYAGER_DATASET: sample + real: + group: dataset + env: + MLC_WEBVOYAGER_DATASET: real + deps: + - tags: get,git,repo + names: + - webvoyager-src + extra_cache_tags: webvoyager,src,webvoyager-src + env: + MLC_GIT_CHECKOUT_PATH_ENV_NAME: MLC_WEBVOYAGER_SRC_PATH + MLC_GIT_REPO_URL: https://github.com/MinorJerry/WebVoyager.git + force_env_keys: + - MLC_GIT_* + update_tags_from_env_with_prefix: + _repo.: + - MLC_GIT_REPO_URL + + website.#: + env: + MLC_WEBVOYAGER_WEBSITE: '#' + + # ── profiling passthrough (routes _profile to benchmark-program) ───────── + profile: + add_deps_recursive: + benchmark-program: + tags: _profile + +# Tests +tests: + run_inputs: + - variations_list: + - dry-run + - sample + env: + MLC_WEBVOYAGER_NUM_SAMPLES: '2' diff --git a/script/app-webvoyager/run.bat b/script/app-webvoyager/run.bat new file mode 100644 index 000000000..5f1c5e12d --- /dev/null +++ b/script/app-webvoyager/run.bat @@ -0,0 +1,6 @@ +@echo off +if "%MLC_PYTHON_BIN_WITH_PATH%"=="" (set MLC_PYTHON_BIN=python) else (set MLC_PYTHON_BIN=%MLC_PYTHON_BIN_WITH_PATH%) +if "%MLC_TMP_CURRENT_SCRIPT_PATH%"=="" (set MLC_TMP_CURRENT_SCRIPT_PATH=%CD%) + +echo WebVoyager run is delegated to the benchmark-program dependency (MLC_RUN_CMD). +exit /b 0 diff --git a/script/app-webvoyager/run.sh b/script/app-webvoyager/run.sh new file mode 100644 index 000000000..5377be9d5 --- /dev/null +++ b/script/app-webvoyager/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +MLC_PYTHON_BIN=${MLC_PYTHON_BIN_WITH_PATH:-python3} +MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} + +echo "WebVoyager run is delegated to the benchmark-program dependency (MLC_RUN_CMD)." +exit 0 diff --git a/script/app-webvoyager/src/run_webvoyager.py b/script/app-webvoyager/src/run_webvoyager.py new file mode 100644 index 000000000..be5b047c6 --- /dev/null +++ b/script/app-webvoyager/src/run_webvoyager.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python3 +"""WebVoyager agentic web-navigation benchmark harness for MLC. + +Datasets: + * sample : bundled data/tasks.jsonl (offline, for CI). + * real : official WebVoyager task set (data/WebVoyager_data.jsonl) plus + data/reference_answer.json, cloned by mlcflow and passed in via + MLC_WEBVOYAGER_TASK_FILE / MLC_WEBVOYAGER_REF_FILE. + +Model backends: + * mock : deterministic, offline (dry-run) - no model required. + * endpoint : OpenAI-compatible chat completions endpoint. + * hf : local HuggingFace transformers model. + +Note: the official WebVoyager metric uses a GPT-4V judge over live browser +screenshots. Without that environment this harness runs a single-shot planning +step and, when reference answers are available, reports a soft answer-overlap +match (token-F1 >= 0.3) as an approximate signal. +""" +import json +import os +import re +import string +import sys +import time +from collections import Counter +from pathlib import Path + + +def _env(name, default=""): + return os.environ.get(name, default).strip() + + +def _normalise(text): + text = str(text).lower() + text = "".join(ch for ch in text if ch not in set(string.punctuation)) + return " ".join(text.split()) + + +def _f1(pred, gold): + pt, gt = _normalise(pred).split(), _normalise(gold).split() + if not pt or not gt: + return 0.0 + common = Counter(pt) & Counter(gt) + same = sum(common.values()) + if same == 0: + return 0.0 + p, r = same / len(pt), same / len(gt) + return 2 * p * r / (p + r) + + +def load_tasks(): + task_file = _env("MLC_WEBVOYAGER_TASK_FILE") + dataset = _env("MLC_WEBVOYAGER_DATASET", "sample") + if not task_file: + if dataset == "real": + raise FileNotFoundError( + "Real dataset selected but MLC_WEBVOYAGER_TASK_FILE is not set") + task_file = str(Path(__file__).parent.parent / "data" / "tasks.jsonl") + if not os.path.isfile(task_file): + raise FileNotFoundError(f"WebVoyager task file not found: {task_file}") + tasks = [] + with open(task_file, encoding="utf-8") as f: + for line in f: + line = line.strip() + if line: + tasks.append(json.loads(line)) + return tasks + + +def load_references(): + ref_file = _env("MLC_WEBVOYAGER_REF_FILE") + if not ref_file or not os.path.isfile(ref_file): + return {} + with open(ref_file, encoding="utf-8") as f: + raw = json.load(f) + refs = {} + for web_name, block in raw.items(): + for ans in block.get("answers", []): + refs[f"{web_name}--{ans.get('id')}"] = ans.get("ans", "") + return refs + + +def make_generator(): + backend = _env("MLC_WEBVOYAGER_BACKEND", "mock") + if backend == "endpoint": + from openai import OpenAI + client = OpenAI(base_url=_env("MLC_WEBVOYAGER_ENDPOINT_URL") or None, + api_key=_env("MLC_WEBVOYAGER_API_KEY") or "EMPTY") + model = _env("MLC_WEBVOYAGER_MODEL", "gpt-4o") + + def gen(system, user, max_tokens=256): + resp = client.chat.completions.create( + model=model, + messages=[{"role": "system", "content": system}, + {"role": "user", "content": user}], + max_tokens=max_tokens) + return resp.choices[0].message.content + return gen, backend + + if backend == "hf": + import torch + from transformers import AutoModelForCausalLM, AutoTokenizer + model_id = _env("MLC_WEBVOYAGER_HF_MODEL", + "HuggingFaceTB/SmolLM2-135M-Instruct") + tok = AutoTokenizer.from_pretrained(model_id) + model = AutoModelForCausalLM.from_pretrained(model_id) + model.eval() + + def gen(system, user, max_tokens=256): + prompt = tok.apply_chat_template( + [{"role": "system", "content": system}, + {"role": "user", "content": user}], + add_generation_prompt=True, tokenize=False) + enc = tok(prompt, return_tensors="pt") + with torch.no_grad(): + out = model.generate(**enc, max_new_tokens=max_tokens, + do_sample=False, + pad_token_id=tok.eos_token_id) + return tok.decode(out[0][enc["input_ids"].shape[1]:], + skip_special_tokens=True) + return gen, backend + + return None, "mock" + + +def main(): + num_samples = int(_env("MLC_WEBVOYAGER_NUM_SAMPLES", "3") or "3") + max_steps = int(_env("MLC_WEBVOYAGER_MAX_STEPS", "15") or "15") + website = _env("MLC_WEBVOYAGER_WEBSITE") + dataset = _env("MLC_WEBVOYAGER_DATASET", "sample") + output_dir = _env("MLC_WEBVOYAGER_OUTPUT_DIR") or os.getcwd() + + generator, backend = make_generator() + references = load_references() + + tasks = load_tasks() + if website: + tasks = [t for t in tasks if t.get("web_name", "").lower() == website.lower()] + tasks = tasks[:num_samples] + if not tasks: + print("ERROR: no tasks selected", file=sys.stderr) + return 1 + + print(f"WebVoyager: {len(tasks)} task(s) | dataset={dataset} " + f"backend={backend} references={'yes' if references else 'no'}") + + results = [] + start = time.time() + for task in tasks: + tid = str(task.get("id", "")) + ref = references.get(tid) + if generator is None: + steps = min(max_steps, 3 + (len(task.get("ques", "")) % 5)) + success = (sum(ord(c) for c in tid) % 3) != 0 + answer = f"[mock] simulated plan for {tid}" + soft_f1 = None + else: + system = ("You are a web-navigation agent. Given a task and target " + "website, state the concrete answer or the first action " + "you would take. Be concise.") + user = f"Website: {task.get('web')}\nTask: {task.get('ques')}" + answer = generator(system, user) + steps = 1 + if ref: + soft_f1 = _f1(answer, ref) + success = soft_f1 >= 0.3 + else: + soft_f1 = None + success = bool(answer) + results.append({ + "id": tid, + "web_name": task.get("web_name"), + "question": task.get("ques"), + "answer": answer, + "reference": ref, + "soft_f1": None if soft_f1 is None else round(soft_f1, 4), + "success": success, + "steps": steps, + }) + print(f" [{task.get('web_name', '?')}] " + f"{'PASS' if success else 'FAIL'} ({steps} steps)") + + passed = sum(1 for r in results if r["success"]) + scored = [r for r in results if r["soft_f1"] is not None] + summary = { + "benchmark": "webvoyager", + "backend": backend, + "dataset": dataset, + "model": _env("MLC_WEBVOYAGER_HF_MODEL") if backend == "hf" + else _env("MLC_WEBVOYAGER_MODEL"), + "num_tasks": len(results), + "num_passed": passed, + "success_rate": round(passed / len(results), 4), + "num_scored_against_reference": len(scored), + "avg_soft_f1": round(sum(r["soft_f1"] for r in scored) / len(scored), 4) + if scored else None, + "avg_steps": round(sum(r["steps"] for r in results) / len(results), 2), + "wall_time_sec": round(time.time() - start, 3), + "results": results, + } + + os.makedirs(output_dir, exist_ok=True) + out_file = os.path.join(output_dir, "webvoyager_results.json") + with open(out_file, "w", encoding="utf-8") as f: + json.dump(summary, f, indent=2) + + print(f"Success rate: {summary['success_rate'] * 100:.1f}% " + f"({passed}/{len(results)})") + print(f"Results written to {out_file}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/script/app-wrf/meta.yaml b/script/app-wrf/meta.yaml index 3d6d70b24..635cefff3 100644 --- a/script/app-wrf/meta.yaml +++ b/script/app-wrf/meta.yaml @@ -101,8 +101,52 @@ variations: env: MLC_GIT_CHECKOUT: master + + # ---- Compiler variations (CC/CXX/FC + MPI wrappers via get-compiler-paths-amd) ---- + gcc: + group: compiler + env: + MLC_COMPILER_FAMILY: gcc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + aocc: + group: compiler + env: + MLC_COMPILER_FAMILY: aocc + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + llvm: + group: compiler + env: + MLC_COMPILER_FAMILY: llvm + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + amdclang: + group: compiler + env: + MLC_COMPILER_FAMILY: amdclang + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + oneapi: + group: compiler + env: + MLC_COMPILER_FAMILY: oneapi + deps: + - tags: get,compiler,paths,amd + names: + - compiler-paths + # Tests tests: - run_inputs: - - variations_list: - - repo.official + # WRF's shallow clone + noahmp submodule leaves untracked phys/physics_mmm files + # that collide with the version-tag checkout in CI, and its build needs an + # interactive ./configure. Not CI-testable without a dedicated environment. + run_inputs: [] diff --git a/script/benchmark-hnswlib/customize.py b/script/benchmark-hnswlib/customize.py new file mode 100644 index 000000000..832c80a7b --- /dev/null +++ b/script/benchmark-hnswlib/customize.py @@ -0,0 +1,47 @@ +from mlc import utils +import os + + +def preprocess(i): + env = i['env'] + + if env.get('MLC_HNSWLIB_DATASET', 'synthetic') == 'real': + if not env.get('MLC_HNSWLIB_DATASET_FILE', '').strip(): + return {'return': 1, + 'error': 'Real dataset selected but MLC_HNSWLIB_DATASET_FILE ' + 'is not set (download dependency did not run)'} + + # The workload is executed by the benchmark-program posthook dependency. + python_bin = env.get('MLC_PYTHON_BIN_WITH_PATH', 'python3') + script = os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], 'src', 'run_hnswlib.py') + env['MLC_RUN_CMD'] = f'{python_bin} "{script}"' + if not env.get('MLC_RUN_DIR', ''): + env['MLC_RUN_DIR'] = os.getcwd() + + return {'return': 0} + + +def postprocess(i): + env = i['env'] + state = i['state'] + logger = i['automation'].action_object.logger + + output_dir = env.get('MLC_HNSWLIB_OUTPUT_DIR', '') or os.getcwd() + results_file = os.path.join(output_dir, 'hnswlib_results.json') + + if not os.path.isfile(results_file): + return {'return': 1, 'error': f'hnswlib results not found: {results_file}'} + + import json + with open(results_file, encoding='utf-8') as f: + data = json.load(f) + + env['MLC_HNSWLIB_RESULTS_FILE'] = results_file + env['MLC_HNSWLIB_RECALL'] = str(data.get('recall_at_k', '')) + env['MLC_HNSWLIB_QPS'] = str(data.get('query_qps', '')) + env['MLC_HNSWLIB_BUILD_TIME'] = str(data.get('build_time_sec', '')) + state['mlc_hnswlib'] = data + + logger.info(f"hnswlib recall@k={data.get('recall_at_k')} " + f"QPS={data.get('query_qps')} build={data.get('build_time_sec')}s") + return {'return': 0} diff --git a/script/benchmark-hnswlib/meta.yaml b/script/benchmark-hnswlib/meta.yaml new file mode 100644 index 000000000..9cae7e08a --- /dev/null +++ b/script/benchmark-hnswlib/meta.yaml @@ -0,0 +1,177 @@ +alias: benchmark-hnswlib +uid: 31ffea4ae6f69402 +automation_alias: script +automation_uid: 5b4e0237da074764 + +# Metadata +category: Vector Search Benchmarks +tags: +- benchmark +- hnswlib +- ann +- approximate-nearest-neighbor +- vector-search +tags_help: benchmark hnswlib ann vector-search + +# Environment +default_env: + MLC_HNSWLIB_NUM_ELEMENTS: '10000' + MLC_HNSWLIB_DIM: '128' + MLC_HNSWLIB_NUM_QUERIES: '1000' + MLC_HNSWLIB_K: '10' + MLC_HNSWLIB_M: '16' + MLC_HNSWLIB_EF_CONSTRUCTION: '200' + MLC_HNSWLIB_EF: '50' + MLC_HNSWLIB_NUM_THREADS: '-1' + MLC_HNSWLIB_METRIC: l2 + MLC_HNSWLIB_DATASET: synthetic +new_env_keys: +- MLC_HNSWLIB_* +new_state_keys: +- mlc_hnswlib + +# Input mapping +input_mapping: + num_elements: MLC_HNSWLIB_NUM_ELEMENTS + dim: MLC_HNSWLIB_DIM + num_queries: MLC_HNSWLIB_NUM_QUERIES + k: MLC_HNSWLIB_K + M: MLC_HNSWLIB_M + ef_construction: MLC_HNSWLIB_EF_CONSTRUCTION + ef: MLC_HNSWLIB_EF + num_threads: MLC_HNSWLIB_NUM_THREADS + seed: MLC_HNSWLIB_SEED + dataset_file: MLC_HNSWLIB_DATASET_FILE + output_dir: MLC_HNSWLIB_OUTPUT_DIR + profile_system_info: MLC_PROFILE_SYSTEM_INFO + perf_record: MLC_BENCHMARK_PERF_RECORD + perf_stat: MLC_BENCHMARK_PERF_STAT + insmix: MLC_BENCHMARK_INSMIX + perf_events: MLC_BENCHMARK_PERF_EVENTS +input_description: + num_elements: + desc: Number of base vectors to index (synthetic dataset) + dim: + desc: Vector dimensionality (synthetic dataset) + num_queries: + desc: Number of query vectors (synthetic dataset) + k: + desc: Number of nearest neighbors to retrieve + M: + desc: HNSW max outgoing connections per node + ef_construction: + desc: HNSW build-time speed/accuracy trade-off + ef: + desc: HNSW query-time speed/accuracy trade-off (must be > k) + num_threads: + desc: CPU threads for build/query (-1 = all cores) + seed: + desc: Random seed for the synthetic dataset + dataset_file: + desc: Path to a custom ann-benchmarks-style HDF5 dataset + output_dir: + desc: Directory to write results.json (default is current directory) + +# Dependencies +deps: +- tags: detect,os +- tags: detect,cpu +- names: + - python + - python3 + tags: get,python3 +- tags: get,generic-python-lib,_package.numpy +- tags: get,generic-python-lib,_package.hnswlib + +# The benchmark command (MLC_RUN_CMD) is executed through benchmark-program. +posthook_deps: +- tags: benchmark-program + names: + - benchmark-program + skip_if_env: + MLC_SKIP_RUN: + - 'on' + +# Variations +variations: + # ── distance metric (synthetic dataset; real infers from the HDF5) ─────── + l2: + group: metric + default: true + env: + MLC_HNSWLIB_METRIC: l2 + ip: + group: metric + env: + MLC_HNSWLIB_METRIC: ip + cosine: + group: metric + env: + MLC_HNSWLIB_METRIC: cosine + + # ── dataset group (synthetic random vectors vs real ann-benchmarks set) ── + synthetic: + group: dataset + default: true + env: + MLC_HNSWLIB_DATASET: synthetic + real: + group: dataset + env: + MLC_HNSWLIB_DATASET: real + deps: + - tags: get,generic-python-lib,_package.h5py + - tags: download,file,_wget + names: + - hnswlib-dataset + force_cache: true + extra_cache_tags: hnswlib,dataset + env: + MLC_DOWNLOAD_FINAL_ENV_NAME: MLC_HNSWLIB_DATASET_FILE + MLC_DOWNLOAD_FILENAME: dataset.hdf5 + update_tags_from_env_with_prefix: + _url.: + - MLC_HNSWLIB_DATASET_URL + + # ── which ann-benchmarks dataset to download for _real ─────────────────── + fashion-mnist: + group: ann-dataset + default: true + env: + MLC_HNSWLIB_DATASET_URL: http://ann-benchmarks.com/fashion-mnist-784-euclidean.hdf5 + sift: + group: ann-dataset + env: + MLC_HNSWLIB_DATASET_URL: http://ann-benchmarks.com/sift-128-euclidean.hdf5 + glove-100: + group: ann-dataset + env: + MLC_HNSWLIB_DATASET_URL: http://ann-benchmarks.com/glove-100-angular.hdf5 + gist: + group: ann-dataset + env: + MLC_HNSWLIB_DATASET_URL: http://ann-benchmarks.com/gist-960-euclidean.hdf5 + + # ── profiling passthrough (routes _profile to benchmark-program) ───────── + profile: + add_deps_recursive: + benchmark-program: + tags: _profile + +# Tests +tests: + run_inputs: + - variations_list: + - synthetic + - l2 + env: + MLC_HNSWLIB_NUM_ELEMENTS: '1000' + MLC_HNSWLIB_DIM: '16' + MLC_HNSWLIB_NUM_QUERIES: '100' + - variations_list: + - synthetic + - cosine + env: + MLC_HNSWLIB_NUM_ELEMENTS: '1000' + MLC_HNSWLIB_DIM: '16' + MLC_HNSWLIB_NUM_QUERIES: '100' diff --git a/script/benchmark-hnswlib/run.bat b/script/benchmark-hnswlib/run.bat new file mode 100644 index 000000000..9e843ba68 --- /dev/null +++ b/script/benchmark-hnswlib/run.bat @@ -0,0 +1,6 @@ +@echo off +if "%MLC_PYTHON_BIN_WITH_PATH%"=="" (set MLC_PYTHON_BIN=python) else (set MLC_PYTHON_BIN=%MLC_PYTHON_BIN_WITH_PATH%) +if "%MLC_TMP_CURRENT_SCRIPT_PATH%"=="" (set MLC_TMP_CURRENT_SCRIPT_PATH=%CD%) + +echo hnswlib run is delegated to the benchmark-program dependency (MLC_RUN_CMD). +exit /b 0 diff --git a/script/benchmark-hnswlib/run.sh b/script/benchmark-hnswlib/run.sh new file mode 100644 index 000000000..e6618b141 --- /dev/null +++ b/script/benchmark-hnswlib/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +MLC_PYTHON_BIN=${MLC_PYTHON_BIN_WITH_PATH:-python3} +MLC_TMP_CURRENT_SCRIPT_PATH=${MLC_TMP_CURRENT_SCRIPT_PATH:-$PWD} + +echo "hnswlib run is delegated to the benchmark-program dependency (MLC_RUN_CMD)." +exit 0 diff --git a/script/benchmark-hnswlib/src/run_hnswlib.py b/script/benchmark-hnswlib/src/run_hnswlib.py new file mode 100644 index 000000000..72b767f4f --- /dev/null +++ b/script/benchmark-hnswlib/src/run_hnswlib.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 +"""hnswlib approximate-nearest-neighbor benchmark harness for MLC. + +Measures HNSW index build time, query throughput (QPS) and recall@k. + +Datasets: + * synthetic : random float32 vectors; exact ground truth is computed with a + brute-force numpy search (used for CI / quick runs). + * real : an ann-benchmarks-style HDF5 file (train / test / neighbors), + downloaded by mlcflow and passed in via MLC_HNSWLIB_DATASET_FILE. + The distance metric is read from the file's 'distance' attribute. +""" +import json +import os +import sys +import time + +import numpy as np + +# ann-benchmarks 'distance' attribute -> hnswlib space name. +DISTANCE_TO_SPACE = {"euclidean": "l2", "angular": "cosine", "dot": "ip"} + + +def _env(name, default=""): + return os.environ.get(name, default).strip() + + +def _int(name, default): + return int(_env(name, str(default)) or default) + + +def brute_force_topk(base, queries, k, metric): + """Exact top-k neighbor indices for each query via numpy.""" + if metric == "cosine": + base = base / (np.linalg.norm(base, axis=1, keepdims=True) + 1e-12) + queries = queries / (np.linalg.norm(queries, axis=1, keepdims=True) + 1e-12) + if metric in ("ip", "cosine"): + scores = queries @ base.T # larger = closer + idx = np.argpartition(-scores, k - 1, axis=1)[:, :k] + else: # l2 + # ||q||^2 - 2 q.b + ||b||^2 ; the ||q||^2 term is constant per row. + b_sq = (base * base).sum(axis=1) + scores = -2 * (queries @ base.T) + b_sq[None, :] # smaller = closer + idx = np.argpartition(scores, k - 1, axis=1)[:, :k] + return idx + + +def recall_at_k(approx_labels, true_neighbors, k): + hits = 0 + total = 0 + for approx, truth in zip(approx_labels, true_neighbors): + truth_set = set(int(x) for x in truth[:k]) + hits += len(truth_set & set(int(x) for x in approx[:k])) + total += len(truth_set) + return hits / total if total else 0.0 + + +def load_synthetic(): + n = _int("MLC_HNSWLIB_NUM_ELEMENTS", 10000) + dim = _int("MLC_HNSWLIB_DIM", 128) + nq = _int("MLC_HNSWLIB_NUM_QUERIES", 1000) + seed = _int("MLC_HNSWLIB_SEED", 42) + metric = _env("MLC_HNSWLIB_METRIC", "l2") + rng = np.random.default_rng(seed) + base = rng.random((n, dim), dtype=np.float32) + queries = rng.random((nq, dim), dtype=np.float32) + k = min(_int("MLC_HNSWLIB_K", 10), n) + true_neighbors = brute_force_topk(base, queries, k, metric) + return base, queries, true_neighbors, metric, k + + +def load_real(): + import h5py + path = _env("MLC_HNSWLIB_DATASET_FILE") + if not path or not os.path.isfile(path): + raise FileNotFoundError(f"HDF5 dataset not found: {path or '(unset)'}") + with h5py.File(path, "r") as f: + base = np.asarray(f["train"], dtype=np.float32) + queries = np.asarray(f["test"], dtype=np.float32) + true_neighbors = np.asarray(f["neighbors"]) + distance = f.attrs.get("distance", "euclidean") + metric = DISTANCE_TO_SPACE.get(str(distance), "l2") + k = min(_int("MLC_HNSWLIB_K", 10), true_neighbors.shape[1]) + return base, queries, true_neighbors, metric, k + + +def main(): + import hnswlib + + dataset = _env("MLC_HNSWLIB_DATASET", "synthetic") + M = _int("MLC_HNSWLIB_M", 16) + ef_construction = _int("MLC_HNSWLIB_EF_CONSTRUCTION", 200) + ef = _int("MLC_HNSWLIB_EF", 50) + num_threads = _int("MLC_HNSWLIB_NUM_THREADS", -1) + output_dir = _env("MLC_HNSWLIB_OUTPUT_DIR") or os.getcwd() + + if dataset == "real": + base, queries, true_neighbors, metric, k = load_real() + else: + base, queries, true_neighbors, metric, k = load_synthetic() + + n, dim = base.shape + nq = queries.shape[0] + ef = max(ef, k) # ef must be > k for meaningful recall + print(f"hnswlib: dataset={dataset} metric={metric} N={n} dim={dim} " + f"queries={nq} k={k} M={M} ef_construction={ef_construction} ef={ef}") + + index = hnswlib.Index(space=metric, dim=dim) + index.init_index(max_elements=n, ef_construction=ef_construction, M=M) + index.set_num_threads(num_threads) + + t0 = time.time() + index.add_items(base, np.arange(n)) + build_time = time.time() - t0 + + index.set_ef(ef) + t0 = time.time() + labels, _ = index.knn_query(queries, k=k) + query_time = time.time() - t0 + + recall = recall_at_k(labels, true_neighbors, k) + qps = nq / query_time if query_time > 0 else float("inf") + build_qps = n / build_time if build_time > 0 else float("inf") + + summary = { + "benchmark": "hnswlib", + "dataset": dataset, + "metric": metric, + "num_elements": n, + "dim": dim, + "num_queries": nq, + "k": k, + "M": M, + "ef_construction": ef_construction, + "ef": ef, + "num_threads": num_threads, + "build_time_sec": round(build_time, 4), + "build_vectors_per_sec": round(build_qps, 2), + "query_qps": round(qps, 2), + "mean_query_latency_ms": round(1000 * query_time / nq, 4), + "recall_at_k": round(recall, 4), + } + + os.makedirs(output_dir, exist_ok=True) + out_file = os.path.join(output_dir, "hnswlib_results.json") + with open(out_file, "w", encoding="utf-8") as f: + json.dump(summary, f, indent=2) + + print(f"Build: {build_time:.3f}s ({build_qps:,.0f} vec/s) | " + f"QPS: {qps:,.0f} | recall@{k}: {recall * 100:.2f}%") + print(f"Results written to {out_file}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/script/benchmark-program-phoronix/meta.yaml b/script/benchmark-program-phoronix/meta.yaml index bb8e2172d..bec1b1036 100644 --- a/script/benchmark-program-phoronix/meta.yaml +++ b/script/benchmark-program-phoronix/meta.yaml @@ -12,18 +12,10 @@ default_env: deps: - tags: detect,os - tags: detect,cpu -- tags: download-and-extract +- tags: get,phoronix-test-suite names: - - phoronix-deb - extra_cache_tags: phoronix,test-suite,deb - force_cache: true - skip_if_env: - MLC_PHORONIX_INSTALLED: - - 'yes' - env: - MLC_DAE_URL: 'https://github.com/phoronix-test-suite/phoronix-test-suite/releases/download/v<<>>/phoronix-test-suite_<<>>_all.deb' - MLC_DOWNLOAD_FINAL_ENV_NAME: MLC_PHORONIX_DEB_PATH - MLC_VERIFY_SSL: 'no' + - phoronix-test-suite + input_mapping: test: MLC_PHORONIX_TEST num_runs: MLC_PHORONIX_NUM_RUNS @@ -32,6 +24,8 @@ input_mapping: results_dir: MLC_PHORONIX_RESULTS_DIR result_identifier: MLC_PHORONIX_RESULT_IDENTIFIER reuse_logs: MLC_PHORONIX_REUSE_LOGS + phoronix_path: MLC_PHORONIX_TEST_SUITE_PATH + version: MLC_PHORONIX_VERSION new_env_keys: - MLC_PHORONIX_* - MLC_PHORONIX_DEB_PATH diff --git a/script/benchmark-program-phoronix/run.sh b/script/benchmark-program-phoronix/run.sh index 3f398c16e..d4e9599ff 100644 --- a/script/benchmark-program-phoronix/run.sh +++ b/script/benchmark-program-phoronix/run.sh @@ -1,20 +1,39 @@ #!/bin/bash -# Benchmark Program - Phoronix Test Suite - -# Install phoronix-test-suite from cached .deb if not already installed -if ! command -v phoronix-test-suite &> /dev/null; then - if [ -n "${MLC_PHORONIX_DEB_PATH}" ] && [ -f "${MLC_PHORONIX_DEB_PATH}" ]; then - echo "Installing phoronix-test-suite from: ${MLC_PHORONIX_DEB_PATH}" - sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "${MLC_PHORONIX_DEB_PATH}" - else - echo "ERROR: phoronix-test-suite not found and MLC_PHORONIX_DEB_PATH is not set" - exit 1 - fi - if ! command -v phoronix-test-suite &> /dev/null; then - echo "ERROR: Failed to install phoronix-test-suite" - exit 1 - fi +# Benchmark Program - Phoronix Test Suite (non-interactive / batch) + +set -o pipefail + +# --- Sanitize PATH ------------------------------------------------------------ +# The phoronix-test-suite launcher is a /bin/sh (dash) wrapper that shells out to +# coreutils (dirname, readlink, mktemp, sh, ...). A PATH polluted with non-POSIX +# entries (e.g. Windows "c:\...;" paths injected by some IDE terminals) makes +# dash fail to resolve them. Keep only absolute POSIX dirs and guarantee the +# standard system locations are present. +_clean_path="" +_oldifs="$IFS"; IFS=':' +for _p in $PATH; do + case "$_p" in + /*) ;; # keep absolute POSIX paths only + *) continue ;; + esac + case "$_p" in *'\'*|*';'*) continue ;; esac + _clean_path="${_clean_path:+$_clean_path:}$_p" +done +IFS="$_oldifs" +for _sys in /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin; do + case ":$_clean_path:" in + *":$_sys:"*) ;; + *) _clean_path="${_clean_path:+$_clean_path:}$_sys" ;; + esac +done +export PATH="$_clean_path" + +# --- Resolve the launcher provided by the get,phoronix-test-suite dep ---------- +PTS="${MLC_PHORONIX_TEST_SUITE_BIN_WITH_PATH:-phoronix-test-suite}" +if ! command -v "${PTS}" &> /dev/null && [ ! -x "${PTS}" ]; then + echo "ERROR: phoronix-test-suite launcher not found (expected from the get,phoronix-test-suite dependency; MLC_PHORONIX_TEST_SUITE_BIN_WITH_PATH=${MLC_PHORONIX_TEST_SUITE_BIN_WITH_PATH})" + exit 1 fi if [ -z "${MLC_PHORONIX_TEST}" ]; then @@ -24,52 +43,143 @@ fi RESULTS_DIR=${MLC_PHORONIX_RESULTS_DIR:-.} RESULT_ID=${MLC_PHORONIX_RESULT_IDENTIFIER:-mlc-benchmark} +mkdir -p "${RESULTS_DIR}" +# --- Seed a non-interactive config (skips the first-run EULA / anonymous-usage +# prompts and makes `batch-benchmark` fully unattended). Only written when +# absent so an existing user configuration is respected. ---------------------- +PTS_USER_DIR="${HOME}/.phoronix-test-suite" +if [ ! -f "${PTS_USER_DIR}/user-config.xml" ]; then + mkdir -p "${PTS_USER_DIR}" + cat > "${PTS_USER_DIR}/user-config.xml" <<'XML_EOF' + + + + + FALSE + FALSE + FALSE + FALSE + + + TRUE + + + FALSE + TRUE + FALSE + + + TRUE + TRUE + TRUE + FALSE + + + TRUE + 20 + 2 + 2 + FALSE + + + TRUE + FALSE + FALSE + FALSE + FALSE + FALSE + TRUE + TRUE + + + FALSE + 20 + + + +XML_EOF + echo "Wrote non-interactive PTS config: ${PTS_USER_DIR}/user-config.xml" +fi + +# Pre-answer the result save prompts (used when PromptSaveName etc. are FALSE). export TEST_RESULTS_NAME="${RESULT_ID}" export TEST_RESULTS_IDENTIFIER="${RESULT_ID}" export TEST_RESULTS_DESCRIPTION="MLC automated benchmark run" -# Configure batch mode -if [ "${MLC_PHORONIX_BATCH_MODE}" == "yes" ]; then - export PRESET_OPTIONS="TRUE" - BATCH_FLAGS="--batch-run" -else - BATCH_FLAGS="" -fi - -# Set run count +# Number of runs per test. if [ -n "${MLC_PHORONIX_NUM_RUNS}" ]; then export FORCE_TIMES_TO_RUN=${MLC_PHORONIX_NUM_RUNS} fi +# Compiler toolchain is taken from the environment (e.g. set by run-phoronix-amd). +# PTS honours CC/CXX/CFLAGS/CXXFLAGS when it compiles tests from source. +echo "" +echo "Compiler environment:" +echo " CC=${CC:-}" +echo " CXX=${CXX:-}" +echo " FC=${FC:-}" +echo " CFLAGS=${CFLAGS}" +echo " CXXFLAGS=${CXXFLAGS}" + echo "" echo "***********************************************************************" echo "Running Phoronix Test Suite" echo " Test: ${MLC_PHORONIX_TEST}" echo " Runs: ${MLC_PHORONIX_NUM_RUNS}" echo " Batch mode: ${MLC_PHORONIX_BATCH_MODE}" +echo " Result id: ${RESULT_ID}" echo "***********************************************************************" -# Install the test first +# Install the test (compiles from source using CC/CXX when applicable). echo "" echo "Installing test: ${MLC_PHORONIX_TEST}" -phoronix-test-suite install "${MLC_PHORONIX_TEST}" +"${PTS}" install "${MLC_PHORONIX_TEST}" +rc=$? +if [ ${rc} -ne 0 ]; then + echo "ERROR: phoronix-test-suite install failed (status ${rc})" + exit ${rc} +fi -# Run the benchmark +OUTPUT_FILE="${RESULTS_DIR}/phoronix_output.txt" echo "" echo "Running benchmark..." -OUTPUT_FILE="${RESULTS_DIR}/phoronix_output.txt" - -phoronix-test-suite ${BATCH_FLAGS} benchmark ${MLC_PHORONIX_EXTRA_ARGS} "${MLC_PHORONIX_TEST}" 2>&1 | tee "${OUTPUT_FILE}" -exitstatus=$? +if [ "${MLC_PHORONIX_BATCH_MODE}" == "yes" ]; then + "${PTS}" batch-benchmark ${MLC_PHORONIX_EXTRA_ARGS} "${MLC_PHORONIX_TEST}" 2>&1 | tee "${OUTPUT_FILE}" +else + "${PTS}" benchmark ${MLC_PHORONIX_EXTRA_ARGS} "${MLC_PHORONIX_TEST}" 2>&1 | tee "${OUTPUT_FILE}" +fi +exitstatus=${PIPESTATUS[0]} if [ ${exitstatus} -ne 0 ]; then echo "Phoronix Test Suite exited with status: ${exitstatus}" exit ${exitstatus} fi -# Export results to JSON if available -phoronix-test-suite result-file-to-json "${RESULT_ID}" > "${RESULTS_DIR}/phoronix_results.json" 2>/dev/null +# Export results. PTS sanitizes the save identifier (strips dots/spaces), +# so discover the actual saved result directory (most recently modified) rather +# than assuming it equals RESULT_ID. +pts_results_root="${HOME}/.phoronix-test-suite/test-results" +saved_name="" +if [ -d "${pts_results_root}" ]; then + saved_name=$(ls -1t "${pts_results_root}" 2>/dev/null | head -1) +fi + +if [ -n "${saved_name}" ]; then + # Archive the raw composite.xml. + if [ -f "${pts_results_root}/${saved_name}/composite.xml" ]; then + cp -f "${pts_results_root}/${saved_name}/composite.xml" "${RESULTS_DIR}/phoronix_composite.xml" + fi + # `result-file-to-json` writes a file and prints "Saved Output To: " + # (with ANSI colour codes) instead of emitting JSON on stdout. + json_msg=$("${PTS}" result-file-to-json "${saved_name}" 2>/dev/null) + saved_json=$(printf '%s\n' "$json_msg" \ + | sed -r 's/\x1B\[[0-9;]*[mK]//g' \ + | sed -n 's/.*Saved Output To:[[:space:]]*//p' | tr -d '\r' | tail -1) + if [ -n "${saved_json}" ] && [ -f "${saved_json}" ]; then + cp -f "${saved_json}" "${RESULTS_DIR}/phoronix_results.json" + fi +fi echo "" echo "***********************************************************************" diff --git a/script/benchmark-program/customize.py b/script/benchmark-program/customize.py index d3d5739fe..a2f0e63c9 100644 --- a/script/benchmark-program/customize.py +++ b/script/benchmark-program/customize.py @@ -49,6 +49,47 @@ def preprocess(i): env['MLC_RUN_DIR'] = os.getcwd() logs_dir = env.get('MLC_LOGS_DIR', env['MLC_RUN_DIR']) + # perf / instruction-mix profiling (opt-in via _perf-record / _perf-stat / + # _insmix or --perf_record / --perf_stat / --insmix). Wraps MLC_RUN_CMD. + perf_out = env.get('MLC_BENCHMARK_PERF_OUTPUT_DIR', '') or logs_dir + requested = [m for m in ( + ('record', env.get('MLC_BENCHMARK_PERF_RECORD', '')), + ('insmix', env.get('MLC_BENCHMARK_INSMIX', '')), + ('stat', env.get('MLC_BENCHMARK_PERF_STAT', ''))) if is_true(m[1])] + perf_post_cmd = '' + if requested and os_info['platform'] != 'windows': + if len(requested) > 1: + logger.warning('Multiple perf modes requested ({}); using {}'.format( + ', '.join(m[0] for m in requested), requested[0][0])) + mode = requested[0][0] + if mode == 'record': + data = os.path.join(perf_out, 'perf.data') + freq = env.get('MLC_BENCHMARK_PERF_FREQ', '') + freq_opt = '-F ' + freq + ' ' if freq else '' + perf_prefix = 'perf record -g ' + freq_opt + '-o ' + q + data + q + ' -- ' + report = os.path.join(perf_out, 'perf_report.txt') + perf_post_cmd = ('perf report -i ' + q + data + q + ' --stdio > ' + + q + report + q + ' 2>/dev/null || true') + env['MLC_BENCHMARK_PERF_DATA'] = data + env['MLC_BENCHMARK_PERF_REPORT_FILE'] = report + elif mode == 'insmix': + # True dynamic instruction mix via Intel SDE (emulated, host-agnostic). + sde_bin = env.get('MLC_INTEL_SDE_BIN_WITH_PATH', 'sde64') + out = os.path.join(perf_out, 'sde-mix-out.txt') + perf_prefix = q + sde_bin + q + ' -mix -omix ' + q + out + q + ' -- ' + perf_post_cmd = 'echo Intel SDE instruction mix written to ' + q + out + q + env['MLC_BENCHMARK_INSMIX_FILE'] = out + else: # stat + events = env.get('MLC_BENCHMARK_PERF_EVENTS', '') + ev_opt = '-e ' + events + ' ' if events else '' + out = os.path.join(perf_out, 'perf_stat.txt') + perf_prefix = 'perf stat ' + ev_opt + '-o ' + q + out + q + ' ' + perf_post_cmd = ('echo ===== perf stat ===== && cat ' + + q + out + q) + env['MLC_BENCHMARK_PERF_STAT_FILE'] = out + env['MLC_RUN_PREFIX0'] = perf_prefix + env.get('MLC_RUN_PREFIX0', '') + logger.info('Perf profiling enabled ({}): {}'.format(mode, perf_prefix)) + x = env.get('MLC_RUN_PREFIX0', '') if x != '': env['MLC_RUN_CMD'] = x + ' ' + env.get('MLC_RUN_CMD', '') @@ -107,6 +148,10 @@ def preprocess(i): print( f"Post run command for killing the process that measures the runtime system information: {post_run_cmd}") + # perf record needs a post-run step to render the human-readable report. + if perf_post_cmd: + post_run_cmd = post_run_cmd + ' ; ' + perf_post_cmd if post_run_cmd else perf_post_cmd + env['MLC_POST_RUN_CMD'] = post_run_cmd # Print info diff --git a/script/benchmark-program/meta.yaml b/script/benchmark-program/meta.yaml index 284110671..6513b0480 100644 --- a/script/benchmark-program/meta.yaml +++ b/script/benchmark-program/meta.yaml @@ -17,10 +17,20 @@ default_env: MLC_ENABLE_PROFILING: '0' new_env_keys: - MLC_RUN_CMD +- MLC_BENCHMARK_PERF_DATA +- MLC_BENCHMARK_PERF_REPORT_FILE +- MLC_BENCHMARK_PERF_STAT_FILE +- MLC_BENCHMARK_INSMIX_FILE # Input mapping input_mapping: profile_system_info: MLC_PROFILE_SYSTEM_INFO + perf_record: MLC_BENCHMARK_PERF_RECORD + perf_stat: MLC_BENCHMARK_PERF_STAT + insmix: MLC_BENCHMARK_INSMIX + perf_events: MLC_BENCHMARK_PERF_EVENTS + perf_freq: MLC_BENCHMARK_PERF_FREQ + perf_output_dir: MLC_BENCHMARK_PERF_OUTPUT_DIR # Dependencies deps: @@ -32,6 +42,29 @@ deps: - 'True' - true tags: set,performance,mode,_performance +# perf is only needed for the perf record / perf stat modes. +- tags: get,generic-sys-util,_linux-tools + enable_if_any_env: + MLC_BENCHMARK_PERF_RECORD: + - 'yes' + - 'on' + - 'true' + - '1' + MLC_BENCHMARK_PERF_STAT: + - 'yes' + - 'on' + - 'true' + - '1' +# Intel SDE provides the true dynamic instruction mix (_insmix). +- tags: get,intel,sde,tool + names: + - intel-sde + enable_if_env: + MLC_BENCHMARK_INSMIX: + - 'yes' + - 'on' + - 'true' + - '1' # Variations variations: @@ -48,3 +81,12 @@ variations: MLC_ENABLE_PROFILING: 1 deps: - tags: get,profiler + perf-record: + env: + MLC_BENCHMARK_PERF_RECORD: 'yes' + perf-stat: + env: + MLC_BENCHMARK_PERF_STAT: 'yes' + insmix: + env: + MLC_BENCHMARK_INSMIX: 'yes' diff --git a/script/get-phoronix-test-suite/customize.py b/script/get-phoronix-test-suite/customize.py new file mode 100644 index 000000000..83a684085 --- /dev/null +++ b/script/get-phoronix-test-suite/customize.py @@ -0,0 +1,87 @@ +from mlc import utils +import os +import shutil + +from utils import is_true + + +def _resolve_launcher(path): + """Return the phoronix-test-suite launcher given a dir or the launcher path.""" + if not path: + return '' + if os.path.isfile(path) and os.access(path, os.X_OK): + return path + if os.path.isdir(path): + for cand in (os.path.join(path, 'bin', 'phoronix-test-suite'), + os.path.join(path, 'phoronix-test-suite')): + if os.path.isfile(cand): + return cand + return '' + + +def preprocess(i): + + env = i['env'] + logger = i['automation'].logger + + user_path = env.get('MLC_PHORONIX_TEST_SUITE_PATH', '') + prefix = env.get('MLC_PHORONIX_INSTALL_PREFIX', '') + bin_path = '' + + if user_path: + bin_path = _resolve_launcher(user_path) + if not bin_path: + return {'return': 1, + 'error': f"phoronix-test-suite not found at MLC_PHORONIX_TEST_SUITE_PATH={user_path}"} + else: + # Reuse an install already on PATH before downloading anything. + which = shutil.which('phoronix-test-suite') + if which: + bin_path = which + elif prefix: + # Reuse a prior no-sudo install in this prefix if present. + bin_path = _resolve_launcher(prefix) + if not bin_path: + # run.sh will perform the no-sudo portable install into the prefix. + env['MLC_PHORONIX_DO_PORTABLE_INSTALL'] = 'yes' + + if bin_path: + env['MLC_PHORONIX_TEST_SUITE_BIN_WITH_PATH'] = bin_path + env['MLC_PHORONIX_SKIP_INSTALL'] = 'yes' + logger.info(f"Using existing phoronix-test-suite: {bin_path}") + elif not prefix: + # No reusable install and no prefix: fall back to the system .deb/apt path. + # Guard against the no-sudo case where apt will fail. + no_sudo = is_true(env.get('MLC_PHORONIX_NO_SUDO', '')) or \ + (env.get('MLC_SUDO_USER', '') not in ('yes', 'True', 'true', True)) + if no_sudo: + return {'return': 1, + 'error': 'phoronix-test-suite is not installed and sudo is unavailable. ' + 'Pass --install_prefix= for a no-sudo install, ' + 'or --phoronix_path=.'} + + return {'return': 0} + + +def postprocess(i): + + env = i['env'] + logger = i['automation'].logger + + bin_path = env.get('MLC_PHORONIX_TEST_SUITE_BIN_WITH_PATH', '') + prefix = env.get('MLC_PHORONIX_INSTALL_PREFIX', '') + + if not bin_path and prefix: + bin_path = _resolve_launcher(prefix) + if not bin_path: + bin_path = shutil.which('phoronix-test-suite') or '' + if not bin_path and os.path.isfile('/usr/bin/phoronix-test-suite'): + bin_path = '/usr/bin/phoronix-test-suite' + + if not bin_path: + return {'return': 1, 'error': 'phoronix-test-suite not found after installation'} + + env['MLC_PHORONIX_TEST_SUITE_BIN_WITH_PATH'] = bin_path + env['MLC_PHORONIX_INSTALLED_PATH'] = os.path.dirname(bin_path) + logger.info(f"phoronix-test-suite: {bin_path}") + return {'return': 0} diff --git a/script/get-phoronix-test-suite/meta.yaml b/script/get-phoronix-test-suite/meta.yaml new file mode 100644 index 000000000..4368b33a0 --- /dev/null +++ b/script/get-phoronix-test-suite/meta.yaml @@ -0,0 +1,68 @@ +alias: get-phoronix-test-suite +uid: 04b2fa91fd104c20 +automation_alias: script +automation_uid: 5b4e0237da074764 + +# Metadata +category: Detection or installation of tools and artifacts +tags: +- get +- install +- phoronix-test-suite +- phoronix +- pts + +# Cache +cache: true + +# Environment +default_env: + MLC_PHORONIX_VERSION: '10.8.4' +new_env_keys: +- MLC_PHORONIX_TEST_SUITE_BIN_WITH_PATH +- MLC_PHORONIX_INSTALLED_PATH +- MLC_PHORONIX_DEB_PATH +- +PATH + +# Input mapping +input_mapping: + phoronix_path: MLC_PHORONIX_TEST_SUITE_PATH + install_path: MLC_PHORONIX_TEST_SUITE_PATH + version: MLC_PHORONIX_VERSION + install_prefix: MLC_PHORONIX_INSTALL_PREFIX + no_sudo: MLC_PHORONIX_NO_SUDO + skip_sudo: MLC_SKIP_SUDO + +input_description: + phoronix_path: + desc: Path to an existing phoronix-test-suite install - either the launcher script itself or the directory containing it. When given, download/install is skipped. + version: + desc: Phoronix Test Suite version to fetch when it is not already installed (default 10.8.4). + install_prefix: + desc: Install the suite (no sudo) into this directory - e.g. a shared /pa_nvme path reusable across SLURM nodes. If it already contains a working launcher it is reused. + no_sudo: + desc: Force the no-sudo portable install (requires install_prefix). Useful on SLURM compute nodes where apt/sudo is unavailable. + +# Dependencies +deps: +- tags: detect,os +- tags: detect,sudo +# Fetch the release .deb only when no existing install path was provided. +- tags: download-and-extract + names: + - phoronix-deb + extra_cache_tags: phoronix,test-suite,deb + force_cache: true + skip_if_env: + MLC_PHORONIX_TEST_SUITE_PATH: + - true + env: + MLC_DAE_URL: 'https://github.com/phoronix-test-suite/phoronix-test-suite/releases/download/v<<>>/phoronix-test-suite_<<>>_all.deb' + MLC_DOWNLOAD_FINAL_ENV_NAME: MLC_PHORONIX_DEB_PATH + MLC_VERIFY_SSL: 'no' + +# Variations +variations: + path.#: + env: + MLC_PHORONIX_TEST_SUITE_PATH: '#' diff --git a/script/get-phoronix-test-suite/run.sh b/script/get-phoronix-test-suite/run.sh new file mode 100755 index 000000000..48b94fa2c --- /dev/null +++ b/script/get-phoronix-test-suite/run.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +# get-phoronix-test-suite: resolve/install the Phoronix Test Suite. +# - If customize.py already resolved an existing launcher -> nothing to do. +# - Portable (no-sudo) install into MLC_PHORONIX_INSTALL_PREFIX when requested +# (works on SLURM compute nodes: downloads the relocatable source tarball plus +# a prefix-local php via apt-get download, no root required). +# - Otherwise install the release .deb via apt (needs sudo). + +# Keep only absolute POSIX PATH entries (some IDE terminals inject Windows paths). +_clean_path="" +_oldifs="$IFS"; IFS=':' +for _p in $PATH; do + case "$_p" in /*) ;; *) continue ;; esac + case "$_p" in *'\'*|*';'*) continue ;; esac + _clean_path="${_clean_path:+$_clean_path:}$_p" +done +IFS="$_oldifs" +for _sys in /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin; do + case ":$_clean_path:" in *":$_sys:"*) ;; *) _clean_path="${_clean_path:+$_clean_path:}$_sys" ;; esac +done +export PATH="$_clean_path" + +PTS_VERSION="${MLC_PHORONIX_VERSION:-10.8.4}" + +if [ "${MLC_PHORONIX_SKIP_INSTALL}" == "yes" ]; then + echo "phoronix-test-suite already available; skipping install." + exit 0 +fi + +# --------------------------------------------------------------------------- +# No-sudo portable install into a (shared) prefix. +# --------------------------------------------------------------------------- +if [ "${MLC_PHORONIX_DO_PORTABLE_INSTALL}" == "yes" ]; then + PREFIX="${MLC_PHORONIX_INSTALL_PREFIX}" + if [ -z "${PREFIX}" ]; then + echo "ERROR: MLC_PHORONIX_INSTALL_PREFIX is required for the portable install" + exit 1 + fi + echo "Portable (no-sudo) install of Phoronix ${PTS_VERSION} into ${PREFIX}" + rm -rf "${PREFIX}"; mkdir -p "${PREFIX}/php-root" "${PREFIX}/bin" + B=$(mktemp -d); cd "${B}" || exit 1 + + # Relocatable launcher from the GitHub source archive (honours $PHP_BIN, + # resolves its core dir via readlink - unlike the .deb which hardcodes /usr/share). + curl -fsSL --max-time 180 -o pts.tgz \ + "https://github.com/phoronix-test-suite/phoronix-test-suite/archive/refs/tags/v${PTS_VERSION}.tar.gz" || { + echo "ERROR: failed to download phoronix source ${PTS_VERSION}"; exit 1; } + tar xf pts.tgz + src=$(find . -maxdepth 1 -type d -name 'phoronix-test-suite-*' | head -1) + [ -n "${src}" ] || { echo "ERROR: phoronix source dir missing"; exit 1; } + cp -a "${src}" "${PREFIX}/phoronix-test-suite" + + # Prefix-local php (+ XML/mbstring), no sudo. Download the concrete php + # packages explicitly (apt-get download fetches even if already installed on the + # build host) and add any still-missing shared libs via --print-uris. + mkdir php && cd php + PHPMM=$(apt-cache depends php-cli 2>/dev/null | grep -oE 'php[0-9]+\.[0-9]+-cli' | head -1 | sed 's/-cli//') + [ -n "${PHPMM}" ] || PHPMM=php8.3 + PKGS="${PHPMM}-cli ${PHPMM}-common ${PHPMM}-opcache ${PHPMM}-readline ${PHPMM}-xml ${PHPMM}-mbstring" + echo "php packages: ${PKGS}" + apt-get download ${PKGS} 2>/dev/null || echo "WARN: some apt-get download failed" + apt-get install --print-uris -y ${PKGS} 2>/dev/null \ + | grep -oE "https?://[^ ']+\.deb" | sort -u > uris.txt + while read -r u; do curl -fsSL -O "$u" || echo "WARN: failed $u"; done < uris.txt + echo "extracting $(ls *.deb 2>/dev/null | wc -l) php .deb(s)" + for d in *.deb; do dpkg-deb -x "$d" "${PREFIX}/php-root"; done + cd "${PREFIX}" + + PHPBIN=$(find php-root/usr/bin -maxdepth 1 -name 'php8*' -type f | head -1) + EXTDIR=$(find php-root/usr/lib/php -maxdepth 1 -type d -name '20*' | head -1) + if [ -z "${PHPBIN}" ] || [ -z "${EXTDIR}" ]; then + echo "ERROR: prefix-local php not found after extraction"; exit 1 + fi + + EXT_FLAGS="" + for e in dom simplexml xml xmlwriter xmlreader mbstring; do + EXT_FLAGS="${EXT_FLAGS} -d extension=${e}" + done + cat > bin/php < bin/phoronix-test-suite </dev/null 2>&1 \ + && echo "Portable install OK: ${PREFIX}/bin/phoronix-test-suite" \ + || { echo "ERROR: portable phoronix launcher failed to run"; exit 1; } + exit 0 +fi + +# --------------------------------------------------------------------------- +# System .deb install via apt (needs sudo). +# --------------------------------------------------------------------------- +if command -v phoronix-test-suite &> /dev/null; then + echo "phoronix-test-suite already on PATH; skipping install." + exit 0 +fi +if [ -z "${MLC_PHORONIX_DEB_PATH}" ] || [ ! -f "${MLC_PHORONIX_DEB_PATH}" ]; then + echo "ERROR: phoronix-test-suite .deb not found (MLC_PHORONIX_DEB_PATH=${MLC_PHORONIX_DEB_PATH})" + exit 1 +fi +echo "Installing phoronix-test-suite from: ${MLC_PHORONIX_DEB_PATH}" +${MLC_SUDO} DEBIAN_FRONTEND=noninteractive apt-get install -y "${MLC_PHORONIX_DEB_PATH}" +rc=$? +if [ ${rc} -ne 0 ] || ! command -v phoronix-test-suite &> /dev/null; then + echo "ERROR: Failed to install phoronix-test-suite (status ${rc})" + exit 1 +fi +exit 0