Skip to content

Commit 436f081

Browse files
MathiasMagnusMeliriusneon60bashbaugalycm
authored
Samples and Utility libraries (#37)
Co-authored-by: Ivan Siutsou <ivan@streamhpc.com> Co-authored-by: Istvan Kiss <istvan@streamhpc.com> Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com> Co-authored-by: Alastair Murray <alastair.murray@codeplay.com>
1 parent 4dfd640 commit 436f081

114 files changed

Lines changed: 25790 additions & 82 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/presubmit.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ jobs:
2828
submodules: recursive
2929
- name: Build
3030
run: |
31-
mkdir build
32-
cd build
31+
if [[ "${{ matrix.os }}" == "ubuntu-20.04" ]]; then
32+
sudo apt update
33+
sudo apt install -y libtclap-dev libglm-dev libglew-dev libsfml-dev libstb-dev libidn11 libx11-dev libxrandr-dev libxi-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libudev-dev
34+
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
35+
brew install tclap glm glew sfml mesa-glu
36+
git clone https://github.com/Microsoft/vcpkg.git
37+
./vcpkg/bootstrap-vcpkg.sh
38+
./vcpkg/vcpkg install stb
39+
TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake"
40+
fi
3341
if [[ "${{ matrix.compiler }}" == "gcc" ]]; then
3442
CC=gcc
3543
CXX=g++
3644
elif [[ "${{ matrix.compiler }}" == "clang" ]]; then
3745
CC=clang
3846
CXX=clang++
3947
fi
40-
cmake -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX ../
41-
make -j2 VERBOSE=1
48+
cmake -D CMAKE_C_COMPILER=$CC -D CMAKE_CXX_COMPILER=$CXX $TOOLCHAIN_ARG -S . -B build
49+
cmake --build ./build --verbose --parallel 2
4250
buildwin:
4351
needs: format
4452
name: Build Windows
@@ -50,10 +58,11 @@ jobs:
5058
submodules: recursive
5159
- name: Build
5260
run: |
53-
mkdir build
54-
cd build
55-
cmake ../
56-
cmake --build .
61+
git clone https://github.com/Microsoft/vcpkg.git
62+
.\vcpkg\bootstrap-vcpkg.bat
63+
.\vcpkg\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb
64+
cmake -D CMAKE_TOOLCHAIN_FILE=.\vcpkg\scripts\buildsystems\vcpkg.cmake -S . -B build
65+
cmake --build ./build -- /verbosity:minimal /maxCpuCount /noLogo
5766
5867
python:
5968
name: Exercise Python examples on ${{matrix.os}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ install/
44
# vim
55
*~
66
.*.sw[op]
7+
.vscode
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM streamhpc/opencl-sdk-base:ubuntu-18.04-20211119
2+
RUN set -ex; \
3+
export DEBIAN_FRONTEND=noninteractive ; \
4+
# Register ROCm APT repo
5+
wget --quiet --recursive --no-directories --no-parent "https://repo.radeon.com/amdgpu-install/latest/ubuntu/bionic/" --accept "amdgpu-install-*_all.deb" ; \
6+
apt install -y -qq ./amdgpu-install-*_all.deb libnuma-dev initramfs-tools ; \
7+
apt update -qq; \
8+
rm ./amdgpu-install-*_all.deb ; \
9+
# Install OpenCL package only (and dependency)
10+
amdgpu-install -y --usecase=opencl

.gitlab/ubuntu-18.04.Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM ubuntu:18.04 AS apt-installs
2+
RUN set -ex; \
3+
export DEBIAN_FRONTEND=noninteractive ; \
4+
apt update -qq; \
5+
# install wget to download repository keys and CMake tarballs
6+
# install software-properties-common for the apt-add-repository command
7+
apt install -y -qq wget software-properties-common ; \
8+
# Canonical hosts recent GCC compilers in ubuntu-toolchain-r/test
9+
apt-add-repository -y ppa:ubuntu-toolchain-r/test ; \
10+
# LLVM hosts most toolchain in separate repos. We only register those absent from ubuntu-toolchain-r/test
11+
wget -q -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - ; \
12+
apt-add-repository -y 'deb [arch=amd64] https://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' ; \
13+
apt-add-repository -y 'deb [arch=amd64] https://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main' ; \
14+
apt-add-repository -y 'deb [arch=amd64] https://apt.llvm.org/bionic/ llvm-toolchain-bionic-13 main' ; \
15+
# install ninja, GCC 7-10, LLVM 8-13 and build-essential to get linkers, etc.
16+
# install git to download dependencies
17+
# install ruby to run CMock
18+
# install libidn11 which CMake 3.1.3 only depends on
19+
# install ca-certificates to `git clone` via HTTPS
20+
# install SFML dependencies
21+
# libx11-dev libxrandr-dev libxi-dev
22+
# mesa-common-dev for gl.h
23+
# libgl1-mesa-dev for libGL.so
24+
# libglu1-mesa-dev for glu.h
25+
# libudev-dev
26+
# install Vcpkg dependencies
27+
# curl zip unzip tar
28+
apt install -y -qq build-essential g++-7 g++-8 g++-9 g++-10 clang-8 clang-9 clang-10 clang-11 clang-12 clang-13 ninja-build git ruby libidn11 ca-certificates libx11-dev libxrandr-dev libxi-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libudev-dev curl zip unzip tar
29+
30+
# install CMake minimum (3.0.2 (Headers, ICD Loader), 3.1.3 (CLHPP), 3.10.3 (SDK)) and latest (3.21.2)
31+
RUN mkdir -p /opt/Kitware/CMake ; \
32+
wget -c https://github.com/Kitware/CMake/releases/download/v3.0.2/cmake-3.0.2-Linux-i386.tar.gz -O - | tar -xz --directory /opt/Kitware/CMake ; \
33+
mv /opt/Kitware/CMake/cmake-3.0.2-Linux-i386 /opt/Kitware/CMake/3.0.2 ; \
34+
wget -c https://github.com/Kitware/CMake/releases/download/v3.1.3/cmake-3.1.3-Linux-x86_64.tar.gz -O - | tar -xz --directory /opt/Kitware/CMake ; \
35+
mv /opt/Kitware/CMake/cmake-3.1.3-Linux-x86_64 /opt/Kitware/CMake/3.1.3 ; \
36+
wget -c https://github.com/Kitware/CMake/releases/download/v3.10.3/cmake-3.10.3-Linux-x86_64.tar.gz -O - | tar -xz --directory /opt/Kitware/CMake ; \
37+
mv /opt/Kitware/CMake/cmake-3.10.3-Linux-x86_64 /opt/Kitware/CMake/3.10.3 ; \
38+
wget -c https://github.com/Kitware/CMake/releases/download/v3.21.2/cmake-3.21.2-linux-x86_64.tar.gz -O - | tar -xz --directory /opt/Kitware/CMake ; \
39+
mv /opt/Kitware/CMake/cmake-3.21.2-linux-x86_64 /opt/Kitware/CMake/3.21.2
40+
41+
# install Vcpkg
42+
RUN git clone --depth 1 https://github.com/Microsoft/vcpkg.git /opt/Microsoft/vcpkg ; \
43+
/opt/Microsoft/vcpkg/bootstrap-vcpkg.sh ; \
44+
# install SFML, TCLAP, GLM
45+
/opt/Microsoft/vcpkg/vcpkg install sfml tclap glm glew

CMakeLists.txt

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,91 @@
1414

1515
cmake_minimum_required(VERSION 3.0)
1616

17-
set(CMAKE_CXX_STANDARD 11)
17+
set(CMAKE_CXX_STANDARD 14)
1818

19-
project(OpenCL-SDK)
19+
project(OpenCL-SDK
20+
VERSION 1.0
21+
LANGUAGES
22+
C CXX
23+
)
24+
25+
include(CMakeDependentOption)
26+
option(OPENCL_SDK_BUILD_SAMPLES "Build sample code" ON)
27+
cmake_dependent_option(OPENCL_SDK_BUILD_OPENGL_SAMPLES "Build OpenCL-OpenGL interop sample code" ON OPENCL_SDK_BUILD_SAMPLES OFF)
28+
cmake_dependent_option(OPENCL_SDK_TEST_SAMPLES "Add CTest to samples (where applicable)" ON OPENCL_SDK_BUILD_SAMPLES OFF)
29+
30+
include(CTest)
2031

2132
if (NOT CMAKE_BUILD_TYPE)
2233
message(STATUS "No build type selected, default to Release")
2334
set(CMAKE_BUILD_TYPE "Release" CACHE PATH "Build Type" FORCE)
2435
endif()
2536

26-
set(OPENCL_ICD_LOADER_HEADERS_DIR
27-
"${PROJECT_SOURCE_DIR}/external/OpenCL-Headers" CACHE PATH "Path to OpenCL
28-
Headers")
29-
3037
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
3138
set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "Install Path" FORCE)
3239
endif()
3340

34-
set(OPENCL_SDK_INCLUDE_DIRS
35-
"${PROJECT_SOURCE_DIR}/external/OpenCL-Headers"
36-
"${PROJECT_SOURCE_DIR}/external/OpenCL-CLHPP/include")
41+
add_subdirectory(external/OpenCL-Headers)
42+
add_subdirectory(external/OpenCL-ICD-Loader)
43+
add_subdirectory(external/OpenCL-CLHPP)
44+
45+
if(OPENCL_SDK_BUILD_SAMPLES)
46+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
47+
add_subdirectory(third_party/cargs)
48+
find_package(TCLAP REQUIRED)
49+
find_package(Stb REQUIRED)
50+
if(OPENCL_SDK_BUILD_OPENGL_SAMPLES)
51+
cmake_minimum_required(VERSION 3.10) # SFML 2 won't find Freetype::Freetype under 3.10
52+
find_package(OpenGL REQUIRED)
53+
if(CMAKE_SYSTEM_NAME MATCHES Linux) # TODO: Add EGL support
54+
# OpenGL doesn't explicitly depend on X11 (as of CMake v3.2) but we'll need it
55+
find_package(X11 REQUIRED)
56+
endif()
57+
find_package(GLEW REQUIRED)
58+
if(NOT TARGET OpenGL::GLU)
59+
# GLU is a dependency of GLEW but it's not advertized as an OpenGL COMPONENT
60+
message(FATAL_ERROR "GLEW depends on GLU but was not found.")
61+
endif()
62+
find_package(SFML 2
63+
REQUIRED
64+
COMPONENTS window graphics
65+
)
66+
find_package(GLEW REQUIRED)
67+
find_package(glm CONFIG REQUIRED)
68+
endif(OPENCL_SDK_BUILD_OPENGL_SAMPLES)
69+
endif(OPENCL_SDK_BUILD_SAMPLES)
70+
71+
add_subdirectory(lib)
72+
if(OPENCL_SDK_BUILD_SAMPLES)
73+
add_subdirectory(samples)
74+
endif()
3775

38-
add_subdirectory(${PROJECT_SOURCE_DIR}/external/OpenCL-ICD-Loader)
39-
add_subdirectory(${PROJECT_SOURCE_DIR}/samples)
76+
include(GNUInstallDirs)
77+
file(
78+
WRITE ${PROJECT_BINARY_DIR}/OpenCL/OpenCLConfig.cmake
79+
[[
80+
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
81+
include("${PARENT_DIR}/OpenCLHeaders/OpenCLHeadersConfig.cmake")
82+
include("${PARENT_DIR}/OpenCLICDLoader/OpenCLICDLoaderConfig.cmake")
83+
include("${PARENT_DIR}/OpenCLHeadersCpp/OpenCLHeadersCppConfig.cmake")
84+
include("${PARENT_DIR}/OpenCLUtils/OpenCLUtilsConfig.cmake")
85+
include("${PARENT_DIR}/OpenCLUtilsCpp/OpenCLUtilsCppConfig.cmake")
86+
]]
87+
)
88+
set(config_package_location ${CMAKE_INSTALL_DATADIR}/cmake/OpenCL)
89+
install(
90+
FILES ${PROJECT_BINARY_DIR}/OpenCL/OpenCLConfig.cmake
91+
DESTINATION ${config_package_location}
92+
)
4093

41-
set_target_properties(OpenCL PROPERTIES LIBRARY_OUTPUT_DIRECTORY
42-
${CMAKE_CURRENT_BINARY_DIR})
94+
unset(CMAKE_SIZEOF_VOID_P)
95+
include(CMakePackageConfigHelpers)
96+
write_basic_package_version_file(
97+
${CMAKE_CURRENT_BINARY_DIR}/OpenCL/OpenCLConfigVersion.cmake
98+
VERSION ${PROJECT_VERSION}
99+
COMPATIBILITY AnyNewerVersion
100+
)
101+
install(
102+
FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenCL/OpenCLConfigVersion.cmake
103+
DESTINATION ${config_package_location}
104+
)

README.md

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OpenCL-SDK (in development)
1+
# OpenCL<sup>TM</sup> SDK (in development)
22

33
This is the Khronos OpenCL SDK. It brings together all the components needed to
44
develop OpenCL applications:
@@ -13,40 +13,57 @@ It also contains resources useful to OpenCL developers:
1313
- Code samples (`samples/`)
1414
- Documentation (`docs/`)
1515

16-
## Setting Up the SDK
16+
## Build Instructions
1717

18-
This repository uses sub-modules for the OpenCL Headers, OpenCL C++ bindings, and OpenCL ICD Loader.
18+
### Dependencies
1919

20-
To clone a new repository with all sub-modules included, use the `--recursive` option.
21-
Note that this option clones all sub-modules and their dependencies, which are not required for the OpenCL SDK:
20+
- This repository uses sub-modules for the OpenCL Headers, OpenCL C++ bindings, and OpenCL ICD Loader and some of their transitive dependencies.
2221

23-
```sh
24-
$ git clone --recursive https://github.com/KhronosGroup/OpenCL-SDK.git
25-
```
22+
- To clone a new repository with all sub-modules included, use the `--recursive` option. Note that this option clones all sub-modules and their dependencies, which are not strictly required for the OpenCL SDK:
2623

27-
Alternatively, to clone only the sub-modules for the OpenCL SDK, first clone this repository without sub-modules included:
24+
git clone --recursive https://github.com/KhronosGroup/OpenCL-SDK.git
2825

29-
```sh
30-
$ git clone https://github.com/KhronosGroup/OpenCL-SDK.git
31-
```
26+
- Alternatively, to clone only the sub-modules for the OpenCL SDK, first clone this repository without sub-modules included then setup submodules non-recursively:
3227

33-
Then setup sub-modules:
28+
git clone https://github.com/KhronosGroup/OpenCL-SDK.git
29+
git submodule init
30+
git submodule update
3431

35-
```sh
36-
$ git submodule init
37-
$ git submodule update
38-
```
32+
- The SDK uses CMake for its build system.
33+
If CMake is not provided by your build system or OS package manager, please consult the [CMake website](https://cmake.org).
3934

40-
## Building the Samples
35+
- The SDK samples depend on
4136

42-
This repository uses CMake as its build system.
43-
The suggested build directory is `build`.
37+
- [Templatized C++ Command Line Parser Library](http://tclap.sourceforge.net/) (aka. TCLAP)
38+
- [Simple and Fast Multimedia Library](https://www.sfml-dev.org/) (aka. SFML)
39+
- [OpenGL Mathematics](https://glm.g-truc.net/0.9.9/index.html) (aka. GLM)
4440

45-
To generate build files, use for example:
41+
### Example Build
4642

47-
```sh
48-
$ mkdir build && cd build
49-
$ cmake ..
50-
```
43+
> The example build guide uses [Vcpkg](https://vcpkg.io/en/index.html) to fetch all dependencies. Note that Vcpkg is _not_ a requirement and is only used for convenience. One may provide dependencies through any other CMake mechanism. For details on how to install Vcpkg, refer to it's [Getting Started Guide](https://vcpkg.io/en/getting-started.html). The example build assumes targeting 64-bit Windows.
5144
52-
Then build with the generated build files.
45+
1. Clone this repo with the rest of the OpenCL SDK components:
46+
47+
git clone https://github.com/KhronosGroup/OpenCL-SDK.git
48+
git submodule init
49+
git submodule update
50+
51+
1. Install dependencies
52+
53+
vcpkg --triplet x64-windows install sfml tclap glm
54+
55+
1. Build and install SDK with samples and no downstream unit tests
56+
57+
cmake -A x64 `
58+
-D BUILD_TESTING=OFF `
59+
-D BUILD_DOCS=OFF `
60+
-D BUILD_EXAMPLES=OFF `
61+
-D BUILD_TESTS=OFF `
62+
-D OPENCL_SDK_BUILD_SAMPLES=ON `
63+
-D OPENCL_SDK_TEST_SAMPLES=OFF `
64+
-D CMAKE_TOOLCHAIN_FILE=/vcpkg/install/root/scripts/buildsystems/vcpkg.cmake `
65+
-D VCPKG_TARGET_TRIPLET=x64-windows
66+
-B ./OpenCL-SDK/build -S ./OpenCL-SDK
67+
cmake --build ./OpenCL-SDK/build --target install
68+
69+
_(Note: on Linux paths to dependent libraries are automatically handled by RPATH in both the build and install tree. On Windows all DLLs have to be on the `PATH`. Vcpkg copies dependent DLLs to the build tree, but in order to do the same in the install tree, sufficiently new CMake version is required. CMake 3.21 instroduces `install(IMPORTED_RUNTIME_ARTIFACTS)`.)_

cmake/Modules/FindStb.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# - Find Stb
2+
# Find the Stb headers
3+
#
4+
# Stb_INCLUDE_DIR - where to find the TCLAP headers
5+
# Stb_FOUND - True if TCLAP is found
6+
7+
if (Stb_INCLUDE_DIR)
8+
# already in cache, be silent
9+
set (Stb_FIND_QUIETLY TRUE)
10+
endif (Stb_INCLUDE_DIR)
11+
12+
# find the headers
13+
find_path (Stb_INCLUDE_PATH stb_image.h
14+
PATHS
15+
${Stb_DIR}
16+
PATH_SUFFIXES
17+
include
18+
include/stb
19+
)
20+
21+
# handle the QUIETLY and REQUIRED arguments and set Stb_FOUND to
22+
# TRUE if all listed variables are TRUE
23+
include (FindPackageHandleStandardArgs)
24+
find_package_handle_standard_args (Stb "Stb (https://github.com/nothings/stb) could not be found. Set Stb_INCLUDE_PATH to point to the headers adding '-D Stb_INCLUDE_PATH=/path/to/stb' to the cmake command." Stb_INCLUDE_PATH)
25+
26+
if (Stb_FOUND)
27+
set (Stb_INCLUDE_DIR ${Stb_INCLUDE_PATH})
28+
endif (Stb_FOUND)
29+
30+
mark_as_advanced(Stb_INCLUDE_PATH)

cmake/Modules/FindTCLAP.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# - Find TCLAP
2+
# Find the TCLAP headers
3+
#
4+
# TCLAP_INCLUDE_DIR - where to find the TCLAP headers
5+
# TCLAP_FOUND - True if TCLAP is found
6+
7+
if (TCLAP_INCLUDE_DIR)
8+
# already in cache, be silent
9+
set (TCLAP_FIND_QUIETLY TRUE)
10+
endif (TCLAP_INCLUDE_DIR)
11+
12+
# find the headers
13+
find_path (TCLAP_INCLUDE_PATH tclap/CmdLine.h
14+
PATHS
15+
${CMAKE_SOURCE_DIR}/include
16+
${CMAKE_INSTALL_PREFIX}/include
17+
)
18+
19+
# handle the QUIETLY and REQUIRED arguments and set TCLAP_FOUND to
20+
# TRUE if all listed variables are TRUE
21+
include (FindPackageHandleStandardArgs)
22+
find_package_handle_standard_args (TCLAP "TCLAP (http://tclap.sourceforge.net/) could not be found. Set TCLAP_INCLUDE_PATH to point to the headers adding '-DTCLAP_INCLUDE_PATH=/path/to/tclap' to the cmake command." TCLAP_INCLUDE_PATH)
23+
24+
if (TCLAP_FOUND)
25+
set (TCLAP_INCLUDE_DIR ${TCLAP_INCLUDE_PATH})
26+
endif (TCLAP_FOUND)
27+
28+
mark_as_advanced(TCLAP_INCLUDE_PATH)

0 commit comments

Comments
 (0)