Skip to content
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

[SYCL] Rename Plugin object -> Adapter. #15363

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions sycl/include/sycl/detail/ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ __SYCL_EXPORT void contextSetExtendedDeleter(const sycl::context &constext,
void *user_data);
}

class plugin;
using PluginPtr = std::shared_ptr<plugin>;
class Adapter;
using AdapterPtr = std::shared_ptr<Adapter>;

// TODO: To be removed as this was only introduced for esimd which was removed.
template <sycl::backend BE>
Expand All @@ -126,11 +126,11 @@ void *getOsLibraryFuncAddress(void *Library, const std::string &FunctionName);
void *getURLoaderLibrary();

// Performs UR one-time initialization.
std::vector<PluginPtr> &
std::vector<AdapterPtr> &
initializeUr(ur_loader_config_handle_t LoaderConfig = nullptr);

// Get the plugin serving given backend.
template <backend BE> const PluginPtr &getPlugin();
// Get the adapter serving given backend.
template <backend BE> const AdapterPtr &getAdapter();

// The SYCL_UR_TRACE sets what we will trace.
// This is a bit-mask of various things we'd want to trace.
Expand Down
8 changes: 4 additions & 4 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,16 +768,16 @@ class __SYCL_EXPORT handler {
int ArgIndex);

/* The kernel passed to StoreLambda can take an id, an item or an nd_item as
* its argument. Since esimd plugin directly invokes the kernel (doesn’t use
* piKernelSetArg), the kernel argument type must be known to the plugin.
* However, passing kernel argument type to the plugin requires changing ABI
* its argument. Since esimd adapter directly invokes the kernel (doesn’t use
* urKernelSetArg), the kernel argument type must be known to the adapter.
* However, passing kernel argument type to the adapter requires changing ABI
* in HostKernel class. To overcome this problem, helpers below wrap the
* “original” kernel with a functor that always takes an nd_item as argument.
* A functor is used instead of a lambda because extractArgsAndReqsFromLambda
* needs access to the “original” kernel and keeps references to its internal
* data, i.e. the kernel passed as argument cannot be local in scope. The
* functor itself is again encapsulated in a std::function since functor’s
* type is unknown to the plugin.
* type is unknown to the adapter.
*/

// For 'id, item w/wo offset, nd_item' kernel arguments
Expand Down
88 changes: 44 additions & 44 deletions sycl/source/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//

