Skip to content

Commit

Permalink
External memory C/C++ example
Browse files Browse the repository at this point in the history
  • Loading branch information
Beanavil authored and mfep committed Oct 27, 2023
1 parent 90a76b2 commit 43b8e34
Show file tree
Hide file tree
Showing 12 changed files with 2,205 additions and 5 deletions.
43 changes: 40 additions & 3 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ jobs:
fetch-depth: 0
submodules: recursive

- name: Install samples dependencies
run: |
if [[ "${{ matrix.BIN }}" == "64" ]]; then
apt-get update -qq;
apt-get install -y libvulkan-dev;
else
dpkg --add-architecture i386;
apt-get update -qq;
apt-get install -y libvulkan-dev:i386;
fi
- name: Configure, package & install OpenCL-Headers
run: $CMAKE_EXE
-G "${{matrix.CONF.GEN}}"
Expand Down Expand Up @@ -392,6 +403,8 @@ jobs:
INTEL_OCL_URL: https://github.com/intel/llvm/releases/download/2023-WW27/win-oclcpuexp-2023.16.6.0.28_rel.zip
INTEL_TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.10.0/oneapi-tbb-2021.10.0-win.zip
IMAGE_INTEL_PREFIX: C:\Tools\Intel
VULKAN_SDK_URL: https://sdk.lunarg.com/sdk/download/1.3.261.1/windows/VulkanSDK-1.3.261.1-Installer.exe
VULKAN_SDK: C:/VulkanSDK/1.3.261.1

steps:
- name: Cache Ninja install
Expand Down Expand Up @@ -428,6 +441,18 @@ jobs:
New-Item -Type File HKLM:\SOFTWARE\Khronos\OpenCL\Vendors | Out-Null; `
Set-ItemProperty -Path HKLM:\SOFTWARE\Khronos\OpenCL\Vendors -Name ${env:IMAGE_INTEL_PREFIX}\oclcpuexp\intelocl64.dll -Type DWord -Value 0;
- name: Install samples dependencies
run: |
Invoke-WebRequest ${env:VULKAN_SDK_URL} -OutFile vulkan-sdk-installer.exe
.\vulkan-sdk-installer.exe --accept-licenses --default-answer --confirm-command install com.lunarg.vulkan.32bit
Remove-Item vulkan-sdk-installer.exe
if ('${{ matrix.BIN }}' -eq 'x64')
{
echo "Vulkan_LIB_DIR=$env:VULKAN_SDK/Lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
} else {
echo "Vulkan_LIB_DIR=$env:VULKAN_SDK/Lib32" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
- name: Cache dependencies (vcpkg)
if: matrix.DEPS == 'vcpkg'
id: vcpkg-install
Expand Down Expand Up @@ -472,6 +497,8 @@ jobs:
-D CMAKE_C_STANDARD=${{matrix.STD.C}} `
-D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} `
-D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install `
-D Vulkan_INCLUDE_DIR=${env:VULKAN_SDK}/Include `
-D Vulkan_LIBRARY=${env:Vulkan_LIB_DIR}/vulkan-1.lib `
-S ${env:GITHUB_WORKSPACE} `
-B ${env:GITHUB_WORKSPACE}\build
if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." }
Expand Down Expand Up @@ -501,6 +528,8 @@ jobs:
-D CMAKE_CXX_STANDARD=${{matrix.STD.CXX}} `
-D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL `
-D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install `
-D Vulkan_INCLUDE_DIR=${env:VULKAN_SDK}/Include `
-D Vulkan_LIBRARY=${env:Vulkan_LIB_DIR}/vulkan-1.lib `
-S ${env:GITHUB_WORKSPACE} `
-B ${env:GITHUB_WORKSPACE}\build
if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." }
Expand Down Expand Up @@ -539,12 +568,14 @@ jobs:
if: matrix.BIN != 'x86'
working-directory: ${{runner.workspace}}/OpenCL-SDK/build
run: |
$EXCLUDE_REGEX = 'externalmemory.*'
foreach ($Config in 'Release','Debug') {
& ctest `
--build-config ${Config} `
--output-on-failure `
--no-tests=error `
--parallel ${env:NUMBER_OF_PROCESSORS}
--parallel ${env:NUMBER_OF_PROCESSORS} `
--exclude-regex "$EXCLUDE_REGEX"
if ($LASTEXITCODE -ne 0) { throw "Running OpenCL-SDK tests in $Config failed." }
}
Expand Down Expand Up @@ -655,6 +686,10 @@ jobs:
brew install pocl
cmake --version
- name: Install samples dependencies
run: |
brew install vulkan-loader
- name: Install dependencies (Homebrew)
if: matrix.DEPS == 'system'
run: brew install tclap glm glew sfml mesa-glu
Expand Down Expand Up @@ -702,8 +737,10 @@ jobs:
- name: Test
working-directory: ${{runner.workspace}}/OpenCL-SDK/build
run: |
OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu`
OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu`
# Incompatible Vulkan Driver
export EXCLUDE_REGEX="externalmemory.*"
OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX"
OCL_ICD_VENDORS=/usr/local/etc/OpenCL/vendors ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX"
- name: Install
run: |
Expand Down
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Global flag to cause add_library() to crea

