Skip to content

[SYCL][PI] Removal of PI_CALL family of macros & implementation of Plugin_impl class #1030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 10, 2020
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
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ class buffer {
: Range{0} {

size_t BufSize = 0;
PI_CALL(piMemGetInfo)(detail::pi::cast<detail::RT::PiMem>(MemObject),
CL_MEM_SIZE, sizeof(size_t), &BufSize, nullptr);
const detail::plugin &Plugin = detail::getSyclObjImpl(SyclContext)->getPlugin();
Plugin.call<detail::PiApiKind::piMemGetInfo>(
Copy link
Contributor

Choose a reason for hiding this comment

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

What about adding some free functions to avoid explicitly extracting PI Plugin every time? Something like:

template <detail::PiApiKind API, typename... Args>
pi_call(const context &SYCLContext, Args...) {
  auto Plugin = detail::getSYCLObjImpl(SYCLContext)->getPlugin();
  Plugin.call<API>(Args...);
}
// overloads for device, event and other SYCL RT classes

// On call site:
pi_call<detail::PiApiKind::piMemGetInfo>(SyclContext, /* rest of the args */);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We wanted to avoid making such calls that takes an extra argument beyond the arguments of the function call.
It should look like a function call.
Also, what is the benefit over the existing call format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AlexeySachkov any comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, what is the benefit over the existing call format?

In most cases in this PR, call to a plugin performed only once, so suggested format can save you one line at most of call sites.

We wanted to avoid making such calls that takes an extra argument beyond the arguments of the function call.
It should look like a function call.

I'm not pushing towards my suggestion, this was just an idea. If the intent was to make this call as close as possible to actual call which will be performed under the hood, then let it be. I don't have objections against it

detail::pi::cast<detail::RT::PiMem>(MemObject), CL_MEM_SIZE,
sizeof(size_t), &BufSize, nullptr);

Range[0] = BufSize / sizeof(T);
impl = std::make_shared<detail::buffer_impl>(
Expand Down
11 changes: 10 additions & 1 deletion sycl/include/CL/sycl/detail/context_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class context_impl {
///
/// @param PiContext is an instance of a valid plug-in context handle.
/// @param AsyncHandler is an instance of async_handler.
context_impl(RT::PiContext PiContext, async_handler AsyncHandler);
/// @param &Plugin is the reference to the underlying Plugin that this context
/// is associated with.
context_impl(RT::PiContext PiContext, async_handler AsyncHandler,
const plugin &Plugin);

~context_impl();

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

/// @return the Plugin associated with the platform of this context.
const plugin &getPlugin() const { return MPlatform->getPlugin(); }

/// @return the PlatformImpl associated with this context.
PlatformImplPtr getPlatformImpl() const { return MPlatform; }

/// Queries this context for information.
///
/// The return type depends on information being queried.
Expand Down
8 changes: 5 additions & 3 deletions sycl/include/CL/sycl/detail/context_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/context_impl.hpp>
#include <CL/sycl/info/info_desc.hpp>

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

static RetType get(RT::PiContext ctx) {
static RetType get(RT::PiContext ctx, const plugin &Plugin) {
RetType Result = 0;
// TODO catch an exception and put it to list of asynchronous exceptions
PI_CALL(piContextGetInfo)(ctx, pi::cast<pi_context_info>(param),
sizeof(Result), &Result, nullptr);
Plugin.call<PiApiKind::piContextGetInfo>(ctx,
pi::cast<pi_context_info>(param),
sizeof(Result), &Result, nullptr);
return Result;
}
};
Expand Down
17 changes: 14 additions & 3 deletions sycl/include/CL/sycl/detail/device_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ namespace detail {

// Forward declaration
class platform_impl;
class platform_impl_pi;
using PlatformImplPtr = std::shared_ptr<platform_impl>;

// TODO: Make code thread-safe
class device_impl {
public:
/// Constructs a SYCL device instance as a host device.
device_impl();

/// Constructs a SYCL device instance using the provided
/// PI device instance.
explicit device_impl(RT::PiDevice Device);
explicit device_impl(RT::PiDevice Device, PlatformImplPtr Platform);

/// Constructs a SYCL device instance using the provided
/// PI device instance.
explicit device_impl(RT::PiDevice Device, const plugin &Plugin);

~device_impl();

Expand Down Expand Up @@ -100,6 +105,9 @@ class device_impl {
/// @return The associated SYCL platform.
platform get_platform() const;

/// @return the associated plugin with this device.
const plugin &getPlugin() const { return MPlatform->getPlugin(); }

/// Check SYCL extension support by device
///
/// @param ExtensionName is a name of queried extension.
Expand Down Expand Up @@ -165,7 +173,7 @@ class device_impl {
}
return get_device_info<
typename info::param_traits<info::device, param>::return_type,
param>::get(this->getHandleRef());
param>::get(this->getHandleRef(), this->getPlugin());
}

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

private:
explicit device_impl(RT::PiDevice Device, PlatformImplPtr Platform,
const plugin &Plugin);
RT::PiDevice MDevice = 0;
RT::PiDeviceType MType;
bool MIsRootDevice = false;
bool MIsHostDevice;
PlatformImplPtr MPlatform;
}; // class device_impl

} // namespace detail
Expand Down
Loading