diff --git a/sycl/include/sycl/backend_types.hpp b/sycl/include/sycl/backend_types.hpp index 2d59d21fa27c7..a095f891fa989 100644 --- a/sycl/include/sycl/backend_types.hpp +++ b/sycl/include/sycl/backend_types.hpp @@ -19,7 +19,7 @@ namespace sycl { __SYCL_INLINE_VER_NAMESPACE(_V1) { enum class backend : char { - host = 0, + host __SYCL2020_DEPRECATED("'host' backend is no longer supported") = 0, opencl = 1, ext_oneapi_level_zero = 2, level_zero __SYCL2020_DEPRECATED("use 'ext_oneapi_level_zero' instead") = diff --git a/sycl/include/sycl/context.hpp b/sycl/include/sycl/context.hpp index fa578435effc0..ac82bfd4197ae 100644 --- a/sycl/include/sycl/context.hpp +++ b/sycl/include/sycl/context.hpp @@ -200,6 +200,8 @@ class __SYCL_EXPORT context { /// Checks if this context is a SYCL host context. /// /// \return true if this context is a SYCL host context. + __SYCL2020_DEPRECATED( + "is_host() is deprecated as the host device is no longer supported.") bool is_host() const; /// Returns the backend associated with this context. diff --git a/sycl/include/sycl/detail/device_filter.hpp b/sycl/include/sycl/detail/device_filter.hpp index 9f19ef0ebb521..903df99c76414 100644 --- a/sycl/include/sycl/detail/device_filter.hpp +++ b/sycl/include/sycl/detail/device_filter.hpp @@ -46,7 +46,6 @@ class device_filter_list { bool backendCompatible(backend Backend); bool deviceTypeCompatible(info::device_type DeviceType); bool deviceNumberCompatible(int DeviceNum); - bool containsHost(); friend std::ostream &operator<<(std::ostream &Out, const device_filter_list &List); }; diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index 927ecf49e353c..5228caca0f246 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -99,6 +99,8 @@ class __SYCL_EXPORT device { /// Check if device is a host device /// /// \return true if SYCL device is a host device + __SYCL2020_DEPRECATED( + "is_host() is deprecated as the host device is no longer supported.") bool is_host() const; /// Check if device is a CPU device diff --git a/sycl/include/sycl/device_selector.hpp b/sycl/include/sycl/device_selector.hpp index 68ab42ed4c96b..ef27a83eb52b8 100644 --- a/sycl/include/sycl/device_selector.hpp +++ b/sycl/include/sycl/device_selector.hpp @@ -96,7 +96,7 @@ __SYCL2020_DEPRECATED("Use the callable sycl::accelerator_selector_v instead.") /// /// \ingroup sycl_api_dev_sel class __SYCL_EXPORT -__SYCL2020_DEPRECATED("Use a callable function instead.") host_selector +__SYCL2020_DEPRECATED("Host device is no longer supported.") host_selector : public device_selector { public: int operator()(const device &dev) const override; diff --git a/sycl/include/sycl/event.hpp b/sycl/include/sycl/event.hpp index 08c6e8c799f04..b672e1c114280 100644 --- a/sycl/include/sycl/event.hpp +++ b/sycl/include/sycl/event.hpp @@ -67,6 +67,8 @@ class __SYCL_EXPORT event { /// Checks if this event is a SYCL host event. /// /// \return true if this event is a SYCL host event. + __SYCL2020_DEPRECATED( + "is_host() is deprecated as the host device is no longer supported.") bool is_host() const; /// Return the list of events that this event waits for. diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index bdb974d7f65ef..0b53442e7d75e 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -468,8 +468,6 @@ class __SYCL_EXPORT handler { ~handler() = default; - bool is_host() { return MIsHost; } - #ifdef __SYCL_DEVICE_ONLY__ // In device compilation accessor isn't inherited from AccessorBaseHost, so // can't detect by it. Since we don't expect it to be ever called in device @@ -543,18 +541,6 @@ class __SYCL_EXPORT handler { sizeof(sampler), ArgIndex); } - void verifyKernelInvoc(const kernel &Kernel) { - if (is_host()) { - throw invalid_object_error( - "This kernel invocation method cannot be used on the host", - PI_ERROR_INVALID_DEVICE); - } - if (Kernel.is_host()) { - throw invalid_object_error("Invalid kernel type, OpenCL expected", - PI_ERROR_INVALID_KERNEL); - } - } - /* The kernel passed to StoreLambda can take an id, an item or an nd_item as * its argument. Since esimd plugin directly invokes the kernel (doesn’t use * piKernelSetArg), the kernel argument type must be known to the plugin. @@ -1066,7 +1052,6 @@ class __SYCL_EXPORT handler { template void parallel_for_impl(range NumWorkItems, kernel Kernel) { throwIfActionIsCreated(); - verifyKernelInvoc(Kernel); MKernel = detail::getSyclObjImpl(std::move(Kernel)); detail::checkValueRange(NumWorkItems); MNDRDesc.set(std::move(NumWorkItems)); @@ -1877,7 +1862,6 @@ class __SYCL_EXPORT handler { /// \param Kernel is a SYCL kernel object. void single_task(kernel Kernel) { throwIfActionIsCreated(); - verifyKernelInvoc(Kernel); // Ignore any set kernel bundles and use the one associated with the kernel setHandlerKernelBundle(Kernel); // No need to check if range is out of INT_MAX limits as it's compile-time @@ -1914,7 +1898,6 @@ class __SYCL_EXPORT handler { void parallel_for(range NumWorkItems, id WorkItemOffset, kernel Kernel) { throwIfActionIsCreated(); - verifyKernelInvoc(Kernel); MKernel = detail::getSyclObjImpl(std::move(Kernel)); detail::checkValueRange(NumWorkItems, WorkItemOffset); MNDRDesc.set(std::move(NumWorkItems), std::move(WorkItemOffset)); @@ -1933,7 +1916,6 @@ class __SYCL_EXPORT handler { /// \param Kernel is a SYCL kernel function. template void parallel_for(nd_range NDRange, kernel Kernel) { throwIfActionIsCreated(); - verifyKernelInvoc(Kernel); MKernel = detail::getSyclObjImpl(std::move(Kernel)); detail::checkValueRange(NDRange); MNDRDesc.set(std::move(NDRange)); diff --git a/sycl/include/sycl/kernel.hpp b/sycl/include/sycl/kernel.hpp index d4a23d5b6cc3a..14efb878bc7ef 100644 --- a/sycl/include/sycl/kernel.hpp +++ b/sycl/include/sycl/kernel.hpp @@ -105,6 +105,8 @@ class __SYCL_EXPORT kernel { /// Check if the associated SYCL context is a SYCL host context. /// /// \return true if this SYCL kernel is a host kernel. + __SYCL2020_DEPRECATED( + "is_host() is deprecated as the host device is no longer supported.") bool is_host() const; /// Get the context that this kernel is defined for. diff --git a/sycl/include/sycl/platform.hpp b/sycl/include/sycl/platform.hpp index fee1b98a4acfc..85de7409ceb7a 100644 --- a/sycl/include/sycl/platform.hpp +++ b/sycl/include/sycl/platform.hpp @@ -109,6 +109,8 @@ class __SYCL_EXPORT platform { /// Checks if this SYCL platform is a host platform. /// /// \return true if this SYCL platform is a host platform. + __SYCL2020_DEPRECATED( + "is_host() is deprecated as the host device is no longer supported.") bool is_host() const; /// Returns all SYCL devices associated with this platform. diff --git a/sycl/include/sycl/queue.hpp b/sycl/include/sycl/queue.hpp index dcfc0488645fc..fd2cf7736dc3a 100644 --- a/sycl/include/sycl/queue.hpp +++ b/sycl/include/sycl/queue.hpp @@ -278,6 +278,8 @@ class __SYCL_EXPORT queue { device get_device() const; /// \return true if this queue is a SYCL host queue. + __SYCL2020_DEPRECATED( + "is_host() is deprecated as the host device is no longer supported.") bool is_host() const; /// Queries SYCL queue for information. @@ -302,28 +304,24 @@ class __SYCL_EXPORT queue { _CODELOCARG(&CodeLoc); #if __SYCL_USE_FALLBACK_ASSERT - if (!is_host()) { - auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert, - event &E) { - if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) && - KernelUsesAssert && !device_has(aspect::accelerator)) { - // __devicelib_assert_fail isn't supported by Device-side Runtime - // Linking against fallback impl of __devicelib_assert_fail is - // performed by program manager class - // Fallback assert isn't supported for FPGA - submitAssertCapture(*this, E, /* SecondaryQueue = */ nullptr, - CodeLoc); - } - }; - - auto Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess); - return discard_or_return(Event); - } else + auto PostProcess = [this, &CodeLoc](bool IsKernel, bool KernelUsesAssert, + event &E) { + if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) && + KernelUsesAssert && !device_has(aspect::accelerator)) { + // __devicelib_assert_fail isn't supported by Device-side Runtime + // Linking against fallback impl of __devicelib_assert_fail is + // performed by program manager class + // Fallback assert isn't supported for FPGA + submitAssertCapture(*this, E, /* SecondaryQueue = */ nullptr, CodeLoc); + } + }; + + auto Event = submit_impl_and_postprocess(CGF, CodeLoc, PostProcess); + return discard_or_return(Event); +#else + auto Event = submit_impl(CGF, CodeLoc); + return discard_or_return(Event); #endif // __SYCL_USE_FALLBACK_ASSERT - { - auto Event = submit_impl(CGF, CodeLoc); - return discard_or_return(Event); - } } /// Submits a command group function object to the queue, in order to be @@ -342,34 +340,27 @@ class __SYCL_EXPORT queue { _CODELOCARG(&CodeLoc); #if __SYCL_USE_FALLBACK_ASSERT - if (!is_host()) { - auto PostProcess = [this, &SecondaryQueue, &CodeLoc]( - bool IsKernel, bool KernelUsesAssert, event &E) { - if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) && - KernelUsesAssert && !device_has(aspect::accelerator)) { - // Only secondary queues on devices need to be added to the assert - // capture. - // TODO: Handle case where primary queue is host but the secondary - // queue is not. - queue *DeviceSecondaryQueue = - SecondaryQueue.is_host() ? nullptr : &SecondaryQueue; - // __devicelib_assert_fail isn't supported by Device-side Runtime - // Linking against fallback impl of __devicelib_assert_fail is - // performed by program manager class - // Fallback assert isn't supported for FPGA - submitAssertCapture(*this, E, DeviceSecondaryQueue, CodeLoc); - } - }; - - auto Event = submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc, - PostProcess); - return discard_or_return(Event); - } else + auto PostProcess = [this, &SecondaryQueue, &CodeLoc]( + bool IsKernel, bool KernelUsesAssert, event &E) { + if (IsKernel && !device_has(aspect::ext_oneapi_native_assert) && + KernelUsesAssert && !device_has(aspect::accelerator)) { + // Only secondary queues on devices need to be added to the assert + // capture. + // __devicelib_assert_fail isn't supported by Device-side Runtime + // Linking against fallback impl of __devicelib_assert_fail is + // performed by program manager class + // Fallback assert isn't supported for FPGA + submitAssertCapture(*this, E, &SecondaryQueue, CodeLoc); + } + }; + + auto Event = + submit_impl_and_postprocess(CGF, SecondaryQueue, CodeLoc, PostProcess); + return discard_or_return(Event); +#else + auto Event = submit_impl(CGF, SecondaryQueue, CodeLoc); + return discard_or_return(Event); #endif // __SYCL_USE_FALLBACK_ASSERT - { - auto Event = submit_impl(CGF, SecondaryQueue, CodeLoc); - return discard_or_return(Event); - } } /// Prevents any commands submitted afterward to this queue from executing diff --git a/sycl/source/context.cpp b/sycl/source/context.cpp index eb6cacc8520bb..fa42664548d46 100644 --- a/sycl/source/context.cpp +++ b/sycl/source/context.cpp @@ -58,8 +58,9 @@ context::context(const std::vector &DeviceList, PI_ERROR_INVALID_VALUE); } auto NonHostDeviceIter = std::find_if_not( - DeviceList.begin(), DeviceList.end(), - [&](const device &CurrentDevice) { return CurrentDevice.is_host(); }); + DeviceList.begin(), DeviceList.end(), [&](const device &CurrentDevice) { + return detail::getSyclObjImpl(CurrentDevice)->is_host(); + }); if (NonHostDeviceIter == DeviceList.end()) impl = std::make_shared(DeviceList[0], AsyncHandler, PropList); @@ -70,7 +71,7 @@ context::context(const std::vector &DeviceList, if (std::any_of(DeviceList.begin(), DeviceList.end(), [&](const device &CurrentDevice) { return ( - CurrentDevice.is_host() || + detail::getSyclObjImpl(CurrentDevice)->is_host() || (detail::getSyclObjImpl(CurrentDevice.get_platform()) ->getHandleRef() != NonHostPlatform)); })) @@ -122,7 +123,11 @@ context::get_info() const { cl_context context::get() const { return impl->get(); } -bool context::is_host() const { return impl->is_host(); } +bool context::is_host() const { + bool IsHost = impl->is_host(); + assert(!IsHost && "context::is_host should not be called in implementation."); + return IsHost; +} backend context::get_backend() const noexcept { return getImplBackend(impl); } diff --git a/sycl/source/detail/backend_impl.hpp b/sycl/source/detail/backend_impl.hpp index 6576340421f10..fb3ab07737dda 100644 --- a/sycl/source/detail/backend_impl.hpp +++ b/sycl/source/detail/backend_impl.hpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #pragma once +#include #include namespace sycl { @@ -14,13 +15,8 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) { namespace detail { template backend getImplBackend(const T &Impl) { - backend Result; - if (Impl->is_host()) - Result = backend::host; - else - Result = Impl->getPlugin().getBackend(); - - return Result; + assert(!Impl->is_host() && "Cannot get the backend for host."); + return Impl->getPlugin().getBackend(); } } // namespace detail diff --git a/sycl/source/detail/context_impl.cpp b/sycl/source/detail/context_impl.cpp index fee5c27ce94b4..a93a98024db7b 100644 --- a/sycl/source/detail/context_impl.cpp +++ b/sycl/source/detail/context_impl.cpp @@ -28,7 +28,8 @@ namespace detail { context_impl::context_impl(const device &Device, async_handler AsyncHandler, const property_list &PropList) : MAsyncHandler(AsyncHandler), MDevices(1, Device), MContext(nullptr), - MPlatform(), MPropList(PropList), MHostContext(Device.is_host()), + MPlatform(), MPropList(PropList), + MHostContext(detail::getSyclObjImpl(Device)->is_host()), MSupportBufferLocationByDevices(NotChecked) { MKernelProgramCache.setContextPtr(this); } diff --git a/sycl/source/detail/device_filter.cpp b/sycl/source/detail/device_filter.cpp index da04cb614143e..3b12da90f71ea 100644 --- a/sycl/source/detail/device_filter.cpp +++ b/sycl/source/detail/device_filter.cpp @@ -61,6 +61,11 @@ device_filter::device_filter(const std::string &FilterString) { else { Backend = It->second; TripleValueID++; + + if (Backend == backend::host) + std::cerr << "WARNING: The 'host' backend type is no longer supported in " + "device filter." + << std::endl; } // Handle the optional 2nd field of the filter - device type. @@ -77,6 +82,11 @@ device_filter::device_filter(const std::string &FilterString) { else { DeviceType = Iter->second; TripleValueID++; + + if (DeviceType == info::device_type::host) + std::cerr << "WARNING: The 'host' device type is no longer supported " + "in device filter." + << std::endl; } } @@ -91,8 +101,8 @@ device_filter::device_filter(const std::string &FilterString) { std::string Message = std::string("Invalid device filter: ") + FilterString + "\nPossible backend values are " - "{host,opencl,level_zero,cuda,hip,esimd_emulator,*}.\n" - "Possible device types are {host,cpu,gpu,acc,*}.\n" + "{opencl,level_zero,cuda,hip,esimd_emulator,*}.\n" + "Possible device types are {cpu,gpu,acc,*}.\n" "Device number should be an non-negative integer.\n"; throw sycl::invalid_parameter_error(Message, PI_ERROR_INVALID_VALUE); } @@ -157,19 +167,6 @@ bool device_filter_list::deviceNumberCompatible(int DeviceNum) { return false; } -bool device_filter_list::containsHost() { - for (const device_filter &Filter : FilterList) { - if (Filter.Backend == backend::host || Filter.Backend == backend::all) - if (Filter.DeviceType == info::device_type::host || - Filter.DeviceType == info::device_type::all) - // SYCL RT never creates more than one HOST device. - // All device numbers other than 0 are rejected. - if (!Filter.HasDeviceNum || Filter.DeviceNum == 0) - return true; - } - return false; -} - } // namespace detail } // __SYCL_INLINE_VER_NAMESPACE(_V1) } // namespace sycl diff --git a/sycl/source/detail/device_impl.cpp b/sycl/source/detail/device_impl.cpp index 486e9997a2c0e..b73e1fd46f285 100644 --- a/sycl/source/detail/device_impl.cpp +++ b/sycl/source/detail/device_impl.cpp @@ -153,12 +153,7 @@ device_impl::create_sub_devices(const cl_device_partition_property *Properties, } std::vector device_impl::create_sub_devices(size_t ComputeUnits) const { - - if (MIsHostDevice) - // TODO: implement host device partitioning - throw runtime_error( - "Partitioning to subdevices of the host device is not implemented yet", - PI_ERROR_INVALID_DEVICE); + assert(!MIsHostDevice && "Partitioning is not supported on host."); if (!is_partition_supported(info::partition_property::partition_equally)) { throw sycl::feature_not_supported( @@ -182,12 +177,7 @@ std::vector device_impl::create_sub_devices(size_t ComputeUnits) const { std::vector device_impl::create_sub_devices(const std::vector &Counts) const { - - if (MIsHostDevice) - // TODO: implement host device partitioning - throw runtime_error( - "Partitioning to subdevices of the host device is not implemented yet", - PI_ERROR_INVALID_DEVICE); + assert(!MIsHostDevice && "Partitioning is not supported on host."); if (!is_partition_supported(info::partition_property::partition_by_counts)) { throw sycl::feature_not_supported( @@ -230,12 +220,7 @@ device_impl::create_sub_devices(const std::vector &Counts) const { std::vector device_impl::create_sub_devices( info::partition_affinity_domain AffinityDomain) const { - - if (MIsHostDevice) - // TODO: implement host device partitioning - throw runtime_error( - "Partitioning to subdevices of the host device is not implemented yet", - PI_ERROR_INVALID_DEVICE); + assert(!MIsHostDevice && "Partitioning is not supported on host."); if (!is_partition_supported( info::partition_property::partition_by_affinity_domain)) { diff --git a/sycl/source/detail/device_info.hpp b/sycl/source/detail/device_info.hpp index 6f00fe20cd001..b62f9aa8a8e56 100644 --- a/sycl/source/detail/device_info.hpp +++ b/sycl/source/detail/device_info.hpp @@ -1302,9 +1302,8 @@ inline bool get_device_info_host() { } template <> inline device get_device_info_host() { - // TODO: implement host device partitioning throw invalid_object_error( - "Partitioning to subdevices of the host device is not implemented yet", + "Partitioning to subdevices of the host device is not implemented", PI_ERROR_INVALID_DEVICE); } diff --git a/sycl/source/detail/filter_selector_impl.cpp b/sycl/source/detail/filter_selector_impl.cpp index eb7e5c3fbca5c..3d89773aa8552 100644 --- a/sycl/source/detail/filter_selector_impl.cpp +++ b/sycl/source/detail/filter_selector_impl.cpp @@ -83,16 +83,6 @@ filter create_filter(const std::string &Input) { } else if (Token == "hip" && !Result.HasBackend) { Result.Backend = backend::ext_oneapi_hip; Result.HasBackend = true; - } else if (Token == "host") { - if (!Result.HasBackend) { - Result.Backend = backend::host; - Result.HasBackend = true; - } else if (!Result.HasDeviceType && Result.Backend != backend::host) { - // We already set everything earlier or it's an error. - throw sycl::runtime_error( - "Cannot specify host device with non-host backend.", - PI_ERROR_INVALID_VALUE); - } } else if (std::regex_match(Token, IntegerExpr) && !Result.HasDeviceNum) { try { Result.DeviceNum = std::stoi(Token); @@ -120,6 +110,9 @@ filter_selector_impl::filter_selector_impl(const std::string &Input) } int filter_selector_impl::operator()(const device &Dev) const { + assert(!sycl::detail::getSyclObjImpl(Dev)->is_host() && + "filter_selector_impl should not be used with host."); + int Score = REJECT_DEVICE_SCORE; for (auto &Filter : mFilters) { @@ -127,14 +120,8 @@ int filter_selector_impl::operator()(const device &Dev) const { bool DeviceTypeOK = true; bool DeviceNumOK = true; - // handle host device specially if (Filter.HasBackend) { - backend BE; - if (Dev.is_host()) { - BE = backend::host; - } else { - BE = sycl::detail::getSyclObjImpl(Dev)->getPlugin().getBackend(); - } + backend BE = sycl::detail::getSyclObjImpl(Dev)->getPlugin().getBackend(); // Backend is okay if the filter BE is set 'all'. if (Filter.Backend == backend::all) BackendOK = true; diff --git a/sycl/source/detail/memory_manager.cpp b/sycl/source/detail/memory_manager.cpp index cf915e6ef2c1a..c2295fb2a4c1a 100644 --- a/sycl/source/detail/memory_manager.cpp +++ b/sycl/source/detail/memory_manager.cpp @@ -840,10 +840,11 @@ void MemoryManager::copy_usm(const void *SrcMem, QueueImplPtr SrcQueue, size_t Len, void *DstMem, std::vector DepEvents, RT::PiEvent *OutEvent) { - sycl::context Context = SrcQueue->get_context(); + assert(!SrcQueue->getContextImplPtr()->is_host() && + "Host queue not supported in fill_usm."); if (!Len) { // no-op, but ensure DepEvents will still be waited on - if (!Context.is_host() && !DepEvents.empty()) { + if (!DepEvents.empty()) { SrcQueue->getPlugin().call( SrcQueue->getHandleRef(), DepEvents.size(), DepEvents.data(), OutEvent); @@ -855,24 +856,21 @@ void MemoryManager::copy_usm(const void *SrcMem, QueueImplPtr SrcQueue, throw runtime_error("NULL pointer argument in memory copy operation.", PI_ERROR_INVALID_VALUE); - if (Context.is_host()) { - std::memcpy(DstMem, SrcMem, Len); - } else { - const detail::plugin &Plugin = SrcQueue->getPlugin(); - Plugin.call(SrcQueue->getHandleRef(), - /* blocking */ false, DstMem, - SrcMem, Len, DepEvents.size(), - DepEvents.data(), OutEvent); - } + const detail::plugin &Plugin = SrcQueue->getPlugin(); + Plugin.call(SrcQueue->getHandleRef(), + /* blocking */ false, DstMem, + SrcMem, Len, DepEvents.size(), + DepEvents.data(), OutEvent); } void MemoryManager::fill_usm(void *Mem, QueueImplPtr Queue, size_t Length, int Pattern, std::vector DepEvents, RT::PiEvent *OutEvent) { - sycl::context Context = Queue->get_context(); + assert(!Queue->getContextImplPtr()->is_host() && + "Host queue not supported in fill_usm."); if (!Length) { // no-op, but ensure DepEvents will still be waited on - if (!Context.is_host() && !DepEvents.empty()) { + if (!DepEvents.empty()) { Queue->getPlugin().call( Queue->getHandleRef(), DepEvents.size(), DepEvents.data(), OutEvent); } @@ -883,42 +881,34 @@ void MemoryManager::fill_usm(void *Mem, QueueImplPtr Queue, size_t Length, throw runtime_error("NULL pointer argument in memory fill operation.", PI_ERROR_INVALID_VALUE); - if (Context.is_host()) { - std::memset(Mem, Pattern, Length); - } else { - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( - Queue->getHandleRef(), Mem, Pattern, Length, DepEvents.size(), - DepEvents.data(), OutEvent); - } + const detail::plugin &Plugin = Queue->getPlugin(); + Plugin.call( + Queue->getHandleRef(), Mem, Pattern, Length, DepEvents.size(), + DepEvents.data(), OutEvent); } void MemoryManager::prefetch_usm(void *Mem, QueueImplPtr Queue, size_t Length, std::vector DepEvents, RT::PiEvent *OutEvent) { - sycl::context Context = Queue->get_context(); + assert(!Queue->getContextImplPtr()->is_host() && + "Host queue not supported in prefetch_usm."); - if (Context.is_host()) { - // TODO: Potentially implement prefetch on the host. - } else { - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call( - Queue->getHandleRef(), Mem, Length, _pi_usm_migration_flags(0), - DepEvents.size(), DepEvents.data(), OutEvent); - } + const detail::plugin &Plugin = Queue->getPlugin(); + Plugin.call( + Queue->getHandleRef(), Mem, Length, _pi_usm_migration_flags(0), + DepEvents.size(), DepEvents.data(), OutEvent); } void MemoryManager::advise_usm(const void *Mem, QueueImplPtr Queue, size_t Length, pi_mem_advice Advice, std::vector /*DepEvents*/, RT::PiEvent *OutEvent) { - sycl::context Context = Queue->get_context(); + assert(!Queue->getContextImplPtr()->is_host() && + "Host queue not supported in advise_usm."); - if (!Context.is_host()) { - const detail::plugin &Plugin = Queue->getPlugin(); - Plugin.call(Queue->getHandleRef(), Mem, - Length, Advice, OutEvent); - } + const detail::plugin &Plugin = Queue->getPlugin(); + Plugin.call(Queue->getHandleRef(), Mem, + Length, Advice, OutEvent); } } // namespace detail } // __SYCL_INLINE_VER_NAMESPACE(_V1) diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index e97f77439fa44..661f6725b4cbb 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -75,7 +75,7 @@ static bool IsBannedPlatform(platform Platform) { // where CUDA is available, the OpenCL support is disabled. // auto IsNVIDIAOpenCL = [](platform Platform) { - if (Platform.is_host()) + if (getSyclObjImpl(Platform)->is_host()) return false; const bool HasCUDA = Platform.get_info().find( @@ -137,14 +137,6 @@ std::vector platform_impl::get_platforms() { // may be initialized after. GlobalHandler::registerDefaultContextReleaseHandler(); - // The host platform should always be available unless not allowed by the - // SYCL_DEVICE_FILTER - detail::device_filter_list *FilterList = - detail::SYCLConfig::get(); - if (!FilterList || FilterList->backendCompatible(backend::host)) - Platforms.emplace_back( - createSyclObjFromImpl(platform_impl::getHostPlatformImpl())); - return Platforms; } @@ -239,12 +231,8 @@ platform_impl::get_devices(info::device_type DeviceType) const { std::vector Res; if (is_host() && (DeviceType == info::device_type::host || DeviceType == info::device_type::all)) { - // If SYCL_DEVICE_FILTER is set, check if filter contains host. - device_filter_list *FilterList = SYCLConfig::get(); - if (!FilterList || FilterList->containsHost()) { - Res.push_back( - createSyclObjFromImpl(device_impl::getHostDeviceImpl())); - } + Res.push_back( + createSyclObjFromImpl(device_impl::getHostDeviceImpl())); } // If any DeviceType other than host was requested for host platform, diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 98c82d812be82..f55b845b1c84e 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -223,7 +223,7 @@ void *queue_impl::instrumentationProlog(const detail::code_location &CodeLoc, if (WaitEvent) { device D = get_device(); std::string DevStr; - if (D.is_host()) + if (getSyclObjImpl(D)->is_host()) DevStr = "HOST"; else if (D.is_cpu()) DevStr = "CPU"; diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 9ab0eba9974d2..8f5f18a090aa8 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -72,7 +72,7 @@ static std::string demangleKernelName(std::string Name) { return Name; } #endif static std::string deviceToString(device Device) { - if (Device.is_host()) + if (getSyclObjImpl(Device)->is_host()) return "HOST"; else if (Device.is_cpu()) return "CPU"; @@ -121,7 +121,7 @@ static void applyFuncOnFilteredArgs( #ifdef XPTI_ENABLE_INSTRUMENTATION static size_t deviceToID(const device &Device) { - if (Device.is_host()) + if (getSyclObjImpl(Device)->is_host()) return 0; else return reinterpret_cast(getSyclObjImpl(Device)->getHandleRef()); @@ -2544,7 +2544,7 @@ pi_int32 ExecCGCommand::enqueueImp() { return PI_SUCCESS; } case CG::CGTYPE::Barrier: { - if (MQueue->get_device().is_host()) { + if (MQueue->getDeviceImplPtr()->is_host()) { // NOP for host device. return PI_SUCCESS; } @@ -2558,7 +2558,7 @@ pi_int32 ExecCGCommand::enqueueImp() { CGBarrier *Barrier = static_cast(MCommandGroup.get()); std::vector Events = Barrier->MEventsWaitWithBarrier; std::vector PiEvents = getPiEvents(Events); - if (MQueue->get_device().is_host() || PiEvents.empty()) { + if (MQueue->getDeviceImplPtr()->is_host() || PiEvents.empty()) { // NOP for host device. // If Events is empty, then the barrier has no effect. return PI_SUCCESS; diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 52ee3769a7cf0..4b52529284cf3 100644 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -53,7 +53,9 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, void *RetVal = nullptr; if (Size == 0) return nullptr; - if (Ctxt.is_host()) { + + std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); + if (CtxImpl->is_host()) { if (!Alignment) { // worst case default Alignment = 128; @@ -67,7 +69,6 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, RetVal = nullptr; } } else { - std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); pi_context C = CtxImpl->getHandleRef(); const detail::plugin &Plugin = CtxImpl->getPlugin(); pi_result Error; @@ -121,7 +122,8 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, if (Size == 0) return nullptr; - if (Ctxt.is_host()) { + std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); + if (CtxImpl->is_host()) { if (Kind == alloc::unknown) { RetVal = nullptr; } else { @@ -139,7 +141,6 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, } } } else { - std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); pi_context C = CtxImpl->getHandleRef(); const detail::plugin &Plugin = CtxImpl->getPlugin(); pi_result Error; @@ -222,11 +223,12 @@ void free(void *Ptr, const context &Ctxt, XPTI_CREATE_TRACEPOINT(CodeLoc); if (Ptr == nullptr) return; - if (Ctxt.is_host()) { + + std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); + if (CtxImpl->is_host()) { // need to use alignedFree here for Windows detail::OSUtil::alignedFree(Ptr); } else { - std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); pi_context C = CtxImpl->getHandleRef(); const detail::plugin &Plugin = CtxImpl->getPlugin(); Plugin.call(C, Ptr); @@ -517,11 +519,12 @@ alloc get_pointer_type(const void *Ptr, const context &Ctxt) { if (!Ptr) return alloc::unknown; + std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); + // Everything on a host device is just system malloc so call it host - if (Ctxt.is_host()) + if (CtxImpl->is_host()) return alloc::host; - std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); pi_context PICtx = CtxImpl->getHandleRef(); pi_usm_type AllocTy; @@ -569,12 +572,12 @@ device get_pointer_device(const void *Ptr, const context &Ctxt) { throw runtime_error("Ptr not a valid USM allocation!", PI_ERROR_INVALID_VALUE); + std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); + // Just return the host device in the host context - if (Ctxt.is_host()) + if (CtxImpl->is_host()) return Ctxt.get_devices()[0]; - std::shared_ptr CtxImpl = detail::getSyclObjImpl(Ctxt); - // Check if ptr is a host allocation if (get_pointer_type(Ptr, Ctxt) == alloc::host) { auto Devs = CtxImpl->getDevices(); diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 19d5c15b6af67..31b2030acf061 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -52,19 +52,6 @@ std::vector device::get_devices(info::device_type deviceType) { std::vector devices; detail::device_filter_list *FilterList = detail::SYCLConfig::get(); - // Host device availability should depend on the forced type - bool includeHost = false; - // If SYCL_DEVICE_FILTER is set, we don't automatically include it. - // We will check if host devices are specified in the filter below. - if (FilterList) { - if (deviceType != info::device_type::host && - deviceType != info::device_type::all) - includeHost = false; - else - includeHost = FilterList->containsHost(); - } else { - includeHost = detail::match_types(deviceType, info::device_type::host); - } info::device_type forced_type = detail::get_forced_type(); // Exclude devices which do not match requested device type if (detail::match_types(deviceType, forced_type)) { @@ -74,24 +61,18 @@ std::vector device::get_devices(info::device_type deviceType) { // backend. backend *ForcedBackend = detail::SYCLConfig::get(); if (ForcedBackend) - if (!plt.is_host() && plt.get_backend() != *ForcedBackend) + if (!detail::getSyclObjImpl(plt)->is_host() && + plt.get_backend() != *ForcedBackend) continue; // If SYCL_DEVICE_FILTER is set, skip platforms that is incompatible // with the filter specification. if (FilterList && !FilterList->backendCompatible(plt.get_backend())) continue; - if (includeHost && plt.is_host()) { - std::vector host_device( - plt.get_devices(info::device_type::host)); - if (!host_device.empty()) - devices.insert(devices.end(), host_device.begin(), host_device.end()); - } else { - std::vector found_devices(plt.get_devices(deviceType)); - if (!found_devices.empty()) - devices.insert(devices.end(), found_devices.begin(), - found_devices.end()); - } + std::vector found_devices(plt.get_devices(deviceType)); + if (!found_devices.empty()) + devices.insert(devices.end(), found_devices.begin(), + found_devices.end()); } } return devices; @@ -99,7 +80,11 @@ std::vector device::get_devices(info::device_type deviceType) { cl_device_id device::get() const { return impl->get(); } -bool device::is_host() const { return impl->is_host(); } +bool device::is_host() const { + bool IsHost = impl->is_host(); + assert(!IsHost && "device::is_host should not be called in implementation."); + return IsHost; +} bool device::is_cpu() const { return impl->is_cpu(); } diff --git a/sycl/source/device_selector.cpp b/sycl/source/device_selector.cpp index 8cd70a29f0e82..10cede574e595 100644 --- a/sycl/source/device_selector.cpp +++ b/sycl/source/device_selector.cpp @@ -35,10 +35,6 @@ namespace detail { static int getDevicePreference(const device &Device) { int Score = 0; - // No preferences for host devices. - if (Device.is_host()) - return Score; - // Strongly prefer devices with available images. auto &program_manager = sycl::detail::ProgramManager::getInstance(); if (program_manager.hasCompatibleImage(Device)) @@ -154,9 +150,6 @@ __SYCL_EXPORT int default_selector_v(const device &dev) { if (dev.is_cpu()) Score += 300; - if (dev.is_host()) - Score += 100; - // Since we deprecate SYCL_BE and SYCL_DEVICE_TYPE, // we should not disallow accelerator to be chosen. // But this device type gets the lowest heuristic point. @@ -199,6 +192,12 @@ __SYCL_EXPORT int accelerator_selector_v(const device &dev) { return Score; } +int host_selector::operator()(const device &dev) const { + // Host device has been removed and host_selector has been deprecated, so this + // should never be able to select a device. + return detail::REJECT_DEVICE_SCORE; +} + // -------------- SYCL 1.2.1 // SYCL 1.2.1 device_selector class and sub-classes @@ -223,16 +222,6 @@ int accelerator_selector::operator()(const device &dev) const { return accelerator_selector_v(dev); } -int host_selector::operator()(const device &dev) const { - int Score = detail::REJECT_DEVICE_SCORE; - - if (dev.is_host()) { - Score = 1000; - Score += detail::getDevicePreference(dev); - } - return Score; -} - namespace ext { namespace oneapi { diff --git a/sycl/source/event.cpp b/sycl/source/event.cpp index ab453a13bc6ad..7950e70162d5e 100644 --- a/sycl/source/event.cpp +++ b/sycl/source/event.cpp @@ -37,7 +37,11 @@ bool event::operator==(const event &rhs) const { return rhs.impl == impl; } bool event::operator!=(const event &rhs) const { return !(*this == rhs); } -bool event::is_host() const { return impl->is_host(); } +bool event::is_host() const { + bool IsHost = impl->is_host(); + assert(!IsHost && "event::is_host should not be called in implementation."); + return IsHost; +} void event::wait() { impl->wait(impl); } diff --git a/sycl/source/kernel.cpp b/sycl/source/kernel.cpp index 60327fd596a04..484a66491b242 100644 --- a/sycl/source/kernel.cpp +++ b/sycl/source/kernel.cpp @@ -23,7 +23,11 @@ kernel::kernel(cl_kernel ClKernel, const context &SyclContext) cl_kernel kernel::get() const { return impl->get(); } -bool kernel::is_host() const { return impl->is_host(); } +bool kernel::is_host() const { + bool IsHost = impl->is_host(); + assert(!IsHost && "kernel::is_host should not be called in implementation."); + return IsHost; +} context kernel::get_context() const { return impl->get_info(); diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 2a51ac28fd9b8..2ffb48a5e6bdf 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -40,7 +40,12 @@ bool platform::has_extension(const std::string &ExtensionName) const { return impl->has_extension(ExtensionName); } -bool platform::is_host() const { return impl->is_host(); } +bool platform::is_host() const { + bool IsHost = impl->is_host(); + assert(!IsHost && + "platform::is_host should not be called in implementation."); + return IsHost; +} std::vector platform::get_devices(info::device_type DeviceType) const { return impl->get_devices(DeviceType); diff --git a/sycl/source/queue.cpp b/sycl/source/queue.cpp index c2cc11213ffb1..47cdc71c70f9c 100644 --- a/sycl/source/queue.cpp +++ b/sycl/source/queue.cpp @@ -74,7 +74,11 @@ context queue::get_context() const { return impl->get_context(); } device queue::get_device() const { return impl->get_device(); } -bool queue::is_host() const { return impl->is_host(); } +bool queue::is_host() const { + bool IsHost = impl->is_host(); + assert(!IsHost && "queue::is_host should not be called in implementation."); + return IsHost; +} void queue::throw_asynchronous() { impl->throw_asynchronous(); } diff --git a/sycl/test/regression/isordered.cpp b/sycl/test/regression/isordered.cpp deleted file mode 100644 index 0005b86a9b2f6..0000000000000 --- a/sycl/test/regression/isordered.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// RUN: %clangxx -fsycl %s -o %t.out -// RUN: env SYCL_DEVICE_FILTER=host %t.out - -#include - -int main() { - sycl::range<1> ndRng(3); - int32_t kernelResult[3]; - sycl::queue testQueue; - { - sycl::buffer buffer(&kernelResult[0], ndRng); - testQueue.submit([&](sycl::handler &h) { - auto resultPtr = buffer.template get_access(h); - h.single_task([=]() { - float inputData_0F(0.1); - float inputData_1F(0.5); - resultPtr[0] = sycl::isordered(inputData_0F, inputData_1F); - - double inputData_0D(0.2); - double inputData_1D(0.3); - resultPtr[1] = sycl::isordered(inputData_0D, inputData_1D); - - sycl::half inputData_0H(0.3); - sycl::half inputData_1H(0.9); - resultPtr[2] = sycl::isordered(inputData_0H, inputData_1H); - }); - }); - } - // Should be 1 according to spec since it's a scalar type not a vector - assert(kernelResult[0] == 1 && "Incorrect result"); - assert(kernelResult[1] == 1 && "Incorrect result"); - assert(kernelResult[2] == 1 && "Incorrect result"); - - return 0; -} diff --git a/sycl/test/regression/mad_sat.cpp b/sycl/test/regression/mad_sat.cpp deleted file mode 100644 index 28a0473ea4359..0000000000000 --- a/sycl/test/regression/mad_sat.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// RUN: %clangxx -fsycl %s -o %t.out -// RUN: env SYCL_DEVICE_FILTER=host %t.out - -#include - -int main() { - sycl::queue testQueue; - - { - const sycl::longlong3 verification3( - 9223372036854775807LL, 9223372036854775807LL, -9223372036854775808LL); - - sycl::longlong3 inputData_0(1152105081885725616LL, 8383539663869980295LL, - -3013159033463244495LL); - sycl::longlong3 inputData_1(9169239286331099647LL, 8545168655265359544LL, - 69290337040907021LL); - sycl::longlong3 inputData_2(-5670250901301018333LL, 216462155376518854LL, - -7910909987096217335LL); - - sycl::buffer buffer(1); - - testQueue.submit([&](sycl::handler &h) { - auto resultPtr = buffer.template get_access(h); - h.single_task([=]() { - resultPtr[0] = sycl::mad_sat(inputData_0, inputData_1, inputData_2); - }); - }); - const auto HostAccessor = buffer.get_access(); - for (int i = 0; i < 3; i++) - assert((HostAccessor[0][i] == verification3[i]) && "Incorrect result"); - } - { - const sycl::longlong4 verification4( - 9223372036854775807LL, 9223372036854775807LL, -9223372036854775808LL, - 9223372036854775807LL); - - sycl::longlong4 inputData_0(-4713774672458165250LL, 7161321293740295698LL, - -7560042360032818022LL, 1712118953348815386LL); - sycl::longlong4 inputData_1(-5256951628950351348LL, 3094294642897896981LL, - 4183324171724765944LL, 1726930751531248453LL); - sycl::longlong4 inputData_2(-614349234816759997LL, -7793620271163345724LL, - 5480991826433743823LL, -3977840325478979484LL); - - sycl::buffer buffer(1); - - testQueue.submit([&](sycl::handler &h) { - auto resultPtr = buffer.template get_access(h); - h.single_task([=]() { - resultPtr[0] = sycl::mad_sat(inputData_0, inputData_1, inputData_2); - }); - }); - const auto HostAccessor = buffer.get_access(); - for (int i = 0; i < 4; i++) - assert((HostAccessor[0][i] == verification4[i]) && "Incorrect result"); - } - { - const sycl::longlong8 verification8( - 9223372036854775807LL, 9223372036854775807LL, -9223372036854775808LL, - -9223372036854775808LL, 9223372036854775807LL, 9223372036854775807LL, - -9223372036854775808LL, -9223372036854775808LL); - - sycl::longlong8 inputData_0(3002837817109371705LL, -6132505093056073745LL, - -2677806413031023542LL, -3906932152445696896LL, - -5966911996430888011LL, 487233493241732294LL, - 8234534527416862935LL, 8302379558520488989LL); - sycl::longlong8 inputData_1(3895748400226584336LL, -3171989754828069475LL, - 6135091761884568657LL, 3449810579449494485LL, - -5153085649597103327LL, 2036067225828737775LL, - -2456339276147680058LL, -2321401317481120691LL); - sycl::longlong8 inputData_2(5847800471474896191LL, 6421268696360310080LL, - 426131359031594004LL, 3388848179800138438LL, - 9095634920776267157LL, 3909069092545608647LL, - -6551917618131929798LL, -5283018165188606431LL); - - sycl::buffer buffer(1); - - testQueue.submit([&](sycl::handler &h) { - auto resultPtr = buffer.template get_access(h); - h.single_task([=]() { - resultPtr[0] = sycl::mad_sat(inputData_0, inputData_1, inputData_2); - }); - }); - const auto HostAccessor = buffer.get_access(); - for (int i = 0; i < 8; i++) - assert((HostAccessor[0][i] == verification8[i]) && "Incorrect result"); - } - { - const sycl::longlong16 verification16( - -9223372036854775808LL, 9223372036854775807LL, 9223372036854775807LL, - -9223372036854775808LL, 9223372036854775807LL, 9223372036854775807LL, - 9223372036854775807LL, 9223372036854775807LL, 9223372036854775807LL, - 9223372036854775807LL, -9223372036854775808LL, 9223372036854775807LL, - -9223372036854775808LL, 9223372036854775807LL, -9223372036854775808LL, - -9223372036854775808LL); - - sycl::longlong16 inputData_0( - 4711072418277000515LL, -8205098172692021203LL, -7385016145788992368LL, - 5953521028589173909LL, -5219240995491769312LL, 8710496141913755416LL, - -6685846261491268433LL, 4193173269411595542LL, -8540195959022520771LL, - -4715465363106336895LL, -1020086937442724783LL, 4496316677230042947LL, - 1321442475247578017LL, -7374746170855359764LL, -3206370806055241163LL, - -2175226063524462053LL); - sycl::longlong16 inputData_1( - -9126728881985856159LL, -8235441378758843293LL, -3529617622861997052LL, - -4696495345590499183LL, -2446014787831249326LL, 3966377959819902357LL, - -8707315735766590681LL, 4940281453308003965LL, -4008494233289413829LL, - -1007875458987895243LL, 8007184939842565626LL, 7006363475270750393LL, - -3126435375497361798LL, -2666957213164527889LL, 3425215156535282625LL, - 5057359883753713949LL); - sycl::longlong16 inputData_2( - -5792361016316836568LL, 1155364222481085809LL, 7552404711758320408LL, - -9123476257323872288LL, -924920183965907175LL, 1921314238201973170LL, - 3462681782260196063LL, 7822120358287768333LL, -3130033938219713817LL, - -3165995450630991604LL, -7647706888277832178LL, -8427901934971949821LL, - 4207763935319579681LL, 1564279736903158695LL, 3722632463806041635LL, - 939009161285897285LL); - - sycl::buffer buffer(1); - - testQueue.submit([&](sycl::handler &h) { - auto resultPtr = buffer.template get_access(h); - - h.single_task([=]() { - resultPtr[0] = sycl::mad_sat(inputData_0, inputData_1, inputData_2); - }); - }); - const auto HostAccessor = buffer.get_access(); - for (int i = 0; i < 16; i++) - assert((HostAccessor[0][i] == verification16[i]) && "Incorrect result"); - } -} diff --git a/sycl/test/scheduler/DataMovement.cpp b/sycl/test/scheduler/DataMovement.cpp deleted file mode 100644 index 08d66980a5a7a..0000000000000 --- a/sycl/test/scheduler/DataMovement.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -I %sycl_source_dir %s -o %t.out -// RUN: env SYCL_DEVICE_FILTER=host %t.out -// -//==-------------------------- DataMovement.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 -// -//===----------------------------------------------------------------------===// - -// The test checks that no additional host allocation is performed by the SYCL -// RT if host ptr is used - -#include - -#include - -#include "../helpers.hpp" - -using sycl_access_mode = sycl::access::mode; - -template class CustomAllocator { -public: - using value_type = T; - using pointer = T*; - using const_pointer = const T*; - using reference = T&; - using const_reference = const T&; - -public: - template struct rebind { typedef CustomAllocator other; }; - - void construct(pointer Ptr, const_reference Val) { - new (Ptr) value_type(Val); - } - - void destroy(pointer Ptr) {} - - pointer address(reference Val) const { return &Val; } - const_pointer address(const_reference Val) { return &Val; } - - pointer allocate(size_t Size) { - throw std::runtime_error("Attempt to make host allocation for the buffer!"); - } - - // Release allocated memory - void deallocate(pointer Ptr, size_t size) { - throw std::runtime_error("Attempt to dealocate user's memory!"); - } - - bool operator==(const CustomAllocator &) { return true; } - bool operator!=(const CustomAllocator &rhs) { return false; } -}; - -int main() { - TestQueue Queue1(sycl::host_selector{}); - TestQueue Queue2(sycl::host_selector{}); - TestQueue Queue3(sycl::host_selector{}); - - std::vector Data(1); - - sycl::buffer> Buf( - Data.data(), Data.size(), {sycl::property::buffer::use_host_ptr()}); - - Queue1.submit([&](sycl::handler &CGH) { - auto BufAcc = Buf.get_access(CGH); - CGH.single_task([=]() { BufAcc[0] = 41; }); - }); - - Queue1.wait_and_throw(); - - { auto HostAcc = Buf.get_access(); } - - Queue2.submit([&](sycl::handler &CGH) { - auto BufAcc = Buf.get_access(CGH); - CGH.single_task([=]() { BufAcc[0] = 42; }); - }); - - Queue2.wait_and_throw(); - - { auto HostAcc = Buf.get_access(); } - - Queue3.submit([&](sycl::handler &CGH) { - auto BufAcc = Buf.get_access(CGH); - CGH.single_task([=]() { BufAcc[0] = 43; }); - }); - - Queue3.wait_and_throw(); - - { auto HostAcc = Buf.get_access(); } - - return 0; -} diff --git a/sycl/test/scheduler/MultipleDevices.cpp b/sycl/test/scheduler/MultipleDevices.cpp deleted file mode 100644 index 05984bde728d5..0000000000000 --- a/sycl/test/scheduler/MultipleDevices.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -I %sycl_source_dir %s -o %t.out -// RUN: env SYCL_DEVICE_FILTER=host %t.out - -//===- MultipleDevices.cpp - Test checking multi-device execution --------===// -// -// 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 - -#include - -using namespace sycl; - -int multidevice_test(queue MyQueue1, queue MyQueue2) { - const size_t N = 100; - - buffer BufA(range<1>{N}); - buffer BufB(range<1>{N}); - buffer BufC(range<1>{N}); - buffer BufD(range<1>{N}); - - MyQueue1.submit([&](handler &cgh) { - auto A = BufA.get_access(cgh); - cgh.parallel_for( - range<1>{N}, [=](id<1> index) { A[index[0]] = index[0]; }); - }); - - MyQueue2.submit([&](handler &cgh) { - auto B = BufB.get_access(cgh); - cgh.parallel_for( - range<1>{N}, [=](id<1> index) { B[index[0]] = N - index[0]; }); - }); - - MyQueue2.submit([&](handler& cgh) { - auto A = BufA.get_access(cgh); - auto B = BufB.get_access(cgh); - auto C = BufC.get_access(cgh); - cgh.parallel_for(range<1>{N}, [=](id<1> index) { - B[index[0]] = B[index[0]] + A[index[0]]; - C[index[0]] = B[index[0]] - index[0]; - }); - }); - - MyQueue2.submit([&](handler &cgh) { - auto D = BufD.get_access(cgh); - cgh.parallel_for(range<1>{N}, - [=](id<1> index) { D[index[0]] = 1; }); - }); - - MyQueue1.submit([&](handler& cgh) { - auto B = BufB.get_access(cgh); - auto C = BufC.get_access(cgh); - auto D = BufD.get_access(cgh); - cgh.parallel_for(range<1>{N}, [=](id<1> index) { - D[index[0]] = D[index[0]] + B[index[0]] - C[index[0]]; - }); - }); - - auto FinalD = BufD.get_access(); - std::cout << "Result:" << std::endl; - for (size_t i = 0; i < N; i++) { - - // A[index[0]] = index[0]; - int A = i; - // B[index[0]] = N - index[0]; - int B = N - i; - // B[index[0]] = B[index[0]] + A[index[0]]; - B = B + A; - // C[index[0]] = B[index[0]] - index[0]; - int C = B - i; - // D[index[0]] = 1; - int D = 1; - // D[index[0]] = D[index[0]] + B[index[0]] - C[index[0]]; - D = D + B - C; - - int Expected = D; - - if (FinalD[i] != D) { - std::cout << "Wrong value for element " << i - << " Expected: " << Expected << " Got: " << FinalD[i] - << std::endl; - return -1; - } - } - - std::cout << "Good computation!" << std::endl; - return 0; -} - -int main() { - host_selector hostSelector; - - int Result = -1; - try { - queue MyQueue1(hostSelector); - queue MyQueue2(hostSelector); - Result &= multidevice_test(MyQueue1, MyQueue2); - } catch (sycl::runtime_error &) { - std::cout << "Skipping host and host" << std::endl; - } - - return Result; -} diff --git a/sycl/test/warnings/sycl_2020_deprecations.cpp b/sycl/test/warnings/sycl_2020_deprecations.cpp index 7db05ee5e4667..e1f3d12177d60 100644 --- a/sycl/test/warnings/sycl_2020_deprecations.cpp +++ b/sycl/test/warnings/sycl_2020_deprecations.cpp @@ -202,7 +202,7 @@ int main() { sycl::gpu_selector gs; // expected-warning@+1{{'accelerator_selector' is deprecated: Use the callable sycl::accelerator_selector_v instead.}} sycl::accelerator_selector as; - // expected-warning@+1{{'host_selector' is deprecated: Use a callable function instead.}} + // expected-warning@+1{{'host_selector' is deprecated: Host device is no longer supported.}} sycl::host_selector hs; // expected-warning@+2{{'local' is deprecated: use `local_accessor` instead}} diff --git a/sycl/tools/sycl-ls/sycl-ls.cpp b/sycl/tools/sycl-ls/sycl-ls.cpp index 331d08a483098..d62aff79dc1f9 100644 --- a/sycl/tools/sycl-ls/sycl-ls.cpp +++ b/sycl/tools/sycl-ls/sycl-ls.cpp @@ -166,7 +166,6 @@ int main(int argc, char **argv) { // Print built-in device selectors choice printSelectorChoice(default_selector(), "default_selector() : "); - printSelectorChoice(host_selector(), "host_selector() : "); printSelectorChoice(accelerator_selector(), "accelerator_selector() : "); printSelectorChoice(cpu_selector(), "cpu_selector() : "); printSelectorChoice(gpu_selector(), "gpu_selector() : "); diff --git a/sycl/unittests/context/Context.cpp b/sycl/unittests/context/Context.cpp index b81483651c660..291cc872ab665 100644 --- a/sycl/unittests/context/Context.cpp +++ b/sycl/unittests/context/Context.cpp @@ -16,18 +16,15 @@ using namespace sycl; class ContextTest : public ::testing::Test { public: - ContextTest() {} - -protected: - void SetUp() override { - unittest::PiMock::EnsureMockPluginInitialized(); - - auto devices = device::get_devices(); - deviceA = devices[0]; - deviceB = devices[(devices.size() > 1 ? 1 : 0)]; - } + // NOTE: Devices must be initialized as part of the constructor to prevent + // default initialization, in case no devices are available before mock + // has been initialized. + ContextTest() + : mock{}, deviceA{mock.getPlatform().get_devices().front()}, + deviceB{mock.getPlatform().get_devices().back()} {} protected: + unittest::PiMock mock; device deviceA, deviceB; }; diff --git a/sycl/unittests/scheduler/AllocaLinking.cpp b/sycl/unittests/scheduler/AllocaLinking.cpp index d99fb05323aa8..c30f49dee53fd 100644 --- a/sycl/unittests/scheduler/AllocaLinking.cpp +++ b/sycl/unittests/scheduler/AllocaLinking.cpp @@ -45,12 +45,13 @@ TEST_F(SchedulerTest, AllocaLinking) { // This host device constructor should be placed before Mock.redefine // because it overrides the real implementation of get_device_info // which is needed when creating a host device. - device HostDevice{host_selector()}; + device HostDevice = detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl()); std::shared_ptr DefaultHostQueue{ new detail::queue_impl(detail::getSyclObjImpl(HostDevice), {}, {})}; sycl::unittest::PiMock Mock; - queue Q{Mock.getPlatform().get_devices()[0]}; + sycl::queue Q{Mock.getPlatform().get_devices()[0]}; Mock.redefine(redefinedDeviceGetInfo); Mock.redefine(redefinedMemBufferCreate); Mock.redefine(redefinedMemRelease); diff --git a/sycl/unittests/scheduler/BlockedCommands.cpp b/sycl/unittests/scheduler/BlockedCommands.cpp index 055e069a97384..e5ab988687493 100644 --- a/sycl/unittests/scheduler/BlockedCommands.cpp +++ b/sycl/unittests/scheduler/BlockedCommands.cpp @@ -9,11 +9,15 @@ #include "SchedulerTest.hpp" #include "SchedulerTestUtils.hpp" +#include + using namespace sycl; using namespace testing; TEST_F(SchedulerTest, BlockedCommands) { - MockCommand MockCmd(detail::getSyclObjImpl(MQueue)); + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + MockCommand MockCmd(detail::getSyclObjImpl(Q)); MockCmd.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; MockCmd.MIsBlockable = true; @@ -50,21 +54,24 @@ TEST_F(SchedulerTest, BlockedCommands) { } TEST_F(SchedulerTest, DontEnqueueDepsIfOneOfThemIsBlocked) { - MockCommand A(detail::getSyclObjImpl(MQueue)); + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + + MockCommand A(detail::getSyclObjImpl(Q)); A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; A.MIsBlockable = true; A.MRetVal = CL_SUCCESS; - MockCommand B(detail::getSyclObjImpl(MQueue)); + MockCommand B(detail::getSyclObjImpl(Q)); B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; B.MIsBlockable = true; B.MRetVal = CL_SUCCESS; - MockCommand C(detail::getSyclObjImpl(MQueue)); + MockCommand C(detail::getSyclObjImpl(Q)); C.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; C.MIsBlockable = true; - MockCommand D(detail::getSyclObjImpl(MQueue)); + MockCommand D(detail::getSyclObjImpl(Q)); D.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; D.MIsBlockable = true; D.MRetVal = CL_SUCCESS; @@ -97,11 +104,14 @@ TEST_F(SchedulerTest, DontEnqueueDepsIfOneOfThemIsBlocked) { } TEST_F(SchedulerTest, EnqueueBlockedCommandEarlyExit) { - MockCommand A(detail::getSyclObjImpl(MQueue)); + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + + MockCommand A(detail::getSyclObjImpl(Q)); A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; A.MIsBlockable = true; - MockCommand B(detail::getSyclObjImpl(MQueue)); + MockCommand B(detail::getSyclObjImpl(Q)); B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; B.MRetVal = CL_OUT_OF_RESOURCES; @@ -140,18 +150,21 @@ TEST_F(SchedulerTest, EnqueueBlockedCommandEarlyExit) { // This unit test is for workaround described in GraphProcessor::enqueueCommand // method. TEST_F(SchedulerTest, EnqueueHostDependency) { - MockCommand A(detail::getSyclObjImpl(MQueue)); + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + + MockCommand A(detail::getSyclObjImpl(Q)); A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; A.MIsBlockable = true; A.MRetVal = CL_SUCCESS; - MockCommand B(detail::getSyclObjImpl(MQueue)); + MockCommand B(detail::getSyclObjImpl(Q)); B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; B.MIsBlockable = true; B.MRetVal = CL_SUCCESS; sycl::detail::EventImplPtr DepEvent{ - new sycl::detail::event_impl(detail::getSyclObjImpl(MQueue))}; + new sycl::detail::event_impl(detail::getSyclObjImpl(Q))}; DepEvent->setCommand(&B); std::vector ToCleanUp; diff --git a/sycl/unittests/scheduler/CommandsWaitForEvents.cpp b/sycl/unittests/scheduler/CommandsWaitForEvents.cpp index a587af9e0e584..603b4e785aa9b 100644 --- a/sycl/unittests/scheduler/CommandsWaitForEvents.cpp +++ b/sycl/unittests/scheduler/CommandsWaitForEvents.cpp @@ -85,7 +85,8 @@ TEST_F(SchedulerTest, CommandsWaitForEvents) { std::shared_ptr E2( new detail::event_impl(TestContext->EventCtx2, Q2.get_context())); - sycl::device HostDevice{host_selector{}}; + device HostDevice = detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl()); std::shared_ptr DefaultHostQueue(new detail::queue_impl( detail::getSyclObjImpl(HostDevice), /*AsyncHandler=*/{}, /*PropList=*/{})); diff --git a/sycl/unittests/scheduler/FailedCommands.cpp b/sycl/unittests/scheduler/FailedCommands.cpp index e0256215663de..6e3014ce79179 100644 --- a/sycl/unittests/scheduler/FailedCommands.cpp +++ b/sycl/unittests/scheduler/FailedCommands.cpp @@ -9,12 +9,18 @@ #include "SchedulerTest.hpp" #include "SchedulerTestUtils.hpp" +#include + using namespace sycl; TEST_F(SchedulerTest, FailedDependency) { + unittest::PiMock Mock; + platform Plt = Mock.getPlatform(); + queue Queue(context(Plt), default_selector_v); + detail::Requirement MockReq = getMockRequirement(); - MockCommand MDep(detail::getSyclObjImpl(MQueue)); - MockCommand MUser(detail::getSyclObjImpl(MQueue)); + MockCommand MDep(detail::getSyclObjImpl(Queue)); + MockCommand MUser(detail::getSyclObjImpl(Queue)); MDep.addUser(&MUser); std::vector ToCleanUp; (void)MUser.addDep(detail::DepDesc{&MDep, &MockReq, nullptr}, ToCleanUp); diff --git a/sycl/unittests/scheduler/FinishedCmdCleanup.cpp b/sycl/unittests/scheduler/FinishedCmdCleanup.cpp index 908d0ed97fa9f..3120fd6075ec1 100644 --- a/sycl/unittests/scheduler/FinishedCmdCleanup.cpp +++ b/sycl/unittests/scheduler/FinishedCmdCleanup.cpp @@ -9,12 +9,17 @@ #include "SchedulerTest.hpp" #include "SchedulerTestUtils.hpp" +#include + #include #include using namespace sycl; TEST_F(SchedulerTest, FinishedCmdCleanup) { + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + MockScheduler MS; buffer BufA(range<1>(1)); buffer BufB(range<1>(1)); @@ -23,8 +28,8 @@ TEST_F(SchedulerTest, FinishedCmdCleanup) { detail::Requirement MockReqB = getMockRequirement(BufB); detail::Requirement MockReqC = getMockRequirement(BufC); std::vector AuxCmds; - detail::MemObjRecord *RecC = MS.getOrInsertMemObjRecord( - detail::getSyclObjImpl(MQueue), &MockReqC, AuxCmds); + detail::MemObjRecord *RecC = + MS.getOrInsertMemObjRecord(detail::getSyclObjImpl(Q), &MockReqC, AuxCmds); // Create a graph and check that all inner nodes have been deleted and // their users have had the corresponding dependency replaced with a @@ -51,32 +56,32 @@ TEST_F(SchedulerTest, FinishedCmdCleanup) { // +---------+ // | AllocaB | // +---------+ - detail::AllocaCommand AllocaA{detail::getSyclObjImpl(MQueue), MockReqA}; - detail::AllocaCommand AllocaB{detail::getSyclObjImpl(MQueue), MockReqB}; + detail::AllocaCommand AllocaA{detail::getSyclObjImpl(Q), MockReqA}; + detail::AllocaCommand AllocaB{detail::getSyclObjImpl(Q), MockReqB}; int NInnerCommandsAlive = 3; std::function Callback = [&]() { --NInnerCommandsAlive; }; - MockCommand *InnerC = new MockCommandWithCallback( - detail::getSyclObjImpl(MQueue), MockReqA, Callback); + MockCommand *InnerC = new MockCommandWithCallback(detail::getSyclObjImpl(Q), + MockReqA, Callback); addEdge(InnerC, &AllocaA, &AllocaA); std::vector ToEnqueue; - MockCommand LeafB{detail::getSyclObjImpl(MQueue), MockReqB}; + MockCommand LeafB{detail::getSyclObjImpl(Q), MockReqB}; addEdge(&LeafB, &AllocaB, &AllocaB); MS.addNodeToLeaves(RecC, &LeafB, access::mode::read, ToEnqueue); - MockCommand LeafA{detail::getSyclObjImpl(MQueue), MockReqA}; + MockCommand LeafA{detail::getSyclObjImpl(Q), MockReqA}; addEdge(&LeafA, InnerC, &AllocaA); MS.addNodeToLeaves(RecC, &LeafA, access::mode::read, ToEnqueue); - MockCommand *InnerB = new MockCommandWithCallback( - detail::getSyclObjImpl(MQueue), MockReqB, Callback); + MockCommand *InnerB = new MockCommandWithCallback(detail::getSyclObjImpl(Q), + MockReqB, Callback); addEdge(InnerB, &LeafB, &AllocaB); - MockCommand *InnerA = new MockCommandWithCallback( - detail::getSyclObjImpl(MQueue), MockReqA, Callback); + MockCommand *InnerA = new MockCommandWithCallback(detail::getSyclObjImpl(Q), + MockReqA, Callback); addEdge(InnerA, &LeafA, &AllocaA); addEdge(InnerA, InnerB, &AllocaB); diff --git a/sycl/unittests/scheduler/InOrderQueueDeps.cpp b/sycl/unittests/scheduler/InOrderQueueDeps.cpp index c0a09929bba4a..fb1c22c6e6575 100644 --- a/sycl/unittests/scheduler/InOrderQueueDeps.cpp +++ b/sycl/unittests/scheduler/InOrderQueueDeps.cpp @@ -96,7 +96,8 @@ TEST_F(SchedulerTest, InOrderQueueDeps) { sycl::detail::QueueImplPtr InOrderQueueImpl = detail::getSyclObjImpl(InOrderQueue); - device HostDevice{host_selector{}}; + device HostDevice = detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl()); std::shared_ptr DefaultHostQueue{ new detail::queue_impl(detail::getSyclObjImpl(HostDevice), {}, {})}; diff --git a/sycl/unittests/scheduler/LeafLimit.cpp b/sycl/unittests/scheduler/LeafLimit.cpp index bcc101072e4cb..94e35bcdebd6a 100644 --- a/sycl/unittests/scheduler/LeafLimit.cpp +++ b/sycl/unittests/scheduler/LeafLimit.cpp @@ -10,6 +10,7 @@ #include "SchedulerTestUtils.hpp" #include +#include #include #include @@ -26,12 +27,16 @@ inline constexpr auto DisablePostEnqueueCleanupName = // correctly with dependency tracking when leaf-limit for generic commands is // overflowed. TEST_F(SchedulerTest, LeafLimit) { + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + // All of the mock commands are owned on the test side, prevent post enqueue // cleanup from deleting some of them. unittest::ScopedEnvVar DisabledCleanup{ DisablePostEnqueueCleanupName, "1", detail::SYCLConfig::reset}; - sycl::queue HQueue(host_selector{}); + sycl::queue HQueue(detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl())); MockScheduler MS; std::vector> LeavesToAdd; std::unique_ptr MockDepCmd; @@ -40,16 +45,16 @@ TEST_F(SchedulerTest, LeafLimit) { detail::Requirement MockReq = getMockRequirement(Buf); MockDepCmd = - std::make_unique(detail::getSyclObjImpl(MQueue), MockReq); + std::make_unique(detail::getSyclObjImpl(Q), MockReq); std::vector AuxCmds; - detail::MemObjRecord *Rec = MS.getOrInsertMemObjRecord( - detail::getSyclObjImpl(MQueue), &MockReq, AuxCmds); + detail::MemObjRecord *Rec = + MS.getOrInsertMemObjRecord(detail::getSyclObjImpl(Q), &MockReq, AuxCmds); // Create commands that will be added as leaves exceeding the limit by 1 for (std::size_t i = 0; i < Rec->MWriteLeaves.genericCommandsCapacity() + 1; ++i) { LeavesToAdd.push_back( - std::make_unique(detail::getSyclObjImpl(MQueue), MockReq)); + std::make_unique(detail::getSyclObjImpl(Q), MockReq)); } // Create edges: all soon-to-be leaves are direct users of MockDep std::vector ToCleanUp; diff --git a/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp b/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp index eeae5d184c740..9700fa5fd6da4 100644 --- a/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp +++ b/sycl/unittests/scheduler/LeafLimitDiffContexts.cpp @@ -10,6 +10,7 @@ #include "SchedulerTestUtils.hpp" #include +#include #include #include @@ -35,14 +36,10 @@ TEST_F(SchedulerTest, LeafLimitDiffContexts) { DisablePostEnqueueCleanupName, "1", detail::SYCLConfig::reset}; - default_selector Selector; - device Device = Selector.select_device(); - // ConnectCmd will not be created for host contextx - if (Device.is_host()) { - std::cout << "Not run due to host-only environment\n"; - return; - } + // Ensure the mock plugin has been initialized prior to selecting a device. + unittest::PiMock::EnsureMockPluginInitialized(); + device Device; struct QueueRelatedObjects { context Context; queue Queue; diff --git a/sycl/unittests/scheduler/LeavesCollection.cpp b/sycl/unittests/scheduler/LeavesCollection.cpp index f2683cb1875e2..ea883041add66 100644 --- a/sycl/unittests/scheduler/LeavesCollection.cpp +++ b/sycl/unittests/scheduler/LeavesCollection.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -28,7 +29,6 @@ class LeavesCollectionTest : public ::testing::Test { } } }; - sycl::queue MQueue = sycl::queue(sycl::host_selector{}, MAsyncHandler); }; std::shared_ptr @@ -46,6 +46,9 @@ createEmptyCommand(const std::shared_ptr &Q, } TEST_F(LeavesCollectionTest, PushBack) { + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + static constexpr size_t GenericCmdsCapacity = 8; size_t TimesGenericWasFull; @@ -65,7 +68,7 @@ TEST_F(LeavesCollectionTest, PushBack) { TimesGenericWasFull = 0; for (size_t Idx = 0; Idx < GenericCmdsCapacity * 2; ++Idx) { - Cmds.push_back(createGenericCommand(getSyclObjImpl(MQueue))); + Cmds.push_back(createGenericCommand(getSyclObjImpl(Q))); LE.push_back(Cmds.back().get(), ToEnqueue); } @@ -93,8 +96,8 @@ TEST_F(LeavesCollectionTest, PushBack) { TimesGenericWasFull = 0; for (size_t Idx = 0; Idx < GenericCmdsCapacity * 4; ++Idx) { - auto Cmd = Idx % 2 ? createGenericCommand(getSyclObjImpl(MQueue)) - : createEmptyCommand(getSyclObjImpl(MQueue), MockReq); + auto Cmd = Idx % 2 ? createGenericCommand(getSyclObjImpl(Q)) + : createEmptyCommand(getSyclObjImpl(Q), MockReq); Cmds.push_back(Cmd); LE.push_back(Cmds.back().get(), ToEnqueue); @@ -112,6 +115,9 @@ TEST_F(LeavesCollectionTest, PushBack) { } TEST_F(LeavesCollectionTest, Remove) { + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + static constexpr size_t GenericCmdsCapacity = 8; std::vector ToEnqueue; @@ -130,8 +136,8 @@ TEST_F(LeavesCollectionTest, Remove) { std::vector> Cmds; for (size_t Idx = 0; Idx < GenericCmdsCapacity * 4; ++Idx) { - auto Cmd = Idx % 2 ? createGenericCommand(getSyclObjImpl(MQueue)) - : createEmptyCommand(getSyclObjImpl(MQueue), MockReq); + auto Cmd = Idx % 2 ? createGenericCommand(getSyclObjImpl(Q)) + : createEmptyCommand(getSyclObjImpl(Q), MockReq); Cmds.push_back(Cmd); if (LE.push_back(Cmds.back().get(), ToEnqueue)) diff --git a/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp b/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp index 3e0dcbc8ee4fc..b9a4726acb7fd 100644 --- a/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp +++ b/sycl/unittests/scheduler/LinkedAllocaDependencies.cpp @@ -59,7 +59,8 @@ TEST_F(SchedulerTest, LinkedAllocaDependencies) { sycl::queue Queue1{Dev}; sycl::detail::QueueImplPtr Q1 = sycl::detail::getSyclObjImpl(Queue1); - sycl::device HostDevice{host_selector{}}; + device HostDevice = detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl()); std::shared_ptr DefaultHostQueue(new detail::queue_impl( detail::getSyclObjImpl(HostDevice), /*AsyncHandler=*/{}, /*PropList=*/{})); diff --git a/sycl/unittests/scheduler/MemObjCommandCleanup.cpp b/sycl/unittests/scheduler/MemObjCommandCleanup.cpp index 9b5d196cde339..aeeb815b2db3a 100644 --- a/sycl/unittests/scheduler/MemObjCommandCleanup.cpp +++ b/sycl/unittests/scheduler/MemObjCommandCleanup.cpp @@ -9,30 +9,35 @@ #include "SchedulerTest.hpp" #include "SchedulerTestUtils.hpp" +#include + #include using namespace sycl; TEST_F(SchedulerTest, MemObjCommandCleanupAllocaUsers) { + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + MockScheduler MS; buffer BufA(range<1>(1)); buffer BufB(range<1>(1)); detail::Requirement MockReqA = getMockRequirement(BufA); detail::Requirement MockReqB = getMockRequirement(BufB); std::vector AuxCmds; - detail::MemObjRecord *RecA = MS.getOrInsertMemObjRecord( - detail::getSyclObjImpl(MQueue), &MockReqA, AuxCmds); + detail::MemObjRecord *RecA = + MS.getOrInsertMemObjRecord(detail::getSyclObjImpl(Q), &MockReqA, AuxCmds); // Create 2 fake allocas, one of which will be cleaned up detail::AllocaCommand *MockAllocaA = - new detail::AllocaCommand(detail::getSyclObjImpl(MQueue), MockReqA); + new detail::AllocaCommand(detail::getSyclObjImpl(Q), MockReqA); std::unique_ptr MockAllocaB{ - new detail::AllocaCommand(detail::getSyclObjImpl(MQueue), MockReqB)}; + new detail::AllocaCommand(detail::getSyclObjImpl(Q), MockReqB)}; RecA->MAllocaCommands.push_back(MockAllocaA); // Create a direct user of both allocas std::unique_ptr MockDirectUser{ - new MockCommand(detail::getSyclObjImpl(MQueue), MockReqA)}; + new MockCommand(detail::getSyclObjImpl(Q), MockReqA)}; addEdge(MockDirectUser.get(), MockAllocaA, MockAllocaA); addEdge(MockDirectUser.get(), MockAllocaB.get(), MockAllocaB.get()); @@ -40,7 +45,7 @@ TEST_F(SchedulerTest, MemObjCommandCleanupAllocaUsers) { bool IndirectUserDeleted = false; std::function Callback = [&]() { IndirectUserDeleted = true; }; MockCommand *MockIndirectUser = new MockCommandWithCallback( - detail::getSyclObjImpl(MQueue), MockReqA, Callback); + detail::getSyclObjImpl(Q), MockReqA, Callback); addEdge(MockIndirectUser, MockDirectUser.get(), MockAllocaA); MS.cleanupCommandsForRecord(RecA); @@ -55,20 +60,23 @@ TEST_F(SchedulerTest, MemObjCommandCleanupAllocaUsers) { } TEST_F(SchedulerTest, MemObjCommandCleanupAllocaDeps) { + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + MockScheduler MS; buffer Buf(range<1>(1)); detail::Requirement MockReq = getMockRequirement(Buf); std::vector AuxCmds; - detail::MemObjRecord *MemObjRec = MS.getOrInsertMemObjRecord( - detail::getSyclObjImpl(MQueue), &MockReq, AuxCmds); + detail::MemObjRecord *MemObjRec = + MS.getOrInsertMemObjRecord(detail::getSyclObjImpl(Q), &MockReq, AuxCmds); // Create a fake alloca. detail::AllocaCommand *MockAllocaCmd = - new detail::AllocaCommand(detail::getSyclObjImpl(MQueue), MockReq); + new detail::AllocaCommand(detail::getSyclObjImpl(Q), MockReq); MemObjRec->MAllocaCommands.push_back(MockAllocaCmd); // Add another mock command and add MockAllocaCmd as its user. - MockCommand DepCmd(detail::getSyclObjImpl(MQueue), MockReq); + MockCommand DepCmd(detail::getSyclObjImpl(Q), MockReq); addEdge(MockAllocaCmd, &DepCmd, nullptr); // Check that DepCmd.MUsers size reflect the dependency properly. diff --git a/sycl/unittests/scheduler/NoHostUnifiedMemory.cpp b/sycl/unittests/scheduler/NoHostUnifiedMemory.cpp index 7fed47a280068..49ac8db448de5 100644 --- a/sycl/unittests/scheduler/NoHostUnifiedMemory.cpp +++ b/sycl/unittests/scheduler/NoHostUnifiedMemory.cpp @@ -103,7 +103,8 @@ TEST_F(SchedulerTest, NoHostUnifiedMemory) { redefinedMemCreateWithNativeHandle); sycl::detail::QueueImplPtr QImpl = detail::getSyclObjImpl(Q); - device HostDevice{host_selector{}}; + device HostDevice = detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl()); std::shared_ptr DefaultHostQueue{ new detail::queue_impl(detail::getSyclObjImpl(HostDevice), {}, {})}; diff --git a/sycl/unittests/scheduler/PostEnqueueCleanup.cpp b/sycl/unittests/scheduler/PostEnqueueCleanup.cpp index 5ea859246f0da..73b52c0214345 100644 --- a/sycl/unittests/scheduler/PostEnqueueCleanup.cpp +++ b/sycl/unittests/scheduler/PostEnqueueCleanup.cpp @@ -243,7 +243,8 @@ TEST_F(SchedulerTest, PostEnqueueCleanup) { MS.addEmptyCmd(Leaf, {&MockReq}, QueueImpl, detail::Command::BlockReason::HostTask, ToEnqueue); }); - device HostDevice{host_selector{}}; + device HostDevice = detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl()); detail::QueueImplPtr DefaultHostQueue{ new detail::queue_impl(detail::getSyclObjImpl(HostDevice), {}, {})}; checkCleanupOnLeafUpdate( diff --git a/sycl/unittests/scheduler/QueueFlushing.cpp b/sycl/unittests/scheduler/QueueFlushing.cpp index 23a01c2c02391..a6916e5dc2f5c 100644 --- a/sycl/unittests/scheduler/QueueFlushing.cpp +++ b/sycl/unittests/scheduler/QueueFlushing.cpp @@ -164,7 +164,8 @@ TEST_F(SchedulerTest, QueueFlushing) { QueueImplA}; testCommandEnqueue(&UnmapCmd, QueueImplB, MockReq); - device HostDevice{host_selector{}}; + device HostDevice = detail::createSyclObjFromImpl( + detail::device_impl::getHostDeviceImpl()); detail::QueueImplPtr DefaultHostQueue{ new detail::queue_impl(detail::getSyclObjImpl(HostDevice), {}, {})}; detail::AllocaCommand HostAllocaCmd = diff --git a/sycl/unittests/scheduler/RunOnHostIntelCG.cpp b/sycl/unittests/scheduler/RunOnHostIntelCG.cpp index dba148a1a24c0..1eaaf63969559 100644 --- a/sycl/unittests/scheduler/RunOnHostIntelCG.cpp +++ b/sycl/unittests/scheduler/RunOnHostIntelCG.cpp @@ -10,6 +10,8 @@ #include "SchedulerTest.hpp" #include "SchedulerTestUtils.hpp" +#include + #include using namespace sycl; @@ -32,8 +34,11 @@ class MockCGExecKernel : public detail::CGExecKernel { // Check that the command group associated with run_on_host_intel is properly // released on command destruction. TEST_F(SchedulerTest, RunOnHostIntelCG) { + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + MockScheduler MS; - detail::QueueImplPtr QueueImpl = detail::getSyclObjImpl(MQueue); + detail::QueueImplPtr QueueImpl = detail::getSyclObjImpl(Q); detail::NDRDescT NDRDesc; NDRDesc.set(range<1>{1}, id<1>{0}); diff --git a/sycl/unittests/scheduler/SchedulerTest.hpp b/sycl/unittests/scheduler/SchedulerTest.hpp index a2fc84697a202..a453368592a40 100644 --- a/sycl/unittests/scheduler/SchedulerTest.hpp +++ b/sycl/unittests/scheduler/SchedulerTest.hpp @@ -25,5 +25,4 @@ class SchedulerTest : public ::testing::Test { } } }; - sycl::queue MQueue = sycl::queue(sycl::host_selector{}, MAsyncHandler); }; diff --git a/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp b/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp index 85d764b4b283a..6828d605ef87e 100644 --- a/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp +++ b/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp @@ -80,8 +80,9 @@ TEST_F(SchedulerTest, StreamInitDependencyOnHost) { unittest::ScopedEnvVar DisabledCleanup{ DisablePostEnqueueCleanupName, "1", detail::SYCLConfig::reset}; - sycl::queue HQueue(host_selector{}); - detail::QueueImplPtr HQueueImpl = detail::getSyclObjImpl(HQueue); + std::shared_ptr HQueueImpl(new detail::queue_impl( + detail::device_impl::getHostDeviceImpl(), /*AsyncHandler=*/{}, + /*PropList=*/{})); // Emulating processing of command group function MockHandlerStreamInit MockCGH(HQueueImpl, true); diff --git a/sycl/unittests/scheduler/WaitAfterCleanup.cpp b/sycl/unittests/scheduler/WaitAfterCleanup.cpp index 751086fc96eec..c1c2192b4424f 100644 --- a/sycl/unittests/scheduler/WaitAfterCleanup.cpp +++ b/sycl/unittests/scheduler/WaitAfterCleanup.cpp @@ -8,12 +8,16 @@ #include "SchedulerTest.hpp" #include "SchedulerTestUtils.hpp" +#include #include using namespace sycl; TEST_F(SchedulerTest, PostEnqueueCleanupForCommandDefault) { - auto Cmd = new MockCommand(detail::getSyclObjImpl(MQueue)); + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + + auto Cmd = new MockCommand(detail::getSyclObjImpl(Q)); auto Event = Cmd->getEvent(); ASSERT_FALSE(Event == nullptr) << "Command must have an event\n"; @@ -26,7 +30,10 @@ TEST_F(SchedulerTest, WaitAfterCleanup) { "SYCL_DISABLE_POST_ENQUEUE_CLEANUP", "1", detail::SYCLConfig::reset}; - auto Cmd = new MockCommand(detail::getSyclObjImpl(MQueue)); + sycl::unittest::PiMock Mock; + sycl::queue Q{Mock.getPlatform().get_devices()[0], MAsyncHandler}; + + auto Cmd = new MockCommand(detail::getSyclObjImpl(Q)); auto Event = Cmd->getEvent(); ASSERT_FALSE(Event == nullptr) << "Command must have an event\n";