Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to configure and build without graphics #8

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: clang-format
uses: jidicula/clang-format-action@v4.11.0
Expand Down Expand Up @@ -101,9 +101,31 @@ jobs:
cmake -B ${{github.workspace}}/build
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DCMAKE_CXX_COMPILER=clang++
-DENABLE_GRAPHICS=ON
-DENABLE_SPIR=ON -DENABLE_CUDA=OFF -DENABLE_HIP=OFF
-DCMAKE_CXX_FLAGS='-Wall -Wextra -Wpedantic -Werror'
-G Ninja

- name: Build
run: cmake --build ${{github.workspace}}/build -- -k 0

cmake-build-nographics:
runs-on: ubuntu-latest
container:
image: intel/oneapi-basekit:latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure CMake (no graphics)
run: >
cmake -B ${{github.workspace}}/build
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-DCMAKE_CXX_COMPILER=icpx
-DENABLE_GRAPHICS=OFF
-DENABLE_SPIR=ON -DENABLE_CUDA=OFF -DENABLE_HIP=OFF
-DCMAKE_CXX_FLAGS='-Wall -Wextra -Wpedantic -Werror'

- name: Build (no graphics)
run: cmake --build ${{github.workspace}}/build -- -k -j
25 changes: 7 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,18 @@ project(SYCL-samples)
set(CMAKE_CXX_STANDARD 17)

# Configure Magnum
list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/modules/magnum-bootstrap/modules"
"${PROJECT_SOURCE_DIR}/modules/magnum-integration/modules")
set(MAGNUM_WITH_SDL2APPLICATION ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_ANYIMAGEIMPORTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_STBIMAGEIMPORTER ON CACHE BOOL "" FORCE)
set(IMGUI_DIR ${PROJECT_SOURCE_DIR}/modules/imgui)
set(MAGNUM_WITH_IMGUI ON CACHE BOOL "" FORCE)
add_subdirectory(modules/corrade EXCLUDE_FROM_ALL)
add_subdirectory(modules/magnum EXCLUDE_FROM_ALL)
add_subdirectory(modules/magnum-plugins EXCLUDE_FROM_ALL)
add_subdirectory(modules/magnum-integration EXCLUDE_FROM_ALL)
find_package(Magnum REQUIRED GL Sdl2Application Shaders Primitives Trade)
find_package(MagnumIntegration REQUIRED ImGui)
include(cmake/ConfigureMagnum.cmake)

# Configure SYCL
include(cmake/ConfigureSYCL.cmake)

# Configure the demo projects
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} CACHE PATH "" FORCE)
add_subdirectory(src/fluid)
add_subdirectory(src/game_of_life)
add_subdirectory(src/mandelbrot)
add_subdirectory(src/nbody)
add_subdirectory(src/matrix_multiply_omp_compare)
add_subdirectory(src/scan_parallel_inclusive)
if(ENABLE_GRAPHICS)
add_subdirectory(src/fluid)
add_subdirectory(src/game_of_life)
add_subdirectory(src/mandelbrot)
add_subdirectory(src/nbody)
endif()
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Drag the mouse around the screen to create fluid particles with velocities in
direction of the mouse travel. The fluid fades slowly over time so as not to fill
the container.

## Non-graphical Demos
### MPI for CUDA Backend
MPI, the Message Passing Interface, is a standard API for communicating data via
messages between distributed processes that is commonly used in HPC to build
Expand Down Expand Up @@ -76,7 +77,9 @@ include them in the checkout via
`git clone --recurse-submodules <this repo's URL>`. SDL2 needs to be supplied by
the user and can be installed with common package managers on most systems, or
built from source. If you install SDL2 from source in a non-default location,
pass it into the CMake configuration with `-DSDL2_ROOT=<path>`.
pass it into the CMake configuration with `-DSDL2_ROOT=<path>`. It is possible
to build the project without the graphical demos using `-DENABLE_GRAPHICS=OFF`
if SDL2 cannot be provided - see the Building section below.

