### Add Examples Subdirectory Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Conditionally adds the 'examples' subdirectory to the build if the STDGPU_BUILD_EXAMPLES option is enabled. This allows building project examples. ```cmake if(STDGPU_BUILD_EXAMPLES) add_subdirectory(examples) endif() ``` -------------------------------- ### Install stdgpu using Provided Script Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/building_from_source.md Installs the locally compiled version of stdgpu using the provided installation script. This is an alternative to the direct CMake install command. ```sh bash tools/install.sh Release ``` -------------------------------- ### Configure and Install Dependencies File Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Configures and installs the stdgpu-dependencies.cmake file. ```cmake configure_file("${stdgpu_SOURCE_DIR}/cmake/stdgpu-dependencies.cmake.in" "${STDGPU_BUILD_CMAKE_DIR}/stdgpu-dependencies.cmake" @ONLY) install(FILES "${STDGPU_BUILD_CMAKE_DIR}/stdgpu-dependencies.cmake" DESTINATION "${STDGPU_CMAKE_INSTALL_DIR}" COMPONENT stdgpu) ``` -------------------------------- ### Setup Clang-Tidy Analysis Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes the Clang-Tidy setup script and configures the project for static analysis if the corresponding option is enabled. ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_clang_tidy.cmake") stdgpu_setup_clang_tidy(STDGPU_PROPERTY_CLANG_TIDY) ``` -------------------------------- ### Install Configuration Files Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Installs the generated stdgpu-config.cmake and stdgpu-config-version.cmake files to the installation directory. These files are needed for package management. ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/stdgpu-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/stdgpu-config-version.cmake" DESTINATION "${STDGPU_CMAKE_INSTALL_DIR}" COMPONENT stdgpu) ``` -------------------------------- ### Setup Cppcheck Analysis Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes the Cppcheck setup script and configures the project for static analysis if the corresponding option is enabled. ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_cppcheck.cmake") stdgpu_setup_cppcheck(STDGPU_PROPERTY_CPPCHECK) ``` -------------------------------- ### Install Sphinx Dependencies Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/documentation.md Installs the necessary Sphinx extensions for building documentation. Ensure you have Python and pip installed. ```sh pip install -r docs/requirements.txt ``` -------------------------------- ### Add Various HIP Examples Source: https://github.com/stotko/stdgpu/blob/master/examples/hip/CMakeLists.txt Demonstrates the usage of the `stdgpu_add_example_hip` macro to add several specific HIP examples to the project. Each call integrates a different example component. ```cmake stdgpu_add_example_hip(atomic) ``` ```cmake stdgpu_add_example_hip(bitset) ``` ```cmake stdgpu_add_example_hip(deque) ``` ```cmake stdgpu_add_example_hip(iterator) ``` ```cmake stdgpu_add_example_hip(mutex_array) ``` ```cmake stdgpu_add_example_hip(ranges) ``` ```cmake stdgpu_add_example_hip(unordered_map) ``` ```cmake stdgpu_add_example_hip(unordered_set) ``` ```cmake stdgpu_add_example_hip(vector) ``` -------------------------------- ### Setup Clang-Format Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes the Clang-Format setup script to format code according to project standards. An option is available to allow newer versions, though this may lead to rejected formatting. ```cmake option(STDGPU_ALLOW_NEWER_CLANG_FORMAT_VERSIONS "CAUTION: Allows finding newer versions of clang-format which may produce different results (WILL BE REJECTED), default: OFF" OFF) include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_clang_format.cmake") stdgpu_setup_clang_format() ``` -------------------------------- ### Add a C++ GPU Example Source: https://github.com/stotko/stdgpu/blob/master/examples/CMakeLists.txt A convenience macro that calls `stdgpu_detail_add_example` specifically for C++ examples, simplifying the process of adding new C++ GPU examples. ```cmake macro(stdgpu_add_example_cpp) stdgpu_detail_add_example(${ARGV0} "cpp") endmacro() ``` -------------------------------- ### Install Compiled stdgpu Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/building_from_source.md Installs the locally compiled version of stdgpu after building. Use this for a system-wide installation. ```sh cmake --install build --config Release ``` -------------------------------- ### Define Installation Paths Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Sets standard installation directories for libraries, binaries, headers, CMake modules, and documentation using variables from GNUInstallDirs. ```cmake include(GNUInstallDirs) set(STDGPU_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) set(STDGPU_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) set(STDGPU_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) set(STDGPU_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/stdgpu") set(STDGPU_DOC_INSTALL_DIR "${CMAKE_INSTALL_DOCDIR}/stdgpu") ``` -------------------------------- ### Install Findthrust.cmake Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Installs the Findthrust.cmake module to the installation directory. ```cmake install(FILES "${stdgpu_SOURCE_DIR}/cmake/Findthrust.cmake" DESTINATION "${STDGPU_CMAKE_INSTALL_DIR}" COMPONENT stdgpu) ``` -------------------------------- ### Add CUDA Examples using stdgpu_add_example_cu Source: https://github.com/stotko/stdgpu/blob/master/examples/cuda/CMakeLists.txt Demonstrates the usage of the stdgpu_add_example_cu macro to add various CUDA examples to the build system. ```cmake stdgpu_add_example_cu(atomic) stdgpu_add_example_cu(bitset) stdgpu_add_example_cu(deque) stdgpu_add_example_cu(iterator) stdgpu_add_example_cu(mutex_array) stdgpu_add_example_cu(ranges) stdgpu_add_example_cu(unordered_map) stdgpu_add_example_cu(unordered_set) stdgpu_add_example_cu(vector) ``` -------------------------------- ### Creating and Destroying Host and Device Objects Source: https://github.com/stotko/stdgpu/blob/master/docs/api/object.md Example demonstrating how to create and destroy both host and device objects using the `MyHostDeviceObjectClass` API. Ensure proper destruction to prevent memory leaks. ```cpp MyClass device_object = MyClass::createDeviceObject(1000); MyClass hoste_object = MyClass::createHostObject(1000); // Do something with device_object and host_object MyClass::destroyDeviceObject(device_object); MyClass::destroyHostObject(host_object); ``` -------------------------------- ### Configure Build with CMake (Direct Command) Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/building_from_source.md Create a build directory and configure the stdgpu build using CMake, specifying release mode and a local installation prefix. ```sh mkdir build cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=bin ``` -------------------------------- ### Define a GPU Example Executable Source: https://github.com/stotko/stdgpu/blob/master/examples/CMakeLists.txt Use this macro to define a new executable for a GPU example. It sets up necessary compile flags, link libraries, and target properties for both host and device code. ```cmake macro(stdgpu_detail_add_example) set(STDGPU_EXAMPLES_NAME "${ARGV0}") add_executable(${STDGPU_EXAMPLES_NAME} "${STDGPU_EXAMPLES_NAME}.${ARGV1}") target_compile_options(${STDGPU_EXAMPLES_NAME} PRIVATE ${STDGPU_DEVICE_FLAGS} ${STDGPU_HOST_FLAGS}) target_link_libraries(${STDGPU_EXAMPLES_NAME} PRIVATE stdgpu::stdgpu) target_compile_definitions(${STDGPU_EXAMPLES_NAME} PRIVATE $<$:NOMINMAX>) set_target_properties(${STDGPU_EXAMPLES_NAME} PROPERTIES CXX_CLANG_TIDY "${STDGPU_PROPERTY_CLANG_TIDY}") set_target_properties(${STDGPU_EXAMPLES_NAME} PROPERTIES CXX_CPPCHECK "${STDGPU_PROPERTY_CPPCHECK}") if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) set_target_properties(${STDGPU_EXAMPLES_NAME} PROPERTIES COMPILE_WARNING_AS_ERROR "${STDGPU_COMPILE_WARNING_AS_ERROR}") endif() endmacro() ``` -------------------------------- ### CMakeLists.txt for stdgpu Installation Source: https://github.com/stotko/stdgpu/blob/master/tests/install_test/CMakeLists.txt This snippet shows the essential CMake commands to find the stdgpu package and link it to your executable. Ensure stdgpu is installed in a location CMake can find. ```cmake cmake_minimum_required(VERSION 3.15) project(install_test LANGUAGES CXX) find_package(stdgpu REQUIRED) add_executable(install_test) target_sources(install_test PRIVATE install_test.cpp) target_link_libraries(install_test PRIVATE stdgpu::stdgpu) ``` -------------------------------- ### Find Pre-Installed stdgpu with CMake Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/integrating_into_your_project.md Use this snippet when stdgpu is already installed on your system. It finds the installed package and links your project against it. ```cmake find_package(stdgpu REQUIRED) add_library(your_project ...) # ... # Link your project against stdgpu target_link_libraries(your_project PUBLIC stdgpu::stdgpu) ``` -------------------------------- ### Define HIP Example Macro Source: https://github.com/stotko/stdgpu/blob/master/examples/hip/CMakeLists.txt Defines a CMake macro `stdgpu_add_example_hip` that calls a lower-level detail function to add a HIP example. This macro simplifies the process of adding new HIP examples. ```cmake macro(stdgpu_add_example_hip) stdgpu_detail_add_example(${ARGV0} "hip") endmacro() ``` -------------------------------- ### Setup Compiler Flags for Device and Host Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes scripts to set device-specific (CUDA/HIP) and host compiler flags. It also handles user-provided architecture flags and provides warnings for fallbacks. ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${STDGPU_BACKEND_DIRECTORY}/set_device_flags.cmake") stdgpu_set_device_flags(STDGPU_DEVICE_FLAGS) stdgpu_set_test_device_flags(STDGPU_TEST_DEVICE_FLAGS) message(STATUS "Created device flags : ${STDGPU_DEVICE_FLAGS}") message(STATUS "Created test device flags : ${STDGPU_TEST_DEVICE_FLAGS}") ``` ```cmake if(STDGPU_BACKEND STREQUAL STDGPU_BACKEND_CUDA) if(STDGPU_CUDA_ARCHITECTURE_FLAGS_USER) # CMAKE_CUDA_ARCHITECTURES already set by the user message(STATUS "Detected user-provided CCs : ${STDGPU_CUDA_ARCHITECTURE_FLAGS_USER}") else() stdgpu_cuda_set_architecture_flags(STDGPU_CUDA_ARCHITECTURE_FLAGS) if(STDGPU_CUDA_ARCHITECTURE_FLAGS) set(CMAKE_CUDA_ARCHITECTURES ${STDGPU_CUDA_ARCHITECTURE_FLAGS}) else() message(WARNING "Falling back to default CCs : ${CMAKE_CUDA_ARCHITECTURES}") endif() endif() # Workaround for bug in libstdc++ (see https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4442#note_737136) if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") message(STATUS "Building with disabled CXX extensions") set(CMAKE_CXX_EXTENSIONS OFF) endif() elseif(STDGPU_BACKEND STREQUAL STDGPU_BACKEND_HIP) if(STDGPU_HIP_ARCHITECTURE_FLAGS_USER) # CMAKE_HIP_ARCHITECTURES already set by the user message(STATUS "Detected user-provided CCs : ${STDGPU_HIP_ARCHITECTURE_FLAGS_USER}") else() # NOTE : Architectures could be detected via the "gcnArchName" property message(WARNING "Falling back to default CCs : ${CMAKE_HIP_ARCHITECTURES}") endif() endif() ``` ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/set_host_flags.cmake") stdgpu_set_host_flags(STDGPU_HOST_FLAGS) stdgpu_set_test_host_flags(STDGPU_TEST_HOST_FLAGS) message(STATUS "Created host flags : ${STDGPU_HOST_FLAGS}") message(STATUS "Created test host flags : ${STDGPU_TEST_HOST_FLAGS}") ``` -------------------------------- ### Install Backend Specific CMake File (if not HIP) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Installs a backend-specific CMake file for determining Thrust paths, unless the backend is HIP. ```cmake if(NOT STDGPU_BACKEND STREQUAL STDGPU_BACKEND_HIP) install(FILES "${stdgpu_SOURCE_DIR}/cmake/${STDGPU_BACKEND_DIRECTORY}/determine_thrust_paths.cmake" DESTINATION "${STDGPU_CMAKE_INSTALL_DIR}/${STDGPU_BACKEND_DIRECTORY}" COMPONENT stdgpu) endif() ``` -------------------------------- ### Install Target (CMake >= 3.23) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Installs the stdgpu target and its associated file sets for different configurations when using CMake 3.23 or later. ```cmake if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.23) install(TARGETS stdgpu EXPORT stdgpu-targets ARCHIVE DESTINATION "${STDGPU_LIB_INSTALL_DIR}" LIBRARY DESTINATION "${STDGPU_LIB_INSTALL_DIR}" FILE_SET stdgpu_headers DESTINATION "${STDGPU_INCLUDE_INSTALL_DIR}" FILE_SET stdgpu_header_implementations DESTINATION "${STDGPU_INCLUDE_INSTALL_DIR}" FILE_SET stdgpu_config_header DESTINATION "${STDGPU_INCLUDE_INSTALL_DIR}" FILE_SET stdgpu_backend_headers DESTINATION "${STDGPU_INCLUDE_INSTALL_DIR}" FILE_SET stdgpu_backend_header_implementations DESTINATION "${STDGPU_INCLUDE_INSTALL_DIR}" COMPONENT stdgpu) else() install(TARGETS stdgpu EXPORT stdgpu-targets DESTINATION "${STDGPU_LIB_INSTALL_DIR}" COMPONENT stdgpu) install(DIRECTORY "${STDGPU_INCLUDE_LOCAL_DIR}/" "${STDGPU_BUILD_INCLUDE_DIR}/" DESTINATION "${STDGPU_INCLUDE_INSTALL_DIR}" COMPONENT stdgpu FILES_MATCHING PATTERN "*.h" PATTERN "*.cuh") endif() ``` -------------------------------- ### STL Sort Example (C++98 and C++11) Source: https://github.com/stotko/stdgpu/blob/master/docs/api/iterator.md Demonstrates sorting a std::vector using both C++98 and C++11 begin/end iterator syntax. ```cpp #include #include #include std::vector vector(1000); // Fill it with something useful std::sort(vector.begin(), vector.end()); // C++98 std::sort(std::begin(vector), std::end(vector)); // C++11 ``` -------------------------------- ### Apply Code Style with Script Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/coding_style.md Use this script to reformat the code according to the project's style guide. This is a convenient way to ensure consistent formatting across the codebase. ```sh bash tools/dev/apply_code_style.sh ``` -------------------------------- ### STL Transform Example (C++14) Source: https://github.com/stotko/stdgpu/blob/master/docs/api/iterator.md Shows a C++14 example of transforming a std::vector using const iterators for input and regular iterators for output. ```cpp #include #include std::vector vector(1000); std::vector vector_out(1000); // Fill it with something useful std::transform(std::cbegin(vector), std::cend(vector), std::begin(vector_out), std::negate()); // C++14 ``` -------------------------------- ### Install Custom Thrust Find Module Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/hip/CMakeLists.txt Installs a custom CMake module for finding Thrust. This module is specific to the HIP backend and is placed in the appropriate installation directory. ```cmake install(FILES "${stdgpu_SOURCE_DIR}/cmake/${STDGPU_BACKEND_DIRECTORY}/Findthrust.cmake" DESTINATION "${STDGPU_CMAKE_INSTALL_DIR}/${STDGPU_BACKEND_DIRECTORY}" COMPONENT stdgpu) ``` -------------------------------- ### Install Exported Targets Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Installs exported targets and CMake files for the stdgpu library. Ensures targets are available for other projects using stdgpu. ```cmake install(EXPORT stdgpu-targets NAMESPACE stdgpu:: DESTINATION "${STDGPU_CMAKE_INSTALL_DIR}" COMPONENT stdgpu) ``` -------------------------------- ### Set Public Include Directories Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Configures the public include directories for the stdgpu target, allowing clients to access installed headers. ```cmake target_include_directories(stdgpu PUBLIC $) ``` -------------------------------- ### Setup Code Coverage Flags Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes the code coverage script and appends necessary compiler flags if both testing and coverage are enabled. Defines exclusions for coverage analysis. ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/code_coverage.cmake") append_coverage_compiler_flags() set(COVERAGE_EXCLUDES '*CMake*' '*build/*' '*benchmarks/*' '*examples/*' '*external/*' '*tests/*' '/usr/*') ``` -------------------------------- ### Basic C++ Class with Array Source: https://github.com/stotko/stdgpu/blob/master/docs/api/object.md A simple C++ class wrapping a float array. This example demonstrates basic constructor, destructor, and member function usage but lacks proper copy/move semantics and GPU compatibility. ```cpp class MyClass { public: MyClass() { this->array = nullptr; this->size = 0; } MyClass(const int size) { this->array = new float[size]; this->size = size; } ~MyClass() { delete[] array; size = 0; } void function(const int parameter) const { // Do something useful with array } private: float* array; int size; }; ``` -------------------------------- ### Add Uninstall Target Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes a CMake script to add an uninstall target. This allows users to uninstall the installed components using 'make uninstall' or equivalent. ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/add_uninstall_target.cmake") ``` -------------------------------- ### Define HIP Backend Header File Sets (CMake >= 3.23) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/hip/CMakeLists.txt Defines file sets for HIP backend headers and implementation headers when using CMake version 3.23 or greater. This helps in organizing and installing header files. ```cmake if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.23) target_sources(stdgpu PUBLIC FILE_SET stdgpu_backend_headers TYPE HEADERS BASE_DIRS ${STDGPU_INCLUDE_LOCAL_DIR} FILES atomic.h device.h memory.h platform.h platform_check.h) target_sources(stdgpu PUBLIC FILE_SET stdgpu_backend_header_implementations TYPE HEADERS BASE_DIRS ${STDGPU_INCLUDE_LOCAL_DIR} FILES impl/atomic_detail.h impl/error.h impl/memory_detail.h) endif() ``` -------------------------------- ### Create Host and Device Arrays Source: https://github.com/stotko/stdgpu/blob/master/docs/api/memory.md Use createDeviceArray and createHostArray to allocate and initialize memory on the GPU and CPU respectively. An optional fill value can be provided; otherwise, default construction is used. ```cpp #include float* device_float_vector = createDeviceArray(1000, 42.0f); float* host_float_vector = createHostArray(1000, 42.0f); ``` -------------------------------- ### Build Documentation with Script Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/documentation.md Builds the project documentation using a provided shell script. This is an alternative to the direct CMake command and also requires the STDGPU_BUILD_DOCUMENTATION option to be enabled. ```sh bash tools/dev/build_documentation.sh ``` -------------------------------- ### Configure Build with Script Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/building_from_source.md Use the provided script to configure the stdgpu build for CUDA in release mode. ```sh bash tools/backend/configure_cuda.sh Release ``` -------------------------------- ### Compile Options and Definitions Source: https://github.com/stotko/stdgpu/blob/master/tests/stdgpu/CMakeLists.txt Sets compile options and definitions for the test executable. Includes device and host flags, and a platform-specific definition for Windows. ```cmake target_compile_options(teststdgpu PRIVATE ${STDGPU_DEVICE_FLAGS} ${STDGPU_HOST_FLAGS} ${STDGPU_TEST_DEVICE_FLAGS} ${STDGPU_TEST_HOST_FLAGS}) target_compile_definitions(teststdgpu PRIVATE $<$:NOMINMAX>) ``` -------------------------------- ### Print Configuration Summary Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes a CMake script to print a summary of the project's configuration. This provides users with a quick overview of enabled features and build settings. ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_summary.cmake") stdgpu_print_configuration_summary() ``` -------------------------------- ### Build Documentation with CMake Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/documentation.md Builds the project documentation using CMake. This command requires the STDGPU_BUILD_DOCUMENTATION option to be enabled during the CMake configuration step. ```sh cmake --build build --target stdgpu_doc --parallel 8 ``` -------------------------------- ### Configure Output Directories Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Sets the runtime, library, and archive output directories to a 'bin' subdirectory within the build directory. ```cmake set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") ``` -------------------------------- ### Compile stdgpu (Provided Script) Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/building_from_source.md Use the provided script to compile the stdgpu library in release mode. ```sh bash tools/build.sh Release ``` -------------------------------- ### Declare and Download GoogleTest using FetchContent Source: https://github.com/stotko/stdgpu/blob/master/tests/CMakeLists.txt This snippet declares the GoogleTest dependency, specifying its URL, a SHA256 hash for integrity, and a download directory. It then makes the downloaded content available for use in the build. ```cmake include(FetchContent) FetchContent_Declare( googletest PREFIX googletest URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip URL_HASH SHA256=40d4ec942217dcc84a9ebe2a68584ada7d4a33a8ee958755763278ea1c5e18ff DOWNLOAD_DIR "${STDGPU_EXTERNAL_DIR}/googletest" ) set(BUILD_GMOCK OFF CACHE INTERNAL "") set(INSTALL_GTEST OFF CACHE INTERNAL "") FetchContent_MakeAvailable(googletest) ``` -------------------------------- ### Define Executable and Sources Source: https://github.com/stotko/stdgpu/blob/master/tests/stdgpu/CMakeLists.txt Defines the test executable and lists its source files. Ensure all necessary .cpp files are included. ```cmake add_executable(teststdgpu main.cpp) target_sources(teststdgpu PRIVATE algorithm.cpp bit.cpp contract.cpp functional.cpp iterator.cpp limits.cpp memory.cpp numeric.cpp ranges.cpp) target_sources(teststdgpu PRIVATE ../test_memory_utils.cpp) ``` -------------------------------- ### Include Backend and Directories Source: https://github.com/stotko/stdgpu/blob/master/tests/stdgpu/CMakeLists.txt Includes the stdgpu backend subdirectory and adds the parent directory for test utilities. This ensures the backend and test utilities are available during the build. ```cmake add_subdirectory(${STDGPU_BACKEND_DIRECTORY}) target_include_directories(teststdgpu PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") # test_utils ``` -------------------------------- ### Run Unit Tests with Provided Script Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/tests.md Execute unit tests using the provided 'run_tests.sh' script. This script simplifies the testing process by automating the necessary steps for the 'Release' configuration. ```sh bash tools/run_tests.sh Release ``` -------------------------------- ### Build stdgpu from Source (Modern CMake FetchContent) with CMake Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/integrating_into_your_project.md Use CMake's FetchContent module to download and build stdgpu directly from its Git repository. This is a convenient way to manage dependencies. ```cmake include(FetchContent) FetchContent_Declare( stdgpu GIT_REPOSITORY https://github.com/stotko/stdgpu.git GIT_TAG master ) # Exclude unneeded parts from the build set(STDGPU_BUILD_EXAMPLES OFF CACHE INTERNAL "") set(STDGPU_BUILD_BENCHMARKS OFF CACHE INTERNAL "") set(STDGPU_BUILD_TESTS OFF CACHE INTERNAL "") FetchContent_MakeAvailable(stdgpu) add_library(your_project ...) # ... # Link your project against stdgpu target_link_libraries(your_project PUBLIC stdgpu::stdgpu) ``` -------------------------------- ### Define stdgpu_add_example_cu Macro Source: https://github.com/stotko/stdgpu/blob/master/examples/cuda/CMakeLists.txt Defines the stdgpu_add_example_cu macro which acts as a wrapper for stdgpu_detail_add_example, specifying the CUDA language. ```cmake macro(stdgpu_add_example_cu) stdgpu_detail_add_example(${ARGV0} "cu") endmacro() ``` -------------------------------- ### Enable Testing and Add Tests Subdirectory Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Enables the testing framework and adds the 'tests' subdirectory to the build if STDGPU_BUILD_TESTS is enabled. This allows running project tests. ```cmake if(STDGPU_BUILD_TESTS) enable_testing() add_subdirectory(tests) if(STDGPU_BUILD_TEST_COVERAGE) setup_target_for_coverage(NAME stdgpu_coverage EXECUTABLE ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR} sh tools/run_tests.sh ${CMAKE_BUILD_TYPE} DEPENDENCIES teststdgpu) endif() endif() ``` -------------------------------- ### Check Code Style with Script Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/coding_style.md Execute this script to perform a coding style check. Ensure you are in the project's root directory. ```sh bash tools/dev/check_code_style.sh ``` -------------------------------- ### stdgpu Iterator API for Device Array Transform Source: https://github.com/stotko/stdgpu/blob/master/docs/api/iterator.md Demonstrates transforming a device array using stdgpu's device_cbegin, device_cend, and device_begin iterators, mirroring the C++14 STL transform. ```cpp #include #include #include #include float* device_array = createDeviceArray(1000); float* device_array_out = createDeviceArray(1000); // Fill it with something useful thrust::transform(stdgpu::device_cbegin(device_array), stdgpu::device_cend(device_array), stdgpu::device_begin(device_array_out), thrust::negate()); destroyDeviceArray(device_array); destroyDeviceArray(device_array_out); ``` -------------------------------- ### Include Backend Subdirectory Source: https://github.com/stotko/stdgpu/blob/master/benchmarks/stdgpu/CMakeLists.txt Adds the stdgpu backend directory as a sub-project, making its targets available. ```cmake add_subdirectory(${STDGPU_BACKEND_DIRECTORY}) ``` -------------------------------- ### Link Benchmark Libraries Source: https://github.com/stotko/stdgpu/blob/master/benchmarks/stdgpu/CMakeLists.txt Links the benchmark executable against the stdgpu library and the Google Benchmark library. ```cmake target_link_libraries(benchmarkstdgpu PRIVATE stdgpu::stdgpu benchmark::benchmark) ``` -------------------------------- ### stdgpu Iterator API for Device Array Sort Source: https://github.com/stotko/stdgpu/blob/master/docs/api/iterator.md Demonstrates sorting a device array using stdgpu's device_begin and device_end iterators, providing a cleaner syntax than raw pointers. ```cpp #include #include #include float* device_array = createDeviceArray(1000); // Fill it with something useful thrust::sort(stdgpu::device_begin(device_array), stdgpu::device_end(device_array)); destroyDeviceArray(device_array); ``` -------------------------------- ### Set Benchmark Include Directories Source: https://github.com/stotko/stdgpu/blob/master/benchmarks/stdgpu/CMakeLists.txt Specifies private include directories for the benchmark executable, including the parent directory. ```cmake target_include_directories(benchmarkstdgpu PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") ``` -------------------------------- ### Set Benchmark Compile Options Source: https://github.com/stotko/stdgpu/blob/master/benchmarks/stdgpu/CMakeLists.txt Applies various compile options to the benchmark executable, including device, host, and test-specific flags. ```cmake target_compile_options(benchmarkstdgpu PRIVATE ${STDGPU_DEVICE_FLAGS} ${STDGPU_HOST_FLAGS} ${STDGPU_TEST_DEVICE_FLAGS} ${STDGPU_TEST_HOST_FLAGS}) ``` -------------------------------- ### Add Blocks to Unordered Set (Agnostic Code) Source: https://github.com/stotko/stdgpu/blob/master/README.md Demonstrates how to add a range of updated blocks to a duplicate-free set using stdgpu's agnostic interface, suitable for data streaming. ```cpp #include #include #include class stream_set { public: void add_blocks(const short3* blocks, const stdgpu::index_t n) { set.insert(stdgpu::make_device(blocks), stdgpu::make_device(blocks + n)); } // Further functions private: stdgpu::unordered_set set; // Further members }; ``` -------------------------------- ### Copy Array from Device to Host Source: https://github.com/stotko/stdgpu/blob/master/docs/api/memory.md Copies a specified number of elements from a device array back to a host array. Ensure both arrays are pre-allocated. ```cpp #include float* host_float_vector; // Create this and set some values float* device_float_vector; // Create this copyDevice2HostArray(device_float_vector, 1000, host_float_vector); ``` -------------------------------- ### Apply Code Style with CMake Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/coding_style.md Run this command to automatically reformat the code to comply with the project's coding style. This command modifies files in place. ```sh cmake --build build --target apply_code_style ``` -------------------------------- ### Configure Package Configuration File Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Generates the stdgpu-config.cmake file using a template. This file is essential for other projects to find and use the stdgpu library. ```cmake include(CMakePackageConfigHelpers) configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/stdgpu-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/stdgpu-config.cmake" INSTALL_DESTINATION ${STDGPU_CMAKE_INSTALL_DIR} PATH_VARS STDGPU_INCLUDE_INSTALL_DIR) ``` -------------------------------- ### Define STDGPU Dependencies Backend Initialization Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/hip/CMakeLists.txt Sets a CMake variable to hold the dependency finding code for the HIP backend. This is used for initializing dependencies. ```cmake #set(STDGPU_DEPENDENCIES_BACKEND_INIT " #find_dependency(hip 7.1 REQUIRED) " PARENT_SCOPE) ``` -------------------------------- ### Link Libraries Source: https://github.com/stotko/stdgpu/blob/master/tests/stdgpu/CMakeLists.txt Links the test executable against the stdgpu library and Google Test. This makes the stdgpu functionality and testing framework available. ```cmake target_link_libraries(teststdgpu PRIVATE stdgpu::stdgpu GTest::gtest) ``` -------------------------------- ### Create and Copy Array from Host to Device Source: https://github.com/stotko/stdgpu/blob/master/docs/api/memory.md Allocates memory on the device and copies a specified number of elements from a host array to the newly allocated device array. This function unifies allocation and copying. ```cpp #include float* host_float_vector; // Create this and set some values float* device_float_vector = copyCreateHost2DeviceArray(host_float_vector, 1000); ``` -------------------------------- ### Run Unit Tests with CMake Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/tests.md Execute unit tests directly using the CMake command-line interface. This command changes the directory to 'build' and then runs 'ctest' with verbose output in the 'Release' configuration. ```sh cmake -E chdir build ctest -V -C Release ``` -------------------------------- ### Thrust Sort with Raw Device Pointers Source: https://github.com/stotko/stdgpu/blob/master/docs/api/iterator.md Illustrates sorting a raw device array using thrust::device_ptr, which requires explicit casting and size specification. ```cpp #include #include #include float* device_array = createDeviceArray(1000); // Fill it with something useful thrust::sort(thrust::device, thrust::device_pointer_cast(device_array), thrust::device_pointer_cast(device_array + 1000)); destroyDeviceArray(device_array); ``` -------------------------------- ### Copy Array from Host to Device Source: https://github.com/stotko/stdgpu/blob/master/docs/api/memory.md Copies a specified number of elements from a host array to a device array. Ensure both arrays are pre-allocated. ```cpp #include float* host_float_vector; // Create this and set some values float* device_float_vector; // Create this copyHost2DeviceArray(host_float_vector, 1000, device_float_vector); ``` -------------------------------- ### Host and Device Container Object Class Source: https://github.com/stotko/stdgpu/blob/master/docs/api/object.md A C++ class designed for both host and device memory management. It includes static factory methods for creation and destruction, and supports operations across host and device. ```cpp class MyHostDeviceObjectClass { public: MyHostDeviceObjectClass() { this->_array = nullptr; this->_size = 0; } [[nodiscard]] static MyHostDeviceObjectClass createDeviceObject(const int size) { MyHostDeviceObjectClass result; result._array = createDeviceArray(size); result._size = size; return result; } static void destroyDeviceObject(MyHostDeviceObjectClass& device_object) { destroyDeviceArray(device_object._array); device_object._size = 0; } [[nodiscard]] static MyHostDeviceObjectClass createHostObject(const int size) { MyHostDeviceObjectClass result; result._array = createHostArray(size); result._size = size; return result; } static void destroyHostObject(MyHostDeviceObjectClass& host_object) { destroyHostArray(host_object._array); host_object._size = 0; } void function(const int parameter) const { // Do something useful with array } private: float* _array; int _size; }; ``` -------------------------------- ### Compile stdgpu (Direct Command) Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/building_from_source.md Compile the stdgpu library and its components using CMake, specifying the build directory and parallel jobs for faster compilation. ```sh cmake --build build --config Release --parallel 8 ``` -------------------------------- ### Add Source Subdirectory Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Includes the 'src' subdirectory, which likely contains the main source code for the project. ```cmake add_subdirectory(src) ``` -------------------------------- ### Write Package Version File Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Creates the stdgpu-config-version.cmake file, which specifies the version of the stdgpu package. This is used by CMake's find_package command. ```cmake write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/stdgpu-config-version.cmake" VERSION ${stdgpu_VERSION} COMPATIBILITY SameMajorVersion) ``` -------------------------------- ### Define Benchmark Executable Source: https://github.com/stotko/stdgpu/blob/master/benchmarks/stdgpu/CMakeLists.txt Defines the main executable for the stdgpu benchmarks, linking the primary source file. ```cmake add_executable(benchmarkstdgpu main.cpp) ``` -------------------------------- ### Clone stdgpu Repository Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/building_from_source.md Download the source code for stdgpu from its official GitHub repository. ```sh git clone https://github.com/stotko/stdgpu ``` -------------------------------- ### Copying Objects Between Host and Device Source: https://github.com/stotko/stdgpu/blob/master/docs/api/object.md Illustrates copying an object from device memory to host memory using a dedicated copy function. This operation is crucial for data transfer between CPU and GPU. ```cpp MyClass device_object = MyClass::createDeviceObject(1000); // Do something with device_object MyClass host_object = MyClass::copyCreateDevice2HostObject(device_object); // Do something with host_object MyClass::destroyDeviceObject(device_object); MyClass::destroyHostObject(host_object); ``` -------------------------------- ### Set Target Properties for Static Analysis Source: https://github.com/stotko/stdgpu/blob/master/benchmarks/stdgpu/CMakeLists.txt Configures C++ static analysis tools (Clang-Tidy and Cppcheck) for the benchmark executable. ```cmake set_target_properties(benchmarkstdgpu PROPERTIES CXX_CLANG_TIDY "${STDGPU_PROPERTY_CLANG_TIDY}") set_target_properties(benchmarkstdgpu PROPERTIES CXX_CPPCHECK "${STDGPU_PROPERTY_CPPCHECK}") ``` -------------------------------- ### Check Code Style with CMake Source: https://github.com/stotko/stdgpu/blob/master/docs/development/contributing/coding_style.md Use this command to verify if the code adheres to the project's coding style standards. This is typically run as part of the CI process. ```sh cmake --build build --target check_code_style ``` -------------------------------- ### Add Documentation Subdirectory Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Conditionally adds the 'docs' subdirectory to the build if the STDGPU_BUILD_DOCUMENTATION option is enabled. This allows building project documentation. ```cmake if(STDGPU_BUILD_DOCUMENTATION) add_subdirectory(docs) endif() ``` -------------------------------- ### Define Device Headers for Compilation Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Lists the header files that must be compiled by the device compiler. ```cmake set(STDGPU_DEVICE_HEADERS atomic.cuh bitset.cuh deque.cuh mutex.cuh queue.cuh stack.cuh unordered_map.cuh unordered_set.cuh vector.cuh) ``` -------------------------------- ### stdgpu Citation (BibTeX) Source: https://github.com/stotko/stdgpu/blob/master/README.md BibTeX entry for the stdgpu publication. Use this when citing the stdgpu project in academic work. ```bibtex @UNPUBLISHED{stotko2019stdgpu, author = {Stotko, P.}, title = {{stdgpu: Efficient STL-like Data Structures on the GPU}}, year = {2019}, month = aug, note = {arXiv:1908.05936}, url = {https://arxiv.org/abs/1908.05936} } ``` -------------------------------- ### Add CUDA Backend Source Files Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/cuda/CMakeLists.txt Specifies the C++ source files for the CUDA backend implementation. ```cmake target_sources(stdgpu PRIVATE impl/device.cpp impl/memory.cpp) ``` -------------------------------- ### Build stdgpu from Source (git submodule) with CMake Source: https://github.com/stotko/stdgpu/blob/master/docs/getting_started/integrating_into_your_project.md Integrate stdgpu as a git submodule and build it alongside your project. This method allows for customization of the stdgpu build. ```cmake # Exclude unneeded parts from the build set(STDGPU_BUILD_EXAMPLES OFF CACHE INTERNAL "") set(STDGPU_BUILD_BENCHMARKS OFF CACHE INTERNAL "") set(STDGPU_BUILD_TESTS OFF CACHE INTERNAL "") add_subdirectory(stdgpu) add_library(your_project ...) # ... # Link your project against stdgpu target_link_libraries(your_project PUBLIC stdgpu::stdgpu) ``` -------------------------------- ### Define STDGPU Dependencies Initialization Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/openmp/CMakeLists.txt Sets a variable to hold the dependency initialization string for OpenMP. This is used to manage dependencies across different parts of the build system. ```cmake set(STDGPU_DEPENDENCIES_BACKEND_INIT " find_dependency(OpenMP 2.0 REQUIRED) " PARENT_SCOPE) ``` -------------------------------- ### Define CUDA Backend Header File Sets (CMake >= 3.23) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/cuda/CMakeLists.txt Organizes CUDA backend header files into distinct sets for better management in newer CMake versions. ```cmake target_sources(stdgpu PUBLIC FILE_SET stdgpu_backend_headers TYPE HEADERS BASE_DIRS ${STDGPU_INCLUDE_LOCAL_DIR} FILES atomic.cuh device.h memory.h platform.h platform_check.h) target_sources(stdgpu PUBLIC FILE_SET stdgpu_backend_header_implementations TYPE HEADERS BASE_DIRS ${STDGPU_INCLUDE_LOCAL_DIR} FILES impl/atomic_detail.cuh impl/error.h impl/memory_detail.h) ``` -------------------------------- ### Create Alias Target Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Creates an alias target stdgpu::stdgpu for the stdgpu library. ```cmake add_library(stdgpu::stdgpu ALIAS stdgpu) ``` -------------------------------- ### Set Source File Properties for Device Headers (CUDA) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Specifies the CUDA language for the device header files when the STDGPU_BACKEND is set to CUDA. ```cmake if(STDGPU_BACKEND STREQUAL STDGPU_BACKEND_CUDA) set_source_files_properties(${STDGPU_DEVICE_HEADERS} PROPERTIES LANGUAGE CUDA) ``` -------------------------------- ### Link Public Library Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Links the stdgpu target with the thrust::thrust public library. ```cmake target_link_libraries(stdgpu PUBLIC thrust::thrust) ``` -------------------------------- ### Set Source File Properties for Device Headers (HIP) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Specifies the HIP language for the device header files when the STDGPU_BACKEND is set to HIP. ```cmake elseif(STDGPU_BACKEND STREQUAL STDGPU_BACKEND_HIP) set_source_files_properties(${STDGPU_DEVICE_HEADERS} PROPERTIES LANGUAGE HIP) endif() ``` -------------------------------- ### Set Private Compile Options Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Applies device and host specific compile options to the stdgpu target. ```cmake target_compile_options(stdgpu PRIVATE ${STDGPU_DEVICE_FLAGS} ${STDGPU_HOST_FLAGS}) ``` -------------------------------- ### Add CMake Module Paths Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Appends backend-specific and generic CMake module paths to the CMAKE_MODULE_PATH. This ensures that backend modules are prioritized over generic ones. ```cmake list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/${STDGPU_BACKEND_DIRECTORY}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") ``` -------------------------------- ### Set Interface Header Sets to Verify (CMake >= 3.24) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Enables the verification of interface header sets for the stdgpu target when using CMake version 3.24 or later. ```cmake set_target_properties(stdgpu PROPERTIES INTERFACE_HEADER_SETS_TO_VERIFY stdgpu_headers) ``` -------------------------------- ### Compute Update Set in CUDA Kernel (Native Code) Source: https://github.com/stotko/stdgpu/blob/master/README.md Illustrates a custom CUDA kernel using stdgpu's native backend to compute a duplicate-free set of updated blocks for 3D scene reconstruction. ```cuda #include #include #include __global__ void compute_update_set(const short3* blocks, const stdgpu::index_t n, const stdgpu::unordered_map tsdf_block_map, stdgpu::unordered_set mc_update_set) { // Global thread index stdgpu::index_t i = blockIdx.x * blockDim.x + threadIdx.x; if (i >= n) return; short3 b_i = blocks[i]; // Neighboring candidate blocks for the update short3 mc_blocks[8] = { short3(b_i.x - 0, b_i.y - 0, b_i.z - 0), short3(b_i.x - 1, b_i.y - 0, b_i.z - 0), short3(b_i.x - 0, b_i.y - 1, b_i.z - 0), short3(b_i.x - 0, b_i.y - 0, b_i.z - 1), short3(b_i.x - 1, b_i.y - 1, b_i.z - 0), short3(b_i.x - 1, b_i.y - 0, b_i.z - 1), short3(b_i.x - 0, b_i.y - 1, b_i.z - 1), short3(b_i.x - 1, b_i.y - 1, b_i.z - 1), }; for (stdgpu::index_t j = 0; j < 8; ++j) { // Only consider existing neighbors if (tsdf_block_map.contains(mc_blocks[j])) { mc_update_set.insert(mc_blocks[j]); } } } ``` -------------------------------- ### Find HIP Package Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/hip/CMakeLists.txt Finds the HIP package with a minimum version of 7.1. This is a prerequisite for using HIP-accelerated features. ```cmake #find_package(hip 7.1 REQUIRED) ``` -------------------------------- ### Set C++ Standard Feature Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Enables C++17 standard features for the stdgpu target. ```cmake target_compile_features(stdgpu PUBLIC cxx_std_17) ``` -------------------------------- ### Set Benchmark Compile Definitions Source: https://github.com/stotko/stdgpu/blob/master/benchmarks/stdgpu/CMakeLists.txt Adds compile definitions to the benchmark executable, conditionally defining NOMINMAX on Windows. ```cmake target_compile_definitions(benchmarkstdgpu PRIVATE $<$:NOMINMAX>) ``` -------------------------------- ### Add Benchmarks Subdirectory Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Conditionally adds the 'benchmarks' subdirectory to the build if the STDGPU_BUILD_BENCHMARKS option is enabled. This allows building project benchmarks. ```cmake if(STDGPU_BUILD_BENCHMARKS) add_subdirectory(benchmarks) endif() ``` -------------------------------- ### Create and Copy with Disabled Checks Source: https://github.com/stotko/stdgpu/blob/master/docs/api/memory.md Allocates device memory and copies data from a host pointer, with memory checks disabled. Use this when dealing with external arrays or stack pointers, and ensure the operation's success manually. ```cpp #include float host_value = 42.0f; float* device_value_pointer = copyCreateHost2DeviceArray(&host_value, 1, MemoryCopy::NO_CHECK); ``` -------------------------------- ### Set Private Compile Definitions for Windows Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/CMakeLists.txt Defines NOMINMAX for Windows platforms to prevent macro conflicts. ```cmake target_compile_definitions(stdgpu PRIVATE $<$:NOMINMAX>) ``` -------------------------------- ### Thrust Device Vector Sort Source: https://github.com/stotko/stdgpu/blob/master/docs/api/iterator.md Shows how to sort a thrust::device_vector, similar to STL vector sorting. ```cpp #include #include thrust::device_vector device_vector(1000); // Fill it with something useful thrust::sort(thrust::device, vector.begin(), vector.end()); ``` -------------------------------- ### SLAMCast Citation (BibTeX) Source: https://github.com/stotko/stdgpu/blob/master/README.md BibTeX entry for the SLAMCast publication. Use this when citing the SLAMCast project in academic work. ```bibtex @article{stotko2019slamcast, author = {Stotko, P. and Krumpen, S. and Hullin, M. B. and Weinmann, M. and Klein, R.}, title = {{SLAMCast: Large-Scale, Real-Time 3D Reconstruction and Streaming for Immersive Multi-Client Live Telepresence}}, journal = {IEEE Transactions on Visualization and Computer Graphics}, volume = {25}, number = {5}, pages = {2102--2112}, year = {2019}, month = may } ``` -------------------------------- ### Define HIP Thrust Device System Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/hip/CMakeLists.txt Sets a compile definition to specify that Thrust should use the HIP device system. This is crucial for Thrust to correctly interact with HIP. ```cmake target_compile_definitions(stdgpu PUBLIC THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP) ``` -------------------------------- ### Destroy Host and Device Arrays Source: https://github.com/stotko/stdgpu/blob/master/docs/api/memory.md Free allocated host and device memory using destroyDeviceArray and destroyHostArray. These functions prevent double-free errors by nullifying the pointer after deallocation and checking for null pointers. ```cpp #include // Define device_float_vector and host_float_vector destroyDeviceArray(device_float_vector); destroyHostArray(host_float_vector); ``` -------------------------------- ### Add Test Source: https://github.com/stotko/stdgpu/blob/master/tests/stdgpu/CMakeLists.txt Defines a CTest test named 'teststdgpu' that executes the compiled test program. This allows the test to be run using the CTest testing framework. ```cmake add_test(NAME teststdgpu COMMAND teststdgpu) ``` -------------------------------- ### Define Public Header File Sets (CMake >= 3.23) Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/openmp/CMakeLists.txt For CMake version 3.23 and above, this defines public header file sets for the stdgpu target. It separates general headers from implementation details. ```cmake target_sources(stdgpu PUBLIC FILE_SET stdgpu_backend_headers TYPE HEADERS BASE_DIRS ${STDGPU_INCLUDE_LOCAL_DIR} FILES atomic.h device.h memory.h platform.h platform_check.h) target_sources(stdgpu PUBLIC FILE_SET stdgpu_backend_header_implementations TYPE HEADERS BASE_DIRS ${STDGPU_INCLUDE_LOCAL_DIR} FILES impl/atomic_detail.h impl/memory_detail.h) ``` -------------------------------- ### Find CUDA Toolkit Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/cuda/CMakeLists.txt Locates the CUDA Toolkit, essential for CUDA development. Requires version 11.5 or higher. ```cmake find_package(CUDAToolkit 11.5 REQUIRED MODULE) ``` -------------------------------- ### Set Target Properties Source: https://github.com/stotko/stdgpu/blob/master/tests/stdgpu/CMakeLists.txt Configures properties for the test executable, including static analysis tools and compiler warnings. The COMPILE_WARNING_AS_ERROR property is conditionally set for CMake version 3.24 and above. ```cmake set_target_properties(teststdgpu PROPERTIES CXX_CLANG_TIDY "${STDGPU_PROPERTY_CLANG_TIDY}") set_target_properties(teststdgpu PROPERTIES CXX_CPPCHECK "${STDGPU_PROPERTY_CPPCHECK}") if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) set_target_properties(teststdgpu PROPERTIES COMPILE_WARNING_AS_ERROR "${STDGPU_COMPILE_WARNING_AS_ERROR}") endif() ``` -------------------------------- ### Link OpenMP Library Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/openmp/CMakeLists.txt Links the stdgpu target against the OpenMP C++ library. This ensures that OpenMP functionalities are available at link time. ```cmake target_link_libraries(stdgpu PUBLIC OpenMP::OpenMP_CXX) ``` -------------------------------- ### Set External Dependencies Directory Source: https://github.com/stotko/stdgpu/blob/master/CMakeLists.txt Defines the directory for external project dependencies, located within the source tree. ```cmake set(STDGPU_EXTERNAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external") ``` -------------------------------- ### Set OpenMP Compile Definition Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/openmp/CMakeLists.txt Adds a public compile definition to the stdgpu target, specifying the Thrust device system as OpenMP. This is crucial for enabling OpenMP support. ```cmake target_compile_definitions(stdgpu PUBLIC THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_OMP) ``` -------------------------------- ### Add Project Subdirectory Source: https://github.com/stotko/stdgpu/blob/master/tests/CMakeLists.txt This command adds the 'stdgpu' subdirectory to the current CMake build. This is typically used to include other CMakeLists.txt files that define targets and configurations for different parts of the project. ```cmake add_subdirectory(stdgpu) ``` -------------------------------- ### Set HIP Compile Features Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/hip/CMakeLists.txt Enables C++17 standard features for the HIP backend. This ensures compatibility with C++17 constructs used in the HIP code. ```cmake target_compile_features(stdgpu PUBLIC hip_std_17) ``` -------------------------------- ### Link CUDA Runtime Library Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/cuda/CMakeLists.txt Links the appropriate CUDA runtime library based on whether shared or static libraries are being built. ```cmake if(STDGPU_BUILD_SHARED_LIBS) target_link_libraries(stdgpu PUBLIC CUDA::cudart) else() target_link_libraries(stdgpu PUBLIC CUDA::cudart_static) endif() ``` -------------------------------- ### Set CUDA Dependency Initialization Source: https://github.com/stotko/stdgpu/blob/master/src/stdgpu/cuda/CMakeLists.txt Defines a variable to hold the find_dependency call for CUDA, useful for managing dependencies. ```cmake set(STDGPU_DEPENDENCIES_BACKEND_INIT " find_dependency(CUDAToolkit 11.5 REQUIRED MODULE) " PARENT_SCOPE) ```