Skip to content

Commit 82e9712

Browse files
committed
[SYCL] populate PI (and direct SYCL RT to PI)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent d39c65c commit 82e9712

Some content is hidden

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

49 files changed

+1499
-734
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Overview
2+
3+
This file describes environment variables that are having effect on SYCL compiler and run-time.
4+
5+
# Controlling SYCL RT
6+
7+
| Environment variable | Description |
8+
| ----------- | ----------- |
9+
| SYCL_PI_TRACE | If set forces tracing of PI calls to stdout. |
10+
| SYCL_BE={PI_OPENCL,PI_OTHER} | When SYCL RT is buils with PI this controls which plugin to use. |

sycl/include/CL/sycl/buffer.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ class buffer {
128128
event AvailableEvent = {}) {
129129

130130
size_t BufSize = 0;
131-
CHECK_OCL_CODE(clGetMemObjectInfo(MemObject, CL_MEM_SIZE, sizeof(size_t),
132-
&BufSize, nullptr));
131+
PI_CALL(detail::RT::piMemGetInfo(
132+
detail::pi_cast<detail::RT::PiMem>(MemObject), CL_MEM_SIZE,
133+
sizeof(size_t), &BufSize, nullptr));
134+
133135
Range[0] = BufSize / sizeof(T);
134136
MemRange[0] = BufSize / sizeof(T);
135137
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <CL/sycl/context.hpp>
1414
#include <CL/sycl/detail/aligned_allocator.hpp>
1515
#include <CL/sycl/detail/common.hpp>
16+
#include <CL/sycl/detail/pi.hpp>
1617
#include <CL/sycl/detail/helpers.hpp>
1718
#include <CL/sycl/detail/memory_manager.hpp>
1819
#include <CL/sycl/detail/scheduler/scheduler.hpp>
@@ -182,13 +183,15 @@ template <typename AllocatorT> class buffer_impl : public SYCLMemObjT {
182183
"Creation of interoperability buffer using host context is not "
183184
"allowed");
184185

185-
cl_context Context = nullptr;
186-
CHECK_OCL_CODE(clGetMemObjectInfo(MInteropMemObject, CL_MEM_CONTEXT,
187-
sizeof(Context), &Context, nullptr));
186+
RT::PiMem Mem = pi_cast<RT::PiMem>(MInteropMemObject);
187+
RT::PiContext Context = nullptr;
188+
PI_CALL(RT::piMemGetInfo(
189+
Mem, CL_MEM_CONTEXT, sizeof(Context), &Context, nullptr));
190+
188191
if (MInteropContext->getHandleRef() != Context)
189192
throw cl::sycl::invalid_parameter_error(
190193
"Input context must be the same as the context of cl_mem");
191-
CHECK_OCL_CODE(clRetainMemObject(MInteropMemObject));
194+
PI_CALL(RT::piMemRetain(Mem));
192195
}
193196

194197
size_t get_size() const { return MSizeInBytes; }
@@ -206,7 +209,7 @@ template <typename AllocatorT> class buffer_impl : public SYCLMemObjT {
206209
releaseHostMem(MShadowCopy);
207210

208211
if (MOpenCLInterop)
209-
CHECK_OCL_CODE_NO_EXC(clReleaseMemObject(MInteropMemObject));
212+
PI_CALL(RT::piMemRelease(pi_cast<RT::PiMem>(MInteropMemObject)));
210213
}
211214

