Skip to content

[SYCL] Fix get_native() and add get_backend() accordingly to the specification and test for the get_native() #3236

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 25 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e1ea2c8
[SYCL] Fix get_native() and add get_backend() accordingly to the spec…
maximdimakov Feb 20, 2021
24706c5
Merge branch 'sycl' into get_native_br
maximdimakov Feb 20, 2021
5cc520b
[SYCL] Clang-format fix
maximdimakov Feb 20, 2021
b08fc22
[SYCL] Clang-format fix
maximdimakov Feb 20, 2021
3daa423
[SYCL] Adress to review comment
maximdimakov Feb 24, 2021
c5f1696
[SYCL] Sycl symbols was added
maximdimakov Feb 24, 2021
f953902
[SYCL] Unit test for the free get_native()
maximdimakov Mar 2, 2021
4e292b4
[SYCL] Clang-format fix
maximdimakov Mar 2, 2021
e0ef3a9
[SYCL] Clang-format fix
maximdimakov Mar 2, 2021
9da4b11
Merge branch 'test_get_native' into get_native_br
maximdimakov Mar 3, 2021
8b0ec15
Merged and resolved conflict with queue_impl.hpp
maximdimakov Mar 3, 2021
39d6fb7
Merge branch 'sycl' into get_native_br
maximdimakov Mar 5, 2021
7ce2a71
[SYCL] Added check for cuda
maximdimakov Mar 5, 2021
e95167c
[SYCL] Addressed to review comment
maximdimakov Mar 5, 2021
b45fa45
Adress review comments
maximdimakov Mar 10, 2021
6e424a8
Merge sycl into get_native_br
maximdimakov Mar 10, 2021
4a85138
[SYCL] Address review comment
maximdimakov Mar 10, 2021
ce3f9ce
[SYCL] Clang-format fix
maximdimakov Mar 10, 2021
78c0c02
Clang-format fix
maximdimakov Mar 10, 2021
a9131d9
Fix comments
maximdimakov Mar 10, 2021
ff97206
Adress review comments
maximdimakov Mar 10, 2021
e20666b
Clang-format fix
maximdimakov Mar 10, 2021
92f6edc
Merge branch 'sycl' into get_native_br
maximdimakov Mar 11, 2021
1c62f3f
symbols updated
maximdimakov Mar 11, 2021
1d00c7b
Symbols updated
maximdimakov Mar 11, 2021
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
4 changes: 4 additions & 0 deletions sycl/include/CL/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

#include <CL/sycl/accessor.hpp>
#include <CL/sycl/backend_types.hpp>
#include <CL/sycl/exception.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

template <backend BackendName, class SyclObjectT>
auto get_native(const SyclObjectT &Obj) ->
typename interop<BackendName, SyclObjectT>::type {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != BackendName)
throw runtime_error("Backends mismatch", PI_INVALID_OPERATION);
return Obj.template get_native<BackendName>();
}

Expand Down
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl/backend/opencl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ template <> struct interop<backend::opencl, program> {
using type = cl_program;
};

template <> struct interop<backend::opencl, event> { using type = cl_event; };

