@@ -30,13 +30,11 @@ static pi_result redefinedDeviceGetInfo(pi_device Device,
30
30
return PI_SUCCESS;
31
31
}
32
32
33
- static RT::PiMemFlags ExpectedMemObjFlags;
34
-
35
33
static pi_result
36
34
redefinedMemBufferCreate (pi_context context, pi_mem_flags flags, size_t size,
37
35
void *host_ptr, pi_mem *ret_mem,
38
36
const pi_mem_properties *properties = nullptr ) {
39
- EXPECT_EQ (flags, ExpectedMemObjFlags );
37
+ EXPECT_EQ (flags, PI_MEM_FLAGS_ACCESS_RW );
40
38
return PI_SUCCESS;
41
39
}
42
40
@@ -85,59 +83,70 @@ TEST_F(SchedulerTest, NoHostUnifiedMemory) {
85
83
new detail::queue_impl (detail::getSyclObjImpl (HostDevice), {}, {})};
86
84
87
85
MockScheduler MS;
88
- // Check non-host -> host alloca with non-discard access mode
86
+ // Check non-host alloca with non-discard access mode
89
87
{
90
88
int val;
91
89
buffer<int , 1 > Buf (&val, range<1 >(1 ));
92
90
detail::Requirement Req = getMockRequirement (Buf);
93
91
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
-
98
92
detail::MemObjRecord *Record = MS.getOrInsertMemObjRecord (QImpl, &Req);
99
93
detail::AllocaCommandBase *NonHostAllocaCmd =
100
94
MS.getOrCreateAllocaForReq (Record, &Req, QImpl);
101
95
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 ());
104
101
EXPECT_TRUE (!HostAllocaCmd->MLinkedAllocaCmd );
105
102
EXPECT_TRUE (!NonHostAllocaCmd->MLinkedAllocaCmd );
103
+ EXPECT_TRUE (Record->MCurContext ->is_host ());
106
104
107
- detail::Command *MemoryMove =
108
- MS.insertMemoryMove (Record, &Req, DefaultHostQueue);
105
+ detail::Command *MemoryMove = MS.insertMemoryMove (Record, &Req, QImpl);
109
106
EXPECT_EQ (MemoryMove->getType (), detail::Command::COPY_MEMORY);
110
107
}
111
- // Check non-host -> host alloca with discard access modes
108
+ // Check non-host alloca with discard access modes
112
109
{
113
110
int val;
114
111
buffer<int , 1 > Buf (&val, range<1 >(1 ));
115
112
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;
118
113
119
114
detail::Requirement DiscardReq = getMockRequirement (Buf);
120
115
DiscardReq.MAccessMode = access::mode::discard_read_write;
121
116
117
+ // No need to create a host allocation in this case since the data can be
118
+ // discarded.
122
119
detail::MemObjRecord *Record = MS.getOrInsertMemObjRecord (QImpl, &Req);
123
120
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 );
124
133
}
125
134
// Check host -> non-host alloca
126
135
{
127
136
int val;
128
137
buffer<int , 1 > Buf (&val, range<1 >(1 ));
129
138
detail::Requirement Req = getMockRequirement (Buf);
130
139
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.
135
142
detail::MemObjRecord *Record =
136
143
MS.getOrInsertMemObjRecord (DefaultHostQueue, &Req);
137
144
detail::AllocaCommandBase *HostAllocaCmd =
138
145
MS.getOrCreateAllocaForReq (Record, &Req, DefaultHostQueue);
146
+ EXPECT_EQ (Record->MAllocaCommands .size (), 1U );
139
147
detail::AllocaCommandBase *NonHostAllocaCmd =
140
148
MS.getOrCreateAllocaForReq (Record, &Req, QImpl);
149
+ EXPECT_EQ (Record->MAllocaCommands .size (), 2U );
141
150
EXPECT_TRUE (!HostAllocaCmd->MLinkedAllocaCmd );
142
151
EXPECT_TRUE (!NonHostAllocaCmd->MLinkedAllocaCmd );
143
152
@@ -150,7 +159,6 @@ TEST_F(SchedulerTest, NoHostUnifiedMemory) {
150
159
int val;
151
160
buffer<int , 1 > Buf (&val, range<1 >(1 ));
152
161
detail::Requirement Req = getMockRequirement (Buf);
153
- ExpectedMemObjFlags = PI_MEM_FLAGS_ACCESS_RW | PI_MEM_FLAGS_HOST_PTR_COPY;
154
162
155
163
detail::Requirement DiscardReq = getMockRequirement (Buf);
156
164
DiscardReq.MAccessMode = access::mode::discard_read_write;
0 commit comments