Skip to content

Commit 78bd66a

Browse files
[SYCL] Removes more uses of OpenCL header definitions (#6328)
This commit adds various PI definitions and replaces some uses of OpenCL header definitions from the SYCL runtime library. To further isolate the remaining uses of the OpenCL headers, the includes of cl.h are moved from common.hpp to the dependent files. Tests updates at: intel/llvm-test-suite#1061
1 parent 25c03fa commit 78bd66a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+643
-803
lines changed

sycl/include/CL/sycl/accessor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <CL/sycl/atomic.hpp>
1313
#include <CL/sycl/buffer.hpp>
1414
#include <CL/sycl/detail/accessor_impl.hpp>
15+
#include <CL/sycl/detail/cl.h>
1516
#include <CL/sycl/detail/common.hpp>
1617
#include <CL/sycl/detail/export.hpp>
1718
#include <CL/sycl/detail/generic_type_traits.hpp>

sycl/include/CL/sycl/aliases.hpp

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

99
#pragma once
1010

11+
#include <CL/sycl/detail/cl.h>
1112
#include <CL/sycl/detail/common.hpp>
1213

1314
#include <cstddef>

sycl/include/CL/sycl/atomic.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <CL/__spirv/spirv_ops.hpp>
1212
#include <CL/sycl/access/access.hpp>
13+
#include <CL/sycl/detail/cl.h>
1314
#include <CL/sycl/detail/helpers.hpp>
1415
#include <CL/sycl/memory_enums.hpp>
1516

sycl/include/CL/sycl/context.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <CL/sycl/detail/backend_traits.hpp>
12+
#include <CL/sycl/detail/cl.h>
1213
#include <CL/sycl/detail/common.hpp>
1314
#include <CL/sycl/detail/export.hpp>
1415
#include <CL/sycl/detail/stl_type_traits.hpp>

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
#pragma once
1010

11-
#include <CL/sycl/detail/cl.h>
1211
#include <CL/sycl/detail/defines.hpp>
1312
#include <CL/sycl/detail/defines_elementary.hpp>
1413
#include <CL/sycl/detail/export.hpp>
14+
#include <CL/sycl/detail/pi.hpp>
1515
#include <CL/sycl/detail/stl_type_traits.hpp>
1616

1717
#include <cstdint>
@@ -91,9 +91,9 @@ __SYCL_INLINE_NAMESPACE(cl) {
9191
namespace sycl {
9292
namespace detail {
9393

94-
__SYCL_EXPORT const char *stringifyErrorCode(cl_int error);
94+
__SYCL_EXPORT const char *stringifyErrorCode(pi_int32 error);
9595

96-
static inline std::string codeToString(cl_int code) {
96+
static inline std::string codeToString(pi_int32 code) {
9797
return std::string(std::to_string(code) + " (" + stringifyErrorCode(code) +
9898
")");
9999
}
@@ -109,20 +109,20 @@ static inline std::string codeToString(cl_int code) {
109109
#define __SYCL_ASSERT(x) assert(x)
110110
#endif // #ifdef __SYCL_DEVICE_ONLY__
111111

112-
#define __SYCL_OCL_ERROR_REPORT \
112+
#define __SYCL_PI_ERROR_REPORT \
113113
"Native API failed. " /*__FILE__*/ \
114114
/* TODO: replace __FILE__ to report only relative path*/ \
115115
/* ":" __SYCL_STRINGIFY(__LINE__) ": " */ \
116116
"Native API returns: "
117117

118-
#ifndef __SYCL_SUPPRESS_OCL_ERROR_REPORT
118+
#ifndef __SYCL_SUPPRESS_PI_ERROR_REPORT
119119
#include <iostream>
120120
// TODO: rename all names with direct use of OCL/OPENCL to be backend agnostic.
121-
#define __SYCL_REPORT_OCL_ERR_TO_STREAM(expr) \
121+
#define __SYCL_REPORT_PI_ERR_TO_STREAM(expr) \
122122
{ \
123123
auto code = expr; \
124-
if (code != CL_SUCCESS) { \
125-
std::cerr << __SYCL_OCL_ERROR_REPORT \
124+
if (code != PI_SUCCESS) { \
125+
std::cerr << __SYCL_PI_ERROR_REPORT \
126126
<< cl::sycl::detail::codeToString(code) << std::endl; \
127127
} \
128128
}
@@ -131,39 +131,39 @@ static inline std::string codeToString(cl_int code) {
131131
#ifndef SYCL_SUPPRESS_EXCEPTIONS
132132
#include <CL/sycl/exception.hpp>
133133
// SYCL 1.2.1 exceptions
134-
#define __SYCL_REPORT_OCL_ERR_TO_EXC(expr, exc, str) \
134+
#define __SYCL_REPORT_PI_ERR_TO_EXC(expr, exc, str) \
135135
{ \
136136
auto code = expr; \
137-
if (code != CL_SUCCESS) { \
137+
if (code != PI_SUCCESS) { \
138138
std::string err_str = \
139139
str ? "\n" + std::string(str) + "\n" : std::string{}; \
140-
throw exc(__SYCL_OCL_ERROR_REPORT + \
140+
throw exc(__SYCL_PI_ERROR_REPORT + \
141141
cl::sycl::detail::codeToString(code) + err_str, \
142142
code); \
143143
} \
144144
}
145-
#define __SYCL_REPORT_OCL_ERR_TO_EXC_THROW(code, exc, str) \
146-
__SYCL_REPORT_OCL_ERR_TO_EXC(code, exc, str)
147-
#define __SYCL_REPORT_OCL_ERR_TO_EXC_BASE(code) \
148-
__SYCL_REPORT_OCL_ERR_TO_EXC(code, cl::sycl::runtime_error, nullptr)
145+
#define __SYCL_REPORT_PI_ERR_TO_EXC_THROW(code, exc, str) \
146+
__SYCL_REPORT_PI_ERR_TO_EXC(code, exc, str)
147+
#define __SYCL_REPORT_PI_ERR_TO_EXC_BASE(code) \
148+
__SYCL_REPORT_PI_ERR_TO_EXC(code, cl::sycl::runtime_error, nullptr)
149149
#else
150-
#define __SYCL_REPORT_OCL_ERR_TO_EXC_BASE(code) \
151-
__SYCL_REPORT_OCL_ERR_TO_STREAM(code)
150+
#define __SYCL_REPORT_PI_ERR_TO_EXC_BASE(code) \
151+
__SYCL_REPORT_PI_ERR_TO_STREAM(code)
152152
#endif
153153
// SYCL 2020 exceptions
154154
#define __SYCL_REPORT_ERR_TO_EXC_VIA_ERRC(expr, errc) \
155155
{ \
156156
auto code = expr; \
157-
if (code != CL_SUCCESS) { \
157+
if (code != PI_SUCCESS) { \
158158
throw sycl::exception(sycl::make_error_code(errc), \
159-
__SYCL_OCL_ERROR_REPORT + \
159+
__SYCL_PI_ERROR_REPORT + \
160160
cl::sycl::detail::codeToString(code)); \
161161
} \
162162
}
163163
#define __SYCL_REPORT_ERR_TO_EXC_THROW_VIA_ERRC(code, errc) \
164164
__SYCL_REPORT_ERR_TO_EXC_VIA_ERRC(code, errc)
165165

166-
#ifdef __SYCL_SUPPRESS_OCL_ERROR_REPORT
166+
#ifdef __SYCL_SUPPRESS_PI_ERROR_REPORT
167167
// SYCL 1.2.1 exceptions
168168
#define __SYCL_CHECK_OCL_CODE(X) (void)(X)
169169
#define __SYCL_CHECK_OCL_CODE_THROW(X, EXC, STR) \
@@ -176,10 +176,10 @@ static inline std::string codeToString(cl_int code) {
176176
#define __SYCL_CHECK_CODE_THROW_VIA_ERRC(X, ERRC) (void)(X)
177177
#else
178178
// SYCL 1.2.1 exceptions
179-
#define __SYCL_CHECK_OCL_CODE(X) __SYCL_REPORT_OCL_ERR_TO_EXC_BASE(X)
179+
#define __SYCL_CHECK_OCL_CODE(X) __SYCL_REPORT_PI_ERR_TO_EXC_BASE(X)
180180
#define __SYCL_CHECK_OCL_CODE_THROW(X, EXC, STR) \
181-
__SYCL_REPORT_OCL_ERR_TO_EXC_THROW(X, EXC, STR)
182-
#define __SYCL_CHECK_OCL_CODE_NO_EXC(X) __SYCL_REPORT_OCL_ERR_TO_STREAM(X)
181+
__SYCL_REPORT_PI_ERR_TO_EXC_THROW(X, EXC, STR)
182+
#define __SYCL_CHECK_OCL_CODE_NO_EXC(X) __SYCL_REPORT_PI_ERR_TO_STREAM(X)
183183
// SYCL 2020 exceptions
184184
#define __SYCL_CHECK_CODE_THROW_VIA_ERRC(X, ERRC) \
185185
__SYCL_REPORT_ERR_TO_EXC_THROW_VIA_ERRC(X, ERRC)

sycl/include/CL/sycl/detail/host_profiling_info.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ namespace detail {
1717

1818
/// Profiling info for the host execution.
1919
class __SYCL_EXPORT HostProfilingInfo {
20-
cl_ulong StartTime = 0;
21-
cl_ulong EndTime = 0;
20+
uint64_t StartTime = 0;
21+
uint64_t EndTime = 0;
2222

2323
public:
2424
/// Returns event's start time.
2525
///
2626
/// \return event's start time in nanoseconds.
27-
cl_ulong getStartTime() const { return StartTime; }
27+
uint64_t getStartTime() const { return StartTime; }
2828
/// Returns event's end time.
2929
///
3030
/// \return event's end time in nanoseconds.
31-
cl_ulong getEndTime() const { return EndTime; }
31+
uint64_t getEndTime() const { return EndTime; }
3232

3333
/// Measures event's start time.
3434
void start();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#pragma once
1010

1111
#include <CL/sycl/access/access.hpp>
12-
#include <CL/sycl/detail/cl.h>
1312
#include <CL/sycl/detail/export.hpp>
1413
#include <CL/sycl/detail/sycl_mem_obj_i.hpp>
1514
#include <CL/sycl/id.hpp>

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

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -102,56 +102,12 @@ using pi_native_handle = uintptr_t;
102102
// for PI <-> OpenCL ways. The PI <-> to other BE translation is almost
103103
// always needed anyway.
104104
//
105-
// TODO: populate PI enums.
106-
//
107105
typedef enum {
108-
PI_SUCCESS = 0,
109-
PI_ERROR_INVALID_KERNEL_NAME = -46,
110-
PI_ERROR_INVALID_OPERATION = -59,
111-
PI_ERROR_INVALID_KERNEL = -48,
112-
PI_ERROR_INVALID_QUEUE_PROPERTIES = -35,
113-
PI_ERROR_INVALID_VALUE = -30,
114-
PI_ERROR_INVALID_CONTEXT = -34,
115-
PI_ERROR_INVALID_PLATFORM = -32,
116-
PI_ERROR_INVALID_DEVICE = -33,
117-
PI_ERROR_INVALID_BINARY = -42,
118-
PI_ERROR_INVALID_QUEUE = -36,
119-
PI_ERROR_OUT_OF_HOST_MEMORY = -6,
120-
PI_ERROR_INVALID_PROGRAM = -44,
121-
PI_ERROR_INVALID_PROGRAM_EXECUTABLE = -45,
122-
PI_ERROR_INVALID_SAMPLER = -41,
123-
PI_ERROR_INVALID_BUFFER_SIZE = -61,
124-
PI_ERROR_INVALID_MEM_OBJECT = -38,
125-
PI_ERROR_OUT_OF_RESOURCES = -5,
126-
PI_ERROR_INVALID_EVENT = -58,
127-
PI_ERROR_INVALID_EVENT_WAIT_LIST = -57,
128-
PI_ERROR_MISALIGNED_SUB_BUFFER_OFFSET = -13,
129-
PI_ERROR_BUILD_PROGRAM_FAILURE = -11,
130-
PI_ERROR_INVALID_WORK_GROUP_SIZE = -54,
131-
PI_ERROR_COMPILER_NOT_AVAILABLE = -3,
132-
PI_ERROR_PROFILING_INFO_NOT_AVAILABLE = -7,
133-
PI_ERROR_DEVICE_NOT_FOUND = -1,
134-
PI_ERROR_INVALID_WORK_ITEM_SIZE = -55,
135-
PI_ERROR_INVALID_WORK_DIMENSION = -53,
136-
PI_ERROR_INVALID_KERNEL_ARGS = -52,
137-
PI_ERROR_INVALID_IMAGE_SIZE = -40,
138-
PI_ERROR_INVALID_ARG_VALUE = -50,
139-
PI_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR = -39,
140-
PI_ERROR_IMAGE_FORMAT_NOT_SUPPORTED = -10,
141-
PI_ERROR_MEM_OBJECT_ALLOCATION_FAILURE = -4,
142-
PI_ERROR_LINK_PROGRAM_FAILURE = -17,
143-
PI_ERROR_PLUGIN_SPECIFIC_ERROR =
144-
-996, ///< PI_ERROR_PLUGIN_SPECIFIC_ERROR indicates
145-
///< that an backend spcific error or
146-
///< warning has been emitted by the plugin.
147-
PI_ERROR_COMMAND_EXECUTION_FAILURE =
148-
-997, ///< PI_ERROR_COMMAND_EXECUTION_FAILURE indicates an error occurred
149-
///< during command enqueue or execution.
150-
PI_ERROR_FUNCTION_ADDRESS_IS_NOT_AVAILABLE =
151-
-998, ///< PI_ERROR_FUNCTION_ADDRESS_IS_NOT_AVAILABLE indicates a fallback
152-
///< method determines the function exists but its address cannot be
153-
///< found.
154-
PI_ERROR_UNKNOWN = -999
106+
#define _PI_ERRC(NAME, VAL) NAME = VAL,
107+
#define _PI_ERRC_WITH_MSG(NAME, VAL, MSG) NAME = VAL,
108+
#include <CL/sycl/detail/pi_error.def>
109+
#undef _PI_ERRC
110+
#undef _PI_ERRC_WITH_MSG
155111
} _pi_result;
156112

157113
typedef enum {
@@ -199,8 +155,9 @@ typedef enum : pi_uint64 {
199155
PI_DEVICE_TYPE_ALL = 0xFFFFFFFF, ///< All devices available in the PI plugin.
200156
PI_DEVICE_TYPE_CPU = (1 << 1), ///< A PI device that is the host processor.
201157
PI_DEVICE_TYPE_GPU = (1 << 2), ///< A PI device that is a GPU.
202-
PI_DEVICE_TYPE_ACC = (1 << 3) ///< A PI device that is a
158+
PI_DEVICE_TYPE_ACC = (1 << 3), ///< A PI device that is a
203159
///< dedicated accelerator.
160+
PI_DEVICE_TYPE_CUSTOM = (1 << 4) ///< A PI device that is a custom device.
204161
} _pi_device_type;
205162

206163
typedef enum {
@@ -340,6 +297,7 @@ typedef enum {
340297

341298
typedef enum {
342299
PI_CONTEXT_INFO_DEVICES = 0x1081,
300+
PI_CONTEXT_INFO_PLATFORM = 0x1084,
343301
PI_CONTEXT_INFO_NUM_DEVICES = 0x1083,
344302
PI_CONTEXT_INFO_PROPERTIES = 0x1082,
345303
PI_CONTEXT_INFO_REFERENCE_COUNT = 0x1080,
@@ -377,16 +335,6 @@ typedef enum {
377335
PI_KERNEL_GROUP_INFO_NUM_REGS = 0x10112
378336
} _pi_kernel_group_info;
379337

380-
typedef enum {
381-
PI_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT = (1 << 7),
382-
PI_FP_ROUND_TO_NEAREST = (1 << 2),
383-
PI_FP_ROUND_TO_ZERO = (1 << 3),
384-
PI_FP_ROUND_TO_INF = (1 << 4),
385-
PI_FP_INF_NAN = (1 << 1),
386-
PI_FP_DENORM = (1 << 0),
387-
PI_FP_FMA = (1 << 5)
388-
} _pi_fp_capabilities;
389-
390338
typedef enum {
391339
PI_IMAGE_INFO_FORMAT = 0x1110,
392340
PI_IMAGE_INFO_ELEMENT_SIZE = 0x1111,
@@ -627,7 +575,6 @@ using pi_image_info = _pi_image_info;
627575
using pi_kernel_info = _pi_kernel_info;
628576
using pi_kernel_group_info = _pi_kernel_group_info;
629577
using pi_kernel_sub_group_info = _pi_kernel_sub_group_info;
630-
using pi_fp_capabilities = _pi_fp_capabilities;
631578
using pi_event_info = _pi_event_info;
632579
using pi_command_type = _pi_command_type;
633580
using pi_mem_type = _pi_mem_type;
@@ -649,16 +596,45 @@ using pi_profiling_info = _pi_profiling_info;
649596
using pi_device_partition_property = intptr_t;
650597
static constexpr pi_device_partition_property PI_DEVICE_PARTITION_EQUALLY =
651598
0x1086;
599+
static constexpr pi_device_partition_property PI_DEVICE_PARTITION_BY_COUNTS =
600+
0x1087;
601+
static constexpr pi_device_partition_property
602+
PI_DEVICE_PARTITION_BY_COUNTS_LIST_END = 0x0;
652603
static constexpr pi_device_partition_property
653604
PI_DEVICE_PARTITION_BY_AFFINITY_DOMAIN = 0x1088;
654605

655606
// For compatibility with OpenCL define this not as enum.
656607
using pi_device_affinity_domain = pi_bitfield;
657608
static constexpr pi_device_affinity_domain PI_DEVICE_AFFINITY_DOMAIN_NUMA =
658609
(1 << 0);
610+
static constexpr pi_device_affinity_domain PI_DEVICE_AFFINITY_DOMAIN_L4_CACHE =
611+
(1 << 1);
612+
static constexpr pi_device_affinity_domain PI_DEVICE_AFFINITY_DOMAIN_L3_CACHE =
613+
(1 << 2);
614+
static constexpr pi_device_affinity_domain PI_DEVICE_AFFINITY_DOMAIN_L2_CACHE =
615+
(1 << 3);
616+
static constexpr pi_device_affinity_domain PI_DEVICE_AFFINITY_DOMAIN_L1_CACHE =
617+
(1 << 4);
659618
static constexpr pi_device_affinity_domain
660619
PI_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE = (1 << 5);
661620

621+
// For compatibility with OpenCL define this not as enum.
622+
using pi_device_fp_config = pi_bitfield;
623+
static constexpr pi_device_fp_config PI_FP_DENORM = (1 << 0);
624+
static constexpr pi_device_fp_config PI_FP_INF_NAN = (1 << 1);
625+
static constexpr pi_device_fp_config PI_FP_ROUND_TO_NEAREST = (1 << 2);
626+
static constexpr pi_device_fp_config PI_FP_ROUND_TO_ZERO = (1 << 3);
627+
static constexpr pi_device_fp_config PI_FP_ROUND_TO_INF = (1 << 4);
628+
static constexpr pi_device_fp_config PI_FP_FMA = (1 << 5);
629+
static constexpr pi_device_fp_config PI_FP_SOFT_FLOAT = (1 << 6);
630+
static constexpr pi_device_fp_config PI_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT =
631+
(1 << 7);
632+
633+
// For compatibility with OpenCL define this not as enum.
634+
using pi_device_exec_capabilities = pi_bitfield;
635+
static constexpr pi_device_exec_capabilities PI_EXEC_KERNEL = (1 << 0);
636+
static constexpr pi_device_exec_capabilities PI_EXEC_NATIVE_KERNEL = (1 << 1);
637+
662638
// Entry type, matches OpenMP for compatibility
663639
struct _pi_offload_entry_struct {
664640
void *addr;

0 commit comments

Comments
 (0)