Skip to content
Open
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
69 changes: 41 additions & 28 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
-G Ninja
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_UNITY_BUILD=${{ matrix.build_type == 'Debug' || matrix.valgrind }}
-DTAPP_REFERENCE_ENABLE_TBLIS=ON
-DTAPP_REFERENCE_ENABLE_TBLIS=${{ !matrix.valgrind }}
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -81,14 +81,6 @@ jobs:
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{github.workspace}}/build

- name: Set sanitizer flags
if: ${{ matrix.sanitize }}
shell: bash
run: |
if [[ '${{ matrix.sanitize }}' = 'true' ]]; then
echo "CXXFLAGS=${{ matrix.sanitize_flags }}" >> "$GITHUB_ENV"
fi

- name: Install prerequisite MacOS packages
if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install ninja ccache
Expand All @@ -112,14 +104,19 @@ jobs:
restore-keys: |
${{ matrix.config.name }}-ccache-
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE $BUILD_CONFIG
# Pass sanitizer flags via CMAKE_{C,CXX}_FLAGS (not CFLAGS/CXXFLAGS env vars)
# to prevent them from leaking into BLIS's autotools build via the environment
run: |
cmake_args=($BUILD_CONFIG)
if [[ "${{ matrix.sanitize }}" == "true" ]]; then
cmake_args+=(
"-DCMAKE_C_FLAGS=${{ matrix.sanitize_flags }}"
"-DCMAKE_CXX_FLAGS=${{ matrix.sanitize_flags }}"
)
fi
cmake $GITHUB_WORKSPACE "${cmake_args[@]}"


- name: Build
Expand All @@ -139,16 +136,32 @@ jobs:
working-directory: ${{github.workspace}}/build
shell: bash
run: |
cat > tblis.supp << 'EOF'
# Suppress uninitialized value errors in TBLIS/BLIS packm functions
# These occur in architecture-specific packing code (zen3, haswell, etc.)
# and appear to be false positives in the BLIS library
{
tblis_packm_bsmtc_uninit
Memcheck:Cond
...
fun:*tblis*packm*bsmtc*
...
}
EOF
valgrind --error-exitcode=1 --leak-check=full --suppressions=tblis.supp ./tapp-reference-test++
valgrind --error-exitcode=1 --leak-check=full ./tapp-reference-demo
valgrind --error-exitcode=1 --leak-check=full ./tapp-reference-driver

- name: Consume from build tree
if: ${{ !matrix.valgrind && !matrix.sanitize }}
shell: bash
run: |
cmake -S $GITHUB_WORKSPACE/test/consume -B ${{github.workspace}}/consume-build \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-Dtapp_DIR=${{github.workspace}}/build
cmake --build ${{github.workspace}}/consume-build
ctest --test-dir ${{github.workspace}}/consume-build --output-on-failure

- name: Install
if: ${{ !matrix.valgrind && !matrix.sanitize }}
shell: bash
run: cmake --install ${{github.workspace}}/build --prefix ${{github.workspace}}/install

- name: Consume from install tree
if: ${{ !matrix.valgrind && !matrix.sanitize }}
shell: bash
run: |
cmake -S $GITHUB_WORKSPACE/test/consume -B ${{github.workspace}}/consume-install \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_PREFIX_PATH=${{github.workspace}}/install
cmake --build ${{github.workspace}}/consume-install
ctest --test-dir ${{github.workspace}}/consume-install --output-on-failure
202 changes: 74 additions & 128 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,160 +3,73 @@ cmake_minimum_required(VERSION 3.15)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable verbose output")

# see https://semver.org/
set (TAPP_REFERENCE_MAJOR_VERSION 0)
set (TAPP_REFERENCE_MINOR_VERSION 5)
set (TAPP_REFERENCE_PATCH_VERSION 0)
set (TAPP_REFERENCE_PRERELEASE_ID )
set (TAPP_REFERENCE_BUILD_ID )

set(TAPP_REFERENCE_VERSION "${TAPP_REFERENCE_MAJOR_VERSION}.${TAPP_REFERENCE_MINOR_VERSION}.${TAPP_REFERENCE_PATCH_VERSION}")
if (TAPP_REFERENCE_PRERELEASE_ID)
set(TAPP_REFERENCE_EXT_VERSION "${TAPP_REFERENCE_VERSION}-${TAPP_REFERENCE_PRERELEASE_ID}")
else(TAPP_REFERENCE_PRERELEASE_ID)
set(TAPP_REFERENCE_EXT_VERSION "${TAPP_REFERENCE_VERSION}")
endif(TAPP_REFERENCE_PRERELEASE_ID)
if (TAPP_REFERENCE_BUILD_ID)
set(TAPP_REFERENCE_EXT_VERSION "${TAPP_REFERENCE_EXT_VERSION}+${TAPP_REFERENCE_BUILD_ID}")
endif(TAPP_REFERENCE_BUILD_ID)
set (TAPP_MAJOR_VERSION 0)
set (TAPP_MINOR_VERSION 5)
set (TAPP_PATCH_VERSION 0)
set (TAPP_PRERELEASE_ID )
set (TAPP_BUILD_ID )

