Skip to content

Commit e34c472

Browse files
Fix destruction sequence in execution environment.
- Gmm needs to be closed after memory manager. Change-Id: I608fc328034012ce52b7e791afd9ad2ff2f0cd1a
1 parent a8ce3ca commit e34c472

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

runtime/execution_environment/execution_environment.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
3232
private:
3333
DeviceFactoryCleaner cleaner;
3434

35+
protected:
36+
std::unique_ptr<GmmHelper> gmmHelper;
37+
3538
public:
3639
ExecutionEnvironment();
3740
~ExecutionEnvironment() override;
3841
void initGmm(const HardwareInfo *hwInfo);
3942
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
4043
std::unique_ptr<MemoryManager> memoryManager;
41-
42-
protected:
43-
std::unique_ptr<GmmHelper> gmmHelper;
4444
};
4545
} // namespace OCLRT

runtime/gmm_helper/gmm_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class GmmHelper {
4141
public:
4242
GmmHelper() = delete;
4343
GmmHelper(const HardwareInfo *hwInfo);
44-
~GmmHelper();
44+
MOCKABLE_VIRTUAL ~GmmHelper();
4545
static constexpr uint32_t cacheDisabledIndex = 0;
4646
static constexpr uint32_t cacheEnabledIndex = 4;
4747
static constexpr uint32_t maxPossiblePitch = 2147483648;

unit_tests/execution_environment/execution_environment_tests.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222

2323
#include "test.h"
2424
#include "runtime/device/device.h"
25+
#include "runtime/gmm_helper/gmm_helper.h"
2526
#include "runtime/execution_environment/execution_environment.h"
27+
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
28+
#include "runtime/helpers/options.h"
2629
#include "runtime/platform/platform.h"
2730

2831
using namespace OCLRT;
@@ -91,4 +94,34 @@ TEST(ExecutionEnvironment, givenDeviceWhenItIsDestroyedThenMemoryManagerIsStillA
9194
std::unique_ptr<Device> device(Device::create<OCLRT::Device>(nullptr, executionEnvironment.get()));
9295
device.reset(nullptr);
9396
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
97+
}
98+
99+
auto destructorId = 0u;
100+
static_assert(sizeof(ExecutionEnvironment) == (is64bit ? 48 : 28), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
101+
102+
TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) {
103+
destructorId = 0u;
104+
struct GmmHelperMock : public GmmHelper {
105+
using GmmHelper::GmmHelper;
106+
~GmmHelperMock() override {
107+
EXPECT_EQ(destructorId, 1u);
108+
destructorId++;
109+
}
110+
};
111+
struct MemoryMangerMock : public OsAgnosticMemoryManager {
112+
~MemoryMangerMock() override {
113+
EXPECT_EQ(destructorId, 0u);
114+
destructorId++;
115+
}
116+
};
117+
struct MockExecutionEnvironment : ExecutionEnvironment {
118+
using ExecutionEnvironment::gmmHelper;
119+
};
120+
121+
std::unique_ptr<MockExecutionEnvironment> executionEnvironment(new MockExecutionEnvironment);
122+
executionEnvironment->gmmHelper.reset(new GmmHelperMock(platformDevices[0]));
123+
executionEnvironment->memoryManager.reset(new MemoryMangerMock);
124+
125+
executionEnvironment.reset(nullptr);
126+
EXPECT_EQ(2u, destructorId);
94127
}

0 commit comments

Comments
 (0)