diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 95d4009f..01731549 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 f8d3e57f..35e1fea8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,8 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_CXX_STANDARD 14) project(OpenCL-SDK - VERSION 2023.04.17 + # ToDo + VERSION 2023.02.07 LANGUAGES C CXX ) @@ -28,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 b8682963..db36ed67 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() @@ -701,10 +708,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 4ac52cbd..5cf20c11 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;