mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Add method for getting number of available devices
Related-To: NEO-3691 Change-Id: Ida2454adbfc9b177acbbb320f3f9577849a6fd74 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
05c8f40677
commit
ea64a3fbc3
@ -97,6 +97,7 @@ class Device : public BaseObject<_cl_device_id> {
|
||||
bool areSharedSystemAllocationsAllowed() const {
|
||||
return this->deviceInfo.sharedSystemMemCapabilities != 0u;
|
||||
}
|
||||
virtual uint32_t getNumAvailableDevices() const = 0;
|
||||
|
||||
protected:
|
||||
Device() = delete;
|
||||
|
@ -18,6 +18,13 @@ uint32_t RootDevice::getNumSubDevices() const {
|
||||
return static_cast<uint32_t>(subdevices.size());
|
||||
}
|
||||
|
||||
uint32_t RootDevice::getNumAvailableDevices() const {
|
||||
if (subdevices.empty()) {
|
||||
return 1u;
|
||||
}
|
||||
return getNumSubDevices();
|
||||
}
|
||||
|
||||
RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : Device(executionEnvironment, deviceIndex) {}
|
||||
bool RootDevice::createDeviceImpl() {
|
||||
auto status = Device::createDeviceImpl();
|
||||
|
@ -17,6 +17,7 @@ class RootDevice : public Device {
|
||||
RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex);
|
||||
~RootDevice() override;
|
||||
bool createDeviceImpl() override;
|
||||
uint32_t getNumAvailableDevices() const override;
|
||||
uint32_t getNumSubDevices() const;
|
||||
|
||||
/* We hide the retain and release function of BaseObject. */
|
||||
|
@ -32,5 +32,8 @@ DeviceBitfield SubDevice::getDeviceBitfieldForOsContext() const {
|
||||
deviceBitfield.set(subDeviceIndex);
|
||||
return deviceBitfield;
|
||||
}
|
||||
uint32_t SubDevice::getNumAvailableDevices() const {
|
||||
return 1u;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
@ -17,6 +17,7 @@ class SubDevice : public Device {
|
||||
unique_ptr_if_unused<Device> release() override;
|
||||
void retainInternal();
|
||||
void releaseInternal();
|
||||
uint32_t getNumAvailableDevices() const override;
|
||||
|
||||
protected:
|
||||
DeviceBitfield getDeviceBitfieldForOsContext() const override;
|
||||
|
@ -19,6 +19,7 @@ TEST(SubDevicesTest, givenDefaultConfigWhenCreateRootDeviceThenItDoesntContainSu
|
||||
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(*platformDevices));
|
||||
|
||||
EXPECT_EQ(0u, device->getNumSubDevices());
|
||||
EXPECT_EQ(1u, device->getNumAvailableDevices());
|
||||
}
|
||||
|
||||
TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThenItContainsSubDevices) {
|
||||
@ -31,6 +32,10 @@ TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThe
|
||||
EXPECT_EQ(0u, device->getDeviceIndex());
|
||||
EXPECT_EQ(1u, device->subdevices.at(0)->getDeviceIndex());
|
||||
EXPECT_EQ(2u, device->subdevices.at(1)->getDeviceIndex());
|
||||
|
||||
EXPECT_EQ(2u, device->getNumAvailableDevices());
|
||||
EXPECT_EQ(1u, device->subdevices.at(0)->getNumAvailableDevices());
|
||||
EXPECT_EQ(1u, device->subdevices.at(1)->getNumAvailableDevices());
|
||||
}
|
||||
|
||||
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceRefcountsAreChangedThenChangeIsPropagatedToRootDevice) {
|
||||
|
Reference in New Issue
Block a user