# Fetch dependencies
if(OPENCL_SDK_BUILD_SAMPLES)
foreach(DEP IN ITEMS cargs TCLAP Stb)
foreach(DEP IN ITEMS cargs TCLAP Stb Vulkan)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/${DEP}")
include(${DEP})
endforeach()
Expand Down
1 change: 1 addition & 0 deletions cmake/Dependencies/Vulkan/Vulkan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_package(Vulkan REQUIRED)
4 changes: 3 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ CHECK_LIBRARY_EXISTS(m sin "" HAVE_LIB_M)
# KERNELS <file0> <file1> ... # optional, specifies kernel files for the sample
# INCLUDES <dir0> <dir1> ... # optional, specifies additional include directories for the sample
# LIBS <lib0> <lib1> ... # optional, specifies additional libraries for the sample
# DEFINITIONS <def0> <def1> # optional, specifies additional compile definitions for the sample
# )
macro(add_sample)
set(options TEST)
set(one_value_args TARGET VERSION CATEGORY)
set(multi_value_args SOURCES KERNELS SHADERS INCLUDES LIBS)
set(multi_value_args SOURCES KERNELS SHADERS INCLUDES LIBS DEFINITIONS)
cmake_parse_arguments(OPENCL_SAMPLE
"${options}" "${one_value_args}" "${multi_value_args}"
${ARGN}
Expand Down Expand Up @@ -75,6 +76,7 @@ macro(add_sample)
CL_HPP_MINIMUM_OPENCL_VERSION=${OPENCL_SAMPLE_VERSION}
CL_HPP_ENABLE_EXCEPTIONS
$<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS> # TODO: remove
${OPENCL_SAMPLE_DEFINITIONS}
)

set_target_properties(${OPENCL_SAMPLE_TARGET}
Expand Down
1 change: 1 addition & 0 deletions samples/extensions/khr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

add_subdirectory(externalmemory)
add_subdirectory(histogram)
if(OPENCL_SDK_BUILD_OPENGL_SAMPLES)
add_subdirectory(conway)
Expand Down
31 changes: 31 additions & 0 deletions samples/extensions/khr/externalmemory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2021 The Khronos Group Inc.
#
# 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.

add_sample(
TEST
TARGET externalmemory
VERSION 300
SOURCES main.c
KERNELS external_saxpy.cl
LIBS Vulkan::Vulkan
DEFINITIONS $<$<PLATFORM_ID:Windows>:VK_USE_PLATFORM_WIN32_KHR>)

add_sample(
TEST
TARGET externalmemorycpp
VERSION 300
SOURCES main.cpp
KERNELS external_saxpy.cl
LIBS Vulkan::Vulkan
DEFINITIONS $<$<PLATFORM_ID:Windows>:VK_USE_PLATFORM_WIN32_KHR>)
Loading

0 comments on commit 43b8e34

Please sign in to comment.