Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into windows-bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottTodd committed Feb 6, 2025
2 parents 5c5d93a + 7ba9eba commit 90580f8
Show file tree
Hide file tree
Showing 37 changed files with 889 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_linux_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
-DTHEROCK_AMDGPU_FAMILIES=gfx110X-dgpu \
-DTHEROCK_PACKAGE_VERSION="${package_version}"
./build_tools/watch_top_processes.sh &
cmake --build build --target therock-archives
cmake --build build --target therock-archives therock-dist
kill %1
# - name: Build Tarballs
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ set(THEROCK_BACKGROUND_BUILD_JOBS "0" CACHE STRING "Number of jobs to reserve fo

set(THEROCK_PACKAGE_VERSION "git" CACHE STRING "Sets the package version string")
set(ROCM_GIT_DIR "${THEROCK_SOURCE_DIR}/sources" CACHE PATH "Directory of rocm-org repo checkout")
# Disable compatibility symlinks created in default ROCM cmake project wide
set(ROCM_SYMLINK_LIBS OFF)
message(STATUS "ROCM_GIT_DIR is set to: ${ROCM_GIT_DIR}")

set(THEROCK_ARTIFACT_ARCHIVE_SUFFIX "" CACHE STRING "Suffix to add to artifact archive file stem names")
Expand Down Expand Up @@ -144,3 +146,4 @@ endif()
# Finalization
################################################################################
therock_subproject_merge_compile_commands()
therock_create_dist()
2 changes: 1 addition & 1 deletion base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ therock_cmake_subproject_declare(rocm-cmake
EXTERNAL_SOURCE_DIR "rocm-cmake"
)
therock_cmake_subproject_provide_package(rocm-cmake
ROCmCMakeBuildToolsConfig share/rocmcmakebuildtools/cmake)
ROCmCMakeBuildTools share/rocmcmakebuildtools/cmake)
therock_cmake_subproject_provide_package(rocm-cmake
ROCM share/rocm/cmake)
therock_cmake_subproject_activate(rocm-cmake)
Expand Down
10 changes: 7 additions & 3 deletions build_tools/fetch_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ def main(argv):
"--manifest-name",
type=str,
help="Repo manifest name",
default="tools/rocm-build/rocm-6.3.1.xml",
default="default.xml",
)
parser.add_argument(
"--manifest-branch",
type=str,
help="Branch to sync with repo tool",
default="roc-6.3.x",
default="amd-mainline",
)
parser.add_argument(
"--patch-tag",
type=str,
default="rocm-6.3.1",
default="amd-mainline",
help="Patch tag to apply to sources after sync",
)
parser.add_argument(
Expand Down Expand Up @@ -198,8 +198,12 @@ def main(argv):
"hipBLAS-common",
"hipBLAS",
"hipBLASLt",
"hipSPARSE",
"rocBLAS",
"rocPRIM",
"rocRAND",
"rocSOLVER",
"rocSPARSE",
],
)
parser.add_argument(
Expand Down
33 changes: 33 additions & 0 deletions build_tools/fileset_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,23 @@ def _open_archive(p: Path, archive_type: str) -> tarfile.TarFile | zipfile.ZipFi
raise ValueError("Expected one of tar.xz, tar.gz, tar.bz2 for archive type")


def _do_artifact_flatten(args):
output_path: Path = args.o
pm = PatternMatcher()
for artifact_path in args.artifact:
manifest_path: Path = artifact_path / "artifact_manifest.txt"
relpaths = manifest_path.read_text().splitlines()
for relpath in relpaths:
if not relpath:
continue
source_dir = artifact_path / relpath
if not source_dir.exists():
continue
pm.add_basedir(source_dir)

pm.copy_to(destdir=output_path, verbose=args.verbose)


def _dup_list_or_str(v: list[str] | str) -> list[str]:
if not v:
return []
Expand Down Expand Up @@ -504,6 +521,22 @@ def run_action(args: argparse.Namespace):
)
artifact_archive_p.set_defaults(func=do_artifact_archive)

