Add alignment check to CL_DEVICE_MEM_BASE_ADDR_ALIGN for compressed buffers

Change-Id: I44fa231411a754fb24398a4a9727ca16f257220e
Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
Kamil Diedrich 2019-04-02 09:42:03 +02:00 committed by sys_ocldev
parent e9a35fbf88
commit cefa3e3119
3 changed files with 22 additions and 4 deletions

View File

@ -98,6 +98,11 @@ inline bool isAligned(T *ptr) {
return ((reinterpret_cast<uintptr_t>(ptr)) % alignment) == 0;
}
template <typename T1, typename T2>
inline bool isAligned(T1 ptr, T2 alignment) {
return ((static_cast<size_t>(ptr)) & (static_cast<size_t>(alignment) - 1u)) == 0;
}
template <typename T>
inline bool isAligned(T *ptr) {
return (reinterpret_cast<uintptr_t>(ptr) & (alignof(T) - 1)) == 0;

View File

@ -61,12 +61,17 @@ bool Buffer::isSubBuffer() {
}
bool Buffer::isValidSubBufferOffset(size_t offset) {
for (size_t i = 0; i < context->getNumDevices(); ++i) {
cl_uint address_align = 32; // 4 byte alignment
if ((offset & (address_align / 8 - 1)) == 0) {
return true;
if (this->getGraphicsAllocation()->getAllocationType() == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED) {
// From spec: "origin value is aligned to the CL_DEVICE_MEM_BASE_ADDR_ALIGN value"
if (!isAligned(offset, this->getContext()->getDevice(0)->getDeviceInfo().memBaseAddressAlign)) {
return false;
}
}
cl_uint address_align = 32; // 4 byte alignment
if ((offset & (address_align / 8 - 1)) == 0) {
return true;
}
return false;
}

View File

@ -85,6 +85,14 @@ TEST_F(SubBufferTest, GivenAlignmentThatIsHigherThen4BytesWhenCheckedForValidity
EXPECT_TRUE(buffer->isValidSubBufferOffset(region2.origin));
cl_buffer_region region3 = {8, 4};
EXPECT_TRUE(buffer->isValidSubBufferOffset(region3.origin));
buffer->getGraphicsAllocation()->setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
EXPECT_FALSE(buffer->isValidSubBufferOffset(region.origin));
EXPECT_FALSE(buffer->isValidSubBufferOffset(region2.origin));
cl_buffer_region region4 = {1025, 4};
EXPECT_FALSE(buffer->isValidSubBufferOffset(region4.origin));
cl_buffer_region region5 = {1024, 4};
EXPECT_TRUE(buffer->isValidSubBufferOffset(region5.origin));
}
TEST_F(SubBufferTest, givenSharingHandlerFromParentBufferWhenCreateThenShareHandler) {