Gmm Memory: initialize client context in constructor

Change-Id: Iaaa40f5485faceb022e018be7930777e14575b46
This commit is contained in:
Mateusz Jablonski
2018-07-23 10:06:00 +02:00
committed by sys_ocldev
parent d80334a534
commit ab7920ba14
3 changed files with 6 additions and 24 deletions

View File

@ -25,10 +25,8 @@
#include "runtime/gmm_helper/gmm_helper.h"
namespace OCLRT {
void GmmMemoryBase::ensureClientContext() {
if (!clientContext) {
clientContext = GmmHelper::gmmClientContext->getHandle();
}
GmmMemoryBase::GmmMemoryBase() {
clientContext = GmmHelper::gmmClientContext->getHandle();
}
bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter,
GMM_ESCAPE_HANDLE hDevice,
@ -39,7 +37,6 @@ bool GmmMemoryBase::configureDeviceAddressSpace(GMM_ESCAPE_HANDLE hAdapter,
BOOLEAN BDWL3Coherency,
GMM_GFX_SIZE_T SizeOverride,
GMM_GFX_SIZE_T SlmGfxSpaceReserve) {
ensureClientContext();
return clientContext->ConfigureDeviceAddressSpace(
{hAdapter},
{hDevice},

View File

@ -40,8 +40,7 @@ class GmmMemoryBase {
GMM_GFX_SIZE_T SlmGfxSpaceReserve);
protected:
GmmMemoryBase() = default;
void ensureClientContext();
GmmMemoryBase();
GMM_CLIENT_CONTEXT *clientContext = nullptr;
};
} // namespace OCLRT

View File

@ -30,25 +30,11 @@ using namespace OCLRT;
class PublicGmmMemory : public GmmMemory {
public:
using GmmMemory::clientContext;
using GmmMemory::ensureClientContext;
};
TEST(GmmMemoryTest, givenGmmMemoryWithoutSetClientContextWhenEnsureClientContextThenSetClientContext) {
PublicGmmMemory gmmMemory;
TEST(GmmMemoryTest, givenGmmHelperWhenCreateGmmMemoryThenItHasClientContextFromGmmHelper) {
GmmHelper gmmHelper(*platformDevices);
EXPECT_EQ(nullptr, gmmMemory.clientContext);
gmmMemory.ensureClientContext();
EXPECT_NE(nullptr, gmmMemory.clientContext);
ASSERT_NE(nullptr, GmmHelper::gmmClientContext);
PublicGmmMemory gmmMemory;
EXPECT_EQ(gmmMemory.clientContext, GmmHelper::gmmClientContext->getHandle());
}
TEST(GmmMemoryTest, givenGmmMemoryWithSetClientContextWhenEnsureClientContextThenDontOverrideClientContext) {
PublicGmmMemory gmmMemory;
GmmHelper gmmHelper(*platformDevices);
auto dummyPtr = reinterpret_cast<GMM_CLIENT_CONTEXT *>(0x123);
gmmMemory.clientContext = dummyPtr;
EXPECT_EQ(dummyPtr, gmmMemory.clientContext);
EXPECT_NE(dummyPtr, GmmHelper::gmmClientContext->getHandle());
gmmMemory.ensureClientContext();
EXPECT_EQ(dummyPtr, gmmMemory.clientContext);
}