set(TAPP_VERSION "${TAPP_MAJOR_VERSION}.${TAPP_MINOR_VERSION}.${TAPP_PATCH_VERSION}")
if (TAPP_PRERELEASE_ID)
set(TAPP_EXT_VERSION "${TAPP_VERSION}-${TAPP_PRERELEASE_ID}")
else(TAPP_PRERELEASE_ID)
set(TAPP_EXT_VERSION "${TAPP_VERSION}")
endif(TAPP_PRERELEASE_ID)
if (TAPP_BUILD_ID)
set(TAPP_EXT_VERSION "${TAPP_EXT_VERSION}+${TAPP_BUILD_ID}")
endif(TAPP_BUILD_ID)

# Extract the git revision tag information
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse -q HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE TAPP_REFERENCE_REVISION )
OUTPUT_VARIABLE TAPP_REVISION )
string(REGEX MATCH "[0-9a-f]*"
TAPP_REFERENCE_REVISION "${TAPP_REFERENCE_REVISION}")
TAPP_REVISION "${TAPP_REVISION}")
else()
set(TAPP_REFERENCE_REVISION "unknown")
set(TAPP_REVISION "unknown")
endif()

project(tapp-reference
VERSION ${TAPP_REFERENCE_VERSION}
DESCRIPTION "Reference Implementation of TAPP (Tensor Algebra Processing Primitives)"
project(tapp
VERSION ${TAPP_VERSION}
DESCRIPTION "TAPP (Tensor Algebra Processing Primitives)"
LANGUAGES C
HOMEPAGE_URL "https://github.com/TAPPOrg/")

include(GNUInstallDirs)

set(TAPP_REFERENCE_INSTALL_BINDIR "bin"
CACHE PATH "TAPP REFERENCE binary install directory")
set(TAPP_REFERENCE_INSTALL_INCLUDEDIR "include"
CACHE PATH "TAPP REFERENCE INCLUDE install directory")
set(TAPP_REFERENCE_INSTALL_LIBDIR "lib"
CACHE PATH "TAPP REFERENCE LIB install directory")
set(TAPP_REFERENCE_INSTALL_DATADIR "share/mpqc/${TAPP_REFERENCE_EXT_VERSION}/data"
CACHE PATH "TAPP REFERENCE DATA install directory")
set(TAPP_REFERENCE_INSTALL_DOCDIR "share/tapp/${TAPP_REFERENCE_EXT_VERSION}/doc"
CACHE PATH "TAPP REFERENCE DOC install directory")
set(TAPP_REFERENCE_INSTALL_CMAKEDIR "lib/cmake/mpqc"
CACHE PATH "TAPP REFERENCE CMAKE install directory")

# this provides tapp-api target
add_subdirectory(api)

add_library(tapp-reference SHARED)

target_sources(
tapp-reference
PRIVATE
reference_implementation/include/ref_impl.h
reference_implementation/src/error.c
reference_implementation/src/executor.c
reference_implementation/src/handle.c
reference_implementation/src/tensor.c
reference_implementation/src/product.c
)

set_property(
TARGET tapp-reference
PROPERTY
C_STANDARD 99
C_STANDARD_REQUIRED YES
C_EXTENSIONS NO
)

target_include_directories(
tapp-reference
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/reference_implementation/include
)
if (APPLE AND CMAKE_C_COMPILER_ID MATCHES "^(Clang|AppleClang)$")
target_link_options(tapp-reference PRIVATE "-undefined;dynamic_lookup")
endif()

target_link_libraries(tapp-reference PUBLIC tapp-api)

# TBLIS requires CXX; enable_language must be called at the top level
option(TAPP_REFERENCE_ENABLE_TBLIS "Build and link TBLIS and TBLIS bindings" OFF)
option(TAPP_REFERENCE_BUILD_EXERCISE "Build contraction exercise with TODOs in it." OFF)

option(TAPP_REFERENCE_ENABLE_F16 "Turn on F16 support" OFF)
option(TAPP_REFERENCE_ENABLE_BF16 "Turn on BF16 support" OFF)

if(TAPP_REFERENCE_ENABLE_F16)
target_compile_definitions(tapp-reference PRIVATE TAPP_REFERENCE_ENABLE_F16=1)
endif()

if(TAPP_REFERENCE_ENABLE_BF16)
target_compile_definitions(tapp-reference PRIVATE TAPP_REFERENCE_ENABLE_BF16=1)
endif()

if(TAPP_REFERENCE_ENABLE_TBLIS)

include(CheckLanguage)
check_language(CXX)
if(CMAKE_CXX_COMPILER)
enable_language(CXX)
else()
message(FATAL_ERROR "Cannot build TBLIS as part of TAPP due to missing CXX language support; ensure that the CXX compiler can be discovered")
endif()
endif()

set(TBLIS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/tblis)

include(FetchContent)

FetchContent_Declare(
tblis
GIT_REPOSITORY https://github.com/devinamatthews/tblis.git
GIT_TAG 9b95712
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_deps/tblis
UPDATE_DISCONNECTED TRUE
)

FetchContent_MakeAvailable(tblis)

target_compile_definitions(tapp-reference PRIVATE TAPP_REFERENCE_ENABLE_TBLIS=1)

target_sources(
tapp-reference
PRIVATE
tblis_bindings/tblis_bind.h
tblis_bindings/tblis_bind.cpp
)
set_property(
TARGET tapp-reference
PROPERTY
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)
target_include_directories(
tapp-reference
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/tblis_bindings
)
include(GNUInstallDirs)

# ----------------------------------------------------------------------------
# interface
set(TAPP_INSTALL_BINDIR "bin"
CACHE PATH "TAPP binary install directory")
set(TAPP_INSTALL_INCLUDEDIR "include"
CACHE PATH "TAPP include install directory")
set(TAPP_INSTALL_LIBDIR "lib"
CACHE PATH "TAPP library install directory")
set(TAPP_INSTALL_CMAKEDIR "lib/cmake/tapp"
CACHE PATH "TAPP CMake config install directory")
set(TAPP_INSTALL_DATADIR "share/tapp/${TAPP_EXT_VERSION}/data"
CACHE PATH "TAPP data install directory")
set(TAPP_INSTALL_DOCDIR "share/tapp/${TAPP_EXT_VERSION}/doc"
CACHE PATH "TAPP doc install directory")

target_link_libraries(
tapp-reference
PUBLIC
tblis-static
)
# this provides tapp-api target
add_subdirectory(api)

endif()
# this provides tapp-reference target
add_subdirectory(reference_implementation)

# ----------------------------------------------------------------------------
# testing
Expand All @@ -182,6 +95,7 @@ if(BUILD_TESTING)
tapp-reference-test++
PRIVATE
tapp-reference
tblis-static
)

