Coder Social home page Coder Social logo

jackakirk / sycl-samples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codeplaysoftware/sycl-samples

0.0 0.0 0.0 141 KB

A collection of samples written using the SYCL standard for C++.

License: Apache License 2.0

C++ 90.52% CMake 7.04% GLSL 1.66% Dockerfile 0.77%

sycl-samples's Introduction

SYCL-samples

A collection of samples and graphical demos written using SYCL.

Graphical Demos

Game of Life

This demo simulates Conway's Game of Life with a dynamically resizable grid. To draw new cells, hold the mouse button and drag the mouse slowly over the grid. Press SPACE to pause/resume the simulation. To resize the grid, use the mouse wheel. Doing this or resizing the window will reset the simulation.

Mandelbrot

This demo dynamically renders and displays a visualization of the Mandelbrot set on the complex plane. Use the mouse wheel to zoom in or out and drag the mouse while holding the mouse button to move around the plane.

NBody

This demo demonstrates the use of numerical integration methods to simulate systems of interacting bodies, where every body exerts a force on every other body. A graphical interface is provided to set the force type, the integration method, and the initial distribution of bodies. The simulation can be initialized from there. The simulation can be viewed from different positions by dragging the mouse and using the mouse wheel to control the camera.

Fluid Simulation

This demo visualizes fluid behavior in a closed container. Each cell in the cellular automata represents a fluid particle existing in a velocity field. 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 applications that can scale to multi-node computer clusters. The three minimal code examples demonstrate how some GPUs can support CUDA-Aware MPI together with SYCL.

The first example uses the SYCL Unified Shared Memory (USM) memory model (send_recv_usm). The second uses the Buffer (send_recv_buff) model. Each example uses the programming pattern Send-Receive.

The third slightly more complex code example scatter_reduce_gather demonstrates a common HPC programming idiom using Scatter, Reduce and Gather. A data array is scattered by two processes associated with different MPI ranks using Scatter. The initial data is updated within each MPI rank. Next the updated data is used to calculate a local quantity that is then reduced to a partial result in each rank using the SYCL 2020 reduction interface. Finally, the partial results from each rank are reduced to a final scalar value, res, using Reduce. Finally, the initial data is updated using Gather.

These three examples form part of the Codeplay oneAPI for NVIDIA GPUs plugin documentation. The documentation refers to the gpu-aware MPI guide for the CUDA backend.

Building the MPI-CUDA examples requires the CUDA backend to be enabled and the MPI headers and library to be present on the system. This demo will be automatically skipped when not building for the CUDA backend or when MPI is not installed/detected. A message saying this will appear in the CMake configuration output. Additionally, in order to run the examples, the MPI implementation needs to be CUDA-aware. This is only detectable at runtime, so the examples may build fine but crash on execution if the linked MPI library isn't CUDA-aware.

Parallel Inclusive Scan

Implementation of a parallel inclusive scan with a given associative binary operation in SYCL.

Matrix Multiply OpenMP Comparison

A block tiled matrix multiplication example which compares an OpenMP blocked matrix multiplication implementation with a SYCL blocked matrix multiplication example. The purpose is not to compare performance, but to show the similarities and differences between them. See block_host for the OpenMP implementation.

Dependencies

The graphical demos use Magnum (and its dependency Corrade) for the graphics and UI abstraction with the SDL2 implementation. Magnum and Corrade are built as part of this project through git submodules. Make sure to 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>. 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. Both the Intel DPC++ release and the open source version are compatible.

Building

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++).

To check out the repository and build the examples, use simply:

git clone --recurse-submodules <this repo's URL>
cd SYCL-samples
mkdir build && cd build
cmake .. -DCMAKE_CXX_COMPILER=<compiler>
cmake --build .

The CMake configuration automatically detects the available SYCL backends and enables the SPIR/CUDA/HIP targets for the device code, including the corresponding architecture flags. If desired, these auto-configured options may be overridden with -D<OPTION>=<VALUE> with the following options:

<OPTION> <VALUE>
ENABLE_SPIR ON or OFF
ENABLE_CUDA ON or OFF
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.

sycl-samples's People

Contributors

rafbiels avatar duncanmcbain avatar georgeweb avatar irudkin avatar martinstarkov avatar mcleary avatar vtec234 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.