mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-30 01:35:20 +08:00
fix: don't use staging for map allocations
Related-To: NEO-13572 Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
8d4721d613
commit
2815d4167d
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2024 Intel Corporation
|
||||
* Copyright (C) 2018-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -2965,7 +2965,7 @@ cl_int CL_API_CALL clEnqueueWriteImage(cl_command_queue commandQueue,
|
||||
TRACING_EXIT(ClEnqueueWriteImage, &retVal);
|
||||
return retVal;
|
||||
}
|
||||
if (pCommandQueue->isValidForStagingTransferImage(pImage, ptr, numEventsInWaitList > 0)) {
|
||||
if (pCommandQueue->isValidForStagingTransfer(pImage, ptr, numEventsInWaitList > 0)) {
|
||||
retVal = pCommandQueue->enqueueStagingWriteImage(pImage, blockingWrite, origin, region, inputRowPitch, inputSlicePitch, ptr, event);
|
||||
} else {
|
||||
retVal = pCommandQueue->enqueueWriteImage(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2024 Intel Corporation
|
||||
* Copyright (C) 2018-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -405,7 +405,7 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
|
||||
size_t inputRowPitch, size_t inputSlicePitch, const void *ptr, cl_event *event);
|
||||
|
||||
bool isValidForStagingBufferCopy(Device &device, void *dstPtr, const void *srcPtr, size_t size, bool hasDependencies);
|
||||
bool isValidForStagingTransferImage(Image *image, const void *ptr, bool hasDependencies);
|
||||
bool isValidForStagingTransfer(MemObj *memObj, const void *ptr, bool hasDependencies);
|
||||
|
||||
protected:
|
||||
void *enqueueReadMemObjForMap(TransferProperties &transferProperties, EventsRequest &eventsRequest, cl_int &errcodeRet);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
* Copyright (C) 2024-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -152,15 +152,21 @@ bool CommandQueue::isValidForStagingBufferCopy(Device &device, void *dstPtr, con
|
||||
return stagingBufferManager->isValidForCopy(device, dstPtr, srcPtr, size, hasDependencies, osContextId);
|
||||
}
|
||||
|
||||
bool CommandQueue::isValidForStagingTransferImage(Image *image, const void *ptr, bool hasDependencies) {
|
||||
bool CommandQueue::isValidForStagingTransfer(MemObj *memObj, const void *ptr, bool hasDependencies) {
|
||||
GraphicsAllocation *allocation = nullptr;
|
||||
context->tryGetExistingMapAllocation(ptr, memObj->getSize(), allocation);
|
||||
if (allocation != nullptr) {
|
||||
// Direct transfer from mapped allocation is faster than staging buffer
|
||||
return false;
|
||||
}
|
||||
auto stagingBufferManager = context->getStagingBufferManager();
|
||||
if (!stagingBufferManager) {
|
||||
return false;
|
||||
}
|
||||
switch (image->getImageDesc().image_type) {
|
||||
switch (memObj->peekClMemObjType()) {
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
return stagingBufferManager->isValidForStagingTransferImage(this->getDevice(), ptr, hasDependencies);
|
||||
return stagingBufferManager->isValidForStagingTransfer(this->getDevice(), ptr, hasDependencies);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2024 Intel Corporation
|
||||
* Copyright (C) 2018-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -801,7 +801,7 @@ HWTEST_F(EnqueueWriteImageTest, whenEnqueueWriteImageWithUsmPtrAndSizeLowerThanR
|
||||
svmManager->freeSVMAlloc(usmPtr);
|
||||
}
|
||||
|
||||
HWTEST_F(EnqueueWriteImageTest, whenIsValidForStagingTransferImageCalledThenReturnCorrectValue) {
|
||||
HWTEST_F(EnqueueWriteImageTest, whenisValidForStagingTransferCalledThenReturnCorrectValue) {
|
||||
bool svmSupported = pDevice->getHardwareInfo().capabilityTable.ftrSvm;
|
||||
if (!svmSupported) {
|
||||
GTEST_SKIP();
|
||||
@@ -810,13 +810,13 @@ HWTEST_F(EnqueueWriteImageTest, whenIsValidForStagingTransferImageCalledThenRetu
|
||||
unsigned char ptr[16];
|
||||
|
||||
std::unique_ptr<Image> image(Image1dHelper<>::create(context));
|
||||
EXPECT_EQ(isStagingBuffersEnabled, pCmdQ->isValidForStagingTransferImage(image.get(), ptr, false));
|
||||
EXPECT_EQ(isStagingBuffersEnabled, pCmdQ->isValidForStagingTransfer(image.get(), ptr, false));
|
||||
|
||||
image.reset(Image2dHelper<>::create(context));
|
||||
EXPECT_EQ(isStagingBuffersEnabled, pCmdQ->isValidForStagingTransferImage(image.get(), ptr, false));
|
||||
EXPECT_EQ(isStagingBuffersEnabled, pCmdQ->isValidForStagingTransfer(image.get(), ptr, false));
|
||||
|
||||
image.reset(Image3dHelper<>::create(context));
|
||||
EXPECT_FALSE(pCmdQ->isValidForStagingTransferImage(image.get(), ptr, false));
|
||||
EXPECT_FALSE(pCmdQ->isValidForStagingTransfer(image.get(), ptr, false));
|
||||
}
|
||||
|
||||
struct WriteImageStagingBufferTest : public EnqueueWriteImageTest {
|
||||
@@ -938,4 +938,16 @@ HWTEST_F(WriteImageStagingBufferTest, whenEnqueueStagingWriteImageFailedThenProp
|
||||
|
||||
EXPECT_EQ(res, CL_INVALID_OPERATION);
|
||||
EXPECT_EQ(1ul, mockCommandQueueHw.enqueueWriteImageCounter);
|
||||
}
|
||||
|
||||
HWTEST_F(WriteImageStagingBufferTest, givenIsValidForStagingTransferWhenUserPtrIsMappedThenReturnFalse) {
|
||||
DebugManagerStateRestore restore{};
|
||||
debugManager.flags.DisableZeroCopyForBuffers.set(1);
|
||||
MockCommandQueueHw<FamilyType> mockCommandQueueHw(context, device.get(), &props);
|
||||
auto buffer = BufferHelper<>::create(context);
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
auto mappedPtr = mockCommandQueueHw.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, buffer->getSize(), 0, nullptr, nullptr, retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_FALSE(mockCommandQueueHw.isValidForStagingTransfer(buffer, mappedPtr, false));
|
||||
delete buffer;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
* Copyright (C) 2024-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -273,7 +273,7 @@ bool StagingBufferManager::isValidForCopy(const Device &device, void *dstPtr, co
|
||||
return stagingCopyEnabled && hostToUsmCopy && !hasDependencies && (isUsedByOsContext || size <= chunkSize);
|
||||
}
|
||||
|
||||
bool StagingBufferManager::isValidForStagingTransferImage(const Device &device, const void *ptr, bool hasDependencies) const {
|
||||
bool StagingBufferManager::isValidForStagingTransfer(const Device &device, const void *ptr, bool hasDependencies) const {
|
||||
auto stagingCopyEnabled = device.getProductHelper().isStagingBuffersEnabled();
|
||||
if (debugManager.flags.EnableCopyWithStagingBuffers.get() != -1) {
|
||||
stagingCopyEnabled = debugManager.flags.EnableCopyWithStagingBuffers.get();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
* Copyright (C) 2024-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -79,7 +79,7 @@ class StagingBufferManager {
|
||||
StagingBufferManager &operator=(const StagingBufferManager &other) = delete;
|
||||
|
||||
bool isValidForCopy(const Device &device, void *dstPtr, const void *srcPtr, size_t size, bool hasDependencies, uint32_t osContextId) const;
|
||||
bool isValidForStagingTransferImage(const Device &device, const void *ptr, bool hasDependencies) const;
|
||||
bool isValidForStagingTransfer(const Device &device, const void *ptr, bool hasDependencies) const;
|
||||
|
||||
StagingTransferStatus performCopy(void *dstPtr, const void *srcPtr, size_t size, ChunkCopyFunction &chunkCopyFunc, CommandStreamReceiver *csr);
|
||||
StagingTransferStatus performImageTransfer(const void *ptr, const size_t *globalOrigin, const size_t *globalRegion, size_t rowPitch, ChunkTransferImageFunc &chunkTransferImageFunc, CommandStreamReceiver *csr, bool isRead);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
* Copyright (C) 2024-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -198,16 +198,16 @@ TEST_F(StagingBufferManagerTest, givenStagingBufferEnabledWhenValidForImageWrite
|
||||
{nonUsmBuffer, true, false},
|
||||
};
|
||||
for (auto i = 0; i < 4; i++) {
|
||||
auto actualValid = stagingBufferManager->isValidForStagingTransferImage(*pDevice, copyParamsStruct[i].ptr, copyParamsStruct[i].hasDependencies);
|
||||
auto actualValid = stagingBufferManager->isValidForStagingTransfer(*pDevice, copyParamsStruct[i].ptr, copyParamsStruct[i].hasDependencies);
|
||||
EXPECT_EQ(actualValid, copyParamsStruct[i].expectValid);
|
||||
}
|
||||
|
||||
debugManager.flags.EnableCopyWithStagingBuffers.set(0);
|
||||
EXPECT_FALSE(stagingBufferManager->isValidForStagingTransferImage(*pDevice, nonUsmBuffer, false));
|
||||
EXPECT_FALSE(stagingBufferManager->isValidForStagingTransfer(*pDevice, nonUsmBuffer, false));
|
||||
|
||||
debugManager.flags.EnableCopyWithStagingBuffers.set(-1);
|
||||
auto isStaingBuffersEnabled = pDevice->getProductHelper().isStagingBuffersEnabled();
|
||||
EXPECT_EQ(isStaingBuffersEnabled, stagingBufferManager->isValidForStagingTransferImage(*pDevice, nonUsmBuffer, false));
|
||||
EXPECT_EQ(isStaingBuffersEnabled, stagingBufferManager->isValidForStagingTransfer(*pDevice, nonUsmBuffer, false));
|
||||
svmAllocsManager->freeSVMAlloc(usmBuffer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user