Skip to content

Commit b2c1d68

Browse files
Revert "Revert "Revert "Fix Read/WriteBuffer for unaligned offsets"""
This reverts commit f6757c0. Change-Id: I239528e7588dc9766b10a7ce7e517d6b2cdd6375 Signed-off-by: Artur Harasimiuk <[email protected]>
1 parent 154917a commit b2c1d68

File tree

6 files changed

+9
-150
lines changed

6 files changed

+9
-150
lines changed

runtime/built_ins/built_ins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ class BuiltInOp<HWFamily, EBuiltInOps::CopyBufferToBuffer> : public BuiltinDispa
243243
} else if (operationParams.srcMemObj) {
244244
kernelSplit1DBuilder.setArg(0, operationParams.srcMemObj);
245245
} else {
246-
kernelSplit1DBuilder.setArgSvm(0, operationParams.size.x + operationParams.srcOffset.x, operationParams.srcPtr, nullptr, CL_MEM_READ_ONLY);
246+
kernelSplit1DBuilder.setArgSvm(0, operationParams.size.x, operationParams.srcPtr, nullptr, CL_MEM_READ_ONLY);
247247
}
248248
if (operationParams.dstSvmAlloc) {
249249
kernelSplit1DBuilder.setArgSvmAlloc(1, operationParams.dstPtr, operationParams.dstSvmAlloc);
250250
} else if (operationParams.dstMemObj) {
251251
kernelSplit1DBuilder.setArg(1, operationParams.dstMemObj);
252252
} else {
253-
kernelSplit1DBuilder.setArgSvm(1, operationParams.size.x + operationParams.dstOffset.x, operationParams.dstPtr);
253+
kernelSplit1DBuilder.setArgSvm(1, operationParams.size.x, operationParams.dstPtr);
254254
}
255255

256256
// Set-up srcOffset

runtime/command_queue/enqueue_read_buffer.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,21 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
8888
BuiltInOwnershipWrapper builtInLock(builder, this->context);
8989

9090
void *dstPtr = ptr;
91-
void *alignedDstPtr = dstPtr;
92-
size_t dstPtrOffset = 0;
93-
94-
if (!isAligned<4>(dstPtr)) {
95-
alignedDstPtr = alignDown(dstPtr, 4);
96-
dstPtrOffset = ptrDiff(dstPtr, alignedDstPtr);
97-
}
9891

9992
MemObjSurface bufferSurf(buffer);
100-
HostPtrSurface hostPtrSurf(alignedDstPtr, size + dstPtrOffset);
93+
HostPtrSurface hostPtrSurf(dstPtr, size);
10194
Surface *surfaces[] = {&bufferSurf, &hostPtrSurf};
10295

10396
if (size != 0) {
10497
bool status = getCommandStreamReceiver().createAllocationForHostSurface(hostPtrSurf, getDevice(), true);
10598
if (!status) {
10699
return CL_OUT_OF_RESOURCES;
107100
}
108-
109-
hostPtrSurf.getAllocation()->allocationOffset = dstPtrOffset;
101+
dstPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
110102
}
111103

112104
BuiltinDispatchInfoBuilder::BuiltinOpParams dc;
113-
dc.dstPtr = alignedDstPtr;
114-
dc.dstOffset = {dstPtrOffset, 0, 0};
105+
dc.dstPtr = dstPtr;
115106
dc.srcMemObj = buffer;
116107
dc.srcOffset = {offset, 0, 0};
117108
dc.size = {size, 0, 0};

runtime/command_queue/enqueue_write_buffer.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,8 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
8989
BuiltInOwnershipWrapper builtInLock(builder, this->context);
9090

9191
void *srcPtr = const_cast<void *>(ptr);
92-
void *alignedSrcPtr = srcPtr;
93-
size_t srcPtrOffset = 0;
9492

95-
if (!isAligned<4>(srcPtr)) {
96-
alignedSrcPtr = alignDown(srcPtr, 4);
97-
srcPtrOffset = ptrDiff(srcPtr, alignedSrcPtr);
98-
}
99-
100-
HostPtrSurface hostPtrSurf(alignedSrcPtr, size + srcPtrOffset, true);
93+
HostPtrSurface hostPtrSurf(srcPtr, size, true);
10194
MemObjSurface bufferSurf(buffer);
10295
Surface *surfaces[] = {&bufferSurf, &hostPtrSurf};
10396

@@ -106,13 +99,11 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
10699
if (!status) {
107100
return CL_OUT_OF_RESOURCES;
108101
}
109-
110-
hostPtrSurf.getAllocation()->allocationOffset = srcPtrOffset;
102+
srcPtr = reinterpret_cast<void *>(hostPtrSurf.getAllocation()->getGpuAddressToPatch());
111103
}
112104

113105
BuiltinDispatchInfoBuilder::BuiltinOpParams dc;
114-
dc.srcPtr = alignedSrcPtr;
115-
dc.srcOffset = {srcPtrOffset, 0, 0};
106+
dc.srcPtr = srcPtr;
116107
dc.dstMemObj = buffer;
117108
dc.dstOffset = {offset, 0, 0};
118109
dc.size = {size, 0, 0};

