Add proper handling decoding resource while import on WSL

- create resource info and handle when needed

Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
Kamil Diedrich
2022-07-01 09:38:41 +00:00
committed by Compute-Runtime-Automation
parent 7829364e67
commit 4d35a76931
4 changed files with 78 additions and 23 deletions

View File

@@ -97,7 +97,7 @@ class GmmResourceInfo {
GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle);
void createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr);
void decodeResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo);
void decodeResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo);
UniquePtrType resourceInfo;

View File

@@ -19,26 +19,28 @@ GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESCREATE_
GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) : GmmResourceInfo(clientContext, inputGmmResourceInfo, false) {}
GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle) : clientContext(clientContext) {
auto resourceInfoPtr = clientContext->copyResInfoObject(inputGmmResourceInfo);
if (openingHandle) {
decodeResourceInfo(resourceInfoPtr, inputGmmResourceInfo);
decodeResourceInfo(inputGmmResourceInfo);
} else {
auto resourceInfoPtr = clientContext->copyResInfoObject(inputGmmResourceInfo);
createResourceInfo(resourceInfoPtr);
}
}
void GmmResourceInfo::decodeResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo) {
void GmmResourceInfo::decodeResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo) {
auto customDeleter = [this](GMM_RESOURCE_INFO *gmmResourceInfo) {
this->clientContext->destroyResInfoObject(gmmResourceInfo);
};
if (this->clientContext->getHandleAllocator()) {
this->resourceInfo = UniquePtrType(resourceInfoPtr, [](GMM_RESOURCE_INFO *gmmResourceInfo) {});
this->clientContext->getHandleAllocator()->openHandle(inputGmmResourceInfo, resourceInfoPtr, this->clientContext->getHandleAllocator()->getHandleSize());
this->handle = resourceInfoPtr;
this->handleSize = this->clientContext->getHandleAllocator()->getHandleSize();
return;
}
UNRECOVERABLE_IF(this->handle != nullptr);
auto resourceInfoPtr = this->clientContext->copyResInfoObject(inputGmmResourceInfo);
this->resourceInfo = UniquePtrType(resourceInfoPtr, customDeleter);
this->handle = this->clientContext->getHandleAllocator()->createHandle(inputGmmResourceInfo);
this->handleSize = this->clientContext->getHandleAllocator()->getHandleSize();
this->clientContext->getHandleAllocator()->openHandle(inputGmmResourceInfo, this->resourceInfo.get(), this->clientContext->getHandleAllocator()->getHandleSize());
}
void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) {
@@ -57,8 +59,8 @@ void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) {
}
void GmmResourceInfo::refreshHandle() {
if (this->clientContext) {
this->decodeResourceInfo(this->resourceInfo.release(), static_cast<GMM_RESOURCE_INFO *>(this->handle));
if (this->clientContext && this->clientContext->getHandleAllocator()) {
this->clientContext->getHandleAllocator()->openHandle(this->handle, this->resourceInfo.get(), this->clientContext->getHandleAllocator()->getHandleSize());
}
}

View File

@@ -95,10 +95,9 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
auto resInfo2 = static_cast<NEO::MockGmmResourceInfo *>(NEO::GmmResourceInfo::create(nullptr, reinterpret_cast<GMM_RESOURCE_INFO *>(resInfo), true));
ASSERT_NE(nullptr, resInfo2);
resInfo2->clientContext = &gmmClientCtx;
auto resourceInfoPtr = resInfo2->clientContext->copyResInfoObject(static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
resInfo2->decodeResourceInfo(resourceInfoPtr, static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
resInfo2->decodeResourceInfo(static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
EXPECT_EQ(1U, created.size());
EXPECT_EQ(2U, created.size());
EXPECT_EQ(1U, opened.size());
EXPECT_EQ(0U, destroyed.size());
@@ -116,7 +115,7 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
resInfo2->refreshHandle();
EXPECT_EQ(1U, created.size());
EXPECT_EQ(2U, created.size());
EXPECT_EQ(2U, opened.size());
EXPECT_EQ(0U, destroyed.size());
EXPECT_EQ(1u, resInfo2->refreshHandleCalled);
@@ -124,12 +123,71 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
delete resInfo;
delete resInfo2;
EXPECT_EQ(1U, created.size());
EXPECT_EQ(2U, created.size());
EXPECT_EQ(2U, opened.size());
EXPECT_EQ(2U, destroyed.size());
EXPECT_NE(destroyed.end(), std::find(destroyed.begin(), destroyed.end(), handle));
}
TEST(GmmResourceInfo, GivenResourceInfoWhenRefreshIsCalledTiwceThenOpenHandleIsCalledTwice) {
NEO::HardwareInfo hwInfo;
hwInfo.platform.eProductFamily = productFamily;
NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo};
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
GMM_RESCREATE_PARAMS createParams = {};
createParams.Type = RESOURCE_BUFFER;
createParams.Format = GMM_FORMAT_R8G8B8A8_SINT;
auto resInfo = static_cast<NEO::MockGmmResourceInfo *>(NEO::GmmResourceInfo::create(nullptr, &createParams));
ASSERT_NE(nullptr, resInfo);
resInfo->clientContext = &gmmClientCtx;
resInfo->createResourceInfo(nullptr);
auto &created = handleAllocator->createdHandles;
auto &opened = handleAllocator->openedHandles;
auto &destroyed = handleAllocator->destroyedHandles;
EXPECT_EQ(0U, opened.size());
auto resInfo2 = static_cast<NEO::MockGmmResourceInfo *>(NEO::GmmResourceInfo::create(nullptr, reinterpret_cast<GMM_RESOURCE_INFO *>(resInfo), true));
ASSERT_NE(nullptr, resInfo2);
resInfo2->clientContext = &gmmClientCtx;
resInfo2->decodeResourceInfo(static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
EXPECT_EQ(2U, created.size());
EXPECT_EQ(1U, opened.size());
EXPECT_EQ(0U, destroyed.size());
EXPECT_EQ(handleAllocator->getHandleSize(), resInfo->GmmResourceInfo::peekHandleSize());
auto handle = resInfo->GmmResourceInfo::peekHandle();
EXPECT_NE(nullptr, handle);
EXPECT_NE(created.end(), std::find(created.begin(), created.end(), handle));
EXPECT_NE(opened.end(), std::find(opened.begin(), opened.end(), handle));
auto handle2 = resInfo2->GmmResourceInfo::peekHandle();
EXPECT_NE(nullptr, handle2);
EXPECT_EQ(0u, resInfo2->refreshHandleCalled);
resInfo2->refreshHandle();
resInfo2->refreshHandle();
EXPECT_EQ(2U, created.size());
EXPECT_EQ(3U, opened.size());
EXPECT_EQ(0U, destroyed.size());
EXPECT_EQ(2u, resInfo2->refreshHandleCalled);
delete resInfo;
delete resInfo2;
EXPECT_EQ(2U, created.size());
EXPECT_EQ(3U, opened.size());
EXPECT_EQ(2U, destroyed.size());
EXPECT_NE(destroyed.end(), std::find(destroyed.begin(), destroyed.end(), handle));
}
TEST(GmmResourceInfo, WhenUsingBaseHandleAllocatorThenHandlesAreEmpty) {
NEO::GmmHandleAllocator defaultAllocator;
EXPECT_EQ(0U, defaultAllocator.getHandleSize());