Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion .buildkite/scripts/ci-bake-rocm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,50 @@ should_export_rocm_smoke() {
|| "${TARGET}" == "smoke-test-rocm-ci" ]]
}

should_export_kernel_symbol_map() {
[[ "${VLLM_KERNEL_SYMBOL_MAP:-0}" == "1" ]] || return 1
case "${TARGET}" in
test-rocm-ci|test-rocm-ci-with-wheel|test-rocm-ci-with-artifacts|\
export-wheel-rocm|csrc-rocm-ci|smoke-test-rocm-ci|kernel-symbol-map-rocm)
return 0 ;;
*) return 1 ;;
esac
}

export_kernel_symbol_map() {
should_export_kernel_symbol_map || return 0
echo "--- :world_map: Exporting ROCm kernel symbol map"
rm -rf ./kernel-symbol-map-rocm || return 1
docker buildx bake \
"${BAKE_ALLOW_ARGS[@]}" "${BAKE_FILES[@]}" \
--progress "${BUILDKIT_PROGRESS:-plain}" \
kernel-symbol-map-rocm || return 1
upload_kernel_symbol_map_if_present
}

export_kernel_symbol_map_from_cache() {
should_export_kernel_symbol_map || return 0
# A separate shell keeps setup failures fatal inside the optional export.
FORCE_BUILD=1 VLLM_KERNEL_SYMBOL_MAP=1 UPLOAD_ROCM_WHEEL_ARTIFACTS=0 \
CI_HCL_SOURCE="${CI_HCL_PATH}" VLLM_BAKE_FILE="${VLLM_BAKE_FILE}" \
BUILDER_NAME="${BUILDER_NAME}" \
bash "${BASH_SOURCE[0]}" kernel-symbol-map-rocm \
|| echo "ROCm kernel symbol map export from cache failed; continuing without it" >&2
}

upload_kernel_symbol_map_if_present() {
should_export_kernel_symbol_map || return 0
local map_dir="./kernel-symbol-map-rocm"
local map_name="kernel_symbol_map.rocm.json.gz"
if [[ ! -s "${map_dir}/${map_name}" ]]; then
echo "ROCm kernel symbol map export is missing: ${map_dir}/${map_name}" >&2
return 1
fi
if [[ "${BUILDKITE:-false}" == "true" ]]; then
(cd "${map_dir}" && buildkite-agent artifact upload "${map_name}")
fi
}

