Skip to content

Commit

Permalink
Merge branch 'main' into large-usm-alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbaug committed Apr 25, 2024
2 parents 91f6971 + efeae73 commit 31c14fb
Show file tree
Hide file tree
Showing 181 changed files with 22,601 additions and 2,718 deletions.
4 changes: 4 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ configuration:
#- Debug
- Release

skip_commits:
files:
- '**/*.md'

before_build:
- git clone --depth=1 https://github.com/KhronosGroup/OpenCL-Headers external/OpenCL-Headers
- git clone --depth=1 https://github.com/KhronosGroup/OpenCL-ICD-Loader external/opencl-icd-loader
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: build

on:
push:
paths-ignore:
- '**/*.md'
pull_request:
branches:
- main

env:
BUILD_TYPE: RelWithDebInfo

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Check Tabs
run: |
if git grep -n $'\t' samples/*.cpp samples/*.h tutorials/*.cpp tutorials/*.h; then echo 'Please replace tabs with spaces in source files.'; false; fi
- name: Check Whitespace
run: |
if git grep -n '[[:blank:]]$' samples/*.cpp samples/*.h tutorials/*.cpp tutorials/*.h; then echo 'Please remove trailing whitespace from source files.'; false; fi
build:
needs: check

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
ext: [YES, NO]

runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3

- name: Get Ubuntu OpenGL Dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libglfw3-dev
- name: Get OpenCL Headers
uses: actions/checkout@v3
with:
repository: KhronosGroup/OpenCL-Headers
path: external/OpenCL-Headers

- name: Get OpenCL ICD Loader
uses: actions/checkout@v3
with:
repository: KhronosGroup/OpenCL-ICD-Loader
path: external/opencl-icd-loader

- name: Get OpenCL Extension Loader
if: matrix.ext == 'YES'
uses: actions/checkout@v3
with:
repository: bashbaug/opencl-extension-loader
path: external/opencl-extension-loader

- name: Create Build Directory
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Run CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake -DOpenCL_INCLUDE_DIRS=$GITHUB_WORKSPACE/external/OpenCL-Headers -DCMAKE_BUILD_TYPE=$BUILD_TYPE $GITHUB_WORKSPACE

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --parallel --config $BUILD_TYPE

#- name: Test
# working-directory: ${{runner.workspace}}/build
# shell: bash
# run: ctest -C $BUILD_TYPE
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,33 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

project(SimpleOpenCLSamples VERSION 1.0)

option(SAMPLES_ENABLE_EXCEPTIONS "Enable Exceptions for OpenCL Errors")

set(OpenCL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/OpenCL-Headers CACHE PATH "Path to OpenCL Headers")
find_package(OpenCL)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${OpenCL_INCLUDE_DIR})

add_subdirectory(external/OpenCL-Headers)
add_subdirectory(external/opencl-icd-loader)
set_target_properties(OpenCL PROPERTIES FOLDER "OpenCL-ICD-Loader")
set_target_properties(cllayerinfo PROPERTIES FOLDER "OpenCL-ICD-Loader")
set(OpenCL_LIBRARIES OpenCL)

if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/opencl-extension-loader)
add_subdirectory(external/opencl-extension-loader)
else()
message(STATUS "OpenCL Extension Loader is not found.")
endif()

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
enable_testing()
endif()

add_subdirectory(layers)
add_subdirectory(samples)
add_subdirectory(tutorials)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/install" CACHE PATH "Install Path" FORCE)
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Simple OpenCL<sup>TM</sup> Samples

[![build](https://github.com/bashbaug/SimpleOpenCLSamples/workflows/build/badge.svg?branch=main)](https://github.com/bashbaug/SimpleOpenCLSamples/actions?query=workflow%3Abuild+branch%3Amain)

This repo contains simple OpenCL samples that demonstrate how to build
OpenCL applications using only the Khronos-provided headers and libs.
All samples have been tested on Windows and Linux.

Most of the samples are written in C and C++ using the OpenCL C++ bindings.
A few of the samples have been ported to Python using [PyOpenCL](https://pypi.org/project/pyopencl/).


## Code Structure

Expand All @@ -13,7 +18,9 @@ LICENSE License information
CMakeLists.txt Top-level CMakefile
external/ External Projects (headers and libs)
include/ Include Files (OpenCL C++ bindings)
samples/ Samples
layers/ Sample Layers
samples/ Sample Applications
tutorials/ Tutorials
```

## How to Build the Samples
Expand All @@ -28,6 +35,10 @@ OpenCL ICD Loader:

git clone https://github.com/KhronosGroup/opencl-icd-loader external/opencl-icd-loader

Many samples that use extensions additionally require the OpenCL Extension Loader:

git clone https://github.com/bashbaug/opencl-extension-loader external/opencl-extension-loader

After satisfying the external dependencies create build files using CMake. For example:

mkdir build && cd build
Expand All @@ -48,10 +59,21 @@ implementations as well.

## Further Reading

* [Environment Setup for Ubuntu 18.04](docs/env/ubuntu/18.04.md)
* [Environment Setup for Ubuntu 22.04](docs/env/ubuntu/22.04.md)
* [OpenCLPapers](https://github.com/bashbaug/OpenCLPapers)
* [OpenCL Specs](https://www.khronos.org/registry/OpenCL/specs/)
* [OpenCL Return Codes](https://streamhpc.com/blog/2013-04-28/opencl-error-codes/)
* [OpenCL Specs](https://registry.khronos.org/OpenCL/)
* [OpenCL Error Codes](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#error_codes)

## A Note About Error Checking

For brevity, most samples do not include error checking. This means that a
sample may crash or incorrectly report success if an OpenCL error occurs. By
defining the CMake variable `SAMPLES_ENABLE_EXCEPTIONS` many samples can instead
throw an exception if an OpenCL error occurs.

Tools like the [OpenCL Intercept Layer](https://github.com/intel/opencl-intercept-layer)
can also be useful to detect when an OpenCL error occurs and to identify the
cause of the error.

## License

Expand All @@ -62,6 +84,11 @@ Notes:
[Khronos OpenCL-CLHPP Repo](https://github.com/KhronosGroup/OpenCL-CLHPP),
and is licensed under the
[Khronos(tm) License](https://github.com/KhronosGroup/OpenCL-CLHPP/blob/master/LICENSE.txt).
* The samples use [popl](https://github.com/badaix/popl) for its options
parsing, which is licensed under the MIT License.
* The samples use [stb](https://github.com/nothings/stb) for image reading and
writing, which is dual-licensed under a public domain license and the MIT
license.

---
OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos.
Expand Down
2 changes: 1 addition & 1 deletion docs/env/ubuntu/18.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OpenCL applications generally link against an OpenCL Installable Compute Device

### AMD

TODO
AMD supports OpenCL through their ROCm platform. Installation instructions are [here](https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#ubuntu).

### Intel
Intel's OpenCL support is provided through the NEO compute runtime, available as a PPA.
Expand Down
2 changes: 1 addition & 1 deletion docs/env/ubuntu/19.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OpenCL applications generally link against an OpenCL Installable Compute Device

### AMD

TODO
AMD provides official support for LTS releases only.

### Intel
Intel's OpenCL support is provided through the NEO compute runtime, available as a PPA.
Expand Down
2 changes: 1 addition & 1 deletion docs/env/ubuntu/19.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ OpenCL applications generally link against an OpenCL Installable Compute Device

### AMD

TODO
AMD provides official support for LTS releases only.

### Intel
Intel's OpenCL support is provided through the NEO compute runtime, available as a PPA.
Expand Down
2 changes: 1 addition & 1 deletion docs/env/ubuntu/20.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ OpenCL applications generally link against an OpenCL Installable Compute Device

### AMD Compute Runtime

TODO
AMD supports OpenCL through their ROCm platform. Installation instructions are [here](https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#ubuntu).

### Intel Compute Runtime

Expand Down
82 changes: 82 additions & 0 deletions docs/env/ubuntu/22.04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Ubuntu 22.04 Setup Instructions

## Verify Hardware Support

Most modern GPUs support OpenCL. For integrated graphics devices (iGPUs), use `lscpu` to get the processor SKU. Detailed information for Intel SKUs is available from [ark.intel.com](ark.intel.com). Detailed information for AMD processors is available from [AMD's product page](https://www.amd.com/en/products/specifications/processors).

## Build Dependencies

OCL Headers:

```bash
sudo apt install opencl-c-headers opencl-clhpp-headers
```

The OpenCL API has its own set of header files; the above command installs both C and C++ headers files. The C header can be found in `<CL/cl.h>`; the C++ header is in `<CL/cl.hpp>`.

OCL ICD Loader:

```bash
sudo apt install ocl-icd-opencl-dev
```

OpenCL applications generally link against an OpenCL Installable Compute Device (ICD) loader instead of a specific OpenCL implementation; see [https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc](https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc) for more information about this system.

## Runtime Dependencies

OpenCL requires a compute runtime to manage the interaction between the OpenCL API and the GPU.

### OCL ICD Loader

```bash
sudo apt install ocl-icd-libopencl1
```

OpenCL applications generally link against an OpenCL Installable Compute Device (ICD) loader instead of a specific OpenCL implementation; see [https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc](https://github.com/bashbaug/OpenCLPapers/blob/master/OpenCLOnLinux.asciidoc) for more information about this system.

### AMD Compute Runtime

AMD supports OpenCL through their ROCm platform. Installation instructions are [here](https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#ubuntu).

### Intel Compute Runtime

Intel's OpenCL support is provided through the NEO compute runtime. Download packages from the project's [GitHub releases page](https://github.com/intel/compute-runtime/releases).

### Nvidia Compute Runtime

Nvidia provides OpenCL support through their proprietary driver, available from the [graphics-drivers PPA](https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa).

```bash
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install nvidia-graphics-drivers-<version>
```

### Configure Permissions

```bash
sudo usermod -a -G video $USER
sudo usermod -a -G render $USER
```

Users running OpenCL applications on a GPU require additional permissions granted by the groups above.

## Verification

The `clinfo` utility can be used to verify the environment has been properly configured.

```bash
$ sudo apt install clinfo
$ clinfo
<platform information should show here>
```

## Troubleshooting

If `clinfo` indicates there are 0 supported platforms:

1. Verify your host has OpenCL-capable hardware attached
2. Verify clinfo is running as a user with appropriate group membership
3. Verify new group membership has been applied (this may require logout or reboot)
4. Verify the correct compute runtime is installed
5. Check the kernel log (`sudo dmesg`) for related errors
Loading

0 comments on commit 31c14fb

Please sign in to comment.