template <typename DataT, int Dimensions, access::mode AccessMode>
struct interop<backend::opencl, accessor<DataT, Dimensions, AccessMode,
access::target::global_buffer,
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ class __SYCL_EXPORT context {
/// \return true if this context is a SYCL host context.
bool is_host() const;

/// Returns the backend associated with this context.
///
/// \return the backend associated with this context.
backend get_backend() const noexcept;

/// Gets platform associated with this SYCL context.
///
/// \return a valid instance of SYCL platform.
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class __SYCL_EXPORT device {
static vector_class<device>
get_devices(info::device_type deviceType = info::device_type::all);

/// Returns the backend associated with this device.
///
/// \return the backend associated with this device.
backend get_backend() const noexcept;

/// Gets the native handle of the SYCL device.
///
/// \return a native handle, the type of which defined by the backend.
Expand Down
8 changes: 7 additions & 1 deletion sycl/include/CL/sycl/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ class __SYCL_EXPORT event {
typename info::param_traits<info::event_profiling, param>::return_type
get_profiling_info() const;

/// Returns the backend associated with this platform.
///
/// \return the backend associated with this platform
backend get_backend() const noexcept;

/// Gets the native handle of the SYCL event.
///
/// \return a native handle, the type of which defined by the backend.
template <backend BackendName>
auto get_native() const -> typename interop<BackendName, event>::type {
return static_cast<typename interop<BackendName, event>::type>(getNative());
return reinterpret_cast<typename interop<BackendName, event>::type>(
getNative());
}

private:
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ class __SYCL_EXPORT program {
#endif // __SYCL_DEVICE_ONLY__
}

/// Returns the backend associated with this program.
///
/// \return the backend associated with this program.
backend get_backend() const noexcept;

/// Gets the native handle of the SYCL platform.
///
/// \return a native handle, the type of which defined by the backend.
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,11 @@ class __SYCL_EXPORT queue {
/// Equivalent to has_property<property::queue::in_order>()
bool is_in_order() const;

/// Returns the backend associated with this queue.
///
/// \return the backend associated with this queue.
backend get_backend() const noexcept;

/// Gets the native handle of the SYCL queue.
///
/// \return a native handle, the type of which defined by the backend.
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <CL/sycl/platform.hpp>
#include <CL/sycl/properties/all_properties.hpp>
#include <CL/sycl/stl.hpp>
#include <detail/backend_impl.hpp>
#include <detail/context_impl.hpp>

#include <algorithm>
Expand Down Expand Up @@ -117,6 +118,8 @@ cl_context context::get() const { return impl->get(); }

bool context::is_host() const { return impl->is_host(); }

backend context::get_backend() const noexcept { return getImplBackend(impl); }

platform context::get_platform() const {
return impl->get_info<info::context::platform>();
}
Expand Down
29 changes: 29 additions & 0 deletions sycl/source/detail/backend_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//==------------------ backend_impl.hpp - get impls backend
//-------------------------==//
//
// 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/backend_types.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {

template <class T> backend getImplBackend(const T &Impl) {
backend Result;
if (Impl->is_host())
Result = backend::host;
else
Result = Impl->getPlugin().getBackend();

return Result;
}

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
2 changes: 2 additions & 0 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ bool context_impl::hasDevice(

pi_native_handle context_impl::getNative() const {
auto Plugin = getPlugin();
if (Plugin.getBackend() == backend::opencl)
Plugin.call<PiApiKind::piContextRetain>(getHandleRef());
pi_native_handle Handle;
Plugin.call<PiApiKind::piextContextGetNativeHandle>(getHandleRef(), &Handle);
return Handle;
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ vector_class<device> device_impl::create_sub_devices(

pi_native_handle device_impl::getNative() const {
auto Plugin = getPlugin();
if (Plugin.getBackend() == backend::opencl)
Plugin.call<PiApiKind::piDeviceRetain>(getHandleRef());
pi_native_handle Handle;
Plugin.call<PiApiKind::piextDeviceGetNativeHandle>(getHandleRef(), &Handle);
return Handle;
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ void HostProfilingInfo::end() { EndTime = getTimestamp(); }

pi_native_handle event_impl::getNative() const {
auto Plugin = getPlugin();
if (Plugin.getBackend() == backend::opencl)
Plugin.call<PiApiKind::piEventRetain>(getHandleRef());
pi_native_handle Handle;
Plugin.call<PiApiKind::piextEventGetNativeHandle>(getHandleRef(), &Handle);
return Handle;
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/event_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/stl.hpp>
#include <detail/plugin.hpp>

#include <atomic>
#include <cassert>
Expand Down
12 changes: 0 additions & 12 deletions sycl/source/detail/platform_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ class platform_impl {
/// \return a vector of all available SYCL platforms.
static vector_class<platform> get_platforms();

// \return the Backend associated with this platform.
backend get_backend() const noexcept {
backend Result;
if (is_host())
Result = backend::host;
else {
Result = getPlugin().getBackend();
}

return Result;
}

// \return the Plugin associated with this platform.
const plugin &getPlugin() const {
assert(!MHostPlatform && "Plugin is not available for Host.");
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/program_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ void program_impl::flush_spec_constants(const RTDeviceBinaryImage &Img,

pi_native_handle program_impl::getNative() const {
const auto &Plugin = getPlugin();
if (Plugin.getBackend() == backend::opencl)
Plugin.call<PiApiKind::piProgramRetain>(MProgram);
pi_native_handle Handle;
Plugin.call<PiApiKind::piextProgramGetNativeHandle>(MProgram, &Handle);
return Handle;
Expand Down
2 changes: 2 additions & 0 deletions sycl/source/detail/queue_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ void queue_impl::initHostTaskAndEventCallbackThreadPool() {

pi_native_handle queue_impl::getNative() const {
const detail::plugin &Plugin = getPlugin();
if (Plugin.getBackend() == backend::opencl)
Plugin.call<PiApiKind::piQueueRetain>(MQueues[0]);
pi_native_handle Handle{};
Plugin.call<PiApiKind::piextQueueGetNativeHandle>(MQueues[0], &Handle);
return Handle;
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <CL/sycl/device.hpp>
#include <CL/sycl/device_selector.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <detail/backend_impl.hpp>
#include <detail/config.hpp>
#include <detail/device_impl.hpp>
#include <detail/force_device.hpp>
Expand Down Expand Up @@ -136,6 +137,8 @@ device::get_info() const {

#undef __SYCL_PARAM_TRAITS_SPEC

backend device::get_backend() const noexcept { return getImplBackend(impl); }

pi_native_handle device::getNative() const { return impl->getNative(); }

bool device::has(aspect Aspect) const { return impl->has(Aspect); }
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <CL/sycl/event.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/stl.hpp>
#include <detail/backend_impl.hpp>
#include <detail/event_impl.hpp>
#include <detail/scheduler/scheduler.hpp>

Expand Down Expand Up @@ -85,6 +86,8 @@ event::event(shared_ptr_class<detail::event_impl> event_impl)

#undef __SYCL_PARAM_TRAITS_SPEC

backend event::get_backend() const noexcept { return getImplBackend(impl); }

pi_native_handle event::getNative() const { return impl->getNative(); }

} // namespace sycl
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <CL/sycl/device_selector.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/platform.hpp>
#include <detail/backend_impl.hpp>
#include <detail/force_device.hpp>
#include <detail/platform_impl.hpp>

Expand Down Expand Up @@ -43,7 +44,7 @@ vector_class<platform> platform::get_platforms() {
return detail::platform_impl::get_platforms();
}

backend platform::get_backend() const noexcept { return impl->get_backend(); }
backend platform::get_backend() const noexcept { return getImplBackend(impl); }

template <info::platform param>
typename info::param_traits<info::platform, param>::return_type
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <CL/sycl/program.hpp>
#include <CL/sycl/properties/all_properties.hpp>
#include <CL/sycl/property_list.hpp>
#include <detail/backend_impl.hpp>
#include <detail/program_impl.hpp>

#include <vector>
Expand Down Expand Up @@ -47,6 +48,8 @@ program::program(const context &context, cl_program clProgram)
clRetainProgram(clProgram);
}

backend program::get_backend() const noexcept { return getImplBackend(impl); }

pi_native_handle program::getNative() const { return impl->getNative(); }

program::program(std::shared_ptr<detail::program_impl> impl) : impl(impl) {}
Expand Down
3 changes: 3 additions & 0 deletions sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <CL/sycl/handler.hpp>
#include <CL/sycl/queue.hpp>
#include <CL/sycl/stl.hpp>
#include <detail/backend_impl.hpp>
#include <detail/queue_impl.hpp>

#include <algorithm>
Expand Down Expand Up @@ -138,6 +139,8 @@ bool queue::is_in_order() const {
return impl->has_property<property::queue::in_order>();
}

backend queue::get_backend() const noexcept { return getImplBackend(impl); }

pi_native_handle queue::getNative() const { return impl->getNative(); }

} // namespace sycl
Expand Down
5 changes: 5 additions & 0 deletions sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -3897,6 +3897,7 @@ _ZNK2cl4sycl15interop_handler12GetNativeMemEPNS0_6detail16AccessorImplHostE
_ZNK2cl4sycl15interop_handler14GetNativeQueueEv
_ZNK2cl4sycl16default_selectorclERKNS0_6deviceE
_ZNK2cl4sycl20accelerator_selectorclERKNS0_6deviceE
_ZNK2cl4sycl5event11get_backendEv
Copy link
Contributor

Choose a reason for hiding this comment

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

Should minor/patch version of library be increased according to ABI policy?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it'll be increased before release is tagged.

_ZNK2cl4sycl5event18get_profiling_infoILNS0_4info15event_profilingE4737EEENS3_12param_traitsIS4_XT_EE11return_typeEv
_ZNK2cl4sycl5event18get_profiling_infoILNS0_4info15event_profilingE4738EEENS3_12param_traitsIS4_XT_EE11return_typeEv
_ZNK2cl4sycl5event18get_profiling_infoILNS0_4info15event_profilingE4739EEENS3_12param_traitsIS4_XT_EE11return_typeEv
Expand All @@ -3908,6 +3909,7 @@ _ZNK2cl4sycl5event9getNativeEv
_ZNK2cl4sycl5eventeqERKS1_
_ZNK2cl4sycl5eventneERKS1_
_ZNK2cl4sycl5queue10get_deviceEv
_ZNK2cl4sycl5queue11get_backendEv
_ZNK2cl4sycl5queue11get_contextEv
_ZNK2cl4sycl5queue11is_in_orderEv
_ZNK2cl4sycl5queue12get_propertyINS0_8property5queue16enable_profilingEEET_v
Expand Down Expand Up @@ -3968,6 +3970,7 @@ _ZNK2cl4sycl6detail19kernel_bundle_plain37get_specialization_constant_raw_valueE
_ZNK2cl4sycl6detail19kernel_bundle_plain3endEv
_ZNK2cl4sycl6detail19kernel_bundle_plain5beginEv
_ZNK2cl4sycl6detail19kernel_bundle_plain5emptyEv
_ZNK2cl4sycl6device11get_backendEv
_ZNK2cl4sycl6device12get_platformEv
_ZNK2cl4sycl6device13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK2cl4sycl6device14is_acceleratorEv
Expand Down Expand Up @@ -4103,6 +4106,7 @@ _ZNK2cl4sycl6stream22get_max_statement_sizeEv
_ZNK2cl4sycl6stream8get_sizeEv
_ZNK2cl4sycl6streameqERKS1_
_ZNK2cl4sycl6streamneERKS1_
_ZNK2cl4sycl7context11get_backendEv
_ZNK2cl4sycl7context11get_devicesEv
_ZNK2cl4sycl7context12get_platformEv
_ZNK2cl4sycl7context12get_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEET_v
Expand Down Expand Up @@ -4135,6 +4139,7 @@ _ZNK2cl4sycl7program10get_kernelENSt7__cxx1112basic_stringIcSt11char_traitsIcESa
_ZNK2cl4sycl7program10get_kernelENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
_ZNK2cl4sycl7program10has_kernelENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK2cl4sycl7program10has_kernelENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
_ZNK2cl4sycl7program11get_backendEv
_ZNK2cl4sycl7program11get_contextEv
_ZNK2cl4sycl7program11get_devicesEv
_ZNK2cl4sycl7program12get_binariesEv
Expand Down
1 change: 1 addition & 0 deletions sycl/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ endforeach()

include(AddSYCLUnitTest)

add_subdirectory(get_native_interop)
add_subdirectory(misc)
add_subdirectory(pi)
add_subdirectory(kernel-and-program)
Expand Down
3 changes: 3 additions & 0 deletions sycl/unittests/get_native_interop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_sycl_unittest_with_device(GetNativeTests OBJECT
test_get_native.cpp
)
Loading