@@ -30,13 +30,11 @@ static pi_result redefinedDeviceGetInfo(pi_device Device,
3030 return PI_SUCCESS;
3131}
3232
33- static RT::PiMemFlags ExpectedMemObjFlags;
34-
3533static pi_result
3634redefinedMemBufferCreate (pi_context context, pi_mem_flags flags, size_t size,
3735 void *host_ptr, pi_mem *ret_mem,
3836 const pi_mem_properties *properties = nullptr ) {
39- EXPECT_EQ (flags, ExpectedMemObjFlags );
37+ EXPECT_EQ (flags, PI_MEM_FLAGS_ACCESS_RW );
4038 return PI_SUCCESS;
4139}
4240
@@ -85,59 +83,70 @@ TEST_F(SchedulerTest, NoHostUnifiedMemory) {
8583 new detail::queue_impl (detail::getSyclObjImpl (HostDevice), {}, {})};
8684
8785 MockScheduler MS;
88- // Check non-host -> host alloca with non-discard access mode
86+ // Check non-host alloca with non-discard access mode
8987 {
9088 int val;
9189 buffer<int , 1 > Buf (&val, range<1 >(1 ));
9290 detail::Requirement Req = getMockRequirement (Buf);
9391
94- // The host pointer should be copied during the non-host allocation in this
95- // case.
96- ExpectedMemObjFlags = PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_COPY;
97-
9892 detail::MemObjRecord *Record = MS.getOrInsertMemObjRecord (QImpl, &Req);
9993 detail::AllocaCommandBase *NonHostAllocaCmd =
10094 MS.getOrCreateAllocaForReq (Record, &Req, QImpl);
10195
102- detail::AllocaCommandBase *HostAllocaCmd =
103- MS.getOrCreateAllocaForReq (Record, &Req, DefaultHostQueue);
96+ // Both non-host and host allocations should be created in this case in
97+ // order to perform a memory move.
98+ EXPECT_EQ (Record->MAllocaCommands .size (), 2U );
99+ detail::AllocaCommandBase *HostAllocaCmd = Record->MAllocaCommands [0 ];
100+ EXPECT_TRUE (HostAllocaCmd->getQueue ()->is_host ());
104101 EXPECT_TRUE (!HostAllocaCmd->MLinkedAllocaCmd );
105102 EXPECT_TRUE (!NonHostAllocaCmd->MLinkedAllocaCmd );
103+ EXPECT_TRUE (Record->MCurContext ->is_host ());
106104
107- detail::Command *MemoryMove =
108- MS.insertMemoryMove (Record, &Req, DefaultHostQueue);
105+ detail::Command *MemoryMove = MS.insertMemoryMove (Record, &Req, QImpl);
109106 EXPECT_EQ (MemoryMove->getType (), detail::Command::COPY_MEMORY);
110107 }
111- // Check non-host -> host alloca with discard access modes
108+ // Check non-host alloca with discard access modes
112109 {
113110 int val;
114111 buffer<int , 1 > Buf (&val, range<1 >(1 ));
115112 detail::Requirement Req = getMockRequirement (Buf);
116- // The host pointer should be ignored due to the discard access mode.
117- ExpectedMemObjFlags = PI_MEM_FLAGS_ACCESS_RW;
118113
119114 detail::Requirement DiscardReq = getMockRequirement (Buf);
120115 DiscardReq.MAccessMode = access::mode::discard_read_write;
121116
117+ // No need to create a host allocation in this case since the data can be
118+ // discarded.
122119 detail::MemObjRecord *Record = MS.getOrInsertMemObjRecord (QImpl, &Req);
123120 MS.getOrCreateAllocaForReq (Record, &DiscardReq, QImpl);
121+ EXPECT_EQ (Record->MAllocaCommands .size (), 1U );
122+ }
123+ // Check non-host alloca without user pointer
124+ {
125+ buffer<int , 1 > Buf (range<1 >(1 ));
126+ detail::Requirement Req = getMockRequirement (Buf);
127+
128+ // No need to create a host allocation in this case since there's no data to
129+ // initialize the buffer with.
130+ detail::MemObjRecord *Record = MS.getOrInsertMemObjRecord (QImpl, &Req);
131+ MS.getOrCreateAllocaForReq (Record, &Req, QImpl);
132+ EXPECT_EQ (Record->MAllocaCommands .size (), 1U );
124133 }
125134 // Check host -> non-host alloca
126135 {
127136 int val;
128137 buffer<int , 1 > Buf (&val, range<1 >(1 ));
129138 detail::Requirement Req = getMockRequirement (Buf);
130139
131- // No copy expected during the second allocation, it is performed as a
132- // separate command.
133- ExpectedMemObjFlags = PI_MEM_FLAGS_ACCESS_RW;
134-
140+ // No special handling required: alloca commands are created one after
141+ // another and the transfer is done via a write operation.
135142 detail::MemObjRecord *Record =
136143 MS.getOrInsertMemObjRecord (DefaultHostQueue, &Req);
137144 detail::AllocaCommandBase *HostAllocaCmd =
138145 MS.getOrCreateAllocaForReq (Record, &Req, DefaultHostQueue);
146+ EXPECT_EQ (Record->MAllocaCommands .size (), 1U );
139147 detail::AllocaCommandBase *NonHostAllocaCmd =
140148 MS.getOrCreateAllocaForReq (Record, &Req, QImpl);
149+ EXPECT_EQ (Record->MAllocaCommands .size (), 2U );
141150 EXPECT_TRUE (!HostAllocaCmd->MLinkedAllocaCmd );
142151 EXPECT_TRUE (!NonHostAllocaCmd->MLinkedAllocaCmd );
143152
@@ -150,7 +159,6 @@ TEST_F(SchedulerTest, NoHostUnifiedMemory) {
150159 int val;
151160 buffer<int , 1 > Buf (&val, range<1 >(1 ));
152161 detail::Requirement Req = getMockRequirement (Buf);
153- ExpectedMemObjFlags = PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_COPY;
154162
155163 detail::Requirement DiscardReq = getMockRequirement (Buf);
156164 DiscardReq.MAccessMode = access::mode::discard_read_write;
0 commit comments