-
Notifications
You must be signed in to change notification settings - Fork 802
[SYCL] Introduce interop handle for host task #1747
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
bader
merged 13 commits into
intel:sycl
from
s-kanaev:private/s-kanaev/ht-interop-handle
Jun 9, 2020
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f37a294
[SYCL] Introduce interop handle for host task
26fe5e5
[SYCL] Remove friend classes as unneeded for now.
e4a35f8
[SYCL] Untie interop_handle from OpenCL.
6d8170a
[SYCL] Fix style issues
6a4cbe8
Merge branch 'sycl' into private/s-kanaev/ht-interop-handle
5f6ea1f
[SYCL] Address comments
a24cee7
[SYCL] Use forward declaration instead of include.
cb0925b
[SYCL][TEST] Add accesor.hpp include to interop_handle.hpp
6cd8d33
[SYCL] Remove tesing include.
3e20e94
Merge branch 'sycl' into private/s-kanaev/ht-interop-handle
605ea4e
[SYCL] Employ static_cast for accessor
add913a
[SYCL] Fix style issue
235b77c
Merge branch 'sycl' into private/s-kanaev/ht-interop-handle
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| //==------------ interop_handle.hpp --- SYCL interop handle ----------------==// | ||
| // | ||
| // 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 | ||
|
|
||
| #include <CL/sycl/access/access.hpp> | ||
| #include <CL/sycl/detail/accessor_impl.hpp> | ||
| #include <CL/sycl/detail/common.hpp> | ||
| #include <CL/sycl/detail/defines.hpp> | ||
| #include <CL/sycl/detail/pi.hpp> | ||
|
|
||
| #include <memory> | ||
|
|
||
| __SYCL_INLINE_NAMESPACE(cl) { | ||
| namespace sycl { | ||
|
|
||
| namespace detail { | ||
| class AccessorBaseHost; | ||
| class ExecCGCommand; | ||
| class DispatchHostTask; | ||
| } // namespace detail | ||
|
|
||
| template <typename DataT, int Dims, access::mode AccMode, | ||
| access::target AccTarget, access::placeholder isPlaceholder> | ||
| class accessor; | ||
|
|
||
| class interop_handle { | ||
| public: | ||
| /// Receives a SYCL accessor that has been defined is a requirement for the | ||
| /// command group, and returns the underlying OpenCL memory object that is | ||
| /// used by the SYCL runtime. If the accessor passed as parameter is not part | ||
| /// of the command group requirements (e.g. it is an unregistered placeholder | ||
| /// accessor), the exception `cl::sycl::invalid_object` is thrown | ||
| /// asynchronously. | ||
| template <typename dataT, int dimensions, access::mode accessmode, | ||
s-kanaev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| access::target accessTarget, access::placeholder isPlaceholder> | ||
| typename std::enable_if<accessTarget != access::target::host_buffer, | ||
| cl_mem>::type | ||
| get_native_mem(const accessor<dataT, dimensions, accessmode, accessTarget, | ||
| isPlaceholder> &Acc) const { | ||
| #ifndef __SYCL_DEVICE_ONLY__ | ||
| // employ reinterpret_cast instead of static_cast due to cycle in includes | ||
| // involving CL/sycl/accessor.hpp | ||
| auto *AccBase = const_cast<detail::AccessorBaseHost *>( | ||
s-kanaev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| reinterpret_cast<const detail::AccessorBaseHost *>(&Acc)); | ||
| return getMemImpl(detail::getSyclObjImpl(*AccBase).get()); | ||
| #else | ||
| (void)Acc; | ||
| // we believe this won't be ever called on device side | ||
| return static_cast<cl_mem>(0x0); | ||
| #endif | ||
| } | ||
|
|
||
| template <typename dataT, int dimensions, access::mode accessmode, | ||
| access::target accessTarget, access::placeholder isPlaceholder> | ||
| typename std::enable_if<accessTarget == access::target::host_buffer, | ||
| cl_mem>::type | ||
| get_native_mem(const accessor<dataT, dimensions, accessmode, accessTarget, | ||
| isPlaceholder> &) const { | ||
| throw invalid_object_error("Getting memory object out of host accessor is " | ||
s-kanaev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "not allowed", | ||
| PI_INVALID_MEM_OBJECT); | ||
| } | ||
|
|
||
| /// Returns an underlying OpenCL queue for the SYCL queue used to submit the | ||
| /// command group, or the fallback queue if this command-group is re-trying | ||
| /// execution on an OpenCL queue. The OpenCL command queue returned is | ||
| /// implementation-defined in cases where the SYCL queue maps to multiple | ||
| /// underlying OpenCL objects. It is responsibility of the SYCL runtime to | ||
| /// ensure the OpenCL queue returned is in a state that can be used to | ||
| /// dispatch work, and that other potential OpenCL command queues associated | ||
| /// with the same SYCL command queue are not executing commands while the host | ||
| /// task is executing. | ||
| cl_command_queue get_native_queue() const noexcept { return MQueue; } | ||
|
|
||
| /// Returns an underlying OpenCL device associated with the SYCL queue used | ||
| /// to submit the command group, or the fallback queue if this command-group | ||
| /// is re-trying execution on an OpenCL queue. | ||
| cl_device_id get_native_device() const noexcept { return MDeviceId; } | ||
|
|
||
| /// Returns an underlying OpenCL context associated with the SYCL queue used | ||
| /// to submit the command group, or the fallback queue if this command-group | ||
| /// is re-trying execution on an OpenCL queue. | ||
| cl_context get_native_context() const noexcept { return MContext; } | ||
|
|
||
| private: | ||
| using ReqToMem = std::pair<detail::Requirement *, pi_mem>; | ||
|
|
||
| template <typename DataT, int Dims, access::mode AccMode, | ||
| access::target AccTarget, access::placeholder isPlaceholder> | ||
| friend class accessor; | ||
| friend class detail::ExecCGCommand; | ||
| friend class detail::DispatchHostTask; | ||
s-kanaev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public: | ||
| // TODO set c-tor private | ||
| interop_handle(std::vector<ReqToMem> MemObjs, cl_command_queue Queue, | ||
| cl_device_id DeviceId, cl_context Context) | ||
| : MQueue(Queue), MDeviceId(DeviceId), MContext(Context), | ||
| MMemObjs(std::move(MemObjs)) {} | ||
|
|
||
| private: | ||
| cl_mem getMemImpl(detail::Requirement *Req) const; | ||
|
|
||
| cl_command_queue MQueue; | ||
| cl_device_id MDeviceId; | ||
| cl_context MContext; | ||
| std::vector<ReqToMem> MMemObjs; | ||
| }; | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| //==------------ interop_handle.cpp --- SYCL interop handle ----------------==// | ||
| // | ||
| // 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 <CL/sycl/detail/accessor_impl.hpp> | ||
| #include <CL/sycl/interop_handle.hpp> | ||
|
|
||
| #include <algorithm> | ||
|
|
||
| __SYCL_INLINE_NAMESPACE(cl) { | ||
| namespace sycl { | ||
|
|
||
| cl_mem interop_handle::getMemImpl(detail::Requirement *Req) const { | ||
| auto Iter = std::find_if(std::begin(MMemObjs), std::end(MMemObjs), | ||
| [=](ReqToMem Elem) { return (Elem.first == Req); }); | ||
|
|
||
| if (Iter == std::end(MMemObjs)) | ||
| throw("Invalid memory object used inside interop"); | ||
s-kanaev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return detail::pi::cast<cl_mem>(Iter->second); | ||
| } | ||
|
|
||
| } // namespace sycl | ||
| } // __SYCL_INLINE_NAMESPACE(cl) | ||
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.