Skip to content

Commit

Permalink
Merge pull request #94 from tud-zih-energy/marenz.test-payload-genera…
Browse files Browse the repository at this point in the history
…tion

Infrastructure for Reference Tests
  • Loading branch information
marenz2569 authored Dec 9, 2024
2 parents 3791fb7 + 53b6705 commit ca08f20
Show file tree
Hide file tree
Showing 38 changed files with 2,182 additions and 389 deletions.
397 changes: 191 additions & 206 deletions .github/workflows/cmake.yml

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions .github/workflows/ctest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: ctest

on: [push, pull_request]

env:
PYTHONUNBUFFERED: 1

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: 'true'

- name: Install python3
run: |
sudo apt update
sudo apt install python3
- name: Create build directory
run: |
mkdir build
- name: Run CMake configure (default)
run: |
cd build
cmake ..
- name: Build
run: |
cd build
make -j4
- name: Ctest
run: |
cd build
ctest
41 changes: 7 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.22)
project(FIRESTARTER)
enable_testing()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)

include(cmake/GitSubmoduleUpdate.cmake)

Expand Down Expand Up @@ -55,41 +57,10 @@ endif()
include(cmake/GitSubmoduleUpdate.cmake)
git_submodule_update()

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2 -fdata-sections -ffunction-sections")
endif()
include(cmake/BuildOptions.cmake)
include(cmake/BuildSettings.cmake)

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
else()
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
endif()

# enable debug features on linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
option(FIRESTARTER_DEBUG_FEATURES "Enable debug features" ON)
if (FIRESTARTER_DEBUG_FEATURES)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_DEBUG_FEATURES")
endif()
endif()

