Skip to content

Commit 89e0e06

Browse files
mfepBeanavilbashbaug
authored
Implemented external memory sample (#90)
* External memory C/C++ example * Fixes from review * Fix find_suitable_device logic to conditionally increment cl_device_count * Conform to OpenCL v3.0.15 specification release * Fix kernel execution time report * Fix opencl version check * Fix logic for finding suitable opencl device * Inform when kernel source is not found * Set VkPhysicalDeviceExternalBufferInfo->usage * Set VkExternalBufferProperties->sType and pNext * fixes for Windows * Fix external memory handle types loop count * Remove unnecesary OpenCL kernel compilation to 3.0 --------- Co-authored-by: Beatriz Navidad Vilches <beatriz@streamhpc.com> Co-authored-by: Ben Ashbaugh <ben.ashbaugh@intel.com>
1 parent edd20e0 commit 89e0e06

13 files changed

Lines changed: 2369 additions & 3 deletions

File tree

.github/workflows/presubmit.yml

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ jobs:
198198
fetch-depth: 0
199199
submodules: recursive
200200

201+
- name: Install samples dependencies
202+
run: |
203+
if [[ "${{ matrix.BIN }}" == "64" ]]; then
204+
apt-get update -qq;
205+
apt-get install -y libvulkan-dev;
206+
else
207+
dpkg --add-architecture i386;
208+
apt-get update -qq;
209+
apt-get install -y libvulkan-dev:i386;
210+
fi
211+
201212
- name: Configure, package & install OpenCL-Headers
202213
run: $CMAKE_EXE
203214
-G "${{matrix.CONF.GEN}}"
@@ -416,6 +427,8 @@ jobs:
416427
INTEL_OCL_URL: https://github.com/intel/llvm/releases/download/2023-WW27/win-oclcpuexp-2023.16.6.0.28_rel.zip
417428
INTEL_TBB_URL: https://github.com/oneapi-src/oneTBB/releases/download/v2021.10.0/oneapi-tbb-2021.10.0-win.zip
418429
IMAGE_INTEL_PREFIX: C:\Tools\Intel
430+
VULKAN_SDK_URL: https://sdk.lunarg.com/sdk/download/1.3.261.1/windows/VulkanSDK-1.3.261.1-Installer.exe
431+
VULKAN_SDK: C:/VulkanSDK/1.3.261.1
419432

420433
steps:
421434

@@ -457,6 +470,18 @@ jobs:
457470
fetch-depth: 0
458471
submodules: recursive
459472

473+
- name: Install samples dependencies
474+
run: |
475+
Invoke-WebRequest ${env:VULKAN_SDK_URL} -OutFile vulkan-sdk-installer.exe
476+
.\vulkan-sdk-installer.exe --accept-licenses --default-answer --confirm-command install com.lunarg.vulkan.32bit
477+
Remove-Item vulkan-sdk-installer.exe
478+
if ('${{ matrix.BIN }}' -eq 'x64')
479+
{
480+
echo "Vulkan_LIB_DIR=$env:VULKAN_SDK/Lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
481+
} else {
482+
echo "Vulkan_LIB_DIR=$env:VULKAN_SDK/Lib32" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
483+
}
484+
460485
- name: Configure (MSBuild)
461486
if: matrix.GEN == 'Visual Studio 17 2022'
462487
run: |
@@ -479,6 +504,8 @@ jobs:
479504
-D CMAKE_C_FLAGS="${env:CMAKE_CFLAGS}" `
480505
-D CMAKE_CXX_FLAGS="${env:CMAKE_CXXFLAGS}" `
481506
-D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install `
507+
-D Vulkan_INCLUDE_DIR=${env:VULKAN_SDK}/Include `
508+
-D Vulkan_LIBRARY=${env:Vulkan_LIB_DIR}/vulkan-1.lib `
482509
-S ${env:GITHUB_WORKSPACE} `
483510
-B ${env:GITHUB_WORKSPACE}\build
484511
if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." }
@@ -509,6 +536,8 @@ jobs:
509536
-D CMAKE_CXX_FLAGS="${env:CMAKE_CXXFLAGS}" `
510537
-D CMAKE_EXE_LINKER_FLAGS=/INCREMENTAL `
511538
-D CMAKE_INSTALL_PREFIX=${env:GITHUB_WORKSPACE}\install `
539+
-D Vulkan_INCLUDE_DIR=${env:VULKAN_SDK}/Include `
540+
-D Vulkan_LIBRARY=${env:Vulkan_LIB_DIR}/vulkan-1.lib `
512541
-S ${env:GITHUB_WORKSPACE} `
513542
-B ${env:GITHUB_WORKSPACE}\build
514543
if ($LASTEXITCODE -ne 0) { throw "Configuring OpenCL-SDK failed." }
@@ -546,12 +575,14 @@ jobs:
546575
if: matrix.BIN != 'x86'
547576
working-directory: ${{runner.workspace}}/OpenCL-SDK/build
548577
run: |
578+
$EXCLUDE_REGEX = 'externalmemory.*'
549579
foreach ($Config in 'Release','Debug') {
550580
& ctest `
551581
--build-config ${Config} `
552582
--output-on-failure `
553583
--no-tests=error `
554-
--parallel ${env:NUMBER_OF_PROCESSORS}
584+
--parallel ${env:NUMBER_OF_PROCESSORS} `
585+
--exclude-regex "$EXCLUDE_REGEX"
555586
if ($LASTEXITCODE -ne 0) { throw "Running OpenCL-SDK tests in $Config failed." }
556587
}
557588
@@ -664,6 +695,10 @@ jobs:
664695
echo "OCL_ICD_VENDORS=$POCL_INSTALL_PATH/etc/OpenCL/vendors" >> $GITHUB_ENV
665696
cmake --version
666697
698+
- name: Install samples dependencies
699+
run: |
700+
brew install vulkan-loader
701+
667702
- name: Install dependencies (Homebrew)
668703
if: matrix.DEPS == 'system'
669704
run: brew install tclap glm glew sfml mesa-glu
@@ -718,7 +753,7 @@ jobs:
718753
- name: Test
719754
working-directory: ${{runner.workspace}}/OpenCL-SDK/build
720755
run: |
721-
EXCLUDE_REGEX="multidevice.*"
756+
EXCLUDE_REGEX="(multidevice|externalmemory).*"
722757
ctest -C Debug --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX"
723758
ctest -C Release --output-on-failure --no-tests=error --parallel `sysctl -n hw.logicalcpu` --exclude-regex "$EXCLUDE_REGEX"
724759

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ include(CMakeDependentOption)
2626
option(OPENCL_SDK_BUILD_UTILITY_LIBRARIES "Build utility libraries" ON)
2727
cmake_dependent_option(OPENCL_SDK_BUILD_SAMPLES "Build sample code" ON OPENCL_SDK_BUILD_UTILITY_LIBRARIES OFF)
2828
cmake_dependent_option(OPENCL_SDK_BUILD_OPENGL_SAMPLES "Build OpenCL-OpenGL interop sample code" ON OPENCL_SDK_BUILD_SAMPLES OFF)
29+
cmake_dependent_option(OPENCL_SDK_BUILD_VULKAN_SAMPLES "Build OpenCL-Vulkan interop sample code" ON OPENCL_SDK_BUILD_SAMPLES OFF)
2930
cmake_dependent_option(OPENCL_SDK_TEST_SAMPLES "Add CTest to samples (where applicable)" ON OPENCL_SDK_BUILD_SAMPLES OFF)
3031

3132
option(OPENCL_SDK_BUILD_CLINFO "Build clinfo utility" ON)

cmake/Dependencies.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ if(OPENCL_SDK_BUILD_SAMPLES)
5252
include(${DEP})
5353
endforeach()
5454
endif(OPENCL_SDK_BUILD_OPENGL_SAMPLES)
55+
56+
if(OPENCL_SDK_BUILD_VULKAN_SAMPLES)
57+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Dependencies/Vulkan")
58+
include(Vulkan)
59+
endif(OPENCL_SDK_BUILD_VULKAN_SAMPLES)
5560
endif(OPENCL_SDK_BUILD_SAMPLES)
5661

5762
if(OPENCL_SDK_BUILD_CLINFO)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
find_package(Vulkan REQUIRED)

samples/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ CHECK_LIBRARY_EXISTS(m sin "" HAVE_LIB_M)
3333
# KERNELS <file0> <file1> ... # optional, specifies kernel files for the sample
3434
# INCLUDES <dir0> <dir1> ... # optional, specifies additional include directories for the sample
3535
# LIBS <lib0> <lib1> ... # optional, specifies additional libraries for the sample
36+
# DEFINITIONS <def0> <def1> # optional, specifies additional compile definitions for the sample
3637
# )
3738
macro(add_sample)
3839
set(options TEST)
3940
set(one_value_args TARGET VERSION CATEGORY)
40-
set(multi_value_args SOURCES KERNELS SHADERS INCLUDES LIBS)
41+
set(multi_value_args SOURCES KERNELS SHADERS INCLUDES LIBS DEFINITIONS)
4142
cmake_parse_arguments(OPENCL_SAMPLE
4243
"${options}" "${one_value_args}" "${multi_value_args}"
4344
${ARGN}
@@ -75,6 +76,7 @@ macro(add_sample)
7576
CL_HPP_MINIMUM_OPENCL_VERSION=${OPENCL_SAMPLE_VERSION}
7677
CL_HPP_ENABLE_EXCEPTIONS
7778
$<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS> # TODO: remove
79+
${OPENCL_SAMPLE_DEFINITIONS}
7880
)
7981

8082
set_target_properties(${OPENCL_SAMPLE_TARGET}

samples/extensions/khr/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ if(OPENCL_SDK_BUILD_OPENGL_SAMPLES)
1717
add_subdirectory(conway)
1818
add_subdirectory(nbody)
1919
endif()
20+
if(OPENCL_SDK_BUILD_VULKAN_SAMPLES)
21+
add_subdirectory(externalmemory)
22+
endif()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2021 The Khronos Group Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
add_sample(
16+
TEST
17+
TARGET externalmemory
18+
VERSION 300
19+
SOURCES main.c
20+
KERNELS external_saxpy.cl
21+
LIBS Vulkan::Vulkan
22+
DEFINITIONS $<$<PLATFORM_ID:Windows>:VK_USE_PLATFORM_WIN32_KHR>)
23+
24+
add_sample(
25+
TEST
26+
TARGET externalmemorycpp
27+
VERSION 300
28+
SOURCES main.cpp
29+
KERNELS external_saxpy.cl
30+
LIBS Vulkan::Vulkan
31+
DEFINITIONS $<$<PLATFORM_ID:Windows>:VK_USE_PLATFORM_WIN32_KHR>)

0 commit comments

Comments
 (0)