Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 94 additions & 2 deletions third-party/host-blas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
TOUCH "${_download_stamp}"
)

# Download sources again to a different directory for ILP64 variant
set(_source_dir_64 "${CMAKE_CURRENT_BINARY_DIR}/source64")
set(_download_stamp_64 "${_source_dir_64}/download.stamp")

therock_subproject_fetch(therock-OpenBLAS64-sources
CMAKE_PROJECT
SOURCE_DIR "${_source_dir_64}"
URL https://rocm-third-party-deps.s3.us-east-2.amazonaws.com/OpenBLAS-0.3.30.tar.gz
URL_HASH SHA256=27342cff518646afb4c2b976d809102e368957974c250a25ccc965e53063c95d
TOUCH "${_download_stamp_64}"
)

# MSVC does not support VLA and AT&T assembly which are required by DYNAMIC_ARCH
# See: https://github.com/OpenMathLib/OpenBLAS/issues/2826#issuecomment-814170090
# Multi-arch support on Windows seems to be a problem not limited to MSVC
Expand Down Expand Up @@ -84,6 +96,61 @@ if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
run
SUBPROJECT_DEPS therock-host-blas
)

# --------------------------------------------------------------------------
# ILP64 (INTERFACE64) variant of OpenBLAS
# Builds a second copy with 64-bit integer interfaces. This is kept fully
# separate via a dedicated sub-project and artifact publication. We rely on
# upstream OpenBLAS CMake variables: INTERFACE64 triggers ILP64, producing
# an "OpenBLAS64" package directory (cmake/OpenBLAS64) and a libopenblas_64.so
# which we rename to librocm-openblas64.so for ROCm.
# --------------------------------------------------------------------------
therock_cmake_subproject_declare(therock-host-blas64
BACKGROUND_BUILD
EXCLUDE_FROM_ALL
NO_MERGE_COMPILE_COMMANDS
OUTPUT_ON_FAILURE
EXTERNAL_SOURCE_DIR .
INTERFACE_LINK_DIRS "lib/host-math/lib"
# RPATH logic needs to know that executables/libs for this project are in
# a non-default location.
INSTALL_RPATH_EXECUTABLE_DIR "lib/host-math/bin"
INSTALL_RPATH_LIBRARY_DIR "lib/host-math/lib"
INTERFACE_INSTALL_RPATH_DIRS "lib/host-math/lib"
CMAKE_ARGS
"-DSOURCE_DIR=${_source_dir_64}"
-DBUILD_SHARED_LIBS=ON
-DC_LAPACK=ON
# https://github.com/OpenMathLib/OpenBLAS?tab=readme-ov-file#x86x86-64
# Picking HASWELL as a baseline that supports modern AMD and Intel CPUs
-DTARGET=HASWELL
-DDYNAMIC_ARCH=${_enable_dynamicArch}
-DBUILD_TESTING=OFF
-DINTERFACE64=ON
EXTRA_DEPENDS
"${_download_stamp_64}"
)
therock_cmake_subproject_provide_package(therock-host-blas64 OpenBLAS64 lib/host-math/lib/cmake/OpenBLAS64)
therock_cmake_subproject_provide_package(therock-host-blas64 cblas64 lib/host-math/lib/cmake/OpenBLAS64)
therock_cmake_subproject_activate(therock-host-blas64)

therock_test_validate_shared_lib(
PATH dist/lib/host-math/lib
LIB_NAMES librocm-openblas64.so
)

therock_provide_artifact(host-blas64
DESCRIPTOR artifact-host-OpenBLAS.toml
TARGET_NEUTRAL
COMPONENTS
dbg
dev
doc
lib
run
SUBPROJECT_DEPS therock-host-blas64
)

return()
endif()

Expand All @@ -110,9 +177,7 @@ add_subdirectory(${SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-openblas)
# name.
# TODO: Also set Linux symbol versioning flags.
set_target_properties(openblas_shared PROPERTIES
# Private SONAME/DLL name.
OUTPUT_NAME rocm-openblas
# Install location in the library is hard-coded to include in the install root.
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/openblas>
)

Expand All @@ -127,3 +192,30 @@ configure_file(
@ONLY
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cblas-config.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenBLAS)

# --------------------------------------------------------------------------
# Build ILP64 (64-bit integer interface) variant
# --------------------------------------------------------------------------
add_subdirectory(${SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/build-openblas64)

# Alterations.
# We would like this to be a library scoped to ROCm, so give it a custom
# name.
# TODO: Also set Linux symbol versioning flags.
set_target_properties(openblas64_shared PROPERTIES
OUTPUT_NAME rocm-openblas64
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/openblas64>
)

# Some of the test targets do not build with an altered library name on
# Windows. Just uniformly exclude them from the build.
set_target_properties(openblas_utest PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(openblas_utest_ext PROPERTIES EXCLUDE_FROM_ALL TRUE)

# Install cblas64-config.cmake to OpenBLAS64 cmake directory
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cblas64-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cblas64-config.cmake
@ONLY
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cblas64-config.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenBLAS64)
7 changes: 7 additions & 0 deletions third-party/host-blas/cblas64-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CBLAS interface for ILP64 OpenBLAS build.
if(NOT TARGET cblas64)
find_package(OpenBLAS64 REQUIRED)
add_library(cblas64 INTERFACE)
target_link_libraries(cblas64 INTERFACE OpenBLAS64::OpenBLAS)
set(CBLAS64_LIBRARIES cblas64)
endif()
Loading