#include "detail/adapter.hpp"
#include "detail/context_impl.hpp"
#include "detail/event_impl.hpp"
#include "detail/kernel_bundle_impl.hpp"
#include "detail/kernel_id_impl.hpp"
#include "detail/platform_impl.hpp"
#include "detail/plugin.hpp"
#include "detail/queue_impl.hpp"
#include "sycl/detail/impl_utils.hpp"
#include <sycl/backend.hpp>
Expand All @@ -29,20 +29,20 @@ namespace sycl {
inline namespace _V1 {
namespace detail {

static const PluginPtr &getPlugin(backend Backend) {
static const AdapterPtr &getAdapter(backend Backend) {
switch (Backend) {
case backend::opencl:
return ur::getPlugin<backend::opencl>();
return ur::getAdapter<backend::opencl>();
case backend::ext_oneapi_level_zero:
return ur::getPlugin<backend::ext_oneapi_level_zero>();
return ur::getAdapter<backend::ext_oneapi_level_zero>();
case backend::ext_oneapi_cuda:
return ur::getPlugin<backend::ext_oneapi_cuda>();
return ur::getAdapter<backend::ext_oneapi_cuda>();
case backend::ext_oneapi_hip:
return ur::getPlugin<backend::ext_oneapi_hip>();
return ur::getAdapter<backend::ext_oneapi_hip>();
default:
throw sycl::exception(
sycl::make_error_code(sycl::errc::runtime),
"getPlugin: Unsupported backend " +
"getAdapter: Unsupported backend " +
detail::codeToString(UR_RESULT_ERROR_INVALID_OPERATION));
}
}
Expand All @@ -68,34 +68,34 @@ backend convertUrBackend(ur_platform_backend_t UrBackend) {
}

platform make_platform(ur_native_handle_t NativeHandle, backend Backend) {
const auto &Plugin = getPlugin(Backend);
const auto &Adapter = getAdapter(Backend);

// Create UR platform first.
ur_platform_handle_t UrPlatform = nullptr;
Plugin->call<UrApiKind::urPlatformCreateWithNativeHandle>(
NativeHandle, Plugin->getUrAdapter(), nullptr, &UrPlatform);
Adapter->call<UrApiKind::urPlatformCreateWithNativeHandle>(
NativeHandle, Adapter->getUrAdapter(), nullptr, &UrPlatform);

return detail::createSyclObjFromImpl<platform>(
platform_impl::getOrMakePlatformImpl(UrPlatform, Plugin));
platform_impl::getOrMakePlatformImpl(UrPlatform, Adapter));
}

__SYCL_EXPORT device make_device(ur_native_handle_t NativeHandle,
backend Backend) {
const auto &Plugin = getPlugin(Backend);
const auto &Adapter = getAdapter(Backend);

ur_device_handle_t UrDevice = nullptr;
Plugin->call<UrApiKind::urDeviceCreateWithNativeHandle>(
NativeHandle, Plugin->getUrAdapter(), nullptr, &UrDevice);
Adapter->call<UrApiKind::urDeviceCreateWithNativeHandle>(
NativeHandle, Adapter->getUrAdapter(), nullptr, &UrDevice);
// Construct the SYCL device from UR device.
return detail::createSyclObjFromImpl<device>(
std::make_shared<device_impl>(UrDevice, Plugin));
std::make_shared<device_impl>(UrDevice, Adapter));
}

__SYCL_EXPORT context make_context(ur_native_handle_t NativeHandle,
const async_handler &Handler,
backend Backend, bool KeepOwnership,
const std::vector<device> &DeviceList) {
const auto &Plugin = getPlugin(Backend);
const auto &Adapter = getAdapter(Backend);

ur_context_handle_t UrContext = nullptr;
ur_context_native_properties_t Properties{};
Expand All @@ -105,12 +105,12 @@ __SYCL_EXPORT context make_context(ur_native_handle_t NativeHandle,
for (const auto &Dev : DeviceList) {
DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef());
}
Plugin->call<UrApiKind::urContextCreateWithNativeHandle>(
NativeHandle, Plugin->getUrAdapter(), DeviceHandles.size(),
Adapter->call<UrApiKind::urContextCreateWithNativeHandle>(
NativeHandle, Adapter->getUrAdapter(), DeviceHandles.size(),
DeviceHandles.data(), &Properties, &UrContext);
// Construct the SYCL context from UR context.
return detail::createSyclObjFromImpl<context>(std::make_shared<context_impl>(
UrContext, Handler, Plugin, DeviceList, !KeepOwnership));
UrContext, Handler, Adapter, DeviceList, !KeepOwnership));
}

__SYCL_EXPORT queue make_queue(ur_native_handle_t NativeHandle,
Expand All @@ -120,7 +120,7 @@ __SYCL_EXPORT queue make_queue(ur_native_handle_t NativeHandle,
const async_handler &Handler, backend Backend) {
ur_device_handle_t UrDevice =
Device ? getSyclObjImpl(*Device)->getHandleRef() : nullptr;
const auto &Plugin = getPlugin(Backend);
const auto &Adapter = getAdapter(Backend);
const auto &ContextImpl = getSyclObjImpl(Context);

if (PropList.has_property<ext::intel::property::queue::compute_index>()) {
Expand Down Expand Up @@ -150,7 +150,7 @@ __SYCL_EXPORT queue make_queue(ur_native_handle_t NativeHandle,
// Create UR queue first.
ur_queue_handle_t UrQueue = nullptr;

Plugin->call<UrApiKind::urQueueCreateWithNativeHandle>(
Adapter->call<UrApiKind::urQueueCreateWithNativeHandle>(
NativeHandle, ContextImpl->getHandleRef(), UrDevice, &NativeProperties,
&UrQueue);
// Construct the SYCL queue from UR queue.
Expand All @@ -166,82 +166,82 @@ __SYCL_EXPORT event make_event(ur_native_handle_t NativeHandle,
__SYCL_EXPORT event make_event(ur_native_handle_t NativeHandle,
const context &Context, bool KeepOwnership,
backend Backend) {
const auto &Plugin = getPlugin(Backend);
const auto &Adapter = getAdapter(Backend);
const auto &ContextImpl = getSyclObjImpl(Context);

ur_event_handle_t UrEvent = nullptr;
ur_event_native_properties_t Properties{};
Properties.stype = UR_STRUCTURE_TYPE_EVENT_NATIVE_PROPERTIES;
Properties.isNativeHandleOwned = !KeepOwnership;

Plugin->call<UrApiKind::urEventCreateWithNativeHandle>(
Adapter->call<UrApiKind::urEventCreateWithNativeHandle>(
NativeHandle, ContextImpl->getHandleRef(), &Properties, &UrEvent);
event Event = detail::createSyclObjFromImpl<event>(
std::make_shared<event_impl>(UrEvent, Context));

if (Backend == backend::opencl)
Plugin->call<UrApiKind::urEventRetain>(UrEvent);
Adapter->call<UrApiKind::urEventRetain>(UrEvent);
return Event;
}

std::shared_ptr<detail::kernel_bundle_impl>
make_kernel_bundle(ur_native_handle_t NativeHandle,
const context &TargetContext, bool KeepOwnership,
bundle_state State, backend Backend) {
const auto &Plugin = getPlugin(Backend);
const auto &Adapter = getAdapter(Backend);
const auto &ContextImpl = getSyclObjImpl(TargetContext);

ur_program_handle_t UrProgram = nullptr;
ur_program_native_properties_t Properties{};
Properties.stype = UR_STRUCTURE_TYPE_PROGRAM_NATIVE_PROPERTIES;
Properties.isNativeHandleOwned = !KeepOwnership;

Plugin->call<UrApiKind::urProgramCreateWithNativeHandle>(
Adapter->call<UrApiKind::urProgramCreateWithNativeHandle>(
NativeHandle, ContextImpl->getHandleRef(), &Properties, &UrProgram);
if (UrProgram == nullptr)
throw sycl::exception(
sycl::make_error_code(sycl::errc::invalid),
"urProgramCreateWithNativeHandle resulted in a null program handle.");

if (ContextImpl->getBackend() == backend::opencl)
Plugin->call<UrApiKind::urProgramRetain>(UrProgram);
Adapter->call<UrApiKind::urProgramRetain>(UrProgram);

std::vector<ur_device_handle_t> ProgramDevices;
uint32_t NumDevices = 0;

Plugin->call<UrApiKind::urProgramGetInfo>(
Adapter->call<UrApiKind::urProgramGetInfo>(
UrProgram, UR_PROGRAM_INFO_NUM_DEVICES, sizeof(NumDevices), &NumDevices,
nullptr);
ProgramDevices.resize(NumDevices);
Plugin->call<UrApiKind::urProgramGetInfo>(
Adapter->call<UrApiKind::urProgramGetInfo>(
UrProgram, UR_PROGRAM_INFO_DEVICES,
sizeof(ur_device_handle_t) * NumDevices, ProgramDevices.data(), nullptr);

for (auto &Dev : ProgramDevices) {
ur_program_binary_type_t BinaryType;
Plugin->call<UrApiKind::urProgramGetBuildInfo>(
Adapter->call<UrApiKind::urProgramGetBuildInfo>(
UrProgram, Dev, UR_PROGRAM_BUILD_INFO_BINARY_TYPE,
sizeof(ur_program_binary_type_t), &BinaryType, nullptr);
switch (BinaryType) {
case (UR_PROGRAM_BINARY_TYPE_NONE):
if (State == bundle_state::object) {
auto Res = Plugin->call_nocheck<UrApiKind::urProgramCompileExp>(
auto Res = Adapter->call_nocheck<UrApiKind::urProgramCompileExp>(
UrProgram, 1, &Dev, nullptr);
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
Res = Plugin->call_nocheck<UrApiKind::urProgramCompile>(
Res = Adapter->call_nocheck<UrApiKind::urProgramCompile>(
ContextImpl->getHandleRef(), UrProgram, nullptr);
}
Plugin->checkUrResult<errc::build>(Res);
Adapter->checkUrResult<errc::build>(Res);
}

else if (State == bundle_state::executable) {
auto Res = Plugin->call_nocheck<UrApiKind::urProgramBuildExp>(
auto Res = Adapter->call_nocheck<UrApiKind::urProgramBuildExp>(
UrProgram, 1, &Dev, nullptr);
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
Res = Plugin->call_nocheck<UrApiKind::urProgramBuild>(
Res = Adapter->call_nocheck<UrApiKind::urProgramBuild>(
ContextImpl->getHandleRef(), UrProgram, nullptr);
}
Plugin->checkUrResult<errc::build>(Res);
Adapter->checkUrResult<errc::build>(Res);
}

break;
Expand All @@ -254,15 +254,15 @@ make_kernel_bundle(ur_native_handle_t NativeHandle,
detail::codeToString(UR_RESULT_ERROR_INVALID_VALUE));
if (State == bundle_state::executable) {
ur_program_handle_t UrLinkedProgram = nullptr;
auto Res = Plugin->call_nocheck<UrApiKind::urProgramLinkExp>(
auto Res = Adapter->call_nocheck<UrApiKind::urProgramLinkExp>(
ContextImpl->getHandleRef(), 1, &Dev, 1, &UrProgram, nullptr,
&UrLinkedProgram);
if (Res == UR_RESULT_ERROR_UNSUPPORTED_FEATURE) {
Res = Plugin->call_nocheck<UrApiKind::urProgramLink>(
Res = Adapter->call_nocheck<UrApiKind::urProgramLink>(
ContextImpl->getHandleRef(), 1, &UrProgram, nullptr,
&UrLinkedProgram);
}
Plugin->checkUrResult<errc::build>(Res);
Adapter->checkUrResult<errc::build>(Res);
if (UrLinkedProgram != nullptr) {
UrProgram = UrLinkedProgram;
}
Expand All @@ -284,9 +284,9 @@ make_kernel_bundle(ur_native_handle_t NativeHandle,
Devices.reserve(ProgramDevices.size());
std::transform(
ProgramDevices.begin(), ProgramDevices.end(), std::back_inserter(Devices),
[&Plugin](const auto &Dev) {
[&Adapter](const auto &Dev) {
auto Platform =
detail::platform_impl::getPlatformFromUrDevice(Dev, Plugin);
detail::platform_impl::getPlatformFromUrDevice(Dev, Adapter);
auto DeviceImpl = Platform->getOrMakeDeviceImpl(Dev, Platform);
return createSyclObjFromImpl<device>(DeviceImpl);
});
Expand Down Expand Up @@ -316,7 +316,7 @@ kernel make_kernel(const context &TargetContext,
const kernel_bundle<bundle_state::executable> &KernelBundle,
ur_native_handle_t NativeHandle, bool KeepOwnership,
backend Backend) {
const auto &Plugin = getPlugin(Backend);
const auto &Adapter = getAdapter(Backend);
const auto &ContextImpl = getSyclObjImpl(TargetContext);
const auto KernelBundleImpl = getSyclObjImpl(KernelBundle);

Expand Down Expand Up @@ -346,12 +346,12 @@ kernel make_kernel(const context &TargetContext,
ur_kernel_native_properties_t Properties{};
Properties.stype = UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES;
Properties.isNativeHandleOwned = !KeepOwnership;
Plugin->call<UrApiKind::urKernelCreateWithNativeHandle>(
Adapter->call<UrApiKind::urKernelCreateWithNativeHandle>(
NativeHandle, ContextImpl->getHandleRef(), UrProgram, &Properties,
&UrKernel);

if (Backend == backend::opencl)
Plugin->call<UrApiKind::urKernelRetain>(UrKernel);
Adapter->call<UrApiKind::urKernelRetain>(UrKernel);

// Construct the SYCL queue from UR queue.
return detail::createSyclObjFromImpl<kernel>(
Expand Down
8 changes: 4 additions & 4 deletions sycl/source/backend/level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include <detail/adapter.hpp>
#include <detail/platform_impl.hpp>
#include <detail/plugin.hpp>
#include <detail/queue_impl.hpp>
#include <sycl/backend.hpp>
#include <sycl/sycl.hpp>
Expand All @@ -19,12 +19,12 @@ using namespace sycl::detail;

__SYCL_EXPORT device make_device(const platform &Platform,
ur_native_handle_t NativeHandle) {
const auto &Plugin = ur::getPlugin<backend::ext_oneapi_level_zero>();
const auto &Adapter = ur::getAdapter<backend::ext_oneapi_level_zero>();
const auto &PlatformImpl = getSyclObjImpl(Platform);
// Create UR device first.
ur_device_handle_t UrDevice;
Plugin->call<UrApiKind::urDeviceCreateWithNativeHandle>(
NativeHandle, Plugin->getUrAdapter(), nullptr, &UrDevice);
Adapter->call<UrApiKind::urDeviceCreateWithNativeHandle>(
NativeHandle, Adapter->getUrAdapter(), nullptr, &UrDevice);

return detail::createSyclObjFromImpl<device>(
PlatformImpl->getOrMakeDeviceImpl(UrDevice, PlatformImpl));
Expand Down
Loading
Loading