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
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
${CMAKE_MODULE_PATH}
${LLVM_CMAKE_DIR})

# A prebuilt clang may predate the CL3.1 patches carried in patches/clang
# (only applied when building clang from source, see below). Probe it so
# we don't try to generate a PCM with a -cl-std value the compiler rejects.
find_program(OPENCL_CLANG_PROBE_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cl31_check.cl" "")
execute_process(
COMMAND ${OPENCL_CLANG_PROBE_CLANG} -cl-std=CL3.1 -x cl -fsyntax-only "${CMAKE_CURRENT_BINARY_DIR}/cl31_check.cl"
RESULT_VARIABLE CLANG_CL31_CHECK_RESULT
OUTPUT_QUIET
ERROR_QUIET
)
if(CLANG_CL31_CHECK_RESULT EQUAL 0)
set(CLANG_SUPPORTS_CL31 TRUE)
else()
set(CLANG_SUPPORTS_CL31 FALSE)
message(STATUS "[OPENCL-CLANG] ${OPENCL_CLANG_PROBE_CLANG} does not support -cl-std=CL3.1; skipping OpenCL 3.1 PCM generation")
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Expand All @@ -67,9 +85,14 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif(LLVMSPIRV_INCLUDED_IN_LLVM)
else(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(USE_PREBUILT_LLVM OFF)
set(CLANG_SUPPORTS_CL31 TRUE)
find_package(Git REQUIRED)
endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)

if(NOT CLANG_SUPPORTS_CL31)
add_definitions(-DOPENCL_CLANG_NO_CL31_PCM)
endif()

include(AddLLVM)
include(TableGen)

Expand Down
47 changes: 31 additions & 16 deletions cl_headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,32 @@ set(OPTS -cl-ext=+all,-cl_khr_fp64,-__opencl_c_fp64)
create_pcm(opencl-c-12-spir.pcm cl12spir opencl-c-base.h "${SPIR_TRIPLE};${CL12};${OPTS}" "${DEPS}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was a condition in line 65 missed? I am having currently some trouble with CL3.1 in NixOS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 65 is set(CL31 "-cl-std=CL3.1") and CL31 isn't used if CLANG_SUPPORTS_CL31 is false.
Could you paste the error? Is CLANG_SUPPORTS_CL31 true or false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#880 will fix out-of-tree build in opencl-clang main branch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that just sets the var 🤦🏼

I figured the issue out in NixOS. Since we have no full git tree, the patching would not work as the exit code of git for rev-prase would be 128. That is handled in newer versions of opencl-clang and logged, but for the time being I just turned one condition to always true. We only consume opencl-clang throuch intel-graphics-compierl.

That's the PR if you are interested NixOS/nixpkgs#555838

And igc still uses the 170 branch, so we are stuck to that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right that NixOS extract llvm-project release from a tarball file and there is not .git folder in llvm-project folder?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please check if #881 works for you? After the PR, opencl-clang can apply patch without requiring .git folder being existing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right that NixOS extract llvm-project release from a tarball file and there is not .git folder in llvm-project folder?

Yep. I tried fetching the git tree, but I could not get a stable hash of that download, so it failed CI, obviously.

I try to look at the patch in the next days.

@wenju-he wenju-he Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to look at the patch in the next days.

great. My local testing shows opencl-clang applied its clang/llvm patch successfully in llvm-project-17.0.6.src folder (no .git subfolder) extracted from llvm-project-17.0.6.src.tar.xz

create_pcm(opencl-c-20-spir.pcm cl20spir opencl-c-base.h "${SPIR_TRIPLE};${CL20};${OPTS}" "${DEPS}")
create_pcm(opencl-c-30-spir.pcm cl30spir opencl-c-base.h "${SPIR_TRIPLE};${CL30};${OPTS};${OPTS30}" "${DEPS}")
create_pcm(opencl-c-31-spir.pcm cl31spir opencl-c-base.h "${SPIR_TRIPLE};${CL31};${OPTS};${OPTS30}" "${DEPS}")
create_pcm(opencl-c-12-spir64.pcm cl12spir64 opencl-c-base.h "${SPIR64_TRIPLE};${CL12};${OPTS}" "${DEPS}")
create_pcm(opencl-c-20-spir64.pcm cl20spir64 opencl-c-base.h "${SPIR64_TRIPLE};${CL20};${OPTS}" "${DEPS}")
create_pcm(opencl-c-30-spir64.pcm cl30spir64 opencl-c-base.h "${SPIR64_TRIPLE};${CL30};${OPTS};${OPTS30}" "${DEPS}")
create_pcm(opencl-c-31-spir64.pcm cl31spir64 opencl-c-base.h "${SPIR64_TRIPLE};${CL31};${OPTS};${OPTS30}" "${DEPS}")
set(OPTS -cl-ext=+all)
create_pcm(opencl-c-12-spir-fp64.pcm cl12spirfp64 opencl-c-base.h "${SPIR_TRIPLE};${CL12};${OPTS}" "${DEPS}")
create_pcm(opencl-c-20-spir-fp64.pcm cl20spirfp64 opencl-c-base.h "${SPIR_TRIPLE};${CL20};${OPTS}" "${DEPS}")
create_pcm(opencl-c-30-spir-fp64.pcm cl30spirfp64 opencl-c-base.h "${SPIR_TRIPLE};${CL30};${OPTS};${OPTS30};${OPTS30_FP64}" "${DEPS}")
create_pcm(opencl-c-31-spir-fp64.pcm cl31spirfp64 opencl-c-base.h "${SPIR_TRIPLE};${CL31};${OPTS};${OPTS30};${OPTS30_FP64}" "${DEPS}")
create_pcm(opencl-c-12-spir64-fp64.pcm cl12spir64fp64 opencl-c-base.h "${SPIR64_TRIPLE};${CL12};${OPTS}" "${DEPS}")
create_pcm(opencl-c-20-spir64-fp64.pcm cl20spir64fp64 opencl-c-base.h "${SPIR64_TRIPLE};${CL20};${OPTS}" "${DEPS}")
create_pcm(opencl-c-30-spir64-fp64.pcm cl30spir64fp64 opencl-c-base.h "${SPIR64_TRIPLE};${CL30};${OPTS};${OPTS30};${OPTS30_FP64}" "${DEPS}")
create_pcm(opencl-c-31-spir64-fp64.pcm cl31spir64fp64 opencl-c-base.h "${SPIR64_TRIPLE};${CL31};${OPTS};${OPTS30};${OPTS30_FP64}" "${DEPS}")

set(CL31_PCM_TARGETS "")
if(CLANG_SUPPORTS_CL31)
set(OPTS -cl-ext=+all,-cl_khr_fp64,-__opencl_c_fp64)
create_pcm(opencl-c-31-spir.pcm cl31spir opencl-c-base.h "${SPIR_TRIPLE};${CL31};${OPTS};${OPTS30}" "${DEPS}")
create_pcm(opencl-c-31-spir64.pcm cl31spir64 opencl-c-base.h "${SPIR64_TRIPLE};${CL31};${OPTS};${OPTS30}" "${DEPS}")
set(OPTS -cl-ext=+all)
create_pcm(opencl-c-31-spir-fp64.pcm cl31spirfp64 opencl-c-base.h "${SPIR_TRIPLE};${CL31};${OPTS};${OPTS30};${OPTS30_FP64}" "${DEPS}")
create_pcm(opencl-c-31-spir64-fp64.pcm cl31spir64fp64 opencl-c-base.h "${SPIR64_TRIPLE};${CL31};${OPTS};${OPTS30};${OPTS30_FP64}" "${DEPS}")
list(APPEND CL31_PCM_TARGETS
opencl-c-31-spir.pcm
opencl-c-31-spir64.pcm
opencl-c-31-spir-fp64.pcm
opencl-c-31-spir64-fp64.pcm
)
endif()

add_custom_target (
opencl.pcm.target
Expand All @@ -102,19 +114,16 @@ add_custom_target (
opencl-c-12-spir.pcm
opencl-c-20-spir.pcm
opencl-c-30-spir.pcm
opencl-c-31-spir.pcm
opencl-c-12-spir64.pcm
opencl-c-20-spir64.pcm
opencl-c-30-spir64.pcm
opencl-c-31-spir64.pcm
opencl-c-12-spir-fp64.pcm
opencl-c-20-spir-fp64.pcm
opencl-c-30-spir-fp64.pcm
opencl-c-31-spir-fp64.pcm
opencl-c-12-spir64-fp64.pcm
opencl-c-20-spir64-fp64.pcm
opencl-c-30-spir64-fp64.pcm
opencl-c-31-spir64-fp64.pcm
${CL31_PCM_TARGETS}
)

function(pack_to_obj SRC DST TAG)
Expand All @@ -137,40 +146,46 @@ else()
opencl-c-12-spir.mod.cpp
opencl-c-20-spir.mod.cpp
opencl-c-30-spir.mod.cpp
opencl-c-31-spir.mod.cpp
opencl-c-12-spir64.mod.cpp
opencl-c-20-spir64.mod.cpp
opencl-c-30-spir64.mod.cpp
opencl-c-31-spir64.mod.cpp
opencl-c-12-spir-fp64.mod.cpp
opencl-c-20-spir-fp64.mod.cpp
opencl-c-30-spir-fp64.mod.cpp
opencl-c-31-spir-fp64.mod.cpp
opencl-c-12-spir64-fp64.mod.cpp
opencl-c-20-spir64-fp64.mod.cpp
opencl-c-30-spir64-fp64.mod.cpp
opencl-c-31-spir64-fp64.mod.cpp
module.modulemap.cpp
)
if(CLANG_SUPPORTS_CL31)
list(APPEND CL_HEADERS_SRC
opencl-c-31-spir.mod.cpp
opencl-c-31-spir64.mod.cpp
opencl-c-31-spir-fp64.mod.cpp
opencl-c-31-spir64-fp64.mod.cpp
)
endif()
# note the .pcm -> .mod extension change
# this is a workaround for CMake bug that caused
# dependency cycle in generated build rules
pack_to_obj(opencl-c-12-spir.pcm opencl-c-12-spir.mod.cpp "PCM_OPENCL_C_12_SPIR_PCM")
pack_to_obj(opencl-c-20-spir.pcm opencl-c-20-spir.mod.cpp "PCM_OPENCL_C_20_SPIR_PCM")
pack_to_obj(opencl-c-30-spir.pcm opencl-c-30-spir.mod.cpp "PCM_OPENCL_C_30_SPIR_PCM")
pack_to_obj(opencl-c-31-spir.pcm opencl-c-31-spir.mod.cpp "PCM_OPENCL_C_31_SPIR_PCM")
pack_to_obj(opencl-c-12-spir64.pcm opencl-c-12-spir64.mod.cpp "PCM_OPENCL_C_12_SPIR64_PCM")
pack_to_obj(opencl-c-20-spir64.pcm opencl-c-20-spir64.mod.cpp "PCM_OPENCL_C_20_SPIR64_PCM")
pack_to_obj(opencl-c-30-spir64.pcm opencl-c-30-spir64.mod.cpp "PCM_OPENCL_C_30_SPIR64_PCM")
pack_to_obj(opencl-c-31-spir64.pcm opencl-c-31-spir64.mod.cpp "PCM_OPENCL_C_31_SPIR64_PCM")
pack_to_obj(opencl-c-12-spir-fp64.pcm opencl-c-12-spir-fp64.mod.cpp "PCM_OPENCL_C_12_SPIR_FP64_PCM")
pack_to_obj(opencl-c-20-spir-fp64.pcm opencl-c-20-spir-fp64.mod.cpp "PCM_OPENCL_C_20_SPIR_FP64_PCM")
pack_to_obj(opencl-c-30-spir-fp64.pcm opencl-c-30-spir-fp64.mod.cpp "PCM_OPENCL_C_30_SPIR_FP64_PCM")
pack_to_obj(opencl-c-31-spir-fp64.pcm opencl-c-31-spir-fp64.mod.cpp "PCM_OPENCL_C_31_SPIR_FP64_PCM")
pack_to_obj(opencl-c-12-spir64-fp64.pcm opencl-c-12-spir64-fp64.mod.cpp "PCM_OPENCL_C_12_SPIR64_FP64_PCM")
pack_to_obj(opencl-c-20-spir64-fp64.pcm opencl-c-20-spir64-fp64.mod.cpp "PCM_OPENCL_C_20_SPIR64_FP64_PCM")
pack_to_obj(opencl-c-30-spir64-fp64.pcm opencl-c-30-spir64-fp64.mod.cpp "PCM_OPENCL_C_30_SPIR64_FP64_PCM")
pack_to_obj(opencl-c-31-spir64-fp64.pcm opencl-c-31-spir64-fp64.mod.cpp "PCM_OPENCL_C_31_SPIR64_FP64_PCM")
if(CLANG_SUPPORTS_CL31)
pack_to_obj(opencl-c-31-spir.pcm opencl-c-31-spir.mod.cpp "PCM_OPENCL_C_31_SPIR_PCM")
pack_to_obj(opencl-c-31-spir64.pcm opencl-c-31-spir64.mod.cpp "PCM_OPENCL_C_31_SPIR64_PCM")
pack_to_obj(opencl-c-31-spir-fp64.pcm opencl-c-31-spir-fp64.mod.cpp "PCM_OPENCL_C_31_SPIR_FP64_PCM")
pack_to_obj(opencl-c-31-spir64-fp64.pcm opencl-c-31-spir64-fp64.mod.cpp "PCM_OPENCL_C_31_SPIR64_FP64_PCM")
endif()
pack_to_obj(module.modulemap module.modulemap.cpp "PCM_OPENCL_C_MODULE_MAP")
endif()

Expand Down
8 changes: 8 additions & 0 deletions cl_headers/OpenCL.rc
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ OPENCL_C_BASE_H PCM "opencl-c-base.h"
OPENCL_C_12_SPIR_PCM PCM "opencl-c-12-spir.pcm"
OPENCL_C_20_SPIR_PCM PCM "opencl-c-20-spir.pcm"
OPENCL_C_30_SPIR_PCM PCM "opencl-c-30-spir.pcm"
#ifndef OPENCL_CLANG_NO_CL31_PCM
OPENCL_C_31_SPIR_PCM PCM "opencl-c-31-spir.pcm"
#endif
OPENCL_C_12_SPIR64_PCM PCM "opencl-c-12-spir64.pcm"
OPENCL_C_20_SPIR64_PCM PCM "opencl-c-20-spir64.pcm"
OPENCL_C_30_SPIR64_PCM PCM "opencl-c-30-spir64.pcm"
#ifndef OPENCL_CLANG_NO_CL31_PCM
OPENCL_C_31_SPIR64_PCM PCM "opencl-c-31-spir64.pcm"
#endif
OPENCL_C_12_SPIR_FP64_PCM PCM "opencl-c-12-spir-fp64.pcm"
OPENCL_C_20_SPIR_FP64_PCM PCM "opencl-c-20-spir-fp64.pcm"
OPENCL_C_30_SPIR_FP64_PCM PCM "opencl-c-30-spir-fp64.pcm"
#ifndef OPENCL_CLANG_NO_CL31_PCM
OPENCL_C_31_SPIR_FP64_PCM PCM "opencl-c-31-spir-fp64.pcm"
#endif
OPENCL_C_12_SPIR64_FP64_PCM PCM "opencl-c-12-spir64-fp64.pcm"
OPENCL_C_20_SPIR64_FP64_PCM PCM "opencl-c-20-spir64-fp64.pcm"
OPENCL_C_30_SPIR64_FP64_PCM PCM "opencl-c-30-spir64-fp64.pcm"
#ifndef OPENCL_CLANG_NO_CL31_PCM
OPENCL_C_31_SPIR64_FP64_PCM PCM "opencl-c-31-spir64-fp64.pcm"
#endif
OPENCL_C_MODULE_MAP PCM "module.modulemap"
8 changes: 8 additions & 0 deletions opencl_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,27 @@ static bool GetHeaders(std::vector<Resource> &Result) {
{OPENCL_C_12_SPIR_PCM, "opencl-c-12-spir.pcm"},
{OPENCL_C_20_SPIR_PCM, "opencl-c-20-spir.pcm"},
{OPENCL_C_30_SPIR_PCM, "opencl-c-30-spir.pcm"},
#ifndef OPENCL_CLANG_NO_CL31_PCM
{OPENCL_C_31_SPIR_PCM, "opencl-c-31-spir.pcm"},
#endif
{OPENCL_C_12_SPIR64_PCM, "opencl-c-12-spir64.pcm"},
{OPENCL_C_20_SPIR64_PCM, "opencl-c-20-spir64.pcm"},
{OPENCL_C_30_SPIR64_PCM, "opencl-c-30-spir64.pcm"},
#ifndef OPENCL_CLANG_NO_CL31_PCM
{OPENCL_C_31_SPIR64_PCM, "opencl-c-31-spir64.pcm"},
#endif
{OPENCL_C_12_SPIR_FP64_PCM, "opencl-c-12-spir-fp64.pcm"},
{OPENCL_C_20_SPIR_FP64_PCM, "opencl-c-20-spir-fp64.pcm"},
{OPENCL_C_30_SPIR_FP64_PCM, "opencl-c-30-spir-fp64.pcm"},
#ifndef OPENCL_CLANG_NO_CL31_PCM
{OPENCL_C_31_SPIR_FP64_PCM, "opencl-c-31-spir-fp64.pcm"},
#endif
{OPENCL_C_12_SPIR64_FP64_PCM, "opencl-c-12-spir64-fp64.pcm"},
{OPENCL_C_20_SPIR64_FP64_PCM, "opencl-c-20-spir64-fp64.pcm"},
{OPENCL_C_30_SPIR64_FP64_PCM, "opencl-c-30-spir64-fp64.pcm"},
#ifndef OPENCL_CLANG_NO_CL31_PCM
{OPENCL_C_31_SPIR64_FP64_PCM, "opencl-c-31-spir64-fp64.pcm"},
#endif
{OPENCL_C_MODULE_MAP, "module.modulemap"}};

Result.clear();
Expand Down
Loading