diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3b5d6f8f0..e5f7c658f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,26 +9,26 @@ include: - local: '/script/compiler_base.yml' cuda92: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-gcc:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-gcc:1.4 variables: CUPLA_CXX: "g++-6" CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_cuda cuda100: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-gcc:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-gcc:1.4 variables: CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_cuda cuda101: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-gcc:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-gcc:1.4 variables: CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_cuda cuda102: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda102-gcc:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda102-gcc:1.4 variables: CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_cuda @@ -58,29 +58,90 @@ clang: extends: .base_clang cudaClang92: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-clang:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda92-clang:1.4 variables: CUPLA_CXX: "clang++-8 clang++-10 clang++-11" CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_cuda_clang cudaClang100: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-clang:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda100-clang:1.4 variables: CUPLA_CXX: "clang++-8 clang++-9 clang++-10 clang++-11" CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_cuda_clang cudaClang101: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-clang:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-cuda101-clang:1.4 variables: CUPLA_CXX: "clang++-9 clang++-10 clang++-11" CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_cuda_clang -hip38: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-rocm3.8:1.1 +hip42: + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-rocm4.2:1.4 variables: - CMAKE_MODULE_PATH: "/opt/rocm-3.8.0/hip/cmake" + CMAKE_MODULE_PATH: "/opt/rocm-4.2.0/hip/cmake" CUPLA_BOOST_VERSIONS: "1.65.1 1.66.0 1.67.0 1.68.0 1.69.0 1.70.0 1.71.0 1.72.0 1.73.0" extends: .base_hip + +################################################################################ +# CMake integration test +# + +# build external project and use cupla via cmake add_subdirectory() +# use internal alpaka +addSubdirectoryInternal: + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4 + variables: + GIT_SUBMODULE_STRATEGY: normal + CUPLA_BOOST_VERSION: 1.73.0 + CUPLA_ALPAKA_PROVIDER: "internal" + script: + - source script/integration/build_add_subdirectory.sh + tags: + - x86_64 + +# build external project and use cupla via cmake add_subdirectory() +# use installed alpaka +addSubdirectoryExternal: + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4 + variables: + GIT_SUBMODULE_STRATEGY: normal + CUPLA_BOOST_VERSION: 1.73.0 + CUPLA_ALPAKA_PROVIDER: "external" + script: + - source script/integration/install_alpaka.sh + - source script/integration/build_add_subdirectory.sh + tags: + - x86_64 + +# build external project and use cupla via cmake find_package() +# cupla was installed with disabled examples +findPackageWithoutExample: + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4 + variables: + GIT_SUBMODULE_STRATEGY: normal + CUPLA_BOOST_VERSION: 1.73.0 + CUPLA_BUILD_EXAMPLE: "OFF" + script: + - source script/integration/install_alpaka.sh + - source script/integration/install_cupla.sh + - source script/integration/build_find_package.sh + tags: + - x86_64 + +# build external project and use cupla via cmake find_package() +# cupla was installed with enabled examples +findPackageWithExample: + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4 + variables: + GIT_SUBMODULE_STRATEGY: normal + CUPLA_BOOST_VERSION: 1.73.0 + CUPLA_BUILD_EXAMPLE: "ON" + script: + - source script/integration/install_alpaka.sh + - source script/integration/install_cupla.sh + - source script/integration/build_find_package.sh + tags: + - x86_64 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..7f0deca50 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,149 @@ +# +# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Simeon Ehrig +# +# This file is part of cupla. +# +# cupla is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cupla is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with cupla. +# If not, see . +# + +################################################################################ +# Required cmake version. +################################################################################ + +cmake_minimum_required(VERSION 3.18.0) + +################################################################################ +# Setup project information +################################################################################ + +# Find cupla version. +file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/cupla/version.hpp" CUPLA_VERSION_MAJOR_HPP REGEX "#define CUPLA_VERSION_MAJOR ") +file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/cupla/version.hpp" CUPLA_VERSION_MINOR_HPP REGEX "#define CUPLA_VERSION_MINOR ") +file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/include/cupla/version.hpp" CUPLA_VERSION_PATCH_HPP REGEX "#define CUPLA_VERSION_PATCH ") + +string(REGEX MATCH "([0-9]+)" CUPLA_VERSION_MAJOR ${CUPLA_VERSION_MAJOR_HPP}) +string(REGEX MATCH "([0-9]+)" CUPLA_VERSION_MINOR ${CUPLA_VERSION_MINOR_HPP}) +string(REGEX MATCH "([0-9]+)" CUPLA_VERSION_PATCH ${CUPLA_VERSION_PATCH_HPP}) + +set(PACKAGE_VERSION "${CUPLA_VERSION_MAJOR}.${CUPLA_VERSION_MINOR}.${CUPLA_VERSION_PATCH}") + + +project(cupla VERSION ${CUPLA_VERSION_MAJOR}.${CUPLA_VERSION_MINOR}.${CUPLA_VERSION_PATCH} + DESCRIPTION "cupla is a simple CUDA like user interface for the platform independent parallel kernel acceleration library alpaka." + HOMEPAGE_URL "https://github.com/alpaka-group/cupla" + LANGUAGES CXX) +include(GNUInstallDirs) + +################################################################################ +# cupla options +################################################################################ + +option(CUPLA_STREAM_ASYNC_ENABLE "Enable asynchronous streams" ON) +option(cupla_BUILD_EXAMPLES "Build examples" OFF) + +################################################################################ +# setup alpaka +################################################################################ + +# the min and max. supported alpaka version is also copied to the cuplaConfig.cmake +set(_CUPLA_MIN_ALPAKA_VERSION 0.7.0) +set(_CUPLA_UNSUPPORTED_ALPAKA_VERSION 0.8.0) + +# the alpaka provider for the internal alpaka is only available, +# if cupla is used via add_subdirectory in another project +# or examples are build +if(cupla_BUILD_EXAMPLES OR (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})) + set(cupla_ALPAKA_PROVIDER "internal" CACHE STRING "Select which alpaka is used") + set_property(CACHE cupla_ALPAKA_PROVIDER PROPERTY STRINGS "internal;external") + mark_as_advanced(cupla_ALPAKA_PROVIDER) + + if(${cupla_ALPAKA_PROVIDER} STREQUAL "internal") + set(alpaka_BUILD_EXAMPLES OFF) + set(BUILD_TESTING OFF) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/alpaka) + else() + find_package(alpaka ${_CUPLA_MIN_ALPAKA_VERSION} REQUIRED HINTS $ENV{ALPAKA_ROOT}) + + if(alpaka_VERSION VERSION_GREATER_EQUAL _CUPLA_UNSUPPORTED_ALPAKA_VERSION) + message(WARNING "Unsupported alpaka version ${alpaka_VERSION}. " + "Supported versions [${_CUPLA_MIN_ALPAKA_VERSION},${_CUPLA_UNSUPPORTED_ALPAKA_VERSION}).") + endif() + endif() + + if(NOT TARGET alpaka::alpaka) + message(FATAL_ERROR "Required cupla dependency alpaka could not be found!") + endif() +endif() + +################################################################################ +# cupla Target. +################################################################################ + +# create cupla target only if the cupla is used via add_subdirectory +# or examples are build +# for the explanation please have a look in the cuplaConfig.cmake.in +if(cupla_BUILD_EXAMPLES OR (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})) + include("${CMAKE_CURRENT_LIST_DIR}/cmake/addExecutable.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/cmake/cuplaTargetHelper.cmake") + + createCuplaTarget(${PROJECT_NAME} + ${PROJECT_SOURCE_DIR}/include # include directory path + ${PROJECT_SOURCE_DIR}/src # src directory path + ) +endif() + + +################################################################################ +# add examples +################################################################################ + +if(cupla_BUILD_EXAMPLES) + add_subdirectory(example/) +endif() + +################################################################################ +# install cupla +################################################################################ + +if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) + include(CMakePackageConfigHelpers) + + set(_CUPLA_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + set(_CUPLA_SOURCE_CMAKEDIR "${PROJECT_SOURCE_DIR}/cmake/") + + write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + + configure_package_config_file( + "${_CUPLA_SOURCE_CMAKEDIR}/${PROJECT_NAME}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${_CUPLA_INSTALL_CMAKEDIR} + PATH_VARS _CUPLA_MIN_ALPAKA_VERSION _CUPLA_UNSUPPORTED_ALPAKA_VERSION) + + install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${_CUPLA_INSTALL_CMAKEDIR}) + + install(FILES "${_CUPLA_SOURCE_CMAKEDIR}/addExecutable.cmake" + "${_CUPLA_SOURCE_CMAKEDIR}/cuplaTargetHelper.cmake" + DESTINATION ${_CUPLA_INSTALL_CMAKEDIR}) + + install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include) + # copy source files instead compiled library + # this is necessary because some functions use the ACC as a template parameter, + # but the ACC is not defined at the install time of cupla + install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION src/cupla) +endif() diff --git a/INSTALL.md b/INSTALL.md index a9e3c51bc..360db9e0e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,48 +1,105 @@ -cupla Install Guide -====================== +# cupla Install Guide -Requirements ------------- +## Requirements -- **cmake** 3.15.0 or higher + +- **cmake** 3.18.0 or higher - *Debian/Ubuntu:* `sudo apt-get install cmake file cmake-curses-gui` - *Arch Linux:* `sudo pacman --sync cmake` -- **cupla** - - https://github.com/alpaka-group/cupla - - `export CUPLA_ROOT=` - - `export CMAKE_PREFIX_PATH=$CUPLA_ROOT:$CMAKE_PREFIX_PATH` - - example: - - `mkdir -p $HOME/src` - - `git clone https://github.com/alpaka-group/cupla.git $HOME/src/cupla` - - `cd $HOME/src/cupla` - - `export CUPLA_ROOT=$HOME/src/cupla` - - use a different alpaka installation: - set environment variable `ALPAKA_ROOT` or extend `CMAKE_PREFIX_PATH` with the - path to alpaka. - - -Compile an example ------------------- - -- create build directory `mkdir -p buildCuplaExample` -- `cd buildCuplaExample` -- `cmake $CUPLA_ROOT/example/CUDASamples/matrixMul -D=ON` - - list of supported `ACC_TYPE`s - - `ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE` - - `ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE` - - `ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE` - - `ALPAKA_ACC_GPU_CUDA_ENABLE` - - `ALPAKA_ACC_CPU_BT_OMP4_ENABLE` - - `ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE` (only allowed in combination with - `CUPLA_KERNEL_OPTI` and `CUPLA_KERNEL_ELEM`, because the `blockSize` must be `dim3(1,1,1)`) - see [TuningGuide.md](doc/TuningGuide.md) -- `make -j` -- `./matrixMul -wA=320 -wB=320 -hA=320 -hB=320` (parameters must be a multiple of 32!) - - -How to update alpaka as git subtree? ------------------------------------- +- **boost** 1.65.1 or higher + - is required by alpaka + - *Install Instructions:* https://github.com/alpaka-group/alpaka#dependencies + +## Compile an example + +```bash +cd +mkdir build && cd build +cmake .. -Dcupla_BUILD_EXAMPLES=ON -D=ON +cmake --build . +# execute an example +# (parameters must be a multiple of 32!) +example/CUDASamples/matrixMul/matrixMul -wA=320 -wB=320 -hA=320 -hB=320 +``` + +- list of supported `ACC_TYPE`s + - `ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE` + - `ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE` + - `ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE` + - `ALPAKA_ACC_GPU_CUDA_ENABLE` + - `ALPAKA_ACC_GPU_HIP_ENABLE` + - `ALPAKA_ACC_CPU_BT_OMP4_ENABLE` + - `ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE` (only allowed in combination with + `CUPLA_KERNEL_OPTI` and `CUPLA_KERNEL_ELEM`, because the `blockSize` must be `dim3(1,1,1)`) + see [TuningGuide.md](doc/TuningGuide.md) + +The CMake argument `cupla_ALPAKA_PROVIDER` controls which `alpaka` is used. If the value is `internal` (default), the alpaka, ship with `cupla` is used. If the value is `external`, am installed `aplaka` via `find_package()` is used. + +## Use cupla in your Project + +`cupla` offers two ways to use it in your project via CMake. + +1. You can install it and use it via `find_package()` +2. You can add the `cupla` project to your project and use it with `add_subdirectory()`. + +### Install Cupla (find_package method) + +The installation of `cupla` requires an installed version of `alpaka`. You can install the `alpaka` version in the `cupla` directory (recommended) or install `aplaka` directly from [source](https://github.com/alpaka-group/alpaka). **Attention**, there is no warning if you overwrite an existing `alpaka` installation. + +```bash +cd +mkdir build && cd build +cmake .. +cmake --build . +cmake --install . +``` + +`cupla` can be installed via + +``` +cd +mkdir build && cd build +cmake .. +cmake --build . +cmake --install . +``` + +To check your installation, you can activate the examples (see section [compiling an example](https://github.com/alpaka-group/cupla/blob/master/INSTALL.md#compile-an-example)) during the configuration of `cupla` and check whether it compiles. Activating the examples does not change anything in the installed `cupla` library. + +```bash +# use external alpka to verify your environment +cmake .. -Dcupla_BUILD_EXAMPLES=ON -Dcupla_ALPAKA_PROVIDER="external" +``` + +If cupla is installed, you can use it via `find_package()` in your project: + +```cmake +cmake_minimum_required(VERSION 3.18.0) +project(exampleProject) + +find_package(cupla) + +cupla_add_executable(${PROJECT_NAME} main.cpp) +``` + +### add_subdirectory + +For the method `add_subdirectory()` you have to copy the `cupla` project folder into your project. After that you can add `cupla` to your project and use it. + +```cmake +cmake_minimum_required(VERSION 3.18.0) +project(exampleProject) + +# requires, that cupla is located in the root directory of your project +add_subdirectory(cupla) + +cupla_add_executable(${PROJECT_NAME} main.cpp) +``` + +Via the CMake variable `cupla_ALPAKA_PROVIDER` you can decide whether you want to use the `alpaka` ship with `cupla` (`-Dcupla_ALPAKA_PROVIDER="interal"`) or an installed version of `alpaka` (`-Dcupla_ALPAKA_PROVIDER="external"` - uses `find_package(alpaka)`). + +## How to update alpaka as git subtree? ```zsh # git author is generic to not mess up contribution statistics diff --git a/cmake/cuplaConfig.cmake.in b/cmake/cuplaConfig.cmake.in new file mode 100644 index 000000000..5cb59a040 --- /dev/null +++ b/cmake/cuplaConfig.cmake.in @@ -0,0 +1,50 @@ +# +# Copyright 2021 Simeon Ehrig +# +# This file is part of cupla. +# +# cupla is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cupla is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with cupla. +# If not, see . +# + +@PACKAGE_INIT@ + +check_required_components("@PROJECT_NAME@") + +option(CUPLA_STREAM_ASYNC_ENABLE "Enable asynchronous streams" ON) + +# the minimum and maximum supported alpaka version are fixed during the installation of cupla +set(_CUPLA_MIN_ALPAKA_VERSION @_CUPLA_MIN_ALPAKA_VERSION@) +set(_CUPLA_UNSUPPORTED_ALPAKA_VERSION @_CUPLA_UNSUPPORTED_ALPAKA_VERSION@) + +find_package(alpaka ${_CUPLA_MIN_ALPAKA_VERSION} REQUIRED HINTS $ENV{ALPAKA_ROOT}) +if(alpaka_VERSION VERSION_GREATER_EQUAL _CUPLA_UNSUPPORTED_ALPAKA_VERSION) + message(WARNING "Unsupported alpaka version ${alpaka_VERSION}. " + "Supported versions [${_CUPLA_MIN_ALPAKA_VERSION},${_CUPLA_UNSUPPORTED_ALPAKA_VERSION}).") +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/addExecutable.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/cuplaTargetHelper.cmake") + +# restore the CMAKE_INSTALL_PREFIX of the installation of cupla +set(_RESTORED_CUPLA_INSTALL_PRFIX "${CMAKE_CURRENT_LIST_DIR}/../../../") +# The cupla target must be created with cupla at project configuration time. +# Some functions in the cupla source files are specialised with the ACC template parameter. +# Compiling the source files must be done at build time of the project. If this were done at +# cupla installation time, the ACC would be set once at cupla installation time for all +# projects using that installation of cupla. +createCuplaTarget(@PROJECT_NAME@ + ${_RESTORED_CUPLA_INSTALL_PRFIX}/include # include directory path + ${_RESTORED_CUPLA_INSTALL_PRFIX}/src/cupla # src directory path + ) diff --git a/cmake/cuplaTargetHelper.cmake b/cmake/cuplaTargetHelper.cmake new file mode 100644 index 000000000..3ccd6b6ad --- /dev/null +++ b/cmake/cuplaTargetHelper.cmake @@ -0,0 +1,78 @@ +# +# Copyright 2021 Simeon Ehrig +# +# This file is part of cupla. +# +# cupla is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cupla is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with cupla. +# If not, see . +# + +# creates the cupla target (library) +macro(createCuplaTarget + TARGET_NAME # name of the cupla target, normally cupla + _CUPLA_INCLUDE_DIR # path of the include folder + _CUPLA_SRC_DIR # path of the src folder + ) + alpaka_add_library( + ${TARGET_NAME} + STATIC + ${_CUPLA_SRC_DIR}/manager/Driver.cpp + ${_CUPLA_SRC_DIR}/common.cpp + ${_CUPLA_SRC_DIR}/device.cpp + ${_CUPLA_SRC_DIR}/event.cpp + ${_CUPLA_SRC_DIR}/memory.cpp + ${_CUPLA_SRC_DIR}/stream.cpp + ) + + target_include_directories(${TARGET_NAME} + PUBLIC + $ + $) + + # Even if there are no sources CMAKE has to know the language. + set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) + + target_link_libraries( + ${TARGET_NAME} + PUBLIC + alpaka::alpaka) + + if(CUPLA_STREAM_ASYNC_ENABLE) + TARGET_COMPILE_DEFINITIONS(${TARGET_NAME} PUBLIC "CUPLA_STREAM_ASYNC_ENABLED=1") + else() + TARGET_COMPILE_DEFINITIONS(${TARGET_NAME} PUBLIC "CUPLA_STREAM_ASYNC_ENABLED=0") + endif() + + # GNU + if(CMAKE_COMPILER_IS_GNUCXX) + TARGET_COMPILE_OPTIONS(${TARGET_NAME} + PRIVATE + "-Wall" + "-Wextra" + "-Wno-unknown-pragmas" + "-Wno-unused-parameter" + "-Wno-unused-local-typedefs" + "-Wno-attributes" + "-Wno-reorder" + "-Wno-sign-compare") + # ICC + elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") + TARGET_COMPILE_OPTIONS(${TARGET_NAME} PRIVATE "-Wall") + # PGI + elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "PGI") + TARGET_COMPILE_OPTIONS(${TARGET_NAME} PRIVATE "-Minform=inform") + endif() + + add_library(${TARGET_NAME}::${TARGET_NAME} ALIAS ${TARGET_NAME}) +endmacro() diff --git a/cuplaConfig.cmake b/cuplaConfig.cmake deleted file mode 100644 index a95e6d952..000000000 --- a/cuplaConfig.cmake +++ /dev/null @@ -1,332 +0,0 @@ -# -# Copyright 2016 Rene Widera, Benjamin Worpitz -# -# This file is part of cupla. -# -# cupla is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cupla is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with cupla. -# If not, see . -# - -################################################################################ -# Required cmake version. -################################################################################ - -cmake_minimum_required(VERSION 3.15.0) - -################################################################################ -# CMake policies -# -# Search in _ROOT: -# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html -################################################################################ - -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - -################################################################################ -# cupla -################################################################################ - -# Return values. -unset(cupla_FOUND) -unset(cupla_VERSION) -unset(cupla_COMPILE_OPTIONS) -unset(cupla_COMPILE_DEFINITIONS) -unset(cupla_DEFINITIONS) -unset(cupla_INCLUDE_DIR) -unset(cupla_INCLUDE_DIRS) -unset(cupla_SOURCE_DIR) -unset(cupla_SOURCE_DIRS) -unset(cupla_LIBRARY) -unset(cupla_LIBRARIES) -unset(cupla_SOURCE_FILES) - -# Internal usage. -unset(_cupla_FOUND) -unset(_cupla_VERSION) -unset(_cupla_COMPILE_OPTIONS_PUBLIC) -unset(_cupla_COMPILE_DEFINITIONS_PUBLIC) -unset(_cupla_INCLUDE_DIR) -unset(_cupla_INCLUDE_DIRECTORIES_PUBLIC) -unset(_cupla_SOURCE_DIR) -unset(_cupla_SOURCE_DIRECTORIES_PUBLIC) -unset(_cupla_LINK_LIBRARIES_PUBLIC) -unset(_cupla_FILES_HEADER) -unset(_cupla_FILES_SOURCE) -unset(_cupla_FILES_OTHER) -unset(_cupla_ADD_EXECUTABLE_FILE) - -################################################################################ -# Directory of this file. -################################################################################ -set(_cupla_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) - -# Normalize the path (e.g. remove ../) -get_filename_component(_cupla_ROOT_DIR "${_cupla_ROOT_DIR}" ABSOLUTE) - -# Add cupla_ADD_EXECUTABLE function. -set(_cupla_ADD_EXECUTABLE_FILE "${_cupla_ROOT_DIR}/cmake/addExecutable.cmake") -include("${_cupla_ADD_EXECUTABLE_FILE}") - -################################################################################ -# Set found to true initially and set it on false if a required dependency is missing. -################################################################################ -set(_cupla_FOUND TRUE) - -################################################################################ -# Common. -################################################################################ -# own modules for find_packages -list(APPEND CMAKE_MODULE_PATH "${_cupla_ROOT_DIR}") -#list(APPEND CMAKE_MODULE_PATH "$ENV{ALPAKA_ROOT}") - - -################################################################################ -# Find alpaka -# NOTE: Do this first, because it declares `list_add_prefix` and `append_recursive_files_add_to_src_group` used later on. -################################################################################ - -# disable all accelerators by default -OPTION(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE "Enable the serial CPU accelerator" OFF) -OPTION(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE "Enable the threads CPU block thread accelerator" OFF) -OPTION(ALPAKA_ACC_CPU_B_SEQ_T_FIBERS_ENABLE "Enable the fibers CPU block thread accelerator" OFF) -OPTION(ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE "Enable the TBB CPU grid block back-end" OFF) -OPTION(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE "Enable the OpenMP 2.0 CPU grid block accelerator" OFF) -OPTION(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE "Enable the OpenMP 2.0 CPU block thread accelerator" OFF) -OPTION(ALPAKA_ACC_ANY_BT_OMP5_ENABLE "Enable the OpenMP 5 offloading block and block thread accelerator" OFF) -OPTION(ALPAKA_ACC_ANY_BT_OACC_ENABLE "Enable the experimental OpenACC offloading block and block thread accelerator" OFF) -OPTION(ALPAKA_ACC_GPU_CUDA_ENABLE "Enable the CUDA GPU accelerator" OFF) -OPTION(ALPAKA_ACC_GPU_HIP_ENABLE "Enable the HIP back-end (all other back-ends must be disabled)" OFF) - -set(cupla_ALPAKA_PROVIDER "intern" CACHE STRING "Select which alpaka is used") -set_property(CACHE cupla_ALPAKA_PROVIDER PROPERTY STRINGS "intern;extern") -mark_as_advanced(cupla_ALPAKA_PROVIDER) - -if(${cupla_ALPAKA_PROVIDER} STREQUAL "intern") - set(alpaka_BUILD_EXAMPLES OFF) - set(BUILD_TESTING OFF) - add_subdirectory(${_cupla_ROOT_DIR}/alpaka ${CMAKE_BINARY_DIR}/alpaka) -else() - set(_cupla_MIN_ALPAKA_VERSION 0.6.0) - set(_cupla_UNSUPPORTED_ALPAKA_VERSION 0.7.0) - find_package(alpaka ${_cupla_MIN_ALPAKA_VERSION} HINTS $ENV{ALPAKA_ROOT}) - - if(alpaka_VERSION VERSION_GREATER_EQUAL _cupla_UNSUPPORTED_ALPAKA_VERSION) - message(WARNING "Unsupported alpaka version ${alpaka_VERSION}. " - "Supported versions [${_cupla_MIN_ALPAKA_VERSION},${_cupla_UNSUPPORTED_ALPAKA_VERSION}).") - endif() -endif() - -if(NOT TARGET alpaka::alpaka) - message(WARNING "Required cupla dependency alpaka could not be found!") - set(_cupla_FOUND FALSE) -endif() - -################################################################################ -# Compiler settings. -################################################################################ -if(MSVC) - # Empty append to define it if it does not already exist. - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC) -else() - # GNU - if(CMAKE_COMPILER_IS_GNUCXX) - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wall") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wextra") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-unknown-pragmas") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-unused-parameter") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-unused-local-typedefs") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-attributes") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-reorder") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wno-sign-compare") - # ICC - elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Wall") - # PGI - elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "PGI") - list(APPEND _cupla_COMPILE_OPTIONS_PUBLIC "-Minform=inform") - endif() -endif() - - -################################################################################ -# cupla. -################################################################################ - -option(CUPLA_STREAM_ASYNC_ENABLE "Enable asynchronous streams" ON) -if(CUPLA_STREAM_ASYNC_ENABLE) - list(APPEND _cupla_COMPILE_DEFINITIONS_PUBLIC "CUPLA_STREAM_ASYNC_ENABLED=1") -else() - list(APPEND _cupla_COMPILE_DEFINITIONS_PUBLIC "CUPLA_STREAM_ASYNC_ENABLED=0") -endif() - -set(_cupla_INCLUDE_DIR "${_cupla_ROOT_DIR}/include") -list(APPEND _cupla_INCLUDE_DIRECTORIES_PUBLIC ${_cupla_INCLUDE_DIR}) -set(_cupla_SUFFIXED_INCLUDE_DIR "${_cupla_INCLUDE_DIR}") - -set(_cupla_SOURCE_DIR "${_cupla_ROOT_DIR}/src") -list(APPEND _cupla_SOURCE_DIRECTORIES_PUBLIC ${_cupla_SOURCE_DIR}) -set(_cupla_SUFFIXED_SOURCE_DIR "${_cupla_SOURCE_DIR}") - -set(_cupla_LINK_LIBRARY) -list(APPEND _cupla_LINK_LIBRARIES_PUBLIC ${_cupla_LINK_LIBRARY}) - -set(_cupla_FILES_OTHER "${_cupla_ROOT_DIR}/Findcupla.cmake" "${_cupla_ROOT_DIR}/cuplaConfig.cmake") - -# Add all the include files in all recursive subdirectories and group them accordingly. -append_recursive_files_add_to_src_group("${_cupla_SUFFIXED_INCLUDE_DIR}" "${_cupla_SUFFIXED_INCLUDE_DIR}" "hpp" _cupla_FILES_HEADER) -append_recursive_files_add_to_src_group("${_cupla_SUFFIXED_INCLUDE_DIR}" "${_cupla_SUFFIXED_INCLUDE_DIR}" "h" _cupla_FILES_HEADER) - -append_recursive_files_add_to_src_group("${_cupla_SUFFIXED_SOURCE_DIR}" "${_cupla_SUFFIXED_SOURCE_DIR}" "cpp" _cupla_FILES_SOURCE) - - -################################################################################ -# cupla Target. -################################################################################ - -alpaka_add_library( - "cupla" - ${_cupla_FILES_HEADER} ${_cupla_FILES_OTHER} ${_cupla_FILES_SOURCE}) - -# Even if there are no sources CMAKE has to know the language. -set_target_properties("cupla" PROPERTIES LINKER_LANGUAGE CXX) - -# Compile options. -message(STATUS "_cupla_COMPILE_OPTIONS_PUBLIC: ${_cupla_COMPILE_OPTIONS_PUBLIC}") -list( - LENGTH - _cupla_COMPILE_OPTIONS_PUBLIC - _cupla_COMPILE_OPTIONS_PUBLIC_LENGTH) -if("${_cupla_COMPILE_OPTIONS_PUBLIC_LENGTH}") - TARGET_COMPILE_OPTIONS( - "cupla" - PUBLIC ${_cupla_COMPILE_OPTIONS_PUBLIC}) -endif() - -# Compile definitions. -message(STATUS "_cupla_COMPILE_DEFINITIONS_PUBLIC: ${_cupla_COMPILE_DEFINITIONS_PUBLIC}") -list( - LENGTH - _cupla_COMPILE_DEFINITIONS_PUBLIC - _cupla_COMPILE_DEFINITIONS_PUBLIC_LENGTH) -if("${_cupla_COMPILE_DEFINITIONS_PUBLIC_LENGTH}") - TARGET_COMPILE_DEFINITIONS( - "cupla" - PUBLIC ${_cupla_COMPILE_DEFINITIONS_PUBLIC}) -endif() - -# Include directories. -message(STATUS "_cupla_INCLUDE_DIRECTORIES_PUBLIC: ${_cupla_INCLUDE_DIRECTORIES_PUBLIC}") -list( - LENGTH - _cupla_INCLUDE_DIRECTORIES_PUBLIC - _cupla_INCLUDE_DIRECTORIES_PUBLIC_LENGTH) -if("${_cupla_INCLUDE_DIRECTORIES_PUBLIC_LENGTH}") - TARGET_INCLUDE_DIRECTORIES( - "cupla" - PUBLIC ${_cupla_INCLUDE_DIRECTORIES_PUBLIC}) -endif() - -# Link libraries. -message(STATUS "_cupla_LINK_LIBRARIES_PUBLIC: ${_cupla_LINK_LIBRARIES_PUBLIC}") - -target_link_libraries( - "cupla" - PUBLIC alpaka::alpaka ${_cupla_LINK_LIBRARIES_PUBLIC}) - -################################################################################ -# Find cupla version. -################################################################################ -# Please also update the version in `include/cupla/version.hpp` -set(_cupla_VERSION "0.3.0") - -################################################################################ -# Set return values. -################################################################################ -set(cupla_VERSION ${_cupla_VERSION}) -set(cupla_COMPILE_OPTIONS ${_cupla_COMPILE_OPTIONS_PUBLIC}) -set(cupla_COMPILE_DEFINITIONS ${_cupla_COMPILE_DEFINITIONS_PUBLIC}) -# Add '-D' to the definitions -set(cupla_DEFINITIONS ${_cupla_COMPILE_DEFINITIONS_PUBLIC}) -list_add_prefix("-D" cupla_DEFINITIONS) -# Add the compile options to the definitions. -list(APPEND cupla_DEFINITIONS ${_cupla_COMPILE_OPTIONS_PUBLIC}) -set(cupla_INCLUDE_DIR ${_cupla_INCLUDE_DIR}) -set(cupla_INCLUDE_DIRS ${_cupla_INCLUDE_DIRECTORIES_PUBLIC}) -set(cupla_LIBRARY ${_cupla_LINK_LIBRARY}) -set(cupla_LIBRARIES ${_cupla_LINK_LIBRARIES_PUBLIC}) -set(cupla_SOURCE_FILES ${_cupla_FILES_SOURCE}) - -# Unset already set variables if not found. -if(NOT _cupla_FOUND) - unset(cupla_FOUND) - unset(cupla_VERSION) - unset(cupla_COMPILE_OPTIONS) - unset(cupla_COMPILE_DEFINITIONS) - unset(cupla_DEFINITIONS) - unset(cupla_INCLUDE_DIR) - unset(cupla_INCLUDE_DIRS) - unset(cupla_SOURCE_DIR) - unset(cupla_SOURCE_DIRS) - unset(cupla_LIBRARY) - unset(cupla_LIBRARIES) - unset(cupla_SOURCE_FILES) - - unset(_cupla_FOUND) - unset(_cupla_COMPILE_OPTIONS_PUBLIC) - unset(_cupla_COMPILE_DEFINITIONS_PUBLIC) - unset(_cupla_INCLUDE_DIR) - unset(_cupla_INCLUDE_DIRECTORIES_PUBLIC) - unset(_cupla_SOURCE_DIR) - unset(_cupla_SOURCE_DIRECTORIES_PUBLIC) - unset(_cupla_LINK_LIBRARY) - unset(_cupla_LINK_LIBRARIES_PUBLIC) - unset(_cupla_FILES_HEADER) - unset(_cupla_FILES_SOURCE) - unset(_cupla_FILES_OTHER) - unset(_cupla_VERSION) - unset(_cupla_ADD_EXECUTABLE_FILE) -else() - # Make internal variables advanced options in the GUI. - MARK_AS_ADVANCED( - cupla_INCLUDE_DIR - cupla_LIBRARY - _cupla_FOUND - _cupla_COMPILE_OPTIONS_PUBLIC - _cupla_COMPILE_DEFINITIONS_PUBLIC - _cupla_INCLUDE_DIR - _cupla_INCLUDE_DIRECTORIES_PUBLIC - _cupla_LINK_LIBRARY - _cupla_LINK_LIBRARIES_PUBLIC - _cupla_FILES_HEADER - _cupla_FILES_SOURCE - _cupla_FILES_OTHER - _cupla_VERSION - _cupla_ADD_EXECUTABLE_FILE - ) -endif() - -############################################################################### -# FindPackage options -############################################################################### - -# Handles the REQUIRED, QUIET and version-related arguments for find_package. -# NOTE: We do not check for cupla_LIBRARIES and cupla_DEFINITIONS because they can be empty. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - "cupla" - FOUND_VAR cupla_FOUND - REQUIRED_VARS cupla_INCLUDE_DIR - VERSION_VAR cupla_VERSION) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 000000000..a483274e1 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(CUDASamples) diff --git a/example/CUDASamples/CMakeLists.txt b/example/CUDASamples/CMakeLists.txt new file mode 100644 index 000000000..53a25ead3 --- /dev/null +++ b/example/CUDASamples/CMakeLists.txt @@ -0,0 +1,6 @@ +add_subdirectory(asyncAPI/) +add_subdirectory(asyncAPI_tuned/) +add_subdirectory(blackScholes/) +add_subdirectory(cuplaVectorAdd/) +add_subdirectory(matrixMul/) +add_subdirectory(vectorAdd/) diff --git a/example/CUDASamples/asyncAPI/CMakeLists.txt b/example/CUDASamples/asyncAPI/CMakeLists.txt index ccecbd711..b18cc47be 100644 --- a/example/CUDASamples/asyncAPI/CMakeLists.txt +++ b/example/CUDASamples/asyncAPI/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2016 Rene Widera, Benjamin Worpitz +# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Simeon Ehrig # # This file is part of cupla. # @@ -22,9 +22,7 @@ # Required CMake version. ################################################################################ -cmake_minimum_required(VERSION 3.15.0) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +cmake_minimum_required(VERSION 3.18.0) ################################################################################ # Project. @@ -32,37 +30,17 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) project(asyncAPI) -################################################################################ -# CMake policies -# -# Search in _ROOT: -# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html# -################################################################################ - -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - ################################################################################ # Find cupla ################################################################################ -set(cupla_ROOT "$ENV{CUPLA_ROOT}" CACHE STRING "The location of the cupla library") - -list(APPEND CMAKE_MODULE_PATH "${cupla_ROOT}") -find_package(cupla REQUIRED) - +if(NOT TARGET cupla::cupla) + find_package(cupla REQUIRED) +endif() ################################################################################ # Add library. ################################################################################ -set(_SOURCE_DIR "src/") - -# Add all the source files in all recursive subdirectories and group them accordingly. -append_recursive_files_add_to_src_group("${_SOURCE_DIR}" "" "cpp" _FILES_SOURCE_CXX) - -# Always add all files to the target executable build call to add them to the build project. -cupla_add_executable(${PROJECT_NAME} ${_FILES_SOURCE_CXX}) - +cupla_add_executable(${PROJECT_NAME} "src/asyncAPI.cpp") target_include_directories(${PROJECT_NAME} PRIVATE "../common/") diff --git a/example/CUDASamples/asyncAPI_tuned/CMakeLists.txt b/example/CUDASamples/asyncAPI_tuned/CMakeLists.txt index ba4452f4a..fb0a3ab6d 100644 --- a/example/CUDASamples/asyncAPI_tuned/CMakeLists.txt +++ b/example/CUDASamples/asyncAPI_tuned/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2016 Rene Widera, Benjamin Worpitz +# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Simeon Ehrig # # This file is part of cupla. # @@ -23,9 +23,7 @@ # Required CMake version. ################################################################################ -cmake_minimum_required(VERSION 3.15.0) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +cmake_minimum_required(VERSION 3.18.0) ################################################################################ # Project. @@ -33,37 +31,17 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) project(asyncAPI_tuned) -################################################################################ -# CMake policies -# -# Search in _ROOT: -# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html# -################################################################################ - -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - ################################################################################ # Find cupla ################################################################################ -set(cupla_ROOT "$ENV{CUPLA_ROOT}" CACHE STRING "The location of the cupla library") - -list(APPEND CMAKE_MODULE_PATH "${cupla_ROOT}") -find_package(cupla REQUIRED) - +if(NOT TARGET cupla::cupla) + find_package(cupla REQUIRED) +endif() ################################################################################ # Add library. ################################################################################ -set(_SOURCE_DIR "src/") - -# Add all the source files in all recursive subdirectories and group them accordingly. -append_recursive_files_add_to_src_group("${_SOURCE_DIR}" "" "cpp" _FILES_SOURCE_CXX) - -# Always add all files to the target executable build call to add them to the build project. -cupla_add_executable(${PROJECT_NAME} ${_FILES_SOURCE_CXX}) - +cupla_add_executable(${PROJECT_NAME} "src/asyncAPI.cpp") target_include_directories(${PROJECT_NAME} PRIVATE "../common/") diff --git a/example/CUDASamples/blackScholes/CMakeLists.txt b/example/CUDASamples/blackScholes/CMakeLists.txt index eb2fbec7c..8366c1683 100644 --- a/example/CUDASamples/blackScholes/CMakeLists.txt +++ b/example/CUDASamples/blackScholes/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2016 Rene Widera, Benjamin Worpitz, Vincent Ridder +# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Vincent Ridder, Simeon Ehrig # # This file is part of cupla. # @@ -23,9 +23,7 @@ # Required CMake version. ################################################################################ -cmake_minimum_required(VERSION 3.15.0) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +cmake_minimum_required(VERSION 3.18.0) ################################################################################ # Project. @@ -33,37 +31,18 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) project("blackScholes") -################################################################################ -# CMake policies -# -# Search in _ROOT: -# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html# -################################################################################ - -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - ################################################################################ # Find cupla ################################################################################ -set(cupla_ROOT "$ENV{CUPLA_ROOT}" CACHE STRING "The location of the cupla library") - -list(APPEND CMAKE_MODULE_PATH "${cupla_ROOT}") -find_package("cupla" REQUIRED) - +if(NOT TARGET cupla::cupla) + find_package(cupla REQUIRED) +endif() ################################################################################ # Add library. ################################################################################ -set(_SOURCE_DIR "src/") - -# Add all the source files in all recursive subdirectories and group them accordingly. -append_recursive_files_add_to_src_group("${_SOURCE_DIR}" "" "cpp" _FILES_SOURCE_CXX) - -# Always add all files to the target executable build call to add them to the build project. -cupla_add_executable(${PROJECT_NAME} ${_FILES_SOURCE_CXX}) +cupla_add_executable(${PROJECT_NAME} src/BlackScholes.cpp src/BlackScholes_gold.cpp) target_include_directories(${PROJECT_NAME} PRIVATE "../common/") diff --git a/example/CUDASamples/cuplaVectorAdd/CMakeLists.txt b/example/CUDASamples/cuplaVectorAdd/CMakeLists.txt index 8411cfa57..e82b713ad 100644 --- a/example/CUDASamples/cuplaVectorAdd/CMakeLists.txt +++ b/example/CUDASamples/cuplaVectorAdd/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2016-2020 Rene Widera, Benjamin Worpitz, Vincent Ridder +# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Vincent Ridder, Simeon Ehrig # # This file is part of cupla. # @@ -22,9 +22,7 @@ # Required CMake version. ################################################################################ -cmake_minimum_required(VERSION 3.11.4) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +cmake_minimum_required(VERSION 3.18.0) ################################################################################ # Project. @@ -32,36 +30,16 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) project(cuplaVectorAdd) -################################################################################ -# CMake policies -# -# Search in _ROOT: -# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html# -################################################################################ - -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - ################################################################################ # Find cupla ################################################################################ -set(cupla_ROOT "$ENV{CUPLA_ROOT}" CACHE STRING "The location of the cupla library") - -list(APPEND CMAKE_MODULE_PATH "${cupla_ROOT}") -find_package(cupla REQUIRED) - +if(NOT TARGET cupla::cupla) + find_package(cupla REQUIRED) +endif() ################################################################################ # Add library. ################################################################################ -set(_SOURCE_DIR "src/") - -# Add all the source files in all recursive subdirectories and group them accordingly. -append_recursive_files_add_to_src_group("${_SOURCE_DIR}" "" "cpp" _FILES_SOURCE_CXX) - -# Always add all files to the target executable build call to add them to the build project. -cupla_add_executable(${PROJECT_NAME} ${_FILES_SOURCE_CXX}) - +cupla_add_executable(${PROJECT_NAME} src/vectorAdd.cpp) diff --git a/example/CUDASamples/matrixMul/CMakeLists.txt b/example/CUDASamples/matrixMul/CMakeLists.txt index b9e42f906..cac6a3149 100644 --- a/example/CUDASamples/matrixMul/CMakeLists.txt +++ b/example/CUDASamples/matrixMul/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2016 Rene Widera, Benjamin Worpitz +# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Simeon Ehrig # # This file is part of cupla. # @@ -23,9 +23,7 @@ # Required CMake version. ################################################################################ -cmake_minimum_required(VERSION 3.15.0) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +cmake_minimum_required(VERSION 3.18.0) ################################################################################ # Project. @@ -33,37 +31,18 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) project(matrixMul) -################################################################################ -# CMake policies -# -# Search in _ROOT: -# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html# -################################################################################ - -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - ################################################################################ # Find cupla ################################################################################ -set(cupla_ROOT "$ENV{CUPLA_ROOT}" CACHE STRING "The location of the cupla library") - -list(APPEND CMAKE_MODULE_PATH "${cupla_ROOT}") -find_package(cupla REQUIRED) - +if(NOT TARGET cupla::cupla) + find_package(cupla REQUIRED) +endif() ################################################################################ # Add library. ################################################################################ -set(_SOURCE_DIR "src/") - -# Add all the source files in all recursive subdirectories and group them accordingly. -append_recursive_files_add_to_src_group("${_SOURCE_DIR}" "" "cpp" _FILES_SOURCE_CXX) - -# Always add all files to the target executable build call to add them to the build project. -cupla_add_executable(${PROJECT_NAME} ${_FILES_SOURCE_CXX}) +cupla_add_executable(${PROJECT_NAME} src/matrixMul.cpp) target_include_directories(${PROJECT_NAME} PRIVATE "../common/") diff --git a/example/CUDASamples/vectorAdd/CMakeLists.txt b/example/CUDASamples/vectorAdd/CMakeLists.txt index b0662c486..da0c5a1ce 100644 --- a/example/CUDASamples/vectorAdd/CMakeLists.txt +++ b/example/CUDASamples/vectorAdd/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2016 Rene Widera, Benjamin Worpitz, Vincent Ridder +# Copyright 2016-2021 Rene Widera, Benjamin Worpitz, Vincent Ridder, Simeon Ehrig # # This file is part of cupla. # @@ -22,9 +22,7 @@ # Required CMake version. ################################################################################ -cmake_minimum_required(VERSION 3.15.0) - -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +cmake_minimum_required(VERSION 3.18.0) ################################################################################ # Project. @@ -32,37 +30,17 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) project(vectorAdd) -################################################################################ -# CMake policies -# -# Search in _ROOT: -# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html# -################################################################################ - -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - ################################################################################ # Find cupla ################################################################################ -set(cupla_ROOT "$ENV{CUPLA_ROOT}" CACHE STRING "The location of the cupla library") - -list(APPEND CMAKE_MODULE_PATH "${cupla_ROOT}") -find_package(cupla REQUIRED) - +if(NOT TARGET cupla::cupla) + find_package(cupla REQUIRED) +endif() ################################################################################ # Add library. ################################################################################ -set(_SOURCE_DIR "src/") - -# Add all the source files in all recursive subdirectories and group them accordingly. -append_recursive_files_add_to_src_group("${_SOURCE_DIR}" "" "cpp" _FILES_SOURCE_CXX) - -# Always add all files to the target executable build call to add them to the build project. -cupla_add_executable(${PROJECT_NAME} ${_FILES_SOURCE_CXX}) - +cupla_add_executable(${PROJECT_NAME} src/vectorAdd.cpp) target_include_directories(${PROJECT_NAME} PRIVATE "../common/") diff --git a/script/compiler_base.yml b/script/compiler_base.yml index 8e3e676fc..fd383f606 100644 --- a/script/compiler_base.yml +++ b/script/compiler_base.yml @@ -1,5 +1,5 @@ .base_gcc: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-gcc:1.4 variables: GIT_SUBMODULE_STRATEGY: normal ALPAKA_ACCS: "ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE @@ -13,7 +13,7 @@ - x86_64 .base_clang: - image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-clang:1.1 + image: registry.gitlab.com/hzdr/crp/alpaka-group-container/alpaka-ci-clang:1.4 variables: GIT_SUBMODULE_STRATEGY: normal ALPAKA_ACCS: "ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE diff --git a/script/integration/build_add_subdirectory.sh b/script/integration/build_add_subdirectory.sh new file mode 100644 index 000000000..f3478266b --- /dev/null +++ b/script/integration/build_add_subdirectory.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +CUPLA_ROOT=$(pwd) + +########################## +# create external project +########################## +mkdir /tmp/external_project +cd /tmp/external_project +# copy source file and CMakeLists.txt to external project to simulate external project +EXT_PROJECT_ROOT=$(pwd) +cp ${CUPLA_ROOT}/example/CUDASamples/cuplaVectorAdd/src/vectorAdd.cpp ${EXT_PROJECT_ROOT} +cp ${CUPLA_ROOT}/test/integration/cupla_add_subdirectory.cmake ${EXT_PROJECT_ROOT}/CMakeLists.txt +cd ${EXT_PROJECT_ROOT} +# link cupla for add_subdirectory() +ln -s ${CUPLA_ROOT} . + +########################## +# build external project +########################## +mkdir build install +export LD_LIBRARY_PATH=${EXT_PROJECT_ROOT}/install/lib:${LD_LIBRARY_PATH} +echo $LD_LIBRARY_PATH +cd build +cmake .. -DALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE=ON -Dcupla_ALPAKA_PROVIDER=${CUPLA_ALPAKA_PROVIDER} -DBOOST_ROOT=/opt/boost/${CUPLA_BOOST_VERSION} -DCMAKE_INSTALL_PREFIX=../install -DBUILD_SHARED_LIBS=ON +cmake --build . +cmake --install . + +########################## +# test build +########################## +cd ../install +ls +bin/cuplaVectorAdd diff --git a/script/integration/build_find_package.sh b/script/integration/build_find_package.sh new file mode 100644 index 000000000..33ff053f0 --- /dev/null +++ b/script/integration/build_find_package.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +CUPLA_ROOT=$(pwd) + +########################## +# create external project +########################## +mkdir /tmp/external_project +cd /tmp/external_project +# copy source file and CMakeLists.txt to external project to simulate external project +EXT_PROJECT_ROOT=$(pwd) +cp ${CUPLA_ROOT}/example/CUDASamples/cuplaVectorAdd/src/vectorAdd.cpp ${EXT_PROJECT_ROOT} +cp ${CUPLA_ROOT}/test/integration/cupla_find_package.cmake ${EXT_PROJECT_ROOT}/CMakeLists.txt +cd ${EXT_PROJECT_ROOT} + +########################## +# build external project +########################## +mkdir build install +export LD_LIBRARY_PATH=${EXT_PROJECT_ROOT}/install/lib:${LD_LIBRARY_PATH} +echo $LD_LIBRARY_PATH +cd build +cmake .. -DALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE=ON -DBOOST_ROOT=/opt/boost/${CUPLA_BOOST_VERSION} -DCMAKE_INSTALL_PREFIX=../install -DBUILD_SHARED_LIBS=ON +cmake --build . +cmake --install . + +########################## +# test build +########################## +cd ../install +ls +bin/cuplaVectorAdd diff --git a/script/integration/install_alpaka.sh b/script/integration/install_alpaka.sh new file mode 100644 index 000000000..443aed349 --- /dev/null +++ b/script/integration/install_alpaka.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +CUPLA_ROOT=$(pwd) +cd alpaka +mkdir build +cd build +cmake .. -DBOOST_ROOT=/opt/boost/${CUPLA_BOOST_VERSION} +cmake --build . +cmake --install . +cd ${CUPLA_ROOT} +# Remove alpaka repository so that it cannot be used accidentally via add_subdirectory() +rm -rf alpaka diff --git a/script/integration/install_cupla.sh b/script/integration/install_cupla.sh new file mode 100644 index 000000000..b74c17d75 --- /dev/null +++ b/script/integration/install_cupla.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +CUPLA_ROOT=$(pwd) +mkdir build +cd build +cmake .. -Dcupla_BUILD_EXAMPLES=${CUPLA_BUILD_EXAMPLE} -Dcupla_ALPAKA_PROVIDER="external" -DBOOST_ROOT=/opt/boost/${CUPLA_BOOST_VERSION} -DALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE=ON +cmake --build . +cmake --install . +cd ${CUPLA_ROOT} diff --git a/script/run_test.sh b/script/run_test.sh index 55457abfd..f9ca3c719 100755 --- a/script/run_test.sh +++ b/script/run_test.sh @@ -12,7 +12,7 @@ fi # cmake config builder ################################################### -CUPLA_CONST_ARGS="" +CUPLA_CONST_ARGS="-Dcupla_BUILD_EXAMPLES=ON -Dcupla_ALPAKA_PROVIDER=\"internal\"" CUPLA_CONST_ARGS="${CUPLA_CONST_ARGS} -DCMAKE_BUILD_TYPE=${CUPLA_BUILD_TYPE}" CUPLA_CONST_ARGS="${CUPLA_CONST_ARGS} ${CUPLA_CMAKE_ARGS}" @@ -45,17 +45,16 @@ for CONFIG in $(seq 0 $((${#CMAKE_CONFIGS[*]} - 1))); do echo "CMAKE_ARGS -> ${CMAKE_ARGS}" echo -e "/////////////////////////////////////////////////// \033[0m \n\n" + cmake $cupla_DIR $CMAKE_ARGS + cmake --build . -j + echo "###################################################" echo "# Example Matrix Multiplication (adapted original)" echo "###################################################" echo "can not run with CPU_B_SEQ_T_SEQ due to missing elements layer in original SDK example" echo "CPU_B_SEQ_T_OMP2/THREADS too many threads necessary (256)" if [[ $CMAKE_ARGS =~ -*DALPAKA_ACC_GPU_CUDA_ENABLE=ON.* ]]; then - cmake $cupla_DIR/example/CUDASamples/matrixMul/ \ - $CMAKE_ARGS - make -j - time ./matrixMul -wA=64 -wB=64 -hA=64 -hB=64 - rm -r * ; + time ./example/CUDASamples/matrixMul/matrixMul -wA=64 -wB=64 -hA=64 -hB=64 fi echo "###################################################" @@ -64,28 +63,31 @@ for CONFIG in $(seq 0 $((${#CMAKE_CONFIGS[*]} - 1))); do echo "can not run with CPU_B_SEQ_T_SEQ due to missing elements layer in original SDK example" echo "CPU_B_SEQ_T_OMP2/THREADS too many threads necessary (512)" if [[ $CMAKE_ARGS =~ -*DALPAKA_ACC_GPU_CUDA_ENABLE=ON.* ]]; then - cmake $cupla_DIR/example/CUDASamples/asyncAPI/ \ - $CMAKE_ARGS - make -j - time ./asyncAPI - rm -r * ; + time ./example/CUDASamples/asyncAPI/asyncAPI fi echo "###################################################" echo "# Example Async API (added elements layer)" echo "###################################################" - cmake $cupla_DIR/example/CUDASamples/asyncAPI_tuned/ \ - $CMAKE_ARGS - make -j - time ./asyncAPI_tuned - rm -r * + time ./example/CUDASamples/asyncAPI_tuned/asyncAPI_tuned echo "###################################################" echo "Example vectorAdd (added elements layer)" echo "###################################################" - cmake $cupla_DIR/example/CUDASamples/vectorAdd/ \ - $CMAKE_ARGS - make -j - time ./vectorAdd 100000 - rm -r * ; + time ./example/CUDASamples/vectorAdd/vectorAdd 100000 + + echo "###################################################" + echo "Example cupla vectorAdd (added elements layer)" + echo "###################################################" + time ./example/CUDASamples/cuplaVectorAdd/cuplaVectorAdd 100000 + + + echo "###################################################" + echo "Example blackSchloles" + echo "###################################################" + if [[ $CMAKE_ARGS =~ -*DALPAKA_ACC_GPU_CUDA_ENABLE=ON.* ]]; then + time ./example/CUDASamples/blackScholes/blackScholes + fi + + rm -r * done diff --git a/script/run_test.yml b/script/run_test.yml deleted file mode 100644 index 223a241f7..000000000 --- a/script/run_test.yml +++ /dev/null @@ -1,57 +0,0 @@ -.test_job: - script: - # the default build type is Release - # if neccesary, you can rerun the pipeline with another build type-> https://docs.gitlab.com/ee/ci/pipelines.html#manually-executing-pipelines - # to change the build type, you must set the environment variable CUPLA_BUILD_TYPE - - if [[ ! -v CUPLA_BUILD_TYPE ]] ; then - CUPLA_BUILD_TYPE=Release ; - fi - - echo "number of processor threads $(nproc)" - - $CXX --version - - cmake --version - - echo "Boost version-> $BOOST_VERSION" - - export cupla_DIR=$CI_PROJECT_DIR - # use one build directory for all build configurations - - mkdir build - - cd build - - echo "Build type-> $CUPLA_BUILD_TYPE" - # ALPAKA_ACCS contains the backends, which are used for each build - # the backends are set in the sepcialized base jobs .base_gcc,.base_clang and.base_cuda - - for CMAKE_FLAGS in $ALPAKA_ACCS ; do - echo "###################################################" - && echo "# Example Matrix Multiplication (adapted original)" - && echo "###################################################" - && echo "can not run with CPU_B_SEQ_T_SEQ due to missing elements layer in original SDK example" - && echo "CPU_B_SEQ_T_OMP2/THREADS too many threads necessary (256)" - && if [[ $CMAKE_FLAGS =~ -*DALPAKA_ACC_GPU_CUDA_ENABLE=ON.* ]]; then - cmake $cupla_DIR/example/CUDASamples/matrixMul/ -DBOOST_ROOT=/opt/boost/$BOOST_VERSION $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=$CUPLA_BUILD_TYPE - && make -j - && time ./matrixMul -wA=64 -wB=64 -hA=64 -hB=64 - && rm -r * ; - fi - && echo "###################################################" - && echo "# Example Async API (adapted original)" - && echo "###################################################" - && echo "can not run with CPU_B_SEQ_T_SEQ due to missing elements layer in original SDK example" - && echo "CPU_B_SEQ_T_OMP2/THREADS too many threads necessary (512)" - && if [[ $CMAKE_FLAGS =~ -*DALPAKA_ACC_GPU_CUDA_ENABLE=ON.* ]]; then - cmake $cupla_DIR/example/CUDASamples/asyncAPI/ -DBOOST_ROOT=/opt/boost/$BOOST_VERSION $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=$CUPLA_BUILD_TYPE - && make -j - && time ./asyncAPI - && rm -r * ; - fi - && echo "###################################################" - && echo "# Example Async API (added elements layer)" - && echo "###################################################" - && cmake $cupla_DIR/example/CUDASamples/asyncAPI_tuned/ -DBOOST_ROOT=/opt/boost/$BOOST_VERSION $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=$CUPLA_BUILD_TYPE - && make -j - && time ./asyncAPI_tuned - && rm -r * - && echo "###################################################" - && echo "Example vectorAdd (added elements layer)" - && echo "###################################################" - && cmake $cupla_DIR/example/CUDASamples/vectorAdd/ -DBOOST_ROOT=/opt/boost/$BOOST_VERSION $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=$CUPLA_BUILD_TYPE - && make -j - && time ./vectorAdd 100000 - && rm -r * ; - done diff --git a/Findcupla.cmake b/test/integration/cupla_add_subdirectory.cmake similarity index 67% rename from Findcupla.cmake rename to test/integration/cupla_add_subdirectory.cmake index 56bc4741d..ffe6a4759 100644 --- a/Findcupla.cmake +++ b/test/integration/cupla_add_subdirectory.cmake @@ -1,5 +1,5 @@ # -# Copyright 2016 Rene Widera, Benjamin Worpitz +# Copyright 2021 Simeon Ehrig # # This file is part of cupla. # @@ -18,14 +18,11 @@ # If not, see . # -find_path( - _cupla_ROOT_DIR - NAMES "include/cuda_to_cupla.hpp" - HINTS "${cupla_ROOT}" ENV CUPLA_ROOT - DOC "cupla ROOT location") +cmake_minimum_required(VERSION 3.18.0) +project(cuplaVectorAdd) -if(_cupla_ROOT_DIR) - include("${_cupla_ROOT_DIR}/cuplaConfig.cmake") -else() - message(FATAL_ERROR "cupla could not be found!") -endif() +add_subdirectory(cupla) + +cupla_add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/vectorAdd.cpp) + +install(TARGETS ${PROJECT_NAME}) diff --git a/test/integration/cupla_find_package.cmake b/test/integration/cupla_find_package.cmake new file mode 100644 index 000000000..ef064b1c0 --- /dev/null +++ b/test/integration/cupla_find_package.cmake @@ -0,0 +1,28 @@ +# +# Copyright 2021 Simeon Ehrig +# +# This file is part of cupla. +# +# cupla is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cupla is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with cupla. +# If not, see . +# + +cmake_minimum_required(VERSION 3.18.0) +project(cuplaVectorAdd) + +find_package(cupla) + +cupla_add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/vectorAdd.cpp) + +install(TARGETS ${PROJECT_NAME})