Respect 3 dimensions when calculating size for host surface

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2021-06-16 14:41:26 +00:00
committed by Compute-Runtime-Automation
parent 5e85fe5042
commit 6c7ccddae0
6 changed files with 64 additions and 5 deletions

View File

@ -16,6 +16,7 @@
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
#include "opencl/test/unit_test/mocks/mock_csr.h"
#include "opencl/test/unit_test/mocks/mock_kernel.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "opencl/test/unit_test/mocks/mock_os_context.h"
#include "opencl/test/unit_test/mocks/mock_timestamp_container.h"
#include "test.h"
@ -1070,7 +1071,8 @@ HWTEST_P(BcsDetaliedTestsWithParams, givenBltSizeWithLeftoverWhenDispatchedThenP
size_t srcRowPitch = std::get<0>(GetParam()).srcRowPitch;
size_t srcSlicePitch = std::get<0>(GetParam()).srcSlicePitch;
auto allocation = buffer->getGraphicsAllocation(pDevice->getRootDeviceIndex());
auto memoryManager = static_cast<MockMemoryManager *>(pDevice->getMemoryManager());
memoryManager->returnFakeAllocation = true;
auto blitProperties = BlitProperties::constructPropertiesForReadWrite(std::get<1>(GetParam()), //blitDirection
csr, allocation, //commandStreamReceiver
nullptr, //memObjAllocation
@ -1085,6 +1087,8 @@ HWTEST_P(BcsDetaliedTestsWithParams, givenBltSizeWithLeftoverWhenDispatchedThenP
srcRowPitch, //gpuRowPitch
srcSlicePitch //gpuSlicePitch
);
memoryManager->returnFakeAllocation = false;
blitBuffer(&csr, blitProperties, true);
HardwareParse hwParser;
@ -1169,6 +1173,8 @@ HWTEST_P(BcsDetaliedTestsWithParams, givenBltSizeWithLeftoverWhenDispatchedThenP
size_t srcSlicePitch = std::get<0>(GetParam()).srcSlicePitch;
auto allocation = buffer->getGraphicsAllocation(pDevice->getRootDeviceIndex());
auto memoryManager = static_cast<MockMemoryManager *>(pDevice->getMemoryManager());
memoryManager->returnFakeAllocation = true;
auto blitProperties = BlitProperties::constructPropertiesForReadWrite(std::get<1>(GetParam()), //blitDirection
csr, allocation, //commandStreamReceiver
nullptr, //memObjAllocation
@ -1183,6 +1189,8 @@ HWTEST_P(BcsDetaliedTestsWithParams, givenBltSizeWithLeftoverWhenDispatchedThenP
srcRowPitch, //gpuRowPitch
srcSlicePitch //gpuSlicePitch
);
memoryManager->returnFakeAllocation = false;
blitBuffer(&csr, blitProperties, true);
HardwareParse hwParser;

View File

@ -1113,6 +1113,8 @@ HWTEST_F(BcsTests, givenBufferWithBigSizesWhenBlitOperationCalledThenProgramCorr
EXPECT_TRUE(BlitCommandsHelper<FamilyType>::isCopyRegionPreferred(region, rootDeviceEnvironment));
auto memoryManager = static_cast<MockMemoryManager *>(pDevice->getMemoryManager());
memoryManager->returnFakeAllocation = true;
// from hostPtr
HardwareParse hwParser;
auto offset = csr.commandStream.getUsed();
@ -1123,6 +1125,7 @@ HWTEST_F(BcsTests, givenBufferWithBigSizesWhenBlitOperationCalledThenProgramCorr
0, srcOrigin, dstOrigin, region,
srcRowPitch, srcSlicePitch, dstRowPitch, dstSlicePitch);
memoryManager->returnFakeAllocation = false;
blitBuffer(&csr, blitProperties, true);
hwParser.parseCommands<FamilyType>(csr.commandStream, offset);

View File

@ -52,6 +52,9 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(cons
}
GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) {
if (returnFakeAllocation) {
return new GraphicsAllocation(properties.rootDeviceIndex, properties.allocationType, reinterpret_cast<void *>(dummyAddress), reinterpret_cast<uint64_t>(ptr), properties.size, 0, MemoryPool::System4KBPages, maxOsContextCount);
}
if (isMockHostMemoryManager) {
allocateGraphicsMemoryWithPropertiesCount++;
if (forceFailureInAllocationWithHostPointer) {

View File

@ -170,6 +170,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
bool isMockHostMemoryManager = false;
bool isMockEventPoolCreateMemoryManager = false;
bool limitedGPU = false;
bool returnFakeAllocation = false;
std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment;
DeviceBitfield recentlyPassedDeviceBitfield{};
std::unique_ptr<MultiGraphicsAllocation> waitAllocations = nullptr;

View File

@ -28,20 +28,20 @@ BlitProperties BlitProperties::constructPropertiesForReadWrite(BlitterConstants:
GraphicsAllocation *hostAllocation = nullptr;
auto clearColorAllocation = commandStreamReceiver.getClearColorAllocation();
copySize.y = copySize.y ? copySize.y : 1;
copySize.z = copySize.z ? copySize.z : 1;
if (preallocatedHostAllocation) {
hostAllocation = preallocatedHostAllocation;
UNRECOVERABLE_IF(hostAllocGpuVa == 0);
} else {
HostPtrSurface hostPtrSurface(hostPtr, static_cast<size_t>(copySize.x), true);
HostPtrSurface hostPtrSurface(hostPtr, static_cast<size_t>(copySize.x * copySize.y * copySize.z), true);
bool success = commandStreamReceiver.createAllocationForHostSurface(hostPtrSurface, false);
UNRECOVERABLE_IF(!success);
hostAllocation = hostPtrSurface.getAllocation();
hostAllocGpuVa = hostAllocation->getGpuAddress();
}
copySize.y = copySize.y ? copySize.y : 1;
copySize.z = copySize.z ? copySize.z : 1;
if (BlitterConstants::BlitDirection::HostPtrToBuffer == blitDirection ||
BlitterConstants::BlitDirection::HostPtrToImage == blitDirection) {
return {

View File

@ -8,16 +8,60 @@
#include "shared/test/common/helpers/blit_commands_helper_tests.inl"
#include "shared/source/command_container/command_encoder.h"
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/helpers/blit_commands_helper.h"
#include "shared/test/common/cmd_parse/hw_parse.h"
#include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(BlitCommandsHelperTest, GivenBufferParamsWhenConstructingPropertiesForReadWriteThenPropertiesCreatedCorrectly) {
uint32_t src[] = {1, 2, 3, 4};
uint32_t dst[] = {4, 3, 2, 1};
uint64_t srcGpuAddr = 0x12345;
std::unique_ptr<MockGraphicsAllocation> srcAlloc(new MockGraphicsAllocation(src, srcGpuAddr, sizeof(src)));
Vec3<size_t> srcOffsets{1, 2, 3};
Vec3<size_t> dstOffsets{3, 2, 1};
Vec3<size_t> copySize{2, 2, 2};
size_t srcRowPitch = 2;
size_t srcSlicePitch = 3;
size_t dstRowPitch = 2;
size_t dstSlicePitch = 3;
UltDeviceFactory deviceFactory{1, 0};
auto csr = deviceFactory.rootDevices[0]->getDefaultEngine().commandStreamReceiver;
auto blitProperties = NEO::BlitProperties::constructPropertiesForReadWrite(BlitterConstants::BlitDirection::BufferToHostPtr,
*csr, srcAlloc.get(), nullptr,
dst,
srcGpuAddr,
0, dstOffsets, srcOffsets, copySize, dstRowPitch, dstSlicePitch, srcRowPitch, srcSlicePitch);
EXPECT_EQ(blitProperties.blitDirection, BlitterConstants::BlitDirection::BufferToHostPtr);
EXPECT_NE(blitProperties.dstAllocation, nullptr);
EXPECT_EQ(blitProperties.dstAllocation->getUnderlyingBufferSize(), copySize.x * copySize.y * copySize.z);
EXPECT_EQ(blitProperties.srcAllocation, srcAlloc.get());
EXPECT_EQ(blitProperties.clearColorAllocation, csr->getClearColorAllocation());
EXPECT_EQ(blitProperties.dstGpuAddress, blitProperties.dstAllocation->getGpuAddress());
EXPECT_EQ(blitProperties.srcGpuAddress, srcGpuAddr);
EXPECT_EQ(blitProperties.copySize, copySize);
EXPECT_EQ(blitProperties.dstOffset, dstOffsets);
EXPECT_EQ(blitProperties.srcOffset, srcOffsets);
EXPECT_EQ(blitProperties.dstRowPitch, dstRowPitch);
EXPECT_EQ(blitProperties.dstSlicePitch, dstSlicePitch);
EXPECT_EQ(blitProperties.srcRowPitch, srcRowPitch);
EXPECT_EQ(blitProperties.srcSlicePitch, srcSlicePitch);
}
TEST(BlitCommandsHelperTest, GivenBufferParamsWhenConstructingPropertiesForBufferRegionsThenPropertiesCreatedCorrectly) {
uint32_t src[] = {1, 2, 3, 4};
uint32_t dst[] = {4, 3, 2, 1};