212215
void set_final_data(std::nullptr_t) { MUploadDataFn = nullptr; }
@@ -243,7 +246,7 @@ template <typename AllocatorT> class buffer_impl : public SYCLMemObjT {
243246
typename std::enable_if<std::is_pointer<Destination>::value>::type * =
244247
0) {
245248
static_assert(!std::is_const<Destination>::value,
246-
"Сan not write in a constant Destination. Destination should "
249+
"Do not write in a constant Destination. Destination should "
247250
"not be const.");
248251
MUploadDataFn = [this, FinalData]() mutable {
249252

@@ -265,7 +268,7 @@ template <typename AllocatorT> class buffer_impl : public SYCLMemObjT {
265268
typename std::enable_if<!std::is_pointer<Destination>::value>::type * =
266269
0) {
267270
static_assert(!std::is_const<Destination>::value,
268-
"Сan not write in a constant Destination. Destination should "
271+
"Do not write in a constant Destination. Destination should "
269272
"not be const.");
270273
MUploadDataFn = [this, FinalData]() mutable {
271274
using FinalDataType =
@@ -340,7 +343,7 @@ template <typename AllocatorT> class buffer_impl : public SYCLMemObjT {
340343
}
341344

342345
void *allocateMem(ContextImplPtr Context, bool InitFromUserData,
343-
cl_event &OutEventToWait) override {
346+
RT::PiEvent &OutEventToWait) override {
344347

345348
void *UserPtr = InitFromUserData ? getUserPtr() : nullptr;
346349

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

+2-25
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,14 @@
1717
#include <string>
1818
#include <type_traits>
1919

20-
// Select underlying runtime interface in compile-time (OpenCL or PI).
21-
// Comment the define of the FORCE_SYCL_BE_OPENCL below to switch to PI.
22-
// As such only one path (OpenCL today) is being regularily tested.
23-
//
24-
// TODO: we can just remove this when switch to PI completely.
25-
//
26-
#define FORCE_SYCL_BE_OPENCL
27-
28-
#ifdef FORCE_SYCL_BE_OPENCL
29-
#include <CL/sycl/detail/pi_opencl.hpp>
30-
#else
31-
#include <CL/sycl/detail/pi.hpp>
32-
#endif
20+
#define STRINGIFY_LINE_HELP(s) #s
21+
#define STRINGIFY_LINE(s) STRINGIFY_LINE_HELP(s)
3322

3423
const char *stringifyErrorCode(cl_int error);
3524

3625
#define OCL_CODE_TO_STR(code) \
3726
std::string(std::to_string(code) + " (" + stringifyErrorCode(code) + ")")
3827

39-
#define STRINGIFY_LINE_HELP(s) #s
40-
#define STRINGIFY_LINE(s) STRINGIFY_LINE_HELP(s)
41-
4228
#define OCL_ERROR_REPORT \
4329
"OpenCL API failed. " __FILE__ \
4430
":" STRINGIFY_LINE(__LINE__) ": " \
@@ -92,15 +78,6 @@ namespace cl {
9278
namespace sycl {
9379
namespace detail {
9480

95-
// Select underlying runtime interface (RT) in compile-time (OpenCL or PI).
96-
// As such only one path (OpenCL today) is being regularily tested.
97-
//
98-
#ifdef FORCE_SYCL_BE_OPENCL
99-
using RT = cl::sycl::detail::opencl;
100-
#else
101-
using RT = cl::sycl::detail::pi;
102-
#endif
103-
10481
// Helper function for extracting implementation from SYCL's interface objects.
10582
// Note! This function relies on the fact that all SYCL interface classes
10683
// contain "impl" field that points to implementation object. "impl" field

sycl/include/CL/sycl/detail/context_impl.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010
#include <CL/sycl/detail/common.hpp>
11+
#include <CL/sycl/detail/pi.hpp>
1112
#include <CL/sycl/exception.hpp>
1213
#include <CL/sycl/info/info_desc.hpp>
1314
#include <CL/sycl/platform.hpp>
@@ -50,13 +51,13 @@ class context_impl {
5051
// modification. Caller must ensure the returned object lives on stack only.
5152
// It can also be safely passed to the underlying native runtime API.
5253
// Warning. Returned reference will be invalid if context_impl was destroyed.
53-
cl_context &getHandleRef();
54-
const cl_context &getHandleRef() const;
54+
RT::PiContext &getHandleRef();
55+
const RT::PiContext &getHandleRef() const;
5556

5657
private:
5758
async_handler m_AsyncHandler;
5859
vector_class<device> m_Devices;
59-
cl_context m_ClContext;
60+
RT::PiContext m_Context;
6061
platform m_Platform;
6162
bool m_OpenCLInterop;
6263
bool m_HostContext;

sycl/include/CL/sycl/detail/context_info.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ namespace cl {
1515
namespace sycl {
1616
namespace detail {
1717

18-
template <info::context param> struct get_context_info_cl {
18+
template <info::context param> struct get_context_info {
1919
using RetType =
2020
typename info::param_traits<info::context, param>::return_type;
2121

22-
static RetType _(cl_context ctx) {
22+
static RetType _(RT::PiContext ctx) {
2323
RetType Result = 0;
2424
// TODO catch an exception and put it to list of asynchronous exceptions
25-
CHECK_OCL_CODE(clGetContextInfo(ctx, cl_context_info(param), sizeof(Result),
26-
&Result, nullptr));
25+
PI_CALL(RT::piContextGetInfo(ctx, pi_cast<pi_context_info>(param),
26+
sizeof(Result), &Result, nullptr));
2727
return Result;
2828
}
2929
};

sycl/include/CL/sycl/detail/device_impl.hpp

+16-23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <CL/sycl/detail/pi.hpp>
1112
#include <CL/sycl/detail/device_info.hpp>
1213
#include <CL/sycl/stl.hpp>
1314
#include <algorithm>
@@ -34,10 +35,8 @@ class device_impl {
3435
// It can also be safely passed to the underlying native runtime API.
3536
// Warning. Returned reference will be invalid if device_impl was destroyed.
3637
//
37-
// TODO: change all uses of getHandleRef to get_handle, and remove the
38-
// getHandleRef after that.
39-
virtual cl_device_id &getHandleRef() = 0;
40-
virtual RT::pi_device get_handle() const = 0;
38+
virtual RT::PiDevice &getHandleRef() = 0;
39+
virtual const RT::PiDevice &getHandleRef() const = 0;
4140

4241
virtual bool is_host() const = 0;
4342

@@ -68,7 +67,7 @@ class device_impl {
6867
}
6968
return get_device_info<
7069
typename info::param_traits<info::device, param>::return_type,
71-
param>::_(this->get_handle());
70+
param>::_(this->getHandleRef());
7271
}
7372

7473
bool is_partition_supported(info::partition_property Prop) const {
@@ -93,15 +92,15 @@ class device_impl {
9392
// TODO: Make code thread-safe
9493
class device_impl_pi : public device_impl {
9594
public:
96-
explicit device_impl_pi(RT::pi_device a_device) : m_device(a_device) {
95+
explicit device_impl_pi(RT::PiDevice a_device) : m_device(a_device) {
9796
// TODO catch an exception and put it to list of asynchronous exceptions
9897
PI_CALL(RT::piDeviceGetInfo(
99-
m_device, PI_DEVICE_INFO_TYPE, sizeof(RT::pi_device_type), &m_type, 0));
98+
m_device, PI_DEVICE_INFO_TYPE, sizeof(RT::PiDeviceType), &m_type, 0));
10099

101-
RT::pi_device parent;
100+
RT::PiDevice parent;
102101
// TODO catch an exception and put it to list of asynchronous exceptions
103102
PI_CALL(RT::piDeviceGetInfo(
104-
m_device, PI_DEVICE_INFO_PARENT, sizeof(RT::pi_device), &parent, 0));
103+
m_device, PI_DEVICE_INFO_PARENT, sizeof(RT::PiDevice), &parent, 0));
105104

106105
m_isRootDevice = (nullptr == parent);
107106
if (!m_isRootDevice) {
@@ -126,14 +125,8 @@ class device_impl_pi : public device_impl {
126125
return pi_cast<cl_device_id>(m_device);
127126
}
128127

129-
cl_device_id &getHandleRef() override {
130-
// TODO: check that device is an OpenCL interop one before cast, or just
131-
// remove when all the users are moved to get_handle.
132-
return (cl_device_id&)(m_device);
133-
}
134-
RT::pi_device get_handle() const override {
135-
return m_device;
136-
}
128+
RT::PiDevice &getHandleRef() override { return m_device; }
129+
const RT::PiDevice &getHandleRef() const override { return m_device; }
137130

138131
bool is_host() const override { return false; }
139132

@@ -146,7 +139,7 @@ class device_impl_pi : public device_impl {
146139
}
147140

148141
platform get_platform() const override {
149-
RT::pi_platform plt;
142+
RT::PiPlatform plt;
150143
// TODO catch an exception and put it to list of asynchronous exceptions
151144
PI_CALL(RT::piDeviceGetInfo(
152145
m_device, PI_DEVICE_INFO_PLATFORM, sizeof(plt), &plt, 0));
@@ -178,8 +171,8 @@ class device_impl_pi : public device_impl {
178171
create_sub_devices(info::partition_affinity_domain AffinityDomain) const override;
179172

180173
private:
181-
RT::pi_device m_device = 0;
182-
RT::pi_device_type m_type;
174+
RT::PiDevice m_device = 0;
175+
RT::PiDeviceType m_type;
183176
bool m_isRootDevice = false;
184177
}; // class device_impl_pi
185178

@@ -192,11 +185,11 @@ class device_host : public device_impl {
192185
cl_device_id get() const override {
193186
throw invalid_object_error("This instance of device is a host instance");
194187
}
195-
cl_device_id &getHandleRef() override {
188+
RT::PiDevice &getHandleRef() override {
196189
throw invalid_object_error("This instance of device is a host instance");
197190
}
198-
RT::pi_device get_handle() const override {
199-
pi_die("This instance of device is a host instance");
191+
const RT::PiDevice &getHandleRef() const override {
192+
throw invalid_object_error("This instance of device is a host instance");
200193
}
201194

202195
bool is_host() const override { return true; }

0 commit comments

Comments
 (0)