diff --git a/sycl/include/sycl/accessor.hpp b/sycl/include/sycl/accessor.hpp index c060625d3329a..cbeed3a3eb76d 100644 --- a/sycl/include/sycl/accessor.hpp +++ b/sycl/include/sycl/accessor.hpp @@ -1182,6 +1182,15 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor : return reinterpret_cast(AccessorBaseHost::getPtr()); } +public: + accessor() + : AccessorBaseHost( + /*Offset=*/{0, 0, 0}, /*AccessRange=*/{0, 0, 0}, + /*MemoryRange=*/{0, 0, 0}, + /*AccessMode=*/getAdjustedMode({}), + /*SYCLMemObject=*/nullptr, /*Dims=*/0, /*ElemSize=*/0, + /*OffsetInBytes=*/0, /*IsSubBuffer=*/false, /*PropertyList=*/{}){}; + #endif // __SYCL_DEVICE_ONLY__ private: @@ -1937,7 +1946,7 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor : size_t byte_size() const noexcept { return size() * sizeof(DataT); } size_t max_size() const noexcept { - return (std::numeric_limits::max)(); + return empty() ? 0 : (std::numeric_limits::max)(); } bool empty() const noexcept { return size() == 0; } diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 8f5f18a090aa8..d6f39b2b9c167 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2001,6 +2001,8 @@ static pi_result SetKernelParamsAndLaunch( break; case kernel_param_kind_t::kind_accessor: { Requirement *Req = (Requirement *)(Arg.MPtr); + if (Req->MAccessRange == range<3>({0, 0, 0})) + break; if (getMemAllocationFunc == nullptr) throw sycl::exception(make_error_code(errc::kernel_argument), "placeholder accessor must be bound by calling " diff --git a/sycl/test/basic_tests/accessor/accessor_default_ctor.cpp b/sycl/test/basic_tests/accessor/accessor_default_ctor.cpp new file mode 100644 index 0000000000000..a60a4aafcb909 --- /dev/null +++ b/sycl/test/basic_tests/accessor/accessor_default_ctor.cpp @@ -0,0 +1,19 @@ +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out + +#include + +int main() { + sycl::accessor + B; + assert(B.empty()); + assert(B.size() == 0); + assert(B.max_size() == 0); + assert(B.byte_size() == 0); + // The return values of get_pointer() and get_multi_ptr() are unspecified. + assert(B.get_pointer() == nullptr); + // TODO: uncomment check with get_multi_ptr() when SYCL 2020 mupti_ptr feature + // will be merged + // assert(B.get_multi_ptr() == nullptr); + + return 0; +} \ No newline at end of file diff --git a/sycl/unittests/scheduler/AccessorDefaultCtor.cpp b/sycl/unittests/scheduler/AccessorDefaultCtor.cpp new file mode 100644 index 0000000000000..473ddcefe75fa --- /dev/null +++ b/sycl/unittests/scheduler/AccessorDefaultCtor.cpp @@ -0,0 +1,42 @@ +#include "SchedulerTest.hpp" +#include "SchedulerTestUtils.hpp" +#include + +#include +#include +#include + +#include + +using namespace sycl; + +TEST_F(SchedulerTest, AccDefaultCtorDoesntAffectDepGraph) { + unittest::PiMock Mock; + platform Plt = Mock.getPlatform(); + + queue QueueDev(context(Plt), default_selector_v); + MockScheduler MS; + + detail::QueueImplPtr QueueDevImpl = detail::getSyclObjImpl(QueueDev); + + std::vector ToEnqueue; + + MockHandlerCustomFinalize MockCGH(QueueDevImpl, false); + + sycl::accessor + B; + + MockCGH.single_task([=]() { + int size = B.size(); + (void)size; + }); + + std::unique_ptr CmdGroup = MockCGH.finalize(); + + detail::Command *NewCmd = + MS.addCG(std::move(CmdGroup), QueueDevImpl, ToEnqueue); + + // if MDeps is empty, accessor built from default ctor does not affect + // dependency graph in accordance with SYCL 2020 + EXPECT_TRUE(NewCmd->MDeps.empty()); +} diff --git a/sycl/unittests/scheduler/CMakeLists.txt b/sycl/unittests/scheduler/CMakeLists.txt index 8211d8ab0ef04..1353b6ca63d24 100644 --- a/sycl/unittests/scheduler/CMakeLists.txt +++ b/sycl/unittests/scheduler/CMakeLists.txt @@ -23,4 +23,5 @@ add_sycl_unittest(SchedulerTests OBJECT InOrderQueueSyncCheck.cpp RunOnHostIntelCG.cpp EnqueueWithDependsOnDeps.cpp + AccessorDefaultCtor.cpp ) diff --git a/sycl/unittests/scheduler/EnqueueWithDependsOnDeps.cpp b/sycl/unittests/scheduler/EnqueueWithDependsOnDeps.cpp index 95c598781cf73..29db4edc8c759 100644 --- a/sycl/unittests/scheduler/EnqueueWithDependsOnDeps.cpp +++ b/sycl/unittests/scheduler/EnqueueWithDependsOnDeps.cpp @@ -8,7 +8,6 @@ #include "SchedulerTest.hpp" #include "SchedulerTestUtils.hpp" -#include #include #include @@ -19,48 +18,13 @@ using namespace sycl; using EventImplPtr = std::shared_ptr; -namespace DependsOnTest { -class MockHandlerCustom : public MockHandler { -public: - MockHandlerCustom(std::shared_ptr Queue, - bool IsHost) - : MockHandler(Queue, IsHost) {} - - std::unique_ptr finalize() { - std::unique_ptr CommandGroup; - switch (getType()) { - case sycl::detail::CG::Kernel: { - CommandGroup.reset(new sycl::detail::CGExecKernel( - getNDRDesc(), std::move(getHostKernel()), getKernel(), - std::move(MImpl->MKernelBundle), getArgsStorage(), getAccStorage(), - getSharedPtrStorage(), getRequirements(), getEvents(), getArgs(), - getKernelName(), getOSModuleHandle(), getStreamStorage(), - MImpl->MAuxiliaryResources, getCGType(), getCodeLoc())); - break; - } - case sycl::detail::CG::CodeplayHostTask: { - CommandGroup.reset(new detail::CGHostTask( - std::move(getHostTask()), getQueue(), getQueue()->getContextImplPtr(), - getArgs(), getArgsStorage(), getAccStorage(), getSharedPtrStorage(), - getRequirements(), getEvents(), getCGType(), getCodeLoc())); - break; - } - default: - throw sycl::runtime_error("Unhandled type of command group", - PI_ERROR_INVALID_OPERATION); - } - - return CommandGroup; - } -}; -} // namespace DependsOnTest detail::Command *AddTaskCG(bool IsHost, MockScheduler &MS, detail::QueueImplPtr DevQueue, const std::vector &Events) { std::vector ToEnqueue; // Emulating processing of command group function - DependsOnTest::MockHandlerCustom MockCGH(DevQueue, false); + MockHandlerCustomFinalize MockCGH(DevQueue, false); for (auto EventImpl : Events) MockCGH.depends_on(detail::createSyclObjFromImpl(EventImpl)); diff --git a/sycl/unittests/scheduler/SchedulerTestUtils.hpp b/sycl/unittests/scheduler/SchedulerTestUtils.hpp index 02511f92eca69..02226e30fa938 100644 --- a/sycl/unittests/scheduler/SchedulerTestUtils.hpp +++ b/sycl/unittests/scheduler/SchedulerTestUtils.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -270,4 +271,38 @@ class MockHandler : public sycl::handler { return nullptr; } -}; \ No newline at end of file +}; + +class MockHandlerCustomFinalize : public MockHandler { +public: + MockHandlerCustomFinalize(std::shared_ptr Queue, + bool IsHost) + : MockHandler(Queue, IsHost) {} + + std::unique_ptr finalize() { + std::unique_ptr CommandGroup; + switch (getType()) { + case sycl::detail::CG::Kernel: { + CommandGroup.reset(new sycl::detail::CGExecKernel( + getNDRDesc(), std::move(getHostKernel()), getKernel(), + std::move(MImpl->MKernelBundle), getArgsStorage(), getAccStorage(), + getSharedPtrStorage(), getRequirements(), getEvents(), getArgs(), + getKernelName(), getOSModuleHandle(), getStreamStorage(), + MImpl->MAuxiliaryResources, getCGType(), getCodeLoc())); + break; + } + case sycl::detail::CG::CodeplayHostTask: { + CommandGroup.reset(new sycl::detail::CGHostTask( + std::move(getHostTask()), getQueue(), getQueue()->getContextImplPtr(), + getArgs(), getArgsStorage(), getAccStorage(), getSharedPtrStorage(), + getRequirements(), getEvents(), getCGType(), getCodeLoc())); + break; + } + default: + throw sycl::runtime_error("Unhandled type of command group", + PI_ERROR_INVALID_OPERATION); + } + + return CommandGroup; + } +};