Skip to content

Commit 8ead8f7

Browse files
Control enabling of local memory based on OS and HW Capabilities
Change-Id: Ia26c856aeef27fe638b7a6e895cc289859f3c579
1 parent 7319023 commit 8ead8f7

File tree

12 files changed

+54
-1
lines changed

12 files changed

+54
-1
lines changed

runtime/device/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
113113
if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo, outDevice.getDeviceIndex())) {
114114
return false;
115115
}
116-
executionEnvironment->initializeMemoryManager(outDevice.getEnabled64kbPages(), outDevice.getHardwareCapabilities().localMemorySupported, outDevice.getDeviceIndex());
116+
executionEnvironment->initializeMemoryManager(outDevice.getEnabled64kbPages(), outDevice.getEnableLocalMemory(), outDevice.getDeviceIndex());
117117

118118
outDevice.osContext = new OsContext(executionEnvironment->osInterface.get(), outDevice.getDeviceIndex());
119119
executionEnvironment->memoryManager->registerOsContext(outDevice.osContext);

runtime/device/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class Device : public BaseObject<_cl_device_id> {
113113
std::string deviceExtensions;
114114
std::string name;
115115
bool getEnabled64kbPages();
116+
bool getEnableLocalMemory();
116117
bool isSourceLevelDebuggerActive() const;
117118
SourceLevelDebugger *getSourceLevelDebugger() { return executionEnvironment->sourceLevelDebugger.get(); }
118119
ExecutionEnvironment *getExecutionEnvironment() const { return executionEnvironment; }

runtime/device/device_caps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ bool Device::getEnabled64kbPages() {
5252
}
5353
};
5454

55+
bool Device::getEnableLocalMemory() {
56+
return OSInterface::osEnableLocalMemory && getHardwareCapabilities().localMemorySupported;
57+
};
58+
5559
void Device::setupFp64Flags() {
5660
if (DebugManager.flags.OverrideDefaultFP64Settings.get() == -1) {
5761
if (hwInfo.capabilityTable.ftrSupportsFP64) {

runtime/memory_manager/memory_manager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ bool MemoryManager::isAsyncDeleterEnabled() const {
234234
return asyncDeleterEnabled;
235235
}
236236

237+
bool MemoryManager::isLocalMemorySupported() const {
238+
return localMemorySupported;
239+
}
240+
237241
bool MemoryManager::isMemoryBudgetExhausted() const {
238242
return false;
239243
}

runtime/memory_manager/memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class MemoryManager {
234234
void waitForDeletions();
235235

236236
bool isAsyncDeleterEnabled() const;
237+
bool isLocalMemorySupported() const;
237238
virtual bool isMemoryBudgetExhausted() const;
238239

239240
virtual AlignedMallocRestrictions *getAlignedMallocRestrictions() {

runtime/os_interface/linux/os_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCLRT {
1111

1212
bool OSInterface::osEnabled64kbPages = false;
13+
bool OSInterface::osEnableLocalMemory = false;
1314

1415
OSInterface::OSInterface() {
1516
osInterfaceImpl = new OSInterfaceImpl();

runtime/os_interface/os_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class OSInterface {
2323
};
2424
unsigned int getHwContextId() const;
2525
static bool osEnabled64kbPages;
26+
static bool osEnableLocalMemory;
2627
static bool are64kbPagesEnabled();
2728
unsigned int getDeviceHandle() const;
2829

runtime/os_interface/windows/os_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace OCLRT {
1414

1515
bool OSInterface::osEnabled64kbPages = true;
16+
bool OSInterface::osEnableLocalMemory = false;
1617

1718
OSInterface::OSInterface() {
1819
osInterfaceImpl = new OSInterfaceImpl();

unit_tests/device/device_caps_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "unit_tests/fixtures/device_fixture.h"
2020
#include "unit_tests/helpers/debug_manager_state_restore.h"
2121
#include "unit_tests/helpers/hw_helper_tests.h"
22+
#include "unit_tests/helpers/variable_backup.h"
2223
#include "unit_tests/mocks/mock_builtins.h"
2324
#include "unit_tests/mocks/mock_device.h"
2425

@@ -767,6 +768,30 @@ TEST(Device_GetCaps, givenDeviceWithNullSourceLevelDebuggerWhenCapsAreInitialize
767768

768769
typedef HwHelperTest DeviceCapsWithModifiedHwInfoTest;
769770

771+
TEST_F(DeviceCapsWithModifiedHwInfoTest, GivenLocalMemorySupportedAndOsEnableLocalMemoryWhenSetThenGetEnableLocalMemoryReturnCorrectValue) {
772+
VariableBackup<bool> orgOsEnableLocalMemory(&OSInterface::osEnableLocalMemory);
773+
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
774+
bool orgHwCapsLocalMemorySupported = device->getHardwareCapabilities().localMemorySupported;
775+
776+
device->setHWCapsLocalMemorySupported(false);
777+
OSInterface::osEnableLocalMemory = false;
778+
EXPECT_FALSE(device->getEnableLocalMemory());
779+
780+
device->setHWCapsLocalMemorySupported(false);
781+
OSInterface::osEnableLocalMemory = true;
782+
EXPECT_FALSE(device->getEnableLocalMemory());
783+
784+
device->setHWCapsLocalMemorySupported(true);
785+
OSInterface::osEnableLocalMemory = false;
786+
EXPECT_FALSE(device->getEnableLocalMemory());
787+
788+
device->setHWCapsLocalMemorySupported(true);
789+
OSInterface::osEnableLocalMemory = true;
790+
EXPECT_TRUE(device->getEnableLocalMemory());
791+
792+
device->setHWCapsLocalMemorySupported(orgHwCapsLocalMemorySupported);
793+
}
794+
770795
TEST_F(DeviceCapsWithModifiedHwInfoTest, givenPlatformWithSourceLevelDebuggerNotSupportedWhenDeviceIsCreatedThenSourceLevelDebuggerActiveIsSetToFalse) {
771796

772797
hwInfo.capabilityTable.sourceLevelDebuggerSupported = false;

unit_tests/execution_environment/execution_environment_tests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "test.h"
2121
#include "unit_tests/mocks/mock_csr.h"
22+
#include "unit_tests/mocks/mock_device.h"
2223
#include "unit_tests/mocks/mock_memory_manager.h"
2324
#include "unit_tests/utilities/destructor_counted.h"
2425
#include "unit_tests/helpers/unit_test_helper.h"
@@ -137,6 +138,14 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCal
137138
EXPECT_EQ(currentAubFileStream, executionEnvironment.aubCenter->getStreamProvider()->getStream());
138139
}
139140

141+
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenLocalMemorySupportedInMemoryManagerHasCorrectValue) {
142+
auto device = std::unique_ptr<Device>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(platformDevices[0]));
143+
auto executionEnvironment = device->getExecutionEnvironment();
144+
executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0u);
145+
executionEnvironment->initializeMemoryManager(false, device->getEnableLocalMemory(), 0u);
146+
EXPECT_EQ(device->getEnableLocalMemory(), executionEnvironment->memoryManager->isLocalMemorySupported());
147+
}
148+
140149
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) {
141150
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
142151
executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0u);

0 commit comments

Comments
 (0)