Skip to content

[SYCL] Host device & queue removal (internal part, not breaking ABI) #14370

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 59 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6e98e3f
not buildable: remove host device from device_impl.*
KseniyaTikhomirova May 22, 2024
abe4586
not-buildable: remove getHostPlatformImpl
KseniyaTikhomirova May 22, 2024
6a0a250
not buildable: remove get_device_info_host
KseniyaTikhomirova May 22, 2024
35b6822
not-buildable: remove is_host from context_impl.*
KseniyaTikhomirova May 22, 2024
77c749c
not-buildable: remove is_host from event_impl.*
KseniyaTikhomirova May 22, 2024
6e71420
not-buildable: update is_host for API objects to be easily removed
KseniyaTikhomirova May 22, 2024
7e5abe9
not-buildable: update most obvious places
KseniyaTikhomirova May 22, 2024
31a702c
not-buildable: remove is_host from obvious places, part2
KseniyaTikhomirova May 23, 2024
fa08c2b
non-buildable: remove is_host from obvious places
KseniyaTikhomirova May 27, 2024
d021de9
not-buildable: remove is_host in simple places
KseniyaTikhomirova May 27, 2024
5b60b90
draft
KseniyaTikhomirova May 28, 2024
21ed380
non-buildable: eliminate getDefaultHostQueue usage
KseniyaTikhomirova May 29, 2024
c533af7
non-buildable: cleanup queue usages
KseniyaTikhomirova Jun 4, 2024
f0868f5
handle nullptr Queue in commands.*
KseniyaTikhomirova Jun 5, 2024
3d044e8
non-buildable: handle nullptr queue in memory_manager.cpp
KseniyaTikhomirova Jun 5, 2024
b3161e8
non-buildable: build enabling
KseniyaTikhomirova Jun 5, 2024
2258a1c
not-buildable: build enabling 2
KseniyaTikhomirova Jun 5, 2024
df27615
almost buildable: build enabling 3
KseniyaTikhomirova Jun 5, 2024
eebc519
almost almost buildable: enable build 4
KseniyaTikhomirova Jun 5, 2024
c6fe5c8
buildable
KseniyaTikhomirova Jun 6, 2024
24669e2
RT-buildable: enabling UT build
KseniyaTikhomirova Jun 6, 2024
fcc7748
RT-buildable: restore incorrectly deleted code
KseniyaTikhomirova Jun 7, 2024
7aa76d9
RT buildable: check-sycl-AccessorTests passed
KseniyaTikhomirova Jun 7, 2024
dc4a94e
RT-buildable: enable unittests 2
KseniyaTikhomirova Jun 7, 2024
8c57888
RT-buildable: unittests enabling 3
KseniyaTikhomirova Jun 7, 2024
abfc5bf
tiny cleanup
KseniyaTikhomirova Jun 17, 2024
6cfa3b7
Merge branch 'sycl' into host_device_removal
KseniyaTikhomirova Jun 18, 2024
75f6eab
move stream_impl flush
KseniyaTikhomirova Jun 17, 2024
be12c01
test fix
KseniyaTikhomirova Jun 19, 2024
e043ee0
restore & update ABI - not breaking
KseniyaTikhomirova Jun 19, 2024
d5173b4
Merge branch 'sycl' into host_device_removal
KseniyaTikhomirova Jun 19, 2024
cea7c72
clang git-clang-format run on changed files
KseniyaTikhomirova Jun 19, 2024
c76484d
fix clang-format
KseniyaTikhomirova Jun 19, 2024
61d1c62
fix connect task queue
KseniyaTikhomirova Jun 19, 2024
5814e46
fix bugs
KseniyaTikhomirova Jun 20, 2024
a034681
fix work with graph
KseniyaTikhomirova Jun 20, 2024
c274c5e
fix tracing tests
KseniyaTikhomirova Jun 20, 2024
f50526b
fix test
KseniyaTikhomirova Jun 21, 2024
2bd06e3
update win symbols
KseniyaTikhomirova Jun 24, 2024
5fbcb1e
fix format
KseniyaTikhomirova Jun 24, 2024
d5d15bf
fix formatting
KseniyaTikhomirova Jun 24, 2024
e185cbc
self review comments fix
KseniyaTikhomirova Jun 25, 2024
a87b328
fix
KseniyaTikhomirova Jun 26, 2024
0a5a758
Update isCOntextInitialized stuff
KseniyaTikhomirova Jun 26, 2024
d2f5f7d
Merge branch 'sycl' into host_device_removal
KseniyaTikhomirova Jun 26, 2024
97c4ce5
prepare removal from handler
KseniyaTikhomirova Jun 26, 2024
6cf3171
fix test
KseniyaTikhomirova Jun 26, 2024
989557a
fix clang-format
KseniyaTikhomirova Jun 26, 2024
1a13975
fix warning
KseniyaTikhomirova Jun 27, 2024
e9fffb6
fix allowlist test cherry-pick issues
KseniyaTikhomirova Jun 27, 2024
d3e3313
Merge branch 'sycl' into host_device_removal
KseniyaTikhomirova Jul 1, 2024
6ec2b63
fix code review comments
KseniyaTikhomirova Jul 1, 2024
a7633f3
Merge branch 'sycl' into host_device_removal
KseniyaTikhomirova Jul 1, 2024
954ba8b
extra code review changes
KseniyaTikhomirova Jul 1, 2024
3fb26e0
fix format
KseniyaTikhomirova Jul 1, 2024
67a5462
fix format 2
KseniyaTikhomirova Jul 1, 2024
76a073c
update win symbols
KseniyaTikhomirova Jul 1, 2024
1cb8e71
Merge branch 'sycl' into host_device_removal
KseniyaTikhomirova Jul 1, 2024
a406fb7
Merge branch 'sycl' into host_device_removal_copy
KseniyaTikhomirova Jul 2, 2024
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
71 changes: 23 additions & 48 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class __SYCL_EXPORT handler {
/// \param Queue is a SYCL queue.
/// \param IsHost indicates if this handler is created for SYCL host device.
/// TODO: Unused. Remove with ABI break.
handler(std::shared_ptr<detail::queue_impl> Queue, bool IsHost);
handler(std::shared_ptr<detail::queue_impl> Queue, bool /*Unused*/);

/// Constructs SYCL handler from the associated queue and the submission's
/// primary and secondary queue.
Expand All @@ -476,20 +476,20 @@ class __SYCL_EXPORT handler {
/// \param PrimaryQueue is the primary SYCL queue of the submission.
/// \param SecondaryQueue is the secondary SYCL queue of the submission. This
/// is null if no secondary queue is associated with the submission.
/// \param IsHost indicates if this handler is created for SYCL host device.
/// TODO: Unused. Remove with ABI break.
handler(std::shared_ptr<detail::queue_impl> Queue,
std::shared_ptr<detail::queue_impl> PrimaryQueue,
std::shared_ptr<detail::queue_impl> SecondaryQueue, bool IsHost);
std::shared_ptr<detail::queue_impl> SecondaryQueue,
bool /* Unused */);

/// Constructs SYCL handler from queue.
///
/// \param Queue is a SYCL queue.
/// \param IsHost indicates if this handler is created for SYCL host device.
/// \param CallerNeedsEvent indicates if the event resulting from this handler
/// is needed by the caller.
handler(std::shared_ptr<detail::queue_impl> Queue, bool IsHost,
bool CallerNeedsEvent);
handler(std::shared_ptr<detail::queue_impl> Queue,
bool /* ABI break: remove */, bool CallerNeedsEvent);

/// Constructs SYCL handler from the associated queue and the submission's
/// primary and secondary queue.
Expand All @@ -504,8 +504,8 @@ class __SYCL_EXPORT handler {
/// is needed by the caller.
handler(std::shared_ptr<detail::queue_impl> Queue,
std::shared_ptr<detail::queue_impl> PrimaryQueue,
std::shared_ptr<detail::queue_impl> SecondaryQueue, bool IsHost,
bool CallerNeedsEvent);
std::shared_ptr<detail::queue_impl> SecondaryQueue,
bool /* ABI break: remove */, bool CallerNeedsEvent);

/// Constructs SYCL handler from Graph.
///
Expand Down Expand Up @@ -644,7 +644,7 @@ class __SYCL_EXPORT handler {
~handler() = default;

// TODO: Private and unusued. Remove when ABI break is allowed.
bool is_host() { return MIsHost; }
bool is_host() { return false; }

#ifdef __SYCL_DEVICE_ONLY__
// In device compilation accessor isn't inherited from host base classes, so
Expand Down Expand Up @@ -923,12 +923,6 @@ class __SYCL_EXPORT handler {
detail::KernelLambdaHasKernelHandlerArgT<KernelType,
LambdaArgType>::value;

if (IsCallableWithKernelHandler && MIsHost) {
throw sycl::feature_not_supported(
"kernel_handler is not yet supported by host device.",
PI_ERROR_INVALID_OPERATION);
}

KernelType *KernelPtr =
ResetHostKernel<KernelType, LambdaArgType, Dims>(KernelFunc);

Expand Down Expand Up @@ -1077,8 +1071,7 @@ class __SYCL_EXPORT handler {
std::enable_if_t<(DimSrc > 0) && (DimDst > 0), bool>
copyAccToAccHelper(accessor<TSrc, DimSrc, ModeSrc, TargetSrc, IsPHSrc> Src,
accessor<TDst, DimDst, ModeDst, TargetDst, IsPHDst> Dst) {
if (!MIsHost &&
IsCopyingRectRegionAvailable(Src.get_range(), Dst.get_range()))
if (IsCopyingRectRegionAvailable(Src.get_range(), Dst.get_range()))
return false;

range<1> LinearizedRange(Src.size());
Expand All @@ -1100,23 +1093,19 @@ class __SYCL_EXPORT handler {
///
/// \param Src is a source SYCL accessor.
/// \param Dst is a destination SYCL accessor.
// ABI break: to remove whole method
template <typename TSrc, int DimSrc, access::mode ModeSrc,
access::target TargetSrc, typename TDst, int DimDst,
access::mode ModeDst, access::target TargetDst,
access::placeholder IsPHSrc, access::placeholder IsPHDst>
std::enable_if_t<DimSrc == 0 || DimDst == 0, bool>
copyAccToAccHelper(accessor<TSrc, DimSrc, ModeSrc, TargetSrc, IsPHSrc> Src,
accessor<TDst, DimDst, ModeDst, TargetDst, IsPHDst> Dst) {
if (!MIsHost)
return false;

single_task<__copyAcc2Acc<TSrc, DimSrc, ModeSrc, TargetSrc, TDst, DimDst,
ModeDst, TargetDst, IsPHSrc, IsPHDst>>(
[=]() { *(Dst.get_pointer()) = *(Src.get_pointer()); });
return true;
copyAccToAccHelper(accessor<TSrc, DimSrc, ModeSrc, TargetSrc, IsPHSrc>,
accessor<TDst, DimDst, ModeDst, TargetDst, IsPHDst>) {
return false;
}

#ifndef __SYCL_DEVICE_ONLY__
// ABI break: to remove whole method
/// Copies the content of memory object accessed by Src into the memory
/// pointed by Dst.
///
Expand All @@ -1136,6 +1125,7 @@ class __SYCL_EXPORT handler {
});
}

// ABI break: to remove whole method
/// Copies 1 element accessed by 0-dimensional accessor Src into the memory
/// pointed by Dst.
///
Expand All @@ -1153,6 +1143,7 @@ class __SYCL_EXPORT handler {
});
}

// ABI break: to remove whole method
/// Copies the memory pointed by Src into the memory accessed by Dst.
///
/// \param Src is a pointer to source memory.
Expand All @@ -1170,6 +1161,7 @@ class __SYCL_EXPORT handler {
});
}

// ABI break: to remove whole method
/// Copies 1 element pointed by Src to memory accessed by 0-dimensional
/// accessor Dst.
///
Expand Down Expand Up @@ -2282,7 +2274,7 @@ class __SYCL_EXPORT handler {
MNDRDesc.set(range<1>{1});
MKernel = detail::getSyclObjImpl(std::move(Kernel));
setType(detail::CG::Kernel);
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
if (!lambdaAndKernelHaveEqualName<NameT>()) {
extractArgsAndReqs();
MKernelName = getKernelName();
} else
Expand Down Expand Up @@ -2319,7 +2311,7 @@ class __SYCL_EXPORT handler {
MKernel = detail::getSyclObjImpl(std::move(Kernel));
setType(detail::CG::Kernel);
setNDRangeUsed(false);
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
if (!lambdaAndKernelHaveEqualName<NameT>()) {
extractArgsAndReqs();
MKernelName = getKernelName();
} else
Expand Down Expand Up @@ -2359,7 +2351,7 @@ class __SYCL_EXPORT handler {
MKernel = detail::getSyclObjImpl(std::move(Kernel));
setType(detail::CG::Kernel);
setNDRangeUsed(false);
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
if (!lambdaAndKernelHaveEqualName<NameT>()) {
extractArgsAndReqs();
MKernelName = getKernelName();
} else
Expand Down Expand Up @@ -2398,7 +2390,7 @@ class __SYCL_EXPORT handler {
MKernel = detail::getSyclObjImpl(std::move(Kernel));
setType(detail::CG::Kernel);
setNDRangeUsed(true);
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
if (!lambdaAndKernelHaveEqualName<NameT>()) {
extractArgsAndReqs();
MKernelName = getKernelName();
} else
Expand Down Expand Up @@ -2725,14 +2717,6 @@ class __SYCL_EXPORT handler {
"Invalid accessor target for the copy method.");
static_assert(isValidModeForSourceAccessor(AccessMode),
"Invalid accessor mode for the copy method.");
#ifndef __SYCL_DEVICE_ONLY__
if (MIsHost) {
// TODO: Temporary implementation for host. Should be handled by memory
// manager.
copyAccToPtrHost(Src, Dst);
return;
}
#endif
setType(detail::CG::CopyAccToPtr);

detail::AccessorBaseHost *AccBase = (detail::AccessorBaseHost *)&Src;
Expand Down Expand Up @@ -2769,14 +2753,7 @@ class __SYCL_EXPORT handler {
"Invalid accessor mode for the copy method.");
// TODO: Add static_assert with is_device_copyable when vec is
// device-copyable.
#ifndef __SYCL_DEVICE_ONLY__
if (MIsHost) {
// TODO: Temporary implementation for host. Should be handled by memory
// manager.
copyPtrToAccHost(Src, Dst);
return;
}
#endif

setType(detail::CG::CopyPtrToAcc);

detail::AccessorBaseHost *AccBase = (detail::AccessorBaseHost *)&Dst;
Expand Down Expand Up @@ -2890,8 +2867,6 @@ class __SYCL_EXPORT handler {
fill(accessor<T, Dims, AccessMode, AccessTarget, IsPlaceholder, PropertyListT>
Dst,
const T &Pattern) {
assert(!MIsHost && "fill() should no longer be callable on a host device.");

if (Dst.is_placeholder())
checkIfPlaceholderIsBoundToHandler(Dst);

Expand Down Expand Up @@ -3429,7 +3404,7 @@ class __SYCL_EXPORT handler {
/// Storage for the CG created when handling graph nodes added explicitly.
std::unique_ptr<detail::CG> MGraphNodeCG;

bool MIsHost = false;
bool MIsHost = false; // ABI break: to remove

detail::code_location MCodeLoc = {};
bool MIsFinalized = false;
Expand Down
42 changes: 15 additions & 27 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,20 @@ context::context(const std::vector<device> &DeviceList,
throw invalid_parameter_error("DeviceList is empty.",
PI_ERROR_INVALID_VALUE);
}
auto NonHostDeviceIter = std::find_if_not(
DeviceList.begin(), DeviceList.end(), [&](const device &CurrentDevice) {
return detail::getSyclObjImpl(CurrentDevice)->is_host();
});
if (NonHostDeviceIter == DeviceList.end())
impl = std::make_shared<detail::context_impl>(DeviceList[0], AsyncHandler,

const auto &RefPlatform =
detail::getSyclObjImpl(DeviceList[0].get_platform())->getHandleRef();
if (std::any_of(DeviceList.begin(), DeviceList.end(),
[&](const device &CurrentDevice) {
return (detail::getSyclObjImpl(CurrentDevice.get_platform())
->getHandleRef() != RefPlatform);
}))
throw invalid_parameter_error(
"Can't add devices across platforms to a single context.",
PI_ERROR_INVALID_DEVICE);
else
impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
PropList);
else {
const device &NonHostDevice = *NonHostDeviceIter;
const auto &NonHostPlatform =
detail::getSyclObjImpl(NonHostDevice.get_platform())->getHandleRef();
if (std::any_of(DeviceList.begin(), DeviceList.end(),
[&](const device &CurrentDevice) {
return (
detail::getSyclObjImpl(CurrentDevice)->is_host() ||
(detail::getSyclObjImpl(CurrentDevice.get_platform())
->getHandleRef() != NonHostPlatform));
}))
throw invalid_parameter_error(
"Can't add devices across platforms to a single context.",
PI_ERROR_INVALID_DEVICE);
else
impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
PropList);
}
}
context::context(cl_context ClContext, async_handler AsyncHandler) {
const auto &Plugin = sycl::detail::pi::getPlugin<backend::opencl>();
Expand Down Expand Up @@ -138,9 +127,8 @@ context::get_backend_info() const {
cl_context context::get() const { return impl->get(); }

bool context::is_host() const {
bool IsHost = impl->is_host();
assert(!IsHost && "context::is_host should not be called in implementation.");
return IsHost;
assert(false && "context::is_host should not be called in implementation.");
return false;
}

backend context::get_backend() const noexcept { return impl->getBackend(); }
Expand Down
1 change: 0 additions & 1 deletion sycl/source/detail/backend_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ inline namespace _V1 {
namespace detail {

template <class T> backend getImplBackend(const T &Impl) {
assert(!Impl->is_host() && "Cannot get the backend for host.");
return Impl->getContextImplPtr()->getBackend();
}

Expand Down
4 changes: 0 additions & 4 deletions sycl/source/detail/bindless_images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,6 @@ __SYCL_EXPORT void *pitched_alloc_device(size_t *resultPitch,

std::shared_ptr<sycl::detail::context_impl> CtxImpl =
sycl::detail::getSyclObjImpl(syclContext);
if (CtxImpl->is_host()) {
throw sycl::exception(sycl::make_error_code(sycl::errc::memory_allocation),
"Cannot allocate pitched memory on host!");
}

pi_context PiContext = CtxImpl->getHandleRef();
const sycl::detail::PluginPtr &Plugin = CtxImpl->getPlugin();
Expand Down
12 changes: 7 additions & 5 deletions sycl/source/detail/buffer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
sycl::detail::pi::PiEvent &OutEventToWait) {
bool HostPtrReadOnly = false;
BaseT::determineHostPtr(Context, InitFromUserData, HostPtr, HostPtrReadOnly);

assert(!(nullptr == HostPtr && BaseT::useHostPtr() && Context->is_host()) &&
assert(!(nullptr == HostPtr && BaseT::useHostPtr() && !Context) &&
"Internal error. Allocating memory on the host "
"while having use_host_ptr property");
return MemoryManager::allocateMemBuffer(
Expand Down Expand Up @@ -71,10 +70,13 @@ buffer_impl::getNativeVector(backend BackendName) const {
sycl::detail::pi::PiMem NativeMem =
pi::cast<sycl::detail::pi::PiMem>(Cmd->getMemAllocation());
auto Ctx = Cmd->getWorkerContext();
auto Platform = Ctx->getPlatformImpl();
// If Host Shared Memory is not supported then there is alloca for host that
// doesn't have platform
if (!Platform || (Platform->getBackend() != BackendName))
// doesn't have context and platform
if (!Ctx)
continue;
PlatformImplPtr Platform = Ctx->getPlatformImpl();
assert(Platform && "Platform must be present for device context");
if (Platform->getBackend() != BackendName)
continue;

auto Plugin = Platform->getPlugin();
Expand Down
Loading
Loading