set_property(
Expand Down Expand Up @@ -255,7 +169,7 @@ if(BUILD_TESTING)
# ----------------------------------------------------------------------------
# exercise: contraction

if(TAPP_REFERENCE_BUILD_EXERCISE)
if(TAPP_BUILD_EXERCISE)
add_executable(tapp-reference-exercise_contraction)

target_sources(
Expand Down Expand Up @@ -353,3 +267,35 @@ if(BUILD_TESTING)
)

endif()

# ============================================================================
# CMake package config / export
# ============================================================================
include(CMakePackageConfigHelpers)

# version file
write_basic_package_version_file(tapp-config-version.cmake
VERSION ${TAPP_VERSION} COMPATIBILITY AnyNewerVersion)

# export targets for the build tree
export(EXPORT tapp
NAMESPACE tapp::
FILE "${PROJECT_BINARY_DIR}/tapp-targets.cmake")

# install target export file
install(EXPORT tapp
FILE "tapp-targets.cmake"
DESTINATION "${TAPP_INSTALL_CMAKEDIR}"
NAMESPACE tapp::
COMPONENT reference)

# configure the config file
configure_package_config_file(cmake/tapp-config.cmake.in
"${PROJECT_BINARY_DIR}/tapp-config.cmake"
INSTALL_DESTINATION "${TAPP_INSTALL_CMAKEDIR}")

install(FILES
"${PROJECT_BINARY_DIR}/tapp-config.cmake"
"${PROJECT_BINARY_DIR}/tapp-config-version.cmake"
DESTINATION "${TAPP_INSTALL_CMAKEDIR}"
COMPONENT reference)
Loading
Loading