Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ jobs:
repository: bashbaug/opencl-extension-loader
path: external/opencl-extension-loader

- name: Get SPIR-V Headers
if: matrix.ext == 'YES'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: KhronosGroup/SPIRV-Headers
path: external/SPIRV-Headers

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

Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ else()
message(STATUS "OpenCL Extension Loader is not found.")
endif()

if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/SPIRV-Headers)
add_subdirectory(external/SPIRV-Headers)
else()
message(STATUS "SPIR-V Headers are not found.")
endif()

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
enable_testing()
endif()
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Many samples that use extensions additionally require the OpenCL Extension Loade

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

Several samples that interact with SPIR-V require the SPIR-V headres:

git clone https://github.com/KhronosGroup/SPIRV-Headers external/SPIRV-Headers

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

mkdir build && cd build
Expand Down
6 changes: 6 additions & 0 deletions include/CL/opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,12 @@ CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_LO
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_CLOCK_CAPABILITIES_KHR, cl_device_kernel_clock_capabilities_khr)
#endif /* cl_khr_kernel_clock */

#if defined(cl_khr_spirv_queries)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_EXTENDED_INSTRUCTION_SETS_KHR, cl::vector<const char*>)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_EXTENSIONS_KHR, cl::vector<const char*>)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_CAPABILITIES_KHR, cl::vector<cl_uint>)
#endif /* cl_khr_spirv_queries */

#if defined(cl_ext_float_atomics)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SINGLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_DOUBLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
Expand Down
4 changes: 2 additions & 2 deletions include/layer_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static inline cl_int writeStringToMemory(
return CL_SUCCESS;
}

static cl_uint getOpenCLVersionFromString(
static cl_version getOpenCLVersionFromString(
const char* str)
{
cl_uint major = 0;
Expand Down Expand Up @@ -105,7 +105,7 @@ static cl_uint getOpenCLVersionFromString(
}
}

return (major << 16) | minor;
return CL_MAKE_VERSION(major, minor, 0);
}

static inline bool checkStringForExtension(
Expand Down
4 changes: 2 additions & 2 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <CL/opencl.hpp>
#include <string>

static cl_uint getDeviceOpenCLVersion(
static cl_version getDeviceOpenCLVersion(
const cl::Device& device)
{
cl_uint major = 0;
Expand Down Expand Up @@ -36,7 +36,7 @@ static cl_uint getDeviceOpenCLVersion(
}
}

return (major << 16) | minor;
return CL_MAKE_VERSION(major, minor, 0);
}

static bool checkDeviceForExtension(
Expand Down
8 changes: 4 additions & 4 deletions layers/10_cmdbufemu/emulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2897,7 +2897,7 @@ bool clGetDeviceInfo_override(
deviceExtensions.data(),
CL_KHR_COMMAND_BUFFER_EXTENSION_NAME ) == false &&
getOpenCLVersionFromString(
deviceVersion.data() ) >= 0x00020001)
deviceVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
{
std::string newExtensions;
newExtensions += CL_KHR_COMMAND_BUFFER_EXTENSION_NAME;
Expand Down Expand Up @@ -2981,7 +2981,7 @@ bool clGetDeviceInfo_override(

if( found == false &&
getOpenCLVersionFromString(
deviceVersion.data() ) >= 0x00020001)
deviceVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
{
{
extensions.emplace_back();
Expand Down Expand Up @@ -3246,7 +3246,7 @@ bool clGetPlatformInfo_override(
platformExtensions.data(),
CL_KHR_COMMAND_BUFFER_EXTENSION_NAME ) == false &&
getOpenCLVersionFromString(
platformVersion.data() ) >= 0x00020001)
platformVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
{
std::string newExtensions;
newExtensions += CL_KHR_COMMAND_BUFFER_EXTENSION_NAME;
Expand Down Expand Up @@ -3330,7 +3330,7 @@ bool clGetPlatformInfo_override(

if( found == false &&
getOpenCLVersionFromString(
platformVersion.data() ) >= 0x00020001)
platformVersion.data() ) >= CL_MAKE_VERSION(2, 1, 0))
{
{
extensions.emplace_back();
Expand Down
2 changes: 1 addition & 1 deletion layers/11_semaemu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

add_opencl_layer(
NUMBER 10
NUMBER 11
TARGET SemaEmu
VERSION 300
SOURCES main.cpp emulate.cpp emulate.h)
10 changes: 10 additions & 0 deletions layers/12_spirvqueriesemu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2025 Ben Ashbaugh
#
# SPDX-License-Identifier: MIT

add_opencl_layer(
NUMBER 12
TARGET SpirvQueriesEmu
VERSION 300
SOURCES main.cpp emulate.cpp emulate.h
INCLUDES ${SPIRV-Headers_SOURCE_DIR}/include)
Loading