mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-29 09:03:14 +08:00
refactor: decouple gmm client context initialization
move gmm interface interaction out of constructor Related-To: NEO-11080 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
c888e8d57c
commit
ce55243f11
@@ -17,7 +17,10 @@
|
||||
#include "shared/source/sku_info/operations/sku_info_transfer.h"
|
||||
|
||||
namespace NEO {
|
||||
GmmClientContext::GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment) {
|
||||
GmmClientContext::GmmClientContext() = default;
|
||||
GmmClientContext::~GmmClientContext() = default;
|
||||
|
||||
void GmmClientContext::initialize(const RootDeviceEnvironment &rootDeviceEnvironment) {
|
||||
auto hardwareInfo = rootDeviceEnvironment.getHardwareInfo();
|
||||
_SKU_FEATURE_TABLE gmmFtrTable = {};
|
||||
_WA_TABLE gmmWaTable = {};
|
||||
@@ -46,14 +49,13 @@ GmmClientContext::GmmClientContext(const RootDeviceEnvironment &rootDeviceEnviro
|
||||
|
||||
UNRECOVERABLE_IF(ret != GMM_SUCCESS);
|
||||
|
||||
clientContext = outArgs.pGmmClientContext;
|
||||
auto deleter = [](auto clientContextHandle) {
|
||||
GMM_INIT_OUT_ARGS outArgs;
|
||||
outArgs.pGmmClientContext = clientContextHandle;
|
||||
GmmInterface::destroy(&outArgs);
|
||||
};
|
||||
clientContext = {outArgs.pGmmClientContext, deleter};
|
||||
}
|
||||
GmmClientContext::~GmmClientContext() {
|
||||
GMM_INIT_OUT_ARGS outArgs;
|
||||
outArgs.pGmmClientContext = clientContext;
|
||||
|
||||
GmmInterface::destroy(&outArgs);
|
||||
};
|
||||
|
||||
MEMORY_OBJECT_CONTROL_STATE GmmClientContext::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) {
|
||||
return clientContext->CachePolicyGetMemoryObject(pResInfo, usage);
|
||||
@@ -72,7 +74,7 @@ void GmmClientContext::destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) {
|
||||
}
|
||||
|
||||
GMM_CLIENT_CONTEXT *GmmClientContext::getHandle() const {
|
||||
return clientContext;
|
||||
return clientContext.get();
|
||||
}
|
||||
|
||||
uint8_t GmmClientContext::getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include "shared/source/gmm_helper/gmm_lib.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace NEO {
|
||||
@@ -20,8 +21,9 @@ class DeallocateGmm;
|
||||
|
||||
class GmmClientContext {
|
||||
public:
|
||||
GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
GmmClientContext();
|
||||
MOCKABLE_VIRTUAL ~GmmClientContext();
|
||||
MOCKABLE_VIRTUAL void initialize(const RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
|
||||
MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage);
|
||||
MOCKABLE_VIRTUAL uint32_t cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage, bool compressed, bool cacheable);
|
||||
@@ -35,7 +37,9 @@ class GmmClientContext {
|
||||
GMM_CLIENT_CONTEXT *getHandle() const;
|
||||
template <typename T>
|
||||
static std::unique_ptr<GmmClientContext> create(const RootDeviceEnvironment &rootDeviceEnvironment) {
|
||||
return std::make_unique<T>(rootDeviceEnvironment);
|
||||
auto retVal = std::make_unique<T>();
|
||||
retVal->initialize(rootDeviceEnvironment);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL uint8_t getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format);
|
||||
@@ -50,7 +54,7 @@ class GmmClientContext {
|
||||
}
|
||||
|
||||
protected:
|
||||
GMM_CLIENT_CONTEXT *clientContext;
|
||||
std::unique_ptr<GMM_CLIENT_CONTEXT, std::function<void(GMM_CLIENT_CONTEXT *)>> clientContext;
|
||||
std::unique_ptr<GmmHandleAllocator> handleAllocator;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -64,7 +64,8 @@ class GmmResourceInfoDrmOrWddmTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
hwInfo = *defaultHwInfo;
|
||||
executionEnvironment = std::make_unique<MockExecutionEnvironment>(&hwInfo);
|
||||
gmmClientContext = std::make_unique<NEO::MockGmmClientContext>(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
gmmClientContext = std::make_unique<NEO::MockGmmClientContext>();
|
||||
gmmClientContext->initialize(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
|
||||
GMM_RESCREATE_PARAMS createParams = {};
|
||||
createParams.Type = RESOURCE_BUFFER;
|
||||
|
||||
@@ -21,7 +21,8 @@ class GmmResourceInfoDrmTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
hwInfo = *defaultHwInfo;
|
||||
executionEnvironment = std::make_unique<MockExecutionEnvironment>(&hwInfo);
|
||||
gmmClientContext = std::make_unique<NEO::MockGmmClientContext>(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
gmmClientContext = std::make_unique<NEO::MockGmmClientContext>();
|
||||
gmmClientContext->initialize(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
|
||||
GMM_RESCREATE_PARAMS createParams = {};
|
||||
createParams.Type = RESOURCE_BUFFER;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2024 Intel Corporation
|
||||
* Copyright (C) 2021-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -47,7 +47,8 @@ struct MockGmmHandleAllocator : NEO::GmmHandleAllocator {
|
||||
TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreatingGmmResourceInfoHandles) {
|
||||
auto hwInfo = *defaultHwInfo;
|
||||
MockExecutionEnvironment executionEnvironment{&hwInfo};
|
||||
NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]};
|
||||
NEO::MockGmmClientContext gmmClientCtx{};
|
||||
gmmClientCtx.initialize(*executionEnvironment.rootDeviceEnvironments[0]);
|
||||
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
|
||||
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
|
||||
|
||||
@@ -80,7 +81,8 @@ TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreating
|
||||
TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenDecodingResourceInfoThenExistingHandleIsOpened) {
|
||||
auto hwInfo = *defaultHwInfo;
|
||||
MockExecutionEnvironment executionEnvironment{&hwInfo};
|
||||
NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]};
|
||||
NEO::MockGmmClientContext gmmClientCtx{};
|
||||
gmmClientCtx.initialize(*executionEnvironment.rootDeviceEnvironments[0]);
|
||||
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
|
||||
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
|
||||
|
||||
@@ -138,7 +140,8 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
|
||||
TEST(GmmResourceInfo, GivenResourceInfoWhenRefreshIsCalledTiwceThenOpenHandleIsCalledTwice) {
|
||||
auto hwInfo = *defaultHwInfo;
|
||||
MockExecutionEnvironment executionEnvironment{&hwInfo};
|
||||
NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]};
|
||||
NEO::MockGmmClientContext gmmClientCtx{};
|
||||
gmmClientCtx.initialize(*executionEnvironment.rootDeviceEnvironments[0]);
|
||||
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
|
||||
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ class GmmResourceInfoWddmTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
hwInfo = *defaultHwInfo;
|
||||
executionEnvironment = std::make_unique<MockExecutionEnvironment>(&hwInfo);
|
||||
gmmClientContext = std::make_unique<NEO::MockGmmClientContext>(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
gmmClientContext = std::make_unique<NEO::MockGmmClientContext>();
|
||||
gmmClientContext->initialize(*executionEnvironment->rootDeviceEnvironments[0]);
|
||||
|
||||
GMM_RESCREATE_PARAMS createParams = {};
|
||||
createParams.Type = RESOURCE_BUFFER;
|
||||
|
||||
Reference in New Issue
Block a user