From 6703858a58cba12bf788ab53d21402706cf1872b Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:51 +0000 Subject: [PATCH 01/46] Add DEB packaging --- .github/workflows/presubmit.yml | 15 ++++++----- .github/workflows/release.yml | 22 +++++++++++++--- .gitignore | 11 ++++++-- CMakeLists.txt | 1 + cmake/Package.cmake | 46 +++++++++++++++++++++++++++++++++ external/OpenCL-CLHPP | 2 +- external/OpenCL-ICD-Loader | 2 +- 7 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 cmake/Package.cmake diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 03bca891..ef58b168 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -6,7 +6,7 @@ jobs: name: Code formatting runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Install clang-format @@ -23,7 +23,7 @@ jobs: compiler: [gcc, clang] deps: [os, fetch, vcpkg] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 submodules: recursive @@ -31,8 +31,9 @@ jobs: run: | if [[ "${{ matrix.os }}" == "ubuntu-20.04" ]]; then sudo apt update - sudo apt install -y libidn11 libx11-dev libxrandr-dev libxcursor-dev libxi-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libudev-dev \ - `if [[ "${{matrix.deps}}" == "os" ]]; then echo libtclap-dev libglm-dev libglew-dev libsfml-dev libstb-dev; fi;` + sudo apt install -y libidn11 libx11-dev libxrandr-dev libxi-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libudev-dev \ + `if [[ "${{matrix.deps}}" == "os" ]]; then echo libtclap-dev libglm-dev libglew-dev libsfml-dev libstb-dev; fi;` \ + `if [[ "${{matrix.deps}}" == "vcpkg" ]]; then echo autoconf libtool libxcursor-dev; fi;` if [[ "${{matrix.deps}}" == "vcpkg" ]]; then git clone https://github.com/Microsoft/vcpkg.git ./vcpkg/bootstrap-vcpkg.sh @@ -75,7 +76,7 @@ jobs: matrix: deps: [fetch, vcpkg] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 submodules: recursive @@ -107,7 +108,7 @@ jobs: os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Environment setup run: | MINIFORGE_INSTALL_DIR=.miniforge3 @@ -144,7 +145,7 @@ jobs: #os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-13] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 submodules: recursive diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f92c392d..52a22ba7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout OpenCL-SDK - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Initialize git submodules shell: pwsh @@ -69,7 +69,7 @@ jobs: /verbosity:minimal ` /noLogo ` } - + - name: Package Binary shell: pwsh run: | @@ -95,9 +95,12 @@ jobs: matrix: OS: [ubuntu-20.04, windows-2022] + env: + DEB_INSTALLATION_PATH: /usr + steps: - name: Checkout OpenCL-SDK - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Initialize git submodules shell: pwsh @@ -117,6 +120,7 @@ jobs: -D OPENCL_SDK_BUILD_SAMPLES=OFF ` -D OPENCL_ICD_LOADER_BUILD_TESTING=OFF ` -D CMAKE_POLICY_DEFAULT_CMP0096=NEW + -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH - name: Check version number shell: pwsh @@ -127,6 +131,16 @@ jobs: )) ` { throw 'CMake project version mismatches Git tag name (without leading "v")'} + - name: Package DEB + shell: pwsh + if: ${{ contains(matrix.OS, 'ubuntu') }} + run: | + cpack + --config "${env:GITHUB_WORKSPACE}/build/CPackSourceConfig.cmake" ` + -G DEB + -C Release + "${env:GITHUB_WORKSPACE}/package-deb" + - name: Package Source shell: pwsh run: | @@ -145,4 +159,4 @@ jobs: with: draft: true files: | - package/OpenCL-SDK-${{github.ref_name}}-Source.* \ No newline at end of file + package/OpenCL-SDK-${{github.ref_name}}-Source.* diff --git a/.gitignore b/.gitignore index adacb9e4..db6026c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,12 @@ -build/ -install/ +# Build dir +[Bb]uild/ + +# Install dir +[Ii]nstall/ + +# Package dirs +[Pp]ackage/ +[Pp]ackage-deb/ # vim *~ diff --git a/CMakeLists.txt b/CMakeLists.txt index cdaa68bf..cc47a34a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules ) include(Dependencies) +include(Package) if(OPENCL_SDK_BUILD_UTILITY_LIBRARIES) add_subdirectory(lib) endif() diff --git a/cmake/Package.cmake b/cmake/Package.cmake new file mode 100644 index 00000000..c6df2b05 --- /dev/null +++ b/cmake/Package.cmake @@ -0,0 +1,46 @@ +set(CPACK_PACKAGE_VENDOR "khronos") + +set(CPACK_DEBIAN_DESCRIPTION "Khronos OpenCL Software Development Kit") + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") + +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") + +if(NOT CPACK_PACKAGING_INSTALL_PREFIX) + set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +endif() + +# DEB packaging configuration +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_ALL binary) + +set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_VENDOR}) + +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE + "https://github.com/KhronosGroup/OpenCL-SDK") + +# Version number [epoch:]upstream_version[-debian_revision] +set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}") # upstream_version +set(CPACK_DEBIAN_PACKAGE_RELEASE "1") # debian_revision (because this is a + # non-native pkg) +set(PACKAGE_VERSION_REVISION "${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}") + +# Get architecture +execute_process(COMMAND dpkg "--print-architecture" OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE) +string(STRIP "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" CPACK_DEBIAN_PACKAGE_ARCHITECTURE) + +## Package runtime component +set(DEBIAN_PACKAGE_NAME "opencl-sdk") + +set(CPACK_DEBIAN_BINARY_PACKAGE_NAME + "${DEBIAN_PACKAGE_NAME}" + CACHE STRING "Package name" FORCE) + +# Package file name in deb format: +# _-_.deb +set(CPACK_DEBIAN_BINARY_FILE_NAME "${CPACK_PACKAGE_VENDOR}-${CPACK_DEBIAN_BINARY_PACKAGE_NAME}_${PACKAGE_VERSION_REVISION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") + +# Replacements +set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers (>= 3.0~2021.04.29), opencl-clhpp-headers (>= 3.0~2021.04.29), ocl-icd-opencl-dev (>= 3.0)") + +set(CPACK_DEBIAN_PACKAGE_DEBUG ON) diff --git a/external/OpenCL-CLHPP b/external/OpenCL-CLHPP index 0bdbbfe5..1c92cd31 160000 --- a/external/OpenCL-CLHPP +++ b/external/OpenCL-CLHPP @@ -1 +1 @@ -Subproject commit 0bdbbfe5ecda42cff50c96cc5e33527f42fcbd45 +Subproject commit 1c92cd31171b95ed01201cdb3451a555a6c43a68 diff --git a/external/OpenCL-ICD-Loader b/external/OpenCL-ICD-Loader index 861b68b2..a845947e 160000 --- a/external/OpenCL-ICD-Loader +++ b/external/OpenCL-ICD-Loader @@ -1 +1 @@ -Subproject commit 861b68b290e76d08e7241608479c16431f529945 +Subproject commit a845947effa4352fa010d813aa211c7be0b29865 From 4473ce0dbc045476d5f3ed69116eaec15158254f Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:52 +0000 Subject: [PATCH 02/46] Update check-format script --- .github/workflows/presubmit.yml | 21 +++++- scripts/check-format.sh | 111 +++++++++++++++++++++++++++++--- 2 files changed, 120 insertions(+), 12 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index ef58b168..80f2ebd3 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -2,15 +2,32 @@ name: Presubmit on: [push, pull_request] jobs: + get-branch: + runs-on: ubuntu-latest + steps: + - name: Get working branch + id: get-branch + run: | + if [[ ${{ github.event_name }} == "push" ]]; then + echo "branch=main" >> $GITHUB_OUTPUT + else + echo "branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT + fi ; + echo $GITHUB_OUTPUT + outputs: + branch: ${{ steps.get-branch.outputs.branch }} + format: name: Code formatting - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest + needs: get-branch steps: - uses: actions/checkout@v3 with: + # repository: ${{ github.repository }} (default) fetch-depth: 0 - name: Install clang-format - run: sudo apt-get install clang-format clang-format-9 + run: sudo apt-get install clang-format - name: Check format run: ./scripts/check-format.sh build: diff --git a/scripts/check-format.sh b/scripts/check-format.sh index 2a9a78ff..d7096528 100755 --- a/scripts/check-format.sh +++ b/scripts/check-format.sh @@ -1,19 +1,110 @@ #!/usr/bin/env bash -# Arg used to specify non-'origin/main' comparison branch -ORIGIN_BRANCH=${1:-"origin/main"} +SOURCE_COMMIT="$1" +if [ "$#" -gt 0 ]; then + shift +fi + +# If no source commit is given target the default branch +if [ "x$SOURCE_COMMIT" = "x" ]; then + # If remote is not set use the remote of the current branch or fallback to "origin" + if [ "x$REMOTE" = "x" ]; then + BRANCH="$(git rev-parse --abbrev-ref HEAD)" + REMOTE="$(git config --local --get "branch.$BRANCH.remote" || echo 'origin')" + fi + SOURCE_COMMIT="remotes/$REMOTE/HEAD" +fi -# Run git-clang-format to check for violations -if [ "$TRAVIS" == "true" ]; then - EXTRA_OPTS="--binary `which clang-format-9`" +# Force colored diff output +DIFF_COLOR_SAVED="$(git config --local --get color.diff)" +if [ "x$DIFF_COLOR_SAVED" != "x" ]; then + git config --local --replace-all "color.diff" "always" +else + git config --local --add "color.diff" "always" fi -CLANG_FORMAT_OUTPUT=$(git-clang-format --diff $ORIGIN_BRANCH --extensions c,cpp,h,hpp $EXTRA_OPTS) + +scratch="$(mktemp -t check-format.XXXXXXXXXX)" +finish () { + # Remove temporary file + rm -rf "$scratch" + # Restore setting + if [ "x$DIFF_COLOR_SAVED" != "x" ]; then + git config --local --replace-all "color.diff" "$DIFF_COLOR_SAVED" + else + git config --local --unset "color.diff" + fi +} +# The trap will be invoked whenever the script exits, even due to a signal, this is a bash only +# feature +trap finish EXIT + +GIT_CLANG_FORMAT="${GIT_CLANG_FORMAT:-git-clang-format}" +"$GIT_CLANG_FORMAT" --style=file --extensions=cc,cp,cpp,c++,cxx,cu,cuh,hh,hpp,hxx,hip,vert,frag --diff "$@" "$SOURCE_COMMIT" > "$scratch" # Check for no-ops -grep '^no modified files to format$' <<<"$CLANG_FORMAT_OUTPUT" && exit 0 -grep '^clang-format did not modify any files$' <<<"$CLANG_FORMAT_OUTPUT" && exit 0 +grep '^no modified files to format$\|^clang-format did not modify any files$' \ + "$scratch" > /dev/null && exit 0 # Dump formatting diff and signal failure -echo -e "\n==== FORMATTING VIOLATIONS DETECTED ====\n" -echo "$CLANG_FORMAT_OUTPUT" +printf \ +"\033[31m==== FORMATTING VIOLATIONS DETECTED ====\033[0m +run '\033[33m%s --style=file %s %s\033[0m' to apply these formating changes\n\n" \ +"$GIT_CLANG_FORMAT" "$*" "$SOURCE_COMMIT" + +cat "$scratch" +exit 1 +#!/usr/bin/env bash + +SOURCE_COMMIT="$1" +if [ "$#" -gt 0 ]; then + shift +fi + +# If no source commit is given target the default branch +if [ "x$SOURCE_COMMIT" = "x" ]; then + # If remote is not set use the remote of the current branch or fallback to "origin" + if [ "x$REMOTE" = "x" ]; then + BRANCH="$(git rev-parse --abbrev-ref HEAD)" + REMOTE="$(git config --local --get "branch.$BRANCH.remote" || echo 'origin')" + fi + SOURCE_COMMIT="remotes/$REMOTE/HEAD" +fi + +# Force colored diff output +DIFF_COLOR_SAVED="$(git config --local --get color.diff)" +if [ "x$DIFF_COLOR_SAVED" != "x" ]; then + git config --local --replace-all "color.diff" "always" +else + git config --local --add "color.diff" "always" +fi + +scratch="$(mktemp -t check-format.XXXXXXXXXX)" +finish () { + # Remove temporary file + rm -rf "$scratch" + # Restore setting + if [ "x$DIFF_COLOR_SAVED" != "x" ]; then + git config --local --replace-all "color.diff" "$DIFF_COLOR_SAVED" + else + git config --local --unset "color.diff" + fi +} +# The trap will be invoked whenever the script exits, even due to a signal, this is a bash only +# feature +trap finish EXIT + +GIT_CLANG_FORMAT="${GIT_CLANG_FORMAT:-git-clang-format}" +"$GIT_CLANG_FORMAT" --style=file --extensions=cc,cp,cpp,c++,cxx,cu,cuh,hh,hpp,hxx,hip,vert,frag --diff "$@" "$SOURCE_COMMIT" > "$scratch" + +# Check for no-ops +grep '^no modified files to format$\|^clang-format did not modify any files$' \ + "$scratch" > /dev/null && exit 0 + +# Dump formatting diff and signal failure +printf \ +"\033[31m==== FORMATTING VIOLATIONS DETECTED ====\033[0m +run '\033[33m%s --style=file %s %s\033[0m' to apply these formating changes\n\n" \ +"$GIT_CLANG_FORMAT" "$*" "$SOURCE_COMMIT" + +cat "$scratch" exit 1 From 7f032c6a4ab32e561edab0436f6958a9ac8a757d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:24:53 +0000 Subject: [PATCH 03/46] Android build in CI --- .github/workflows/presubmit.yml | 232 ++++++++++++++++++++++++- cmake/Modules/FindStb.cmake | 3 +- cmake/Modules/FindTCLAP.cmake | 1 + lib/include/CL/Utils/Event.h | 2 +- lib/src/Extensions/src/openclext.cpp | 5 - samples/core/binaries/main.c | 2 +- samples/core/blur/blur.hpp | 2 +- samples/core/copybuffer/main.cpp | 4 +- samples/core/copybufferkernel/main.cpp | 4 +- samples/core/enumopencl/main.c | 2 +- samples/core/reduce/main.c | 4 +- 11 files changed, 244 insertions(+), 17 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 80f2ebd3..18ce7a2b 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -29,7 +29,197 @@ jobs: - name: Install clang-format run: sudo apt-get install clang-format - name: Check format - run: ./scripts/check-format.sh + run: $GITHUB_WORKSPACE/scripts/check-format.sh origin/${{ needs.get-branch.outputs.branch }} --binary clang-format + + linux: + if: false + runs-on: ubuntu-latest + needs: format + strategy: + matrix: + CMAKE: [3.26.4] + COMPILER: + - C_NAME: gcc + CXX_NAME: g++ + VER: 11 + # - C_NAME: gcc + # CXX_NAME: g++ + # VER: 13 + # - C_NAME: clang + # CXX_NAME: clang++ + # VER: 14 + # - C_NAME: clang + # CXX_NAME: clang++ + # VER: 16 + DEPS: [os, vcpkg] + BIN: [64] + STD: [11, 17] + CONF: + - GEN: Unix Makefiles + CONFIG: Debug + IMAGE: + - streamhpc/opencl-sdk-base:ubuntu-22.04-20230717 + container: ${{matrix.IMAGE}} + env: + CMAKE_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cmake + CPACK_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cpack + CTEST_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/ctest + DEB_INSTALLATION_PATH: /usr + CC: ${{matrix.COMPILER.C_NAME}}-${{matrix.COMPILER.VER}} + CXX: ${{matrix.COMPILER.CXX_NAME}}-${{matrix.COMPILER.VER}} + + steps: + - name: Checkout OpenCL-SDK + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + + - name: Configure, package & install OpenCL-Headers + shell: bash + run: $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + -D BUILD_TESTING=OFF + -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH + -S $GITHUB_WORKSPACE/external/OpenCL-Headers + -B $GITHUB_WORKSPACE/external/OpenCL-Headers/build && + $CPACK_EXE + --config "$GITHUB_WORKSPACE/external/OpenCL-Headers/build/CPackConfig.cmake" + -G DEB + -C ${{matrix.CONF.CONFIG}} + -B "$GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb" && + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb/*.deb + + - name: Configure, package & install OpenCL-ICD-Loader + run: $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D ${{matrix.CONF.CONFIG}}"; fi` + -D BUILD_TESTING=OFF + -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH + -S $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader + -B $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build && + $CPACK_EXE + --config "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build/CPackConfig.cmake" + -G DEB + -C ${{matrix.CONF.CONFIG}} + -B "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb" && + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb && + dpkg -c $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/ocl-icd-opencl-dev_3.0-1_amd64.deb + + - name: Configure, package & install OpenCL-CLHPP + shell: bash + run: $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + -D BUILD_TESTING=OFF + -D BUILD_EXAMPLES=OFF + -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH + -S $GITHUB_WORKSPACE/external/OpenCL-CLHPP + -B $GITHUB_WORKSPACE/external/OpenCL-CLHPP/build && + $CPACK_EXE + --config "$GITHUB_WORKSPACE/external/OpenCL-CLHPP/build/CPackConfig.cmake" + -G DEB + -C ${{matrix.CONF.CONFIG}} + -B "$GITHUB_WORKSPACE/external/OpenCL-CLHPP/package-deb" && + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-CLHPP/package-deb/*.deb + + - name: Configure + shell: bash + run: if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; + then + git clone https://github.com/Microsoft/vcpkg.git; + ./vcpkg/bootstrap-vcpkg.sh; + ./vcpkg/vcpkg install sfml tclap glm glew stb; + TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; + else + TOOLCHAIN_ARG=""; + fi && + mkdir $GITHUB_WORKSPACE/build && cd $GITHUB_WORKSPACE/build && + $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + -D BUILD_DOCS=ON + -D BUILD_TESTING=ON + -D BUILD_EXAMPLES=ON + -D OPENCL_SDK_BUILD_SAMPLES=OFF + -D OPENCL_ICD_LOADER_BUILD_TESTING=ON + -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install + -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH + $GITHUB_WORKSPACE + + - name: Build + shell: bash + run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/build -- -j`nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Debug -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Release -- -j`nproc`; + fi; + + - name: Test + shell: bash + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CTEST_EXE --output-on-failure --parallel `nproc`; + else + $CTEST_EXE --output-on-failure -C Debug --parallel `nproc`; + $CTEST_EXE --output-on-failure -C Release --parallel `nproc`; + fi; + + - name: Package DEB + shell: bash + run: $CPACK_EXE + --config "$GITHUB_WORKSPACE/build/CPackConfig.cmake" + -G DEB + -C ${{matrix.CONF.CONFIG}} + -B "$GITHUB_WORKSPACE/package-deb" && + dpkg -c $GITHUB_WORKSPACE/package-deb/khronos-opencl-sdk_2023.4.17-1_amd64.deb + + - name: Consume (DEB) + shell: bash + run: dpkg -i $GITHUB_WORKSPACE/package-deb/*.deb && + mkdir $GITHUB_WORKSPACE/build_package && + cd $GITHUB_WORKSPACE/build_package && + $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil && + if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package -- -j`nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Debug -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Release -- -j`nproc`; + fi; + + - name: Uninstall (DEB) + shell: bash + run: apt-get remove -y ocl-icd-opencl-dev ocl-icd-libopencl1 opencl-c-headers opencl-clhpp-headers opencl-sdk + + - name: Test install + shell: bash + run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} -- -j`nproc` && + ls -lR $GITHUB_WORKSPACE/install + + - name: Consume (install) + shell: bash + run: mkdir $GITHUB_WORKSPACE/build_install && cd $GITHUB_WORKSPACE/build_install && + $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + -D CMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/install + $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil && + if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install -- -j`nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Debug -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Release -- -j`nproc`; + fi; + build: needs: format name: Build ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.deps }} @@ -179,3 +369,43 @@ jobs: - name: Run Ruby Samples run: rake test working-directory: ruby + + android: + runs-on: ubuntu-latest + needs: format + strategy: + matrix: + ABI: + - arm64-v8a + - x86_64 + API_LEVEL: + - android-29 + - android-33 + CONFIG: + - Debug + - Release + env: + CFLAGS: -Wall -Wextra -pedantic -Werror -Wno-error=gnu-statement-expression + CXXFLAGS: -Wall -Wextra -pedantic -Werror -Wno-error=missing-field-initializers + steps: + - name: Checkout OpenCL-SDK + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + + - name: Configure + shell: bash + run: cmake + -G "Unix Makefiles" + -D CMAKE_BUILD_TYPE=${{matrix.CONFIG}} + -D CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake + -D ANDROID_ABI=${{matrix.ABI}} + -D ANDROID_PLATFORM=${{matrix.API_LEVEL}} + -D OPENCL_SDK_BUILD_OPENGL_SAMPLES=OFF + -S $GITHUB_WORKSPACE + -B $GITHUB_WORKSPACE/build + + - name: Build + shell: bash + run: cmake --build $GITHUB_WORKSPACE/build --parallel `nproc` diff --git a/cmake/Modules/FindStb.cmake b/cmake/Modules/FindStb.cmake index bafa70a8..e8673a2e 100644 --- a/cmake/Modules/FindStb.cmake +++ b/cmake/Modules/FindStb.cmake @@ -16,7 +16,8 @@ find_path (Stb_INCLUDE_PATH stb_image.h PATH_SUFFIXES include include/stb - ) + NO_CMAKE_FIND_ROOT_PATH +) # handle the QUIETLY and REQUIRED arguments and set Stb_FOUND to # TRUE if all listed variables are TRUE diff --git a/cmake/Modules/FindTCLAP.cmake b/cmake/Modules/FindTCLAP.cmake index 2e55bd14..c2e05c74 100644 --- a/cmake/Modules/FindTCLAP.cmake +++ b/cmake/Modules/FindTCLAP.cmake @@ -14,6 +14,7 @@ find_path (TCLAP_INCLUDE_PATH tclap/CmdLine.h PATHS ${CMAKE_SOURCE_DIR}/include ${CMAKE_INSTALL_PREFIX}/include + NO_CMAKE_FIND_ROOT_PATH ) # handle the QUIETLY and REQUIRED arguments and set TCLAP_FOUND to diff --git a/lib/include/CL/Utils/Event.h b/lib/include/CL/Utils/Event.h index f144e215..0cd45ca0 100644 --- a/lib/include/CL/Utils/Event.h +++ b/lib/include/CL/Utils/Event.h @@ -10,4 +10,4 @@ UTILS_EXPORT cl_ulong cl_util_get_event_duration(const cl_event event, const cl_profiling_info start, const cl_profiling_info end, - cl_int* const error); \ No newline at end of file + cl_int* const error); diff --git a/lib/src/Extensions/src/openclext.cpp b/lib/src/Extensions/src/openclext.cpp index 384e91ed..c4f3afd5 100644 --- a/lib/src/Extensions/src/openclext.cpp +++ b/lib/src/Extensions/src/openclext.cpp @@ -64,11 +64,6 @@ #include -static inline cl_platform_id _get_platform(cl_platform_id platform) -{ - return platform; -} - static inline cl_platform_id _get_platform(cl_device_id device) { if (device == nullptr) return nullptr; diff --git a/samples/core/binaries/main.c b/samples/core/binaries/main.c index b9d5f5bb..c78276ff 100644 --- a/samples/core/binaries/main.c +++ b/samples/core/binaries/main.c @@ -159,7 +159,7 @@ int main(int argc, char *argv[]) cl_platform_id platform; cl_device_id device; cl_context context; - cl_command_queue queue; + cl_command_queue queue = NULL; cl_program program; diff --git a/samples/core/blur/blur.hpp b/samples/core/blur/blur.hpp index 160dbed9..ccfd0c0c 100644 --- a/samples/core/blur/blur.hpp +++ b/samples/core/blur/blur.hpp @@ -11,7 +11,7 @@ class BlurCppExample { public: BlurCppExample(int argc, char* argv[]) - : gauss_kernel(nullptr), origin({ 0, 0 }) + : origin({ 0, 0 }), gauss_kernel(nullptr) { parse_command_line(argc, argv); } diff --git a/samples/core/copybuffer/main.cpp b/samples/core/copybuffer/main.cpp index 5429afa6..3c971ee3 100644 --- a/samples/core/copybuffer/main.cpp +++ b/samples/core/copybuffer/main.cpp @@ -100,7 +100,7 @@ int main(int argc, char** argv) if (!strcmp(argv[i], "-d")) { ++i; - if (i < argc) + if (i < static_cast(argc)) { deviceIndex = strtoul(argv[i], NULL, 10); } @@ -108,7 +108,7 @@ int main(int argc, char** argv) else if (!strcmp(argv[i], "-p")) { ++i; - if (i < argc) + if (i < static_cast(argc)) { platformIndex = strtoul(argv[i], NULL, 10); } diff --git a/samples/core/copybufferkernel/main.cpp b/samples/core/copybufferkernel/main.cpp index 1b14cfc2..d4314f9e 100644 --- a/samples/core/copybufferkernel/main.cpp +++ b/samples/core/copybufferkernel/main.cpp @@ -111,7 +111,7 @@ int main(int argc, char** argv) if (!strcmp(argv[i], "-d")) { ++i; - if (i < argc) + if (i < static_cast(argc)) { deviceIndex = strtoul(argv[i], NULL, 10); } @@ -119,7 +119,7 @@ int main(int argc, char** argv) else if (!strcmp(argv[i], "-p")) { ++i; - if (i < argc) + if (i < static_cast(argc)) { platformIndex = strtoul(argv[i], NULL, 10); } diff --git a/samples/core/enumopencl/main.c b/samples/core/enumopencl/main.c index 697c2e2d..c2676c26 100644 --- a/samples/core/enumopencl/main.c +++ b/samples/core/enumopencl/main.c @@ -195,7 +195,7 @@ static cl_int PrintDeviceInfoSummary(cl_device_id* devices, cl_uint numDevices) return errorCode; } -int main(int argc, char** argv) +int main(void) { cl_uint numPlatforms = 0; clGetPlatformIDs(0, NULL, &numPlatforms); diff --git a/samples/core/reduce/main.c b/samples/core/reduce/main.c index a9c8b1fa..b4acbd31 100644 --- a/samples/core/reduce/main.c +++ b/samples/core/reduce/main.c @@ -232,13 +232,13 @@ cl_int accumulate(cl_int *arr, size_t len, cl_int zero_elem, cl_ulong new_size(const cl_ulong actual, const cl_ulong factor) { return actual / factor + (actual % factor == 0 ? 0 : 1); -}; +} // NOTE: because one work-group produces one output // new_size == number_of_work_groups size_t global(const size_t actual, const cl_ulong factor, const size_t wgs) { return new_size(actual, factor) * wgs; -}; +} // Random number generator state pcg32_random_t rng; From d7fde2b60dc752f044fab03363d54425712bd27d Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:53 +0000 Subject: [PATCH 04/46] Add linux CI --- .github/workflows/presubmit.yml | 38 +++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 18ce7a2b..f60baa3e 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -1,4 +1,5 @@ name: Presubmit + on: [push, pull_request] jobs: @@ -32,7 +33,6 @@ jobs: run: $GITHUB_WORKSPACE/scripts/check-format.sh origin/${{ needs.get-branch.outputs.branch }} --binary clang-format linux: - if: false runs-on: ubuntu-latest needs: format strategy: @@ -42,23 +42,27 @@ jobs: - C_NAME: gcc CXX_NAME: g++ VER: 11 - # - C_NAME: gcc - # CXX_NAME: g++ - # VER: 13 - # - C_NAME: clang - # CXX_NAME: clang++ - # VER: 14 - # - C_NAME: clang - # CXX_NAME: clang++ - # VER: 16 + - C_NAME: gcc + CXX_NAME: g++ + VER: 13 + - C_NAME: clang + CXX_NAME: clang++ + VER: 14 + - C_NAME: clang + CXX_NAME: clang++ + VER: 16 DEPS: [os, vcpkg] BIN: [64] STD: [11, 17] CONF: - GEN: Unix Makefiles CONFIG: Debug + - GEN: Unix Makefiles + CONFIG: Release + - GEN: Ninja Multi-Config + CONFIG: Release IMAGE: - - streamhpc/opencl-sdk-base:ubuntu-22.04-20230717 + - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 container: ${{matrix.IMAGE}} env: CMAKE_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cmake @@ -67,6 +71,8 @@ jobs: DEB_INSTALLATION_PATH: /usr CC: ${{matrix.COMPILER.C_NAME}}-${{matrix.COMPILER.VER}} CXX: ${{matrix.COMPILER.CXX_NAME}}-${{matrix.COMPILER.VER}} + CFLAGS: -Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} + CXXFLAGS: -Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} steps: - name: Checkout OpenCL-SDK @@ -180,7 +186,8 @@ jobs: - name: Consume (DEB) shell: bash - run: dpkg -i $GITHUB_WORKSPACE/package-deb/*.deb && + run: dpkg -i $GITHUB_WORKSPACE/external/OpenCL-*/package-deb/*.deb && + dpkg -i --force-overwrite $GITHUB_WORKSPACE/package-deb/*.deb && mkdir $GITHUB_WORKSPACE/build_package && cd $GITHUB_WORKSPACE/build_package && $CMAKE_EXE @@ -201,8 +208,7 @@ jobs: - name: Test install shell: bash - run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} -- -j`nproc` && - ls -lR $GITHUB_WORKSPACE/install + run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} -- -j`nproc`; - name: Consume (install) shell: bash @@ -221,6 +227,7 @@ jobs: fi; build: + if: false needs: format name: Build ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.deps }} runs-on: ${{ matrix.os }} @@ -276,6 +283,7 @@ jobs: --verbose \ --parallel `numproc` buildwin: + if: false needs: format name: Build Windows ${{ matrix.deps }} runs-on: windows-latest @@ -308,6 +316,7 @@ jobs: /noLogo python: + if: false name: Exercise Python examples on ${{matrix.os}} strategy: matrix: @@ -345,6 +354,7 @@ jobs: done checkruby: + if: false name: Check Ruby Samples ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: From f3b634695c11112a9e19c7ab949d665f83898246 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:54 +0000 Subject: [PATCH 05/46] Remove the C headers, C++ headers and loader from the SDK deb package --- .github/workflows/presubmit.yml | 49 +++++++++++++++---------------- .gitignore | 3 ++ CMakeLists.txt | 2 ++ lib/CMakeLists.txt | 13 ++++++++ lib/src/Extensions/CMakeLists.txt | 11 +++++++ 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index f60baa3e..f925b446 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -42,15 +42,15 @@ jobs: - C_NAME: gcc CXX_NAME: g++ VER: 11 - - C_NAME: gcc - CXX_NAME: g++ - VER: 13 - - C_NAME: clang - CXX_NAME: clang++ - VER: 14 - - C_NAME: clang - CXX_NAME: clang++ - VER: 16 + # - C_NAME: gcc + # CXX_NAME: g++ + # VER: 13 + # - C_NAME: clang + # CXX_NAME: clang++ + # VER: 14 + # - C_NAME: clang + # CXX_NAME: clang++ + # VER: 16 DEPS: [os, vcpkg] BIN: [64] STD: [11, 17] @@ -59,10 +59,10 @@ jobs: CONFIG: Debug - GEN: Unix Makefiles CONFIG: Release - - GEN: Ninja Multi-Config - CONFIG: Release + # - GEN: Ninja Multi-Config + # CONFIG: Release IMAGE: - - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 + - streamhpc/opencl-sdk-base:ubuntu-22.04-20230717 container: ${{matrix.IMAGE}} env: CMAKE_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cmake @@ -98,9 +98,10 @@ jobs: dpkg -i $GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb/*.deb - name: Configure, package & install OpenCL-ICD-Loader + shell: bash run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D ${{matrix.CONF.CONFIG}}"; fi` + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D BUILD_TESTING=OFF -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH -S $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader @@ -110,8 +111,7 @@ jobs: -G DEB -C ${{matrix.CONF.CONFIG}} -B "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb" && - dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb && - dpkg -c $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/ocl-icd-opencl-dev_3.0-1_amd64.deb + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb - name: Configure, package & install OpenCL-CLHPP shell: bash @@ -141,7 +141,6 @@ jobs: else TOOLCHAIN_ARG=""; fi && - mkdir $GITHUB_WORKSPACE/build && cd $GITHUB_WORKSPACE/build && $CMAKE_EXE -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` @@ -152,7 +151,8 @@ jobs: -D OPENCL_ICD_LOADER_BUILD_TESTING=ON -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH - $GITHUB_WORKSPACE + -S $GITHUB_WORKSPACE + -B $GITHUB_WORKSPACE/build - name: Build shell: bash @@ -186,14 +186,13 @@ jobs: - name: Consume (DEB) shell: bash - run: dpkg -i $GITHUB_WORKSPACE/external/OpenCL-*/package-deb/*.deb && - dpkg -i --force-overwrite $GITHUB_WORKSPACE/package-deb/*.deb && - mkdir $GITHUB_WORKSPACE/build_package && - cd $GITHUB_WORKSPACE/build_package && + run: dpkg -i $GITHUB_WORKSPACE/package-deb/*.deb && $CMAKE_EXE + --debug-find -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` - $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil && + -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil + -B $GITHUB_WORKSPACE/build_package && if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package -- -j`nproc`; @@ -208,12 +207,12 @@ jobs: - name: Test install shell: bash - run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} -- -j`nproc`; + run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} -- -j`nproc` && + ls -lR $GITHUB_WORKSPACE/install - name: Consume (install) shell: bash - run: mkdir $GITHUB_WORKSPACE/build_install && cd $GITHUB_WORKSPACE/build_install && - $CMAKE_EXE + run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D CMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/install diff --git a/.gitignore b/.gitignore index db6026c8..2cbf6017 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ [Pp]ackage/ [Pp]ackage-deb/ +# Cmake +CMakeFiles/ + # vim *~ .*.sw[op] diff --git a/CMakeLists.txt b/CMakeLists.txt index cc47a34a..ec38ac21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ set(config_package_location ${CMAKE_INSTALL_DATADIR}/cmake/OpenCL) install( FILES ${PROJECT_BINARY_DIR}/OpenCL/OpenCLConfig.cmake DESTINATION ${config_package_location} + COMPONENT binary ) unset(CMAKE_SIZEOF_VOID_P) @@ -84,6 +85,7 @@ write_basic_package_version_file( install( FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCL/OpenCLConfigVersion.cmake DESTINATION ${config_package_location} + COMPONENT binary ) include(CPack) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e605c8ff..dfb336db 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -66,14 +66,17 @@ foreach(UTIL_LIB_NAME IN ITEMS Utils UtilsCpp) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT binary ) install( DIRECTORY include/CL/Utils DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CL + COMPONENT binary ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/OpenCL${UTIL_LIB_NAME}_Export.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CL/Utils + COMPONENT binary ) export( EXPORT OpenCL${UTIL_LIB_NAME}Targets @@ -91,10 +94,12 @@ foreach(UTIL_LIB_NAME IN ITEMS Utils UtilsCpp) FILE OpenCL${UTIL_LIB_NAME}Targets.cmake NAMESPACE OpenCL:: DESTINATION ${config_package_location} + COMPONENT binary ) install( FILES ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME}/OpenCL${UTIL_LIB_NAME}Config.cmake DESTINATION ${config_package_location} + COMPONENT binary ) unset(CMAKE_SIZEOF_VOID_P) @@ -107,6 +112,14 @@ foreach(UTIL_LIB_NAME IN ITEMS Utils UtilsCpp) install( FILES ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/cmake/OpenCL${UTIL_LIB_NAME}/OpenCL${UTIL_LIB_NAME}ConfigVersion.cmake DESTINATION ${config_package_location} + COMPONENT binary + ) + + # For packaging the utils libraries + install( + TARGETS ${UTIL_LIB_TARGET} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT binary ) endforeach() diff --git a/lib/src/Extensions/CMakeLists.txt b/lib/src/Extensions/CMakeLists.txt index 4bb34d6c..38cd1628 100644 --- a/lib/src/Extensions/CMakeLists.txt +++ b/lib/src/Extensions/CMakeLists.txt @@ -120,6 +120,7 @@ if (OPENCL_EXTENSION_LOADER_INSTALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT binary ) export(EXPORT OpenCLExtensionLoaderTargets @@ -130,6 +131,7 @@ if (OPENCL_EXTENSION_LOADER_INSTALL) FILE OpenCLExtensionLoaderTargets.cmake NAMESPACE OpenCL:: DESTINATION ${OPENCL_EXTENSION_LOADER_CONFIG_PATH} + COMPONENT binary ) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/OpenCLExtensionLoader/OpenCLExtensionLoaderConfig.cmake @@ -137,6 +139,7 @@ if (OPENCL_EXTENSION_LOADER_INSTALL) ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCLExtensionLoader/OpenCLExtensionLoaderConfig.cmake DESTINATION ${OPENCL_EXTENSION_LOADER_CONFIG_PATH} + COMPONENT binary ) write_basic_package_version_file( @@ -146,6 +149,14 @@ if (OPENCL_EXTENSION_LOADER_INSTALL) ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCLExtensionLoader/OpenCLExtensionLoaderConfigVersion.cmake DESTINATION ${OPENCL_EXTENSION_LOADER_CONFIG_PATH} + COMPONENT binary + ) + + # For packaging the extensions library + install( + TARGETS OpenCLExt + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT binary ) endif() From 7c9a7e99056a6a62a8f90957937004047ce36409 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:55 +0000 Subject: [PATCH 06/46] Submodules update --- .github/workflows/presubmit.yml | 8 ++++---- .gitmodules | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index f925b446..fadaa135 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -57,8 +57,8 @@ jobs: CONF: - GEN: Unix Makefiles CONFIG: Debug - - GEN: Unix Makefiles - CONFIG: Release + # - GEN: Unix Makefiles + # CONFIG: Release # - GEN: Ninja Multi-Config # CONFIG: Release IMAGE: @@ -111,7 +111,8 @@ jobs: -G DEB -C ${{matrix.CONF.CONFIG}} -B "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb" && - dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb && + dpkg -c $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/ocl-icd-opencl-dev_3.0-1_amd64.deb - name: Configure, package & install OpenCL-CLHPP shell: bash @@ -188,7 +189,6 @@ jobs: shell: bash run: dpkg -i $GITHUB_WORKSPACE/package-deb/*.deb && $CMAKE_EXE - --debug-find -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil diff --git a/.gitmodules b/.gitmodules index 940e8ead..4c2bdc2d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "loader"] path = external/OpenCL-ICD-Loader - url = https://github.com/KhronosGroup/OpenCL-ICD-Loader.git + url = https://github.com/StreamHPC/OpenCL-ICD-Loader.git [submodule "headers"] path = external/OpenCL-Headers - url = https://github.com/KhronosGroup/OpenCL-Headers.git + url = https://github.com/StreamHPC/OpenCL-Headers.git [submodule "headers-cpp"] path = external/OpenCL-CLHPP - url = https://github.com/KhronosGroup/OpenCL-CLHPP.git + url = https://github.com/StreamHPC/OpenCL-CLHPP.git From ad82569cb00ffee48d61b275b8b5e7fb91a2b971 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:56 +0000 Subject: [PATCH 07/46] Add Windows CI job --- .github/workflows/presubmit.yml | 264 ++++++++++++++++++++++++++++---- 1 file changed, 231 insertions(+), 33 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index fadaa135..9760e2f5 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -33,6 +33,7 @@ jobs: run: $GITHUB_WORKSPACE/scripts/check-format.sh origin/${{ needs.get-branch.outputs.branch }} --binary clang-format linux: + if: false runs-on: ubuntu-latest needs: format strategy: @@ -62,7 +63,7 @@ jobs: # - GEN: Ninja Multi-Config # CONFIG: Release IMAGE: - - streamhpc/opencl-sdk-base:ubuntu-22.04-20230717 + - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 container: ${{matrix.IMAGE}} env: CMAKE_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cmake @@ -225,6 +226,235 @@ jobs: $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Release -- -j`nproc`; fi; + windows: + runs-on: windows-latest + needs: format + strategy: + matrix: + VER: [v141, v142, v143, clangcl] + GEN: [Visual Studio 17 2022, Ninja Multi-Config] + DEPS: [os, vcpkg] + BIN: [x64] + STD: [14, 17] + exclude: + - VER: clangcl + GEN: Ninja Multi-Config + include: + - VER: v142 + GEN: Visual Studio 17 2022 + BIN: x86 + env: + NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip + NINJA_ROOT: C:\Tools\Ninja + VS_ROOT: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' + UseMultiToolTask: true # Better parallel MSBuild execution + EnforceProcessCountAcrossBuilds: 'true' # -=- + MultiProcMaxCount: '3' # -=- + WindowsSDKVersion: '10.0.22621.0' + + steps: + - name: Cache Ninja install + if: matrix.GEN == 'Ninja Multi-Config' + id: ninja-install + uses: actions/cache@v3 + with: + path: | + C:\Tools\Ninja + key: ${{runner.os}}-ninja-${{env.NINJA_URL}} + + - name: Install Ninja + if: matrix.GEN == 'Ninja Multi-Config' && steps.ninja-install.outputs.cache-hit != 'true' + shell: pwsh + run: | + Invoke-WebRequest ${env:NINJA_URL} -OutFile ~\Downloads\ninja-win.zip + Expand-Archive ~\Downloads\ninja-win.zip -DestinationPath ${env:NINJA_ROOT}\ + Remove-Item ~\Downloads\* + + - name: Checkout OpenCL-SDK + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + + - name: Configure (MSBuild) + if: matrix.GEN == 'Visual Studio 17 2022' + shell: pwsh + run: | + if ('${{ matrix.DEPS }}' -eq 'vcpkg') { + Get-ChildItem Env:\ + & ${env:VCPKG_INSTALLATION_ROOT}\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb + $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" + } else { + $TOOLCHAIN_ARG='' + } + $BIN = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} + & cmake ` + $TOOLCHAIN_ARG ` + -G "${{matrix.GEN}}" ` + -A $BIN ` + -T ${{matrix.VER}} ` + -D BUILD_DOCS=ON ` + -D BUILD_TESTING=ON ` + -D OPENCL_SDK_BUILD_SAMPLES=OFF ` + -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` + -D CMAKE_C_STANDARD=${{matrix.STD}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` + -S ${env:GITHUB_WORKSPACE} ` + -B ${env:GITHUB_WORKSPACE}\build + + - name: Configure (Ninja Multi-Config) + if: matrix.GEN == 'Ninja Multi-Config' + shell: pwsh + run: | + if ('${{ matrix.DEPS }}' -eq 'vcpkg') { + Get-ChildItem Env:\ + & ${env:VCPKG_INSTALLATION_ROOT}\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb + $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" + } else { + $TOOLCHAIN_ARG='' + } + $VER = switch ('${{matrix.VER}}') { ` + 'v141' {'14.1'} ` + 'v142' {'14.2'} ` + 'v143' {'14.3'} } + Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" + & cmake ` + $TOOLCHAIN_ARG ` + -G "${{matrix.GEN}}" ` + -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` + -D BUILD_DOCS=ON ` + -D BUILD_TESTING=ON ` + -D OPENCL_SDK_BUILD_SAMPLES=OFF ` + -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` + -D CMAKE_C_STANDARD=${{matrix.STD}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` + -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` + -S ${env:GITHUB_WORKSPACE} ` + -B ${env:GITHUB_WORKSPACE}\build + + - name: Build (MSBuild) + if: matrix.GEN == 'Visual Studio 17 2022' + shell: pwsh + run: | + foreach ($Config in 'Release','Debug') { ` + & cmake ` + --build "${env:GITHUB_WORKSPACE}\build" ` + --config $Config ` + -- ` + /verbosity:minimal ` + /maxCpuCount ` + /noLogo + } + + - name: Build (Ninja Multi-Config) + if: matrix.GEN == 'Ninja Multi-Config' + shell: pwsh + run: | + $VER = switch ('${{matrix.VER}}') { ` + 'v141' {'14.1'} ` + 'v142' {'14.2'} ` + 'v143' {'14.3'} } + Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" + foreach ($Config in 'Release','Debug') { ` + & cmake ` + --build "${env:GITHUB_WORKSPACE}\build" ` + --config $Config ` + -- ` + -j ${env:NUMBER_OF_PROCESSORS} + } + + - name: Test + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + shell: pwsh + run: | + $REG = if('${{matrix.BIN}}' -eq 'x64') {"reg"} else {"${env:SystemRoot}\Syswow64\reg.exe"} + $KEY_NAME = "HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors" + foreach ($Config in 'Release','Debug') { + $VALUE_NAME = "${env:GITHUB_WORKSPACE}/build/$Config/OpenCLDriverStub.dll" + & $REG ADD $KEY_NAME /v $VALUE_NAME /t REG_DWORD /d 0 + & ctest ` + --build-config ${Config} ` + --output-on-failure ` + --parallel ${env:NUMBER_OF_PROCESSORS} + & $REG DELETE $KEY_NAME /v $VALUE_NAME /f + } + + - name: Install + shell: pwsh + run: | + & cmake ` + --install "${env:GITHUB_WORKSPACE}\build" ` + --prefix "${env:GITHUB_WORKSPACE}\install" ` + --config Release + + - name: "Consume (MSBuild SDK): Configure/Build/Test" + shell: pwsh + run: | + if ('${{ matrix.DEPS }}' -eq 'vcpkg') { + $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" + } else { + $TOOLCHAIN_ARG='' + } + $BIN = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} + & cmake ` + $TOOLCHAIN_ARG ` + -G '${{matrix.GEN}}' ` + -A $BIN ` + -T ${{matrix.VER}} ` + -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` + -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\install" ` + -D DRIVER_STUB_PATH="${env:GITHUB_WORKSPACE}\build\Release\OpenCLDriverStub.dll" ` + -D CMAKE_C_STANDARD=${{matrix.STD}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -S "${env:GITHUB_WORKSPACE}\test\pkgconfig\useutil" ` + -B "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" + foreach ($Config in 'Release','Debug') { ` + & cmake ` + --build "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" ` + --config ${Config} ` + & cd ${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil ` + & ctest ` + --output-on-failure -C ${Config} + } + + - name: "Consume (Ninja-Multi-Config SDK): Configure/Build/Test" + shell: pwsh + run: | + if ('${{ matrix.DEPS }}' -eq 'vcpkg') { + $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" + } else { + $TOOLCHAIN_ARG='' + } + $VER = switch ('${{matrix.VER}}') { ` + 'v141' {'14.1'} ` + 'v142' {'14.2'} ` + 'v143' {'14.3'} } + Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=${VER}" + & cmake ` + $TOOLCHAIN_ARG ` + -G '${{matrix.GEN}}' ` + -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` + -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` + -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\external\OpenCL-Headers\install;${env:GITHUB_WORKSPACE}\install" ` + -D DRIVER_STUB_PATH="${env:GITHUB_WORKSPACE}\build\Release\OpenCLDriverStub.dll" ` + -D CMAKE_C_STANDARD=${{matrix.STD}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -S "${env:GITHUB_WORKSPACE}\test\pkgconfig\useutil" ` + -B "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" + foreach ($Config in 'Release','Debug') { ` + & cmake ` + --build "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" ` + --config ${Config} ` + & cd ${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil ` + & ctest ` + --output-on-failure -C ${Config} + } + build: if: false needs: format @@ -281,38 +511,6 @@ jobs: --build ./build \ --verbose \ --parallel `numproc` - buildwin: - if: false - needs: format - name: Build Windows ${{ matrix.deps }} - runs-on: windows-latest - strategy: - matrix: - deps: [fetch, vcpkg] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: recursive - - name: Build - shell: pwsh - run: | - if ('${{ matrix.deps }}' -eq 'vcpkg') { - Get-ChildItem Env:\ - & ${env:VCPKG_INSTALLATION_ROOT}\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb - $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" - } else { - $TOOLCHAIN_ARG='' - } - cmake ` - $TOOLCHAIN_ARG ` - -S . -B build - cmake ` - --build ./build ` - -- ` - /verbosity:minimal ` - /maxCpuCount ` - /noLogo python: if: false From 32623474c312940a0b548bcf87effbac501b27a3 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:56 +0000 Subject: [PATCH 08/46] Add MacOS CI job --- .github/workflows/presubmit.yml | 156 ++++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 50 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 9760e2f5..7a32523c 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -33,7 +33,6 @@ jobs: run: $GITHUB_WORKSPACE/scripts/check-format.sh origin/${{ needs.get-branch.outputs.branch }} --binary clang-format linux: - if: false runs-on: ubuntu-latest needs: format strategy: @@ -455,62 +454,119 @@ jobs: --output-on-failure -C ${Config} } - build: - if: false + macos: + runs-on: macos-latest needs: format - name: Build ${{ matrix.os }} ${{ matrix.compiler }} ${{ matrix.deps }} - runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, macos-latest] - compiler: [gcc, clang] - deps: [os, fetch, vcpkg] + COMPILER: + - C_NAME: /usr/bin/gcc + CXX_NAME: /usr/bin/g++ + - C_NAME: /usr/local/bin/gcc-11 + CXX_NAME: /usr/local/bin/g++-11 + - C_NAME: /usr/local/bin/gcc-13 + CXX_NAME: /usr/local/bin/g++-13 + GEN: + - Xcode + - Ninja Multi-Config + STD: [14, 17] + DEPS: [os, vcpkg] + exclude: + - COMPILER: + C_NAME: /usr/bin/gcc + CXX_NAME: /usr/bin/g++ + GEN: Ninja Multi-Config + - COMPILER: + C_NAME: /usr/local/bin/gcc-11 + CXX_NAME: /usr/local/bin/g++-11 + GEN: Xcode + - COMPILER: + C_NAME: /usr/local/bin/gcc-13 + CXX_NAME: /usr/local/bin/g++-13 + GEN: Xcode + env: + CC: ${{matrix.COMPILER.C_NAME}} + CCX: ${{matrix.COMPILER.CXX_NAME}} + CFLAGS: -Wall -Wextra -pedantic -Werror + CXXFLAGS: -Wall -Wextra -pedantic -Wno-format -Werror + steps: - - uses: actions/checkout@v3 + - name: Checkout OpenCL-SDK + uses: actions/checkout@v3 with: - fetch-depth: 0 - submodules: recursive + fetch-depth: 0 + submodules: recursive + + - name: Create Build Environment + shell: bash + run: | + cmake -E make_directory $GITHUB_WORKSPACE/build && + cmake -E make_directory $GITHUB_WORKSPACE/install && + if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && + # Install Ninja only if it's the selected generator and it's not available. + cmake --version + + - name: Configure + shell: bash + run: if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; + then + git clone https://github.com/Microsoft/vcpkg.git; + ./vcpkg/bootstrap-vcpkg.sh; + ./vcpkg/vcpkg install sfml tclap glm glew stb; + TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; + else + TOOLCHAIN_ARG=""; + fi && + cmake + $TOOLCHAIN_ARG + -G "${{matrix.GEN}}" + -D BUILD_DOCS=ON + -D BUILD_TESTING=ON + -D BUILD_EXAMPLES=ON + -D OPENCL_SDK_BUILD_SAMPLES=OFF + -D OPENCL_ICD_LOADER_BUILD_TESTING=ON + -D CMAKE_C_STANDARD=${{matrix.STD}} + -D CMAKE_CXX_STANDARD=${{matrix.STD}} + -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install + -S $GITHUB_WORKSPACE + -B $GITHUB_WORKSPACE/build + - name: Build + shell: bash run: | - if [[ "${{ matrix.os }}" == "ubuntu-20.04" ]]; then - sudo apt update - sudo apt install -y libidn11 libx11-dev libxrandr-dev libxi-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libudev-dev \ - `if [[ "${{matrix.deps}}" == "os" ]]; then echo libtclap-dev libglm-dev libglew-dev libsfml-dev libstb-dev; fi;` \ - `if [[ "${{matrix.deps}}" == "vcpkg" ]]; then echo autoconf libtool libxcursor-dev; fi;` - if [[ "${{matrix.deps}}" == "vcpkg" ]]; then - git clone https://github.com/Microsoft/vcpkg.git - ./vcpkg/bootstrap-vcpkg.sh - ./vcpkg/vcpkg install sfml tclap glm glew stb - TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake" - else - TOOLCHAIN_ARG="" - fi - if [[ "${{matrix.deps}}" == "fetch" ]]; then - sudo apt remove -y libtclap-dev libglm-dev libglew-dev libsfml-dev libstb-dev libfreetype6-dev - fi - elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then - brew install tclap glm glew sfml mesa-glu - git clone https://github.com/Microsoft/vcpkg.git - ./vcpkg/bootstrap-vcpkg.sh - ./vcpkg/vcpkg install stb - TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake" - fi - if [[ "${{ matrix.compiler }}" == "gcc" ]]; then - CC=gcc - CXX=g++ - elif [[ "${{ matrix.compiler }}" == "clang" ]]; then - CC=clang - CXX=clang++ - fi - cmake \ - -D CMAKE_C_COMPILER=$CC \ - -D CMAKE_CXX_COMPILER=$CXX \ - $TOOLCHAIN_ARG \ - -S . -B build - cmake \ - --build ./build \ - --verbose \ - --parallel `numproc` + cmake --build $GITHUB_WORKSPACE/build --config Release --parallel `sysctl -n hw.logicalcpu` + cmake --build $GITHUB_WORKSPACE/build --config Debug --parallel `sysctl -n hw.logicalcpu` + + - name: Test + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + shell: bash + run: | + ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` + ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` + + - name: Test install + shell: bash + run: | + cmake --build $GITHUB_WORKSPACE/build --config Release --target install + + - name: Consume (install) + shell: bash + run: if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; + then + TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; + else + TOOLCHAIN_ARG=""; + fi & + cmake + $TOOLCHAIN_ARG + -G "${{matrix.GEN}}" + -D CMAKE_C_STANDARD=${{matrix.STD}} + -D CMAKE_CXX_STANDARD=${{matrix.STD}} + -D CMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install" + -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil + -B $GITHUB_WORKSPACE/build_install && + cmake --build $GITHUB_WORKSPACE/build_install --config Release --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` && + cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` python: if: false From 869757005ef6d82eeaf2ad01e88ac46d1edc786a Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:57 +0000 Subject: [PATCH 09/46] Unify C/C++ standards --- .github/workflows/presubmit.yml | 51 ++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 7a32523c..ee48cec6 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -53,7 +53,11 @@ jobs: # VER: 16 DEPS: [os, vcpkg] BIN: [64] - STD: [11, 17] + STD: + - C: 99 + CXX: 14 + - C: 17 + CXX: 17 CONF: - GEN: Unix Makefiles CONFIG: Debug @@ -150,6 +154,8 @@ jobs: -D BUILD_EXAMPLES=ON -D OPENCL_SDK_BUILD_SAMPLES=OFF -D OPENCL_ICD_LOADER_BUILD_TESTING=ON + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH -S $GITHUB_WORKSPACE @@ -191,6 +197,8 @@ jobs: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil -B $GITHUB_WORKSPACE/build_package && if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; @@ -216,7 +224,10 @@ jobs: -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D CMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/install - $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil && + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} + -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil + -B $GITHUB_WORKSPACE/build_install && if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install -- -j`nproc`; @@ -234,7 +245,11 @@ jobs: GEN: [Visual Studio 17 2022, Ninja Multi-Config] DEPS: [os, vcpkg] BIN: [x64] - STD: [14, 17] + STD: + - C: 99 + CXX: 14 + - C: 17 + CXX: 17 exclude: - VER: clangcl GEN: Ninja Multi-Config @@ -296,8 +311,8 @@ jobs: -D BUILD_TESTING=ON ` -D OPENCL_SDK_BUILD_SAMPLES=OFF ` -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` - -D CMAKE_C_STANDARD=${{matrix.STD}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` -S ${env:GITHUB_WORKSPACE} ` -B ${env:GITHUB_WORKSPACE}\build @@ -327,8 +342,8 @@ jobs: -D BUILD_TESTING=ON ` -D OPENCL_SDK_BUILD_SAMPLES=OFF ` -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` - -D CMAKE_C_STANDARD=${{matrix.STD}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` -S ${env:GITHUB_WORKSPACE} ` @@ -407,8 +422,8 @@ jobs: -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\install" ` -D DRIVER_STUB_PATH="${env:GITHUB_WORKSPACE}\build\Release\OpenCLDriverStub.dll" ` - -D CMAKE_C_STANDARD=${{matrix.STD}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -S "${env:GITHUB_WORKSPACE}\test\pkgconfig\useutil" ` -B "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" foreach ($Config in 'Release','Debug') { ` @@ -441,8 +456,8 @@ jobs: -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\external\OpenCL-Headers\install;${env:GITHUB_WORKSPACE}\install" ` -D DRIVER_STUB_PATH="${env:GITHUB_WORKSPACE}\build\Release\OpenCLDriverStub.dll" ` - -D CMAKE_C_STANDARD=${{matrix.STD}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD}} ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -S "${env:GITHUB_WORKSPACE}\test\pkgconfig\useutil" ` -B "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" foreach ($Config in 'Release','Debug') { ` @@ -469,7 +484,11 @@ jobs: GEN: - Xcode - Ninja Multi-Config - STD: [14, 17] + STD: + - C: 99 + CXX: 14 + - C: 17 + CXX: 17 DEPS: [os, vcpkg] exclude: - COMPILER: @@ -525,8 +544,8 @@ jobs: -D BUILD_EXAMPLES=ON -D OPENCL_SDK_BUILD_SAMPLES=OFF -D OPENCL_ICD_LOADER_BUILD_TESTING=ON - -D CMAKE_C_STANDARD=${{matrix.STD}} - -D CMAKE_CXX_STANDARD=${{matrix.STD}} + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build @@ -560,8 +579,8 @@ jobs: cmake $TOOLCHAIN_ARG -G "${{matrix.GEN}}" - -D CMAKE_C_STANDARD=${{matrix.STD}} - -D CMAKE_CXX_STANDARD=${{matrix.STD}} + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} -D CMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install" -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil -B $GITHUB_WORKSPACE/build_install && From 6fa9eebd8461bb96d8a1de63f512b2c5f9fd055c Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:58 +0000 Subject: [PATCH 10/46] Fix warnings and errors gcc --- .github/workflows/presubmit.yml | 75 +++++++++++++----------------- cmake/Dependencies.cmake | 49 ++++++++++++++++--- cmake/Dependencies/SFML/SFML.cmake | 14 ++++++ lib/include/CL/SDK/CLI.h | 2 - lib/src/Utils/File.c | 10 +++- test/cmake/platformenum.c | 2 +- test/cmake/platformenum.cpp | 2 +- test/cmake/useutil.c | 2 +- 8 files changed, 101 insertions(+), 55 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index ee48cec6..42c0a607 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -39,22 +39,22 @@ jobs: matrix: CMAKE: [3.26.4] COMPILER: - - C_NAME: gcc - CXX_NAME: g++ - VER: 11 + # - C_NAME: gcc + # CXX_NAME: g++ + # VER: 11 # - C_NAME: gcc # CXX_NAME: g++ # VER: 13 - # - C_NAME: clang - # CXX_NAME: clang++ - # VER: 14 - # - C_NAME: clang - # CXX_NAME: clang++ - # VER: 16 + - C_NAME: clang + CXX_NAME: clang++ + VER: 14 + - C_NAME: clang + CXX_NAME: clang++ + VER: 16 DEPS: [os, vcpkg] BIN: [64] STD: - - C: 99 + - C: 11 # Utils C library uses C11 functions (e.g. timespec_get) CXX: 14 - C: 17 CXX: 17 @@ -75,8 +75,12 @@ jobs: DEB_INSTALLATION_PATH: /usr CC: ${{matrix.COMPILER.C_NAME}}-${{matrix.COMPILER.VER}} CXX: ${{matrix.COMPILER.CXX_NAME}}-${{matrix.COMPILER.VER}} - CFLAGS: -Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} - CXXFLAGS: -Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} + # Excluding missing-field-initializers error because it comes from the Std dependency + # Excluding maybe-uninitialized error because cannot workaround the compiler issuing this error + # Not using -pedantic: error: ISO C forbids braced-groups within expressions + CFLAGS: -Wall -Wextra -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }} + # Excluding missing-field-initializers error because it comes from the Std dependency + CXXFLAGS: -Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers steps: - name: Checkout OpenCL-SDK @@ -97,7 +101,7 @@ jobs: $CPACK_EXE --config "$GITHUB_WORKSPACE/external/OpenCL-Headers/build/CPackConfig.cmake" -G DEB - -C ${{matrix.CONF.CONFIG}} + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` -B "$GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb" && dpkg -i $GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb/*.deb @@ -113,7 +117,7 @@ jobs: $CPACK_EXE --config "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build/CPackConfig.cmake" -G DEB - -C ${{matrix.CONF.CONFIG}} + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` -B "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb" && dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb && dpkg -c $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/ocl-icd-opencl-dev_3.0-1_amd64.deb @@ -131,7 +135,7 @@ jobs: $CPACK_EXE --config "$GITHUB_WORKSPACE/external/OpenCL-CLHPP/build/CPackConfig.cmake" -G DEB - -C ${{matrix.CONF.CONFIG}} + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` -B "$GITHUB_WORKSPACE/external/OpenCL-CLHPP/package-deb" && dpkg -i $GITHUB_WORKSPACE/external/OpenCL-CLHPP/package-deb/*.deb @@ -147,12 +151,13 @@ jobs: TOOLCHAIN_ARG=""; fi && $CMAKE_EXE + $TOOLCHAIN_ARG -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D BUILD_DOCS=ON -D BUILD_TESTING=ON -D BUILD_EXAMPLES=ON - -D OPENCL_SDK_BUILD_SAMPLES=OFF + -D OPENCL_SDK_BUILD_SAMPLES=ON -D OPENCL_ICD_LOADER_BUILD_TESTING=ON -D CMAKE_C_STANDARD=${{matrix.STD.C}} -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} @@ -187,7 +192,7 @@ jobs: run: $CPACK_EXE --config "$GITHUB_WORKSPACE/build/CPackConfig.cmake" -G DEB - -C ${{matrix.CONF.CONFIG}} + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` -B "$GITHUB_WORKSPACE/package-deb" && dpkg -c $GITHUB_WORKSPACE/package-deb/khronos-opencl-sdk_2023.4.17-1_amd64.deb @@ -215,8 +220,12 @@ jobs: - name: Test install shell: bash - run: $CMAKE_EXE --build $GITHUB_WORKSPACE/build --target install --config ${{matrix.CONF.CONFIG}} -- -j`nproc` && - ls -lR $GITHUB_WORKSPACE/install + run: $CMAKE_EXE + --build $GITHUB_WORKSPACE/build + --target install + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "--config ${{matrix.CONF.CONFIG}}"; fi` + -- + -j`nproc` - name: Consume (install) shell: bash @@ -309,7 +318,7 @@ jobs: -T ${{matrix.VER}} ` -D BUILD_DOCS=ON ` -D BUILD_TESTING=ON ` - -D OPENCL_SDK_BUILD_SAMPLES=OFF ` + -D OPENCL_SDK_BUILD_SAMPLES=ON ` -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` @@ -340,7 +349,7 @@ jobs: -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` -D BUILD_DOCS=ON ` -D BUILD_TESTING=ON ` - -D OPENCL_SDK_BUILD_SAMPLES=OFF ` + -D OPENCL_SDK_BUILD_SAMPLES=ON ` -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` @@ -408,14 +417,8 @@ jobs: - name: "Consume (MSBuild SDK): Configure/Build/Test" shell: pwsh run: | - if ('${{ matrix.DEPS }}' -eq 'vcpkg') { - $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" - } else { - $TOOLCHAIN_ARG='' - } $BIN = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} & cmake ` - $TOOLCHAIN_ARG ` -G '${{matrix.GEN}}' ` -A $BIN ` -T ${{matrix.VER}} ` @@ -438,11 +441,6 @@ jobs: - name: "Consume (Ninja-Multi-Config SDK): Configure/Build/Test" shell: pwsh run: | - if ('${{ matrix.DEPS }}' -eq 'vcpkg') { - $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" - } else { - $TOOLCHAIN_ARG='' - } $VER = switch ('${{matrix.VER}}') { ` 'v141' {'14.1'} ` 'v142' {'14.2'} ` @@ -450,7 +448,6 @@ jobs: Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=${VER}" & cmake ` - $TOOLCHAIN_ARG ` -G '${{matrix.GEN}}' ` -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` @@ -542,7 +539,7 @@ jobs: -D BUILD_DOCS=ON -D BUILD_TESTING=ON -D BUILD_EXAMPLES=ON - -D OPENCL_SDK_BUILD_SAMPLES=OFF + -D OPENCL_SDK_BUILD_SAMPLES=ON -D OPENCL_ICD_LOADER_BUILD_TESTING=ON -D CMAKE_C_STANDARD=${{matrix.STD.C}} -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} @@ -570,14 +567,7 @@ jobs: - name: Consume (install) shell: bash - run: if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; - then - TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; - else - TOOLCHAIN_ARG=""; - fi & - cmake - $TOOLCHAIN_ARG + run: cmake -G "${{matrix.GEN}}" -D CMAKE_C_STANDARD=${{matrix.STD.C}} -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} @@ -653,6 +643,7 @@ jobs: working-directory: ruby android: + if: false runs-on: ubuntu-latest needs: format strategy: diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index f9176312..98b031a8 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1,10 +1,38 @@ -if(OPENCL_SDK_BUILD_UTILITY_LIBRARIES) - foreach(DEP IN ITEMS whereami) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/${DEP}") - include(${DEP}) - endforeach() +# Save global flags and strip diagnostics locally +set(USER_C_FLAGS ${CMAKE_C_FLAGS}) +set(USER_CXX_FLAGS ${CMAKE_CXX_FLAGS}) +if(DEFINED BUILD_SHARED_LIBS) + set(USER_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) endif() +set(USER_ROCM_WARN_TOOLCHAIN_VAR ${ROCM_WARN_TOOLCHAIN_VAR}) +set(ROCM_WARN_TOOLCHAIN_VAR OFF CACHE BOOL "") +# Turn off C warnings and errors for all warnings in dependencies +separate_arguments(C_FLAGS_LIST NATIVE_COMMAND ${CMAKE_C_FLAGS}) +list(REMOVE_ITEM C_FLAGS_LIST /WX -Werror -Werror=pendantic -pedantic-errors) +if(MSVC) + list(FILTER C_FLAGS_LIST EXCLUDE REGEX "/[Ww]([0-4]?)(all)?") # Remove MSVC warning flags + list(APPEND C_FLAGS_LIST /w) +else() + list(FILTER C_FLAGS_LIST EXCLUDE REGEX "-W(all|extra|everything)") # Remove GCC/LLVM flags + list(APPEND C_FLAGS_LIST -w) +endif() +list(JOIN C_FLAGS_LIST " " CMAKE_C_FLAGS) +# Turn off C++ warnings and errors for all warnings in dependencies +separate_arguments(CXX_FLAGS_LIST NATIVE_COMMAND ${CMAKE_CXX_FLAGS}) +list(REMOVE_ITEM CXX_FLAGS_LIST /WX -Werror -Werror=pendantic -pedantic-errors) +if(MSVC) + list(FILTER CXX_FLAGS_LIST EXCLUDE REGEX "/[Ww]([0-4]?)(all)?") # Remove MSVC warning flags + list(APPEND CXX_FLAGS_LIST /w) +else() + list(FILTER CXX_FLAGS_LIST EXCLUDE REGEX "-W(all|extra|everything)") # Remove GCC/LLVM flags + list(APPEND CXX_FLAGS_LIST -w) +endif() +list(JOIN CXX_FLAGS_LIST " " CMAKE_CXX_FLAGS) +# Don't build client dependencies as shared +set(BUILD_SHARED_LIBS OFF CACHE BOOL "Global flag to cause add_library() to create shared libraries if on." FORCE) + +# Fetch dependencies if(OPENCL_SDK_BUILD_SAMPLES) foreach(DEP IN ITEMS cargs TCLAP Stb) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/${DEP}") @@ -17,4 +45,13 @@ if(OPENCL_SDK_BUILD_SAMPLES) include(${DEP}) endforeach() endif(OPENCL_SDK_BUILD_OPENGL_SAMPLES) -endif(OPENCL_SDK_BUILD_SAMPLES) \ No newline at end of file +endif(OPENCL_SDK_BUILD_SAMPLES) + +# Restore user global state +set(CMAKE_C_FLAGS ${USER_C_FLAGS}) +set(CMAKE_CXX_FLAGS ${USER_CXX_FLAGS}) +if(DEFINED USER_BUILD_SHARED_LIBS) + set(BUILD_SHARED_LIBS ${USER_BUILD_SHARED_LIBS}) +else() + unset(BUILD_SHARED_LIBS CACHE ) +endif() \ No newline at end of file diff --git a/cmake/Dependencies/SFML/SFML.cmake b/cmake/Dependencies/SFML/SFML.cmake index 56f6deee..cdb740b8 100644 --- a/cmake/Dependencies/SFML/SFML.cmake +++ b/cmake/Dependencies/SFML/SFML.cmake @@ -36,4 +36,18 @@ if(NOT (SFML_FOUND OR TARGET SFML::Graphics)) INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" FOLDER "Dependencies" ) + target_compile_options (sfml-window + PRIVATE + -Wno-implicit-fallthrough + -Wno-sign-compare + -Wno-unused-parameter) + target_compile_options (sfml-graphics + PRIVATE + -Wno-implicit-fallthrough + -Wno-unused-but-set-variable + -Wno-unused-parameter) + target_compile_options (sfml-system + PRIVATE + -Wno-implicit-fallthrough + -Wno-maybe-uninitialized) endif() \ No newline at end of file diff --git a/lib/include/CL/SDK/CLI.h b/lib/include/CL/SDK/CLI.h index f85470cf..66356cbb 100644 --- a/lib/include/CL/SDK/CLI.h +++ b/lib/include/CL/SDK/CLI.h @@ -10,8 +10,6 @@ // cargs includes #include -typedef struct cag_option cag_option; - SDK_EXPORT cag_option *add_CLI_options(cag_option *opts, size_t *const num_opts, cag_option *add_opts, size_t add_num_opts); diff --git a/lib/src/Utils/File.c b/lib/src/Utils/File.c index a806da4a..bd8d4af7 100644 --- a/lib/src/Utils/File.c +++ b/lib/src/Utils/File.c @@ -266,7 +266,10 @@ cl_int cl_util_write_binaries(const cl_program program, for (cl_uint i = 0; i < num_devices; ++i) free(binaries_ptr[i]); free(binaries_ptr); } - free(binaries_size); + if(binaries_size != NULL) + { + free(binaries_size); + } return error; } @@ -335,7 +338,10 @@ cl_program cl_util_read_binaries(const cl_context context, for (cl_uint i = 0; i < num_devices; ++i) free(binaries_ptr[i]); free(binaries_ptr); } - free(binaries_size); + if(binaries_size != NULL) + { + free(binaries_size); + } if (error != NULL) *error = err; return program; diff --git a/test/cmake/platformenum.c b/test/cmake/platformenum.c index 0c787caa..fe20e0fe 100644 --- a/test/cmake/platformenum.c +++ b/test/cmake/platformenum.c @@ -10,7 +10,7 @@ #define print(...) printf(__VA_ARGS__) #endif -int main() +int main(void) { cl_int CL_err = CL_SUCCESS; cl_uint numPlatforms = 0; diff --git a/test/cmake/platformenum.cpp b/test/cmake/platformenum.cpp index b91e630f..0c153b2c 100644 --- a/test/cmake/platformenum.cpp +++ b/test/cmake/platformenum.cpp @@ -5,7 +5,7 @@ #include // std::cout #include // EXIT_FAILURE -int main() +int main(void) { try { diff --git a/test/cmake/useutil.c b/test/cmake/useutil.c index 0c787caa..fe20e0fe 100644 --- a/test/cmake/useutil.c +++ b/test/cmake/useutil.c @@ -10,7 +10,7 @@ #define print(...) printf(__VA_ARGS__) #endif -int main() +int main(void) { cl_int CL_err = CL_SUCCESS; cl_uint numPlatforms = 0; From 155dc4fa5e6770febb59b0009abb7d5b2e086734 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:59 +0000 Subject: [PATCH 11/46] Fix warnings and errors clang --- .github/workflows/presubmit.yml | 4 ++++ samples/extensions/khr/conway/main.cpp | 2 +- samples/extensions/khr/nbody/main.cpp | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 42c0a607..5fcf8ac9 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -42,15 +42,19 @@ jobs: # - C_NAME: gcc # CXX_NAME: g++ # VER: 11 + # EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized # - C_NAME: gcc # CXX_NAME: g++ # VER: 13 + # EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - C_NAME: clang CXX_NAME: clang++ VER: 14 + EXCLUSIVE_C_FLAGS: "" - C_NAME: clang CXX_NAME: clang++ VER: 16 + EXCLUSIVE_C_FLAGS: "" DEPS: [os, vcpkg] BIN: [64] STD: diff --git a/samples/extensions/khr/conway/main.cpp b/samples/extensions/khr/conway/main.cpp index 8a3f3c96..549dbd71 100644 --- a/samples/extensions/khr/conway/main.cpp +++ b/samples/extensions/khr/conway/main.cpp @@ -306,7 +306,7 @@ void Conway::updateScene() conway( cl::EnqueueArgs{ queue, cl::NDRange{ getSize().x, getSize().y } }, cl_images.front, cl_images.back, - cl_float2{ 1.f / getSize().x, 1.f / getSize().y }); + cl_float2{ { 1.f / getSize().x, 1.f / getSize().y } }); queue.enqueueReleaseGLObjects(&interop_resources, nullptr, &release); diff --git a/samples/extensions/khr/nbody/main.cpp b/samples/extensions/khr/nbody/main.cpp index c0af5d27..56159f58 100644 --- a/samples/extensions/khr/nbody/main.cpp +++ b/samples/extensions/khr/nbody/main.cpp @@ -225,8 +225,8 @@ void NBody::initializeGL() y_dist = uni(-y_abs_range, y_abs_range), z_dist = uni(-z_abs_range, z_abs_range), m_dist = uni(mass_min, mass_max)]() mutable { - return cl_float4{ x_dist(prng), y_dist(prng), - z_dist(prng), m_dist(prng) }; + return cl_float4{ { x_dist(prng), y_dist(prng), + z_dist(prng), m_dist(prng) } }; }); glUseProgram(gl_program); @@ -299,7 +299,7 @@ void NBody::initializeCL() // }); velocity_buffer = cl::Buffer{ opencl_context, CL_MEM_READ_WRITE, particle_count * sizeof(cl_float3), nullptr }; - queue.enqueueFillBuffer(velocity_buffer, cl_float4{ 0, 0, 0, 0 }, 0, + queue.enqueueFillBuffer(velocity_buffer, cl_float4{ { 0, 0, 0, 0 } }, 0, particle_count * sizeof(cl_float4)); queue.finish(); From 1fd7920a8e516c73a342685d4cdd132e00d31de1 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:24:59 +0000 Subject: [PATCH 12/46] Fix multi-config --- .github/workflows/presubmit.yml | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 5fcf8ac9..8f55a134 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -39,14 +39,14 @@ jobs: matrix: CMAKE: [3.26.4] COMPILER: - # - C_NAME: gcc - # CXX_NAME: g++ - # VER: 11 - # EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - # - C_NAME: gcc - # CXX_NAME: g++ - # VER: 13 - # EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + - C_NAME: gcc + CXX_NAME: g++ + VER: 11 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + - C_NAME: gcc + CXX_NAME: g++ + VER: 13 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - C_NAME: clang CXX_NAME: clang++ VER: 14 @@ -65,10 +65,10 @@ jobs: CONF: - GEN: Unix Makefiles CONFIG: Debug - # - GEN: Unix Makefiles - # CONFIG: Release - # - GEN: Ninja Multi-Config - # CONFIG: Release + - GEN: Unix Makefiles + CONFIG: Release + - GEN: Ninja Multi-Config + CONFIG: Release IMAGE: - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 container: ${{matrix.IMAGE}} @@ -118,6 +118,13 @@ jobs: -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH -S $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader -B $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build && + if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build -- -j`nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build --config Debug -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build --config Release -- -j`nproc`; + fi && $CPACK_EXE --config "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build/CPackConfig.cmake" -G DEB From 27ea08bfbb02a810a9db6d152737ff24133444f7 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:00 +0000 Subject: [PATCH 13/46] Fix MacOS errors --- .github/workflows/presubmit.yml | 50 +++++++++++++++----------- lib/src/SDK/CLI.c | 4 +-- samples/core/copybuffer/main.cpp | 6 ++-- samples/core/copybufferkernel/main.cpp | 6 ++-- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 8f55a134..d03f3fd8 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -485,37 +485,51 @@ jobs: COMPILER: - C_NAME: /usr/bin/gcc CXX_NAME: /usr/bin/g++ + EXCLUSIVE_C_FLAGS: -Wno-conditional-uninitialized - C_NAME: /usr/local/bin/gcc-11 CXX_NAME: /usr/local/bin/g++-11 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - C_NAME: /usr/local/bin/gcc-13 CXX_NAME: /usr/local/bin/g++-13 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized GEN: - Xcode - Ninja Multi-Config STD: - - C: 99 + - C: 11 CXX: 14 - C: 17 CXX: 17 - DEPS: [os, vcpkg] exclude: - COMPILER: C_NAME: /usr/bin/gcc CXX_NAME: /usr/bin/g++ + EXCLUSIVE_C_FLAGS: -Wno-conditional-uninitialized GEN: Ninja Multi-Config - COMPILER: C_NAME: /usr/local/bin/gcc-11 CXX_NAME: /usr/local/bin/g++-11 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized GEN: Xcode - COMPILER: C_NAME: /usr/local/bin/gcc-13 CXX_NAME: /usr/local/bin/g++-13 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized GEN: Xcode env: CC: ${{matrix.COMPILER.C_NAME}} CCX: ${{matrix.COMPILER.CXX_NAME}} - CFLAGS: -Wall -Wextra -pedantic -Werror - CXXFLAGS: -Wall -Wextra -pedantic -Wno-format -Werror + # Not using -pedantic: error: ISO C forbids braced-groups within expressions + # The flags + # * -Wno-missing-field-initializers + # * matrix.COMPILER.EXCLUSIVE_C_FLAGS + # have been added because of Std compilation errors + CFLAGS: -Wall -Wextra -Werror -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }} + # The flags + # * -Wno-deprecated-declarations + # * -Wno-missing-field-initializers + # have been added because of Std compilation errors + CXXFLAGS: -Wall -Wextra -pedantic -Wno-format -Werror -Wno-missing-field-initializers -Wno-deprecated-declarations steps: - name: Checkout OpenCL-SDK @@ -531,19 +545,15 @@ jobs: cmake -E make_directory $GITHUB_WORKSPACE/install && if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && # Install Ninja only if it's the selected generator and it's not available. - cmake --version + cmake --version && + brew install tclap glm glew sfml mesa-glu - name: Configure shell: bash - run: if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; - then - git clone https://github.com/Microsoft/vcpkg.git; - ./vcpkg/bootstrap-vcpkg.sh; - ./vcpkg/vcpkg install sfml tclap glm glew stb; - TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; - else - TOOLCHAIN_ARG=""; - fi && + run: git clone https://github.com/Microsoft/vcpkg.git vcpkg && + ./vcpkg/bootstrap-vcpkg.sh && + ./vcpkg/vcpkg install stb && + TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake" && cmake $TOOLCHAIN_ARG -G "${{matrix.GEN}}" @@ -564,12 +574,12 @@ jobs: cmake --build $GITHUB_WORKSPACE/build --config Release --parallel `sysctl -n hw.logicalcpu` cmake --build $GITHUB_WORKSPACE/build --config Debug --parallel `sysctl -n hw.logicalcpu` - - name: Test - working-directory: ${{runner.workspace}}/OpenCL-SDK/build - shell: bash - run: | - ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` - ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` + # - name: Test + # working-directory: ${{runner.workspace}}/OpenCL-SDK/build + # shell: bash + # run: | + # ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` + # ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` - name: Test install shell: bash diff --git a/lib/src/SDK/CLI.c b/lib/src/SDK/CLI.c index ac110370..4dc7c6a1 100644 --- a/lib/src/SDK/CLI.c +++ b/lib/src/SDK/CLI.c @@ -108,8 +108,8 @@ SDK_EXPORT ParseState parse_SingleDeviceOptions( switch (identifier) { - case 'p': IF_ERR(dev_opts->triplet.plat_index = strtoul(value, NULL, 0)) - case 'd': IF_ERR(dev_opts->triplet.dev_index = strtoul(value, NULL, 0)) + case 'p': IF_ERR(dev_opts->triplet.plat_index = (cl_uint)strtoul(value, NULL, 0)) + case 'd': IF_ERR(dev_opts->triplet.dev_index = (cl_uint)strtoul(value, NULL, 0)) case 't': IF_ERR(dev_opts->triplet.dev_type = get_dev_type(value)) } return NotParsed; diff --git a/samples/core/copybuffer/main.cpp b/samples/core/copybuffer/main.cpp index 3c971ee3..c8a9df52 100644 --- a/samples/core/copybuffer/main.cpp +++ b/samples/core/copybuffer/main.cpp @@ -102,7 +102,8 @@ int main(int argc, char** argv) ++i; if (i < static_cast(argc)) { - deviceIndex = strtoul(argv[i], NULL, 10); + deviceIndex = + static_cast(strtoul(argv[i], NULL, 10)); } } else if (!strcmp(argv[i], "-p")) @@ -110,7 +111,8 @@ int main(int argc, char** argv) ++i; if (i < static_cast(argc)) { - platformIndex = strtoul(argv[i], NULL, 10); + platformIndex = + static_cast(strtoul(argv[i], NULL, 10)); } } else diff --git a/samples/core/copybufferkernel/main.cpp b/samples/core/copybufferkernel/main.cpp index d4314f9e..be436bd0 100644 --- a/samples/core/copybufferkernel/main.cpp +++ b/samples/core/copybufferkernel/main.cpp @@ -113,7 +113,8 @@ int main(int argc, char** argv) ++i; if (i < static_cast(argc)) { - deviceIndex = strtoul(argv[i], NULL, 10); + deviceIndex = + static_cast(strtoul(argv[i], NULL, 10)); } } else if (!strcmp(argv[i], "-p")) @@ -121,7 +122,8 @@ int main(int argc, char** argv) ++i; if (i < static_cast(argc)) { - platformIndex = strtoul(argv[i], NULL, 10); + platformIndex = + static_cast(strtoul(argv[i], NULL, 10)); } } else From 92f5e4cced21794b82cec95f7e016aa147740d40 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:01 +0000 Subject: [PATCH 14/46] Fix Windows errors --- .github/workflows/presubmit.yml | 35 ++++++++++++++------------ cmake/Dependencies/SFML/SFML.cmake | 4 ++- samples/extensions/khr/conway/main.cpp | 18 ++++++------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index d03f3fd8..4dc2ed42 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -266,7 +266,7 @@ jobs: DEPS: [os, vcpkg] BIN: [x64] STD: - - C: 99 + - C: 11 CXX: 14 - C: 17 CXX: 17 @@ -277,6 +277,9 @@ jobs: - VER: v142 GEN: Visual Studio 17 2022 BIN: x86 + STD: + C: 11 + CXX: 14 env: NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip NINJA_ROOT: C:\Tools\Ninja @@ -401,21 +404,21 @@ jobs: -j ${env:NUMBER_OF_PROCESSORS} } - - name: Test - working-directory: ${{runner.workspace}}/OpenCL-SDK/build - shell: pwsh - run: | - $REG = if('${{matrix.BIN}}' -eq 'x64') {"reg"} else {"${env:SystemRoot}\Syswow64\reg.exe"} - $KEY_NAME = "HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors" - foreach ($Config in 'Release','Debug') { - $VALUE_NAME = "${env:GITHUB_WORKSPACE}/build/$Config/OpenCLDriverStub.dll" - & $REG ADD $KEY_NAME /v $VALUE_NAME /t REG_DWORD /d 0 - & ctest ` - --build-config ${Config} ` - --output-on-failure ` - --parallel ${env:NUMBER_OF_PROCESSORS} - & $REG DELETE $KEY_NAME /v $VALUE_NAME /f - } + # - name: Test + # working-directory: ${{runner.workspace}}/OpenCL-SDK/build + # shell: pwsh + # run: | + # $REG = if('${{matrix.BIN}}' -eq 'x64') {"reg"} else {"${env:SystemRoot}\Syswow64\reg.exe"} + # $KEY_NAME = "HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors" + # foreach ($Config in 'Release','Debug') { + # $VALUE_NAME = "${env:GITHUB_WORKSPACE}/build/$Config/OpenCLDriverStub.dll" + # & $REG ADD $KEY_NAME /v $VALUE_NAME /t REG_DWORD /d 0 + # & ctest ` + # --build-config ${Config} ` + # --output-on-failure ` + # --parallel ${env:NUMBER_OF_PROCESSORS} + # & $REG DELETE $KEY_NAME /v $VALUE_NAME /f + # } - name: Install shell: pwsh diff --git a/cmake/Dependencies/SFML/SFML.cmake b/cmake/Dependencies/SFML/SFML.cmake index cdb740b8..0a32852b 100644 --- a/cmake/Dependencies/SFML/SFML.cmake +++ b/cmake/Dependencies/SFML/SFML.cmake @@ -36,7 +36,8 @@ if(NOT (SFML_FOUND OR TARGET SFML::Graphics)) INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" FOLDER "Dependencies" ) - target_compile_options (sfml-window + if((CMAKE_C_COMPILER_ID MATCHES "GNU") OR (CMAKE_C_COMPILER_ID MATCHES "Clang")) + target_compile_options (sfml-window PRIVATE -Wno-implicit-fallthrough -Wno-sign-compare @@ -50,4 +51,5 @@ if(NOT (SFML_FOUND OR TARGET SFML::Graphics)) PRIVATE -Wno-implicit-fallthrough -Wno-maybe-uninitialized) + endif() endif() \ No newline at end of file diff --git a/samples/extensions/khr/conway/main.cpp b/samples/extensions/khr/conway/main.cpp index 549dbd71..463f417e 100644 --- a/samples/extensions/khr/conway/main.cpp +++ b/samples/extensions/khr/conway/main.cpp @@ -46,17 +46,13 @@ class Conway : public cl::sdk::InteropWindow { explicit Conway(int width, int height, bool fullscreen, cl_uint platform_id = 0, cl_uint device_id = 0, cl_bitfield device_type = CL_DEVICE_TYPE_DEFAULT) - : InteropWindow{ sf::VideoMode(width, height), - "Conway's Game of Life", - fullscreen ? sf::Style::Fullscreen - : sf::Style::Default, - sf::ContextSettings{ - 0, 0, 0, // Depth, Stencil, AA - 3, 3, // OpenGL version - sf::ContextSettings::Attribute::Core }, - platform_id, - device_id, - device_type }, + : InteropWindow( + sf::VideoMode(width, height), "Conway's Game of Life", + fullscreen ? sf::Style::Fullscreen : sf::Style::Default, + sf::ContextSettings{ 0, 0, 0, // Depth, Stencil, AA + 3, 3, // OpenGL version + sf::ContextSettings::Attribute::Core }, + platform_id, device_id, device_type), animating(true) {} From d5994da0d76fa038a94a6297b7f547c9d9e73031 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:02 +0000 Subject: [PATCH 15/46] Install Windows OpenCL runtime --- .github/workflows/presubmit.yml | 48 +++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 4dc2ed42..516e93bf 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -288,6 +288,9 @@ jobs: EnforceProcessCountAcrossBuilds: 'true' # -=- MultiProcMaxCount: '3' # -=- WindowsSDKVersion: '10.0.22621.0' + INTEL_OCL_URL: https://github.com/intel/llvm/releases/download/2023-WW27/win-oclcpuexp-2023.16.6.0.28_rel.zip + INTEL_TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.10.0/oneapi-tbb-2021.10.0-win.zip + IMAGE_INTEL_PREFIX: C:\Tools\Intel steps: - name: Cache Ninja install @@ -307,6 +310,24 @@ jobs: Expand-Archive ~\Downloads\ninja-win.zip -DestinationPath ${env:NINJA_ROOT}\ Remove-Item ~\Downloads\* + - name: Install OpenCL runtime + shell: pwsh + run: | + $INTEL_OCL_ARCHIVE_NAME = Split-Path ${env:INTEL_OCL_URL} -Leaf; ` + Invoke-WebRequest ${env:INTEL_OCL_URL} -OutFile ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME; ` + Expand-Archive ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME -DestinationPath ${env:IMAGE_INTEL_PREFIX}\oclcpuexp; ` + Remove-Item ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME; ` + $INTEL_TBB_ARCHIVE_NAME = Split-Path ${env:INTEL_TBB_URL} -Leaf; ` + Invoke-WebRequest ${env:INTEL_TBB_URL} -OutFile ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME; ` + Expand-Archive ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME -DestinationPath ${env:IMAGE_INTEL_PREFIX}; ` + Get-ChildItem ${env:IMAGE_INTEL_PREFIX}\oneapi-tbb* | Rename-Item -NewName oneapi-tbb; ` + Remove-Item ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME; ` + New-Item -Type Directory ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\tbb | Out-Null; ` + Get-ChildItem ${env:IMAGE_INTEL_PREFIX}\oneapi-tbb\redist\intel64\vc14\*.dll | ForEach-Object { New-Item -Type SymbolicLink -Path ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\tbb -Name $_.Name -Value $_.FullName | Out-Null; }; ` + New-Item -Type Directory HKLM:\SOFTWARE\Khronos\OpenCL -Force | Out-Null; ` + New-Item -Type File HKLM:\SOFTWARE\Khronos\OpenCL\Vendors | Out-Null; ` + Set-ItemProperty -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors -Name ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\intelocl64.dll -Type DWord -Value 0; + - name: Checkout OpenCL-SDK uses: actions/checkout@v3 with: @@ -333,7 +354,6 @@ jobs: -D BUILD_DOCS=ON ` -D BUILD_TESTING=ON ` -D OPENCL_SDK_BUILD_SAMPLES=ON ` - -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` @@ -364,7 +384,6 @@ jobs: -D BUILD_DOCS=ON ` -D BUILD_TESTING=ON ` -D OPENCL_SDK_BUILD_SAMPLES=ON ` - -D OPENCL_ICD_LOADER_BUILD_TESTING=ON ` -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` @@ -404,21 +423,16 @@ jobs: -j ${env:NUMBER_OF_PROCESSORS} } - # - name: Test - # working-directory: ${{runner.workspace}}/OpenCL-SDK/build - # shell: pwsh - # run: | - # $REG = if('${{matrix.BIN}}' -eq 'x64') {"reg"} else {"${env:SystemRoot}\Syswow64\reg.exe"} - # $KEY_NAME = "HKEY_LOCAL_MACHINE\SOFTWARE\Khronos\OpenCL\Vendors" - # foreach ($Config in 'Release','Debug') { - # $VALUE_NAME = "${env:GITHUB_WORKSPACE}/build/$Config/OpenCLDriverStub.dll" - # & $REG ADD $KEY_NAME /v $VALUE_NAME /t REG_DWORD /d 0 - # & ctest ` - # --build-config ${Config} ` - # --output-on-failure ` - # --parallel ${env:NUMBER_OF_PROCESSORS} - # & $REG DELETE $KEY_NAME /v $VALUE_NAME /f - # } + - name: Test + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + shell: pwsh + run: | + foreach ($Config in 'Release','Debug') { + & ctest ` + --build-config ${Config} ` + --output-on-failure ` + --parallel ${env:NUMBER_OF_PROCESSORS} + } - name: Install shell: pwsh From bbb8c209d8a12a15fb4531b9cf28ac6da46c2838 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:02 +0000 Subject: [PATCH 16/46] Fix blur/blurcpp samples failures --- .github/workflows/presubmit.yml | 5 +---- samples/CMakeLists.txt | 21 +++++++++++---------- samples/core/blur/main.c | 9 ++++++++- samples/core/blur/main.cpp | 18 ++++++++++-------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 516e93bf..93e7537a 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -59,7 +59,7 @@ jobs: BIN: [64] STD: - C: 11 # Utils C library uses C11 functions (e.g. timespec_get) - CXX: 14 + CXX: 14 # Utils C++ library uses C14 types (e.g. integer_sequence) - C: 17 CXX: 17 CONF: @@ -616,7 +616,6 @@ jobs: cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` python: - if: false name: Exercise Python examples on ${{matrix.os}} strategy: matrix: @@ -654,7 +653,6 @@ jobs: done checkruby: - if: false name: Check Ruby Samples ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -681,7 +679,6 @@ jobs: working-directory: ruby android: - if: false runs-on: ubuntu-latest needs: format strategy: diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 0834853a..b9635d99 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -130,17 +130,18 @@ macro(add_sample) ) foreach(CONFIG ${OPENCL_SAMPLE_CONFIGS}) - install(TARGETS ${OPENCL_SAMPLE_TARGET} CONFIGURATIONS ${CONFIG} DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(FILES ${OPENCL_SAMPLE_KERNELS} CONFIGURATIONS ${CONFIG} DESTINATION ${CMAKE_INSTALL_BINDIR}) - install(FILES ${OPENCL_SAMPLE_SHADERS} CONFIGURATIONS ${CONFIG} DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(TARGETS ${OPENCL_SAMPLE_TARGET} CONFIGURATIONS ${CONFIG} DESTINATION ${CMAKE_INSTALL_BINDIR}/${CONFIG}) + install(FILES ${OPENCL_SAMPLE_KERNELS} CONFIGURATIONS ${CONFIG} DESTINATION ${CMAKE_INSTALL_BINDIR}/${CONFIG}) + install(FILES ${OPENCL_SAMPLE_SHADERS} CONFIGURATIONS ${CONFIG} DESTINATION ${CMAKE_INSTALL_BINDIR}/${CONFIG}) + if(OPENCL_SDK_TEST_SAMPLES AND OPENCL_SAMPLE_TEST) + add_test( + NAME "${OPENCL_SAMPLE_TARGET}_${CONFIG}" + COMMAND ${OPENCL_SAMPLE_TARGET} + CONFIGURATIONS ${CONFIG} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + ) + endif() endforeach() - if(OPENCL_SDK_TEST_SAMPLES AND OPENCL_SAMPLE_TEST) - add_test( - NAME ${OPENCL_SAMPLE_TARGET} - COMMAND ${OPENCL_SAMPLE_TARGET} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - ) - endif() endmacro() diff --git a/samples/core/blur/main.c b/samples/core/blur/main.c index d29a3a41..8960f06c 100644 --- a/samples/core/blur/main.c +++ b/samples/core/blur/main.c @@ -1118,8 +1118,9 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup relative exchange blur\n"); kernel_op[0] = '\0'; + // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 + strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); - OCLERROR_RET(dual_pass_subgroup_exchange_box_blur( &s, (cl_int)blur_opts.size), error, prg); @@ -1129,6 +1130,8 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup exchange blur\n"); kernel_op[0] = '\0'; + // cl_khr_subgroup_shuffle requires OpenCL 2.0 + strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); OCLERROR_RET(dual_pass_subgroup_exchange_box_blur( @@ -1172,6 +1175,8 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup relative exchange Gaussian blur\n"); kernel_op[0] = '\0'; + // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 + strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size, @@ -1183,6 +1188,8 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup exchange Gaussian blur\n"); kernel_op[0] = '\0'; + // cl_khr_subgroup_shuffle requires OpenCL 2.0 + strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size, diff --git a/samples/core/blur/main.cpp b/samples/core/blur/main.cpp index 1face850..1b724f17 100644 --- a/samples/core/blur/main.cpp +++ b/samples/core/blur/main.cpp @@ -89,8 +89,9 @@ int main(int argc, char* argv[]) { std::cout << "Dual-pass subgroup relative exchange blur" << std::endl; - - blur.build_program("-D USE_SUBGROUP_EXCHANGE_RELATIVE "); + // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 + blur.build_program( + "-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_box_blur(); } @@ -99,8 +100,8 @@ int main(int argc, char* argv[]) if (use_subgroup_exchange) { std::cout << "Dual-pass subgroup exchange blur" << std::endl; - - blur.build_program("-D USE_SUBGROUP_EXCHANGE "); + // cl_khr_subgroup_shuffle requires OpenCL 2.0 + blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_box_blur(); } } // Box blur @@ -137,8 +138,9 @@ int main(int argc, char* argv[]) std::cout << "Dual-pass subgroup relative exchange Gaussian blur" << std::endl; - - blur.build_program("-D USE_SUBGROUP_EXCHANGE_RELATIVE "); + // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 + blur.build_program( + "-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_kernel_blur(); } @@ -148,8 +150,8 @@ int main(int argc, char* argv[]) { std::cout << "Dual-pass subgroup exchange Gaussian blur" << std::endl; - - blur.build_program("-D USE_SUBGROUP_EXCHANGE "); + // cl_khr_subgroup_shuffle requires OpenCL 2.0 + blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_kernel_blur(); } } // Gaussian blur From bbb4e48be7cccfa20ff07533535e5c34f8e9c6ed Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:03 +0000 Subject: [PATCH 17/46] Fix MacOS test execution --- .github/workflows/presubmit.yml | 26 +++++++++++++++-------- samples/core/binaries/main.c | 2 +- samples/core/binaries/main.cpp | 2 +- samples/core/blur/blur.cpp | 5 +++++ samples/core/blur/blur.hpp | 3 +++ samples/core/blur/main.c | 20 +++++++++++++---- samples/core/blur/main.cpp | 10 +++++---- samples/core/reduce/main.cpp | 2 +- samples/core/saxpy/main.cpp | 2 +- samples/extensions/khr/conway/main.cpp | 2 +- samples/extensions/khr/histogram/main.cpp | 2 +- samples/extensions/khr/nbody/main.cpp | 2 +- 12 files changed, 54 insertions(+), 24 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 93e7537a..dc5564d8 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -565,6 +565,13 @@ jobs: cmake --version && brew install tclap glm glew sfml mesa-glu + # We need to provide an OpenCL driver for Intel CPU on mac + - name: Install PoCL + shell: bash + run: | + brew install pocl && + sudo ls /usr/local/etc/OpenCL/vendors + - name: Configure shell: bash run: git clone https://github.com/Microsoft/vcpkg.git vcpkg && @@ -578,7 +585,6 @@ jobs: -D BUILD_TESTING=ON -D BUILD_EXAMPLES=ON -D OPENCL_SDK_BUILD_SAMPLES=ON - -D OPENCL_ICD_LOADER_BUILD_TESTING=ON -D CMAKE_C_STANDARD=${{matrix.STD.C}} -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install @@ -588,15 +594,15 @@ jobs: - name: Build shell: bash run: | - cmake --build $GITHUB_WORKSPACE/build --config Release --parallel `sysctl -n hw.logicalcpu` cmake --build $GITHUB_WORKSPACE/build --config Debug --parallel `sysctl -n hw.logicalcpu` + cmake --build $GITHUB_WORKSPACE/build --config Release --parallel `sysctl -n hw.logicalcpu` - # - name: Test - # working-directory: ${{runner.workspace}}/OpenCL-SDK/build - # shell: bash - # run: | - # ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` - # ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` + - name: Test + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + shell: bash + run: | + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` - name: Test install shell: bash @@ -612,8 +618,10 @@ jobs: -D CMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install" -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil -B $GITHUB_WORKSPACE/build_install && + cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` && cmake --build $GITHUB_WORKSPACE/build_install --config Release --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` && - cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` && + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` python: name: Exercise Python examples on ${{matrix.os}} diff --git a/samples/core/binaries/main.c b/samples/core/binaries/main.c index c78276ff..4e1ad36b 100644 --- a/samples/core/binaries/main.c +++ b/samples/core/binaries/main.c @@ -198,7 +198,7 @@ int main(int argc, char *argv[]) OCLERROR_PAR(kernel = cl_util_read_exe_relative_text_file( "Collatz.cl", &program_size, &error), error, cont); - printf("OpenCL file red... "); + printf("OpenCL file read... "); OCLERROR_PAR(program = clCreateProgramWithSource(context, 1, (const char **)&kernel, diff --git a/samples/core/binaries/main.cpp b/samples/core/binaries/main.cpp index 035cfab9..b39cdaea 100644 --- a/samples/core/binaries/main.cpp +++ b/samples/core/binaries/main.cpp @@ -208,7 +208,7 @@ int main(int argc, char* argv[]) std::exit(e.err()); } catch (cl::Error& e) { - std::cerr << "OpenCL rutnime error: " << e.what() << std::endl; + std::cerr << "OpenCL runtime error: " << e.what() << std::endl; std::exit(e.err()); } catch (std::exception& e) { diff --git a/samples/core/blur/blur.cpp b/samples/core/blur/blur.cpp index 06f6dd52..b8682963 100644 --- a/samples/core/blur/blur.cpp +++ b/samples/core/blur/blur.cpp @@ -503,6 +503,11 @@ std::tuple BlurCppExample::query_capabilities() use_subgroup_exchange_relative); } +bool BlurCppExample::query_opencl_2_0_support() +{ + return cl::util::opencl_c_version_contains(device, "2.0"); +} + void BlurCppExample::create_image_buffers() { input_image_buf = cl::Image2D( diff --git a/samples/core/blur/blur.hpp b/samples/core/blur/blur.hpp index ccfd0c0c..88c7904d 100644 --- a/samples/core/blur/blur.hpp +++ b/samples/core/blur/blur.hpp @@ -41,6 +41,9 @@ class BlurCppExample { // Query device and runtime capabilities std::tuple query_capabilities(); + // Query device support for OpenCL 2.0 + bool query_opencl_2_0_support(); + void create_image_buffers(); void build_program(std::string kernel_op); diff --git a/samples/core/blur/main.c b/samples/core/blur/main.c index 8960f06c..71708872 100644 --- a/samples/core/blur/main.c +++ b/samples/core/blur/main.c @@ -1048,6 +1048,18 @@ int main(int argc, char *argv[]) free(name); } + // 5) query if OpenCL driver version is 2.0 + bool opencl_version_2_0 = false; + { + char *driver_version = NULL; + OCLERROR_PAR( + driver_version = cl_util_get_device_info(s.device, CL_DRIVER_VERSION, &error), + error, clean); + opencl_version_2_0 = strcmp("2.0", driver_version) ? 0 : 1; + clean: + free(driver_version); + } + /// Create image buffers const cl_image_desc desc = { .image_type = CL_MEM_OBJECT_IMAGE2D, .image_width = s.input_image.width, @@ -1113,7 +1125,7 @@ int main(int argc, char *argv[]) error, prg); /// Subgroup exchange in dual-pass blur - if (use_subgroup_exchange_relative) + if (use_subgroup_exchange_relative && opencl_version_2_0) { printf("Dual-pass subgroup relative exchange blur\n"); @@ -1125,7 +1137,7 @@ int main(int argc, char *argv[]) &s, (cl_int)blur_opts.size), error, prg); } - if (use_subgroup_exchange) + if (use_subgroup_exchange && opencl_version_2_0) { printf("Dual-pass subgroup exchange blur\n"); @@ -1170,7 +1182,7 @@ int main(int argc, char *argv[]) } /// Subgroup exchange in dual-pass Gaussian blur - if (use_subgroup_exchange_relative) + if (use_subgroup_exchange_relative && opencl_version_2_0) { printf("Dual-pass subgroup relative exchange Gaussian blur\n"); @@ -1183,7 +1195,7 @@ int main(int argc, char *argv[]) gauss_kern), error, gkrn); } - if (use_subgroup_exchange) + if (use_subgroup_exchange && opencl_version_2_0) { printf("Dual-pass subgroup exchange Gaussian blur\n"); diff --git a/samples/core/blur/main.cpp b/samples/core/blur/main.cpp index 1b724f17..7472f7e2 100644 --- a/samples/core/blur/main.cpp +++ b/samples/core/blur/main.cpp @@ -49,6 +49,8 @@ int main(int argc, char* argv[]) std::tie(use_local_mem, use_subgroup_exchange, use_subgroup_exchange_relative) = blur.query_capabilities(); + bool opencl_version_2_0 = blur.query_opencl_2_0_support(); + // Create image buffers used for operation. In this example input, // output and temporary image buffers are used. Temporary buffer is used // when 2 blur operations in the row are performed. Result of the first @@ -85,7 +87,7 @@ int main(int argc, char* argv[]) // file you can find 'USE_SUBGROUP_EXCHANGE_RELATIVE' C-like // definition switch for blur_box_horizontal_subgroup_exchange // function. In this case, 2 blur kernel functors are used. - if (use_subgroup_exchange_relative) + if (use_subgroup_exchange_relative && opencl_version_2_0) { std::cout << "Dual-pass subgroup relative exchange blur" << std::endl; @@ -97,7 +99,7 @@ int main(int argc, char* argv[]) // Same as the previous one, but with a different build switch. See // the blur.cl file for more info about the switch. - if (use_subgroup_exchange) + if (use_subgroup_exchange && opencl_version_2_0) { std::cout << "Dual-pass subgroup exchange blur" << std::endl; // cl_khr_subgroup_shuffle requires OpenCL 2.0 @@ -133,7 +135,7 @@ int main(int argc, char* argv[]) // Similar to dual_pass_subgroup_exchange_box_blur but with a gauss // kernel. - if (use_subgroup_exchange_relative) + if (use_subgroup_exchange_relative && opencl_version_2_0) { std::cout << "Dual-pass subgroup relative exchange Gaussian blur" @@ -146,7 +148,7 @@ int main(int argc, char* argv[]) // Same as the previous one, but with a different build switch. See // the blur.cl file for more info about the switch. - if (use_subgroup_exchange) + if (use_subgroup_exchange && opencl_version_2_0) { std::cout << "Dual-pass subgroup exchange Gaussian blur" << std::endl; diff --git a/samples/core/reduce/main.cpp b/samples/core/reduce/main.cpp index 053a2286..088ca469 100644 --- a/samples/core/reduce/main.cpp +++ b/samples/core/reduce/main.cpp @@ -306,7 +306,7 @@ int main(int argc, char* argv[]) std::exit(e.err()); } catch (cl::Error& e) { - std::cerr << "OpenCL rutnime error: " << e.what() << std::endl; + std::cerr << "OpenCL runtime error: " << e.what() << std::endl; std::exit(e.err()); } catch (std::exception& e) { diff --git a/samples/core/saxpy/main.cpp b/samples/core/saxpy/main.cpp index c9f9b188..1e09a4be 100644 --- a/samples/core/saxpy/main.cpp +++ b/samples/core/saxpy/main.cpp @@ -155,7 +155,7 @@ int main(int argc, char* argv[]) std::exit(e.err()); } catch (cl::Error& e) { - std::cerr << "OpenCL rutnime error: " << e.what() << std::endl; + std::cerr << "OpenCL runtime error: " << e.what() << std::endl; std::exit(e.err()); } catch (std::exception& e) { diff --git a/samples/extensions/khr/conway/main.cpp b/samples/extensions/khr/conway/main.cpp index 463f417e..f3c5cb15 100644 --- a/samples/extensions/khr/conway/main.cpp +++ b/samples/extensions/khr/conway/main.cpp @@ -387,7 +387,7 @@ int main(int argc, char* argv[]) std::exit(e.err()); } catch (cl::Error& e) { - std::cerr << "OpenCL rutnime error: " << e.what() << std::endl; + std::cerr << "OpenCL runtime error: " << e.what() << std::endl; std::exit(e.err()); } catch (std::exception& e) { diff --git a/samples/extensions/khr/histogram/main.cpp b/samples/extensions/khr/histogram/main.cpp index a4f33ec5..3409b962 100644 --- a/samples/extensions/khr/histogram/main.cpp +++ b/samples/extensions/khr/histogram/main.cpp @@ -194,7 +194,7 @@ int main(int argc, char* argv[]) std::exit(e.err()); } catch (cl::Error& e) { - std::cerr << "OpenCL rutnime error: " << e.what() << std::endl; + std::cerr << "OpenCL runtime error: " << e.what() << std::endl; std::exit(e.err()); } catch (std::exception& e) { diff --git a/samples/extensions/khr/nbody/main.cpp b/samples/extensions/khr/nbody/main.cpp index 56159f58..3c93fca9 100644 --- a/samples/extensions/khr/nbody/main.cpp +++ b/samples/extensions/khr/nbody/main.cpp @@ -493,7 +493,7 @@ int main(int argc, char* argv[]) std::exit(e.err()); } catch (cl::Error& e) { - std::cerr << "OpenCL rutnime error: " << e.what() << std::endl; + std::cerr << "OpenCL runtime error: " << e.what() << std::endl; std::exit(e.err()); } catch (std::exception& e) { From 09b102ec3935a95e98bdb3b7d44a2e792dd84a25 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:04 +0000 Subject: [PATCH 18/46] Fixed blur/blucpp OpenCL 2.0 check --- samples/core/blur/blur.cpp | 9 ++++++--- samples/core/blur/blur.hpp | 2 +- samples/core/blur/main.c | 16 ++++++---------- samples/core/blur/main.cpp | 14 +++++--------- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/samples/core/blur/blur.cpp b/samples/core/blur/blur.cpp index b8682963..3efa4427 100644 --- a/samples/core/blur/blur.cpp +++ b/samples/core/blur/blur.cpp @@ -494,16 +494,19 @@ std::tuple BlurCppExample::query_capabilities() (device.getInfo() == CL_LOCAL); // 4) query if device allow subgroup shuffle operations + bool use_subgroups = + cl::util::supports_extension(device, "cl_khr_subgroups"); bool use_subgroup_exchange = cl::util::supports_extension(device, "cl_khr_subgroup_shuffle"); bool use_subgroup_exchange_relative = cl::util::supports_extension( device, "cl_khr_subgroup_shuffle_relative"); - return std::make_tuple(use_local_mem, use_subgroup_exchange, - use_subgroup_exchange_relative); + return std::make_tuple(use_local_mem, + use_subgroups && use_subgroup_exchange, + use_subgroups && use_subgroup_exchange_relative); } -bool BlurCppExample::query_opencl_2_0_support() +bool BlurCppExample::query_opencl_c_2_0_support() { return cl::util::opencl_c_version_contains(device, "2.0"); } diff --git a/samples/core/blur/blur.hpp b/samples/core/blur/blur.hpp index 88c7904d..6aa8b808 100644 --- a/samples/core/blur/blur.hpp +++ b/samples/core/blur/blur.hpp @@ -42,7 +42,7 @@ class BlurCppExample { std::tuple query_capabilities(); // Query device support for OpenCL 2.0 - bool query_opencl_2_0_support(); + bool query_opencl_c_2_0_support(); void create_image_buffers(); diff --git a/samples/core/blur/main.c b/samples/core/blur/main.c index 71708872..47ce6b1f 100644 --- a/samples/core/blur/main.c +++ b/samples/core/blur/main.c @@ -1049,13 +1049,13 @@ int main(int argc, char *argv[]) } // 5) query if OpenCL driver version is 2.0 - bool opencl_version_2_0 = false; + bool opencl_c_version_2_0 = false; { char *driver_version = NULL; OCLERROR_PAR( driver_version = cl_util_get_device_info(s.device, CL_DRIVER_VERSION, &error), error, clean); - opencl_version_2_0 = strcmp("2.0", driver_version) ? 0 : 1; + opencl_c_version_2_0 = strcmp("2.0", driver_version) ? 0 : 1; clean: free(driver_version); } @@ -1125,24 +1125,22 @@ int main(int argc, char *argv[]) error, prg); /// Subgroup exchange in dual-pass blur - if (use_subgroup_exchange_relative && opencl_version_2_0) + if (use_subgroup_exchange_relative && opencl_c_version_2_0) { printf("Dual-pass subgroup relative exchange blur\n"); kernel_op[0] = '\0'; - // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); OCLERROR_RET(dual_pass_subgroup_exchange_box_blur( &s, (cl_int)blur_opts.size), error, prg); } - if (use_subgroup_exchange && opencl_version_2_0) + if (use_subgroup_exchange && opencl_c_version_2_0) { printf("Dual-pass subgroup exchange blur\n"); kernel_op[0] = '\0'; - // cl_khr_subgroup_shuffle requires OpenCL 2.0 strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); @@ -1182,12 +1180,11 @@ int main(int argc, char *argv[]) } /// Subgroup exchange in dual-pass Gaussian blur - if (use_subgroup_exchange_relative && opencl_version_2_0) + if (use_subgroup_exchange_relative && opencl_c_version_2_0) { printf("Dual-pass subgroup relative exchange Gaussian blur\n"); kernel_op[0] = '\0'; - // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); @@ -1195,12 +1192,11 @@ int main(int argc, char *argv[]) gauss_kern), error, gkrn); } - if (use_subgroup_exchange && opencl_version_2_0) + if (use_subgroup_exchange && opencl_c_version_2_0) { printf("Dual-pass subgroup exchange Gaussian blur\n"); kernel_op[0] = '\0'; - // cl_khr_subgroup_shuffle requires OpenCL 2.0 strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); diff --git a/samples/core/blur/main.cpp b/samples/core/blur/main.cpp index 7472f7e2..a33a16e0 100644 --- a/samples/core/blur/main.cpp +++ b/samples/core/blur/main.cpp @@ -49,7 +49,7 @@ int main(int argc, char* argv[]) std::tie(use_local_mem, use_subgroup_exchange, use_subgroup_exchange_relative) = blur.query_capabilities(); - bool opencl_version_2_0 = blur.query_opencl_2_0_support(); + bool opencl_c_version_2_0 = blur.query_opencl_c_2_0_support(); // Create image buffers used for operation. In this example input, // output and temporary image buffers are used. Temporary buffer is used @@ -87,11 +87,10 @@ int main(int argc, char* argv[]) // file you can find 'USE_SUBGROUP_EXCHANGE_RELATIVE' C-like // definition switch for blur_box_horizontal_subgroup_exchange // function. In this case, 2 blur kernel functors are used. - if (use_subgroup_exchange_relative && opencl_version_2_0) + if (use_subgroup_exchange_relative && opencl_c_version_2_0) { std::cout << "Dual-pass subgroup relative exchange blur" << std::endl; - // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 blur.build_program( "-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_box_blur(); @@ -99,10 +98,9 @@ int main(int argc, char* argv[]) // Same as the previous one, but with a different build switch. See // the blur.cl file for more info about the switch. - if (use_subgroup_exchange && opencl_version_2_0) + if (use_subgroup_exchange && opencl_c_version_2_0) { std::cout << "Dual-pass subgroup exchange blur" << std::endl; - // cl_khr_subgroup_shuffle requires OpenCL 2.0 blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_box_blur(); } @@ -135,12 +133,11 @@ int main(int argc, char* argv[]) // Similar to dual_pass_subgroup_exchange_box_blur but with a gauss // kernel. - if (use_subgroup_exchange_relative && opencl_version_2_0) + if (use_subgroup_exchange_relative && opencl_c_version_2_0) { std::cout << "Dual-pass subgroup relative exchange Gaussian blur" << std::endl; - // cl_khr_subgroup_shuffle_relative requires OpenCL 2.0 blur.build_program( "-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_kernel_blur(); @@ -148,11 +145,10 @@ int main(int argc, char* argv[]) // Same as the previous one, but with a different build switch. See // the blur.cl file for more info about the switch. - if (use_subgroup_exchange && opencl_version_2_0) + if (use_subgroup_exchange && opencl_c_version_2_0) { std::cout << "Dual-pass subgroup exchange Gaussian blur" << std::endl; - // cl_khr_subgroup_shuffle requires OpenCL 2.0 blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 "); blur.dual_pass_subgroup_exchange_kernel_blur(); } From ca75f3e86e8bc5621f8adfcb669aa125f13f6a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:05 +0000 Subject: [PATCH 19/46] Various minor improvements --- .github/workflows/presubmit.yml | 1037 +++++++++-------- CMakeLists.txt | 2 +- lib/src/Extensions/CMakeLists.txt | 2 +- samples/core/copybuffer/main.cpp | 4 +- samples/core/copybufferkernel/main.cpp | 4 +- test/cmake/findmodule/CMakeLists.txt | 2 +- .../pkgconfig/platformenum/CMakeLists.txt | 4 +- test/cmake/pkgconfig/useutil/CMakeLists.txt | 4 +- 8 files changed, 595 insertions(+), 464 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index dc5564d8..42a98c09 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -3,25 +3,12 @@ name: Presubmit on: [push, pull_request] jobs: - get-branch: - runs-on: ubuntu-latest - steps: - - name: Get working branch - id: get-branch - run: | - if [[ ${{ github.event_name }} == "push" ]]; then - echo "branch=main" >> $GITHUB_OUTPUT - else - echo "branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT - fi ; - echo $GITHUB_OUTPUT - outputs: - branch: ${{ steps.get-branch.outputs.branch }} - format: name: Code formatting runs-on: ubuntu-latest - needs: get-branch + defaults: + run: + shell: bash steps: - uses: actions/checkout@v3 with: @@ -30,47 +17,113 @@ jobs: - name: Install clang-format run: sudo apt-get install clang-format - name: Check format - run: $GITHUB_WORKSPACE/scripts/check-format.sh origin/${{ needs.get-branch.outputs.branch }} --binary clang-format + run: $GITHUB_WORKSPACE/scripts/check-format.sh + origin/`if [[ "${{ github.event_name }}" == "push" ]]; then echo "main"; else echo "${{ github.base_ref }}"; fi` + --binary clang-format linux: runs-on: ubuntu-latest needs: format + defaults: + run: + shell: bash strategy: matrix: CMAKE: [3.26.4] COMPILER: - - C_NAME: gcc - CXX_NAME: g++ - VER: 11 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - - C_NAME: gcc - CXX_NAME: g++ - VER: 13 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - - C_NAME: clang - CXX_NAME: clang++ - VER: 14 - EXCLUSIVE_C_FLAGS: "" - - C_NAME: clang - CXX_NAME: clang++ - VER: 16 - EXCLUSIVE_C_FLAGS: "" + - C_NAME: gcc + CXX_NAME: g++ + VER: 11 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + - C_NAME: gcc + CXX_NAME: g++ + VER: 13 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + - C_NAME: clang + CXX_NAME: clang++ + VER: 14 + EXCLUSIVE_C_FLAGS: "" + - C_NAME: clang + CXX_NAME: clang++ + VER: 16 + EXCLUSIVE_C_FLAGS: "" DEPS: [os, vcpkg] BIN: [64] STD: - - C: 11 # Utils C library uses C11 functions (e.g. timespec_get) - CXX: 14 # Utils C++ library uses C14 types (e.g. integer_sequence) - - C: 17 - CXX: 17 + - C: 11 # Utils C library uses C11 functions (e.g. timespec_get) + CXX: 14 # Utils C++ library uses C14 types (e.g. integer_sequence) + - C: 17 + CXX: 17 CONF: - - GEN: Unix Makefiles + - GEN: Unix Makefiles + CONFIG: Debug + - GEN: Unix Makefiles + CONFIG: Release + - GEN: Ninja Multi-Config + CONFIG: Release + IMAGE: + - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 + include: + - CMAKE: system + COMPILER: + C_NAME: gcc + CXX_NAME: g++ + VER: 9 + EXCLUSIVE_C_FLAGS: "" + DEPS: system + BIN: 64 + STD: + C: 11 + CXX: 14 + CONF: + GEN: Unix Makefiles CONFIG: Debug - - GEN: Unix Makefiles + IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 + - CMAKE: system + COMPILER: + C_NAME: gcc + CXX_NAME: g++ + VER: 9 + EXCLUSIVE_C_FLAGS: "" + DEPS: system + BIN: 64 + STD: + C: 11 + CXX: 14 + CONF: + GEN: Unix Makefiles CONFIG: Release - - GEN: Ninja Multi-Config + IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 + - CMAKE: system + COMPILER: + C_NAME: gcc + CXX_NAME: g++ + VER: 9 + EXCLUSIVE_C_FLAGS: "" + DEPS: vcpkg + BIN: 32 + STD: + C: 11 + CXX: 14 + CONF: + GEN: Unix Makefiles + CONFIG: Debug + IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 + - CMAKE: system + COMPILER: + C_NAME: gcc + CXX_NAME: g++ + VER: 9 + EXCLUSIVE_C_FLAGS: "" + DEPS: vcpkg + BIN: 32 + STD: + C: 11 + CXX: 14 + CONF: + GEN: Unix Makefiles CONFIG: Release - IMAGE: - - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 + IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 container: ${{matrix.IMAGE}} env: CMAKE_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cmake @@ -79,39 +132,75 @@ jobs: DEB_INSTALLATION_PATH: /usr CC: ${{matrix.COMPILER.C_NAME}}-${{matrix.COMPILER.VER}} CXX: ${{matrix.COMPILER.CXX_NAME}}-${{matrix.COMPILER.VER}} - # Excluding missing-field-initializers error because it comes from the Std dependency - # Excluding maybe-uninitialized error because cannot workaround the compiler issuing this error - # Not using -pedantic: error: ISO C forbids braced-groups within expressions - CFLAGS: -Wall -Wextra -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }} - # Excluding missing-field-initializers error because it comes from the Std dependency - CXXFLAGS: -Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers - steps: - - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: recursive + - name: Set up vcpkg triplet + if: matrix.DEPS == 'vcpkg' + run: if [[ "${{ matrix.BIN }}" == "64" ]]; then + echo "VCPKG_TRIPLET=x64-linux" >> $GITHUB_ENV; + else + echo "VCPKG_TRIPLET=x86-linux" >> $GITHUB_ENV; + fi + + - name: Install system CMake + if: matrix.CMAKE == 'system' + run: apt-get update -qq && apt-get install -y cmake && + echo "CMAKE_EXE=cmake" >> "$GITHUB_ENV" && + echo "CTEST_EXE=ctest" >> "$GITHUB_ENV" && + echo "CPACK_EXE=cpack" >> "$GITHUB_ENV" + + - name: Cache dependencies (vcpkg) + if: matrix.DEPS == 'vcpkg' + id: vcpkg-install + uses: actions/cache@v3 + with: + path: /opt/Microsoft/vcpkg + key: vcpkg-linux-${{matrix.BIN}} + + - name: Install dependencies (vcpkg) + if: matrix.DEPS == 'vcpkg' && steps.vcpkg-install.outputs.cache-hit != 'true' + run: | + cd /opt/Microsoft/vcpkg + git pull + ./bootstrap-vcpkg.sh + ./vcpkg --triplet=$VCPKG_TRIPLET install tclap stb + # It is not possible to cross-compile the OpenGL samples on Ubuntu + # because system dev dependencies are not available for i386 + if [[ "${{ matrix.BIN }}" == "64" ]]; then + ./vcpkg --triplet=$VCPKG_TRIPLET install sfml glm glew; + fi + + - name: Set up compiler flags + run: | + # Excluding missing-field-initializers error because it comes from the Std dependency + # Excluding maybe-uninitialized error because cannot workaround the compiler issuing this error + # Not using -pedantic: error: ISO C forbids braced-groups within expressions + echo "CFLAGS=-Wall -Wextra -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }}" >> $GITHUB_ENV; + # Excluding missing-field-initializers error because it comes from the Std dependency + echo "CXXFLAGS=-Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers" >> $GITHUB_ENV; - - name: Configure, package & install OpenCL-Headers - shell: bash - run: $CMAKE_EXE + - name: Checkout OpenCL-SDK + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + + - name: Configure, package & install OpenCL-Headers + run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D BUILD_TESTING=OFF -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH -S $GITHUB_WORKSPACE/external/OpenCL-Headers -B $GITHUB_WORKSPACE/external/OpenCL-Headers/build && - $CPACK_EXE + $CPACK_EXE --config "$GITHUB_WORKSPACE/external/OpenCL-Headers/build/CPackConfig.cmake" -G DEB - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` + -C ${{matrix.CONF.CONFIG}} -B "$GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb" && - dpkg -i $GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb/*.deb + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-Headers/package-deb/*.deb - - name: Configure, package & install OpenCL-ICD-Loader - shell: bash - run: $CMAKE_EXE + - name: Configure, package & install OpenCL-ICD-Loader + run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D BUILD_TESTING=OFF @@ -120,166 +209,176 @@ jobs: -B $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build && if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then - $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build --parallel `nproc`; else - $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build --config Debug -- -j`nproc`; - $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build --config Release -- -j`nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build --config Debug --parallel `nproc`; + $CMAKE_EXE --build $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build --config Release --parallel `nproc`; fi && - $CPACK_EXE + $CPACK_EXE --config "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/build/CPackConfig.cmake" -G DEB - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` + -C ${{matrix.CONF.CONFIG}} -B "$GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb" && - dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb && - dpkg -c $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/ocl-icd-opencl-dev_3.0-1_amd64.deb + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-ICD-Loader/package-deb/*.deb - - name: Configure, package & install OpenCL-CLHPP - shell: bash - run: $CMAKE_EXE + - name: Configure, package & install OpenCL-CLHPP + run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` -D BUILD_TESTING=OFF -D BUILD_EXAMPLES=OFF + -D BUILD_DOCS=OFF -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH -S $GITHUB_WORKSPACE/external/OpenCL-CLHPP -B $GITHUB_WORKSPACE/external/OpenCL-CLHPP/build && - $CPACK_EXE + $CPACK_EXE --config "$GITHUB_WORKSPACE/external/OpenCL-CLHPP/build/CPackConfig.cmake" -G DEB - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` + -C ${{matrix.CONF.CONFIG}} -B "$GITHUB_WORKSPACE/external/OpenCL-CLHPP/package-deb" && - dpkg -i $GITHUB_WORKSPACE/external/OpenCL-CLHPP/package-deb/*.deb - - - name: Configure - shell: bash - run: if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; - then - git clone https://github.com/Microsoft/vcpkg.git; - ./vcpkg/bootstrap-vcpkg.sh; - ./vcpkg/vcpkg install sfml tclap glm glew stb; - TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; - else - TOOLCHAIN_ARG=""; - fi && - $CMAKE_EXE - $TOOLCHAIN_ARG - -G "${{matrix.CONF.GEN}}" - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` - -D BUILD_DOCS=ON - -D BUILD_TESTING=ON - -D BUILD_EXAMPLES=ON - -D OPENCL_SDK_BUILD_SAMPLES=ON - -D OPENCL_ICD_LOADER_BUILD_TESTING=ON - -D CMAKE_C_STANDARD=${{matrix.STD.C}} - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} - -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install - -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH - -S $GITHUB_WORKSPACE - -B $GITHUB_WORKSPACE/build - - - name: Build - shell: bash - run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; - then - $CMAKE_EXE --build $GITHUB_WORKSPACE/build -- -j`nproc`; - else - $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Debug -- -j`nproc`; - $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Release -- -j`nproc`; - fi; - - - name: Test - shell: bash - working-directory: ${{runner.workspace}}/OpenCL-SDK/build - run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; - then - $CTEST_EXE --output-on-failure --parallel `nproc`; - else - $CTEST_EXE --output-on-failure -C Debug --parallel `nproc`; - $CTEST_EXE --output-on-failure -C Release --parallel `nproc`; - fi; - - - name: Package DEB - shell: bash - run: $CPACK_EXE - --config "$GITHUB_WORKSPACE/build/CPackConfig.cmake" - -G DEB - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-C ${{matrix.CONF.CONFIG}}"; fi` - -B "$GITHUB_WORKSPACE/package-deb" && - dpkg -c $GITHUB_WORKSPACE/package-deb/khronos-opencl-sdk_2023.4.17-1_amd64.deb - - - name: Consume (DEB) - shell: bash - run: dpkg -i $GITHUB_WORKSPACE/package-deb/*.deb && - $CMAKE_EXE - -G "${{matrix.CONF.GEN}}" - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` - -D CMAKE_C_STANDARD=${{matrix.STD.C}} - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} - -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil - -B $GITHUB_WORKSPACE/build_package && - if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; - then - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package -- -j`nproc`; - else - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Debug -- -j`nproc`; - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Release -- -j`nproc`; - fi; - - - name: Uninstall (DEB) - shell: bash - run: apt-get remove -y ocl-icd-opencl-dev ocl-icd-libopencl1 opencl-c-headers opencl-clhpp-headers opencl-sdk + dpkg -i $GITHUB_WORKSPACE/external/OpenCL-CLHPP/package-deb/*.deb - - name: Test install - shell: bash - run: $CMAKE_EXE - --build $GITHUB_WORKSPACE/build - --target install - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "--config ${{matrix.CONF.CONFIG}}"; fi` - -- - -j`nproc` + - name: Configure + run: $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + `if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; then echo "-D CMAKE_TOOLCHAIN_FILE=/opt/Microsoft/vcpkg/scripts/buildsystems/vcpkg.cmake"; fi;` + `if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; then echo "-D VCPKG_TARGET_TRIPLET=$VCPKG_TRIPLET"; fi;` + -D BUILD_DOCS=ON + -D BUILD_TESTING=ON + -D BUILD_EXAMPLES=ON + -D OPENCL_SDK_BUILD_SAMPLES=ON + `if [[ "${{matrix.BIN}}" == "32" ]]; then echo "-D OPENCL_SDK_BUILD_OPENGL_SAMPLES=OFF"; fi;` + -D OPENCL_ICD_LOADER_BUILD_TESTING=ON + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} + -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install + -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH + -S $GITHUB_WORKSPACE + -B $GITHUB_WORKSPACE/build - - name: Consume (install) - shell: bash - run: $CMAKE_EXE - -G "${{matrix.CONF.GEN}}" - `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` - -D CMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/install - -D CMAKE_C_STANDARD=${{matrix.STD.C}} - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} - -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil - -B $GITHUB_WORKSPACE/build_install && - if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; - then - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install -- -j`nproc`; - else - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Debug -- -j`nproc`; - $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Release -- -j`nproc`; - fi; + - name: Build + run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --parallel `nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Debug; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build --config Release; + fi; + + - name: Test + if: matrix.BIN != 32 + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CTEST_EXE --output-on-failure --no-tests=error -C ${{matrix.CONF.CONFIG}} --parallel `nproc`; + else + $CTEST_EXE --output-on-failure --no-tests=error -C Debug --parallel `nproc`; + $CTEST_EXE --output-on-failure --no-tests=error -C Release --parallel `nproc`; + fi; + + - name: Package DEB + run: $CPACK_EXE + --config "$GITHUB_WORKSPACE/build/CPackConfig.cmake" + -G DEB + -C ${{matrix.CONF.CONFIG}} + -B "$GITHUB_WORKSPACE/package-deb" + + - name: Consume (DEB) + run: dpkg -i $GITHUB_WORKSPACE/package-deb/*.deb && + $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} + -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil + -B $GITHUB_WORKSPACE/build_package && + if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --parallel `nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Debug; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_package --config Release; + fi + + - name: Run consume test (DEB) + if: matrix.BIN != 32 + working-directory: ${{runner.workspace}}/OpenCL-SDK/build_package + run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CTEST_EXE -C ${{matrix.CONF.CONFIG}} --no-tests=error --output-on-failure --parallel `nproc`; + else + $CTEST_EXE -C Debug --output-on-failure --no-tests=error --parallel `nproc`; + $CTEST_EXE -C Release --output-on-failure --no-tests=error --parallel `nproc`; + fi + + - name: Uninstall (DEB) + # ToDo: khronos-opencl-loader* + run: apt-get remove -y "ocl-icd*" opencl-c-headers opencl-clhpp-headers opencl-sdk + + - name: Test install + run: $CMAKE_EXE + --build $GITHUB_WORKSPACE/build + --target install + --config ${{matrix.CONF.CONFIG}} + --parallel `nproc` + + - name: Consume (install) + run: $CMAKE_EXE + -G "${{matrix.CONF.GEN}}" + `if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; then echo "-D CMAKE_BUILD_TYPE=${{matrix.CONF.CONFIG}}"; fi` + -D CMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/install + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} + -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil + -B $GITHUB_WORKSPACE/build_install && + if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --parallel `nproc`; + else + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Debug; + $CMAKE_EXE --build $GITHUB_WORKSPACE/build_install --config Release; + fi + + - name: Run consume test (install) + if: matrix.BIN != 32 + working-directory: ${{runner.workspace}}/OpenCL-SDK/build_install + run: if [[ "${{matrix.CONF.GEN}}" == "Unix Makefiles" ]]; + then + $CTEST_EXE -C ${{matrix.CONF.CONFIG}} --output-on-failure --no-tests=error --parallel `nproc`; + else + $CTEST_EXE -C Debug --output-on-failure --no-tests=error --parallel `nproc`; + $CTEST_EXE -C Release --output-on-failure --no-tests=error --parallel `nproc`; + fi windows: runs-on: windows-latest needs: format + defaults: + run: + shell: pwsh strategy: matrix: VER: [v141, v142, v143, clangcl] GEN: [Visual Studio 17 2022, Ninja Multi-Config] - DEPS: [os, vcpkg] + DEPS: [vcpkg, fetch] BIN: [x64] STD: - - C: 11 - CXX: 14 - - C: 17 - CXX: 17 + - C: 11 + CXX: 14 + - C: 17 + CXX: 17 exclude: - VER: clangcl GEN: Ninja Multi-Config include: - - VER: v142 - GEN: Visual Studio 17 2022 - BIN: x86 - STD: - C: 11 - CXX: 14 + - VER: v142 + GEN: Visual Studio 17 2022 + BIN: x86 + DEPS: fetch + STD: + C: 11 + CXX: 14 env: NINJA_URL: https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip NINJA_ROOT: C:\Tools\Ninja @@ -293,261 +392,274 @@ jobs: IMAGE_INTEL_PREFIX: C:\Tools\Intel steps: - - name: Cache Ninja install - if: matrix.GEN == 'Ninja Multi-Config' - id: ninja-install - uses: actions/cache@v3 - with: - path: | - C:\Tools\Ninja - key: ${{runner.os}}-ninja-${{env.NINJA_URL}} + - name: Cache Ninja install + if: matrix.GEN == 'Ninja Multi-Config' + id: ninja-install + uses: actions/cache@v3 + with: + path: | + C:\Tools\Ninja + key: ${{runner.os}}-ninja-${{env.NINJA_URL}} + + - name: Install Ninja + if: matrix.GEN == 'Ninja Multi-Config' && steps.ninja-install.outputs.cache-hit != 'true' + run: | + Invoke-WebRequest ${env:NINJA_URL} -OutFile ~\Downloads\ninja-win.zip + Expand-Archive ~\Downloads\ninja-win.zip -DestinationPath ${env:NINJA_ROOT}\ + Remove-Item ~\Downloads\* + + - name: Install OpenCL runtime + if: matrix.BIN != 'x86' + run: | + $INTEL_OCL_ARCHIVE_NAME = Split-Path ${env:INTEL_OCL_URL} -Leaf; ` + Invoke-WebRequest ${env:INTEL_OCL_URL} -OutFile ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME; ` + Expand-Archive ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME -DestinationPath ${env:IMAGE_INTEL_PREFIX}\oclcpuexp; ` + Remove-Item ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME; ` + $INTEL_TBB_ARCHIVE_NAME = Split-Path ${env:INTEL_TBB_URL} -Leaf; ` + Invoke-WebRequest ${env:INTEL_TBB_URL} -OutFile ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME; ` + Expand-Archive ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME -DestinationPath ${env:IMAGE_INTEL_PREFIX}; ` + Get-ChildItem ${env:IMAGE_INTEL_PREFIX}\oneapi-tbb* | Rename-Item -NewName oneapi-tbb; ` + Remove-Item ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME; ` + New-Item -Type Directory ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\tbb | Out-Null; ` + Get-ChildItem ${env:IMAGE_INTEL_PREFIX}\oneapi-tbb\redist\intel64\vc14\*.dll | ForEach-Object { New-Item -Type SymbolicLink -Path ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\tbb -Name $_.Name -Value $_.FullName | Out-Null; }; ` + New-Item -Type Directory HKLM:\SOFTWARE\Khronos\OpenCL -Force | Out-Null; ` + New-Item -Type File HKLM:\SOFTWARE\Khronos\OpenCL\Vendors | Out-Null; ` + Set-ItemProperty -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors -Name ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\intelocl64.dll -Type DWord -Value 0; + + - name: Cache dependencies (vcpkg) + if: matrix.DEPS == 'vcpkg' + id: vcpkg-install + uses: actions/cache@v3 + with: + path: | + C:\vcpkg + key: x64-windows-sfml-tclap-glm-glew-stb - - name: Install Ninja - if: matrix.GEN == 'Ninja Multi-Config' && steps.ninja-install.outputs.cache-hit != 'true' - shell: pwsh - run: | - Invoke-WebRequest ${env:NINJA_URL} -OutFile ~\Downloads\ninja-win.zip - Expand-Archive ~\Downloads\ninja-win.zip -DestinationPath ${env:NINJA_ROOT}\ - Remove-Item ~\Downloads\* + - name: Install dependencies (vcpkg) + if: matrix.DEPS == 'vcpkg' && steps.vcpkg-install.outputs.cache-hit != 'true' + run: C:\vcpkg\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb - - name: Install OpenCL runtime - shell: pwsh - run: | - $INTEL_OCL_ARCHIVE_NAME = Split-Path ${env:INTEL_OCL_URL} -Leaf; ` - Invoke-WebRequest ${env:INTEL_OCL_URL} -OutFile ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME; ` - Expand-Archive ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME -DestinationPath ${env:IMAGE_INTEL_PREFIX}\oclcpuexp; ` - Remove-Item ${env:TEMP}\$INTEL_OCL_ARCHIVE_NAME; ` - $INTEL_TBB_ARCHIVE_NAME = Split-Path ${env:INTEL_TBB_URL} -Leaf; ` - Invoke-WebRequest ${env:INTEL_TBB_URL} -OutFile ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME; ` - Expand-Archive ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME -DestinationPath ${env:IMAGE_INTEL_PREFIX}; ` - Get-ChildItem ${env:IMAGE_INTEL_PREFIX}\oneapi-tbb* | Rename-Item -NewName oneapi-tbb; ` - Remove-Item ${env:TEMP}\$INTEL_TBB_ARCHIVE_NAME; ` - New-Item -Type Directory ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\tbb | Out-Null; ` - Get-ChildItem ${env:IMAGE_INTEL_PREFIX}\oneapi-tbb\redist\intel64\vc14\*.dll | ForEach-Object { New-Item -Type SymbolicLink -Path ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\tbb -Name $_.Name -Value $_.FullName | Out-Null; }; ` - New-Item -Type Directory HKLM:\SOFTWARE\Khronos\OpenCL -Force | Out-Null; ` - New-Item -Type File HKLM:\SOFTWARE\Khronos\OpenCL\Vendors | Out-Null; ` - Set-ItemProperty -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors -Name ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\intelocl64.dll -Type DWord -Value 0; + - name: Set up compiler flags + run: | + echo "CFLAGS=/W4 /WX" >> $GITHUB_ENV + echo "CXXFLAGS=/W4 /WX" >> $GITHUB_ENV - - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: recursive + - name: Checkout OpenCL-SDK + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive - - name: Configure (MSBuild) - if: matrix.GEN == 'Visual Studio 17 2022' - shell: pwsh - run: | - if ('${{ matrix.DEPS }}' -eq 'vcpkg') { - Get-ChildItem Env:\ - & ${env:VCPKG_INSTALLATION_ROOT}\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb - $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" - } else { - $TOOLCHAIN_ARG='' - } - $BIN = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} + - name: Configure (MSBuild) + if: matrix.GEN == 'Visual Studio 17 2022' + run: | + if ('${{ matrix.DEPS }}' -eq 'vcpkg') { + $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" + } else { + $TOOLCHAIN_ARG='' + } + $BIN = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} + & cmake ` + $TOOLCHAIN_ARG ` + -G "${{matrix.GEN}}" ` + -A $BIN ` + -T ${{matrix.VER}} ` + -D BUILD_DOCS=ON ` + -D BUILD_TESTING=ON ` + -D OPENCL_SDK_BUILD_SAMPLES=ON ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` + -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` + -S ${env:GITHUB_WORKSPACE} ` + -B ${env:GITHUB_WORKSPACE}\build + if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." } + + - name: Configure (Ninja Multi-Config) + if: matrix.GEN == 'Ninja Multi-Config' + run: | + if ('${{ matrix.DEPS }}' -eq 'vcpkg') { + $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" + } else { + $TOOLCHAIN_ARG='' + } + $VER = switch ('${{matrix.VER}}') { ` + 'v141' {'14.1'} ` + 'v142' {'14.2'} ` + 'v143' {'14.3'} } + Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" + & cmake ` + $TOOLCHAIN_ARG ` + -G "${{matrix.GEN}}" ` + -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` + -D BUILD_DOCS=ON ` + -D BUILD_TESTING=ON ` + -D OPENCL_SDK_BUILD_SAMPLES=ON ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` + -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` + -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` + -S ${env:GITHUB_WORKSPACE} ` + -B ${env:GITHUB_WORKSPACE}\build + if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." } + + - name: Build (MSBuild) + if: matrix.GEN == 'Visual Studio 17 2022' + run: | + foreach ($Config in 'Release','Debug') { ` & cmake ` - $TOOLCHAIN_ARG ` - -G "${{matrix.GEN}}" ` - -A $BIN ` - -T ${{matrix.VER}} ` - -D BUILD_DOCS=ON ` - -D BUILD_TESTING=ON ` - -D OPENCL_SDK_BUILD_SAMPLES=ON ` - -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` - -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` - -S ${env:GITHUB_WORKSPACE} ` - -B ${env:GITHUB_WORKSPACE}\build - - - name: Configure (Ninja Multi-Config) - if: matrix.GEN == 'Ninja Multi-Config' - shell: pwsh - run: | - if ('${{ matrix.DEPS }}' -eq 'vcpkg') { - Get-ChildItem Env:\ - & ${env:VCPKG_INSTALLATION_ROOT}\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb - $TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" - } else { - $TOOLCHAIN_ARG='' - } - $VER = switch ('${{matrix.VER}}') { ` - 'v141' {'14.1'} ` - 'v142' {'14.2'} ` - 'v143' {'14.3'} } - Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" - Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" - & cmake ` - $TOOLCHAIN_ARG ` - -G "${{matrix.GEN}}" ` - -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` - -D BUILD_DOCS=ON ` - -D BUILD_TESTING=ON ` - -D OPENCL_SDK_BUILD_SAMPLES=ON ` - -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` - -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` - -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` - -S ${env:GITHUB_WORKSPACE} ` - -B ${env:GITHUB_WORKSPACE}\build - - - name: Build (MSBuild) - if: matrix.GEN == 'Visual Studio 17 2022' - shell: pwsh - run: | - foreach ($Config in 'Release','Debug') { ` - & cmake ` - --build "${env:GITHUB_WORKSPACE}\build" ` - --config $Config ` - -- ` - /verbosity:minimal ` - /maxCpuCount ` - /noLogo - } - - - name: Build (Ninja Multi-Config) - if: matrix.GEN == 'Ninja Multi-Config' - shell: pwsh - run: | - $VER = switch ('${{matrix.VER}}') { ` - 'v141' {'14.1'} ` - 'v142' {'14.2'} ` - 'v143' {'14.3'} } - Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" - Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" - foreach ($Config in 'Release','Debug') { ` - & cmake ` - --build "${env:GITHUB_WORKSPACE}\build" ` - --config $Config ` - -- ` - -j ${env:NUMBER_OF_PROCESSORS} - } - - - name: Test - working-directory: ${{runner.workspace}}/OpenCL-SDK/build - shell: pwsh - run: | - foreach ($Config in 'Release','Debug') { - & ctest ` - --build-config ${Config} ` - --output-on-failure ` - --parallel ${env:NUMBER_OF_PROCESSORS} - } - - - name: Install - shell: pwsh - run: | + --build "${env:GITHUB_WORKSPACE}\build" ` + --config $Config ` + -- ` + /verbosity:minimal ` + /maxCpuCount ` + /noLogo + if ($LASTEXITCODE -ne 0) { throw "Building OpenCL-SDK in $Config failed." } + } + + - name: Build (Ninja Multi-Config) + if: matrix.GEN == 'Ninja Multi-Config' + run: | + $VER = switch ('${{matrix.VER}}') { ` + 'v141' {'14.1'} ` + 'v142' {'14.2'} ` + 'v143' {'14.3'} } + Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" + foreach ($Config in 'Release','Debug') { ` & cmake ` - --install "${env:GITHUB_WORKSPACE}\build" ` - --prefix "${env:GITHUB_WORKSPACE}\install" ` - --config Release - - - name: "Consume (MSBuild SDK): Configure/Build/Test" - shell: pwsh - run: | - $BIN = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} + --build "${env:GITHUB_WORKSPACE}\build" ` + --config $Config + if ($LASTEXITCODE -ne 0) { throw "Building OpenCL-SDK in $Config failed." } + } + + - name: Test + if: matrix.BIN != 'x86' + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + run: | + foreach ($Config in 'Release','Debug') { + & ctest ` + --build-config ${Config} ` + --output-on-failure ` + --no-tests=error ` + --parallel ${env:NUMBER_OF_PROCESSORS} + if ($LASTEXITCODE -ne 0) { throw "Running OpenCL-SDK tests in $Config failed." } + } + + - name: Install + run: | + & cmake ` + --install "${env:GITHUB_WORKSPACE}\build" ` + --prefix "${env:GITHUB_WORKSPACE}\install" ` + --config Release + if ($LASTEXITCODE -ne 0) { throw "Installing OpenCL-SDK failed." } + + - name: "Consume (MSBuild SDK): Configure/Build/Test" + if: matrix.GEN == 'Visual Studio 17 2022' + run: | + $BIN = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} + & cmake ` + -G '${{matrix.GEN}}' ` + -A $BIN ` + -T ${{matrix.VER}} ` + -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` + -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\install" ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` + -S ${env:GITHUB_WORKSPACE}\test\cmake\pkgconfig\useutil ` + -B ${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil + if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK consume test failed." } + foreach ($Config in 'Release') { & cmake ` - -G '${{matrix.GEN}}' ` - -A $BIN ` - -T ${{matrix.VER}} ` - -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` - -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\install" ` - -D DRIVER_STUB_PATH="${env:GITHUB_WORKSPACE}\build\Release\OpenCLDriverStub.dll" ` - -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` - -S "${env:GITHUB_WORKSPACE}\test\pkgconfig\useutil" ` - -B "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" - foreach ($Config in 'Release','Debug') { ` - & cmake ` - --build "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" ` - --config ${Config} ` - & cd ${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil ` - & ctest ` - --output-on-failure -C ${Config} - } - - - name: "Consume (Ninja-Multi-Config SDK): Configure/Build/Test" - shell: pwsh - run: | - $VER = switch ('${{matrix.VER}}') { ` - 'v141' {'14.1'} ` - 'v142' {'14.2'} ` - 'v143' {'14.3'} } - Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" - Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=${VER}" + --build "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" ` + --config ${Config} + if ($LASTEXITCODE -ne 0) { throw "Building OpenCL-SDK consume test in $Config failed." } + } + + - name: "Consume (Ninja-Multi-Config SDK): Configure/Build/Test" + if: matrix.GEN == 'Ninja Multi-Config' + run: | + $VER = switch ('${{matrix.VER}}') { ` + 'v141' {'14.1'} ` + 'v142' {'14.2'} ` + 'v143' {'14.3'} } + Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" + Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=${VER}" + & cmake ` + -G '${{matrix.GEN}}' ` + -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` + -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` + -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\external\OpenCL-Headers\install;${env:GITHUB_WORKSPACE}\install" ` + -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` + -S ${env:GITHUB_WORKSPACE}\test\cmake\pkgconfig\useutil ` + -B ${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil + if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK consume test failed." } + foreach ($Config in 'Release') { & cmake ` - -G '${{matrix.GEN}}' ` - -D CMAKE_MAKE_PROGRAM="${env:NINJA_ROOT}\ninja.exe" ` - -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` - -D CMAKE_PREFIX_PATH="${env:GITHUB_WORKSPACE}\external\OpenCL-Headers\install;${env:GITHUB_WORKSPACE}\install" ` - -D DRIVER_STUB_PATH="${env:GITHUB_WORKSPACE}\build\Release\OpenCLDriverStub.dll" ` - -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` - -S "${env:GITHUB_WORKSPACE}\test\pkgconfig\useutil" ` - -B "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" - foreach ($Config in 'Release','Debug') { ` - & cmake ` - --build "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" ` - --config ${Config} ` - & cd ${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil ` - & ctest ` - --output-on-failure -C ${Config} - } + --build "${env:GITHUB_WORKSPACE}\downstream\pkgconfig\useutil" ` + --config ${Config} + if ($LASTEXITCODE -ne 0) { throw "Building OpenCL-SDK consume test in $Config failed." } + } + + - name: Consume test + if: matrix.BIN != 'x86' + working-directory: ${{runner.workspace}}/OpenCL-SDK/downstream/pkgconfig/useutil + run: | + foreach ($Config in 'Release') { + & ctest ` + --build-config ${Config} ` + --output-on-failure ` + --no-tests=error ` + --parallel ${env:NUMBER_OF_PROCESSORS} + if ($LASTEXITCODE -ne 0) { throw "Running OpenCL-SDK consume test in $Config failed." } + } macos: runs-on: macos-latest needs: format + defaults: + run: + shell: bash strategy: matrix: COMPILER: - - C_NAME: /usr/bin/gcc - CXX_NAME: /usr/bin/g++ - EXCLUSIVE_C_FLAGS: -Wno-conditional-uninitialized - - C_NAME: /usr/local/bin/gcc-11 - CXX_NAME: /usr/local/bin/g++-11 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - - C_NAME: /usr/local/bin/gcc-13 - CXX_NAME: /usr/local/bin/g++-13 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + - C_NAME: /usr/bin/clang + CXX_NAME: /usr/bin/clang++ + EXCLUSIVE_C_FLAGS: -Wno-conditional-uninitialized + - C_NAME: /usr/local/bin/gcc-11 + CXX_NAME: /usr/local/bin/g++-11 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + - C_NAME: /usr/local/bin/gcc-13 + CXX_NAME: /usr/local/bin/g++-13 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized GEN: - Xcode - Ninja Multi-Config + DEPS: + - system + - vcpkg + - fetch STD: - - C: 11 - CXX: 14 - - C: 17 - CXX: 17 + - C: 11 + CXX: 14 + - C: 17 + CXX: 17 exclude: - - COMPILER: - C_NAME: /usr/bin/gcc - CXX_NAME: /usr/bin/g++ - EXCLUSIVE_C_FLAGS: -Wno-conditional-uninitialized - GEN: Ninja Multi-Config - - COMPILER: - C_NAME: /usr/local/bin/gcc-11 - CXX_NAME: /usr/local/bin/g++-11 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - GEN: Xcode - - COMPILER: - C_NAME: /usr/local/bin/gcc-13 - CXX_NAME: /usr/local/bin/g++-13 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - GEN: Xcode + # These entries are excluded, since XCode selects its own compiler + - COMPILER: + C_NAME: /usr/local/bin/gcc-11 + CXX_NAME: /usr/local/bin/g++-11 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + GEN: Xcode + - COMPILER: + C_NAME: /usr/local/bin/gcc-13 + CXX_NAME: /usr/local/bin/g++-13 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + GEN: Xcode env: CC: ${{matrix.COMPILER.C_NAME}} - CCX: ${{matrix.COMPILER.CXX_NAME}} - # Not using -pedantic: error: ISO C forbids braced-groups within expressions - # The flags - # * -Wno-missing-field-initializers - # * matrix.COMPILER.EXCLUSIVE_C_FLAGS - # have been added because of Std compilation errors - CFLAGS: -Wall -Wextra -Werror -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }} - # The flags - # * -Wno-deprecated-declarations - # * -Wno-missing-field-initializers - # have been added because of Std compilation errors - CXXFLAGS: -Wall -Wextra -pedantic -Wno-format -Werror -Wno-missing-field-initializers -Wno-deprecated-declarations - + CXX: ${{matrix.COMPILER.CXX_NAME}} steps: - name: Checkout OpenCL-SDK uses: actions/checkout@v3 @@ -556,31 +668,42 @@ jobs: submodules: recursive - name: Create Build Environment - shell: bash run: | - cmake -E make_directory $GITHUB_WORKSPACE/build && - cmake -E make_directory $GITHUB_WORKSPACE/install && - if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && # Install Ninja only if it's the selected generator and it's not available. - cmake --version && - brew install tclap glm glew sfml mesa-glu + if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && + # We need to provide an OpenCL driver for Intel CPU on mac + brew install pocl + cmake --version - # We need to provide an OpenCL driver for Intel CPU on mac - - name: Install PoCL - shell: bash + - name: Install dependencies (Homebrew) + if: matrix.DEPS == 'system' + run: brew install tclap glm glew sfml mesa-glu + + - name: Install dependencies (vcpkg) + if: matrix.DEPS == 'vcpkg' + run: | + git clone https://github.com/Microsoft/vcpkg.git vcpkg + ./vcpkg/bootstrap-vcpkg.sh + ./vcpkg/vcpkg install tclap glm glew sfml stb + + - name: Set up compiler flags run: | - brew install pocl && - sudo ls /usr/local/etc/OpenCL/vendors + # Not using -pedantic: error: ISO C forbids braced-groups within expressions + # The flags + # * -Wno-missing-field-initializers + # * matrix.COMPILER.EXCLUSIVE_C_FLAGS + # have been added because of Std compilation errors + echo "CFLAGS=-Wall -Wextra -Werror -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }}" >> $GITHUB_ENV; + # The flags + # * -Wno-deprecated-declarations + # * -Wno-missing-field-initializers + # have been added because of Std compilation errors + echo "CXXFLAGS=-Wall -Wextra -pedantic -Wno-format -Werror -Wno-missing-field-initializers -Wno-deprecated-declarations" >> $GITHUB_ENV; - name: Configure - shell: bash - run: git clone https://github.com/Microsoft/vcpkg.git vcpkg && - ./vcpkg/bootstrap-vcpkg.sh && - ./vcpkg/vcpkg install stb && - TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake" && - cmake - $TOOLCHAIN_ARG + run: cmake -G "${{matrix.GEN}}" + `if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; then echo "-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; fi` -D BUILD_DOCS=ON -D BUILD_TESTING=ON -D BUILD_EXAMPLES=ON @@ -592,25 +715,21 @@ jobs: -B $GITHUB_WORKSPACE/build - name: Build - shell: bash run: | cmake --build $GITHUB_WORKSPACE/build --config Debug --parallel `sysctl -n hw.logicalcpu` cmake --build $GITHUB_WORKSPACE/build --config Release --parallel `sysctl -n hw.logicalcpu` - name: Test working-directory: ${{runner.workspace}}/OpenCL-SDK/build - shell: bash run: | - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` - - name: Test install - shell: bash + - name: Install run: | cmake --build $GITHUB_WORKSPACE/build --config Release --target install - name: Consume (install) - shell: bash run: cmake -G "${{matrix.GEN}}" -D CMAKE_C_STANDARD=${{matrix.STD.C}} @@ -618,13 +737,17 @@ jobs: -D CMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install" -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil -B $GITHUB_WORKSPACE/build_install && - cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` && - cmake --build $GITHUB_WORKSPACE/build_install --config Release --parallel `sysctl -n hw.logicalcpu` `if [[ "${{matrix.GEN}}" == "Xcode" ]]; then echo "-- -quiet"; fi;` && - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --parallel `sysctl -n hw.logicalcpu` && - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --parallel `sysctl -n hw.logicalcpu` + cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` && + cmake --build $GITHUB_WORKSPACE/build_install --config Release --parallel `sysctl -n hw.logicalcpu` && + cd $GITHUB_WORKSPACE/build_install && + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` && + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` python: name: Exercise Python examples on ${{matrix.os}} + defaults: + run: + shell: bash strategy: matrix: #os: [ubuntu-latest, macos-latest] @@ -662,6 +785,9 @@ jobs: checkruby: name: Check Ruby Samples ${{ matrix.os }} + defaults: + run: + shell: bash runs-on: ${{ matrix.os }} strategy: matrix: @@ -689,6 +815,9 @@ jobs: android: runs-on: ubuntu-latest needs: format + defaults: + run: + shell: bash strategy: matrix: ABI: @@ -711,7 +840,6 @@ jobs: submodules: recursive - name: Configure - shell: bash run: cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=${{matrix.CONFIG}} @@ -723,5 +851,4 @@ jobs: -B $GITHUB_WORKSPACE/build - name: Build - shell: bash run: cmake --build $GITHUB_WORKSPACE/build --parallel `nproc` diff --git a/CMakeLists.txt b/CMakeLists.txt index ec38ac21..99c785ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.16) set(CMAKE_CXX_STANDARD 14) diff --git a/lib/src/Extensions/CMakeLists.txt b/lib/src/Extensions/CMakeLists.txt index 38cd1628..e05d4e74 100644 --- a/lib/src/Extensions/CMakeLists.txt +++ b/lib/src/Extensions/CMakeLists.txt @@ -4,7 +4,7 @@ # Note: cmake 3.7 is needed to use OpenCL::OpenCL. # Older versions may work by explicitly specifying OpenCL_INCLUDE_DIRS and OpenCL_LIBRARIES. -cmake_minimum_required(VERSION 3.7 FATAL_ERROR) +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_CXX_STANDARD 11) diff --git a/samples/core/copybuffer/main.cpp b/samples/core/copybuffer/main.cpp index c8a9df52..9895d44c 100644 --- a/samples/core/copybuffer/main.cpp +++ b/samples/core/copybuffer/main.cpp @@ -100,7 +100,7 @@ int main(int argc, char** argv) if (!strcmp(argv[i], "-d")) { ++i; - if (i < static_cast(argc)) + if (i < argc) { deviceIndex = static_cast(strtoul(argv[i], NULL, 10)); @@ -109,7 +109,7 @@ int main(int argc, char** argv) else if (!strcmp(argv[i], "-p")) { ++i; - if (i < static_cast(argc)) + if (i < argc) { platformIndex = static_cast(strtoul(argv[i], NULL, 10)); diff --git a/samples/core/copybufferkernel/main.cpp b/samples/core/copybufferkernel/main.cpp index be436bd0..20e31dad 100644 --- a/samples/core/copybufferkernel/main.cpp +++ b/samples/core/copybufferkernel/main.cpp @@ -111,7 +111,7 @@ int main(int argc, char** argv) if (!strcmp(argv[i], "-d")) { ++i; - if (i < static_cast(argc)) + if (i < argc) { deviceIndex = static_cast(strtoul(argv[i], NULL, 10)); @@ -120,7 +120,7 @@ int main(int argc, char** argv) else if (!strcmp(argv[i], "-p")) { ++i; - if (i < static_cast(argc)) + if (i < argc) { platformIndex = static_cast(strtoul(argv[i], NULL, 10)); diff --git a/test/cmake/findmodule/CMakeLists.txt b/test/cmake/findmodule/CMakeLists.txt index 4fee1e80..6da08165 100644 --- a/test/cmake/findmodule/CMakeLists.txt +++ b/test/cmake/findmodule/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.16) project(FindModuleTest) diff --git a/test/cmake/pkgconfig/platformenum/CMakeLists.txt b/test/cmake/pkgconfig/platformenum/CMakeLists.txt index 926dccf3..84a6cb6b 100644 --- a/test/cmake/pkgconfig/platformenum/CMakeLists.txt +++ b/test/cmake/pkgconfig/platformenum/CMakeLists.txt @@ -1,7 +1,9 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.16) project(PkgConfigTest-PlatformEnum) +include(CTest) + find_package(OpenCL REQUIRED CONFIG diff --git a/test/cmake/pkgconfig/useutil/CMakeLists.txt b/test/cmake/pkgconfig/useutil/CMakeLists.txt index db0134b2..7310ae43 100644 --- a/test/cmake/pkgconfig/useutil/CMakeLists.txt +++ b/test/cmake/pkgconfig/useutil/CMakeLists.txt @@ -1,7 +1,9 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.16) project(PkgConfigTest-UseUtil) +include(CTest) + find_package(OpenCL REQUIRED CONFIG From 4eb99c1e33f64d824b56b9b9155f777a5ebe6a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:05 +0000 Subject: [PATCH 20/46] Updated release scripts --- .github/workflows/presubmit.yml | 15 ++- .github/workflows/release.yml | 156 ++++++++++++++++++++++++-------- cmake/DebSourcePkg.cmake | 110 ++++++++++++++++++++++ cmake/Package.cmake | 48 +--------- cmake/PackageSetup.cmake | 45 +++++++++ 5 files changed, 292 insertions(+), 82 deletions(-) create mode 100644 cmake/DebSourcePkg.cmake create mode 100644 cmake/PackageSetup.cmake diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 42a98c09..7fc537b2 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -447,8 +447,8 @@ jobs: - name: Checkout OpenCL-SDK uses: actions/checkout@v3 with: - fetch-depth: 0 - submodules: recursive + fetch-depth: 0 + submodules: recursive - name: Configure (MSBuild) if: matrix.GEN == 'Visual Studio 17 2022' @@ -657,6 +657,17 @@ jobs: CXX_NAME: /usr/local/bin/g++-13 EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized GEN: Xcode + # The gnu binaries are not compatible with the Homebrew installed binaries + - COMPILER: + C_NAME: /usr/local/bin/gcc-11 + CXX_NAME: /usr/local/bin/g++-11 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + DEPS: system + - COMPILER: + C_NAME: /usr/local/bin/gcc-13 + CXX_NAME: /usr/local/bin/g++-13 + EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized + DEPS: system env: CC: ${{matrix.COMPILER.C_NAME}} CXX: ${{matrix.COMPILER.CXX_NAME}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 52a22ba7..c43736d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,33 +7,28 @@ name: Create Release jobs: windows-binary: + if: false runs-on: windows-2022 + defaults: + run: + shell: pwsh strategy: matrix: VER: [v143] GEN: [Visual Studio 17 2022] BIN: [x64, x86] - + env: + UseMultiToolTask: true + EnforceProcessCountAcrossBuilds: true + MultiProcMaxCount: 3 steps: - name: Checkout OpenCL-SDK uses: actions/checkout@v3 - - - name: Initialize git submodules - shell: pwsh - run: | - & git submodule init - & git submodule update - - - name: Create Build Environment - shell: pwsh - run: | - # Parallelize MSBuild across projects - [Environment]::SetEnvironmentVariable('UseMultiToolTask', 'true', [EnvironmentVariableTarget]::User) - [Environment]::SetEnvironmentVariable('EnforceProcessCountAcrossBuilds', 'true', [EnvironmentVariableTarget]::User) - [Environment]::SetEnvironmentVariable('MultiProcMaxCount', "$env:NUMBER_OF_PROCESSORS", [EnvironmentVariableTarget]::User) + with: + fetch-depth: 0 + submodules: recursive - name: Configure - shell: pwsh run: | $Bin = if('${{matrix.BIN}}' -eq 'x86') {'Win32'} else {'x64'} & cmake ` @@ -42,15 +37,16 @@ jobs: -T ${{matrix.VER}} ` -S "${env:GITHUB_WORKSPACE}" ` -B "${env:GITHUB_WORKSPACE}\build" ` + -D CMAKE_INSTALL_PREFIX="${env:GITHUB_WORKSPACE}\install" ` -D BUILD_DOCS=OFF ` -D BUILD_TESTING=OFF ` -D BUILD_EXAMPLES=OFF ` -D OPENCL_SDK_BUILD_SAMPLES=OFF ` -D OPENCL_ICD_LOADER_BUILD_TESTING=OFF ` -D CMAKE_POLICY_DEFAULT_CMP0096=NEW + if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." } - name: Check version number - shell: pwsh run: | if ( -not (` Get-Content ${env:GITHUB_WORKSPACE}\build\CMakeCache.txt | ` @@ -59,7 +55,6 @@ jobs: { throw 'CMake project version mismatches Git tag name (without leading "v")'} - name: Build - shell: pwsh run: | foreach ($Config in "Debug","Release") { ` & cmake ` @@ -67,11 +62,11 @@ jobs: --config $Config ` -- ` /verbosity:minimal ` - /noLogo ` + /noLogo + if ($LASTEXITCODE -ne 0) { throw "Building OpenCL-SDK in $Config failed." } } - name: Package Binary - shell: pwsh run: | & cpack ` --config "${env:GITHUB_WORKSPACE}\build\CPackConfig.cmake" ` @@ -79,18 +74,22 @@ jobs: -C 'Debug;Release' ` -D CPACK_PACKAGE_FILE_NAME='OpenCL-SDK-${{github.ref_name}}-Win-${{matrix.BIN}}' ` -B "${env:GITHUB_WORKSPACE}\package" + if ($LASTEXITCODE -ne 0) { throw "Packaging OpenCL-SDK failed." } - name: Upload Package uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') with: draft: true files: | package/OpenCL-SDK-${{github.ref_name}}-Win-${{matrix.BIN}}.zip source: + if: false name: Source Release (${{ matrix.os }}) runs-on: ${{ matrix.os }} + defaults: + run: + shell: pwsh strategy: matrix: OS: [ubuntu-20.04, windows-2022] @@ -101,15 +100,11 @@ jobs: steps: - name: Checkout OpenCL-SDK uses: actions/checkout@v3 - - - name: Initialize git submodules - shell: pwsh - run: | - & git submodule init - & git submodule update + with: + fetch-depth: 0 + submodules: recursive - name: Configure - shell: pwsh run: | & cmake ` -S "${env:GITHUB_WORKSPACE}" ` @@ -119,11 +114,11 @@ jobs: -D BUILD_EXAMPLES=OFF ` -D OPENCL_SDK_BUILD_SAMPLES=OFF ` -D OPENCL_ICD_LOADER_BUILD_TESTING=OFF ` - -D CMAKE_POLICY_DEFAULT_CMP0096=NEW + -D CMAKE_POLICY_DEFAULT_CMP0096=NEW ` -D CPACK_PACKAGING_INSTALL_PREFIX=$DEB_INSTALLATION_PATH + if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." } - name: Check version number - shell: pwsh run: | if ( -not (` Get-Content ${env:GITHUB_WORKSPACE}/build/CMakeCache.txt | ` @@ -132,17 +127,16 @@ jobs: { throw 'CMake project version mismatches Git tag name (without leading "v")'} - name: Package DEB - shell: pwsh if: ${{ contains(matrix.OS, 'ubuntu') }} run: | - cpack + cpack ` --config "${env:GITHUB_WORKSPACE}/build/CPackSourceConfig.cmake" ` - -G DEB - -C Release + -G DEB ` + -C Release ` "${env:GITHUB_WORKSPACE}/package-deb" + if ($LASTEXITCODE -ne 0) { throw "Packaging OpenCL-SDK deb failed." } - name: Package Source - shell: pwsh run: | $Generator = if('${{matrix.OS}}' -match 'windows') {'ZIP'} else {'TGZ'} & cpack ` @@ -152,11 +146,101 @@ jobs: -D CPACK_SOURCE_IGNORE_FILES="/\\.git/;/\\.gitignore;/\\.gitmodules;/\\.gitlab/;/\\.github/;/\\.reuse/;/\\.appveyor.yml;/build/;/install/;/package/" ` -D CPACK_PACKAGE_FILE_NAME='OpenCL-SDK-${{github.ref_name}}-Source' ` -B "${env:GITHUB_WORKSPACE}/package" + if ($LASTEXITCODE -ne 0) { throw "Packaging OpenCL-SDK source failed." } - name: Release Source uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') with: draft: true files: | package/OpenCL-SDK-${{github.ref_name}}-Source.* + + ppa: + runs-on: ubuntu-latest + defaults: + run: + shell: bash + env: + OPENCL_HEADERS_REPOSITORY: mfep/OpenCL-Headers + OPENCL_ICD_LOADER_REPOSITORY: mfep/OpenCL-ICD-Loader + OPENCL_CLHPP_REPOSITORY: mfep/OpenCL-CLHPP + distroseries: jammy + steps: + - name: Add PPA + run: sudo add-apt-repository -y ppa:${{ vars.PPA }} + + - name: Install prerequisites + run: sudo apt-get update -qq && sudo apt-get install -y + cmake + devscripts + debhelper-compat=13 + opencl-c-headers + opencl-clhpp-headers + khronos-opencl-loader-libopencl1 + khronos-opencl-loader-opencl-dev + + - name: Import GPG signing key + run: echo "${{ secrets.DEB_SIGNING_KEY }}" | gpg --import + + - name: Download and extract source code (OpenCL-SDK) + run: | + wget -O $GITHUB_WORKSPACE/source.orig.tar.gz https://github.com/$GITHUB_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz + tar -xvf $GITHUB_WORKSPACE/source.orig.tar.gz -C $GITHUB_WORKSPACE + mv $GITHUB_WORKSPACE/OpenCL-SDK-* $GITHUB_WORKSPACE/OpenCL-SDK + + - name: Download and extract source code (OpenCL-Headers) + run: | + # ToDo remove + export GITHUB_REF_NAME=v2023.02.01 + wget -O $GITHUB_WORKSPACE/opencl-headers.tar.gz https://github.com/$OPENCL_HEADERS_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz + tar -xvf $GITHUB_WORKSPACE/opencl-headers.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external + rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-Headers + mv $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-Headers-* $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-Headers + + - name: Download and extract source code (OpenCL-ICD-Loader) + run: | + # ToDo remove + export GITHUB_REF_NAME=v2023.02.01 + wget -O $GITHUB_WORKSPACE/opencl-icd-loader.tar.gz https://github.com/$OPENCL_ICD_LOADER_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz + tar -xvf $GITHUB_WORKSPACE/opencl-icd-loader.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external + rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-ICD-Loader + mv $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-ICD-Loader-* $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-ICD-Loader + + - name: Download and extract source code (OpenCL-CLHPP) + run: | + # ToDo remove + export GITHUB_REF_NAME=v2023.02.01 + wget -O $GITHUB_WORKSPACE/opencl-clhpp.tar.gz https://github.com/$OPENCL_CLHPP_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz + tar -xvf $GITHUB_WORKSPACE/opencl-clhpp.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external + rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-CLHPP + mv $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-CLHPP-* $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-CLHPP + + - name: Configure project out-of-tree + run: cmake + -S $GITHUB_WORKSPACE/OpenCL-SDK* + -B $GITHUB_WORKSPACE/../build + -D CMAKE_BUILD_TYPE=Release + -D CMAKE_INSTALL_PREFIX=/usr + -D BUILD_TESTING=OFF + -D OPENCL_SDK_BUILD_SAMPLES=OFF + -D LATEST_RELEASE_VERSION=$GITHUB_REF_NAME + -D CPACK_DEBIAN_PACKAGE_MAINTAINER="${{ vars.DEB_MAINTAINER }}" + -D DEBIAN_VERSION_SUFFIX=${{ vars.DEB_VERSION_SUFFIX }} + + - name: Generate packaging scripts + run: cmake + -D CMAKE_CACHE_PATH=$GITHUB_WORKSPACE/../build/CMakeCache.txt + -D ORIG_ARCHIVE=$GITHUB_WORKSPACE/source.orig.tar.gz + -D LATEST_RELEASE_VERSION=$GITHUB_REF_NAME + -D DEBIAN_DISTROSERIES=${{ env.distroseries }} + -D DEBIAN_PACKAGE_MAINTAINER="${{ vars.DEB_MAINTAINER }}" + -D DEBIAN_VERSION_SUFFIX=${{ vars.DEB_VERSION_SUFFIX }} + -P $GITHUB_WORKSPACE/OpenCL-SDK*/cmake/DebSourcePkg.cmake + + - name: Build source package + run: | + cd $GITHUB_WORKSPACE/OpenCL-SDK*/ + debuild -S -sa + + - name: Push source package to the PPA + run: dput ppa:${{ vars.PPA }} $GITHUB_WORKSPACE/*source.changes diff --git a/cmake/DebSourcePkg.cmake b/cmake/DebSourcePkg.cmake new file mode 100644 index 00000000..c674e866 --- /dev/null +++ b/cmake/DebSourcePkg.cmake @@ -0,0 +1,110 @@ +# This script produces the changelog, control and rules file in the debian +# directory. These files are needed to build a Debian source package from the repository. +# Run this in CMake script mode, e.g. +# $ cd OpenCL-SDK +# $ cmake -S . -B ../build -D BUILD_TESTING=OFF +# $ cmake +# -DCMAKE_CACHE_PATH=../build/CMakeCache.txt +# -DCPACK_DEBIAN_PACKAGE_MAINTAINER="Example Name " +# -DDEBIAN_DISTROSERIES=jammy +# -DORIG_ARCHIVE=../OpenCL-SDK.tar.gz +# -DLATEST_RELEASE_VERSION=v2023.08.29 +# -P cmake/DebSourcePkg.cmake +# $ debuild -S -sa + +cmake_minimum_required(VERSION 3.21) # file(COPY_FILE) is added in CMake 3.21 + +set(DEB_SOURCE_PKG_NAME "khronos-opencl-sdk") + +if(NOT EXISTS "${CMAKE_CACHE_PATH}") + message(FATAL_ERROR "CMAKE_CACHE_PATH is not set or does not exist") +endif() +if(NOT DEFINED DEBIAN_PACKAGE_MAINTAINER) + message(FATAL_ERROR "DEBIAN_PACKAGE_MAINTAINER is not set") +endif() +if(NOT DEFINED DEBIAN_DISTROSERIES) + message(FATAL_ERROR "DEBIAN_DISTROSERIES is not set") +endif() +if(NOT DEFINED ORIG_ARCHIVE) + message(WARNING "ORIG_ARCHIVE is not set") +elseif(NOT EXISTS "${ORIG_ARCHIVE}") + message(FATAL_ERROR "ORIG_ARCHIVE is defined, but the file does not exist at \"${ORIG_ARCHIVE}\"") +endif() +if(NOT DEFINED LATEST_RELEASE_VERSION) + message(WARNING "LATEST_RELEASE_VERSION is not set") +endif() +if(NOT DEFINED DEBIAN_VERSION_SUFFIX) + message(WARNING "DEBIAN_VERSION_SUFFIX is not set") +endif() + +# Extracting the project version from the main CMakeLists.txt via regex +file(READ "${CMAKE_CACHE_PATH}" CMAKE_CACHE) +string(REGEX MATCH "CMAKE_PROJECT_VERSION[^=]*=([^\n]*)" REGEX_MATCH "${CMAKE_CACHE}") +if(NOT REGEX_MATCH) + message(FATAL_ERROR "Could not extract project version from CMakeLists.txt") +endif() +set(PROJECT_VERSION "${CMAKE_MATCH_1}") + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") +# Package.cmake contains all details for packaging +include(PackageSetup) + +# Append a space after every newline in the description. This format is required +# in the control file. +string(REPLACE "\n" "\n " CPACK_DEBIAN_DESCRIPTION "${CPACK_DEBIAN_DESCRIPTION}") + +set(DEB_SOURCE_PKG_DIR "${CMAKE_CURRENT_LIST_DIR}/../debian") +# Write debian/control +file(WRITE "${DEB_SOURCE_PKG_DIR}/control" +"Source: ${DEB_SOURCE_PKG_NAME} +Section: ${CPACK_DEBIAN_BINARY_PACKAGE_SECTION} +Priority: optional +Maintainer: ${DEBIAN_PACKAGE_MAINTAINER} +Build-Depends: cmake, debhelper-compat (=13), ${CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS} +Rules-Requires-Root: no +Homepage: ${CPACK_DEBIAN_PACKAGE_HOMEPAGE} +Standards-Version: 4.6.2 + +Package: ${CPACK_DEBIAN_BINARY_PACKAGE_NAME} +Architecture: any +Multi-Arch: same +Depends: ${CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS} +Description: ${CPACK_DEBIAN_DESCRIPTION} +" +) +# Write debian/changelog +string(TIMESTAMP CURRENT_TIMESTAMP "%a, %d %b %Y %H:%M:%S +0000" UTC) +file(WRITE "${DEB_SOURCE_PKG_DIR}/changelog" +"${DEB_SOURCE_PKG_NAME} (${PACKAGE_VERSION_REVISION}) ${DEBIAN_DISTROSERIES}; urgency=medium + + * Released version ${PACKAGE_VERSION_REVISION} + + -- ${DEBIAN_PACKAGE_MAINTAINER} ${CURRENT_TIMESTAMP} +") +# Write debian/rules +file(WRITE "${DEB_SOURCE_PKG_DIR}/rules" +"#!/usr/bin/make -f +%: +\tdh $@ + +override_dh_auto_configure: +\tdh_auto_configure -- -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DOPENCL_SDK_BUILD_SAMPLES=OFF + +override_dh_auto_install: + +override_dh_install: +\tcmake --install obj-* --component binary --prefix ./debian/${CPACK_DEBIAN_BINARY_PACKAGE_NAME}/usr +") + +if(DEFINED ORIG_ARCHIVE) + # Copy the passed orig.tar.gz file. The target filename is deduced from the version number, as expected by debuild + cmake_path(IS_ABSOLUTE ORIG_ARCHIVE IS_ORIG_ARCHIVE_ABSOLUTE) + if (NOT IS_ORIG_ARCHIVE_ABSOLUTE) + message(FATAL_ERROR "ORIG_ARCHIVE must be an absolute path (passed: \"${ORIG_ARCHIVE}\")") + endif() + cmake_path(GET ORIG_ARCHIVE EXTENSION ORIG_ARCHIVE_EXT) + cmake_path(GET ORIG_ARCHIVE PARENT_PATH ORIG_ARCHIVE_PARENT) + set(TARGET_PATH "${ORIG_ARCHIVE_PARENT}/${DEB_SOURCE_PKG_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}${ORIG_ARCHIVE_EXT}") + message(STATUS "Copying \"${ORIG_ARCHIVE}\" to \"${TARGET_PATH}\"") + file(COPY_FILE "${ORIG_ARCHIVE}" "${TARGET_PATH}") +endif() diff --git a/cmake/Package.cmake b/cmake/Package.cmake index c6df2b05..f94a653e 100644 --- a/cmake/Package.cmake +++ b/cmake/Package.cmake @@ -1,46 +1,6 @@ -set(CPACK_PACKAGE_VENDOR "khronos") - -set(CPACK_DEBIAN_DESCRIPTION "Khronos OpenCL Software Development Kit") - -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") - -set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") - -if(NOT CPACK_PACKAGING_INSTALL_PREFIX) - set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + include("${CMAKE_CURRENT_LIST_DIR}/PackageSetup.cmake") + set(CPACK_DEBIAN_PACKAGE_DEBUG ON) endif() -# DEB packaging configuration -set(CPACK_DEB_COMPONENT_INSTALL ON) -set(CPACK_COMPONENTS_ALL binary) - -set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_VENDOR}) - -set(CPACK_DEBIAN_PACKAGE_HOMEPAGE - "https://github.com/KhronosGroup/OpenCL-SDK") - -# Version number [epoch:]upstream_version[-debian_revision] -set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}") # upstream_version -set(CPACK_DEBIAN_PACKAGE_RELEASE "1") # debian_revision (because this is a - # non-native pkg) -set(PACKAGE_VERSION_REVISION "${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}") - -# Get architecture -execute_process(COMMAND dpkg "--print-architecture" OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE) -string(STRIP "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" CPACK_DEBIAN_PACKAGE_ARCHITECTURE) - -## Package runtime component -set(DEBIAN_PACKAGE_NAME "opencl-sdk") - -set(CPACK_DEBIAN_BINARY_PACKAGE_NAME - "${DEBIAN_PACKAGE_NAME}" - CACHE STRING "Package name" FORCE) - -# Package file name in deb format: -# _-_.deb -set(CPACK_DEBIAN_BINARY_FILE_NAME "${CPACK_PACKAGE_VENDOR}-${CPACK_DEBIAN_BINARY_PACKAGE_NAME}_${PACKAGE_VERSION_REVISION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") - -# Replacements -set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers (>= 3.0~2021.04.29), opencl-clhpp-headers (>= 3.0~2021.04.29), ocl-icd-opencl-dev (>= 3.0)") - -set(CPACK_DEBIAN_PACKAGE_DEBUG ON) +include(CPack) diff --git a/cmake/PackageSetup.cmake b/cmake/PackageSetup.cmake new file mode 100644 index 00000000..0c201d0b --- /dev/null +++ b/cmake/PackageSetup.cmake @@ -0,0 +1,45 @@ +set(CPACK_PACKAGE_VENDOR "khronos") + +set(CPACK_DEBIAN_DESCRIPTION "Khronos OpenCL Software Development Kit") + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") + +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") + +if(NOT CPACK_PACKAGING_INSTALL_PREFIX) + set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +endif() + +# DEB packaging configuration +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_COMPONENTS_ALL binary) + +set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_VENDOR}) + +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE + "https://github.com/KhronosGroup/OpenCL-SDK") + +# Version number [epoch:]upstream_version[-debian_revision] +set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}") # upstream_version +set(CPACK_DEBIAN_PACKAGE_RELEASE "1") # debian_revision (because this is a + # non-native pkg) +set(PACKAGE_VERSION_REVISION "${CPACK_DEBIAN_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}${DEBIAN_VERSION_SUFFIX}") + +# Get architecture +execute_process(COMMAND dpkg "--print-architecture" OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE) +string(STRIP "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" CPACK_DEBIAN_PACKAGE_ARCHITECTURE) + +## Package runtime component +set(DEBIAN_PACKAGE_NAME "opencl-sdk") + +set(CPACK_DEBIAN_BINARY_PACKAGE_NAME "${DEBIAN_PACKAGE_NAME}") + +# Package file name in deb format: +# _-_.deb +set(CPACK_DEBIAN_BINARY_FILE_NAME "${CPACK_DEBIAN_BINARY_PACKAGE_NAME}_${PACKAGE_VERSION_REVISION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") + +# Replacements +# ToDo +# set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers (>= 3.0~${PROJECT_VERSION}), opencl-clhpp-headers (>= 3.0~${PROJECT_VERSION}), khronos-opencl-loader-libopencl1 (>= 3.0~${PROJECT_VERSION}), khronos-opencl-loader-opencl-dev (>= 3.0~${PROJECT_VERSION})") +set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers, opencl-clhpp-headers, khronos-opencl-loader-libopencl1, khronos-opencl-loader-opencl-dev") +set(CPACK_DEBIAN_BINARY_PACKAGE_SECTION "libdevel") From a50c61c27f4ade1321fe9b55e771adc78006be64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:06 +0000 Subject: [PATCH 21/46] Building and packaging clinfo --- CMakeLists.txt | 2 + cmake/DebSourcePkg.cmake | 14 +++ cmake/Dependencies.cmake | 6 +- cmake/Dependencies/clinfo/CMakeLists.txt | 48 ++++++++++ cmake/Dependencies/clinfo/clinfo.cmake | 20 ++++ cmake/Dependencies/clinfo/ext.h | 115 +++++++++++++++++++++++ cmake/Dependencies/clinfo/patch.cmake | 11 +++ cmake/Package.cmake | 2 - cmake/PackageSetup.cmake | 24 ++++- 9 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 cmake/Dependencies/clinfo/CMakeLists.txt create mode 100644 cmake/Dependencies/clinfo/clinfo.cmake create mode 100644 cmake/Dependencies/clinfo/ext.h create mode 100644 cmake/Dependencies/clinfo/patch.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 99c785ba..66f73763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ cmake_dependent_option(OPENCL_SDK_BUILD_SAMPLES "Build sample code" ON OPENCL_SD cmake_dependent_option(OPENCL_SDK_BUILD_OPENGL_SAMPLES "Build OpenCL-OpenGL interop sample code" ON OPENCL_SDK_BUILD_SAMPLES OFF) cmake_dependent_option(OPENCL_SDK_TEST_SAMPLES "Add CTest to samples (where applicable)" ON OPENCL_SDK_BUILD_SAMPLES OFF) +option(OPENCL_SDK_BUILD_CLINFO "Build clinfo utility" ON) + include(CTest) if (NOT CMAKE_BUILD_TYPE) diff --git a/cmake/DebSourcePkg.cmake b/cmake/DebSourcePkg.cmake index c674e866..97d04b5d 100644 --- a/cmake/DebSourcePkg.cmake +++ b/cmake/DebSourcePkg.cmake @@ -46,12 +46,15 @@ endif() set(PROJECT_VERSION "${CMAKE_MATCH_1}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") +# Also get the package details for clinfo +set(OPENCL_SDK_BUILD_CLINFO ON) # Package.cmake contains all details for packaging include(PackageSetup) # Append a space after every newline in the description. This format is required # in the control file. string(REPLACE "\n" "\n " CPACK_DEBIAN_DESCRIPTION "${CPACK_DEBIAN_DESCRIPTION}") +string(REPLACE "\n" "\n " CPACK_DEBIAN_CLINFO_DESCRIPTION "${CPACK_DEBIAN_CLINFO_DESCRIPTION}") set(DEB_SOURCE_PKG_DIR "${CMAKE_CURRENT_LIST_DIR}/../debian") # Write debian/control @@ -70,6 +73,16 @@ Architecture: any Multi-Arch: same Depends: ${CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS} Description: ${CPACK_DEBIAN_DESCRIPTION} + +Package: ${CPACK_DEBIAN_CLINFO_PACKAGE_NAME} +Architecture: any +Multi-Arch: same +Depends: ${CPACK_DEBIAN_CLINFO_PACKAGE_DEPENDS} +Conflicts: ${CPACK_DEBIAN_CLINFO_PACKAGE_CONFLICTS} +Replaces: ${CPACK_DEBIAN_CLINFO_PACKAGE_REPLACES} +Provides: ${CPACK_DEBIAN_CLINFO_PACKAGE_PROVIDES} +Section: ${CPACK_DEBIAN_CLINFO_PACKAGE_SECTION} +Description: ${CPACK_DEBIAN_CLINFO_DESCRIPTION} " ) # Write debian/changelog @@ -94,6 +107,7 @@ override_dh_auto_install: override_dh_install: \tcmake --install obj-* --component binary --prefix ./debian/${CPACK_DEBIAN_BINARY_PACKAGE_NAME}/usr +\tcmake --install obj-* --component clinfo --prefix ./debian/${CPACK_DEBIAN_CLINFO_PACKAGE_NAME}/usr ") if(DEFINED ORIG_ARCHIVE) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 98b031a8..4fd0ab1a 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -47,6 +47,10 @@ if(OPENCL_SDK_BUILD_SAMPLES) endif(OPENCL_SDK_BUILD_OPENGL_SAMPLES) endif(OPENCL_SDK_BUILD_SAMPLES) +if(OPENCL_SDK_BUILD_CLINFO) + include("${CMAKE_CURRENT_LIST_DIR}/Dependencies/clinfo/clinfo.cmake") +endif() + # Restore user global state set(CMAKE_C_FLAGS ${USER_C_FLAGS}) set(CMAKE_CXX_FLAGS ${USER_CXX_FLAGS}) @@ -54,4 +58,4 @@ if(DEFINED USER_BUILD_SHARED_LIBS) set(BUILD_SHARED_LIBS ${USER_BUILD_SHARED_LIBS}) else() unset(BUILD_SHARED_LIBS CACHE ) -endif() \ No newline at end of file +endif() diff --git a/cmake/Dependencies/clinfo/CMakeLists.txt b/cmake/Dependencies/clinfo/CMakeLists.txt new file mode 100644 index 00000000..01783dd4 --- /dev/null +++ b/cmake/Dependencies/clinfo/CMakeLists.txt @@ -0,0 +1,48 @@ +include(GNUInstallDirs) + +add_executable(clinfo src/clinfo.c) +target_include_directories(clinfo PRIVATE src) +target_link_libraries(clinfo PRIVATE OpenCL::OpenCL) +target_compile_definitions(clinfo PRIVATE + CL_TARGET_OPENCL_VERSION=300 + CL_NO_NON_ICD_DISPATCH_EXTENSION_PROTOTYPES +) +add_test(NAME clinfo COMMAND $) + +# if (APPLE) +# set(RBASE "@loader_path") +# else () +# set(RBASE "$ORIGIN") +# endif () +# file(RELATIVE_PATH REL_LIB_DIR +# "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" +# "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}" +# ) +# set_target_properties(clinfo PROPERTIES INSTALL_RPATH "${RBASE}/${REL_LIB_DIR}") +install( + TARGETS clinfo + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + COMPONENT clinfo +) + +# Generating and installing the documentation +find_program(gzip_program gzip) +if (EXISTS "${gzip_program}") + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/clinfo.1.gz" + COMMAND gzip -c "${CMAKE_CURRENT_SOURCE_DIR}/man1/clinfo.1" > "${CMAKE_CURRENT_BINARY_DIR}/clinfo.1.gz" + MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/man1/clinfo.1" + ) + add_custom_target( + clinfo_manpage + ALL + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/clinfo.1.gz" + ) + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/clinfo.1.gz" + DESTINATION "${CMAKE_INSTALL_DATADIR}/man/man1" + COMPONENT clinfo + ) +else() + message(WARNING "Could not find gzip. Skipping the generation of documentation for clinfo") +endif() diff --git a/cmake/Dependencies/clinfo/clinfo.cmake b/cmake/Dependencies/clinfo/clinfo.cmake new file mode 100644 index 00000000..4ea210eb --- /dev/null +++ b/cmake/Dependencies/clinfo/clinfo.cmake @@ -0,0 +1,20 @@ +if(NOT DEPENDENCIES_FORCE_DOWNLOAD) + find_package(clinfo QUIET) +endif() + +if(NOT clinfo_FOUND) + if(DEPENDENCIES_FORCE_DOWNLOAD) + message(STATUS "DEPENDENCIES_FORCE_DOWNLOAD is ON. Fetching clinfo.") + else() + message(STATUS "Fetching clinfo.") + endif() + + include(FetchContent) + FetchContent_Declare( + clinfo + GIT_REPOSITORY https://github.com/Oblomov/clinfo.git + GIT_TAG 3.0.23.01.25 + PATCH_COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_LIST_DIR}/patch.cmake" + ) + FetchContent_MakeAvailable(clinfo) +endif() diff --git a/cmake/Dependencies/clinfo/ext.h b/cmake/Dependencies/clinfo/ext.h new file mode 100644 index 00000000..10337b23 --- /dev/null +++ b/cmake/Dependencies/clinfo/ext.h @@ -0,0 +1,115 @@ +/* Include OpenCL header, and define OpenCL extensions, since what is and is not + * available in the official headers is very system-dependent */ + +#ifndef EXT_H +#define EXT_H + +/* Khronos now provides unified headers for all OpenCL versions, and + * it should be included after defining a target OpenCL version + * (otherwise, the maximum version will simply be used, but a message + * will be printed). + * + * TODO: until 3.0 gets finalized, we only target 2.2 because the 3.0 + * defines etc are still changing, so users may have an older version + * of the 3.0 headers lying around, which may prevent clinfo from being + * compilable. + */ +#ifndef CL_TARGET_OPENCL_VERSION +#define CL_TARGET_OPENCL_VERSION 220 +#endif + +/* We will use the deprecated clGetExtensionFunctionAddress, + * so let the headers know that we don't care about it being deprecated. + * The standard CL_USE_DEPRECATED_OPENCL_1_1_APIS define apparently + * doesn't work for macOS, so we'll just tell the compiler to not + * warn about deprecated functions. + * A more correct solution would be to suppress the warning only around the + * clGetExtensionFunctionAddress call, but honestly I just cleaned up that + * piece of code. And I'm actually wondering if it even makes sense to + * build that part of the code on macOS: does anybody actually use + * ocl-icd as OpenCL dispatcher on macOS? + */ + +#ifdef __APPLE__ +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#include +#else +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#include +#include +#endif + +/* cl_amd_object_metadata */ +#define CL_PLATFORM_MAX_KEYS_AMD 0x403C + +/* cl_khr_terminate_context */ +#define CL_DEVICE_TERMINATE_CAPABILITY_KHR_1x 0x200F +#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x2031 + +/* cl_nv_device_attribute_query */ +#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 +#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 +#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 +#define CL_DEVICE_WARP_SIZE_NV 0x4003 +#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 +#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 +#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 +#define CL_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT_NV 0x4007 +#define CL_DEVICE_PCI_BUS_ID_NV 0x4008 +#define CL_DEVICE_PCI_SLOT_ID_NV 0x4009 +#define CL_DEVICE_PCI_DOMAIN_ID_NV 0x400A + +/* cl_ext_atomic_counters_{32,64} */ +#define CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT 0x4032 + +/* cl_amd_device_attribute_query */ +#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 +#define CL_DEVICE_TOPOLOGY_AMD 0x4037 +#define CL_DEVICE_BOARD_NAME_AMD 0x4038 +#define CL_DEVICE_GLOBAL_FREE_MEMORY_AMD 0x4039 +#define CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 0x4040 +#define CL_DEVICE_SIMD_WIDTH_AMD 0x4041 +#define CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD 0x4042 +#define CL_DEVICE_WAVEFRONT_WIDTH_AMD 0x4043 +#define CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD 0x4044 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD 0x4045 +#define CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD 0x4046 +#define CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD 0x4047 +#define CL_DEVICE_LOCAL_MEM_BANKS_AMD 0x4048 +#define CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD 0x4049 +#define CL_DEVICE_GFXIP_MAJOR_AMD 0x404A +#define CL_DEVICE_GFXIP_MINOR_AMD 0x404B +#define CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD 0x404C +/* These two are undocumented */ +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_QUEUES_AMD 0x404D +#define CL_DEVICE_MAX_REAL_TIME_COMPUTE_UNITS_AMD 0x404E +/* These were added in v4 of the extension, but have values lower than + * than the older ones, and spanning around the cl_ext_atomic_counters_* + * define + */ +#define CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD 0x4030 +#define CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD 0x4031 +#define CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD 0x4033 +#define CL_DEVICE_PCIE_ID_AMD 0x4034 + +#ifndef CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD +#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1 + +typedef union +{ + struct { cl_uint type; cl_uint data[5]; } raw; + struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char function; } pcie; +} cl_device_topology_amd; +#endif + +/* cl_amd_offline_devices */ +#define CL_CONTEXT_OFFLINE_DEVICES_AMD 0x403F + +/* cl_amd_copy_buffer_p2p */ +#define CL_DEVICE_NUM_P2P_DEVICES_AMD 0x4088 +#define CL_DEVICE_P2P_DEVICES_AMD 0x4089 + +/* cl_altera_device_temperature */ +#define CL_DEVICE_CORE_TEMPERATURE_ALTERA 0x40F3 + +#endif diff --git a/cmake/Dependencies/clinfo/patch.cmake b/cmake/Dependencies/clinfo/patch.cmake new file mode 100644 index 00000000..d1956167 --- /dev/null +++ b/cmake/Dependencies/clinfo/patch.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" "${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt" RESULT_VARIABLE RESULT_VAR) +if (NOT "${RESULT_VAR}" EQUAL "0") + message(FATAL_ERROR "Could not copy file with CMake") +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/ext.h" "${CMAKE_CURRENT_BINARY_DIR}/src/ext.h" RESULT_VARIABLE RESULT_VAR) +if (NOT "${RESULT_VAR}" EQUAL "0") + message(FATAL_ERROR "Could not copy file with CMake") +endif() diff --git a/cmake/Package.cmake b/cmake/Package.cmake index f94a653e..d2bb20c1 100644 --- a/cmake/Package.cmake +++ b/cmake/Package.cmake @@ -2,5 +2,3 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") include("${CMAKE_CURRENT_LIST_DIR}/PackageSetup.cmake") set(CPACK_DEBIAN_PACKAGE_DEBUG ON) endif() - -include(CPack) diff --git a/cmake/PackageSetup.cmake b/cmake/PackageSetup.cmake index 0c201d0b..eabb1a08 100644 --- a/cmake/PackageSetup.cmake +++ b/cmake/PackageSetup.cmake @@ -30,9 +30,9 @@ execute_process(COMMAND dpkg "--print-architecture" OUTPUT_VARIABLE CPACK_DEBIAN string(STRIP "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" CPACK_DEBIAN_PACKAGE_ARCHITECTURE) ## Package runtime component -set(DEBIAN_PACKAGE_NAME "opencl-sdk") +set(CPACK_DEBIAN_PACKAGE_NAME "opencl-sdk") -set(CPACK_DEBIAN_BINARY_PACKAGE_NAME "${DEBIAN_PACKAGE_NAME}") +set(CPACK_DEBIAN_BINARY_PACKAGE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}") # Package file name in deb format: # _-_.deb @@ -43,3 +43,23 @@ set(CPACK_DEBIAN_BINARY_FILE_NAME "${CPACK_DEBIAN_BINARY_PACKAGE_NAME}_${PACKAGE # set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers (>= 3.0~${PROJECT_VERSION}), opencl-clhpp-headers (>= 3.0~${PROJECT_VERSION}), khronos-opencl-loader-libopencl1 (>= 3.0~${PROJECT_VERSION}), khronos-opencl-loader-opencl-dev (>= 3.0~${PROJECT_VERSION})") set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers, opencl-clhpp-headers, khronos-opencl-loader-libopencl1, khronos-opencl-loader-opencl-dev") set(CPACK_DEBIAN_BINARY_PACKAGE_SECTION "libdevel") + +# Package clinfo, if enabled +if(OPENCL_SDK_BUILD_CLINFO) + list(APPEND CPACK_COMPONENTS_ALL "clinfo") + set(CPACK_DEBIAN_CLINFO_PACKAGE_NAME "clinfo") + set(CPACK_DEBIAN_CLINFO_FILE_NAME "clinfo_${PACKAGE_VERSION_REVISION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") + set(CPACK_DEBIAN_CLINFO_DESCRIPTION +"Query OpenCL system information +OpenCL (Open Computing Language) is a multivendor open standard for +general-purpose parallel programming of heterogeneous systems that include +CPUs, GPUs and other processors. +. +This package contains a tool that queries the capabilities of the available +OpenCL drivers.") + set(CPACK_DEBIAN_CLINFO_PACKAGE_DEPENDS "libc6 (>= 2.14), khronos-opencl-loader-libopencl1 (>= 3.0~${CPACK_DEBIAN_PACKAGE_VERSION}) | libopencl1") + set(CPACK_DEBIAN_CLINFO_PACKAGE_CONFLICTS "amd-clinfo, clinfo, fglrx-updates-core") + set(CPACK_DEBIAN_CLINFO_PACKAGE_REPLACES "amd-clinfo, clinfo, fglrx-updates-core") + set(CPACK_DEBIAN_CLINFO_PACKAGE_PROVIDES "clinfo") + set(CPACK_DEBIAN_CLINFO_PACKAGE_SECTION "admin") +endif() From a20b454b1541436539b83c78396651da7df519bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:07 +0000 Subject: [PATCH 22/46] Minor fixes and improvements --- .github/workflows/presubmit.yml | 197 ++++++++++------------- .github/workflows/release.yml | 9 +- CMakeLists.txt | 3 + cmake/DebSourcePkg.cmake | 16 +- cmake/Dependencies/clinfo/CMakeLists.txt | 10 -- cmake/PackageSetup.cmake | 2 +- docs/RELEASE.md | 23 +++ samples/CMakeLists.txt | 2 +- samples/core/blur/blur.cpp | 33 ++-- samples/core/blur/main.c | 7 +- 10 files changed, 141 insertions(+), 161 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 7fc537b2..a6691f0c 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -312,9 +312,11 @@ jobs: $CTEST_EXE -C Release --output-on-failure --no-tests=error --parallel `nproc`; fi + - name: Run clinfo (DEB) + run: clinfo + - name: Uninstall (DEB) - # ToDo: khronos-opencl-loader* - run: apt-get remove -y "ocl-icd*" opencl-c-headers opencl-clhpp-headers opencl-sdk + run: apt-get remove -y "khronos-opencl-loader*" opencl-c-headers opencl-clhpp-headers opencl-sdk clinfo - name: Test install run: $CMAKE_EXE @@ -623,16 +625,6 @@ jobs: shell: bash strategy: matrix: - COMPILER: - - C_NAME: /usr/bin/clang - CXX_NAME: /usr/bin/clang++ - EXCLUSIVE_C_FLAGS: -Wno-conditional-uninitialized - - C_NAME: /usr/local/bin/gcc-11 - CXX_NAME: /usr/local/bin/g++-11 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - - C_NAME: /usr/local/bin/gcc-13 - CXX_NAME: /usr/local/bin/g++-13 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized GEN: - Xcode - Ninja Multi-Config @@ -645,114 +637,91 @@ jobs: CXX: 14 - C: 17 CXX: 17 - exclude: - # These entries are excluded, since XCode selects its own compiler - - COMPILER: - C_NAME: /usr/local/bin/gcc-11 - CXX_NAME: /usr/local/bin/g++-11 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - GEN: Xcode - - COMPILER: - C_NAME: /usr/local/bin/gcc-13 - CXX_NAME: /usr/local/bin/g++-13 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - GEN: Xcode - # The gnu binaries are not compatible with the Homebrew installed binaries - - COMPILER: - C_NAME: /usr/local/bin/gcc-11 - CXX_NAME: /usr/local/bin/g++-11 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - DEPS: system - - COMPILER: - C_NAME: /usr/local/bin/gcc-13 - CXX_NAME: /usr/local/bin/g++-13 - EXCLUSIVE_C_FLAGS: -Wno-maybe-uninitialized - DEPS: system env: - CC: ${{matrix.COMPILER.C_NAME}} - CXX: ${{matrix.COMPILER.CXX_NAME}} + CC: /usr/bin/clang + CXX: /usr/bin/clang++ steps: - - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: recursive + - name: Checkout OpenCL-SDK + uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive - - name: Create Build Environment - run: | - # Install Ninja only if it's the selected generator and it's not available. - if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && - # We need to provide an OpenCL driver for Intel CPU on mac - brew install pocl - cmake --version - - - name: Install dependencies (Homebrew) - if: matrix.DEPS == 'system' - run: brew install tclap glm glew sfml mesa-glu - - - name: Install dependencies (vcpkg) - if: matrix.DEPS == 'vcpkg' - run: | - git clone https://github.com/Microsoft/vcpkg.git vcpkg - ./vcpkg/bootstrap-vcpkg.sh - ./vcpkg/vcpkg install tclap glm glew sfml stb + - name: Create Build Environment + run: | + # Install Ninja only if it's the selected generator and it's not available. + if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && + # We need to provide an OpenCL driver for Intel CPU on mac + brew install pocl + cmake --version - - name: Set up compiler flags - run: | - # Not using -pedantic: error: ISO C forbids braced-groups within expressions - # The flags - # * -Wno-missing-field-initializers - # * matrix.COMPILER.EXCLUSIVE_C_FLAGS - # have been added because of Std compilation errors - echo "CFLAGS=-Wall -Wextra -Werror -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }}" >> $GITHUB_ENV; - # The flags - # * -Wno-deprecated-declarations - # * -Wno-missing-field-initializers - # have been added because of Std compilation errors - echo "CXXFLAGS=-Wall -Wextra -pedantic -Wno-format -Werror -Wno-missing-field-initializers -Wno-deprecated-declarations" >> $GITHUB_ENV; - - - name: Configure - run: cmake - -G "${{matrix.GEN}}" - `if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; then echo "-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; fi` - -D BUILD_DOCS=ON - -D BUILD_TESTING=ON - -D BUILD_EXAMPLES=ON - -D OPENCL_SDK_BUILD_SAMPLES=ON - -D CMAKE_C_STANDARD=${{matrix.STD.C}} - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} - -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install - -S $GITHUB_WORKSPACE - -B $GITHUB_WORKSPACE/build - - - name: Build - run: | - cmake --build $GITHUB_WORKSPACE/build --config Debug --parallel `sysctl -n hw.logicalcpu` - cmake --build $GITHUB_WORKSPACE/build --config Release --parallel `sysctl -n hw.logicalcpu` + - name: Install dependencies (Homebrew) + if: matrix.DEPS == 'system' + run: brew install tclap glm glew sfml mesa-glu - - name: Test - working-directory: ${{runner.workspace}}/OpenCL-SDK/build - run: | - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` + - name: Install dependencies (vcpkg) + if: matrix.DEPS == 'vcpkg' + run: | + git clone https://github.com/Microsoft/vcpkg.git vcpkg + ./vcpkg/bootstrap-vcpkg.sh + ./vcpkg/vcpkg install tclap glm glew sfml stb - - name: Install - run: | - cmake --build $GITHUB_WORKSPACE/build --config Release --target install - - - name: Consume (install) - run: cmake - -G "${{matrix.GEN}}" - -D CMAKE_C_STANDARD=${{matrix.STD.C}} - -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} - -D CMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install" - -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil - -B $GITHUB_WORKSPACE/build_install && - cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` && - cmake --build $GITHUB_WORKSPACE/build_install --config Release --parallel `sysctl -n hw.logicalcpu` && - cd $GITHUB_WORKSPACE/build_install && - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` && - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` + - name: Set up compiler flags + run: | + # Not using -pedantic: error: ISO C forbids braced-groups within expressions + # The flags + # * -Wno-missing-field-initializers + # * -Wno-conditional-uninitialized + # have been added because of Std compilation errors + echo "CFLAGS=-Wall -Wextra -Werror -Wno-missing-field-initializers -Wno-conditional-uninitialized" >> $GITHUB_ENV; + # The flags + # * -Wno-deprecated-declarations + # * -Wno-missing-field-initializers + # have been added because of Std compilation errors + echo "CXXFLAGS=-Wall -Wextra -pedantic -Wno-format -Werror -Wno-missing-field-initializers -Wno-deprecated-declarations" >> $GITHUB_ENV; + + - name: Configure + run: cmake + -G "${{matrix.GEN}}" + `if [[ "${{matrix.DEPS}}" == "vcpkg" ]]; then echo "-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"; fi` + -D BUILD_DOCS=ON + -D BUILD_TESTING=ON + -D BUILD_EXAMPLES=ON + -D OPENCL_SDK_BUILD_SAMPLES=ON + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} + -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install + -S $GITHUB_WORKSPACE + -B $GITHUB_WORKSPACE/build + + - name: Build + run: | + cmake --build $GITHUB_WORKSPACE/build --config Debug --parallel `sysctl -n hw.logicalcpu` + cmake --build $GITHUB_WORKSPACE/build --config Release --parallel `sysctl -n hw.logicalcpu` + + - name: Test + working-directory: ${{runner.workspace}}/OpenCL-SDK/build + run: | + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` + + - name: Install + run: | + cmake --build $GITHUB_WORKSPACE/build --config Release --target install + + - name: Consume (install) + run: cmake + -G "${{matrix.GEN}}" + -D CMAKE_C_STANDARD=${{matrix.STD.C}} + -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} + -D CMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install" + -S $GITHUB_WORKSPACE/test/cmake/pkgconfig/useutil + -B $GITHUB_WORKSPACE/build_install && + cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` && + cmake --build $GITHUB_WORKSPACE/build_install --config Release --parallel `sysctl -n hw.logicalcpu` && + cd $GITHUB_WORKSPACE/build_install && + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` && + OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` python: name: Exercise Python examples on ${{matrix.os}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c43736d2..a3f1f2d4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,6 @@ name: Create Release jobs: windows-binary: - if: false runs-on: windows-2022 defaults: run: @@ -84,7 +83,6 @@ jobs: package/OpenCL-SDK-${{github.ref_name}}-Win-${{matrix.BIN}}.zip source: - if: false name: Source Release (${{ matrix.os }}) runs-on: ${{ matrix.os }} defaults: @@ -178,6 +176,7 @@ jobs: opencl-clhpp-headers khronos-opencl-loader-libopencl1 khronos-opencl-loader-opencl-dev + clinfo - name: Import GPG signing key run: echo "${{ secrets.DEB_SIGNING_KEY }}" | gpg --import @@ -191,7 +190,7 @@ jobs: - name: Download and extract source code (OpenCL-Headers) run: | # ToDo remove - export GITHUB_REF_NAME=v2023.02.01 + export GITHUB_REF_NAME=v2023.02.11 wget -O $GITHUB_WORKSPACE/opencl-headers.tar.gz https://github.com/$OPENCL_HEADERS_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz tar -xvf $GITHUB_WORKSPACE/opencl-headers.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-Headers @@ -200,7 +199,7 @@ jobs: - name: Download and extract source code (OpenCL-ICD-Loader) run: | # ToDo remove - export GITHUB_REF_NAME=v2023.02.01 + export GITHUB_REF_NAME=v2023.02.11 wget -O $GITHUB_WORKSPACE/opencl-icd-loader.tar.gz https://github.com/$OPENCL_ICD_LOADER_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz tar -xvf $GITHUB_WORKSPACE/opencl-icd-loader.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-ICD-Loader @@ -209,7 +208,7 @@ jobs: - name: Download and extract source code (OpenCL-CLHPP) run: | # ToDo remove - export GITHUB_REF_NAME=v2023.02.01 + export GITHUB_REF_NAME=v2023.02.11 wget -O $GITHUB_WORKSPACE/opencl-clhpp.tar.gz https://github.com/$OPENCL_CLHPP_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz tar -xvf $GITHUB_WORKSPACE/opencl-clhpp.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-CLHPP diff --git a/CMakeLists.txt b/CMakeLists.txt index 66f73763..686243d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,9 @@ cmake_dependent_option(OPENCL_SDK_BUILD_OPENGL_SAMPLES "Build OpenCL-OpenGL inte cmake_dependent_option(OPENCL_SDK_TEST_SAMPLES "Add CTest to samples (where applicable)" ON OPENCL_SDK_BUILD_SAMPLES OFF) option(OPENCL_SDK_BUILD_CLINFO "Build clinfo utility" ON) +if (("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")) + string(APPEND CMAKE_CXX_FLAGS " -stdlib=libstdc++") +endif() include(CTest) diff --git a/cmake/DebSourcePkg.cmake b/cmake/DebSourcePkg.cmake index 97d04b5d..405785bc 100644 --- a/cmake/DebSourcePkg.cmake +++ b/cmake/DebSourcePkg.cmake @@ -46,15 +46,12 @@ endif() set(PROJECT_VERSION "${CMAKE_MATCH_1}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") -# Also get the package details for clinfo -set(OPENCL_SDK_BUILD_CLINFO ON) # Package.cmake contains all details for packaging include(PackageSetup) # Append a space after every newline in the description. This format is required # in the control file. string(REPLACE "\n" "\n " CPACK_DEBIAN_DESCRIPTION "${CPACK_DEBIAN_DESCRIPTION}") -string(REPLACE "\n" "\n " CPACK_DEBIAN_CLINFO_DESCRIPTION "${CPACK_DEBIAN_CLINFO_DESCRIPTION}") set(DEB_SOURCE_PKG_DIR "${CMAKE_CURRENT_LIST_DIR}/../debian") # Write debian/control @@ -73,16 +70,6 @@ Architecture: any Multi-Arch: same Depends: ${CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS} Description: ${CPACK_DEBIAN_DESCRIPTION} - -Package: ${CPACK_DEBIAN_CLINFO_PACKAGE_NAME} -Architecture: any -Multi-Arch: same -Depends: ${CPACK_DEBIAN_CLINFO_PACKAGE_DEPENDS} -Conflicts: ${CPACK_DEBIAN_CLINFO_PACKAGE_CONFLICTS} -Replaces: ${CPACK_DEBIAN_CLINFO_PACKAGE_REPLACES} -Provides: ${CPACK_DEBIAN_CLINFO_PACKAGE_PROVIDES} -Section: ${CPACK_DEBIAN_CLINFO_PACKAGE_SECTION} -Description: ${CPACK_DEBIAN_CLINFO_DESCRIPTION} " ) # Write debian/changelog @@ -101,13 +88,12 @@ file(WRITE "${DEB_SOURCE_PKG_DIR}/rules" \tdh $@ override_dh_auto_configure: -\tdh_auto_configure -- -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DOPENCL_SDK_BUILD_SAMPLES=OFF +\tdh_auto_configure -- -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DOPENCL_SDK_BUILD_SAMPLES=OFF -DOPENCL_SDK_BUILD_CLINFO=OFF override_dh_auto_install: override_dh_install: \tcmake --install obj-* --component binary --prefix ./debian/${CPACK_DEBIAN_BINARY_PACKAGE_NAME}/usr -\tcmake --install obj-* --component clinfo --prefix ./debian/${CPACK_DEBIAN_CLINFO_PACKAGE_NAME}/usr ") if(DEFINED ORIG_ARCHIVE) diff --git a/cmake/Dependencies/clinfo/CMakeLists.txt b/cmake/Dependencies/clinfo/CMakeLists.txt index 01783dd4..bb3541e4 100644 --- a/cmake/Dependencies/clinfo/CMakeLists.txt +++ b/cmake/Dependencies/clinfo/CMakeLists.txt @@ -9,16 +9,6 @@ target_compile_definitions(clinfo PRIVATE ) add_test(NAME clinfo COMMAND $) -# if (APPLE) -# set(RBASE "@loader_path") -# else () -# set(RBASE "$ORIGIN") -# endif () -# file(RELATIVE_PATH REL_LIB_DIR -# "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" -# "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}" -# ) -# set_target_properties(clinfo PROPERTIES INSTALL_RPATH "${RBASE}/${REL_LIB_DIR}") install( TARGETS clinfo RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" diff --git a/cmake/PackageSetup.cmake b/cmake/PackageSetup.cmake index eabb1a08..90a5b47e 100644 --- a/cmake/PackageSetup.cmake +++ b/cmake/PackageSetup.cmake @@ -41,7 +41,7 @@ set(CPACK_DEBIAN_BINARY_FILE_NAME "${CPACK_DEBIAN_BINARY_PACKAGE_NAME}_${PACKAGE # Replacements # ToDo # set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers (>= 3.0~${PROJECT_VERSION}), opencl-clhpp-headers (>= 3.0~${PROJECT_VERSION}), khronos-opencl-loader-libopencl1 (>= 3.0~${PROJECT_VERSION}), khronos-opencl-loader-opencl-dev (>= 3.0~${PROJECT_VERSION})") -set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers, opencl-clhpp-headers, khronos-opencl-loader-libopencl1, khronos-opencl-loader-opencl-dev") +set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "opencl-c-headers, opencl-clhpp-headers, khronos-opencl-loader-libopencl1, khronos-opencl-loader-opencl-dev, clinfo") set(CPACK_DEBIAN_BINARY_PACKAGE_SECTION "libdevel") # Package clinfo, if enabled diff --git a/docs/RELEASE.md b/docs/RELEASE.md index aa76ec2d..92f7cfd1 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -44,6 +44,27 @@ git push origin vYYYY.MM.DD > > Note 2: Compatibility between packages is guaranteed manually. CI for each project fetches newest `main` and not using the same tag. Pushing tags in dep order is important to guarantee that when CI runs on pushing tags in these repos, tests are run using the correct versions of their deps. +### Uploading source packages to the Launchpad PPA + +As part of the release workflow for the sub-projects, a Debian source package is created and uploaded to the prescribed PPA. The details of the packaging must be set up in the GitHub projects of each sub-project separately. The following values must be set up prior to launching the release workflow: + +|Setting type |Setting name |Example value |Note | +|------------ |------------ |------------- |---- | +|Action variable|`DEB_MAINTAINER` |`Test User ` | | +|Action variable|`DEB_VERSION_SUFFIX`|`ppa0` | | +|Action variable|`PPA` |`KhronosGroup/OpenCL` |Has to be created on [launchpad.net](https://launchpad.net) beforehand| +|Action secret |`DEB_SIGNING_KEY` |`BEGIN PGP PRIVATE KEY BLOCK` ...|Output of `gpg --armor --export-secret-keys ` | + + +Be aware, that the automatic process of publishing of the binary Debian packages on the PPA can take hours. Moreover, since the projects depend on each other, the person creating the releases **must trigger the release workflow once the binary packages from the prerequisites are live**. The source package dependencies are the following: + +|Project |Dependencies| +|------- |------------| +|[OpenCL-Headers](https://github.com/KhronosGroup/OpenCL-Headers) |-| +|[OpenCL-ICD-Loader](https://github.com/KhronosGroup/OpenCL-ICD-Loader)|[OpenCL-Headers](https://github.com/KhronosGroup/OpenCL-Headers)| +|[OpenCL-CLHPP](https://github.com/KhronosGroup/OpenCL-CLHPP) |[OpenCL-Headers](https://github.com/KhronosGroup/OpenCL-Headers)| +|[OpenCL-SDK](https://github.com/KhronosGroup/OpenCL-SDK) |[OpenCL-Headers](https://github.com/KhronosGroup/OpenCL-Headers), [OpenCL-ICD-Loader](https://github.com/KhronosGroup/OpenCL-ICD-Loader), [OpenCL-CLHPP](https://github.com/KhronosGroup/OpenCL-CLHPP)| + ## Update submodule hashes Submodules may have moved to a different commit hash due to the previous step. The SDK wants to pick up all those changes (if it hasn't already been done). If `git status` shows, changes, push the changes. @@ -67,6 +88,8 @@ git commit -a -m "Update project version" ## Tag SDK +> As noted previously, wait with the tagging until the prerequisite Debian packages has been published. + ``` git tag vYYYY.MM.DD git push vYYYY.MM.DD diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index b9635d99..28bbe937 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -138,7 +138,7 @@ macro(add_sample) NAME "${OPENCL_SAMPLE_TARGET}_${CONFIG}" COMMAND ${OPENCL_SAMPLE_TARGET} CONFIGURATIONS ${CONFIG} - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + WORKING_DIRECTORY "$" ) endif() endforeach() diff --git a/samples/core/blur/blur.cpp b/samples/core/blur/blur.cpp index 3efa4427..be08c770 100644 --- a/samples/core/blur/blur.cpp +++ b/samples/core/blur/blur.cpp @@ -19,10 +19,14 @@ #include #include -// STL includes -#include +// standard includes #include +#include #include +#include +#include + +// C header includes #include // TCLAP includes @@ -40,7 +44,7 @@ template <> auto cl::sdk::parse() std::make_shared>( "i", "in", "Input image file", false, "", "name"), std::make_shared>( - "o", "out", "Output image file", false, "out.png", "name"), + "o", "out", "Output image file", false, "blurcpp_out.png", "name"), std::make_shared>("s", "size", "Size of blur kernel", false, (float)1.0, "positive float"), @@ -439,14 +443,18 @@ void BlurCppExample::read_input_image() /// If file not provided in command line, create a default one. if (blur_opts.in.empty()) { - std::string fname("andrew_svk_7oJ4D_ewB7c_unsplash.png"); + const int random_val = std::random_device{}(); + std::stringstream fname; + fname << "andrew_svk_7oJ4D_ewB7c_unsplash_" << std::hex << random_val + << ".png"; - std::cout << "No file given, use standard image " << fname << std::endl; + std::cout << "No file given, use standard image " << fname.str() + << std::endl; const char* fcont = (const char*)andrew_svk_7oJ4D_ewB7c_unsplash_png; const size_t fsize = andrew_svk_7oJ4D_ewB7c_unsplash_png_size; - std::fstream f(fname, std::ios::out | std::ios::binary); + std::fstream f(fname.str(), std::ios::out | std::ios::binary); if (!f.is_open()) { throw std::runtime_error{ std::string{ @@ -456,7 +464,7 @@ void BlurCppExample::read_input_image() f.write(fcont, fsize); f.close(); - blur_opts.in = fname; + blur_opts.in = fname.str(); } input_image = cl::sdk::read_image(blur_opts.in.c_str(), nullptr); @@ -472,9 +480,8 @@ void BlurCppExample::prepare_output_image() output_image.height = input_image.height; output_image.pixel_size = input_image.pixel_size; output_image.pixels.clear(); - output_image.pixels.reserve(sizeof(unsigned char) * output_image.width - * output_image.height - * output_image.pixel_size); + output_image.pixels.resize(output_image.width * output_image.height + * output_image.pixel_size); } std::tuple BlurCppExample::query_capabilities() @@ -704,10 +711,10 @@ cl::ImageFormat BlurCppExample::set_image_format() std::cout << "Converting picture into supported format... "; const size_t pixels = input_image.width * input_image.height; - const size_t new_size = sizeof(unsigned char) * pixels * 4; + const size_t new_size = pixels * 4; - input_image.pixels.reserve(new_size); - output_image.pixels.reserve(new_size); + input_image.pixels.resize(new_size); + output_image.pixels.resize(new_size); // change picture const size_t pixel_size = input_image.pixel_size; diff --git a/samples/core/blur/main.c b/samples/core/blur/main.c index 47ce6b1f..6e2c6707 100644 --- a/samples/core/blur/main.c +++ b/samples/core/blur/main.c @@ -923,6 +923,7 @@ cl_int dual_pass_subgroup_exchange_kernel_blur(state *const s, cl_int size, int main(int argc, char *argv[]) { + srand((unsigned int)time(NULL)); cl_int error = CL_SUCCESS, end_error = CL_SUCCESS; state s; cl_platform_id platform; @@ -934,7 +935,7 @@ int main(int argc, char *argv[]) .triplet = { 0, 0, CL_DEVICE_TYPE_ALL } }; struct options_Blur blur_opts = { - .size = 1, .op = "box", .in = NULL, .out = "out.png" + .size = 1, .op = "box", .in = NULL, .out = "blur_out.png" }; OCLERROR_RET(parse_options(argc, argv, &diag_opts, &dev_opts, &blur_opts), @@ -969,9 +970,11 @@ int main(int argc, char *argv[]) if (!diag_opts.quiet) cl_util_print_device_info(s.device); /// Read input image and prepare output image - const char fname[] = "andrew_svk_7oJ4D_ewB7c_unsplash.png"; + char fname[FILENAME_MAX]; + memset(fname, 0, FILENAME_MAX); if (!blur_opts.in) { + sprintf(fname, "andrew_svk_7oJ4D_ewB7c_unsplash_%x.png", rand()); printf("No file given, use standard image %s\n", fname); const unsigned char *fcont = andrew_svk_7oJ4D_ewB7c_unsplash_png; const size_t fsize = andrew_svk_7oJ4D_ewB7c_unsplash_png_size; From e1710438a04c7ab019b35faa714135befb8a9751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:07 +0000 Subject: [PATCH 23/46] Removed ToDos --- .github/workflows/release.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a3f1f2d4..c4d998a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -189,8 +189,6 @@ jobs: - name: Download and extract source code (OpenCL-Headers) run: | - # ToDo remove - export GITHUB_REF_NAME=v2023.02.11 wget -O $GITHUB_WORKSPACE/opencl-headers.tar.gz https://github.com/$OPENCL_HEADERS_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz tar -xvf $GITHUB_WORKSPACE/opencl-headers.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-Headers @@ -198,8 +196,6 @@ jobs: - name: Download and extract source code (OpenCL-ICD-Loader) run: | - # ToDo remove - export GITHUB_REF_NAME=v2023.02.11 wget -O $GITHUB_WORKSPACE/opencl-icd-loader.tar.gz https://github.com/$OPENCL_ICD_LOADER_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz tar -xvf $GITHUB_WORKSPACE/opencl-icd-loader.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-ICD-Loader @@ -207,8 +203,6 @@ jobs: - name: Download and extract source code (OpenCL-CLHPP) run: | - # ToDo remove - export GITHUB_REF_NAME=v2023.02.11 wget -O $GITHUB_WORKSPACE/opencl-clhpp.tar.gz https://github.com/$OPENCL_CLHPP_REPOSITORY/archive/refs/tags/$GITHUB_REF_NAME.tar.gz tar -xvf $GITHUB_WORKSPACE/opencl-clhpp.tar.gz -C $GITHUB_WORKSPACE/OpenCL-SDK/external rm -rf $GITHUB_WORKSPACE/OpenCL-SDK/external/OpenCL-CLHPP From caf368fdff00eedbd01cf30d6210cfb8e7e6bed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:08 +0000 Subject: [PATCH 24/46] Updated RELEASE.md --- docs/RELEASE.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/RELEASE.md b/docs/RELEASE.md index 92f7cfd1..228ba058 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -88,7 +88,13 @@ git commit -a -m "Update project version" ## Tag SDK -> As noted previously, wait with the tagging until the prerequisite Debian packages has been published. +The automatic release pipeline that is triggered on git tags, generates a Debian source package from the SDK code and uploads it to Launchpad. The packaging details and credentials have to be set as [described before](#uploading-source-packages-to-the-launchpad-ppa). + +While the SDK repository consumes the [OpenCL-Headers](https://github.com/KhronosGroup/OpenCL-Headers), [OpenCL-ICD-Loader](https://github.com/KhronosGroup/OpenCL-ICD-Loader) and [OpenCL-CLHPP](https://github.com/KhronosGroup/OpenCL-CLHPP) as git submodules, the same relation between the generated source packages is defined as a package dependency. Therefore, all 3 dependencies must be available in the Launchpad PPA to be able to build the SDK source package. The maintainer must make sure that the dependencies have already become available in the prescribed PPA before attempting to push a release tag for the OpenCL SDK. + +All Debian packages are version locked, which means that the **OpenCL SDK Debian package depends on exactly the same versions of the Headers, CLHPP and ICD-Loader as itself**. The source of this version information is the main `project` statement in the CMake scripts, therefore the maintainer has to make sure that all repositories have updated the version number, as [described above](#update-project-version). + +When all dependencies are published to the PPA, the SDK can be released by the following commands: ``` git tag vYYYY.MM.DD From 26b835d926f2b3589463afb4ff53ec6d7c39606d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:10 +0000 Subject: [PATCH 25/46] Removed _get_platform(cl_platform_id platform) from mako --- lib/src/Extensions/scripts/openclext.cpp.mako | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/src/Extensions/scripts/openclext.cpp.mako b/lib/src/Extensions/scripts/openclext.cpp.mako index af887c31..0cf5af02 100644 --- a/lib/src/Extensions/scripts/openclext.cpp.mako +++ b/lib/src/Extensions/scripts/openclext.cpp.mako @@ -181,11 +181,6 @@ def getCParameterStrings(params): #include -static inline cl_platform_id _get_platform(cl_platform_id platform) -{ - return platform; -} - static inline cl_platform_id _get_platform(cl_device_id device) { if (device == nullptr) return nullptr; From 6d318770dfed05ab8fe98808ba1ae788ca81a969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:11 +0000 Subject: [PATCH 26/46] Fixed resource release bug in binaries sample --- samples/core/binaries/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/core/binaries/main.c b/samples/core/binaries/main.c index 4e1ad36b..b01dcc14 100644 --- a/samples/core/binaries/main.c +++ b/samples/core/binaries/main.c @@ -159,7 +159,7 @@ int main(int argc, char *argv[]) cl_platform_id platform; cl_device_id device; cl_context context; - cl_command_queue queue = NULL; + cl_command_queue queue; cl_program program; @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) printf("Binary file written.\n\n"); prgs: - OCLERROR_RET(clReleaseProgram(program), end_error, que); + OCLERROR_RET(clReleaseProgram(program), end_error, cont); ker: free(kernel); From 9320dec88752c0d6baf04e945d4ccc0a1b7dd8d3 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:13 +0000 Subject: [PATCH 27/46] Remove null pointer checks --- lib/src/Utils/File.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/src/Utils/File.c b/lib/src/Utils/File.c index bd8d4af7..a806da4a 100644 --- a/lib/src/Utils/File.c +++ b/lib/src/Utils/File.c @@ -266,10 +266,7 @@ cl_int cl_util_write_binaries(const cl_program program, for (cl_uint i = 0; i < num_devices; ++i) free(binaries_ptr[i]); free(binaries_ptr); } - if(binaries_size != NULL) - { - free(binaries_size); - } + free(binaries_size); return error; } @@ -338,10 +335,7 @@ cl_program cl_util_read_binaries(const cl_context context, for (cl_uint i = 0; i < num_devices; ++i) free(binaries_ptr[i]); free(binaries_ptr); } - if(binaries_size != NULL) - { - free(binaries_size); - } + free(binaries_size); if (error != NULL) *error = err; return program; From 8d1c13ed57ec874f2a85161fadc6355b49fba68e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:14 +0000 Subject: [PATCH 28/46] Re-added whereami --- cmake/Dependencies.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 4fd0ab1a..e9777716 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1,3 +1,10 @@ +if(OPENCL_SDK_BUILD_UTILITY_LIBRARIES) + foreach(DEP IN ITEMS whereami) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/${DEP}") + include(${DEP}) + endforeach() +endif() + # Save global flags and strip diagnostics locally set(USER_C_FLAGS ${CMAKE_C_FLAGS}) set(USER_CXX_FLAGS ${CMAKE_CXX_FLAGS}) From 419c16f566a505f4a4c902046ba600b0735aa4b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:15 +0000 Subject: [PATCH 29/46] Using upstream main for OpenCL-Headers submodule --- .gitmodules | 2 +- external/OpenCL-Headers | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4c2bdc2d..08f7f035 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,7 +3,7 @@ url = https://github.com/StreamHPC/OpenCL-ICD-Loader.git [submodule "headers"] path = external/OpenCL-Headers - url = https://github.com/StreamHPC/OpenCL-Headers.git + url = https://github.com/KhronosGroup/OpenCL-Headers.git [submodule "headers-cpp"] path = external/OpenCL-CLHPP url = https://github.com/StreamHPC/OpenCL-CLHPP.git diff --git a/external/OpenCL-Headers b/external/OpenCL-Headers index 8275634c..c860bb55 160000 --- a/external/OpenCL-Headers +++ b/external/OpenCL-Headers @@ -1 +1 @@ -Subproject commit 8275634cf9ec31b6484c2e6be756237cb583999d +Subproject commit c860bb551eeef9a47d56286a70cea903db3d6ed2 From 492bfdbe5dbf46c715357c7ded209fb76871234f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:15 +0000 Subject: [PATCH 30/46] Bump deprecated actions --- .github/workflows/presubmit.yml | 20 ++++++++++---------- .github/workflows/release.yml | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index a6691f0c..b8cb12fe 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -10,7 +10,7 @@ jobs: run: shell: bash steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: # repository: ${{ github.repository }} (default) fetch-depth: 0 @@ -151,7 +151,7 @@ jobs: - name: Cache dependencies (vcpkg) if: matrix.DEPS == 'vcpkg' id: vcpkg-install - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: /opt/Microsoft/vcpkg key: vcpkg-linux-${{matrix.BIN}} @@ -179,7 +179,7 @@ jobs: echo "CXXFLAGS=-Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers" >> $GITHUB_ENV; - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive @@ -397,7 +397,7 @@ jobs: - name: Cache Ninja install if: matrix.GEN == 'Ninja Multi-Config' id: ninja-install - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | C:\Tools\Ninja @@ -431,7 +431,7 @@ jobs: - name: Cache dependencies (vcpkg) if: matrix.DEPS == 'vcpkg' id: vcpkg-install - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | C:\vcpkg @@ -447,7 +447,7 @@ jobs: echo "CXXFLAGS=/W4 /WX" >> $GITHUB_ENV - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive @@ -642,7 +642,7 @@ jobs: CXX: /usr/bin/clang++ steps: - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive @@ -734,7 +734,7 @@ jobs: os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Environment setup run: | MINIFORGE_INSTALL_DIR=.miniforge3 @@ -774,7 +774,7 @@ jobs: #os: [ubuntu-latest, macos-latest] os: [ubuntu-latest, macos-13] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive @@ -814,7 +814,7 @@ jobs: CXXFLAGS: -Wall -Wextra -pedantic -Werror -Wno-error=missing-field-initializers steps: - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c4d998a0..023e3778 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: MultiProcMaxCount: 3 steps: - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive @@ -97,7 +97,7 @@ jobs: steps: - name: Checkout OpenCL-SDK - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 submodules: recursive From a89ab83ea16d364df8b1f873b8103bfdc3e736c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:16 +0000 Subject: [PATCH 31/46] Removed MSVC++ v141 jobs --- .github/workflows/presubmit.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index b8cb12fe..c92d83dc 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -361,7 +361,7 @@ jobs: shell: pwsh strategy: matrix: - VER: [v141, v142, v143, clangcl] + VER: [v142, v143, clangcl] GEN: [Visual Studio 17 2022, Ninja Multi-Config] DEPS: [vcpkg, fetch] BIN: [x64] @@ -485,7 +485,6 @@ jobs: $TOOLCHAIN_ARG='' } $VER = switch ('${{matrix.VER}}') { ` - 'v141' {'14.1'} ` 'v142' {'14.2'} ` 'v143' {'14.3'} } Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" @@ -523,7 +522,6 @@ jobs: if: matrix.GEN == 'Ninja Multi-Config' run: | $VER = switch ('${{matrix.VER}}') { ` - 'v141' {'14.1'} ` 'v142' {'14.2'} ` 'v143' {'14.3'} } Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" @@ -582,7 +580,6 @@ jobs: if: matrix.GEN == 'Ninja Multi-Config' run: | $VER = switch ('${{matrix.VER}}') { ` - 'v141' {'14.1'} ` 'v142' {'14.2'} ` 'v143' {'14.3'} } Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" From 1ec6a1d7cadd701dbbcb0f6c32febef6041832bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:17 +0000 Subject: [PATCH 32/46] Whereami workaround --- test/cmake/pkgconfig/useutil/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/cmake/pkgconfig/useutil/CMakeLists.txt b/test/cmake/pkgconfig/useutil/CMakeLists.txt index 7310ae43..245621ae 100644 --- a/test/cmake/pkgconfig/useutil/CMakeLists.txt +++ b/test/cmake/pkgconfig/useutil/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.16) project(PkgConfigTest-UseUtil) include(CTest) +include("${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake/Dependencies/whereami/whereami.cmake") find_package(OpenCL REQUIRED @@ -27,6 +28,7 @@ target_link_libraries(${PROJECT_NAME}_cpp OpenCL::HeadersCpp OpenCL::Headers OpenCL::OpenCL + whereami ) target_compile_definitions(${PROJECT_NAME}_cpp @@ -51,6 +53,7 @@ target_link_libraries(${PROJECT_NAME}_c OpenCL::Utils OpenCL::Headers OpenCL::OpenCL + whereami ) target_compile_definitions(${PROJECT_NAME}_c From 0c9e6886f9f7ced7aabbc4b300f6b0d6a4c6aed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:18 +0000 Subject: [PATCH 33/46] fix(ci): Fetch a newer version of SFML, update patch --- cmake/Dependencies/SFML/CMakeLists.txt | 35 +++++++++----------------- cmake/Dependencies/SFML/SFML.cmake | 2 +- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/cmake/Dependencies/SFML/CMakeLists.txt b/cmake/Dependencies/SFML/CMakeLists.txt index 88440e50..bd8c9581 100644 --- a/cmake/Dependencies/SFML/CMakeLists.txt +++ b/cmake/Dependencies/SFML/CMakeLists.txt @@ -49,10 +49,6 @@ set(SRC ${SRCROOT}/Vertex.cpp ${INCROOT}/Vertex.hpp ) -if(NOT SFML_OPENGL_ES) - list(APPEND SRC ${SRCROOT}/GLLoader.cpp) - list(APPEND SRC ${SRCROOT}/GLLoader.hpp) -endif() source_group("" FILES ${SRC}) # drawables sources @@ -97,7 +93,10 @@ sfml_add_library(sfml-graphics target_link_libraries(sfml-graphics PUBLIC sfml-window) # stb_image sources -target_include_directories(sfml-graphics PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/stb_image") +target_include_directories(sfml-graphics SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/stb_image") + +# glad sources +target_include_directories(sfml-graphics SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/glad/include") # let CMake know about our additional graphics libraries paths if(SFML_OS_WINDOWS) @@ -112,26 +111,16 @@ elseif(SFML_OS_ANDROID) endif() # find external libraries -if(SFML_OPENGL_ES) - if(SFML_OS_LINUX) - sfml_find_package(EGL INCLUDE "EGL_INCLUDE_DIR" LINK "EGL_LIBRARY") - sfml_find_package(GLES INCLUDE "GLES_INCLUDE_DIR" LINK "GLES_LIBRARY") - target_link_libraries(sfml-graphics PRIVATE EGL GLES) - elseif(SFML_OS_IOS) - target_link_libraries(sfml-graphics PRIVATE "-framework OpenGLES") - endif() -else() - # Target OpenGL already defined for Window component so no sfml_find_package() here - target_link_libraries(sfml-graphics PRIVATE OpenGL) - - if(SFML_OS_LINUX) - # Target X11 already defined for Window component so no sfml_find_package() here - target_link_libraries(sfml-graphics PRIVATE X11) - endif() +if(SFML_OS_ANDROID) + target_link_libraries(sfml-graphics PRIVATE z) +elseif(SFML_OS_IOS) + target_link_libraries(sfml-graphics PRIVATE z bz2) endif() -if(SFML_OS_ANDROID) - target_link_libraries(sfml-graphics PRIVATE z EGL GLESv1_CM) +# starting from Visual Studio 2015, inline versions of some C functions are used; for compatibility link this library +# see https://docs.microsoft.com/en-us/cpp/porting/overview-of-potential-upgrade-issues-visual-cpp?view=msvc-160#libraries +if((SFML_COMPILER_MSVC AND SFML_MSVC_VERSION GREATER_EQUAL 14) OR (SFML_COMPILER_CLANG AND SFML_OS_WINDOWS AND NOT MINGW)) + target_link_libraries(sfml-graphics PRIVATE legacy_stdio_definitions.lib) endif() target_link_libraries(sfml-graphics diff --git a/cmake/Dependencies/SFML/SFML.cmake b/cmake/Dependencies/SFML/SFML.cmake index 0a32852b..22025ac5 100644 --- a/cmake/Dependencies/SFML/SFML.cmake +++ b/cmake/Dependencies/SFML/SFML.cmake @@ -24,7 +24,7 @@ if(NOT (SFML_FOUND OR TARGET SFML::Graphics)) FetchContent_Declare( sfml-external GIT_REPOSITORY https://github.com/SFML/SFML.git - GIT_TAG 2.5.1 # 2f11710abc5aa478503a7ff3f9e654bd2078ebab + GIT_TAG 2.6.1 # 69ea0cd863aed1d4092b970b676924a716ff718b PATCH_COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" "${CMAKE_CURRENT_BINARY_DIR}/_deps/sfml-external-src/src/SFML/Graphics/CMakeLists.txt" ) FetchContent_MakeAvailable(sfml-external) From 94b92f9a36bce97bc35c455af436b7c8a57225cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:18 +0000 Subject: [PATCH 34/46] fix(ci): Set up OSX architecture --- .github/workflows/presubmit.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index c92d83dc..49d89b7f 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -650,6 +650,7 @@ jobs: if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && # We need to provide an OpenCL driver for Intel CPU on mac brew install pocl + echo "OCL_ICD_VENDORS=/opt/homebrew/Cellar/pocl/5.0/etc/OpenCL/vendors" >> $GITHUB_ENV cmake --version - name: Install dependencies (Homebrew) @@ -688,6 +689,7 @@ jobs: -D CMAKE_C_STANDARD=${{matrix.STD.C}} -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} -D CMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install + -D CMAKE_OSX_ARCHITECTURES=arm64 -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build @@ -699,8 +701,9 @@ jobs: - name: Test working-directory: ${{runner.workspace}}/OpenCL-SDK/build run: | - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` + EXCLUDE_REGEX="multidevice.*" + ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX" + ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX" - name: Install run: | @@ -717,8 +720,8 @@ jobs: cmake --build $GITHUB_WORKSPACE/build_install --config Debug --parallel `sysctl -n hw.logicalcpu` && cmake --build $GITHUB_WORKSPACE/build_install --config Release --parallel `sysctl -n hw.logicalcpu` && cd $GITHUB_WORKSPACE/build_install && - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` && - OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` + ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` && + ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` python: name: Exercise Python examples on ${{matrix.os}} From 120a6e0b4762495cc051a2d573a367189447737d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:19 +0000 Subject: [PATCH 35/46] fix(binaries): Sample lang in binary name --- samples/core/binaries/main.c | 6 +++--- samples/core/binaries/main.cpp | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/samples/core/binaries/main.c b/samples/core/binaries/main.c index b01dcc14..c1a09abc 100644 --- a/samples/core/binaries/main.c +++ b/samples/core/binaries/main.c @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) if (!diag_opts.quiet) cl_util_print_device_info(device); /// Try to read binary - program = cl_util_read_binaries(context, &device, 1, "Collatz", &error); + program = cl_util_read_binaries(context, &device, 1, "Collatz-c", &error); if (error != CL_SUCCESS) { // if binary not present, compile and save @@ -207,7 +207,7 @@ int main(int argc, char *argv[]) OCLERROR_RET(cl_util_build_program(program, device, options), error, prgs); - OCLERROR_RET(cl_util_write_binaries(program, "Collatz"), error, prgs); + OCLERROR_RET(cl_util_write_binaries(program, "Collatz-c"), error, prgs); printf("Binary file written.\n\n"); prgs: @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) free(kernel); OCLERROR_PAR(program = cl_util_read_binaries(context, &device, 1, - "Collatz", &error), + "Collatz-c", &error), error, cont); } diff --git a/samples/core/binaries/main.cpp b/samples/core/binaries/main.cpp index b39cdaea..32776c7d 100644 --- a/samples/core/binaries/main.cpp +++ b/samples/core/binaries/main.cpp @@ -93,7 +93,8 @@ int main(int argc, char* argv[]) try { /// Try to read binary - binaries = cl::util::read_binary_files(devices, "Collatz", &error); + binaries = + cl::util::read_binary_files(devices, "Collatz-cpp", &error); } catch (cl::util::Error& e) { // if binary not present, compile and save @@ -106,7 +107,7 @@ int main(int argc, char* argv[]) program.build(devices.at(0)); binaries = program.getInfo(&error); - cl::util::write_binaries(binaries, devices, "Collatz"); + cl::util::write_binaries(binaries, devices, "Collatz-cpp"); } // if the binary is already present - calculate From 5d5f7a619666150977e122568be062bfd4fb7e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc=20Serf=C5=91z=C5=91?= Date: Sat, 6 Jul 2024 01:25:20 +0000 Subject: [PATCH 36/46] fix(ci): Fixed system deps in Linux builds --- .github/workflows/presubmit.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 49d89b7f..38cfc7d0 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -47,7 +47,7 @@ jobs: CXX_NAME: clang++ VER: 16 EXCLUSIVE_C_FLAGS: "" - DEPS: [os, vcpkg] + DEPS: [system, vcpkg, fetch] BIN: [64] STD: - C: 11 # Utils C library uses C11 functions (e.g. timespec_get) @@ -69,7 +69,9 @@ jobs: C_NAME: gcc CXX_NAME: g++ VER: 9 - EXCLUSIVE_C_FLAGS: "" + # A warning in libstb-dev + EXCLUSIVE_C_FLAGS: "-Wno-type-limits" + EXCLUSIVE_CXX_FLAGS: "-Wno-type-limits" DEPS: system BIN: 64 STD: @@ -84,7 +86,9 @@ jobs: C_NAME: gcc CXX_NAME: g++ VER: 9 - EXCLUSIVE_C_FLAGS: "" + # A warning in libstb-dev + EXCLUSIVE_C_FLAGS: "-Wno-type-limits" + EXCLUSIVE_CXX_FLAGS: "-Wno-type-limits" DEPS: system BIN: 64 STD: @@ -148,6 +152,10 @@ jobs: echo "CTEST_EXE=ctest" >> "$GITHUB_ENV" && echo "CPACK_EXE=cpack" >> "$GITHUB_ENV" + - name: Install dependencies (system) + if: matrix.DEPS == 'system' + run: apt-get update -qq && apt-get install -y libfreetype-dev libsfml-dev libglm-dev libglew-dev libtclap-dev libstb-dev + - name: Cache dependencies (vcpkg) if: matrix.DEPS == 'vcpkg' id: vcpkg-install @@ -176,7 +184,7 @@ jobs: # Not using -pedantic: error: ISO C forbids braced-groups within expressions echo "CFLAGS=-Wall -Wextra -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_C_FLAGS }}" >> $GITHUB_ENV; # Excluding missing-field-initializers error because it comes from the Std dependency - echo "CXXFLAGS=-Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers" >> $GITHUB_ENV; + echo "CXXFLAGS=-Wall -Wextra -pedantic -Werror -m${{matrix.BIN}} -Wno-missing-field-initializers ${{ matrix.COMPILER.EXCLUSIVE_CXX_FLAGS }}" >> $GITHUB_ENV; - name: Checkout OpenCL-SDK uses: actions/checkout@v4 From ce3b855eed19eac66564a330bdc9e26c26e7b767 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:21 +0000 Subject: [PATCH 37/46] Update docker images --- .github/workflows/presubmit.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 38cfc7d0..20ad3d62 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -62,7 +62,7 @@ jobs: - GEN: Ninja Multi-Config CONFIG: Release IMAGE: - - streamhpc/opencl-sdk-intelcpu:ubuntu-22.04-20230717 + - khronosgroup/docker-images:opencl-sdk-intelcpu-ubuntu-22.04.20230717 include: - CMAKE: system COMPILER: @@ -80,7 +80,7 @@ jobs: CONF: GEN: Unix Makefiles CONFIG: Debug - IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 + IMAGE: khronosgroup/docker-images:opencl-sdk-intelcpu-ubuntu-20.04.20230717 - CMAKE: system COMPILER: C_NAME: gcc @@ -97,7 +97,7 @@ jobs: CONF: GEN: Unix Makefiles CONFIG: Release - IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 + IMAGE: khronosgroup/docker-images:opencl-sdk-intelcpu-ubuntu-20.04.20230717 - CMAKE: system COMPILER: C_NAME: gcc @@ -112,7 +112,7 @@ jobs: CONF: GEN: Unix Makefiles CONFIG: Debug - IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 + IMAGE: khronosgroup/docker-images:opencl-sdk-intelcpu-ubuntu-20.04.20230717 - CMAKE: system COMPILER: C_NAME: gcc @@ -127,7 +127,7 @@ jobs: CONF: GEN: Unix Makefiles CONFIG: Release - IMAGE: streamhpc/opencl-sdk-intelcpu:ubuntu-20.04-20230717 + IMAGE: khronosgroup/docker-images:opencl-sdk-intelcpu-ubuntu-20.04.20230717 container: ${{matrix.IMAGE}} env: CMAKE_EXE: /opt/Kitware/CMake/${{ matrix.CMAKE }}/bin/cmake From 958ff0146b982110bb443d45676354a15b783dfc Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:21 +0000 Subject: [PATCH 38/46] Fix MSVC compiler toolset version --- .github/workflows/presubmit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 20ad3d62..95d5ed45 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -494,7 +494,7 @@ jobs: } $VER = switch ('${{matrix.VER}}') { ` 'v142' {'14.2'} ` - 'v143' {'14.3'} } + 'v143' {'14.4'} } Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" & cmake ` @@ -531,7 +531,7 @@ jobs: run: | $VER = switch ('${{matrix.VER}}') { ` 'v142' {'14.2'} ` - 'v143' {'14.3'} } + 'v143' {'14.4'} } Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=$VER" foreach ($Config in 'Release','Debug') { ` @@ -589,7 +589,7 @@ jobs: run: | $VER = switch ('${{matrix.VER}}') { ` 'v142' {'14.2'} ` - 'v143' {'14.3'} } + 'v143' {'14.4'} } Import-Module "${env:VS_ROOT}\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" Enter-VsDevShell -VsInstallPath ${env:VS_ROOT} -SkipAutomaticLocation -DevCmdArguments "-host_arch=x64 -arch=${{matrix.BIN}} -vcvars_ver=${VER}" & cmake ` From b9d0dca9805d97f9da8ae6c55da1d6f3e5528cae Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:22 +0000 Subject: [PATCH 39/46] Removed OpenCL 2.0 check and cl_khr_subgroups from blur sample --- samples/core/blur/blur.cpp | 39 +++++++++++++++++++++++++--------- samples/core/blur/blur.hpp | 6 ++---- samples/core/blur/main.c | 43 +++++++++++++++++++++++--------------- samples/core/blur/main.cpp | 32 +++++++++++++++------------- 4 files changed, 74 insertions(+), 46 deletions(-) diff --git a/samples/core/blur/blur.cpp b/samples/core/blur/blur.cpp index be08c770..e94bdbdf 100644 --- a/samples/core/blur/blur.cpp +++ b/samples/core/blur/blur.cpp @@ -25,6 +25,7 @@ #include #include #include +#include // C header includes #include @@ -484,7 +485,13 @@ void BlurCppExample::prepare_output_image() * output_image.pixel_size); } -std::tuple BlurCppExample::query_capabilities() +bool opencl_version_contains(const cl::string& dev_version, + const cl::string& version_fragment) +{ + return dev_version.find(version_fragment) != cl::string::npos; +} + +std::tuple BlurCppExample::query_capabilities() { // 1) query image support if (!device.getInfo()) @@ -501,21 +508,33 @@ std::tuple BlurCppExample::query_capabilities() (device.getInfo() == CL_LOCAL); // 4) query if device allow subgroup shuffle operations - bool use_subgroups = - cl::util::supports_extension(device, "cl_khr_subgroups"); bool use_subgroup_exchange = cl::util::supports_extension(device, "cl_khr_subgroup_shuffle"); bool use_subgroup_exchange_relative = cl::util::supports_extension( device, "cl_khr_subgroup_shuffle_relative"); - return std::make_tuple(use_local_mem, - use_subgroups && use_subgroup_exchange, - use_subgroups && use_subgroup_exchange_relative); -} + // 5) Query OpenCL version to compile for. + // If no -cl-std option is specified then the highest 1.x version + // supported by each device is used to compile the program. Therefore, + // it's only necessary to add the -cl-std option for 2.0 and 3.0 OpenCL + // versions. + const std::string dev_version = device.getInfo(); + cl::string compiler_options; + constexpr int max_major_version = 3; + for (auto i = 2; i <= max_major_version; ++i) + { + std::string version_str = std::to_string(i) + "."; // "i." + std::string compiler_opt_str = + "-cl-std=CL" + std::to_string(i) + ".0 "; // -cl-std=CLi.0 + + compiler_options += + cl::string{ opencl_version_contains(dev_version, version_str) + ? compiler_opt_str + : "" }; + } -bool BlurCppExample::query_opencl_c_2_0_support() -{ - return cl::util::opencl_c_version_contains(device, "2.0"); + return std::make_tuple(use_local_mem, use_subgroup_exchange, + use_subgroup_exchange_relative, compiler_options); } void BlurCppExample::create_image_buffers() diff --git a/samples/core/blur/blur.hpp b/samples/core/blur/blur.hpp index 6aa8b808..b6ff3d27 100644 --- a/samples/core/blur/blur.hpp +++ b/samples/core/blur/blur.hpp @@ -7,6 +7,7 @@ // STL includes #include +#include class BlurCppExample { public: @@ -39,10 +40,7 @@ class BlurCppExample { void prepare_output_image(); // Query device and runtime capabilities - std::tuple query_capabilities(); - - // Query device support for OpenCL 2.0 - bool query_opencl_c_2_0_support(); + std::tuple query_capabilities(); void create_image_buffers(); diff --git a/samples/core/blur/main.c b/samples/core/blur/main.c index 6e2c6707..fc4156e4 100644 --- a/samples/core/blur/main.c +++ b/samples/core/blur/main.c @@ -920,6 +920,12 @@ cl_int dual_pass_subgroup_exchange_kernel_blur(state *const s, cl_int size, return error; } +cl_int opencl_version_contains(const char *dev_version, + const char *version_fragment) +{ + char *found_version = strstr(dev_version, version_fragment); + return (found_version != NULL); +} int main(int argc, char *argv[]) { @@ -1051,16 +1057,23 @@ int main(int argc, char *argv[]) free(name); } - // 5) query if OpenCL driver version is 2.0 - bool opencl_c_version_2_0 = false; + // 5) Query OpenCL version to compile for. + // If no -cl-std option is specified then the highest 1.x version + // supported by each device is used to compile the program. Therefore, + // it's only necessary to add the -cl-std option for 2.0 and 3.0 OpenCL + // versions. + char dev_version[64]; + OCLERROR_RET(clGetDeviceInfo(s.device, CL_DEVICE_VERSION, + sizeof(dev_version), &dev_version, NULL), + error, end); + char compiler_options[1024] = ""; + if (opencl_version_contains(dev_version, "3.")) + { + strcat(compiler_options, "-cl-std=CL3.0 "); + } + else if (opencl_version_contains(dev_version, "2.")) { - char *driver_version = NULL; - OCLERROR_PAR( - driver_version = cl_util_get_device_info(s.device, CL_DRIVER_VERSION, &error), - error, clean); - opencl_c_version_2_0 = strcmp("2.0", driver_version) ? 0 : 1; - clean: - free(driver_version); + strcat(compiler_options, "-cl-std=CL2.0 "); } /// Create image buffers @@ -1128,23 +1141,21 @@ int main(int argc, char *argv[]) error, prg); /// Subgroup exchange in dual-pass blur - if (use_subgroup_exchange_relative && opencl_c_version_2_0) + if (use_subgroup_exchange_relative) { printf("Dual-pass subgroup relative exchange blur\n"); kernel_op[0] = '\0'; - strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); OCLERROR_RET(dual_pass_subgroup_exchange_box_blur( &s, (cl_int)blur_opts.size), error, prg); } - if (use_subgroup_exchange && opencl_c_version_2_0) + if (use_subgroup_exchange) { printf("Dual-pass subgroup exchange blur\n"); kernel_op[0] = '\0'; - strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); OCLERROR_RET(dual_pass_subgroup_exchange_box_blur( @@ -1183,24 +1194,22 @@ int main(int argc, char *argv[]) } /// Subgroup exchange in dual-pass Gaussian blur - if (use_subgroup_exchange_relative && opencl_c_version_2_0) + if (use_subgroup_exchange_relative) { printf("Dual-pass subgroup relative exchange Gaussian blur\n"); kernel_op[0] = '\0'; - strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size, gauss_kern), error, gkrn); } - if (use_subgroup_exchange && opencl_c_version_2_0) + if (use_subgroup_exchange) { printf("Dual-pass subgroup exchange Gaussian blur\n"); kernel_op[0] = '\0'; - strcat(kernel_op, " -cl-std=CL2.0 "); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size, diff --git a/samples/core/blur/main.cpp b/samples/core/blur/main.cpp index a33a16e0..2ded6008 100644 --- a/samples/core/blur/main.cpp +++ b/samples/core/blur/main.cpp @@ -46,10 +46,10 @@ int main(int argc, char* argv[]) // Query device and runtime capabilities bool use_local_mem, use_subgroup_exchange, use_subgroup_exchange_relative; + std::string compiler_options; std::tie(use_local_mem, use_subgroup_exchange, - use_subgroup_exchange_relative) = blur.query_capabilities(); - - bool opencl_c_version_2_0 = blur.query_opencl_c_2_0_support(); + use_subgroup_exchange_relative, compiler_options) = + blur.query_capabilities(); // Create image buffers used for operation. In this example input, // output and temporary image buffers are used. Temporary buffer is used @@ -61,7 +61,7 @@ int main(int argc, char* argv[]) // Create kernel and build program for selected device and blur.cl file // without any options. If this function fails, ensure that the blur.cl // file is available in place of execution. - blur.build_program(""); + blur.build_program(compiler_options); // The box blur operation will be performed if you pass "-b box" or // don't select any option. @@ -87,27 +87,28 @@ int main(int argc, char* argv[]) // file you can find 'USE_SUBGROUP_EXCHANGE_RELATIVE' C-like // definition switch for blur_box_horizontal_subgroup_exchange // function. In this case, 2 blur kernel functors are used. - if (use_subgroup_exchange_relative && opencl_c_version_2_0) + if (use_subgroup_exchange_relative) { std::cout << "Dual-pass subgroup relative exchange blur" << std::endl; - blur.build_program( - "-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 "); + blur.build_program(compiler_options + + "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); blur.dual_pass_subgroup_exchange_box_blur(); } // Same as the previous one, but with a different build switch. See // the blur.cl file for more info about the switch. - if (use_subgroup_exchange && opencl_c_version_2_0) + if (use_subgroup_exchange) { std::cout << "Dual-pass subgroup exchange blur" << std::endl; - blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 "); + blur.build_program(compiler_options + + "-D USE_SUBGROUP_EXCHANGE "); blur.dual_pass_subgroup_exchange_box_blur(); } } // Box blur // Build default program with no kernel arguments. - blur.build_program(""); + blur.build_program(compiler_options); // The gauss blur operation is performed when the "-b gauss" option or // no option is passed. The following examples use a manually created @@ -133,23 +134,24 @@ int main(int argc, char* argv[]) // Similar to dual_pass_subgroup_exchange_box_blur but with a gauss // kernel. - if (use_subgroup_exchange_relative && opencl_c_version_2_0) + if (use_subgroup_exchange_relative) { std::cout << "Dual-pass subgroup relative exchange Gaussian blur" << std::endl; - blur.build_program( - "-D USE_SUBGROUP_EXCHANGE_RELATIVE -cl-std=CL2.0 "); + blur.build_program(compiler_options + + "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); blur.dual_pass_subgroup_exchange_kernel_blur(); } // Same as the previous one, but with a different build switch. See // the blur.cl file for more info about the switch. - if (use_subgroup_exchange && opencl_c_version_2_0) + if (use_subgroup_exchange) { std::cout << "Dual-pass subgroup exchange Gaussian blur" << std::endl; - blur.build_program("-D USE_SUBGROUP_EXCHANGE -cl-std=CL2.0 "); + blur.build_program(compiler_options + + "-D USE_SUBGROUP_EXCHANGE "); blur.dual_pass_subgroup_exchange_kernel_blur(); } } // Gaussian blur From 5ed64c402ba6909ae8a9196cad76ab07d83d47f4 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:23 +0000 Subject: [PATCH 40/46] Fixed compiler options being reset --- samples/core/blur/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/core/blur/main.c b/samples/core/blur/main.c index fc4156e4..c6fe07b8 100644 --- a/samples/core/blur/main.c +++ b/samples/core/blur/main.c @@ -1146,6 +1146,7 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup relative exchange blur\n"); kernel_op[0] = '\0'; + strcat(kernel_op, compiler_options); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); OCLERROR_RET(dual_pass_subgroup_exchange_box_blur( &s, (cl_int)blur_opts.size), @@ -1156,6 +1157,7 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup exchange blur\n"); kernel_op[0] = '\0'; + strcat(kernel_op, compiler_options); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); OCLERROR_RET(dual_pass_subgroup_exchange_box_blur( @@ -1199,6 +1201,7 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup relative exchange Gaussian blur\n"); kernel_op[0] = '\0'; + strcat(kernel_op, compiler_options); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE_RELATIVE "); OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size, @@ -1210,6 +1213,7 @@ int main(int argc, char *argv[]) printf("Dual-pass subgroup exchange Gaussian blur\n"); kernel_op[0] = '\0'; + strcat(kernel_op, compiler_options); strcat(kernel_op, "-D USE_SUBGROUP_EXCHANGE "); OCLERROR_RET(dual_pass_subgroup_exchange_kernel_blur(&s, gauss_size, From 807a04a548fdfc88dbfe27a63ee42f821155cb9d Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Sat, 6 Jul 2024 01:25:23 +0000 Subject: [PATCH 41/46] Bumped version of pocl --- .github/workflows/presubmit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 95d5ed45..40b29ebc 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -658,7 +658,7 @@ jobs: if [[ "${{matrix.GEN}}" == "Ninja Multi-Config" && ! `which ninja` ]]; then brew install ninja; fi && # We need to provide an OpenCL driver for Intel CPU on mac brew install pocl - echo "OCL_ICD_VENDORS=/opt/homebrew/Cellar/pocl/5.0/etc/OpenCL/vendors" >> $GITHUB_ENV + echo "OCL_ICD_VENDORS=/opt/homebrew/Cellar/pocl/6.0/etc/OpenCL/vendors" >> $GITHUB_ENV cmake --version - name: Install dependencies (Homebrew) From e5221a1e8a75b30fa9dee7f8e60d2be3420fb7b2 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Fri, 29 Sep 2023 10:19:00 +0000 Subject: [PATCH 42/46] External memory C/C++ example --- .github/workflows/presubmit.yml | 39 +- cmake/Dependencies.cmake | 2 +- cmake/Dependencies/Vulkan/Vulkan.cmake | 1 + samples/CMakeLists.txt | 4 +- samples/extensions/khr/CMakeLists.txt | 1 + .../khr/externalmemory/CMakeLists.txt | 31 + .../extensions/khr/externalmemory/README.md | 257 +++++++ .../khr/externalmemory/external_saxpy.cl | 8 + samples/extensions/khr/externalmemory/main.c | 654 ++++++++++++++++++ .../extensions/khr/externalmemory/main.cpp | 559 +++++++++++++++ .../khr/externalmemory/vulkan_utils.h | 382 ++++++++++ .../khr/externalmemory/vulkan_utils.hpp | 268 +++++++ 12 files changed, 2202 insertions(+), 4 deletions(-) create mode 100644 cmake/Dependencies/Vulkan/Vulkan.cmake create mode 100644 samples/extensions/khr/externalmemory/CMakeLists.txt create mode 100644 samples/extensions/khr/externalmemory/README.md create mode 100644 samples/extensions/khr/externalmemory/external_saxpy.cl create mode 100644 samples/extensions/khr/externalmemory/main.c create mode 100644 samples/extensions/khr/externalmemory/main.cpp create mode 100644 samples/extensions/khr/externalmemory/vulkan_utils.h create mode 100644 samples/extensions/khr/externalmemory/vulkan_utils.hpp diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 40b29ebc..b8ce2db2 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -192,6 +192,17 @@ jobs: fetch-depth: 0 submodules: recursive + - name: Install samples dependencies + run: | + if [[ "${{ matrix.BIN }}" == "64" ]]; then + apt-get update -qq; + apt-get install -y libvulkan-dev; + else + dpkg --add-architecture i386; + apt-get update -qq; + apt-get install -y libvulkan-dev:i386; + fi + - name: Configure, package & install OpenCL-Headers run: $CMAKE_EXE -G "${{matrix.CONF.GEN}}" @@ -400,6 +411,8 @@ jobs: INTEL_OCL_URL: https://github.com/intel/llvm/releases/download/2023-WW27/win-oclcpuexp-2023.16.6.0.28_rel.zip INTEL_TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.10.0/oneapi-tbb-2021.10.0-win.zip IMAGE_INTEL_PREFIX: C:\Tools\Intel + VULKAN_SDK_URL: https://sdk.lunarg.com/sdk/download/1.3.261.1/windows/VulkanSDK-1.3.261.1-Installer.exe + VULKAN_SDK: C:/VulkanSDK/1.3.261.1 steps: - name: Cache Ninja install @@ -436,6 +449,18 @@ jobs: New-Item -Type File HKLM:\SOFTWARE\Khronos\OpenCL\Vendors | Out-Null; ` Set-ItemProperty -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors -Name ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\intelocl64.dll -Type DWord -Value 0; + - name: Install samples dependencies + run: | + Invoke-WebRequest ${env:VULKAN_SDK_URL} -OutFile vulkan-sdk-installer.exe + .\vulkan-sdk-installer.exe --accept-licenses --default-answer --confirm-command install com.lunarg.vulkan.32bit + Remove-Item vulkan-sdk-installer.exe + if ('${{ matrix.BIN }}' -eq 'x64') + { + echo "Vulkan_LIB_DIR=$env:VULKAN_SDK/Lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } else { + echo "Vulkan_LIB_DIR=$env:VULKAN_SDK/Lib32" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + - name: Cache dependencies (vcpkg) if: matrix.DEPS == 'vcpkg' id: vcpkg-install @@ -480,6 +505,8 @@ jobs: -D CMAKE_C_STANDARD=${{matrix.STD.C}} ` -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` + -D Vulkan_INCLUDE_DIR=${env:VULKAN_SDK}/Include ` + -D Vulkan_LIBRARY=${env:Vulkan_LIB_DIR}/vulkan-1.lib ` -S ${env:GITHUB_WORKSPACE} ` -B ${env:GITHUB_WORKSPACE}\build if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." } @@ -508,6 +535,8 @@ jobs: -D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} ` -D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL ` -D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install ` + -D Vulkan_INCLUDE_DIR=${env:VULKAN_SDK}/Include ` + -D Vulkan_LIBRARY=${env:Vulkan_LIB_DIR}/vulkan-1.lib ` -S ${env:GITHUB_WORKSPACE} ` -B ${env:GITHUB_WORKSPACE}\build if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." } @@ -545,12 +574,14 @@ jobs: if: matrix.BIN != 'x86' working-directory: ${{runner.workspace}}/OpenCL-SDK/build run: | + $EXCLUDE_REGEX = 'externalmemory.*' foreach ($Config in 'Release','Debug') { & ctest ` --build-config ${Config} ` --output-on-failure ` --no-tests=error ` - --parallel ${env:NUMBER_OF_PROCESSORS} + --parallel ${env:NUMBER_OF_PROCESSORS} ` + --exclude-regex "$EXCLUDE_REGEX" if ($LASTEXITCODE -ne 0) { throw "Running OpenCL-SDK tests in $Config failed." } } @@ -661,6 +692,10 @@ jobs: echo "OCL_ICD_VENDORS=/opt/homebrew/Cellar/pocl/6.0/etc/OpenCL/vendors" >> $GITHUB_ENV cmake --version + - name: Install samples dependencies + run: | + brew install vulkan-loader + - name: Install dependencies (Homebrew) if: matrix.DEPS == 'system' run: brew install tclap glm glew sfml mesa-glu @@ -709,7 +744,7 @@ jobs: - name: Test working-directory: ${{runner.workspace}}/OpenCL-SDK/build run: | - EXCLUDE_REGEX="multidevice.*" + EXCLUDE_REGEX="(multidevice|externalmemory).*" ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX" ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX" diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index e9777716..24383896 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -41,7 +41,7 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Global flag to cause add_library() to crea # Fetch dependencies if(OPENCL_SDK_BUILD_SAMPLES) - foreach(DEP IN ITEMS cargs TCLAP Stb) + foreach(DEP IN ITEMS cargs TCLAP Stb Vulkan) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/${DEP}") include(${DEP}) endforeach() diff --git a/cmake/Dependencies/Vulkan/Vulkan.cmake b/cmake/Dependencies/Vulkan/Vulkan.cmake new file mode 100644 index 00000000..ffdcdbd0 --- /dev/null +++ b/cmake/Dependencies/Vulkan/Vulkan.cmake @@ -0,0 +1 @@ +find_package(Vulkan REQUIRED) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 28bbe937..b3a92a4b 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -33,11 +33,12 @@ CHECK_LIBRARY_EXISTS(m sin "" HAVE_LIB_M) # KERNELS ... # optional, specifies kernel files for the sample # INCLUDES ... # optional, specifies additional include directories for the sample # LIBS ... # optional, specifies additional libraries for the sample +# DEFINITIONS # optional, specifies additional compile definitions for the sample # ) macro(add_sample) set(options TEST) set(one_value_args TARGET VERSION CATEGORY) - set(multi_value_args SOURCES KERNELS SHADERS INCLUDES LIBS) + set(multi_value_args SOURCES KERNELS SHADERS INCLUDES LIBS DEFINITIONS) cmake_parse_arguments(OPENCL_SAMPLE "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN} @@ -75,6 +76,7 @@ macro(add_sample) CL_HPP_MINIMUM_OPENCL_VERSION=${OPENCL_SAMPLE_VERSION} CL_HPP_ENABLE_EXCEPTIONS $<$:_CRT_SECURE_NO_WARNINGS> # TODO: remove + ${OPENCL_SAMPLE_DEFINITIONS} ) set_target_properties(${OPENCL_SAMPLE_TARGET} diff --git a/samples/extensions/khr/CMakeLists.txt b/samples/extensions/khr/CMakeLists.txt index 82d4426f..4bf194d7 100644 --- a/samples/extensions/khr/CMakeLists.txt +++ b/samples/extensions/khr/CMakeLists.txt @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +add_subdirectory(externalmemory) add_subdirectory(histogram) if(OPENCL_SDK_BUILD_OPENGL_SAMPLES) add_subdirectory(conway) diff --git a/samples/extensions/khr/externalmemory/CMakeLists.txt b/samples/extensions/khr/externalmemory/CMakeLists.txt new file mode 100644 index 00000000..78ea8a8c --- /dev/null +++ b/samples/extensions/khr/externalmemory/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2021 The Khronos Group Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_sample( + TEST + TARGET externalmemory + VERSION 300 + SOURCES main.c + KERNELS external_saxpy.cl + LIBS Vulkan::Vulkan + DEFINITIONS $<$:VK_USE_PLATFORM_WIN32_KHR>) + +add_sample( + TEST + TARGET externalmemorycpp + VERSION 300 + SOURCES main.cpp + KERNELS external_saxpy.cl + LIBS Vulkan::Vulkan + DEFINITIONS $<$:VK_USE_PLATFORM_WIN32_KHR>) diff --git a/samples/extensions/khr/externalmemory/README.md b/samples/extensions/khr/externalmemory/README.md new file mode 100644 index 00000000..78ca63f6 --- /dev/null +++ b/samples/extensions/khr/externalmemory/README.md @@ -0,0 +1,257 @@ +# External Memory Sample + +## Sample purpose +External devices resources can be shared across GPU APIs. This can specially come in handy when developing graphical applications, as usually we have specialized APIs for graphics (like OpenGL or the lower-level-API Vulkan) that are used for rendering and the more general APIs (like OpenCL, SYCL, etc). This sample showcases an OpenCL program that interacts with the Vulkan API by sharing buffers. For one that actually does rendering, the [open_cl_interop](https://github.com/KhronosGroup/Vulkan-Samples/tree/main/samples/extensions/open_cl_interop) sample should be consulted. + +## Key APIs and Concepts +### Kernel logic +The kernel used in this sample is a saxpy, i.e. performs the vector operation $a*x+y$ where $x$ and $y$ are the input vectors and $a$ is a scalar. This simple kernel was chosen because the main purpose of the example is to showcase the buffer sharing between the OpenCL and Vulkan APIs, rather than showing off some complex kernel implementation. + +### Create Vulkan instance with the necessary extensions enabled +The Vulkan function `vkCreateInstance` creates a new Vulkan instance (object gathering the application's state), which later can be used to query the physical devices available on the system for our program. When calling to this function, a `VkInstanceCreateInfo` object must be passed in order to tell the Vulkan API some characteristics of the application. In this sample, one of the main pieces of information passed to the named function is a list of Vulkan instance extensions to be enabled: +- `VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME` for exporting non-Vulkan handles from Vulkan buffers. +- `VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME` for also being able to query the properties of physical devices (needed for obtaining the devices' UUIDs). + +### Find an OpenCL device Vulkan-compatible +In the context of a given OpenCL program, for a device to be compatible with the Vulkan API there are three main requirements: +- It has to be recognized by Vulkan as a physical device, that is, Vulkan must report the existence of a physical device with the same UUID than the selected OpenCL device's. In Vulkan, with `vkGetPhysicalDeviceProperties2` we can get the properties of a physical device, among which is included the `deviceUUID` attribute storing the UUID of the corresponding device. For OpenCL, we can query the device's UUID by calling `clGetDeviceInfo` (or the C++ wrapper `cl::Device::getInfo<>()`) with the `CL_DEVICE_UUID_KHR` value as `cl_device_info` parameter. + - Beware the query of the UUID in OpenCL/Vulkan cannot be done without the device supporting the `cl_khr_device_uuid`/`VK_KHR_get_physical_device_properties2`. +- It must support the Vulkan device extensions needed for the program at hand. In this occasion, we need the Vulkan device to support exporting non-Vulkan handles from Vulkan memory objects (e.g. buffers). The `vkEnumerateDeviceExtensionProperties` function is used for querying the Vulkan device extensions supported by a given physical device. +- It also needs to support the Khronos extension `cl_khr_external_memory_opaque_fd` for Linux systems or `cl_khr_external_memory_win32` for Windows. With the C API, The function `clGetDeviceInfo` called with the parameter `CL_DEVICE_EXTENSIONS` provides information about whether this extension is supported by the OpenCL device. The C++ API (Utils library) provides the function `cl::util::supports_extension`, with which this check can be done easier. + + _Note: The `cl_khr_external_memory` extension requires OpenCL 3.0, which we make sure to check that is indeed supported on the device before compiling the OpenCL kernel._ + +Once a suitable Vulkan physical device (and its correspondent OpenCL device) has been found, we can create a Vulkan device object from it with `vkCreateDevice`. We must set the `ppEnabledExtensionNames` attribute of the `VkDeviceCreateInfo` passed to the said function with the names of the required Vulkan device extensions (that we already checked the device supports) in order for them to be enabled on the device. + +### Create Vulkan buffers for external sharing +When creating the Vulkan buffer objects for our application, we must make explicit that those buffers are going to be shared with an external API. The way of doing this can be summarized into the following steps: +- Before starting to allocate Vulkan memory objects, we need to ensure that the external memory handle type needed for importing Vulkan memory objects is supported by the device, both in OpenCL and in Vulkan APIs. +The mapping between Vulkan and OpenCL handle types is as follows: + + | Vulkan external memory handle type | OpenCL external memory handle type | + | ------------------------------------------------------------------ | ------------------------------------------------------------- | + | `VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR` | `CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR` | + | `VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR` | `CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR` | + | `VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR` | `CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_BIT_KHR` | + + The first row contains the handle types used for Linux, while for Windows platforms the handle types used are either the ones from the second or third row. + + To check whether the OpenCL device supports the memory handle we use `clGetDeviceInfo` with the `CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR` value as `cl_device_info` parameter in order to get a list of supported external memory handle types. + + For Vulkan, we can request a `VkExternalBufferProperties` object containing this information by calling to `vkGetPhysicalDeviceExternalBufferProperties`. + +- We now create our Vulkan buffer objects. We first initialize a `VkExternalMemoryBufferCreateInfo` structure with the necessary information for the buffers bounded to the exported memory. It is **mandatory** when creating a Vulkan buffer that will be bound to exported/imported memory to pass a **non-null** value for the **`handleTypes`** field of this info structure. A pointer to this object is then added as the `pNext` field of a `VkBufferCreateInfo` structure, which contains the information for creating Vulkan buffers (that are not necessarily bounded to external memory). We finally create our buffers by calling `vkCreateBuffer`. + +- The next step is to allocate device memory. This is done with the function `vkAllocateMemory`, which needs a `VkMemoryAllocateInfo` parameter. The key information to set up when allocating external memory is the `pNext` field, pointing to a `VkExportMemoryAllocateInfo` structure which `handleTypes` field specifies the handle types that may be exported. + +- After allocating the device memory, it is only left to bind it to the buffer objects with `vkBindBufferMemory` and to map the latter into the application address space with `vkMapMemory`. If the buffer objects are to be mapped in their entirety, we can use `VK_WHOLE_SIZE` as the `size` parameter of `vkMapMemory`. After mapping the buffer objects we obtain host-accessible pointers to the beginning of the mapped ranges and we can just copy the contents of the host arrays to those ranges. + +### Initialize OpenCL buffers from external API +The key point when initializing OpenCL buffers from external memory is that we need a file descriptor associated to this external memory in order to access it from the OpenCL API. In the Vulkan API we can get such file descriptor by making use of the function `vkGetMemoryFdKHR` provided by the `VK_KHR_external_memory_fd` extension. + +Being provided by an extension, we need to obtain a function pointer to it by calling to `vkGetDeviceProcAddr`. We can then call `vkGetMemoryFdKHR` with a `VkMemoryGetFdInfoKHR` parameter containing the information about the memory range for which we want to obtain a file descriptor: + - `memory` field containing the pointer to the said range + - `handleType` field with the same Vulkan external memory handle type used in the `VkExportMemoryAllocateInfo` structure when memory was allocated. + +Once we have the file descriptor, we can initialize an array of `cl_mem_properties` with the following entries: +- The OpenCL external memory handle type to use. +- The file descriptor previously obtained for the Vulkan memory range. +- A list of devices to which these properties apply. This list must start with an entry containing the macro `CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR`, followed by as many entries as devices in the list containing the corresponding `cl_device_id` objects. The list must end with an entry containing the macro `CL_DEVICE_HANDLE_LIST_END_KHR`. +- A $0$ indicating the end of the array. + +_Note: With the C++ API we can obtain the `cl_device_id` object from a `cl::Device device` wrapper by using the `()` operator._ + +This array of properties is then passed to `clCreateBufferWithProperties` (or to the C++ constructor of `cl::Buffer`). When creating OpenCL buffer objects from external memory there are a couple of restrictions in the parameters allowed for `clCreateBufferWithProperties`/`cl::Buffer::Buffer()`, namely: +- The `flags` parameter used to specify usage information for the buffer must not include `CL_MEM_USE_HOST_PTR`, `CL_MEM_ALLOC_HOST_PTR`, or `CL_MEM_COPY_HOST_PTR`. +- The `host_ptr` argument must be null. + +From this point on the OpenCL API functions are called as usual. + +## Application flow +### Overview +1. Parse user options. +2. Initialize Vulkan instance. +3. Find an OpenCL Vulkan-compatible device. +4. Create a Vulkan device object from the physical device selected enabling the required extensions on it. +5. Check that the OpenCL device supports the necessary Khronos extensions. +6. Create Vulkan's buffer objects for sharing them with an external API. +7. Query the requirements for memory to be exportable. Allocate memory, bind buffers to memory and map the former to the Vulkan address space. Copy input from host to Vulkan memory objects. +8. Query the file descriptors correspondent to Vulkan's memory ranges mapped and initialize OpenCL buffers from them. +9. Enqueue kernel call to saxpy. +10. Fetch and validate result. +11. Free resources. + +## Used API surface +### C +```c +CL_BLOCKING +CL_CONTEXT_PLATFORM +CL_DEVICE_EXTENSIONS +CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR +CL_DEVICE_HANDLE_LIST_KHR +CL_DEVICE_HANDLE_LIST_END_KHR +CL_DEVICE_NAME +CL_DEVICE_PLATFORM +CL_DEVICE_TYPE_ALL +CL_HPP_TARGET_OPENCL_VERSION +CL_INVALID_ARG_VALUE +CL_INVALID_VALUE +CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR +CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR +CL_KERNEL_WORK_GROUP_SIZE +CL_KHR_EXTERNAL_MEMORY_OPAQUE_FD_EXTENSION_NAME +CL_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME +CL_MEM_READ_ONLY +CL_MEM_READ_WRITE +CL_PLATFORM_VENDOR +CL_PROFILING_COMMAND_END +CL_PROFILING_COMMAND_START +CL_QUEUE_PROFILING_ENABLE +CL_QUEUE_PROPERTIES +CL_SUCCESS +CL_UUID_SIZE_KHR +cl_command_queue +cl_command_queue_properties +cl_context +cl_context_properties +cl_device_id +cl_event +cl_float +cl_int +cl_kernel +cl_external_memory_handle_type_khr +cl_khr_external_memory_opaque_fd +cl_khr_external_memory_win32 +cl_mem +cl_mem_properties +cl_platform_id +cl_program +cl_sdk_fill_with_random_ints_range(pcg32_random_t*, cl_int*, size_t, cl_int, cl_int) +cl_sdk_options_Diagnostic +cl_sdk_options_SingleDevice +cl_uint +cl_uchar +cl_ulong +cl_util_build_program(cl_program, cl_device_id, char*) +cl_util_get_device(cl_uint, cl_uint, cl_device_type, cl_int*) +cl_util_get_event_duration(cl_event, cl_profiling_info, cl_profiling_info, cl_int*) +cl_util_print_device_info*(cl_device_id) +cl_util_print_error(cl_int) +cl_util_read_text_file(char*const, size_t*const, cl_int*) +clCreateBufferWithProperties(cl_context, cl_mem_properties*, cl_mem_flags, size_t, void*, cl_int*) +clCreateCommandQueueWithProperties(cl_context, cl_device_id, cl_queue_properties*, cl_int*) -> OpenCL >= 2.0 +clCreateContext(cl_context_properties*, cl_uint, cl_device_id*, void *(char*, void*,size_t, void*), void*, cl_int*) +clCreateKernel(cl_program, char*, cl_int*) +clGetKernelWorkGroupInfo(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void*, size_t*) +clCreateProgramWithSource(cl_context, cl_uint, char**, size_t*, cl_int*) +clEnqueueNDRangeKernel(cl_command_queue, cl_kernel, cl_uint, size_t*, size_t*, size_t*, cl_uint, cl_event*, cl_event*) +clEnqueueReadBuffer(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void*, cl_uint, cl_event*, cl_event*) +clGetDeviceIDs(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*) +clGetDeviceInfo(cl_device_id, cl_device_info, size_t, void*, size_t*) +clGetPlatformIDs(cl_uint, cl_platform_id*, cl_uint*) +clReleaseCommandQueue(cl_command_queue) +clReleaseContext(cl_context) +clReleaseKernel(cl_kernel) +clReleaseMemObject(cl_mem) +clReleaseProgram(cl_program) +clSetKernelArg(cl_kernel, cl_uint, size_t, void *) +clWaitForEvents(cl_uint, cl_event*) +``` + +### C++ +```c++ +cl::Buffer::Buffer(const Context&, const vector&, IteratorType, IteratorType, bool, bool=false, cl_int*=NULL) +cl::BuildError +cl::CommandQueue::CommandQueue(const cl::Context&, const Device&,cl::QueueProperties, cl_int*=NULL) +cl::Context +cl::Device::Device() +cl::EnqueueArgs::EnqueueArgs(cl::CommandQueue&, cl::NDRange, cl::NDRange) +cl::Error +cl::Event +cl::KernelFunctor::KernelFunctor(const Program&, const string, cl_int*=NULL) +cl::NDRange::NDRange(size_t, size_t) +cl::Platform::Platform() +cl::Platform::Platform(cl::Platform) +cl::Platform::get(vector*) +cl::Program::Program(cl::Program) +cl::WaitForEvents(const vector&) +cl::copy(const CommandQueue&, const cl::Buffer&, IteratorType, IteratorType) +cl::sdk::comprehend() +cl::sdk::fill_with_random() +cl::sdk::get_context(cl_uint, cl_uint, cl_device_type, cl_int*) +cl::sdk::parse() +cl::sdk::parse_cli() +cl::sdk::options::Diagnostic +cl::sdk::options::SingleDevice +cl::string::string(cl::string) +cl::util::Error +cl::util::get_duration(cl::Event&) +cl::util::supports_extension(const cl::Device&, const cl::string&) +``` + +### Vulkan +```c +PFN_vkCreateDevice(VkPhysicalDevice, const VkDeviceCreateInfo*, const VkAllocationCallbacks*, VkDevice*) +VK_BUFFER_USAGE_TRANSFER_DST_BIT +VK_BUFFER_USAGE_TRANSFER_SRC_BIT +VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR +VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR +VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME +VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME +VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME +VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME +VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME +VK_MAKE_VERSION +VK_MEMORY_PROPERTY_HOST_COHERENT_BIT +VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT +VK_SHARING_MODE_EXCLUSIVE +VK_STRUCTURE_TYPE_APPLICATION_INFO +VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO +VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO +VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO +VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO +VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO +VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO +VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR +VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR +VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR +VK_SUCCESS +VK_WHOLE_SIZE +VkApplicationInfo +VkBuffer +VkBufferCreateInfo +VkDevice +VkDeviceMemory +VkDeviceQueueCreateInfo +VkExportMemoryAllocateInfo +VkExtensionProperties +VkExternalMemoryBufferCreateInfo +VkExternalMemoryHandleTypeFlagBits +VkInstance +VkInstanceCreateInfo +VkMemoryAllocateInfo +VkMemoryGetFdInfoKHR +VkMemoryPropertyFlags +VkMemoryRequirements +VkPhysicalDevice +VkPhysicalDeviceIDPropertiesKHR +VkPhysicalDeviceMemoryProperties +VkPhysicalDeviceProperties2KHR +VkPhysicalDeviceProperties +VkResult +vkAllocateMemory(VkDevice, const VkMemoryAllocateInfo*, const VkAllocationCallbacks*, VkDeviceMemory*) +vkBindBufferMemory(VkDevice, VkBuffer, VkDeviceMemory, VkDeviceSize) +vkCreateBuffer(VkDevice, const VkBufferCreateInfo*, const VkAllocationCallbacks*, VkBuffer*) +vkCreateInstance(const VkInstanceCreateInfo*, const VkAllocationCallbacks*, VkInstance*) +vkDestroyBuffer(VkDevice, VkBuffer, const VkAllocationCallbacks*) +vkEnumerateDeviceExtensionProperties(VkPhysicalDevice, const char*, uint32_t*, VkExtensionProperties*) +vkEnumeratePhysicalDevices(VkInstance, uint32_t*, VkPhysicalDevice*) +vkFreeMemory(VkDevice, VkDeviceMemory, const VkAllocationCallbacks*) +vkGetBufferMemoryRequirements(VkDevice, VkBuffer, VkMemoryRequirements*) +vkGetDeviceProcAddr(VkDevice, const char*) +vkGetMemoryFdKHR(VkDevice, const VkMemoryGetFdInfoKHR*, int*) +vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice, VkPhysicalDeviceMemoryProperties*) +vkGetPhysicalDeviceProperties2(VkPhysicalDevice, VkPhysicalDeviceProperties2) +vkMapMemory(VkDevice, VkDeviceMemory, VkDeviceSize, VkDeviceSize, VkMemoryMapFlags, void**) +vkUnmapMemory(VkDevice, VkDeviceMemory) +``` diff --git a/samples/extensions/khr/externalmemory/external_saxpy.cl b/samples/extensions/khr/externalmemory/external_saxpy.cl new file mode 100644 index 00000000..c5780872 --- /dev/null +++ b/samples/extensions/khr/externalmemory/external_saxpy.cl @@ -0,0 +1,8 @@ +__kernel void saxpy(float a, + __global float* x, + __global float* y) +{ + int gid = get_global_id(0); + + y[gid] = fma(a, x[gid], y[gid]); +} diff --git a/samples/extensions/khr/externalmemory/main.c b/samples/extensions/khr/externalmemory/main.c new file mode 100644 index 00000000..c49ff2c6 --- /dev/null +++ b/samples/extensions/khr/externalmemory/main.c @@ -0,0 +1,654 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// OpenCL SDK includes. +#include +#include +#include +#include + +// OpenCL Utils includes. +#include +#include +#include + +// Vulkan includes. +#include + +// Vulkan utils includes. +#include "vulkan_utils.h" + +// Standard header includes. +#include +#include +#include +#include + +// Sample-specific option. +struct options_Saxpy +{ + size_t length; +}; + +// Add option to CLI-parsing SDK utility for input length. +cag_option SaxpyOptions[] = { { .identifier = 'l', + .access_letters = "l", + .access_name = "length", + .value_name = "(positive integer)", + .description = "Length of input" } }; + +ParseState parse_SaxpyOptions(const char identifier, + cag_option_context* cag_context, + struct options_Saxpy* opts) +{ + const char* value; + switch (identifier) + { + case 'l': + if (0 != (value = cag_option_get_value(cag_context))) + { + opts->length = strtoul(value, NULL, 0); + return ParsedOK; + } + else + return ParseError; + } + return NotParsed; +} + +cl_int parse_options(int argc, char* argv[], + struct cl_sdk_options_Diagnostic* diag_opts, + struct options_Saxpy* saxpy_opts) +{ + cl_int error = CL_SUCCESS; + struct cag_option *opts = NULL, *tmp = NULL; + size_t n = 0; + + // Prepare options array. + MEM_CHECK(opts = add_CLI_options(opts, &n, DiagnosticOptions, + CAG_ARRAY_SIZE(DiagnosticOptions)), + error, end); + opts = tmp; + MEM_CHECK(tmp = add_CLI_options(opts, &n, SaxpyOptions, + CAG_ARRAY_SIZE(SaxpyOptions)), + error, end); + opts = tmp; + + char identifier; + cag_option_context cag_context; + + // Prepare the context and iterate over all options. + cag_option_prepare(&cag_context, opts, n, argc, argv); + while (cag_option_fetch(&cag_context)) + { + ParseState state = NotParsed; + identifier = cag_option_get(&cag_context); + + PARS_OPTIONS(parse_DiagnosticOptions(identifier, diag_opts), state); + PARS_OPTIONS(parse_SaxpyOptions(identifier, &cag_context, saxpy_opts), + state); + + if (identifier == 'h') + { + printf("Usage: externalmemory [OPTION]...\n"); + printf("Option name and value should be separated by '=' or a " + "space\n"); + printf("Demonstrates OpenCL--Vulkan interop.\n\n"); + cag_option_print(opts, n, stdout); + exit((state == ParseError) ? CL_INVALID_ARG_VALUE : CL_SUCCESS); + } + } +end: + free(opts); + return error; +} + +// Host-side saxpy implementation. +void host_saxpy(const cl_float* x, cl_float* y, const float a, size_t length) +{ + for (size_t i = 0; i < length; ++i) + { + y[i] = fmaf(a, x[i], y[i]); + } +} + +// Vulkan instance extensions required for sharing OpenCL and Vulkan types: +// - VK_KHR_EXTERNAL_MEMORY_CAPABILITIES required for sharing buffers. +// - VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2 required for the previous one +// and for querying the device's UUID. +const char* const required_instance_extensions[] = { + VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, /*VK_KHR_external_memory_capabilities*/ + VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME /*VK_KHR_get_physical_device_properties2*/ +}; +const size_t required_instance_extensions_count = + sizeof(required_instance_extensions) / sizeof(const char*); + +// General Vulkan extensions that a device needs to support for exporting +// memory. +const char* required_device_extensions[] = { + VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, /*VK_KHR_external_memory*/ +#ifdef _WIN32 + VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME /*VK_KHR_external_memory_win32*/ +#else + VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME /*VK_KHR_external_memory_fd*/ +#endif +}; +const size_t required_device_extensions_count = + sizeof(required_device_extensions) / sizeof(const char*); + +// Khronos extensions that a device needs to support memory sharing with Vulkan. +const char* required_khronos_extensions[] = { +#ifdef _WIN32 + CL_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME /*cl_khr_external_memory_win32*/ +#else + CL_KHR_EXTERNAL_MEMORY_OPAQUE_FD_EXTENSION_NAME /*cl_khr_external_memory_opaque_fd*/ +#endif +}; +const size_t required_khronos_extensions_count = + sizeof(required_khronos_extensions) / sizeof(const char*); + +// Required Vulkan external memory handle. +const VkExternalMemoryHandleTypeFlagBits vk_external_memory_handle_type = +#ifdef _WIN32 + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR; +#else + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; +#endif + +// Required OpenCL external memory handle. +const cl_external_memory_handle_type_khr cl_external_memory_handle_type = +#ifdef _WIN32 + CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR; +#else + CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR; +#endif + +// Check if a given OpenCL device supports a particular external memory handle +// type. +bool cl_check_external_memory_handle_type( + const cl_device_id cl_device, + cl_external_memory_handle_type_khr external_memory_handle_type) +{ + cl_external_memory_handle_type_khr* supported_handle_types = NULL; + size_t supported_handle_types_count = 0; + cl_int error = CL_SUCCESS; + + OCLERROR_RET( + clGetDeviceInfo(cl_device, + CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, 0, + NULL, &supported_handle_types_count), + error, err); + supported_handle_types = (cl_external_memory_handle_type_khr*)malloc( + supported_handle_types_count); + + OCLERROR_RET( + clGetDeviceInfo( + cl_device, CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, + supported_handle_types_count, supported_handle_types, NULL), + error, err); + for (size_t i = 0; i < supported_handle_types_count; ++i) + { + if (external_memory_handle_type == supported_handle_types[i]) + { + free(supported_handle_types); + return true; + } + } + free(supported_handle_types); + return false; +err: + fprintf(stderr, + "Error: OpenCL could not query supported external memory handle " + "types\n"); + free(supported_handle_types); + exit(EXIT_FAILURE); +} + +int main(int argc, char* argv[]) +{ + cl_int error = CL_SUCCESS; + cl_int end_error = CL_SUCCESS; + cl_platform_id cl_platform; + cl_device_id cl_device; + VkPhysicalDevice vk_physical_device; + VkDevice vk_device; + cl_context context = NULL; + cl_command_queue queue = NULL; + + cl_program program; + + // Parse command-line options. + struct cl_sdk_options_Diagnostic diag_opts = { .quiet = false, + .verbose = false }; + // Define as default length 1048576 = 4 * 262144 = sizeof(cl_float) * 2^18. + struct options_Saxpy saxpy_opts = { .length = 1048576 }; + + OCLERROR_RET(parse_options(argc, argv, &diag_opts, &saxpy_opts), error, + end); + + // Fill in Vulkan application info. + VkApplicationInfo app_info = { 0 }; + app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + app_info.pApplicationName = "OpenCL-Vulkan interop example"; + app_info.applicationVersion = VK_MAKE_VERSION(3, 0, 0); + app_info.pEngineName = "OpenCL-SDK samples"; + app_info.engineVersion = VK_MAKE_VERSION(3, 0, 0); + app_info.apiVersion = VK_MAKE_VERSION(3, 0, 0); + + // Initialize Vulkan instance info and create Vulkan instance. + VkInstanceCreateInfo instance_create_info = { + VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO + }; + instance_create_info.pApplicationInfo = &app_info; + instance_create_info.enabledExtensionCount = + (uint32_t)required_instance_extensions_count; + instance_create_info.ppEnabledExtensionNames = required_instance_extensions; + + VkInstance instance; + VK_CHECK(vkCreateInstance(&instance_create_info, NULL, &instance)); + + // Find a suitable (Vulkan-compatible) OpenCL device for the sample. + struct device_candidate candidate = find_suitable_device( + instance, required_device_extensions, required_device_extensions_count); + + // OpenCL device object for the selected device. + cl_device = candidate.cl_candidate.device; + + // Vulkan physical device object for the selected device. + vk_physical_device = candidate.vk_candidate; + + // Set up necessary info and create Vulkan device from physical device. + const float default_queue_priority = 1.0f; + VkDeviceQueueCreateInfo queue_create_info = { + VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO + }; + queue_create_info.queueFamilyIndex = 0; + queue_create_info.queueCount = 1; + queue_create_info.pQueuePriorities = &default_queue_priority; + + VkDeviceCreateInfo device_create_info = { + VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO + }; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &queue_create_info; + device_create_info.enabledExtensionCount = + (uint32_t)required_device_extensions_count; + device_create_info.ppEnabledExtensionNames = required_device_extensions; + + VK_CHECK(vkCreateDevice(vk_physical_device, &device_create_info, NULL, + &vk_device)); + + if (!diag_opts.quiet) + { + cl_util_print_device_info(cl_device); + } + + // Create OpenCL runtime objects. + OCLERROR_RET(clGetDeviceInfo(cl_device, CL_DEVICE_PLATFORM, + sizeof(cl_platform_id), &cl_platform, NULL), + error, cont); + cl_context_properties context_props[] = { + CL_CONTEXT_PLATFORM, (cl_context_properties)cl_platform, 0 + }; + OCLERROR_PAR(context = clCreateContext(context_props, 1, &cl_device, NULL, + NULL, &error), + error, end); + + // Check if the device supports the Khronos extensions needed before + // attempting to compile the kernel. + if (diag_opts.verbose) + { + printf("\nChecking Khronos extensions support... "); + fflush(stdout); + } + + if (!check_khronos_extensions(cl_device, required_khronos_extensions, + required_khronos_extensions_count)) + { + fprintf(stdout, + "OpenCL device does not support the required Khronos " + "extensions\n"); + exit(EXIT_SUCCESS); + } + + // Compile kernel. + if (diag_opts.verbose) + { + printf("done.\nCompiling OpenCL kernel... "); + fflush(stdout); + } + const char* kernel_location = "./external_saxpy.cl"; + char *kernel = NULL, *tmp = NULL; + size_t program_size = 0; + OCLERROR_PAR( + kernel = cl_util_read_text_file(kernel_location, &program_size, &error), + error, que); + MEM_CHECK(tmp = (char*)realloc(kernel, program_size), error, ker); + kernel = tmp; + OCLERROR_PAR(program = clCreateProgramWithSource( + context, 1, (const char**)&kernel, &program_size, &error), + error, ker); + + // The Khronos extension showcased requires OpenCL 3.0 version. + char compiler_options[1023] = ""; +#if CL_HPP_TARGET_OPENCL_VERSION >= 300 + strcat(compiler_options, "-cl-std=CL3.0 "); +#else + fprintf(stderr, "\nError: OpenCL version must be at least 3.0\n"); + exit(EXIT_FAILURE); +#endif + + OCLERROR_RET(cl_util_build_program(program, cl_device, compiler_options), + error, prg); + + // Query maximum workgroup size (WGS) supported based on private mem + // (registers) constraints. + size_t wgs; + cl_kernel saxpy; + OCLERROR_PAR(saxpy = clCreateKernel(program, "saxpy", &error), error, prg); + OCLERROR_RET(clGetKernelWorkGroupInfo(saxpy, cl_device, + CL_KERNEL_WORK_GROUP_SIZE, + sizeof(size_t), &wgs, NULL), + error, ker); + + // Initialize host-side storage. + const size_t length = saxpy_opts.length; + + // Random number generator. + pcg32_random_t rng; + pcg32_srandom_r(&rng, 11111, 2222); + + // Initialize input and output vectors and constant. + cl_float *arr_x, *arr_y, a; + MEM_CHECK(arr_x = (cl_float*)malloc(sizeof(cl_float) * length), error, sxp); + MEM_CHECK(arr_y = (cl_float*)malloc(sizeof(cl_float) * length), error, + arrx); + if (diag_opts.verbose) + { + printf("done.\nGenerating random scalar and %zd random numbers for " + "saxpy input vector...", + length); + fflush(stdout); + } + cl_sdk_fill_with_random_floats_range(&rng, &a, 1, -100, 100); + cl_sdk_fill_with_random_floats_range(&rng, arr_x, length, -100, 100); + cl_sdk_fill_with_random_floats_range(&rng, arr_y, length, -100, 100); + + // Check if the device supports the required OpenCL handle type. + if (diag_opts.verbose) + { + printf( + "done.\nChecking OpenCL external memory handle type support... "); + fflush(stdout); + } + + if (!cl_check_external_memory_handle_type(cl_device, + cl_external_memory_handle_type)) + { + fprintf(stderr, + "\nError: Unsupported OpenCL external memory handle type\n"); + exit(EXIT_FAILURE); + } + + if (!vk_check_external_memory_handle_type(vk_physical_device, + vk_external_memory_handle_type)) + { + fprintf(stderr, + "\nError: Unsupported Vulkan external memory handle type\n"); + exit(EXIT_FAILURE); + } + + // Initialize Vulkan device-side storage. + if (diag_opts.verbose) + { + printf("done.\nInitializing Vulkan device storage... "); + fflush(stdout); + } + + // Create Vulkan (external) buffers and assign memory to them. + VkExternalMemoryBufferCreateInfo external_memory_buffer_info = { + VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO + }; + external_memory_buffer_info.handleTypes = vk_external_memory_handle_type; + + VkBufferCreateInfo buffer_info = { 0 }; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.pNext = &external_memory_buffer_info; + buffer_info.size = sizeof(cl_float) * length; + buffer_info.usage = + VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; + ; + buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkBuffer vk_buf_x, vk_buf_y; + VK_CHECK(vkCreateBuffer(vk_device, &buffer_info, NULL, &vk_buf_x)); + VK_CHECK(vkCreateBuffer(vk_device, &buffer_info, NULL, &vk_buf_y)); + + // Get requirements and necessary information for (exportable) memory. + VkMemoryRequirements mem_requirements_x = { 0 }, mem_requirements_y = { 0 }; + vkGetBufferMemoryRequirements(vk_device, vk_buf_x, &mem_requirements_x); + vkGetBufferMemoryRequirements(vk_device, vk_buf_y, &mem_requirements_y); + + VkExportMemoryAllocateInfo export_memory_alloc_info = { + VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO + }; + export_memory_alloc_info.handleTypes = vk_external_memory_handle_type; + + VkMemoryAllocateInfo memory_alloc_info_x = { 0 }; + memory_alloc_info_x.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_alloc_info_x.pNext = &export_memory_alloc_info; + memory_alloc_info_x.allocationSize = mem_requirements_x.size; + memory_alloc_info_x.memoryTypeIndex = find_vk_memory_type( + vk_physical_device, mem_requirements_x.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + + VkMemoryAllocateInfo memory_alloc_info_y = { 0 }; + memory_alloc_info_y.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_alloc_info_y.pNext = &export_memory_alloc_info; + memory_alloc_info_y.allocationSize = mem_requirements_y.size; + memory_alloc_info_y.memoryTypeIndex = find_vk_memory_type( + vk_physical_device, mem_requirements_y.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + + // Allocate and bind memory. + VkDeviceMemory vk_buf_x_memory, vk_buf_y_memory; + VK_CHECK(vkAllocateMemory(vk_device, &memory_alloc_info_x, NULL, + &vk_buf_x_memory)); + VK_CHECK(vkAllocateMemory(vk_device, &memory_alloc_info_y, NULL, + &vk_buf_y_memory)); + + VK_CHECK(vkBindBufferMemory(vk_device, vk_buf_x, vk_buf_x_memory, 0)); + VK_CHECK(vkBindBufferMemory(vk_device, vk_buf_y, vk_buf_y_memory, 0)); + + // Map memory. + void *vk_arr_x, *vk_arr_y; + VK_CHECK(vkMapMemory(vk_device, vk_buf_x_memory, 0, VK_WHOLE_SIZE, 0, + &vk_arr_x)); + VK_CHECK(vkMapMemory(vk_device, vk_buf_y_memory, 0, VK_WHOLE_SIZE, 0, + &vk_arr_y)); + + memcpy(vk_arr_x, arr_x, sizeof(cl_float) * length); + memcpy(vk_arr_y, arr_y, sizeof(cl_float) * length); + + // Get Vulkan external memory file descriptors for accessing external memory + // with OpenCL. + VkMemoryGetFdInfoKHR fd_info_x = { 0 }; + fd_info_x.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR; + fd_info_x.pNext = NULL; + fd_info_x.memory = vk_buf_x_memory; + fd_info_x.handleType = vk_external_memory_handle_type; + int fd_x; + + VkMemoryGetFdInfoKHR fd_info_y = { 0 }; + fd_info_y.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR; + fd_info_y.pNext = NULL; + fd_info_y.memory = vk_buf_y_memory; + fd_info_y.handleType = vk_external_memory_handle_type; + int fd_y; + + // We need to get the pointer to the vkGetMemoryFdKHR function because it's + // from extension VK_KHR_external_memory_fd. + PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR = + (PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(vk_device, + "vkGetMemoryFdKHR"); + + VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_x, &fd_x)); + VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_y, &fd_y)); + + // Create OpenCL buffers from Vulkan external memory file descriptors. + cl_mem_properties ext_mem_props_x[] = { + (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, + (cl_mem_properties)fd_x, + (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)(uintptr_t)cl_device, + CL_DEVICE_HANDLE_LIST_END_KHR, + 0 + }; + cl_mem_properties ext_mem_props_y[] = { + (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, + (cl_mem_properties)fd_y, + (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)(uintptr_t)cl_device, + CL_DEVICE_HANDLE_LIST_END_KHR, + 0 + }; + cl_mem cl_buf_x, cl_buf_y; + OCLERROR_PAR(cl_buf_x = clCreateBufferWithProperties( + context, ext_mem_props_x, CL_MEM_READ_ONLY, + sizeof(cl_float) * length, NULL, &error), + error, vulkan); + OCLERROR_PAR(cl_buf_y = clCreateBufferWithProperties( + context, ext_mem_props_y, CL_MEM_READ_WRITE, + sizeof(cl_float) * length, NULL, &error), + error, clbufx); + + // Initialize queue for command execution. + cl_command_queue_properties queue_props[] = { CL_QUEUE_PROPERTIES, + CL_QUEUE_PROFILING_ENABLE, + 0 }; + OCLERROR_PAR(queue = clCreateCommandQueueWithProperties( + context, cl_device, queue_props, &error), + error, cont); + + // Set kernel arguments. + OCLERROR_RET(clSetKernelArg(saxpy, 0, sizeof(cl_float), &a), error, clbufy); + OCLERROR_RET(clSetKernelArg(saxpy, 1, sizeof(cl_mem), &cl_buf_x), error, + clbufy); + OCLERROR_RET(clSetKernelArg(saxpy, 2, sizeof(cl_mem), &cl_buf_y), error, + clbufy); + + // Launch kernel. + if (diag_opts.verbose) + { + printf("done.\nExecuting on device... "); + fflush(stdout); + } + + cl_event kernel_run; + GET_CURRENT_TIMER(dev_start) + OCLERROR_RET(clEnqueueNDRangeKernel(queue, saxpy, 1, NULL, &length, &wgs, 0, + NULL, &kernel_run), + error, clbufy); + OCLERROR_RET(clWaitForEvents(1, &kernel_run), error, clbufy); + GET_CURRENT_TIMER(dev_end) + + cl_ulong dev_time; + TIMER_DIFFERENCE(dev_time, dev_start, dev_end) + + // Concurrently calculate reference saxpy. + if (diag_opts.verbose) + { + printf("done.\nExecuting on host... "); + } + + GET_CURRENT_TIMER(host_start) + host_saxpy(arr_x, arr_y, a, length); + GET_CURRENT_TIMER(host_end) + cl_ulong host_time; + TIMER_DIFFERENCE(host_time, host_start, host_end) + + if (diag_opts.verbose) + { + printf("done.\n"); + } + + // Fetch results. + OCLERROR_RET(clEnqueueReadBuffer(queue, cl_buf_y, CL_BLOCKING, 0, + sizeof(cl_float) * length, (void*)arr_x, 0, + NULL, NULL), + error, clbufy); + + // Validate solution. + for (size_t i = 0; i < length; ++i) + if (arr_y[i] != arr_x[i]) + { + printf("Verification failed! %f != %f at index %zu\n", arr_y[i], + arr_x[i], i); + error = CL_INVALID_VALUE; + } + if (error == CL_SUCCESS) + { + printf("Verification passed.\n"); + } + + if (!diag_opts.quiet) + { + printf("Kernel execution time as seen by host: %llu us.\n", + (unsigned long long)(dev_time + 500) / 1000); + + printf("Kernel execution time as measured by device:\n"); + printf("\t%llu us.\n", + (unsigned long long)(cl_util_get_event_duration( + kernel_run, CL_PROFILING_COMMAND_START, + CL_PROFILING_COMMAND_END, &error) + + 500) + / 1000); + + printf("Reference execution as seen by host: %llu us.\n", + (unsigned long long)(host_time + 500) / 1000); + } + + // Release resources. +clbufy: + OCLERROR_RET(clReleaseMemObject(cl_buf_y), end_error, clbufx); +clbufx: + OCLERROR_RET(clReleaseMemObject(cl_buf_x), end_error, vulkan); +vulkan: + vkDestroyBuffer(vk_device, vk_buf_y, NULL); + vkDestroyBuffer(vk_device, vk_buf_x, NULL); + vkUnmapMemory(vk_device, vk_buf_y_memory); + vkUnmapMemory(vk_device, vk_buf_x_memory); + vkFreeMemory(vk_device, vk_buf_y_memory, NULL); + vkFreeMemory(vk_device, vk_buf_x_memory, NULL); + free(arr_y); +arrx: + free(arr_x); +sxp: + OCLERROR_RET(clReleaseKernel(saxpy), end_error, prg); +prg: + OCLERROR_RET(clReleaseProgram(program), end_error, ker); +ker: + free(kernel); +que: + OCLERROR_RET(clReleaseCommandQueue(queue), end_error, cont); +cont: + OCLERROR_RET(clReleaseContext(context), end_error, end); +end: + if (error) cl_util_print_error(error); + return error; +} diff --git a/samples/extensions/khr/externalmemory/main.cpp b/samples/extensions/khr/externalmemory/main.cpp new file mode 100644 index 00000000..e4026c23 --- /dev/null +++ b/samples/extensions/khr/externalmemory/main.cpp @@ -0,0 +1,559 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// OpenCL C++ headers includes. +#include + +// OpenCL SDK includes. +#include +#include +#include +#include + +// OpenCL Utils includes. +#include +#include +#include + +// Vulkan includes. +#include + +// Vulkan utils includes. +#include "vulkan_utils.hpp" + +// Standard header includes. +#include +#include +#include +#include +#include + +// Sample-specific option. +struct SaxpyOptions +{ + size_t length; +}; + +// Add option to CLI-parsing SDK utility for input dimensions. +template <> auto cl::sdk::parse() +{ + return std::make_tuple(std::make_shared>( + "l", "length", "Length of input", false, 1'048'576, + "positive integral")); +} +template <> +SaxpyOptions cl::sdk::comprehend( + std::shared_ptr> length_arg) +{ + return SaxpyOptions{ length_arg->getValue() }; +} + +// Host-side saxpy implementation. +void host_saxpy(std::vector x, std::vector& y, const float a, + size_t length) +{ + for (size_t i = 0; i < length; ++i) + { + y[i] = std::fmaf(a, x[i], y[i]); + } +} + +// Vulkan instance extensions required for sharing OpenCL and Vulkan types: +// - VK_KHR_EXTERNAL_MEMORY_CAPABILITIES required for sharing buffers. +// - VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2 required for the previous one +// and for querying the device's UUID. +const std::vector required_instance_extensions_str = { + VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, /*VK_KHR_external_memory_capabilities*/ + VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME /*VK_KHR_get_physical_device_properties2*/ +}; + +// General Vulkan extensions that a device needs to support to run this +// example: +// - VK_KHR_EXTERNAL_MEMORY required for sharing memory. +const std::vector required_device_extensions_str = { + std::string{ + VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME }, /*VK_KHR_external_memory*/ +#ifdef _WIN64 + std::string{ + VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME } /*VK_KHR_external_memory_win32*/ +#else + std::string{ + VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME } /*VK_KHR_external_memory_fd*/ +#endif +}; + +// Required Vulkan external memory handle. +const VkExternalMemoryHandleTypeFlagBits vk_external_memory_handle_type = +#ifdef _WIN32 + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR; +#else + VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; +#endif + +// Khronos extensions that a device needs to support memory sharing with Vulkan. +const std::vector required_khronos_extensions = { +#ifdef _WIN32 + std::string{ "cl_khr_external_memory_win32" } +#else + std::string{ "cl_khr_external_memory_opaque_fd" } +#endif +}; + +// Required OpenCL external memory handle. +const cl_external_memory_handle_type_khr cl_external_memory_handle_type = +#ifdef _WIN32 + CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR; +#else + CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR; +#endif + +// Check if a given OpenCL device supports a particular external memory handle +// type. +bool cl_check_external_memory_handle_type( + const cl::Device cl_device, + cl_external_memory_handle_type_khr external_memory_handle_type) +{ + std::vector supported_handle_types; + cl_device.getInfo(CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, + &supported_handle_types); + + const auto it = std::find_if( + supported_handle_types.begin(), supported_handle_types.end(), + [&](const cl_external_memory_handle_type_khr& supported_handle_type) { + return external_memory_handle_type == supported_handle_type; + }); + return it != supported_handle_types.end(); +} + +int main(int argc, char* argv[]) +{ + try + { + // Parse command-line options. + auto opts = + cl::sdk::parse_cli( + argc, argv); + const auto& diag_opts = std::get<0>(opts); + const auto& saxpy_opts = std::get<1>(opts); + + // Fill in Vulkan application info. + VkApplicationInfo app_info{}; + app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + app_info.pApplicationName = "OpenCL-Vulkan interop example"; + app_info.applicationVersion = VK_MAKE_VERSION(3, 0, 0); + app_info.pEngineName = "OpenCL-SDK samples"; + app_info.engineVersion = VK_MAKE_VERSION(3, 0, 0); + app_info.apiVersion = VK_MAKE_VERSION(3, 0, 0); + + // Initialize Vulkan instance info and create Vulkan instance. + std::vector required_instance_extensions( + required_instance_extensions_str.size(), nullptr); + std::transform(required_instance_extensions_str.begin(), + required_instance_extensions_str.end(), + required_instance_extensions.begin(), + [&](const std::string& str) { return str.c_str(); }); + VkInstanceCreateInfo instance_create_info{}; + instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + instance_create_info.pApplicationInfo = &app_info; + instance_create_info.enabledExtensionCount = + static_cast(required_instance_extensions.size()); + instance_create_info.ppEnabledExtensionNames = + required_instance_extensions.data(); + + VkInstance instance; + VK_CHECK(vkCreateInstance(&instance_create_info, nullptr, &instance)); + + // Find a suitable (Vulkan-compatible) OpenCL device for the sample. + std::vector required_device_extensions( + required_device_extensions_str.size(), nullptr); + std::transform(required_device_extensions_str.begin(), + required_device_extensions_str.end(), + required_device_extensions.begin(), + [&](const std::string& str) { return str.c_str(); }); + device_candidate candidate = + find_suitable_device(instance, required_device_extensions); + + // OpenCL device and platform objects for the selected device. + cl::Device cl_device = candidate.cl_candidate.device; + const cl::Platform cl_platform{ + cl_device.getInfo() + }; + + // Vulkan physical device object for the selected device. + const VkPhysicalDevice vk_physical_device = candidate.vk_candidate; + + // Set up necessary info and create Vulkan device from physical device. + constexpr float default_queue_priority = 1.0f; + VkDeviceQueueCreateInfo queue_create_info{}; + queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; + queue_create_info.queueFamilyIndex = 0; + queue_create_info.queueCount = 1; + queue_create_info.pQueuePriorities = &default_queue_priority; + + VkDeviceCreateInfo device_create_info{}; + device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; + device_create_info.queueCreateInfoCount = 1; + device_create_info.pQueueCreateInfos = &queue_create_info; + device_create_info.enabledExtensionCount = + static_cast(required_device_extensions.size()); + device_create_info.ppEnabledExtensionNames = + required_device_extensions.data(); + + VkDevice vk_device; + VK_CHECK(vkCreateDevice(vk_physical_device, &device_create_info, + nullptr, &vk_device)); + + if (!diag_opts.quiet) + { + std::cout << "Selected platform: " + << cl_platform.getInfo() << "\n" + << "Selected device: " + << cl_device.getInfo() << "\n" + << std::endl; + } + + // Create OpenCL runtime objects. + cl::Context cl_context{ cl_device }; + + // Check if the device supports the Khronos extensions needed before + // attempting to compile the kernel. + if (diag_opts.verbose) + { + std::cout << "Checking Khronos extensions support... "; + std::cout.flush(); + } + + for (const auto& extension : required_khronos_extensions) + { + if (!cl::util::supports_extension(cl_device, extension)) + { + std::cout << "OpenCL device does not support the required " + "Khronos extension " + << extension << std::endl; + exit(EXIT_SUCCESS); + } + } + + // Compile kernel. + if (diag_opts.verbose) + { + std::cout << " done.\nCompiling OpenCL kernel... "; + std::cout.flush(); + } + const char* kernel_location = "./external_saxpy.cl"; + std::ifstream kernel_stream{ kernel_location }; + if (!kernel_stream.is_open()) + throw std::runtime_error{ + std::string{ "Cannot open kernel source: " } + kernel_location + }; + cl::Program cl_program{ + cl_context, + std::string{ std::istreambuf_iterator{ kernel_stream }, + std::istreambuf_iterator{} } + }; + + // The Khronos extension showcased requires OpenCL 3.0 version. + cl::string compiler_options = ""; +#if CL_HPP_TARGET_OPENCL_VERSION >= 300 + compiler_options += cl::string{ "-cl-std=CL3.0 " }; +#else + sdt::cerr << "\nError: OpenCL version must be at least 3.0" + << std::endl; + exit(EXIT_FAILURE); +#endif + + cl_program.build(cl_device, compiler_options.c_str()); + + // Query maximum workgroup size (WGS) supported based on private mem + // (registers) constraints. + auto saxpy = cl::KernelFunctor( + cl_program, "saxpy"); + auto wgs = + saxpy.getKernel().getWorkGroupInfo( + cl_device); + + // Initialize host-side storage. + const auto length = saxpy_opts.length; + + // Random number generator. + auto prng = [engine = std::default_random_engine{}, + dist = std::uniform_real_distribution{ + -1.0, 1.0 }]() mutable { return dist(engine); }; + + // Initialize input and output vectors and constant. + std::vector arr_x(length), arr_y(length); + if (diag_opts.verbose) + { + std::cout << "Generating random scalar and " << length + << " random numbers for saxpy input vector." << std::endl; + } + cl_float a = prng(); + cl::sdk::fill_with_random(prng, arr_x, arr_y); + + // Check if the device supports the required OpenCL handle type. + if (diag_opts.verbose) + { + std::cout << "done.\nChecking OpenCL external memory handle type " + "support... "; + std::cout.flush(); + } + + if (!cl_check_external_memory_handle_type( + cl_device, cl_external_memory_handle_type)) + { + std::cerr + << "\nError: Unsupported OpenCL external memory handle type" + << std::endl; + exit(EXIT_FAILURE); + } + + if (!vk_check_external_memory_handle_type( + vk_physical_device, vk_external_memory_handle_type)) + { + std::cerr + << "\nError: Unsupported Vulkan external memory handle type" + << std::endl; + exit(EXIT_FAILURE); + } + + // Initialize Vulkan device-side storage. + if (diag_opts.verbose) + { + std::cout << "done.\nInitializing Vulkan device storage... "; + std::cout.flush(); + } + + // Create Vulkan (external) buffers and assign memory to them. + VkExternalMemoryBufferCreateInfo external_memory_buffer_info{}; + external_memory_buffer_info.sType = + VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO; + external_memory_buffer_info.handleTypes = + vk_external_memory_handle_type; + + VkBufferCreateInfo buffer_info{}; + buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + buffer_info.pNext = &external_memory_buffer_info; + buffer_info.size = sizeof(cl_float) * length; + buffer_info.usage = + VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; + ; + buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + + VkBuffer vk_buf_x, vk_buf_y; + VK_CHECK(vkCreateBuffer(vk_device, &buffer_info, nullptr, &vk_buf_x)); + VK_CHECK(vkCreateBuffer(vk_device, &buffer_info, nullptr, &vk_buf_y)); + + // Get requirements and necessary information for (exportable) memory. + VkMemoryRequirements mem_requirements_x{}, mem_requirements_y{}; + vkGetBufferMemoryRequirements(vk_device, vk_buf_x, &mem_requirements_x); + vkGetBufferMemoryRequirements(vk_device, vk_buf_y, &mem_requirements_y); + + VkExportMemoryAllocateInfo export_memory_alloc_info{}; + export_memory_alloc_info.sType = + VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO; + export_memory_alloc_info.handleTypes = vk_external_memory_handle_type; + + VkMemoryAllocateInfo memory_alloc_info_x{}; + memory_alloc_info_x.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_alloc_info_x.pNext = &export_memory_alloc_info; + memory_alloc_info_x.allocationSize = mem_requirements_x.size; + memory_alloc_info_x.memoryTypeIndex = find_vk_memory_type( + vk_physical_device, mem_requirements_x.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + + VkMemoryAllocateInfo memory_alloc_info_y{}; + memory_alloc_info_y.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + memory_alloc_info_y.pNext = &export_memory_alloc_info; + memory_alloc_info_y.allocationSize = mem_requirements_y.size; + memory_alloc_info_y.memoryTypeIndex = find_vk_memory_type( + vk_physical_device, mem_requirements_y.memoryTypeBits, + VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + + // Allocate and bind memory. + VkDeviceMemory vk_buf_x_memory, vk_buf_y_memory; + VK_CHECK(vkAllocateMemory(vk_device, &memory_alloc_info_x, nullptr, + &vk_buf_x_memory)); + VK_CHECK(vkAllocateMemory(vk_device, &memory_alloc_info_y, nullptr, + &vk_buf_y_memory)); + + VK_CHECK(vkBindBufferMemory(vk_device, vk_buf_x, vk_buf_x_memory, 0)); + VK_CHECK(vkBindBufferMemory(vk_device, vk_buf_y, vk_buf_y_memory, 0)); + + // Map memory. + void *vk_arr_x, *vk_arr_y; + VK_CHECK(vkMapMemory(vk_device, vk_buf_x_memory, 0, VK_WHOLE_SIZE, 0, + &vk_arr_x)); + VK_CHECK(vkMapMemory(vk_device, vk_buf_y_memory, 0, VK_WHOLE_SIZE, 0, + &vk_arr_y)); + + memcpy(vk_arr_x, arr_x.data(), sizeof(cl_float) * length); + memcpy(vk_arr_y, arr_y.data(), sizeof(cl_float) * length); + + // Get Vulkan external memory file descriptors for accessing external + // memory with OpenCL. + VkMemoryGetFdInfoKHR fd_info_x{}; + fd_info_x.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR; + fd_info_x.pNext = nullptr; + fd_info_x.memory = vk_buf_x_memory; + fd_info_x.handleType = vk_external_memory_handle_type; + int fd_x; + + VkMemoryGetFdInfoKHR fd_info_y{}; + fd_info_y.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR; + fd_info_y.pNext = nullptr; + fd_info_y.memory = vk_buf_y_memory; + fd_info_y.handleType = vk_external_memory_handle_type; + int fd_y; + + // We need to get the pointer to the vkGetMemoryFdKHR function because + // it's from extension VK_KHR_external_memory_fd. + PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR = + (PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(vk_device, + "vkGetMemoryFdKHR"); + + VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_x, &fd_x)); + VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_y, &fd_y)); + + // Create OpenCL buffers from Vulkan external memory file descriptors. + std::vector ext_mem_props_x = { + (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, + (cl_mem_properties)fd_x, + (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)cl_device(), + CL_DEVICE_HANDLE_LIST_END_KHR, + 0 + }; + std::vector ext_mem_props_y = { + (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, + (cl_mem_properties)fd_y, + (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)cl_device(), + CL_DEVICE_HANDLE_LIST_END_KHR, + 0 + }; + + cl::Buffer cl_buf_x{ cl_context, ext_mem_props_x, CL_MEM_READ_ONLY, + sizeof(cl_float) * length }; + cl::Buffer cl_buf_y{ cl_context, ext_mem_props_y, CL_MEM_READ_WRITE, + sizeof(cl_float) * length }; + + // Initialize queue for command execution. + cl_command_queue_properties queue_props[] = { CL_QUEUE_PROFILING_ENABLE, + 0 }; + cl::CommandQueue queue{ cl_context, cl_device, *queue_props }; + + // Launch kernel. + if (diag_opts.verbose) + { + std::cout << "done.\nExecuting on device... "; + std::cout.flush(); + } + + std::vector kernel_run; + auto dev_start = std::chrono::high_resolution_clock::now(); + kernel_run.push_back( + saxpy(cl::EnqueueArgs{ queue, cl::NDRange{ length }, wgs }, a, + cl_buf_x, cl_buf_y)); + cl::WaitForEvents(kernel_run); + auto dev_end = std::chrono::high_resolution_clock::now(); + + // Concurrently calculate reference saxpy. + if (diag_opts.verbose) + { + std::cout << "done.\nExecuting on host... "; + std::cout.flush(); + } + + auto host_start = std::chrono::high_resolution_clock::now(); + host_saxpy(arr_x, arr_y, a, length); + auto host_end = std::chrono::high_resolution_clock::now(); + + if (diag_opts.verbose) + { + std::cout << "done.\n"; + std::cout.flush(); + } + + // Fetch results. + cl::copy(queue, cl_buf_y, arr_x.begin(), arr_x.end()); + + // Validate solution. + if (std::equal(std::begin(arr_x), std::end(arr_x), std::begin(arr_y), + std::end(arr_y))) + std::cout << "Verification passed." << std::endl; + else + throw std::runtime_error{ "Verification failed!" }; + + if (!diag_opts.quiet) + { + std::cout << "Kernel execution time as seen by host: " + << std::chrono::duration_cast( + dev_end - dev_start) + .count() + << " us." << std::endl; + + std::cout << "Kernel execution time as measured by device: "; + std::cout << cl::util::get_duration( + kernel_run[0]) + .count() + << " us." << std::endl; + + std::cout << "Reference execution as seen by host: " + << std::chrono::duration_cast( + host_end - host_start) + .count() + << " us." << std::endl; + } + + // Release resources. + vkDestroyBuffer(vk_device, vk_buf_y, nullptr); + vkDestroyBuffer(vk_device, vk_buf_x, nullptr); + vkUnmapMemory(vk_device, vk_buf_y_memory); + vkUnmapMemory(vk_device, vk_buf_x_memory); + vkFreeMemory(vk_device, vk_buf_y_memory, nullptr); + vkFreeMemory(vk_device, vk_buf_x_memory, nullptr); + + } catch (cl::BuildError& e) + { + std::cerr << "OpenCL build error: " << e.what() << std::endl; + for (auto& build_log : e.getBuildLog()) + { + std::cerr << "\tBuild log for device: " + << build_log.first.getInfo() << "\n" + << std::endl; + std::cerr << build_log.second << "\n" << std::endl; + } + std::exit(e.err()); + } catch (cl::util::Error& e) + { + std::cerr << "OpenCL utils error: " << e.what() << std::endl; + std::exit(e.err()); + } catch (cl::Error& e) + { + std::cerr << "OpenCL runtime error: " << e.what() << std::endl; + std::exit(e.err()); + } catch (std::exception& e) + { + std::cerr << "Error: " << e.what() << std::endl; + std::exit(EXIT_FAILURE); + } + + return 0; +} diff --git a/samples/extensions/khr/externalmemory/vulkan_utils.h b/samples/extensions/khr/externalmemory/vulkan_utils.h new file mode 100644 index 00000000..2b718564 --- /dev/null +++ b/samples/extensions/khr/externalmemory/vulkan_utils.h @@ -0,0 +1,382 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _SAMPLES_CORE_EXTERNALMEMORY_UTILS_H +#define _SAMPLES_CORE_EXTERNALMEMORY_UTILS_H + +// OpenCL C headers includes. +#include + +// OpenCL Utils includes. +#include + +// Vulkan includes. +#include + +// Standard header includes. +#include +#include +#include +#include + +// Check if the provided Vulkan error code is \p VK_SUCCESS. If not, prints an +// error message to the standard error output and terminates the program with an +// error code. +#define VK_CHECK(condition) \ + { \ + const VkResult _error = condition; \ + if (_error != VK_SUCCESS) \ + { \ + fprintf(stderr, "A vulkan error encountered: %d at %s: %d\n", \ + _error, __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } \ + } + +// OpenCL device that is suitable for this example. +struct cl_device_candidate +{ + /// The OpenCL device id representing the device. + cl_device_id device; + + /// The Vulkan-compatible device UUID. + cl_uchar uuid[CL_UUID_SIZE_KHR]; +}; + +// OpenCL and Vulkan physical device suitable for the sample. +struct device_candidate +{ + /// The Vulkan physical device handle of the device to be used. + VkPhysicalDevice vk_candidate; + + /// The candidate device's Vulkan device properties. + VkPhysicalDeviceProperties vk_props; + + /// The OpenCL device candidate that this Vulkan device corresponds to. + struct cl_device_candidate cl_candidate; +}; + +// Check if the extensions supported by a Vulkan device includes a given set of +// required extensions. +bool extensions_supported( + const VkExtensionProperties* supported_extensions_properties, + const size_t supported_extensions_count, + const char* const* required_device_extensions, + const size_t required_device_extensions_count) +{ + for (size_t i = 0; i < required_device_extensions_count; ++i) + { + size_t j = 0; + while (strcmp(required_device_extensions[i], + supported_extensions_properties[j].extensionName) + && j < supported_extensions_count) + { + ++j; + } + if (j == supported_extensions_count) + { + return false; + } + } + return true; +} + +// Check if a given Vulkan device supports all the required Vulkan extensions. +bool check_device_extensions(const VkPhysicalDevice vk_device, + const char* const* required_device_extensions, + const size_t required_device_extensions_count) +{ + uint32_t supported_extensions_count; + VK_CHECK(vkEnumerateDeviceExtensionProperties( + vk_device, NULL, &supported_extensions_count, NULL)); + VkExtensionProperties* vk_supported_extensions_properties = + (VkExtensionProperties*)malloc(supported_extensions_count + * sizeof(VkExtensionProperties)); + VK_CHECK(vkEnumerateDeviceExtensionProperties( + vk_device, NULL, &supported_extensions_count, + vk_supported_extensions_properties)); + + bool result = extensions_supported( + vk_supported_extensions_properties, supported_extensions_count, + required_device_extensions, required_device_extensions_count); + + free(vk_supported_extensions_properties); + + return result; +} + +// Check if a given Vulkan physical device is compatible with any of the OpenCL +// devices available. +bool is_vk_device_suitable(const struct cl_device_candidate* cl_candidates, + const size_t cl_candidates_count, + VkPhysicalDevice vk_device, + struct device_candidate* candidate, + const char* const* required_device_extensions, + const size_t required_device_extensions_count) +{ + // Check if the device supports OpenCL by checking if there is any device + // with the same UUID. + { + // Query the Vulkan device UUID using vkGetPhysicalDeviceProperties2. + VkPhysicalDeviceIDPropertiesKHR id_props = { 0 }; + id_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR; + + VkPhysicalDeviceProperties2KHR props2 = { 0 }; + props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; + props2.pNext = &id_props; + + vkGetPhysicalDeviceProperties2(vk_device, &props2); + + // Look for an OpenCL device which UUID matches the UUID reported by + // Vulkan. + size_t compatible_dev_index = cl_candidates_count; + for (size_t i = 0; i < cl_candidates_count + && compatible_dev_index == cl_candidates_count; + ++i) + { + compatible_dev_index = i; + for (uint32_t j = 0; j < CL_UUID_SIZE_KHR; ++j) + { + if (cl_candidates[i].uuid[j] != id_props.deviceUUID[j]) + { + compatible_dev_index = cl_candidates_count; + break; + } + } + } + + if (compatible_dev_index == cl_candidates_count) + { + return false; + } + + candidate->vk_props = props2.properties; + candidate->cl_candidate = cl_candidates[compatible_dev_index]; + } + + // Check if the device supports the required extensions. + if (!check_device_extensions(vk_device, required_device_extensions, + required_device_extensions_count)) + { + return false; + } + + candidate->vk_candidate = vk_device; + return true; +} + +// Check if a given OpenCL device supports a particular set of Khronos +// extensions. +bool check_khronos_extensions( + const cl_device_id cl_device, + const char* const* const required_khronos_extensions, + const size_t required_khronos_extensions_count) +{ + cl_int error = CL_SUCCESS; + size_t supported_extensions_count; + OCLERROR_RET(clGetDeviceInfo(cl_device, CL_DEVICE_EXTENSIONS, 0, NULL, + &supported_extensions_count), + error, ret); + char* supported_extensions = + (char*)malloc(supported_extensions_count * sizeof(char)); + OCLERROR_RET(clGetDeviceInfo(cl_device, CL_DEVICE_EXTENSIONS, + supported_extensions_count, + supported_extensions, NULL), + error, err); + + for (size_t i = 0; i < required_khronos_extensions_count; ++i) + { + if (!strstr(supported_extensions, required_khronos_extensions[i])) + { + free(supported_extensions); + return false; + } + } + free(supported_extensions); + return true; +err: + free(supported_extensions); +ret: + return false; +} + +// Find a suitable device for the example, that is, an OpenCL +// device that is also Vulkan-compatible and that supports the required +// Vulkan device extensions. +struct device_candidate +find_suitable_device(VkInstance instance, + const char* const* required_device_extensions, + const size_t required_device_extensions_count) +{ + // Query OpenCL devices available. + cl_int error = CL_SUCCESS; + bool candidate_found = false; + cl_uint cl_platform_count = 0; + struct device_candidate found_candidate = {0}; + OCLERROR_RET(clGetPlatformIDs(0, NULL, &cl_platform_count), error, ret); + + cl_platform_id* platforms = + (cl_platform_id*)malloc(cl_platform_count * sizeof(cl_platform_id)); + OCLERROR_RET(clGetPlatformIDs(cl_platform_count, platforms, NULL), error, + platforms); + + size_t cl_device_count = 0; + const char* uuid_khronos_extension[] = { + CL_KHR_DEVICE_UUID_EXTENSION_NAME + }; + for (cl_uint cl_platform_id = 0; cl_platform_id < cl_platform_count; + ++cl_platform_id) + { + cl_uint cl_platform_devices_count = 0; + OCLERROR_RET(clGetDeviceIDs(platforms[cl_platform_id], + CL_DEVICE_TYPE_ALL, 0, NULL, + &cl_platform_devices_count), + error, platforms); + for (cl_uint device_id = 0; device_id < cl_platform_devices_count; + ++device_id) + { + cl_device_id device; + OCLERROR_PAR(device = cl_util_get_device( + cl_platform_id, device_id, CL_DEVICE_TYPE_ALL, &error), error, platforms); + cl_device_count += + check_khronos_extensions(device, uuid_khronos_extension, 1); + } + } + + // For each OpenCL device, query its Vulkan-compatible device UUID and + // add it to the list of candidates. The device must support the + // cl_khr_device_uuid extension for us to be able to query the device's + // UUID. + struct cl_device_candidate* cl_candidates = + (struct cl_device_candidate*)malloc( + cl_device_count * sizeof(struct cl_device_candidate)); + cl_device_count = 0; + for (cl_uint cl_platform_id = 0; cl_platform_id < cl_platform_count; + ++cl_platform_id) + { + cl_uint cl_platform_devices_count = 0; + OCLERROR_RET(clGetDeviceIDs(platforms[cl_platform_id], + CL_DEVICE_TYPE_ALL, 0, NULL, + &cl_platform_devices_count), + error, candidates); + + for (cl_uint cl_candidate_id = 0; + cl_candidate_id < cl_platform_devices_count; + ++cl_candidate_id, ++cl_device_count) + { + cl_device_id device = cl_util_get_device( + cl_platform_id, cl_candidate_id, CL_DEVICE_TYPE_ALL, &error); + if (check_khronos_extensions(device, uuid_khronos_extension, 1)) + { + cl_uchar vk_candidate_uuid[CL_UUID_SIZE_KHR]; + OCLERROR_RET(clGetDeviceInfo(device, CL_DEVICE_UUID_KHR, + CL_UUID_SIZE_KHR, + &vk_candidate_uuid, NULL), + error, candidates); + + struct cl_device_candidate candidate; + candidate.device = device; + memcpy(candidate.uuid, &vk_candidate_uuid, + sizeof(cl_uchar) * CL_UUID_SIZE_KHR); + cl_candidates[cl_device_count] = candidate; + } + } + } + + // Query the Vulkan physical devices available. + uint32_t vk_device_count; + VK_CHECK(vkEnumeratePhysicalDevices(instance, &vk_device_count, NULL)); + + VkPhysicalDevice* vk_devices = + (VkPhysicalDevice*)malloc(vk_device_count * sizeof(VkPhysicalDevice)); + VK_CHECK( + vkEnumeratePhysicalDevices(instance, &vk_device_count, vk_devices)); + + // Find a suitable Vulkan physical device compatible with one of the OpenCL + // devices available. + for (cl_uint vk_device_id = 0; vk_device_id < vk_device_count; + ++vk_device_id) + { + VkPhysicalDevice vk_device = vk_devices[vk_device_id]; + if (is_vk_device_suitable(cl_candidates, cl_device_count, vk_device, + &found_candidate, required_device_extensions, + required_device_extensions_count)) + { + candidate_found = true; + break; + } + } + if (!candidate_found) + { + printf("No suitable OpenCL Vulkan-compatible devices available\n"); + } + + free(vk_devices); +candidates: + free(cl_candidates); +platforms: + free(platforms); +ret: + if (candidate_found) + { + return found_candidate; + } + exit(error); +} + + +// Check if a given Vulkan device supports a particular external memory handle +// type. +bool vk_check_external_memory_handle_type( + VkPhysicalDevice vk_physical_device, + VkExternalMemoryHandleTypeFlagBits vk_external_memory_handle_type) +{ + VkPhysicalDeviceExternalBufferInfo physical_device_external_buffer_info = { + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO + }; + physical_device_external_buffer_info.handleType = + vk_external_memory_handle_type; + + VkExternalBufferProperties external_buffer_properties; + + vkGetPhysicalDeviceExternalBufferProperties( + vk_physical_device, &physical_device_external_buffer_info, + &external_buffer_properties); + + return (vk_external_memory_handle_type + & external_buffer_properties.externalMemoryProperties + .compatibleHandleTypes); +} + +// Find Vulkan memory properties from Vulkan physical device property flags. +uint32_t find_vk_memory_type(VkPhysicalDevice vk_device, uint32_t type_filter, + VkMemoryPropertyFlags properties) +{ + VkPhysicalDeviceMemoryProperties mem_properties; + vkGetPhysicalDeviceMemoryProperties(vk_device, &mem_properties); + for (uint32_t i = 0; i < mem_properties.memoryTypeCount; i++) + { + if ((type_filter & (1 << i)) + && (mem_properties.memoryTypes[i].propertyFlags & properties) + == properties) + { + return i; + } + } + return 0; +} + +#endif // _SAMPLES_CORE_EXTERNALMEMORY_UTILS_H diff --git a/samples/extensions/khr/externalmemory/vulkan_utils.hpp b/samples/extensions/khr/externalmemory/vulkan_utils.hpp new file mode 100644 index 00000000..90090dfd --- /dev/null +++ b/samples/extensions/khr/externalmemory/vulkan_utils.hpp @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _SAMPLES_CORE_EXTERNALMEMORY_UTILS_HPP +#define _SAMPLES_CORE_EXTERNALMEMORY_UTILS_HPP + +// OpenCL C++ headers includes. +#include + +// OpenCL Utils includes. +#include + +// Vulkan includes. +#include + +// Standard header includes. +#include +#include +#include +#include + +// Check if the provided Vulkan error code is \p VK_SUCCESS. If not, prints an +// error message to the standard error output and terminates the program with an +// error code. +#define VK_CHECK(condition) \ + { \ + const VkResult error = condition; \ + if (error != VK_SUCCESS) \ + { \ + std::cerr << "A vulkan error encountered: " << error << " at " \ + << __FILE__ << ':' << __LINE__ << std::endl; \ + std::exit(EXIT_FAILURE); \ + } \ + } + +// OpenCL device that is suitable for this example. +struct cl_device_candidate +{ + /// The OpenCL device id representing the device. + cl::Device device; + + /// The Vulkan-compatible device UUID. + cl_uchar uuid[CL_UUID_SIZE_KHR]; +}; + +// OpenCL and Vulkan physical device suitable for the sample. +struct device_candidate +{ + /// The Vulkan physical device handle of the device to be used. + VkPhysicalDevice vk_candidate; + + /// The candidate device's Vulkan device properties. + VkPhysicalDeviceProperties vk_props; + + /// The OpenCL device candidate that this Vulkan device corresponds to. + struct cl_device_candidate cl_candidate; +}; + +// Check if the extensions supported by a Vulkan device includes a given set of +// required extensions. +template +bool extensions_supported( + const std::vector supported_extensions_properties, + const IteratorT required_device_extensions_begin, + const IteratorT required_device_extensions_end) +{ + IteratorT it = required_device_extensions_begin; + for (; it != required_device_extensions_end; ++it) + { + const auto supported_it = + std::find_if(supported_extensions_properties.begin(), + supported_extensions_properties.end(), + [&](const VkExtensionProperties& props) { + return std::strcmp(*it, props.extensionName) == 0; + }); + if (supported_it == supported_extensions_properties.end()) + { + return false; + } + } + return true; +} + +// Check if a given Vulkan device supports all the required Vulkan extensions. +bool check_device_extensions( + const VkPhysicalDevice vk_device, + const std::vector required_device_extensions) +{ + uint32_t supported_extensions_count; + VK_CHECK(vkEnumerateDeviceExtensionProperties( + vk_device, nullptr, &supported_extensions_count, nullptr)); + std::vector vk_supported_extensions_properties( + supported_extensions_count); + VK_CHECK(vkEnumerateDeviceExtensionProperties( + vk_device, nullptr, &supported_extensions_count, + vk_supported_extensions_properties.data())); + + return extensions_supported(vk_supported_extensions_properties, + required_device_extensions.begin(), + required_device_extensions.end()); +} + +// Check if a given Vulkan physical device is compatible with any of the OpenCL +// devices available. +bool is_vk_device_suitable( + const std::vector cl_candidates, + VkPhysicalDevice vk_device, device_candidate& candidate, + const std::vector required_device_extensions) +{ + // Check if the device supports OpenCL by checking if there is any device + // with the same UUID. + { + // Query the Vulkan device UUID using vkGetPhysicalDeviceProperties2. + VkPhysicalDeviceIDPropertiesKHR id_props = {}; + id_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR; + + VkPhysicalDeviceProperties2KHR props2 = {}; + props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; + props2.pNext = &id_props; + + vkGetPhysicalDeviceProperties2(vk_device, &props2); + + // Look for an OpenCL device which UUID matches the UUID reported by + // Vulkan. + const auto cmp_device_uuid = + [&](const cl_device_candidate& cl_candidate) { + return std::equal(std::begin(cl_candidate.uuid), + std::end(cl_candidate.uuid), + std::begin(id_props.deviceUUID), + std::end(id_props.deviceUUID)); + }; + const auto it = std::find_if(cl_candidates.begin(), cl_candidates.end(), + cmp_device_uuid); + if (it == cl_candidates.end()) + { + // This device does not support HIP. + return false; + } + + candidate.vk_props = props2.properties; + candidate.cl_candidate = *it; + } + + // Check if the device supports the required extensions. + if (!check_device_extensions(vk_device, required_device_extensions)) + { + return false; + } + + candidate.vk_candidate = vk_device; + return true; +} + +// Find a suitable device for the example, that is, an OpenCL +// device that is also Vulkan-compatible and that supports the required +// Vulkan device extensions. +struct device_candidate +find_suitable_device(VkInstance instance, + std::vector required_device_extensions) +{ + // Query OpenCL devices available. + std::vector platforms; + cl::Platform::get(&platforms); + + // For each OpenCL device, query its Vulkan-compatible device UUID and + // add it to the list of candidates. + std::vector cl_candidates; + for (const auto& platform : platforms) + { + std::vector platform_devices; + platform.getDevices(CL_DEVICE_TYPE_ALL, &platform_devices); + + for (const auto& device : platform_devices) + { + if (cl::util::supports_extension(device, "cl_khr_device_uuid")) + { + cl_uchar vk_candidate_uuid[CL_UUID_SIZE_KHR]; + device.getInfo(CL_DEVICE_UUID_KHR, &vk_candidate_uuid); + + cl_device_candidate candidate; + candidate.device = device; + std::memcpy(candidate.uuid, &vk_candidate_uuid, + sizeof(cl_uchar) * CL_UUID_SIZE_KHR); + cl_candidates.push_back(candidate); + } + } + } + + // Query the Vulkan physical devices available. + uint32_t vk_device_count; + VK_CHECK(vkEnumeratePhysicalDevices(instance, &vk_device_count, nullptr)); + + std::vector vk_devices(vk_device_count); + VK_CHECK(vkEnumeratePhysicalDevices(instance, &vk_device_count, + vk_devices.data())); + + // Find a suitable Vulkan physical device compatible with one of the OpenCL + // devices available. + device_candidate candidate; + for (const auto vk_device : vk_devices) + { + if (is_vk_device_suitable(cl_candidates, vk_device, candidate, + required_device_extensions)) + { + return candidate; + } + } + + std::cout << "No suitable OpenCL Vulkan-compatible devices available" + << std::endl; + exit(EXIT_SUCCESS); +} + +// Check if a given OpenCL device supports a particular external memory handle +// type. +bool vk_check_external_memory_handle_type( + VkPhysicalDevice vk_physical_device, + VkExternalMemoryHandleTypeFlagBits vk_external_memory_handle_type) +{ + VkPhysicalDeviceExternalBufferInfo physical_device_external_buffer_info{}; + physical_device_external_buffer_info.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO; + physical_device_external_buffer_info.handleType = + vk_external_memory_handle_type; + + VkExternalBufferProperties external_buffer_properties; + + vkGetPhysicalDeviceExternalBufferProperties( + vk_physical_device, &physical_device_external_buffer_info, + &external_buffer_properties); + + return (vk_external_memory_handle_type + & external_buffer_properties.externalMemoryProperties + .compatibleHandleTypes); +} + +// Find Vulkan memory properties from Vulkan physical device property flags. +uint32_t find_vk_memory_type(VkPhysicalDevice vk_device, uint32_t type_filter, + VkMemoryPropertyFlags properties) +{ + VkPhysicalDeviceMemoryProperties mem_properties; + vkGetPhysicalDeviceMemoryProperties(vk_device, &mem_properties); + for (uint32_t i = 0; i < mem_properties.memoryTypeCount; i++) + { + if ((type_filter & (1 << i)) + && (mem_properties.memoryTypes[i].propertyFlags & properties) + == properties) + { + return i; + } + } + return 0; +} + +#endif // _SAMPLES_CORE_EXTERNALMEMORY_UTILS_HPP From 8b4f18b35d3b605abb594f6e7dc5d222d8b7aa7d Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Thu, 14 Dec 2023 10:44:15 +0000 Subject: [PATCH 43/46] Fixes from review --- CMakeLists.txt | 1 + cmake/Dependencies.cmake | 7 +- samples/extensions/khr/CMakeLists.txt | 4 +- samples/extensions/khr/externalmemory/main.c | 72 +++++++++++++++-- .../extensions/khr/externalmemory/main.cpp | 79 +++++++++++++++++-- .../khr/externalmemory/vulkan_utils.h | 24 +++--- 6 files changed, 160 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 686243d1..7264d983 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ include(CMakeDependentOption) option(OPENCL_SDK_BUILD_UTILITY_LIBRARIES "Build utility libraries" ON) cmake_dependent_option(OPENCL_SDK_BUILD_SAMPLES "Build sample code" ON OPENCL_SDK_BUILD_UTILITY_LIBRARIES OFF) cmake_dependent_option(OPENCL_SDK_BUILD_OPENGL_SAMPLES "Build OpenCL-OpenGL interop sample code" ON OPENCL_SDK_BUILD_SAMPLES OFF) +cmake_dependent_option(OPENCL_SDK_BUILD_VULKAN_SAMPLES "Build OpenCL-Vulkan interop sample code" ON OPENCL_SDK_BUILD_SAMPLES OFF) cmake_dependent_option(OPENCL_SDK_TEST_SAMPLES "Add CTest to samples (where applicable)" ON OPENCL_SDK_BUILD_SAMPLES OFF) option(OPENCL_SDK_BUILD_CLINFO "Build clinfo utility" ON) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 24383896..06145cb8 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -41,7 +41,7 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Global flag to cause add_library() to crea # Fetch dependencies if(OPENCL_SDK_BUILD_SAMPLES) - foreach(DEP IN ITEMS cargs TCLAP Stb Vulkan) + foreach(DEP IN ITEMS cargs TCLAP Stb) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/${DEP}") include(${DEP}) endforeach() @@ -52,6 +52,11 @@ if(OPENCL_SDK_BUILD_SAMPLES) include(${DEP}) endforeach() endif(OPENCL_SDK_BUILD_OPENGL_SAMPLES) + + if(OPENCL_SDK_BUILD_VULKAN_SAMPLES) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/Vulkan") + include(Vulkan) + endif(OPENCL_SDK_BUILD_VULKAN_SAMPLES) endif(OPENCL_SDK_BUILD_SAMPLES) if(OPENCL_SDK_BUILD_CLINFO) diff --git a/samples/extensions/khr/CMakeLists.txt b/samples/extensions/khr/CMakeLists.txt index 4bf194d7..efc6d747 100644 --- a/samples/extensions/khr/CMakeLists.txt +++ b/samples/extensions/khr/CMakeLists.txt @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -add_subdirectory(externalmemory) add_subdirectory(histogram) if(OPENCL_SDK_BUILD_OPENGL_SAMPLES) add_subdirectory(conway) add_subdirectory(nbody) endif() +if(OPENCL_SDK_BUILD_VULKAN_SAMPLES) + add_subdirectory(externalmemory) +endif() diff --git a/samples/extensions/khr/externalmemory/main.c b/samples/extensions/khr/externalmemory/main.c index c49ff2c6..b7698fc6 100644 --- a/samples/extensions/khr/externalmemory/main.c +++ b/samples/extensions/khr/externalmemory/main.c @@ -430,7 +430,6 @@ int main(int argc, char* argv[]) buffer_info.size = sizeof(cl_float) * length; buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; - ; buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VkBuffer vk_buf_x, vk_buf_y; @@ -485,6 +484,35 @@ int main(int argc, char* argv[]) memcpy(vk_arr_x, arr_x, sizeof(cl_float) * length); memcpy(vk_arr_y, arr_y, sizeof(cl_float) * length); +#ifdef _WIN32 + // Get Vulkan external memory file descriptors for accessing external memory + // with OpenCL. + VkMemoryGetWin32HandleInfoKHR handle_info_x = { 0 }; + handle_info_x.sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR; + handle_info_x.pNext = NULL; + handle_info_x.memory = vk_buf_x_memory; + handle_info_x.handleType = vk_external_memory_handle_type; + HANDLE handle_x; + + VkMemoryGetWin32HandleInfoKHR handle_info_y = { 0 }; + handle_info_y.sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR; + handle_info_y.pNext = NULL; + handle_info_y.memory = vk_buf_y_memory; + handle_info_y.handleType = vk_external_memory_handle_type; + HANDLE handle_y; + + // We need to get the pointer to the + // vkGetMemoryFdKHR/vkGetMemoryWin32HandleKHR function because it's from + // extension VK_KHR_external_memory_fd. This Vulkan function exports a POSIX + // file descriptor/Windows handle referencing the payload of a Vulkan device + // memory object. + PFN_vkGetMemoryWin32HandleKHR vkGetMemoryWin32Handle; + *(PFN_vkGetMemoryWin32HandleKHR*)&vkGetMemoryWin32Handle = + (PFN_vkGetMemoryWin32HandleKHR)vkGetDeviceProcAddr( + vk_device, "vkGetMemoryWin32HandleKHR"); + VK_CHECK(vkGetMemoryWin32Handle(vk_device, &handle_info_x, &handle_x)); + VK_CHECK(vkGetMemoryWin32Handle(vk_device, &handle_info_y, &handle_y)); +#else // Get Vulkan external memory file descriptors for accessing external memory // with OpenCL. VkMemoryGetFdInfoKHR fd_info_x = { 0 }; @@ -501,19 +529,28 @@ int main(int argc, char* argv[]) fd_info_y.handleType = vk_external_memory_handle_type; int fd_y; - // We need to get the pointer to the vkGetMemoryFdKHR function because it's - // from extension VK_KHR_external_memory_fd. - PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR = + // We need to get the pointer to the + // vkGetMemoryFdKHR/vkGetMemoryWin32HandleKHR function because it's from + // extension VK_KHR_external_memory_fd. This Vulkan function exports a POSIX + // file descriptor/Windows handle referencing the payload of a Vulkan device + // memory object. + PFN_vkGetMemoryFdKHR vkGetMemoryFd; + *(PFN_vkGetMemoryFdKHR*)&vkGetMemoryFd = (PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(vk_device, "vkGetMemoryFdKHR"); + VK_CHECK(vkGetMemoryFd(vk_device, &fd_info_x, &fd_x)); + VK_CHECK(vkGetMemoryFd(vk_device, &fd_info_y, &fd_y)); +#endif - VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_x, &fd_x)); - VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_y, &fd_y)); // Create OpenCL buffers from Vulkan external memory file descriptors. cl_mem_properties ext_mem_props_x[] = { (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, +#ifdef _WIN32 + (cl_mem_properties)handle_x, +#else (cl_mem_properties)fd_x, +#endif (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)(uintptr_t)cl_device, CL_DEVICE_HANDLE_LIST_END_KHR, @@ -521,7 +558,11 @@ int main(int argc, char* argv[]) }; cl_mem_properties ext_mem_props_y[] = { (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, +#ifdef _WIN32 + (cl_mem_properties)handle_y, +#else (cl_mem_properties)fd_y, +#endif (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)(uintptr_t)cl_device, CL_DEVICE_HANDLE_LIST_END_KHR, @@ -552,6 +593,16 @@ int main(int argc, char* argv[]) OCLERROR_RET(clSetKernelArg(saxpy, 2, sizeof(cl_mem), &cl_buf_y), error, clbufy); + // Acquire OpenCL memory objects created from Vulkan external memory + // handles. + cl_mem cl_mem_objects[] = { cl_buf_x, cl_buf_y }; + clEnqueueAcquireExternalMemObjectsKHR_fn + clEnqueueAcquireExternalMemObjects = + (clEnqueueAcquireExternalMemObjectsKHR_fn) + clGetExtensionFunctionAddressForPlatform( + cl_platform, "clEnqueueAcquireExternalMemObjectsKHR"); + clEnqueueAcquireExternalMemObjects(queue, 2, cl_mem_objects, 0, NULL, NULL); + // Launch kernel. if (diag_opts.verbose) { @@ -570,6 +621,15 @@ int main(int argc, char* argv[]) cl_ulong dev_time; TIMER_DIFFERENCE(dev_time, dev_start, dev_end) + // Release OpenCL memory objects created from Vulkan external memory + // handles. + clEnqueueReleaseExternalMemObjectsKHR_fn + clEnqueueReleaseExternalMemObjects = + (clEnqueueReleaseExternalMemObjectsKHR_fn) + clGetExtensionFunctionAddressForPlatform( + cl_platform, "clEnqueueReleaseExternalMemObjectsKHR"); + clEnqueueReleaseExternalMemObjects(queue, 2, cl_mem_objects, 0, NULL, NULL); + // Concurrently calculate reference saxpy. if (diag_opts.verbose) { diff --git a/samples/extensions/khr/externalmemory/main.cpp b/samples/extensions/khr/externalmemory/main.cpp index e4026c23..c82d8994 100644 --- a/samples/extensions/khr/externalmemory/main.cpp +++ b/samples/extensions/khr/externalmemory/main.cpp @@ -349,7 +349,6 @@ int main(int argc, char* argv[]) buffer_info.size = sizeof(cl_float) * length; buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; - ; buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; VkBuffer vk_buf_x, vk_buf_y; @@ -404,6 +403,37 @@ int main(int argc, char* argv[]) memcpy(vk_arr_x, arr_x.data(), sizeof(cl_float) * length); memcpy(vk_arr_y, arr_y.data(), sizeof(cl_float) * length); +#ifdef _WIN32 + // Get Vulkan external memory file descriptors for accessing external + // memory with OpenCL. + VkMemoryGetWin32HandleInfoKHR handle_info_x{}; + handle_info_x.sType = + VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR; + handle_info_x.pNext = nullptr; + handle_info_x.memory = vk_buf_x_memory; + handle_info_x.handleType = vk_external_memory_handle_type; + HANDLE handle_x; + + VkMemoryGetWin32HandleInfoKHR handle_info_y{}; + handle_info_y.sType = + VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR; + handle_info_y.pNext = nullptr; + handle_info_y.memory = vk_buf_y_memory; + handle_info_y.handleType = vk_external_memory_handle_type; + HANDLE handle_y; + + // We need to get the pointer to the + // vkGetMemoryFdKHR/vkGetMemoryWin32HandleKHR function because it's from + // the extension VK_KHR_external_memory_fd. This Vulkan function exports + // a POSIX file descriptor/Windows handle referencing the payload of a + // Vulkan device memory object. + PFN_vkGetMemoryWin32HandleKHR vkGetMemoryWin32Handle; + *(PFN_vkGetMemoryWin32HandleKHR*)&vkGetMemoryWin32Handle = + (PFN_vkGetMemoryWin32HandleKHR)vkGetDeviceProcAddr( + vk_device, "vkGetMemoryWin32HandleKHR"); + VK_CHECK(vkGetMemoryWin32Handle(vk_device, &handle_info_x, &handle_x)); + VK_CHECK(vkGetMemoryWin32Handle(vk_device, &handle_info_y, &handle_y)); +#else // Get Vulkan external memory file descriptors for accessing external // memory with OpenCL. VkMemoryGetFdInfoKHR fd_info_x{}; @@ -420,19 +450,27 @@ int main(int argc, char* argv[]) fd_info_y.handleType = vk_external_memory_handle_type; int fd_y; - // We need to get the pointer to the vkGetMemoryFdKHR function because - // it's from extension VK_KHR_external_memory_fd. - PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR = + // We need to get the pointer to the + // vkGetMemoryFdKHR/vkGetMemoryWin32HandleKHR function because it's from + // extension VK_KHR_external_memory_fd. This Vulkan function exports a + // POSIX file descriptor/Windows handle referencing the payload of a + // Vulkan device memory object. + PFN_vkGetMemoryFdKHR vkGetMemoryFd; + *(PFN_vkGetMemoryFdKHR*)&vkGetMemoryFd = (PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(vk_device, "vkGetMemoryFdKHR"); - - VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_x, &fd_x)); - VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_y, &fd_y)); + VK_CHECK(vkGetMemoryFd(vk_device, &fd_info_x, &fd_x)); + VK_CHECK(vkGetMemoryFd(vk_device, &fd_info_y, &fd_y)); +#endif // Create OpenCL buffers from Vulkan external memory file descriptors. std::vector ext_mem_props_x = { (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, +#ifdef _WIN32 + (cl_mem_properties)handle_x, +#else (cl_mem_properties)fd_x, +#endif (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)cl_device(), CL_DEVICE_HANDLE_LIST_END_KHR, @@ -440,7 +478,11 @@ int main(int argc, char* argv[]) }; std::vector ext_mem_props_y = { (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR, +#ifdef _WIN32 + (cl_mem_properties)handle_y, +#else (cl_mem_properties)fd_y, +#endif (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)cl_device(), CL_DEVICE_HANDLE_LIST_END_KHR, @@ -457,6 +499,18 @@ int main(int argc, char* argv[]) 0 }; cl::CommandQueue queue{ cl_context, cl_device, *queue_props }; + // Acquire OpenCL memory objects created from Vulkan external memory + // handles. + std::vector cl_mem_objects = { cl_buf_x(), cl_buf_y() }; + clEnqueueAcquireExternalMemObjectsKHR_fn + clEnqueueAcquireExternalMemObjects = + (clEnqueueAcquireExternalMemObjectsKHR_fn) + clGetExtensionFunctionAddressForPlatform( + cl_platform(), "clEnqueueAcquireExternalMemObjectsKHR"); + clEnqueueAcquireExternalMemObjects( + queue(), static_cast(cl_mem_objects.size()), + cl_mem_objects.data(), 0, nullptr, nullptr); + // Launch kernel. if (diag_opts.verbose) { @@ -472,6 +526,17 @@ int main(int argc, char* argv[]) cl::WaitForEvents(kernel_run); auto dev_end = std::chrono::high_resolution_clock::now(); + // Release OpenCL memory objects created from Vulkan external memory + // handles. + clEnqueueReleaseExternalMemObjectsKHR_fn + clEnqueueReleaseExternalMemObjects = + (clEnqueueReleaseExternalMemObjectsKHR_fn) + clGetExtensionFunctionAddressForPlatform( + cl_platform(), "clEnqueueReleaseExternalMemObjectsKHR"); + clEnqueueReleaseExternalMemObjects( + queue(), static_cast(cl_mem_objects.size()), + cl_mem_objects.data(), 0, nullptr, nullptr); + // Concurrently calculate reference saxpy. if (diag_opts.verbose) { diff --git a/samples/extensions/khr/externalmemory/vulkan_utils.h b/samples/extensions/khr/externalmemory/vulkan_utils.h index 2b718564..130bc45e 100644 --- a/samples/extensions/khr/externalmemory/vulkan_utils.h +++ b/samples/extensions/khr/externalmemory/vulkan_utils.h @@ -224,24 +224,24 @@ find_suitable_device(VkInstance instance, // Query OpenCL devices available. cl_int error = CL_SUCCESS; bool candidate_found = false; - cl_uint cl_platform_count = 0; + cl_uint platform_count = 0; struct device_candidate found_candidate = {0}; - OCLERROR_RET(clGetPlatformIDs(0, NULL, &cl_platform_count), error, ret); + OCLERROR_RET(clGetPlatformIDs(0, NULL, &platform_count), error, ret); cl_platform_id* platforms = - (cl_platform_id*)malloc(cl_platform_count * sizeof(cl_platform_id)); - OCLERROR_RET(clGetPlatformIDs(cl_platform_count, platforms, NULL), error, + (cl_platform_id*)malloc(platform_count * sizeof(cl_platform_id)); + OCLERROR_RET(clGetPlatformIDs(platform_count, platforms, NULL), error, platforms); size_t cl_device_count = 0; const char* uuid_khronos_extension[] = { CL_KHR_DEVICE_UUID_EXTENSION_NAME }; - for (cl_uint cl_platform_id = 0; cl_platform_id < cl_platform_count; - ++cl_platform_id) + for (cl_uint platform_id = 0; platform_id < platform_count; + ++platform_id) { cl_uint cl_platform_devices_count = 0; - OCLERROR_RET(clGetDeviceIDs(platforms[cl_platform_id], + OCLERROR_RET(clGetDeviceIDs(platforms[platform_id], CL_DEVICE_TYPE_ALL, 0, NULL, &cl_platform_devices_count), error, platforms); @@ -250,7 +250,7 @@ find_suitable_device(VkInstance instance, { cl_device_id device; OCLERROR_PAR(device = cl_util_get_device( - cl_platform_id, device_id, CL_DEVICE_TYPE_ALL, &error), error, platforms); + platform_id, device_id, CL_DEVICE_TYPE_ALL, &error), error, platforms); cl_device_count += check_khronos_extensions(device, uuid_khronos_extension, 1); } @@ -264,11 +264,11 @@ find_suitable_device(VkInstance instance, (struct cl_device_candidate*)malloc( cl_device_count * sizeof(struct cl_device_candidate)); cl_device_count = 0; - for (cl_uint cl_platform_id = 0; cl_platform_id < cl_platform_count; - ++cl_platform_id) + for (cl_uint platform_id = 0; platform_id < platform_count; + ++platform_id) { cl_uint cl_platform_devices_count = 0; - OCLERROR_RET(clGetDeviceIDs(platforms[cl_platform_id], + OCLERROR_RET(clGetDeviceIDs(platforms[platform_id], CL_DEVICE_TYPE_ALL, 0, NULL, &cl_platform_devices_count), error, candidates); @@ -278,7 +278,7 @@ find_suitable_device(VkInstance instance, ++cl_candidate_id, ++cl_device_count) { cl_device_id device = cl_util_get_device( - cl_platform_id, cl_candidate_id, CL_DEVICE_TYPE_ALL, &error); + platform_id, cl_candidate_id, CL_DEVICE_TYPE_ALL, &error); if (check_khronos_extensions(device, uuid_khronos_extension, 1)) { cl_uchar vk_candidate_uuid[CL_UUID_SIZE_KHR]; From a6f5c7b40234bcde074d3fd1ac4aa5e95124ce08 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Wed, 29 May 2024 10:45:54 +0200 Subject: [PATCH 44/46] Fix find_suitable_device logic to conditionally increment cl_device_count --- samples/extensions/khr/externalmemory/vulkan_utils.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/samples/extensions/khr/externalmemory/vulkan_utils.h b/samples/extensions/khr/externalmemory/vulkan_utils.h index 130bc45e..f2d82554 100644 --- a/samples/extensions/khr/externalmemory/vulkan_utils.h +++ b/samples/extensions/khr/externalmemory/vulkan_utils.h @@ -256,6 +256,12 @@ find_suitable_device(VkInstance instance, } } + if (!cl_device_count) + { + printf("No suitable OpenCL Vulkan-compatible devices available\n"); + goto platforms; + } + // For each OpenCL device, query its Vulkan-compatible device UUID and // add it to the list of candidates. The device must support the // cl_khr_device_uuid extension for us to be able to query the device's @@ -275,7 +281,7 @@ find_suitable_device(VkInstance instance, for (cl_uint cl_candidate_id = 0; cl_candidate_id < cl_platform_devices_count; - ++cl_candidate_id, ++cl_device_count) + ++cl_candidate_id) { cl_device_id device = cl_util_get_device( platform_id, cl_candidate_id, CL_DEVICE_TYPE_ALL, &error); @@ -292,6 +298,7 @@ find_suitable_device(VkInstance instance, memcpy(candidate.uuid, &vk_candidate_uuid, sizeof(cl_uchar) * CL_UUID_SIZE_KHR); cl_candidates[cl_device_count] = candidate; + cl_device_count++; } } } From 801c68777160912b97467621dd5d05e830b6d459 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Wed, 29 May 2024 11:23:22 +0200 Subject: [PATCH 45/46] Conform to OpenCL v3.0.15 specification release --- samples/extensions/khr/externalmemory/main.c | 8 ++++---- samples/extensions/khr/externalmemory/main.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/extensions/khr/externalmemory/main.c b/samples/extensions/khr/externalmemory/main.c index b7698fc6..f00b7036 100644 --- a/samples/extensions/khr/externalmemory/main.c +++ b/samples/extensions/khr/externalmemory/main.c @@ -551,9 +551,9 @@ int main(int argc, char* argv[]) #else (cl_mem_properties)fd_x, #endif - (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)(uintptr_t)cl_device, - CL_DEVICE_HANDLE_LIST_END_KHR, + CL_MEM_DEVICE_HANDLE_LIST_END_KHR, 0 }; cl_mem_properties ext_mem_props_y[] = { @@ -563,9 +563,9 @@ int main(int argc, char* argv[]) #else (cl_mem_properties)fd_y, #endif - (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)(uintptr_t)cl_device, - CL_DEVICE_HANDLE_LIST_END_KHR, + CL_MEM_DEVICE_HANDLE_LIST_END_KHR, 0 }; cl_mem cl_buf_x, cl_buf_y; diff --git a/samples/extensions/khr/externalmemory/main.cpp b/samples/extensions/khr/externalmemory/main.cpp index c82d8994..97b99a29 100644 --- a/samples/extensions/khr/externalmemory/main.cpp +++ b/samples/extensions/khr/externalmemory/main.cpp @@ -471,9 +471,9 @@ int main(int argc, char* argv[]) #else (cl_mem_properties)fd_x, #endif - (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)cl_device(), - CL_DEVICE_HANDLE_LIST_END_KHR, + CL_MEM_DEVICE_HANDLE_LIST_END_KHR, 0 }; std::vector ext_mem_props_y = { @@ -483,9 +483,9 @@ int main(int argc, char* argv[]) #else (cl_mem_properties)fd_y, #endif - (cl_mem_properties)CL_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR, (cl_mem_properties)cl_device(), - CL_DEVICE_HANDLE_LIST_END_KHR, + CL_MEM_DEVICE_HANDLE_LIST_END_KHR, 0 }; From 4bf7ad404e8b4711f4ea6482b621a7d38c545b98 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Wed, 5 Jun 2024 06:53:44 +0000 Subject: [PATCH 46/46] Fix kernel execution time report --- samples/extensions/khr/externalmemory/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/extensions/khr/externalmemory/main.c b/samples/extensions/khr/externalmemory/main.c index f00b7036..d0d3bd28 100644 --- a/samples/extensions/khr/externalmemory/main.c +++ b/samples/extensions/khr/externalmemory/main.c @@ -671,8 +671,7 @@ int main(int argc, char* argv[]) printf("Kernel execution time as seen by host: %llu us.\n", (unsigned long long)(dev_time + 500) / 1000); - printf("Kernel execution time as measured by device:\n"); - printf("\t%llu us.\n", + printf("Kernel execution time as measured by device: %llu us.\n", (unsigned long long)(cl_util_get_event_duration( kernel_run, CL_PROFILING_COMMAND_START, CL_PROFILING_COMMAND_END, &error)