mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-29 09:03:14 +08:00
Read resource info from internal represenation for WSL
Related-To: LOCI-3037 Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
2578a988c5
commit
7bb3bcbc05
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -22,6 +22,9 @@ class GmmHandleAllocator {
|
||||
}
|
||||
virtual void destroyHandle(void *handle) {
|
||||
}
|
||||
virtual bool openHandle(void *handle, GMM_RESOURCE_INFO *dstResInfo, size_t handleSize) {
|
||||
return true;
|
||||
}
|
||||
virtual size_t getHandleSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,10 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_
|
||||
gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), &resourceParams));
|
||||
}
|
||||
|
||||
Gmm::Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm) : gmmHelper(gmmHelper) {
|
||||
gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), inputGmm));
|
||||
Gmm::Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm) : Gmm(gmmHelper, inputGmm, false) {}
|
||||
|
||||
Gmm::Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm, bool openingHandle) : gmmHelper(gmmHelper) {
|
||||
gmmResourceInfo.reset(GmmResourceInfo::create(gmmHelper->getClientContext(), inputGmm, openingHandle));
|
||||
applyDebugOverrides();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class Gmm {
|
||||
Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_t alignment,
|
||||
GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsage, bool preferCompressed, StorageInfo storageInfo, bool allowLargePages);
|
||||
Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm);
|
||||
Gmm(GmmHelper *gmmHelper, GMM_RESOURCE_INFO *inputGmm, bool openingHandle);
|
||||
|
||||
void queryImageParams(ImageInfo &inputOutputImgInfo);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -15,4 +15,9 @@ GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RE
|
||||
GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) {
|
||||
return new GmmResourceInfo(clientContext, inputGmmResourceInfo);
|
||||
}
|
||||
|
||||
GmmResourceInfo *GmmResourceInfo::create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle) {
|
||||
return new GmmResourceInfo(clientContext, inputGmmResourceInfo, openingHandle);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -19,6 +19,8 @@ class GmmResourceInfo {
|
||||
|
||||
static GmmResourceInfo *create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo);
|
||||
|
||||
static GmmResourceInfo *create(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle);
|
||||
|
||||
MOCKABLE_VIRTUAL ~GmmResourceInfo();
|
||||
|
||||
MOCKABLE_VIRTUAL size_t getSizeAllocation() { return static_cast<size_t>(resourceInfo->GetSize(GMM_TOTAL_SURF)); }
|
||||
@@ -90,7 +92,10 @@ class GmmResourceInfo {
|
||||
|
||||
GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo);
|
||||
|
||||
GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle);
|
||||
|
||||
void createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr);
|
||||
void createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo);
|
||||
|
||||
UniquePtrType resourceInfo;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -16,15 +16,29 @@ GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESCREATE_
|
||||
createResourceInfo(resourceInfoPtr);
|
||||
}
|
||||
|
||||
GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) : clientContext(clientContext) {
|
||||
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);
|
||||
createResourceInfo(resourceInfoPtr);
|
||||
if (openingHandle) {
|
||||
createResourceInfo(resourceInfoPtr, inputGmmResourceInfo);
|
||||
} else {
|
||||
createResourceInfo(resourceInfoPtr);
|
||||
}
|
||||
}
|
||||
|
||||
GmmResourceInfo::~GmmResourceInfo() {
|
||||
if (this->clientContext && this->clientContext->getHandleAllocator()) {
|
||||
this->clientContext->getHandleAllocator()->destroyHandle(this->handle);
|
||||
void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, 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;
|
||||
}
|
||||
this->resourceInfo = UniquePtrType(resourceInfoPtr, customDeleter);
|
||||
}
|
||||
|
||||
void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) {
|
||||
@@ -42,4 +56,10 @@ void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) {
|
||||
}
|
||||
}
|
||||
|
||||
GmmResourceInfo::~GmmResourceInfo() {
|
||||
if (this->clientContext && this->clientContext->getHandleAllocator()) {
|
||||
this->clientContext->getHandleAllocator()->destroyHandle(this->handle);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
* Copyright (C) 2021-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -34,6 +34,8 @@ class WslComputeHelperGmmHandleAllocator : public GmmHandleAllocator {
|
||||
|
||||
void *createHandle(const GMM_RESOURCE_INFO *gmmResourceInfo) override;
|
||||
|
||||
bool openHandle(void *handle, GMM_RESOURCE_INFO *dstResInfo, size_t handleSize) override;
|
||||
|
||||
void destroyHandle(void *handle) override;
|
||||
|
||||
size_t getHandleSize() override {
|
||||
@@ -172,6 +174,15 @@ class WslComputeHelperUmKmDataTranslator : public UmKmDataTranslator {
|
||||
return tokensToStructFn(TOK_S_GMM_RESOURCE_INFO_WIN_STRUCT, dst, dstSize, &marshalled.base.header, reinterpret_cast<TokenHeader *>(&marshalled + 1));
|
||||
}
|
||||
|
||||
bool translateGmmResourceInfoFromInternalRepresentation(GmmResourceInfoWinStruct &resInfoPodStruct, const void *src, size_t srcSize) {
|
||||
std::vector<uint8_t> tokData(gmmResourceInfoTokensSize);
|
||||
TokenHeader *tok = reinterpret_cast<TokenHeader *>(tokData.data());
|
||||
if (false == structToTokensFn(TOK_S_GMM_RESOURCE_INFO_WIN_STRUCT, tok, gmmResourceInfoTokensSize, src, srcSize)) {
|
||||
return false;
|
||||
}
|
||||
return Demarshaller<TOK_S_GMM_RESOURCE_INFO_WIN_STRUCT>::demarshall(resInfoPodStruct, tok, tok + gmmResourceInfoTokensSize / sizeof(TokenHeader));
|
||||
}
|
||||
|
||||
bool translateGmmGfxPartitioningToInternalRepresentation(void *dst, size_t dstSize, const GMM_GFX_PARTITIONING &src) override {
|
||||
if (computeHelperLibraryVersion == 0) {
|
||||
return (0 == memcpy_s(dst, dstSize, &src, sizeof(src)));
|
||||
@@ -235,6 +246,16 @@ void *WslComputeHelperGmmHandleAllocator::createHandle(const GMM_RESOURCE_INFO *
|
||||
return ret.release();
|
||||
}
|
||||
|
||||
bool WslComputeHelperGmmHandleAllocator::openHandle(void *handle, GMM_RESOURCE_INFO *dstResInfo, size_t handleSize) {
|
||||
GmmResourceInfoWinStruct resInfoPodStruct = {};
|
||||
|
||||
translator->translateGmmResourceInfoFromInternalRepresentation(resInfoPodStruct, handle, handleSize);
|
||||
|
||||
static_cast<GmmResourceInfoWinAccessor *>(dstResInfo)->set(resInfoPodStruct);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WslComputeHelperGmmHandleAllocator::destroyHandle(void *handle) {
|
||||
translator->destroyGmmResourceInfo(handle, translator->getSizeForGmmResourceInfoInternalRepresentation());
|
||||
delete[] reinterpret_cast<uint64_t *>(handle);
|
||||
|
||||
@@ -749,12 +749,13 @@ bool Wddm::openNTHandle(HANDLE handle, WddmAllocation *alloc) {
|
||||
status = getGdi()->openResourceFromNtHandle(&openResourceFromNtHandle);
|
||||
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
||||
|
||||
auto resourceInfo = const_cast<void *>(allocationInfo2[0].pPrivateDriverData);
|
||||
|
||||
alloc->setDefaultGmm(new Gmm(rootDeviceEnvironment.getGmmHelper(), static_cast<GMM_RESOURCE_INFO *>(resourceInfo), hwDeviceId->getUmKmDataTranslator()->enabled()));
|
||||
|
||||
alloc->setDefaultHandle(allocationInfo2[0].hAllocation);
|
||||
alloc->resourceHandle = openResourceFromNtHandle.hResource;
|
||||
|
||||
auto resourceInfo = const_cast<void *>(allocationInfo2[0].pPrivateDriverData);
|
||||
alloc->setDefaultGmm(new Gmm(rootDeviceEnvironment.getGmmHelper(), static_cast<GMM_RESOURCE_INFO *>(resourceInfo)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user