set(FIRESTARTER_BUILD_TYPE "FIRESTARTER" CACHE STRING "FIRESTARTER_BUILD_TYPE can be any of FIRESTARTER, FIRESTARTER_CUDA, FIRESTARTER_ONEAPI, or FIRESTARTER_HIP.")
set_property(CACHE FIRESTARTER_BUILD_TYPE PROPERTY STRINGS FIRESTARTER FIRESTARTER_CUDA FIRESTARTER_ONEAPI)
if (${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER")
option(FIRESTARTER_LINK_STATIC "Link FIRESTARTER as a static binary. Note, dlopen is not supported in static binaries. This option is not available on macOS or with CUDA or OneAPI enabled." ON)
endif()
if (${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER")
option(FIRESTARTER_BUILD_HWLOC "Build hwloc dependency." ON)
elseif(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER_CUDA")
option(FIRESTARTER_BUILD_HWLOC "Build hwloc dependency." ON)
elseif(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER_ONEAPI")
option(FIRESTARTER_BUILD_HWLOC "Build hwloc dependency." ON)
elseif(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER_HIP")
option(FIRESTARTER_BUILD_HWLOC "Build hwloc dependency." ON)
endif()
option(FIRESTARTER_THREAD_AFFINITY "Enable FIRESTARTER to set affinity to hardware threads." ON)
include(cmake/DarwinBuild.cmake)

if(NOT DEFINED ASMJIT_STATIC)
set(ASMJIT_STATIC TRUE)
Expand All @@ -111,3 +82,5 @@ find_package(Threads REQUIRED)
include(cmake/InstallHwloc.cmake)

add_subdirectory(src)

add_subdirectory(test)
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ CMake option | Description
`FIRESTARTER_BUILD_HWLOC` | Build hwloc dependency. Default `ON`
`FIRESTARTER_THREAD_AFFINITY` | Enable FIRESTARTER to set affinity to hardware threads. Default `ON`

When building `FIRESTARTER_ONEAPI` make sure that the Intel Math Kernel Library (MKL) and the complier `icx` can be found. These will be used to build `FIRESTARTER`, while dependencies will be build with `$CC` and `$CXX` respectively.
When building `FIRESTARTER_ONEAPI` make sure that the Intel Math Kernel
Library (MKL) and the compiler `icx` and `icpx` can be found. Please provide
them through the `CC` and `CXX` environment variables.

When building `FIRESTARTER_HIP` make sure that the compiler `hipcc` can be
found. Please provide it through the `CC` and `CXX` environment variables.

## Metrics

Expand Down
26 changes: 26 additions & 0 deletions cmake/BuildOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include(CMakeDependentOption)

# Set the different available FIRESTARTER builds.
set(FIRESTARTER_BUILD_TYPE "FIRESTARTER" CACHE STRING "FIRESTARTER_BUILD_TYPE can be any of FIRESTARTER, FIRESTARTER_CUDA, FIRESTARTER_ONEAPI, or FIRESTARTER_HIP.")
set_property(CACHE FIRESTARTER_BUILD_TYPE PROPERTY STRINGS FIRESTARTER FIRESTARTER_CUDA FIRESTARTER_ONEAPI FIRESTARTER_HIP)

# Static linking is not supported with GPU devices or MacOS.
if(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER" AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(FIRESTARTER_LINK_STATIC "Link FIRESTARTER as a static binary. Note, dlopen is not supported in static binaries. This option is not available on macOS or with CUDA, OneAPI or HIP enabled." ON)
endif()


# We vendor hwloc per default.
option(FIRESTARTER_BUILD_HWLOC "Build hwloc dependency." ON)


# Use of thread affinity is enabled on linux per default.
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(FIRESTARTER_THREAD_AFFINITY "Enable FIRESTARTER to set affinity to hardware threads." ON)
endif()


# Debug feature are enabled on linux per default.
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(FIRESTARTER_DEBUG_FEATURES "Enable debug features" ON)
endif()
69 changes: 69 additions & 0 deletions cmake/BuildSettings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Dependent Linux features
if(FIRESTARTER_LINK_STATIC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_LINK_STATIC")
endif()

if (FIRESTARTER_DEBUG_FEATURES)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_DEBUG_FEATURES")
endif()

if (FIRESTARTER_THREAD_AFFINITY)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_THREAD_AFFINITY")
endif()


# Not MSVC
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2 -fdata-sections -ffunction-sections")
endif()


# Darwin
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dead_strip")
endif()


# Not (Darwin or MSVC)
# equivalent to Linux and Windows with mingw
if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"))
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
endif()


# Linux
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# enable position independant code on linux
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()


# Find packages, set the compiler and compile flags specific to the selected FIRESTARTER build.
if(${FIRESTARTER_BUILD_TYPE} STREQUAL "FIRESTARTER")
# No specific compiler selected
elseif ("${FIRESTARTER_BUILD_TYPE}" STREQUAL "FIRESTARTER_CUDA")
find_package(CUDAToolkit REQUIRED)
include_directories(${CUDAToolkit_INCLUDE_DIRS})

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_BUILD_CUDA")
elseif ("${FIRESTARTER_BUILD_TYPE}" STREQUAL "FIRESTARTER_ONEAPI")
find_program(ICX_PATH icx REQUIRED)

message(STATUS "Path of icx executable is: ${ICX_PATH}")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -DFIRESTARTER_BUILD_ONEAPI")
elseif("${FIRESTARTER_BUILD_TYPE}" STREQUAL "FIRESTARTER_HIP")
if (NOT DEFINED ROCM_PATH )
set ( ROCM_PATH "/opt/rocm" CACHE STRING "Default ROCM installation directory." )
endif ()

# Search for rocm in common locations
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/hip ${ROCM_PATH}/lib ${ROCM_PATH})
find_package(HIP REQUIRED)
find_package(rocblas REQUIRED)
find_package(rocrand REQUIRED)
find_package(hiprand REQUIRED)
find_package(hipblas REQUIRED)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFIRESTARTER_BUILD_HIP")
endif()
18 changes: 18 additions & 0 deletions cmake/DarwinBuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
find_library( IOKIT_LIBRARY IOKit )
endif()

# Function to link against the correct libraries on darwin
function(target_link_libraries_darwin)
set(oneValueArgs NAME)
cmake_parse_arguments(TARGET "" "${oneValueArgs}"
"" ${ARGN} )

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(${TARGET_NAME}
${COREFOUNDATION_LIBRARY}
${IOKIT_LIBRARY}
)
endif()
endfunction()
4 changes: 4 additions & 0 deletions cmake/InstallHwloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (FIRESTARTER_BUILD_HWLOC)
BUILD_IN_SOURCE 1
BUILD_COMMAND make -j
INSTALL_COMMAND make install
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/libhwloc.a
)

SET(HWLOC_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lib/Hwloc/install")
Expand All @@ -36,6 +37,7 @@ if (FIRESTARTER_BUILD_HWLOC)
CONFIGURE_COMMAND ""
BUILD_COMMAND cd <SOURCE_DIR>\\contrib\\windows && MSBuild /p:Configuration=Release /p:Platform=x64 hwloc.sln
INSTALL_COMMAND ""
BUILD_BYPRODUCTS <SOURCE_DIR>/contrib/windows/x64/Release/libhwloc.lib
)

SET(HWLOC_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lib/Hwloc/sources")
Expand All @@ -55,6 +57,7 @@ if (FIRESTARTER_BUILD_HWLOC)
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_BYPRODUCTS <SOURCE_DIR>/lib/libhwloc.a
)

SET(HWLOC_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lib/Hwloc/sources")
Expand All @@ -66,4 +69,5 @@ if (FIRESTARTER_BUILD_HWLOC)
endif()

include_directories(${HWLOC_INCLUDE_DIR}/include)
add_dependencies(hwloc HwlocInstall)
endif()
18 changes: 6 additions & 12 deletions include/firestarter/Cuda/CudaHipCompat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,6 @@ auto getErrorString(CUresult Result) -> const char* {
accellSafeCall(cuGetErrorName(Result, &ErrorString), __FILE__, __LINE__);
return ErrorString;
}
#else
// define types to not run into compile errors with if constexpr

enum class CUresult {};
// NOLINTBEGIN(readability-identifier-naming)
constexpr const int CUDA_SUCCESS = 0;
// NOLINTEND(readability-identifier-naming)
#endif

template <typename T> void accellSafeCall(T TVal, const char* File, const int Line, std::optional<int> DeviceIndex) {
Expand All @@ -368,14 +361,15 @@ template <typename T> void accellSafeCall(T TVal, const char* File, const int Li
if (TVal == RandStatusT::RAND_STATUS_SUCCESS) {
return;
}
} else if constexpr (std::is_same_v<T, CUresult>) {
#ifndef FIRESTARTER_BUILD_CUDA
static_assert(false, "Tried to call accellSafeCall with CUresult, but not building for CUDA.");
#endif
}
#ifdef FIRESTARTER_BUILD_CUDA
else if constexpr (std::is_same_v<T, CUresult>) {
if (TVal == CUDA_SUCCESS) {
return;
}
} else {
}
#endif
else {
assert(false && "Tried to call accellSafeCall with an unknown type.");
}

Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/Environment/Environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class Environment {
virtual void printSelectedCodePathSummary() = 0;

/// Print a list of available high-load function and if they are available on the current system.
virtual void printFunctionSummary() = 0;
/// \arg ForceYes Force all functions to be shown as avaialable
virtual void printFunctionSummary(bool ForceYes) = 0;

/// Get the number of threads FIRESTARTER will run with.
[[nodiscard]] auto requestedNumThreads() const -> uint64_t { return RequestedNumThreads; }
Expand Down
5 changes: 3 additions & 2 deletions include/firestarter/Environment/Payload/Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ class Payload {
/// compiled payload.
/// \arg ErrorDetection Should the code to support error detection between thread be baked into the high load routine
/// of the compiled payload.
/// \arg PrintAssembler Should the generated assembler code be logged.
/// \returns The compiled payload that provides access to the init and load functions.
[[nodiscard]] virtual auto compilePayload(const PayloadSettings& Settings, bool DumpRegisters,
bool ErrorDetection) const -> CompiledPayload::UniquePtr = 0;
[[nodiscard]] virtual auto compilePayload(const PayloadSettings& Settings, bool DumpRegisters, bool ErrorDetection,
bool PrintAssembler) const -> CompiledPayload::UniquePtr = 0;

/// Get the available instruction items that are supported by this payload.
/// \returns The available instruction items that are supported by this payload.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class AVX512Payload final : public X86Payload {
/// compiled payload.
/// \arg ErrorDetection Should the code to support error detection between thread be baked into the high load routine
/// of the compiled payload.
/// \arg PrintAssembler Should the generated assembler code be logged.
/// \returns The compiled payload that provides access to the init and load functions.
[[nodiscard]] auto compilePayload(const environment::payload::PayloadSettings& Settings, bool DumpRegisters,
bool ErrorDetection) const
bool ErrorDetection, bool PrintAssembler) const
-> environment::payload::CompiledPayload::UniquePtr override;

private:
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/Environment/X86/Payload/AVXPayload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class AVXPayload final : public X86Payload {
/// compiled payload.
/// \arg ErrorDetection Should the code to support error detection between thread be baked into the high load routine
/// of the compiled payload.
/// \arg PrintAssembler Should the generated assembler code be logged.
/// \returns The compiled payload that provides access to the init and load functions.
[[nodiscard]] auto compilePayload(const environment::payload::PayloadSettings& Settings, bool DumpRegisters,
bool ErrorDetection) const
bool ErrorDetection, bool PrintAssembler) const
-> environment::payload::CompiledPayload::UniquePtr override;

private:
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/Environment/X86/Payload/FMA4Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class FMA4Payload final : public X86Payload {
/// compiled payload.
/// \arg ErrorDetection Should the code to support error detection between thread be baked into the high load routine
/// of the compiled payload.
/// \arg PrintAssembler Should the generated assembler code be logged.
/// \returns The compiled payload that provides access to the init and load functions.
[[nodiscard]] auto compilePayload(const environment::payload::PayloadSettings& Settings, bool DumpRegisters,
bool ErrorDetection) const
bool ErrorDetection, bool PrintAssembler) const
-> environment::payload::CompiledPayload::UniquePtr override;

private:
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/Environment/X86/Payload/FMAPayload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ class FMAPayload final : public X86Payload {
/// compiled payload.
/// \arg ErrorDetection Should the code to support error detection between thread be baked into the high load routine
/// of the compiled payload.
/// \arg PrintAssembler Should the generated assembler code be logged.
/// \returns The compiled payload that provides access to the init and load functions.
[[nodiscard]] auto compilePayload(const environment::payload::PayloadSettings& Settings, bool DumpRegisters,
bool ErrorDetection) const
bool ErrorDetection, bool PrintAssembler) const
-> environment::payload::CompiledPayload::UniquePtr override;

private:
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/Environment/X86/Payload/SSE2Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class SSE2Payload final : public X86Payload {
/// compiled payload.
/// \arg ErrorDetection Should the code to support error detection between thread be baked into the high load routine
/// of the compiled payload.
/// \arg PrintAssembler Should the generated assembler code be logged.
/// \returns The compiled payload that provides access to the init and load functions.
[[nodiscard]] auto compilePayload(const environment::payload::PayloadSettings& Settings, bool DumpRegisters,
bool ErrorDetection) const
bool ErrorDetection, bool PrintAssembler) const
-> environment::payload::CompiledPayload::UniquePtr override;

private:
Expand Down
Loading

0 comments on commit ca08f20

Please sign in to comment.