Skip to content

Commit 95652d4

Browse files
authored
[SYCL][PI] Replace PI_CALL family of macros with new plugin_impl class (#1030)
The changeset removes the family of PI_CALL macros, and replaces them with call API in a new plugin_impl class. The object of this class is stored in Platform class. When multiple platforms are associated with the same Plugin, they will have shared_ptr to the same plugin_impl object. Eg: An OpenCLPlugin can have multiple platforms attached to it. To effectively use this change, following additional fetaures/changes were added: - To make access to the plugin_impl class easy, getPlugin() API has been introduced to some *_impl classes, that eventually call the platform_impl->getPlugin() API. It has been included in context_impl, event_impl, kernel_impl, platform_impl, program_impl, queue_impl. Is not present in accessor_impl(Does not call PI), buffer_impl (Needs only in the constructor where context is passed), sampler_impl (Does not have a single context), stream_impl (Does not call PI), usm_impl (Has no member sycl_impl objects.) The API returns const reference to plugin_impl class. - Use of PiApiKind enum to uniquely identify the PI API. - PI API calls are done using : plugin_impl.call, plugin_impl.call_nocheck, plugin_impl.checkPiResult<Exception> - GlobalPlugin is a SharedPtr to a globally available Plugin for the use with Interoperability Constructors. It is used as a shared_ptr to avoid making copies of it. - Changes in *_info structs and get() methods. They now take a const plugin_impl& argument. - To make Pi Api calls by host to check if certain events are finished on a device, the plugin_impl class is needed. At such places, event_impl is passed instead of a PiEvent. Eg: memory_manager.cpp - The use of Global variable has been restricted to only the GlobalPlugin now. Signed-off-by: Garima Gupta <[email protected]>
1 parent 1de18ea commit 95652d4

Some content is hidden

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

50 files changed

+1048
-756
lines changed

sycl/include/CL/sycl/buffer.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ class buffer {
195195
: Range{0} {
196196

197197
size_t BufSize = 0;
198-
PI_CALL(piMemGetInfo)(detail::pi::cast<detail::RT::PiMem>(MemObject),
199-
CL_MEM_SIZE, sizeof(size_t), &BufSize, nullptr);
198+
const detail::plugin &Plugin = detail::getSyclObjImpl(SyclContext)->getPlugin();
199+
Plugin.call<detail::PiApiKind::piMemGetInfo>(
200+
detail::pi::cast<detail::RT::PiMem>(MemObject), CL_MEM_SIZE,
201+
sizeof(size_t), &BufSize, nullptr);
200202

201203
Range[0] = BufSize / sizeof(T);
202204
impl = std::make_shared<detail::buffer_impl>(

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ class context_impl {
5959
///
6060
/// @param PiContext is an instance of a valid plug-in context handle.
6161
/// @param AsyncHandler is an instance of async_handler.
62-
context_impl(RT::PiContext PiContext, async_handler AsyncHandler);
62+
/// @param &Plugin is the reference to the underlying Plugin that this context
63+
/// is associated with.
64+
context_impl(RT::PiContext PiContext, async_handler AsyncHandler,
65+
const plugin &Plugin);
6366

6467
~context_impl();
6568

@@ -78,6 +81,12 @@ class context_impl {
7881
/// @return an instance of SYCL async_handler.
7982
const async_handler &get_async_handler() const;
8083

84+
/// @return the Plugin associated with the platform of this context.
85+
const plugin &getPlugin() const { return MPlatform->getPlugin(); }
86+
87+
/// @return the PlatformImpl associated with this context.
88+
PlatformImplPtr getPlatformImpl() const { return MPlatform; }
89+
8190
/// Queries this context for information.
8291
///
8392
/// The return type depends on information being queried.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <CL/sycl/detail/common.hpp>
12+
#include <CL/sycl/detail/context_impl.hpp>
1213
#include <CL/sycl/info/info_desc.hpp>
1314

1415
__SYCL_INLINE namespace cl {
@@ -19,11 +20,12 @@ template <info::context param> struct get_context_info {
1920
using RetType =
2021
typename info::param_traits<info::context, param>::return_type;
2122

22-
static RetType get(RT::PiContext ctx) {
23+
static RetType get(RT::PiContext ctx, const plugin &Plugin) {
2324
RetType Result = 0;
2425
// TODO catch an exception and put it to list of asynchronous exceptions
25-
PI_CALL(piContextGetInfo)(ctx, pi::cast<pi_context_info>(param),
26-
sizeof(Result), &Result, nullptr);
26+
Plugin.call<PiApiKind::piContextGetInfo>(ctx,
27+
pi::cast<pi_context_info>(param),
28+
sizeof(Result), &Result, nullptr);
2729
return Result;
2830
}
2931
};

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ namespace detail {
2323

2424
// Forward declaration
2525
class platform_impl;
26-
class platform_impl_pi;
26+
using PlatformImplPtr = std::shared_ptr<platform_impl>;
2727

2828
// TODO: Make code thread-safe
2929
class device_impl {
3030
public:
3131
/// Constructs a SYCL device instance as a host device.
3232
device_impl();
33+
3334
/// Constructs a SYCL device instance using the provided
3435
/// PI device instance.
35-
explicit device_impl(RT::PiDevice Device);
36+
explicit device_impl(RT::PiDevice Device, PlatformImplPtr Platform);
37+
38+
/// Constructs a SYCL device instance using the provided
39+
/// PI device instance.
40+
explicit device_impl(RT::PiDevice Device, const plugin &Plugin);
3641

3742
~device_impl();
3843

@@ -100,6 +105,9 @@ class device_impl {
100105
/// @return The associated SYCL platform.
101106
platform get_platform() const;
102107

108+
/// @return the associated plugin with this device.
109+
const plugin &getPlugin() const { return MPlatform->getPlugin(); }
110+
103111
/// Check SYCL extension support by device
104112
///
105113
/// @param ExtensionName is a name of queried extension.
@@ -165,7 +173,7 @@ class device_impl {
165173
}
166174
return get_device_info<
167175
typename info::param_traits<info::device, param>::return_type,
168-
param>::get(this->getHandleRef());
176+
param>::get(this->getHandleRef(), this->getPlugin());
169177
}
170178

171179
/// Check if affinity partitioning by specified domain is supported by device
@@ -176,10 +184,13 @@ class device_impl {
176184
is_affinity_supported(info::partition_affinity_domain AffinityDomain) const;
177185

178186
private:
187+
explicit device_impl(RT::PiDevice Device, PlatformImplPtr Platform,
188+
const plugin &Plugin);
179189
RT::PiDevice MDevice = 0;
180190
RT::PiDeviceType MType;
181191
bool MIsRootDevice = false;
182192
bool MIsHostDevice;
193+
PlatformImplPtr MPlatform;
183194
}; // class device_impl
184195

185196
} // namespace detail

0 commit comments

Comments
 (0)