Although the code should compile with any SYCL implementation, the CMake
configuration assumes the DPC++ compiler driver CLI for compilation flags setup.
Expand All @@ -89,7 +92,8 @@ The project uses a standard CMake build configuration system. Ensure the SYCL
compiler is used by the configuration either by setting the
environment variable `CXX=<compiler>` or passing the configuration flag
`-DCMAKE_CXX_COMPILER=<compiler>` where `<compiler>` is your SYCL compiler's
executable (for example Intel `icpx` or LLVM `clang++`). \
executable (for example Intel `icpx` or LLVM `clang++`).

To check out the repository and build the examples, use simply:
```
git clone --recurse-submodules <this repo's URL>
Expand All @@ -110,3 +114,10 @@ be overridden with `-D<OPTION>=<VALUE>` with the following options:
| `ENABLE_HIP` | `ON` or `OFF` |
| `CUDA_COMPUTE_CAPABILITY` | Integer, e.g. `70` meaning capability 7.0 (arch `sm_70`) |
| `HIP_GFX_ARCH` | String, e.g. `gfx1030` |

### Building without graphics
It is possible to build only the non-graphical demos by adding the option
`-DENABLE_GRAPHICS=OFF` to the CMake configuration command. In this case
building of the Magnum library will be skipped and the SDL2 library is not
required as dependency. The option `--recurse-submodules` can also be skipped
during the checkout when building only the non-graphical demos.
56 changes: 56 additions & 0 deletions cmake/ConfigureMagnum.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
############################################################################
#
# Copyright (C) Codeplay Software Limited
# 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.
#
# Description:
# CMake helper script configuring the graphics wrapper library Magnum
#
############################################################################

# Auto-configure ENABLE_GRAPHICS if not set on command line
find_package(SDL2 QUIET)
if (NOT DEFINED ENABLE_GRAPHICS)
if(SDL2_FOUND)
set(ENABLE_GRAPHICS ON CACHE BOOL "Build graphical demos")
message(STATUS "Auto-configured ENABLE_GRAPHICS=ON")
else()
message(WARNING "SDL2 not found, disabling all graphical demos. If you "
"are building the project intentionally without graphical "
"demos, add -DENABLE_GRAPHICS=OFF to your cmake configuration "
"command.")
set(ENABLE_GRAPHICS OFF CACHE BOOL "Build graphical demos")
endif()
elseif(ENABLE_GRAPHICS AND NOT SDL2_FOUND)
message(FATAL_ERROR "ENABLE_GRAPHICS was set to ON, but SDL was not found. "
"Cannot build the graphical demos. Set ENABLE_GRAPHICS=OFF to "
"build the project without them.")
endif()

# Configure Magnum
if (ENABLE_GRAPHICS)
list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/modules/magnum-bootstrap/modules"
"${PROJECT_SOURCE_DIR}/modules/magnum-integration/modules")
set(MAGNUM_WITH_SDL2APPLICATION ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_ANYIMAGEIMPORTER ON CACHE BOOL "" FORCE)
set(MAGNUM_WITH_STBIMAGEIMPORTER ON CACHE BOOL "" FORCE)
set(IMGUI_DIR ${PROJECT_SOURCE_DIR}/modules/imgui)
set(MAGNUM_WITH_IMGUI ON CACHE BOOL "" FORCE)
add_subdirectory(modules/corrade EXCLUDE_FROM_ALL)
add_subdirectory(modules/magnum EXCLUDE_FROM_ALL)
add_subdirectory(modules/magnum-plugins EXCLUDE_FROM_ALL)
add_subdirectory(modules/magnum-integration EXCLUDE_FROM_ALL)
find_package(Magnum REQUIRED GL Sdl2Application Shaders Primitives Trade)
find_package(MagnumIntegration REQUIRED ImGui)
endif()
Loading