Skip to content

Commit 3dc75a7

Browse files
[SYCL] Host device & queue removal (internal part, not breaking ABI) (#14370)
Host device support is deprecated long time ago. Although our internal host task & host accessor implementation was still using it. This change eliminates it and remove possibility to create host queue/context and device. This brings the following changes: - Commands & Events could not guarantee queried Context != nullptr and Queue!= nullptr since for host task stuff no device queue/context is involved. For host task we have submitted queue instance stored in event to be able to report exceptions to user and to be able to properly handle dependencies. Submitted queue for host task is guaranteed to be not null. - Connection command for cross context dependencies is now attached to the queue of new command (dependency for which is being analyzed). Previously it was also related to host queue only. No perf impact is expected. - Stream flush command is now submitted to the same queue as corresponding kernel (previously it was submitted to the host queue). This could bring negative perf impact for stream usage with in-order queue but stream is not perf oriented feature. ABI breaking changes to remove is_host methods and some SYCL_EXTERN stuff will be submitted separately. --------- Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 3e06221 commit 3dc75a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+883
-2690
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class __SYCL_EXPORT handler {
466466
/// \param Queue is a SYCL queue.
467467
/// \param IsHost indicates if this handler is created for SYCL host device.
468468
/// TODO: Unused. Remove with ABI break.
469-
handler(std::shared_ptr<detail::queue_impl> Queue, bool IsHost);
469+
handler(std::shared_ptr<detail::queue_impl> Queue, bool /*Unused*/);
470470

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

485485
/// Constructs SYCL handler from queue.
486486
///
487487
/// \param Queue is a SYCL queue.
488488
/// \param IsHost indicates if this handler is created for SYCL host device.
489489
/// \param CallerNeedsEvent indicates if the event resulting from this handler
490490
/// is needed by the caller.
491-
handler(std::shared_ptr<detail::queue_impl> Queue, bool IsHost,
492-
bool CallerNeedsEvent);
491+
handler(std::shared_ptr<detail::queue_impl> Queue,
492+
bool /* ABI break: remove */, bool CallerNeedsEvent);
493493

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

510510
/// Constructs SYCL handler from Graph.
511511
///
@@ -644,7 +644,7 @@ class __SYCL_EXPORT handler {
644644
~handler() = default;
645645

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

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

926-
if (IsCallableWithKernelHandler && MIsHost) {
927-
throw sycl::feature_not_supported(
928-
"kernel_handler is not yet supported by host device.",
929-
PI_ERROR_INVALID_OPERATION);
930-
}
931-
932926
KernelType *KernelPtr =
933927
ResetHostKernel<KernelType, LambdaArgType, Dims>(KernelFunc);
934928

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

10841077
range<1> LinearizedRange(Src.size());
@@ -1100,23 +1093,19 @@ class __SYCL_EXPORT handler {
11001093
///
11011094
/// \param Src is a source SYCL accessor.
11021095
/// \param Dst is a destination SYCL accessor.
1096+
// ABI break: to remove whole method
11031097
template <typename TSrc, int DimSrc, access::mode ModeSrc,
11041098
access::target TargetSrc, typename TDst, int DimDst,
11051099
access::mode ModeDst, access::target TargetDst,
11061100
access::placeholder IsPHSrc, access::placeholder IsPHDst>
11071101
std::enable_if_t<DimSrc == 0 || DimDst == 0, bool>
1108-
copyAccToAccHelper(accessor<TSrc, DimSrc, ModeSrc, TargetSrc, IsPHSrc> Src,
1109-
accessor<TDst, DimDst, ModeDst, TargetDst, IsPHDst> Dst) {
1110-
if (!MIsHost)
1111-
return false;
1112-
1113-
single_task<__copyAcc2Acc<TSrc, DimSrc, ModeSrc, TargetSrc, TDst, DimDst,
1114-
ModeDst, TargetDst, IsPHSrc, IsPHDst>>(
1115-
[=]() { *(Dst.get_pointer()) = *(Src.get_pointer()); });
1116-
return true;
1102+
copyAccToAccHelper(accessor<TSrc, DimSrc, ModeSrc, TargetSrc, IsPHSrc>,
1103+
accessor<TDst, DimDst, ModeDst, TargetDst, IsPHDst>) {
1104+
return false;
11171105
}
11181106

11191107
#ifndef __SYCL_DEVICE_ONLY__
1108+
// ABI break: to remove whole method
11201109
/// Copies the content of memory object accessed by Src into the memory
11211110
/// pointed by Dst.
11221111
///
@@ -1136,6 +1125,7 @@ class __SYCL_EXPORT handler {
11361125
});
11371126
}
11381127

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

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

1164+
// ABI break: to remove whole method
11731165
/// Copies 1 element pointed by Src to memory accessed by 0-dimensional
11741166
/// accessor Dst.
11751167
///
@@ -2282,7 +2274,7 @@ class __SYCL_EXPORT handler {
22822274
MNDRDesc.set(range<1>{1});
22832275
MKernel = detail::getSyclObjImpl(std::move(Kernel));
22842276
setType(detail::CG::Kernel);
2285-
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
2277+
if (!lambdaAndKernelHaveEqualName<NameT>()) {
22862278
extractArgsAndReqs();
22872279
MKernelName = getKernelName();
22882280
} else
@@ -2319,7 +2311,7 @@ class __SYCL_EXPORT handler {
23192311
MKernel = detail::getSyclObjImpl(std::move(Kernel));
23202312
setType(detail::CG::Kernel);
23212313
setNDRangeUsed(false);
2322-
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
2314+
if (!lambdaAndKernelHaveEqualName<NameT>()) {
23232315
extractArgsAndReqs();
23242316
MKernelName = getKernelName();
23252317
} else
@@ -2359,7 +2351,7 @@ class __SYCL_EXPORT handler {
23592351
MKernel = detail::getSyclObjImpl(std::move(Kernel));
23602352
setType(detail::CG::Kernel);
23612353
setNDRangeUsed(false);
2362-
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
2354+
if (!lambdaAndKernelHaveEqualName<NameT>()) {
23632355
extractArgsAndReqs();
23642356
MKernelName = getKernelName();
23652357
} else
@@ -2398,7 +2390,7 @@ class __SYCL_EXPORT handler {
23982390
MKernel = detail::getSyclObjImpl(std::move(Kernel));
23992391
setType(detail::CG::Kernel);
24002392
setNDRangeUsed(true);
2401-
if (!MIsHost && !lambdaAndKernelHaveEqualName<NameT>()) {
2393+
if (!lambdaAndKernelHaveEqualName<NameT>()) {
24022394
extractArgsAndReqs();
24032395
MKernelName = getKernelName();
24042396
} else
@@ -2725,14 +2717,6 @@ class __SYCL_EXPORT handler {
27252717
"Invalid accessor target for the copy method.");
27262718
static_assert(isValidModeForSourceAccessor(AccessMode),
27272719
"Invalid accessor mode for the copy method.");
2728-
#ifndef __SYCL_DEVICE_ONLY__
2729-
if (MIsHost) {
2730-
// TODO: Temporary implementation for host. Should be handled by memory
2731-
// manager.
2732-
copyAccToPtrHost(Src, Dst);
2733-
return;
2734-
}
2735-
#endif
27362720
setType(detail::CG::CopyAccToPtr);
27372721

27382722
detail::AccessorBaseHost *AccBase = (detail::AccessorBaseHost *)&Src;
@@ -2769,14 +2753,7 @@ class __SYCL_EXPORT handler {
27692753
"Invalid accessor mode for the copy method.");
27702754
// TODO: Add static_assert with is_device_copyable when vec is
27712755
// device-copyable.
2772-
#ifndef __SYCL_DEVICE_ONLY__
2773-
if (MIsHost) {
2774-
// TODO: Temporary implementation for host. Should be handled by memory
2775-
// manager.
2776-
copyPtrToAccHost(Src, Dst);
2777-
return;
2778-
}
2779-
#endif
2756+
27802757
setType(detail::CG::CopyPtrToAcc);
27812758

27822759
detail::AccessorBaseHost *AccBase = (detail::AccessorBaseHost *)&Dst;
@@ -2890,8 +2867,6 @@ class __SYCL_EXPORT handler {
28902867
fill(accessor<T, Dims, AccessMode, AccessTarget, IsPlaceholder, PropertyListT>
28912868
Dst,
28922869
const T &Pattern) {
2893-
assert(!MIsHost && "fill() should no longer be callable on a host device.");
2894-
28952870
if (Dst.is_placeholder())
28962871
checkIfPlaceholderIsBoundToHandler(Dst);
28972872

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

3432-
bool MIsHost = false;
3407+
bool MIsHost = false; // ABI break: to remove
34333408

34343409
detail::code_location MCodeLoc = {};
34353410
bool MIsFinalized = false;

sycl/source/context.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,20 @@ context::context(const std::vector<device> &DeviceList,
5656
throw invalid_parameter_error("DeviceList is empty.",
5757
PI_ERROR_INVALID_VALUE);
5858
}
59-
auto NonHostDeviceIter = std::find_if_not(
60-
DeviceList.begin(), DeviceList.end(), [&](const device &CurrentDevice) {
61-
return detail::getSyclObjImpl(CurrentDevice)->is_host();
62-
});
63-
if (NonHostDeviceIter == DeviceList.end())
64-
impl = std::make_shared<detail::context_impl>(DeviceList[0], AsyncHandler,
59+
60+
const auto &RefPlatform =
61+
detail::getSyclObjImpl(DeviceList[0].get_platform())->getHandleRef();
62+
if (std::any_of(DeviceList.begin(), DeviceList.end(),
63+
[&](const device &CurrentDevice) {
64+
return (detail::getSyclObjImpl(CurrentDevice.get_platform())
65+
->getHandleRef() != RefPlatform);
66+
}))
67+
throw invalid_parameter_error(
68+
"Can't add devices across platforms to a single context.",
69+
PI_ERROR_INVALID_DEVICE);
70+
else
71+
impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
6572
PropList);
66-
else {
67-
const device &NonHostDevice = *NonHostDeviceIter;
68-
const auto &NonHostPlatform =
69-
detail::getSyclObjImpl(NonHostDevice.get_platform())->getHandleRef();
70-
if (std::any_of(DeviceList.begin(), DeviceList.end(),
71-
[&](const device &CurrentDevice) {
72-
return (
73-
detail::getSyclObjImpl(CurrentDevice)->is_host() ||
74-
(detail::getSyclObjImpl(CurrentDevice.get_platform())
75-
->getHandleRef() != NonHostPlatform));
76-
}))
77-
throw invalid_parameter_error(
78-
"Can't add devices across platforms to a single context.",
79-
PI_ERROR_INVALID_DEVICE);
80-
else
81-
impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
82-
PropList);
83-
}
8473
}
8574
context::context(cl_context ClContext, async_handler AsyncHandler) {
8675
const auto &Plugin = sycl::detail::pi::getPlugin<backend::opencl>();
@@ -138,9 +127,8 @@ context::get_backend_info() const {
138127
cl_context context::get() const { return impl->get(); }
139128

140129
bool context::is_host() const {
141-
bool IsHost = impl->is_host();
142-
assert(!IsHost && "context::is_host should not be called in implementation.");
143-
return IsHost;
130+
assert(false && "context::is_host should not be called in implementation.");
131+
return false;
144132
}
145133

146134
backend context::get_backend() const noexcept { return impl->getBackend(); }

sycl/source/detail/backend_impl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ inline namespace _V1 {
1515
namespace detail {
1616

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

sycl/source/detail/bindless_images.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,6 @@ __SYCL_EXPORT void *pitched_alloc_device(size_t *resultPitch,
862862

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

870866
pi_context PiContext = CtxImpl->getHandleRef();
871867
const sycl::detail::PluginPtr &Plugin = CtxImpl->getPlugin();

sycl/source/detail/buffer_impl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ void *buffer_impl::allocateMem(ContextImplPtr Context, bool InitFromUserData,
2424
sycl::detail::pi::PiEvent &OutEventToWait) {
2525
bool HostPtrReadOnly = false;
2626
BaseT::determineHostPtr(Context, InitFromUserData, HostPtr, HostPtrReadOnly);
27-
28-
assert(!(nullptr == HostPtr && BaseT::useHostPtr() && Context->is_host()) &&
27+
assert(!(nullptr == HostPtr && BaseT::useHostPtr() && !Context) &&
2928
"Internal error. Allocating memory on the host "
3029
"while having use_host_ptr property");
3130
return MemoryManager::allocateMemBuffer(
@@ -71,10 +70,13 @@ buffer_impl::getNativeVector(backend BackendName) const {
7170
sycl::detail::pi::PiMem NativeMem =
7271
pi::cast<sycl::detail::pi::PiMem>(Cmd->getMemAllocation());
7372
auto Ctx = Cmd->getWorkerContext();
74-
auto Platform = Ctx->getPlatformImpl();
7573
// If Host Shared Memory is not supported then there is alloca for host that
76-
// doesn't have platform
77-
if (!Platform || (Platform->getBackend() != BackendName))
74+
// doesn't have context and platform
75+
if (!Ctx)
76+
continue;
77+
PlatformImplPtr Platform = Ctx->getPlatformImpl();
78+
assert(Platform && "Platform must be present for device context");
79+
if (Platform->getBackend() != BackendName)
7880
continue;
7981

8082
auto Plugin = Platform->getPlugin();

0 commit comments

Comments
 (0)