verify_rocm_smoke_export() {
local marker="./build/rocm-smoke-export/vllm-smoke-ok"
local expected_smoke_id="${BUILDKITE_BUILD_ID:-local}"
Expand Down Expand Up @@ -1453,7 +1497,8 @@ maybe_skip_existing_image() {
return 0
fi
if ! is_ci_base_target \
&& { should_upload_wheel_artifacts || should_export_rocm_smoke; }; then
&& { should_upload_wheel_artifacts || should_export_rocm_smoke \
|| [[ "${TARGET}" == "kernel-symbol-map-rocm" ]]; }; then
echo "Local-output targets always run for the current build"
return 0
fi
Expand Down Expand Up @@ -1501,11 +1546,13 @@ maybe_skip_existing_image() {

echo "Commit image already exists: ${IMAGE_TAG}"
echo "Skipping build"
export_kernel_symbol_map_from_cache
exit 0
fi

echo "Image already exists: ${IMAGE_TAG}"
echo "Skipping build"
export_kernel_symbol_map_from_cache
exit 0
}

Expand Down Expand Up @@ -1806,6 +1853,7 @@ EOF
uses_rocm_csrc_cache() {
case "${TARGET}" in
csrc-rocm-ci \
| kernel-symbol-map-rocm \
| test-rocm-ci \
| test-rocm-ci-with-wheel \
| test-rocm-ci-with-artifacts \
Expand Down Expand Up @@ -2252,6 +2300,15 @@ EOF
cat <<EOF
}

target "kernel-symbol-map-rocm" {
cache-from = concat(
get_cache_from_rocm_csrc(),
EOF
write_hcl_string_list " " "${csrc_content_cache_from[@]}"
cat <<EOF
)
}

target "test-rocm-ci" {
cache-from = concat(
get_cache_from_rocm(),
Expand Down Expand Up @@ -2724,12 +2781,21 @@ main() {
# from an earlier build or retry.
rm -rf ./build/rocm-smoke-export
fi
if [[ "${TARGET}" == "kernel-symbol-map-rocm" ]]; then
rm -rf ./kernel-symbol-map-rocm
fi
seed_dependency_caches_if_needed
run_bake
verify_rocm_smoke_export
promote_stable_ci_base_tag
publish_ci_base_handoff_ref
upload_wheel_artifacts_if_present
if [[ "${TARGET}" == "kernel-symbol-map-rocm" ]]; then
upload_kernel_symbol_map_if_present
else
export_kernel_symbol_map \
|| echo "ROCm kernel symbol map export or upload failed; continuing without it" >&2
fi
}

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
Expand Down
31 changes: 31 additions & 0 deletions .buildkite/scripts/hardware_ci/run-amd-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ clear_ci_orchestration_env() {
VLLM_ALLOW_DEPRECATED_BEAM_SEARCH
}

configure_kernrec_docker_args() {
kernrec_docker_args=()
[[ "$1" == *recorders/kernrec/ci_setup.sh* ]] || return 0
local checkout="${BUILDKITE_BUILD_CHECKOUT_PATH:-}"
if [[ -z "$checkout" || ! -d "$checkout" ]] ||
! mkdir -p "$checkout/.kernrec" || ! chmod 0777 "$checkout/.kernrec"; then
echo "kernrec: checkout unavailable; container recordings cannot be uploaded" >&2
kernrec_docker_args=(-e KERNREC_DISABLE=1)
return 0
fi
kernrec_docker_args=(
-v "$checkout/.kernrec:/tmp/kernrec-checkout/.kernrec"
-e "KERNREC_CHECKOUT_PATH=/tmp/kernrec-checkout"
-e BUILDKITE_JOB_ID
-e BUILDKITE_STEP_KEY
-e BUILDKITE_LABEL
-e BUILDKITE_BUILD_NUMBER
-e BUILDKITE_COMMIT
-e KERNREC_PYTHON
-e VLLM_WORKER_MULTIPROC_METHOD
-e VLLM_WORKER_SHUTDOWN_TIMEOUT_SECONDS
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: This only runs on the dind path, and every AMD step is dind: false today. Is it still needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, it isn't needed. Every AMD step is dind: false, so the runner exits in the native branch before it reaches docker run. The only jobs that can still be dind (no_plugin and multi-node) are already excluded from kernrec in ci-infra's _kernrec_applies. I removed the helper, the sourcing guard and tests/tools/test_amd_runner.py, so run-amd-test.sh now matches main.


amd_ci_teardown_log() {
local event=$1
shift
Expand Down Expand Up @@ -1465,6 +1489,11 @@ handle_amd_runner_exit() {
return 0
}

# Sourcing exposes the shell helpers without starting a CI workload.
if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
return 0
fi

# Catch both test failures and wrapper/setup failures. Runtime-specific cleanup
# traps below replace this trap and call the same handler after cleanup.
trap handle_amd_runner_exit EXIT
Expand Down Expand Up @@ -1770,6 +1799,7 @@ else
fi

exit_code=0
configure_kernrec_docker_args "$commands"
# shellcheck disable=SC2086 # word splitting is intentional: both hold multiple docker flags
run_docker_with_ci_timeout docker run \
"${docker_run_terminal_args[@]}" \
Expand Down Expand Up @@ -1806,6 +1836,7 @@ else
-e "PYTORCH_ROCM_ARCH=" \
"${cpu_platform_env[@]}" \
"${standalone_merge_base_env[@]}" \
"${kernrec_docker_args[@]}" \
--name "${container_name}" \
"${image_name}" \
/bin/bash -c "${CONTAINER_PREFLIGHT} && ${commands}" || exit_code=$?
Expand Down
12 changes: 11 additions & 1 deletion .buildkite/test_areas/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ steps:
source_file_dependencies:
- .buildkite/release-pipeline.yaml
- .buildkite/scripts/docker-build-metadata-args.sh
- .buildkite/scripts/hardware_ci/run-amd-test.sh
- .buildkite/scripts/rocm/build-config.sh
- docker/Dockerfile
- docker/Dockerfile.cpu
- docker/docker-bake.hcl
- tests/tools/test_docker_build_metadata_args.py
- tests/tools/test_amd_runner.py
- tests/tools/test_kernel_symbol_map.py
- tools/ci/kernel_symbol_map.py
- tools/ci/rocm_kernel_symbol_map.py
commands:
- pytest -v -s tools/test_docker_build_metadata_args.py
- pytest -v -s tools/test_docker_build_metadata_args.py tools/test_amd_runner.py
- pytest -v -s tools/test_kernel_symbol_map.py
mirror:
amd:
label: ":amd: (MI250) Docker Build Metadata"
Expand All @@ -32,3 +39,6 @@ steps:
- docker/ci-rocm.hcl
- docker/docker-bake-rocm.hcl
- tests/tools/test_docker_build_metadata_args.py
- tests/tools/test_kernel_symbol_map.py
- tools/ci/kernel_symbol_map.py
- tools/ci/rocm_kernel_symbol_map.py
1 change: 1 addition & 0 deletions .buildkite/test_areas/misc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ steps:
- vllm/v1/
- vllm/version.py
- cmake/utils.cmake
- cmake/hipify.py
- tests/test_uvicorn_logging.py
- tests/test_attention_backend_registry.py
- tests/test_audio_media_size_precheck.py
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ endif()

# CUDA by default, can be overridden by using -DVLLM_TARGET_DEVICE=... (used by setup.py)
set(VLLM_TARGET_DEVICE "cuda" CACHE STRING "Target device backend for vLLM")
if (VLLM_TARGET_DEVICE STREQUAL "rocm" OR "$ENV{VLLM_KERNEL_SYMBOL_MAP}" STREQUAL "1")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Target device: ${VLLM_TARGET_DEVICE}")

Expand Down Expand Up @@ -406,6 +409,15 @@ if(VLLM_GPU_LANG STREQUAL "CUDA" OR VLLM_GPU_LANG STREQUAL "HIP")
WORKING_DIRECTORY "${TORCH_SHADOW_INCLUDE_DIR}"
COMMAND_ERROR_IS_FATAL ANY)

execute_process(
COMMAND ${Python_EXECUTABLE} -c
"import json,sys; from pathlib import Path; Path(sys.argv[1]).write_text(json.dumps({sys.argv[2]: sys.argv[3:]}))"
"${CMAKE_CURRENT_BINARY_DIR}/generated-source-deps.json"
"${TORCH_SHADOW_INCLUDE_DIR}/${_stable_hdr_rel}"
"${TORCH_INCLUDE_DIR}/${_stable_hdr_rel}"
"${CMAKE_CURRENT_LIST_DIR}/cmake/patches/pytorch_stable_string.patch"
COMMAND_ERROR_IS_FATAL ANY)

include_directories(BEFORE "${TORCH_SHADOW_INCLUDE_DIR}")
endif()
endif()
Expand Down
46 changes: 40 additions & 6 deletions cmake/hipify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#

import argparse
import json
import os
import shutil
from pathlib import Path

from torch.utils.hipify.hipify_python import get_hip_file_path, hipify

Expand Down Expand Up @@ -48,14 +50,29 @@ def _expected_hip_build_path(source_abs: str, output_directory: str) -> str:
parser.add_argument(
"sources", help="Source files to hipify.", nargs="*", default=[]
)
parser.add_argument(
"--manifest", help="Write generated-to-original source/header provenance."
)

args = parser.parse_args()

# Limit include scope to project_dir only
includes = [os.path.join(args.project_dir, "*")]

# Get absolute path for all source files.
extra_files = [os.path.abspath(s) for s in args.sources]
project_dir = Path(args.project_dir).resolve()
output_dir = Path(args.output_dir).resolve()
provenance = {
str(output_dir / source.relative_to(project_dir)): str(source)
for source in project_dir.rglob("*")
if source.is_file()
}
source_copies = {
os.path.abspath(source): str(
output_dir / Path(source).resolve().relative_to(project_dir)
)
for source in args.sources
}
extra_files = list(source_copies.values())

# Copy sources from project directory to output directory.
# The directory might already exist to hold object files so we ignore that.
Expand All @@ -75,27 +92,44 @@ def _expected_hip_build_path(source_abs: str, output_directory: str) -> str:
is_pytorch_extension=True,
hipify_extra_files_only=True,
)
copied_sources = dict(provenance)
for source, result in hipify_result.items():
if result.hipified_path is not None:
original = copied_sources.get(
os.path.abspath(source), os.path.abspath(source)
)
provenance[os.path.abspath(result.hipified_path)] = original

hipified_sources = []
for source in args.sources:
s_abs = os.path.abspath(source)
if s_abs in hipify_result and hipify_result[s_abs].hipified_path is not None:
path = hipify_result[s_abs].hipified_path
copied = source_copies[s_abs]
if copied in hipify_result and hipify_result[copied].hipified_path is not None:
path = hipify_result[copied].hipified_path
# PyTorch skips writing when is_pytorch_extension and text unchanged;
# hipified_path then stays *.cu. CMake expects *.hip under output_dir.
if s_abs.endswith(".cu") and path.endswith(".cu"):
dest = _expected_hip_build_path(s_abs, args.output_dir)
dest = _expected_hip_build_path(copied, args.output_dir)
if os.path.normpath(path) != os.path.normpath(dest):
os.makedirs(os.path.dirname(dest), exist_ok=True)
shutil.copy2(path, dest)
hipified_s_abs = dest
else:
hipified_s_abs = path
else:
hipified_s_abs = s_abs
hipified_s_abs = copied
hipified_sources.append(hipified_s_abs)
provenance[os.path.abspath(hipified_s_abs)] = s_abs

assert len(hipified_sources) == len(args.sources)

manifest = (
Path(args.manifest) if args.manifest else output_dir / "hipify-source-map.json"
)
manifest.parent.mkdir(parents=True, exist_ok=True)
temporary = manifest.with_suffix(manifest.suffix + ".tmp")
temporary.write_text(json.dumps(provenance, indent=2, sort_keys=True) + "\n")
temporary.replace(manifest)

# Print hipified source files.
print("\n".join(hipified_sources))
7 changes: 5 additions & 2 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ function (vllm_finalize_hipify_target)
list(REMOVE_DUPLICATES ALL_BYPRODUCTS)

set(CSRC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/csrc)
set(HIPIFY_MANIFEST ${CMAKE_CURRENT_BINARY_DIR}/hipify-source-map.json)
add_custom_target(
hipify_all
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR}/csrc -o ${CSRC_BUILD_DIR} ${ALL_SRCS}
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR}/csrc -o ${CSRC_BUILD_DIR} --manifest ${HIPIFY_MANIFEST} ${ALL_SRCS}
DEPENDS ${CMAKE_SOURCE_DIR}/cmake/hipify.py ${ALL_SRCS}
BYPRODUCTS ${ALL_BYPRODUCTS}
BYPRODUCTS ${ALL_BYPRODUCTS} ${HIPIFY_MANIFEST}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
VERBATIM
COMMENT "Running hipify on all extension source files.")
endfunction()

Expand Down
17 changes: 17 additions & 0 deletions docker/Dockerfile.rocm
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,23 @@ RUN --mount=type=bind,source=pyproject.toml,target=${COMMON_WORKDIR}/vllm/pyproj
&& echo "=== ccache stats after ROCm native build ===" \
&& (ccache --show-stats || true)

FROM csrc-build AS kernel-symbol-map-build
ARG VLLM_KERNEL_SYMBOL_MAP=0
ARG buildkite_commit=""
COPY tools/ci/kernel_symbol_map.py tools/ci/rocm_kernel_symbol_map.py tools/ci/
RUN if [ "${VLLM_KERNEL_SYMBOL_MAP}" = "1" ]; then \
uv venv --system-site-packages /tmp/kernel-map/.venv \
&& /tmp/kernel-map/.venv/bin/python tools/ci/kernel_symbol_map.py \
--backend rocm --build-root build --source-root . \
--commit "${buildkite_commit}" \
--out dist/kernel_symbol_map.rocm.json.gz \
&& rm -rf /tmp/kernel-map; \
fi

FROM scratch AS kernel-symbol-map-rocm
ARG COMMON_WORKDIR
COPY --from=kernel-symbol-map-build ${COMMON_WORKDIR}/vllm/dist/kernel_symbol_map.rocm.json.gz /

# Build the full vLLM ROCm wheel by reusing the native extension wheel from
# csrc-build. This stage still rebuilds for Python/package changes, but skips
# the expensive dependency installation and HIP/C++ compilation when their
Expand Down
Loading
Loading