Add Device::getParentDevice function

Change-Id: I7b75bca67dceb74624c8dd8fd8c1542437fd9393
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2020-07-15 12:38:34 +02:00
parent 74d520e893
commit bbf50f8d4d
6 changed files with 25 additions and 1 deletions

View File

@ -12,6 +12,7 @@
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
#include "shared/test/unit_test/helpers/ult_hw_config.h"
#include "shared/test/unit_test/helpers/variable_backup.h"
#include "shared/test/unit_test/mocks/ult_device_factory.h"
#include "opencl/source/command_stream/tbx_command_stream_receiver.h"
#include "opencl/source/platform/platform.h"
@ -329,6 +330,18 @@ TEST(DeviceCreation, givenDeviceWhenCheckingEnginesCountThenNumberGreaterThanZer
EXPECT_GT(HwHelper::getEnginesCount(device->getHardwareInfo()), 0u);
}
TEST(DeviceCreation, givenDeviceWhenCheckingParentDeviceThenCorrectValueIsReturned) {
UltDeviceFactory deviceFactory{2, 2};
EXPECT_EQ(nullptr, deviceFactory.rootDevices[0]->getParentDevice());
EXPECT_EQ(deviceFactory.rootDevices[0], deviceFactory.subDevices[0]->getParentDevice());
EXPECT_EQ(deviceFactory.rootDevices[0], deviceFactory.subDevices[1]->getParentDevice());
EXPECT_EQ(nullptr, deviceFactory.rootDevices[1]->getParentDevice());
EXPECT_EQ(deviceFactory.rootDevices[1], deviceFactory.subDevices[2]->getParentDevice());
EXPECT_EQ(deviceFactory.rootDevices[1], deviceFactory.subDevices[3]->getParentDevice());
}
using DeviceHwTest = ::testing::Test;
HWTEST_F(DeviceHwTest, givenHwHelperInputWhenInitializingCsrThenCreatePageTableManagerIfNeeded) {

View File

@ -86,6 +86,7 @@ class Device : public ReferenceTrackedObject<Device> {
virtual uint32_t getRootDeviceIndex() const = 0;
virtual uint32_t getNumAvailableDevices() const = 0;
virtual Device *getDeviceById(uint32_t deviceId) const = 0;
virtual Device *getParentDevice() const = 0;
virtual DeviceBitfield getDeviceBitfield() const = 0;
static decltype(&PerformanceCounters::create) createPerformanceCountersFunc;

View File

@ -48,7 +48,11 @@ Device *RootDevice::getDeviceById(uint32_t deviceId) const {
return const_cast<RootDevice *>(this);
}
return subdevices[deviceId];
};
}
Device *RootDevice::getParentDevice() const {
return nullptr;
}
SubDevice *RootDevice::createSubDevice(uint32_t subDeviceIndex) {
return Device::create<SubDevice>(executionEnvironment, subDeviceIndex, *this);

View File

@ -20,6 +20,7 @@ class RootDevice : public Device {
uint32_t getNumAvailableDevices() const override;
uint32_t getRootDeviceIndex() const override;
Device *getDeviceById(uint32_t deviceId) const override;
Device *getParentDevice() const override;
uint32_t getNumSubDevices() const;

View File

@ -43,6 +43,10 @@ Device *SubDevice::getDeviceById(uint32_t deviceId) const {
return const_cast<SubDevice *>(this);
}
Device *SubDevice::getParentDevice() const {
return &rootDevice;
}
uint64_t SubDevice::getGlobalMemorySize() const {
auto globalMemorySize = Device::getGlobalMemorySize();
return globalMemorySize / rootDevice.getNumAvailableDevices();

View File

@ -19,6 +19,7 @@ class SubDevice : public Device {
uint32_t getNumAvailableDevices() const override;
uint32_t getRootDeviceIndex() const override;
Device *getDeviceById(uint32_t deviceId) const override;
Device *getParentDevice() const override;
uint32_t getSubDeviceIndex() const;