Revert "Add setArgBuffer caching to l0"

This reverts commit e6460e5534.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation 2022-03-12 20:18:35 +01:00 committed by Compute-Runtime-Automation
parent 4f31b569e4
commit cee7ded064
3 changed files with 10 additions and 111 deletions

View File

@ -546,33 +546,6 @@ ze_result_t KernelImp::setArgUnknown(uint32_t argIndex, size_t argSize, const vo
}
ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const void *argVal) {
const auto device = static_cast<DeviceImp *>(this->module->getDevice());
const auto driverHandle = static_cast<DriverHandleImp *>(device->getDriverHandle());
const auto svmAllocsManager = driverHandle->getSvmAllocsManager();
const auto allocationsCounter = svmAllocsManager->allocationsCounter.load();
NEO::SvmAllocationData *allocData = nullptr;
if (argVal != nullptr) {
const auto &argInfo = this->kernelArgInfos[argIndex];
if (argInfo.allocId > 0 && argVal == argInfo.value) {
bool reuseFromCache = false;
if (allocationsCounter > 0) {
if (allocationsCounter == argInfo.allocIdMemoryManagerCounter) {
reuseFromCache = true;
} else {
const auto requestedAddress = *reinterpret_cast<void *const *>(argVal);
allocData = svmAllocsManager->getSVMAlloc(requestedAddress);
if (allocData && allocData->getAllocId() == argInfo.allocId) {
reuseFromCache = true;
this->kernelArgInfos[argIndex].allocIdMemoryManagerCounter = allocationsCounter;
}
}
if (reuseFromCache) {
return ZE_RESULT_SUCCESS;
}
}
}
}
const auto &allArgs = kernelImmData->getDescriptor().payloadMappings.explicitArgs;
const auto &currArg = allArgs[argIndex];
if (currArg.getTraits().getAddressQualifier() == NEO::KernelArgMetadata::AddrLocal) {
@ -605,16 +578,16 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
NEO::patchPointer(ArrayRef<uint8_t>(crossThreadData.get(), crossThreadDataSize), arg, nullBufferValue);
return ZE_RESULT_SUCCESS;
}
const auto requestedAddress = *reinterpret_cast<void *const *>(argVal);
uintptr_t gpuAddress = 0u;
NEO::GraphicsAllocation *alloc = driverHandle->getDriverSystemMemoryAllocation(requestedAddress,
1u,
device->getRootDeviceIndex(),
&gpuAddress);
if (allocData == nullptr) {
allocData = svmAllocsManager->getSVMAlloc(requestedAddress);
}
auto requestedAddress = *reinterpret_cast<void *const *>(argVal);
uintptr_t gpuAddress = 0u;
NEO::GraphicsAllocation *alloc = module->getDevice()->getDriverHandle()->getDriverSystemMemoryAllocation(requestedAddress,
1u,
module->getDevice()->getRootDeviceIndex(),
&gpuAddress);
DeviceImp *device = static_cast<DeviceImp *>(this->module->getDevice());
DriverHandleImp *driverHandle = static_cast<DriverHandleImp *>(device->getDriverHandle());
auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(requestedAddress);
if (driverHandle->isRemoteResourceNeeded(requestedAddress, alloc, allocData, device)) {
if (allocData == nullptr) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
@ -630,9 +603,6 @@ ze_result_t KernelImp::setArgBuffer(uint32_t argIndex, size_t argSize, const voi
gpuAddress += offset;
}
const uint32_t allocId = allocData ? allocData->getAllocId() : 0u;
kernelArgInfos[argIndex] = KernelArgInfo{argVal, allocId, allocationsCounter};
return setArgBufferWithAlloc(argIndex, gpuAddress, alloc);
}
@ -816,7 +786,7 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) {
}
slmArgSizes.resize(this->kernelArgHandlers.size(), 0);
kernelArgInfos.resize(this->kernelArgHandlers.size(), {});
isArgUncached.resize(this->kernelArgHandlers.size(), 0);
if (kernelImmData->getSurfaceStateHeapSize() > 0) {

View File

@ -17,12 +17,6 @@
namespace L0 {
struct KernelArgInfo {
const void *value;
uint32_t allocId;
uint32_t allocIdMemoryManagerCounter;
};
struct KernelImp : Kernel {
KernelImp(Module *module);
@ -178,7 +172,6 @@ struct KernelImp : Kernel {
Module *module = nullptr;
typedef ze_result_t (KernelImp::*KernelArgHandler)(uint32_t argIndex, size_t argSize, const void *argVal);
std::vector<KernelArgInfo> kernelArgInfos;
std::vector<KernelImp::KernelArgHandler> kernelArgHandlers;
std::vector<NEO::GraphicsAllocation *> residencyContainer;

View File

@ -67,70 +67,6 @@ TEST(KernelArgTest, givenKernelWhenSetArgUnknownCalledThenSuccessRteurned) {
EXPECT_EQ(mockKernel.setArgUnknown(0, 0, nullptr), ZE_RESULT_SUCCESS);
}
struct MockKernelWithCallTracking : Mock<::L0::Kernel> {
using ::L0::KernelImp::kernelArgInfos;
ze_result_t setArgBufferWithAlloc(uint32_t argIndex, uintptr_t argVal, NEO::GraphicsAllocation *allocation) override {
++setArgBufferWithAllocCalled;
return KernelImp::setArgBufferWithAlloc(argIndex, argVal, allocation);
}
size_t setArgBufferWithAllocCalled = 0u;
};
using SetKernelArgCacheTest = Test<ModuleFixture>;
TEST_F(SetKernelArgCacheTest, givenValidBufferArgumentWhenSetMultipleTimesThenSetArgBufferWithAllocOnlyCalledIfNeeded) {
MockKernelWithCallTracking mockKernel;
mockKernel.module = module.get();
ze_kernel_desc_t desc = {};
desc.pKernelName = kernelName.c_str();
mockKernel.initialize(&desc);
auto svmAllocsManager = device->getDriverHandle()->getSvmAllocsManager();
auto allocationProperties = NEO::SVMAllocsManager::SvmAllocationProperties{};
auto svmAllocation = svmAllocsManager->createSVMAlloc(4096, allocationProperties, context->rootDeviceIndices, context->deviceBitfields);
size_t callCounter = 0u;
//first setArg - called
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(svmAllocation), &svmAllocation));
EXPECT_EQ(++callCounter, mockKernel.setArgBufferWithAllocCalled);
//same setArg but allocationCounter == 0 - called
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(svmAllocation), &svmAllocation));
EXPECT_EQ(++callCounter, mockKernel.setArgBufferWithAllocCalled);
//same setArg - not called and argInfo.allocationCounter is updated
++svmAllocsManager->allocationsCounter;
EXPECT_EQ(0u, mockKernel.kernelArgInfos[0].allocIdMemoryManagerCounter);
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(svmAllocation), &svmAllocation));
EXPECT_EQ(callCounter, mockKernel.setArgBufferWithAllocCalled);
EXPECT_EQ(svmAllocsManager->allocationsCounter, mockKernel.kernelArgInfos[0].allocIdMemoryManagerCounter);
//same setArg and allocationCounter - not called
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(svmAllocation), &svmAllocation));
EXPECT_EQ(callCounter, mockKernel.setArgBufferWithAllocCalled);
//same setArg but different allocId - called
svmAllocsManager->getSVMAlloc(svmAllocation)->setAllocId(1u);
++svmAllocsManager->allocationsCounter;
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(svmAllocation), &svmAllocation));
EXPECT_EQ(++callCounter, mockKernel.setArgBufferWithAllocCalled);
//different value - called
auto secondSvmAllocation = svmAllocsManager->createSVMAlloc(4096, allocationProperties, context->rootDeviceIndices, context->deviceBitfields);
EXPECT_EQ(ZE_RESULT_SUCCESS, mockKernel.setArgBuffer(0, sizeof(secondSvmAllocation), &secondSvmAllocation));
EXPECT_EQ(++callCounter, mockKernel.setArgBufferWithAllocCalled);
//same value but no svmData - ZE_RESULT_ERROR_INVALID_ARGUMENT
svmAllocsManager->freeSVMAlloc(secondSvmAllocation);
++svmAllocsManager->allocationsCounter;
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, mockKernel.setArgBuffer(0, sizeof(secondSvmAllocation), &secondSvmAllocation));
EXPECT_EQ(callCounter, mockKernel.setArgBufferWithAllocCalled);
svmAllocsManager->freeSVMAlloc(svmAllocation);
}
using KernelImpSetGroupSizeTest = Test<DeviceFixture>;
TEST_F(KernelImpSetGroupSizeTest, WhenCalculatingLocalIdsThenGrfSizeIsTakenFromCapabilityTable) {