# 'artifact-flatten' command
artifact_flatten_p = sub_p.add_parser(
"artifact-flatten",
help="Flattens one or more artifact directories into one output directory",
)
artifact_flatten_p.add_argument(
"artifact", nargs="+", type=Path, help="Artifact directory"
)
artifact_flatten_p.add_argument(
"-o", type=Path, required=True, help="Output archive name"
)
artifact_flatten_p.add_argument(
"--verbose", action="store_true", help="Print verbose status"
)
artifact_flatten_p.set_defaults(func=_do_artifact_flatten)

args = p.parse_args(cl_args)
args.func(args)

Expand Down
28 changes: 14 additions & 14 deletions build_tools/save_patches.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash
# Saves patches that are maintained locally to make TheRock work with a given
# branch.
# Usage: save_patches.sh base_tag project_name
# Usage: save_patches.sh base_tag project_name patch_subdir
#
# Example:
# save_patches.sh m/amd-mainline hipBLASLt amd-mainline
#
# This will save patch files for all commits to hipBLASLt since the commit
# "m/amd-mainline". Patch files will be saved in patches/amd-mainline/hipBLASLT
#
# The base_tag must be checked out on the current branch. All commits above it
# will be dumped as patches.
set -euo pipefail

repo_dir="$(pwd)"
this_dir="$(cd $(dirname $0) && pwd)"
root_dir="$(cd $this_dir/.. && pwd)"

Expand All @@ -16,30 +22,24 @@ version_tag="$1"
shift
project_name="$1"
shift
patch_subdir="$1"
shift
set -eu

if [ -z "$version_tag" ] || [ -z "$project_name" ]; then
echo "Syntax: save_patches.sh <version_tag> <project_name>"
if [ -z "$version_tag" ] || [ -z "$project_name" ] || [ -z "$patch_subdir" ]; then
echo "Syntax: save_patches.sh <version_tag> <project_name> <patch_subdir>"
exit 1
fi

# Directories.
patch_dir="$root_dir/patches/$version_tag/$project_name"
patch_dir="$root_dir/patches/$patch_subdir/$project_name"
mkdir -p $patch_dir
source_dir="$root_dir/sources/$project_name"
if ! [ -d "$source_dir" ]; then
echo "Source directory not found: $source_dir"
exit 1
fi

# Get the most recent upstream base commit.
base_commit="$(cd $source_dir && git rev-list -1 "tags/$version_tag")"
if [ -z "$base_commit" ]; then
echo "Could not find base commit for tags/$version_tag in $source_dir"
exit 1
fi
echo "Base commit: $base_commit"

