Skip to content

Commit 8a0fbfb

Browse files
authored
[SYCL][AOT] Define CL_TARGET_OPENCL_VERSION to OpenCL 2.2 (#1608)
When using the Khronos OpenCL headers from GitHub, set the preprocessor symbol CL_TARGET_OPENCL_VERSION=220 to silence the compilation message from the OpenCL header files, and define all OpenCL 2.2 symbols. Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>
1 parent d7a7e11 commit 8a0fbfb

16 files changed

Lines changed: 44 additions & 17 deletions

File tree

opencl-aot/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if (NOT OpenCL_INCLUDE_DIRS)
2525
STEP_TARGETS build
2626
COMMENT "Downloading OpenCL headers."
2727
)
28+
add_definitions(-DCL_TARGET_OPENCL_VERSION=220)
2829
else ()
2930
add_custom_target(opencl-headers ALL
3031
DEPENDS ${OpenCL_INCLUDE_DIRS}

opencl-aot/source/utils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,18 @@ std::string getOpenCLErrorNameByErrorCode(cl_int CLErr) {
140140
return "CL_INVALID_LINKER_OPTIONS";
141141
case CL_INVALID_DEVICE_PARTITION_COUNT:
142142
return "CL_INVALID_DEVICE_PARTITION_COUNT";
143+
#ifdef CL_VERSION_2_0
143144
case CL_INVALID_PIPE_SIZE:
144145
return "CL_INVALID_PIPE_SIZE";
145146
case CL_INVALID_DEVICE_QUEUE:
146147
return "CL_INVALID_DEVICE_QUEUE";
148+
#endif
149+
#ifdef CL_VERSION_2_2
147150
case CL_INVALID_SPEC_ID:
148151
return "CL_INVALID_SPEC_ID";
149152
case CL_MAX_SIZE_RESTRICTION_EXCEEDED:
150153
return "CL_MAX_SIZE_RESTRICTION_EXCEEDED";
154+
#endif
151155
default:
152156
return "Unknown error code";
153157
}

sycl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ if( NOT OpenCL_INCLUDE_DIRS )
9292
STEP_TARGETS build
9393
COMMENT "Downloading OpenCL headers."
9494
)
95+
add_definitions(-DCL_TARGET_OPENCL_VERSION=220)
9596
else()
9697
add_custom_target( ocl-headers ALL
9798
DEPENDS ${OpenCL_INCLUDE_DIRS}

sycl/include/CL/sycl/backend/opencl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#pragma once
1111

12-
#include <CL/cl.h>
1312
#include <CL/sycl/accessor.hpp>
1413
#include <CL/sycl/backend_types.hpp>
14+
#include <CL/sycl/detail/cl.h>
1515

1616
__SYCL_INLINE_NAMESPACE(cl) {
1717
namespace sycl {

sycl/include/CL/sycl/detail/aligned_allocator.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010

11-
#include <CL/cl.h>
1211
#include <CL/sycl/detail/common.hpp>
1312
#include <CL/sycl/detail/os_util.hpp>
1413
#include <CL/sycl/range.hpp>

sycl/include/CL/sycl/detail/buffer_impl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010

11-
#include <CL/cl.h>
1211
#include <CL/sycl/access/access.hpp>
1312
#include <CL/sycl/context.hpp>
1413
#include <CL/sycl/detail/common.hpp>

sycl/include/CL/sycl/detail/cl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//==---------------- cl.h - Include OpenCL headers -------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
// Suppress a compiler message about undefined CL_TARGET_OPENCL_VERSION
12+
// and define all symbols up to OpenCL 2.2
13+
#ifndef CL_TARGET_OPENCL_VERSION
14+
#define CL_TARGET_OPENCL_VERSION 220
15+
#endif
16+
17+
#include <CL/cl.h>
18+
#include <CL/cl_ext.h>

sycl/include/CL/sycl/detail/common.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,11 @@
88

99
#pragma once
1010

11+
#include <CL/cl_ext_intel.h>
12+
#include <CL/sycl/detail/cl.h>
1113
#include <CL/sycl/detail/defines.hpp>
1214
#include <CL/sycl/detail/export.hpp>
1315

14-
// Suppress a compiler warning about undefined CL_TARGET_OPENCL_VERSION
15-
// Khronos ICD supports only latest OpenCL version
16-
#define CL_TARGET_OPENCL_VERSION 220
17-
#include <CL/cl.h>
18-
#include <CL/cl_ext.h>
19-
#include <CL/cl_ext_intel.h>
20-
2116
#include <cstdint>
2217
#include <string>
2318
#include <type_traits>

sycl/include/CL/sycl/detail/memory_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#pragma once
1010

11-
#include <CL/cl.h>
1211
#include <CL/sycl/access/access.hpp>
12+
#include <CL/sycl/detail/cl.h>
1313
#include <CL/sycl/detail/export.hpp>
1414
#include <CL/sycl/detail/sycl_mem_obj_i.hpp>
1515
#include <CL/sycl/range.hpp>

sycl/include/CL/sycl/detail/pi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
// TODO: we need a mapping of PI to OpenCL somewhere, and this can be done
4646
// elsewhere, e.g. in the pi_opencl, but constants/enums mapping is now
4747
// done here, for efficiency and simplicity.
48-
//
48+
4949
#include <CL/cl_usm_ext.h>
50-
#include <CL/opencl.h>
50+
#include <CL/sycl/detail/cl.h>
5151
#include <cstdint>
5252

5353
#ifdef __cplusplus

0 commit comments

Comments
 (0)