runtime/command_stream/aub_command_stream_receiver_hw.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ void AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(uint64_t gpuAddress, voi
623623

624624
template <typename GfxFamily>
625625
bool AUBCommandStreamReceiverHw<GfxFamily>::writeMemory(GraphicsAllocation &gfxAllocation) {
626-
auto cpuAddress = ptrOffset(gfxAllocation.getUnderlyingBuffer(), static_cast<size_t>(gfxAllocation.allocationOffset));
626+
auto cpuAddress = gfxAllocation.getUnderlyingBuffer();
627627
auto gpuAddress = GmmHelper::decanonize(gfxAllocation.getGpuAddress());
628628
auto size = gfxAllocation.getUnderlyingBufferSize();
629629
if (gfxAllocation.gmm && gfxAllocation.gmm->isRenderCompressed) {

unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -143,66 +143,3 @@ HWTEST_F(AUBReadBuffer, reserveCanonicalGpuAddress) {
143143

144144
AUBCommandStreamFixture::expectMemory<FamilyType>(dstGpuAddress, srcMemory, sizeof(dstMemory));
145145
}
146-
147-
struct AUBReadBufferUnaligned
148-
: public CommandEnqueueAUBFixture,
149-
public ::testing::Test {
150-
151-
void SetUp() override {
152-
CommandEnqueueAUBFixture::SetUp();
153-
}
154-
155-
void TearDown() override {
156-
CommandEnqueueAUBFixture::TearDown();
157-
}
158-
159-
template <typename FamilyType>
160-
void testReadBufferUnaligned(size_t offset, size_t size) {
161-
MockContext context(&pCmdQ->getDevice());
162-
163-
char srcMemory[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
164-
const auto bufferSize = sizeof(srcMemory);
165-
char dstMemory[bufferSize] = {0};
166-
167-
auto retVal = CL_INVALID_VALUE;
168-
169-
auto buffer = std::unique_ptr<Buffer>(Buffer::create(
170-
&context,
171-
CL_MEM_USE_HOST_PTR,
172-
bufferSize,
173-
srcMemory,
174-
retVal));
175-
ASSERT_NE(nullptr, buffer);
176-
177-
buffer->forceDisallowCPUCopy = true;
178-
179-
// Map destination memory to GPU
180-
GraphicsAllocation *allocation = createResidentAllocationAndStoreItInCsr(dstMemory, bufferSize);
181-
auto dstMemoryGPUPtr = reinterpret_cast<char *>(allocation->getGpuAddress());
182-
183-
// Do unaligned read
184-
retVal = pCmdQ->enqueueReadBuffer(
185-
buffer.get(),
186-
CL_TRUE,
187-
offset,
188-
size,
189-
ptrOffset(dstMemory, offset),
190-
0,
191-
nullptr,
192-
nullptr);
193-
EXPECT_EQ(CL_SUCCESS, retVal);
194-
195-
// Check the memory
196-
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(dstMemoryGPUPtr, offset), ptrOffset(srcMemory, offset), size);
197-
}
198-
};
199-
200-
HWTEST_F(AUBReadBufferUnaligned, all) {
201-
const std::vector<size_t> offsets = {0, 1, 2, 3};
202-
const std::vector<size_t> sizes = {4, 3, 2, 1};
203-
for (auto offset : offsets) {
204-
for (auto size : sizes) {
205-
testReadBufferUnaligned<FamilyType>(offset, size);
206-
}
207-
}
208-
}

unit_tests/aub_tests/command_queue/enqueue_write_buffer_aub_tests.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -108,63 +108,3 @@ INSTANTIATE_TEST_CASE_P(AUBWriteBuffer_simple,
108108
1 * sizeof(cl_float),
109109
2 * sizeof(cl_float),
110110
3 * sizeof(cl_float)));
111-
112-
struct AUBWriteBufferUnaligned
113-
: public CommandEnqueueAUBFixture,
114-
public ::testing::Test {
115-
116-
void SetUp() override {
117-
CommandEnqueueAUBFixture::SetUp();
118-
}
119-
120-
void TearDown() override {
121-
CommandEnqueueAUBFixture::TearDown();
122-
}
123-
124-
template <typename FamilyType>
125-
void testWriteBufferUnaligned(size_t offset, size_t size) {
126-
MockContext context(&pCmdQ->getDevice());
127-
128-
char srcMemory[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
129-
const auto bufferSize = sizeof(srcMemory);
130-
char dstMemory[bufferSize] = {0};
131-
132-
auto retVal = CL_INVALID_VALUE;
133-
134-
auto buffer = std::unique_ptr<Buffer>(Buffer::create(
135-
&context,
136-
CL_MEM_USE_HOST_PTR,
137-
bufferSize,
138-
dstMemory,
139-
retVal));
140-
ASSERT_NE(nullptr, buffer);
141-
142-
buffer->forceDisallowCPUCopy = true;
143-
144-
// Do unaligned write
145-
retVal = pCmdQ->enqueueWriteBuffer(
146-
buffer.get(),
147-
CL_TRUE,
148-
offset,
149-
size,
150-
ptrOffset(srcMemory, offset),
151-
0,
152-
nullptr,
153-
nullptr);
154-
EXPECT_EQ(CL_SUCCESS, retVal);
155-
156-
// Check the memory
157-
auto bufferGPUPtr = reinterpret_cast<char *>((buffer->getGraphicsAllocation()->getGpuAddress()));
158-
AUBCommandStreamFixture::expectMemory<FamilyType>(ptrOffset(bufferGPUPtr, offset), ptrOffset(srcMemory, offset), size);
159-
}
160-
};
161-
162-
HWTEST_F(AUBWriteBufferUnaligned, all) {
163-
const std::vector<size_t> offsets = {0, 1, 2, 3};
164-
const std::vector<size_t> sizes = {4, 3, 2, 1};
165-
for (auto offset : offsets) {
166-
for (auto size : sizes) {
167-
testWriteBufferUnaligned<FamilyType>(offset, size);
168-
}
169-
}
170-
}

0 commit comments

Comments
 (0)