# Remove existing patch files.
for existing in $patch_dir/*.patch; do
if [ -f "$existing" ]; then
Expand All @@ -48,4 +48,4 @@ for existing in $patch_dir/*.patch; do
done

# And format.
(cd $source_dir && git format-patch -o $patch_dir "$base_commit")
(cd $source_dir && git format-patch -o $patch_dir "$version_tag")
52 changes: 45 additions & 7 deletions cmake/therock_artifacts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# Facilities for bundling artifacts for bootstrapping and subsequent CI/CD
# phases.

# Property containing all artifact directories for all components created via
# therock_provide_artifact(). This is used to populate the dist/rocm directory
# by flattening them all. In the future, we may have multiple dist groups but
# there is just this one for now.
set_property(GLOBAL PROPERTY THEROCK_DIST_ARTIFACT_DIRS)

function(therock_provide_artifact slice_name)
cmake_parse_arguments(PARSE_ARGV 1 ARG
"TARGET_NEUTRAL"
Expand Down Expand Up @@ -34,11 +40,10 @@ function(therock_provide_artifact slice_name)

# Determine top-level name.
if(ARG_TARGET_NEUTRAL)
set(_bundle_name "any")
set(_bundle_suffix "")
else()
set(_bundle_name "${THEROCK_AMDGPU_DIST_BUNDLE_NAME}")
set(_bundle_suffix "_${THEROCK_AMDGPU_DIST_BUNDLE_NAME}")
endif()
set(_artifact_base_name "${slice_name}_${_bundle_name}")

### Generate artifact directories.
# Determine dependencies.
Expand All @@ -50,7 +55,8 @@ function(therock_provide_artifact slice_name)
set(_command_list)
set(_manifest_files)
foreach(_component ${ARG_COMPONENTS})
set(_component_dir "${THEROCK_BINARY_DIR}/artifacts/${_artifact_base_name}_${_component}")
set(_component_dir "${THEROCK_BINARY_DIR}/artifacts/${slice_name}_${_component}${_bundle_suffix}")
set_property(GLOBAL APPEND PROPERTY THEROCK_DIST_ARTIFACT_DIRS "${_component_dir}")
set(_manifest_file "${_component_dir}/artifact_manifest.txt")
list(APPEND _manifest_files "${_manifest_file}")
list(APPEND _command_list
Expand Down Expand Up @@ -78,13 +84,13 @@ function(therock_provide_artifact slice_name)
)
add_dependencies(therock-artifacts "${_target_name}")

### Generate archives.
### Generate artifact archive commands.
set(_archive_files)
foreach(_component ${ARG_COMPONENTS})
foreach(_archive_type ${THEROCK_ARTIFACT_ARCHIVE_TYPES})
set(_component_dir "${THEROCK_BINARY_DIR}/artifacts/${_artifact_base_name}_${_component}")
set(_component_dir "${THEROCK_BINARY_DIR}/artifacts/${slice_name}_${_component}${_bundle_suffix}")
set(_manifest_file "${_component_dir}/artifact_manifest.txt")
set(_archive_file "${THEROCK_BINARY_DIR}/archives/${_artifact_base_name}_${_component}${THEROCK_ARTIFACT_ARCHIVE_SUFFIX}.${_archive_type}")
set(_archive_file "${THEROCK_BINARY_DIR}/artifacts/${slice_name}_${_component}${_bundle_suffix}${THEROCK_ARTIFACT_ARCHIVE_SUFFIX}.${_archive_type}")
list(APPEND _archive_files "${_archive_file}")
set(_archive_sha_file "${_archive_file}.sha256sum")
add_custom_command(
Expand All @@ -107,3 +113,35 @@ function(therock_provide_artifact slice_name)
add_custom_target("${_archive_target_name}" DEPENDS ${_archive_files})
add_dependencies(therock-archives "${_archive_target_name}")
endfunction()


function(therock_create_dist)
# Currently there is only one dist se we hard-code. These could become
# settings later.
set(_dist_dir "${THEROCK_BINARY_DIR}/dist/rocm")
set(_stamp_file "${THEROCK_BINARY_DIR}/dist/.rocm.stamp")
set(_dist_name "rocm")
get_property(_artifact_dirs GLOBAL PROPERTY THEROCK_DIST_ARTIFACT_DIRS)

set(_fileset_tool "${THEROCK_SOURCE_DIR}/build_tools/fileset_tool.py")
list(TRANSFORM _artifact_dirs APPEND "/artifact_manifest.txt" OUTPUT_VARIABLE _manifest_files)

add_custom_command(
OUTPUT "${_stamp_file}"
COMMENT "Creating dist ${_dist_dir}"
COMMAND "${Python3_EXECUTABLE}" "${_fileset_tool}" artifact-flatten --verbose
-o "${_dist_dir}" ${_artifact_dirs}
COMMAND
"${CMAKE_COMMAND}" -E touch "${_stamp_file}"
DEPENDS
"${_fileset_tool}"
${_manifest_files}
)

set(_dist_target_name "therock-dist-${_dist_name}")
add_custom_target("${_dist_target_name}" DEPENDS "${_stamp_file}")
if(NOT TARGET therock-dist)
add_custom_target(therock-dist)
endif()
add_dependencies(therock-dist "${_dist_target_name}")
endfunction()
26 changes: 21 additions & 5 deletions cmake/therock_subproject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set_property(GLOBAL PROPERTY THEROCK_DEFAULT_CMAKE_VARS
THEROCK_SOURCE_DIR
THEROCK_BINARY_DIR
ROCM_GIT_DIR
ROCM_SYMLINK_LIBS
)

set_property(GLOBAL PROPERTY THEROCK_SUBPROJECT_COMPILE_COMMANDS_FILES)
Expand Down Expand Up @@ -755,10 +756,23 @@ function(_therock_cmake_subproject_setup_toolchain compiler_toolchain toolchain_
if(NOT compiler_toolchain)
# Make any additional customizations if no toolchain specified.
elseif(compiler_toolchain STREQUAL "amd-llvm" OR compiler_toolchain STREQUAL "amd-hip")
# amd-llvm toolchain: The private built LLVM in isolation.
_therock_assert_is_cmake_subproject("amd-llvm")
get_target_property(_amd_llvm_dist_dir amd-llvm THEROCK_DIST_DIR)
get_target_property(_amd_llvm_stamp_dir amd-llvm THEROCK_STAMP_DIR)
# The "amd-llvm" and "amd-hip" toolchains are configured very similarly so
# we commingle them, but they are different:
# "amd-llvm": Just the base LLVM compiler and device libraries. This
# doesn't know anything about hip (i.e. it doesn't have hipconfig, etc).
# "amd-hip": Superset of "amd-llvm" which also includes hipcc, hip headers,
# and hip version info. This has hipconfig in it.
# The main difference is that for "amd-llvm", we derive the configuration from
# the amd-llvm project's dist/ tree. And for "amd-hip", from the hip-clr
# project (which has runtime dependencies on the underlying toolchain).
if (compiler_toolchain STREQUAL "amd-hip")
set(_toolchain_subproject "hip-clr")
else()
set(_toolchain_subproject "amd-llvm")
endif()
_therock_assert_is_cmake_subproject("${_toolchain_subproject}")
get_target_property(_amd_llvm_dist_dir "${_toolchain_subproject}" THEROCK_DIST_DIR)
get_target_property(_amd_llvm_stamp_dir "${_toolchain_subproject}" THEROCK_STAMP_DIR)
# Add a dependency on the toolchain's dist
set(AMD_LLVM_C_COMPILER "${_amd_llvm_dist_dir}/lib/llvm/bin/clang")
set(AMD_LLVM_CXX_COMPILER "${_amd_llvm_dist_dir}/lib/llvm/bin/clang++")
Expand All @@ -770,15 +784,17 @@ function(_therock_cmake_subproject_setup_toolchain compiler_toolchain toolchain_
string(APPEND _toolchain_contents "set(CMAKE_C_COMPILER @AMD_LLVM_C_COMPILER@)\n")
string(APPEND _toolchain_contents "set(CMAKE_CXX_COMPILER @AMD_LLVM_CXX_COMPILER@)\n")
string(APPEND _toolchain_contents "set(CMAKE_LINKER @AMD_LLVM_LINKER@)\n")
# TODO: AMDGPU_TARGETS is being deprecated. For now we set both.
string(APPEND _toolchain_contents "set(AMDGPU_TARGETS @THEROCK_AMDGPU_TARGETS@ CACHE STRING \"From super-project\" FORCE)\n")
string(APPEND _toolchain_contents "set(GPU_TARGETS @THEROCK_AMDGPU_TARGETS@ CACHE STRING \"From super-project\" FORCE)\n")
string(APPEND _toolchain_contents "string(APPEND CMAKE_CXX_FLAGS_INIT \" ${_amd_llvm_cxx_flags_spaces}\")\n")

message(STATUS "Compiler toolchain ${compiler_toolchain}:")
string(APPEND CMAKE_MESSAGE_INDENT " ")
message(STATUS "CMAKE_C_COMPILER = ${AMD_LLVM_C_COMPILER}")
message(STATUS "CMAKE_CXX_COMPILER = ${AMD_LLVM_CXX_COMPILER}")
message(STATUS "CMAKE_LINKER = ${AMD_LLVM_LINKER}")
message(STATUS "AMDGPU_TARGETS = ${THEROCK_AMDGPU_TARGETS_SPACES}")
message(STATUS "GPU_TARGETS = ${THEROCK_AMDGPU_TARGETS_SPACES}")
else()
message(FATAL_ERROR "Unsupported COMPILER_TOOLCHAIN = ${compiler_toolchain} (supported: 'amd-llvm' or none)")
endif()
Expand Down
3 changes: 3 additions & 0 deletions comm-libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ if(THEROCK_ENABLE_RCCL)
-DROCM_PATH=
-DROCM_DIR=
"-DEXPLICIT_ROCM_VERSION=${ROCM_MAJOR_VERSION}.${ROCM_MINOR_VERSION}.${ROCM_PATCH_VERSION}"
# TODO(#56): Enable once reworked.
-DENABLE_MSCCLPP=OFF
-DENABLE_MSCCL_KERNEL=OFF
COMPILER_TOOLCHAIN
amd-hip
IGNORE_PACKAGES
Expand Down
Loading

0 comments on commit 90580f8

Please sign in to comment.