-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] SYCL 2020 backend interoperability part 1 #3354
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d57fa09
[SYCL] SYCL 2020 backend interoperability part 1
9ff5d64
minor fixes
7829e2f
Add tests
1471900
more fixes
e9aa694
update symbols dump
07f3686
Merge remote-tracking branch 'upstream/sycl' into sycl_interop
0ac2d92
More fixes
4638c8a
Address comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//==-------------- backend_traits.hpp - SYCL backend traits ----------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
__SYCL_INLINE_NAMESPACE(cl) { | ||
namespace sycl { | ||
namespace detail { | ||
template <backend Backend> struct InteropFeatureSupportMap { | ||
static constexpr bool MakePlatform = false; | ||
static constexpr bool MakeDevice = false; | ||
static constexpr bool MakeContext = false; | ||
static constexpr bool MakeQueue = false; | ||
static constexpr bool MakeEvent = false; | ||
static constexpr bool MakeBuffer = false; | ||
static constexpr bool MakeKernel = false; | ||
}; | ||
} // namespace detail | ||
} // namespace sycl | ||
} // __SYCL_INLINE_NAMESPACE(cl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//==------------------- backend.cpp ----------------------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "detail/context_impl.hpp" | ||
#include "detail/event_impl.hpp" | ||
#include "detail/platform_impl.hpp" | ||
#include "detail/plugin.hpp" | ||
#include "detail/queue_impl.hpp" | ||
#include <CL/sycl/backend.hpp> | ||
#include <CL/sycl/detail/export.hpp> | ||
#include <CL/sycl/detail/pi.h> | ||
#include <CL/sycl/exception_list.hpp> | ||
|
||
__SYCL_INLINE_NAMESPACE(cl) { | ||
namespace sycl { | ||
namespace detail { | ||
|
||
static const plugin &getPlugin(backend Backend) { | ||
switch (Backend) { | ||
case backend::opencl: | ||
return pi::getPlugin<backend::opencl>(); | ||
case backend::level_zero: | ||
return pi::getPlugin<backend::level_zero>(); | ||
default: | ||
throw sycl::runtime_error{"Unsupported backend", PI_INVALID_OPERATION}; | ||
} | ||
} | ||
|
||
platform make_platform(pi_native_handle NativeHandle, backend Backend) { | ||
const auto &Plugin = getPlugin(Backend); | ||
|
||
// Create PI platform first. | ||
pi::PiPlatform PiPlatform = nullptr; | ||
Plugin.call<PiApiKind::piextPlatformCreateWithNativeHandle>(NativeHandle, | ||
&PiPlatform); | ||
|
||
return detail::createSyclObjFromImpl<platform>( | ||
platform_impl::getOrMakePlatformImpl(PiPlatform, Plugin)); | ||
} | ||
|
||
__SYCL_EXPORT device make_device(pi_native_handle NativeHandle, | ||
backend Backend) { | ||
const auto &Plugin = getPlugin(Backend); | ||
|
||
pi::PiDevice PiDevice = nullptr; | ||
Plugin.call<PiApiKind::piextDeviceCreateWithNativeHandle>(NativeHandle, | ||
nullptr, &PiDevice); | ||
// Construct the SYCL device from PI device. | ||
return detail::createSyclObjFromImpl<device>( | ||
std::make_shared<device_impl>(PiDevice, Plugin)); | ||
} | ||
|
||
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle, | ||
const async_handler &Handler, | ||
backend Backend) { | ||
const auto &Plugin = getPlugin(Backend); | ||
|
||
pi::PiContext PiContext = nullptr; | ||
Plugin.call<PiApiKind::piextContextCreateWithNativeHandle>( | ||
NativeHandle, 0, nullptr, false, &PiContext); | ||
// Construct the SYCL context from PI context. | ||
return detail::createSyclObjFromImpl<context>( | ||
std::make_shared<context_impl>(PiContext, Handler, Plugin)); | ||
} | ||
|
||
__SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle, | ||
const context &Context, | ||
const async_handler &Handler, backend Backend) { | ||
const auto &Plugin = getPlugin(Backend); | ||
const auto &ContextImpl = getSyclObjImpl(Context); | ||
// Create PI queue first. | ||
pi::PiQueue PiQueue = nullptr; | ||
Plugin.call<PiApiKind::piextQueueCreateWithNativeHandle>( | ||
NativeHandle, ContextImpl->getHandleRef(), &PiQueue); | ||
// Construct the SYCL queue from PI queue. | ||
return detail::createSyclObjFromImpl<queue>( | ||
std::make_shared<queue_impl>(PiQueue, ContextImpl, Handler)); | ||
} | ||
|
||
__SYCL_EXPORT event make_event(pi_native_handle NativeHandle, | ||
const context &Context, backend Backend) { | ||
const auto &Plugin = getPlugin(Backend); | ||
|
||
pi::PiEvent PiEvent = nullptr; | ||
Plugin.call<PiApiKind::piextEventCreateWithNativeHandle>(NativeHandle, | ||
&PiEvent); | ||
|
||
return detail::createSyclObjFromImpl<event>( | ||
std::make_shared<event_impl>(PiEvent, Context)); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace sycl | ||
} // __SYCL_INLINE_NAMESPACE(cl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.