mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Update sub device internal ref counts
Change-Id: I82eea99bbb3d1edc32d09c0b703dee30b62f6b76 Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
6d4832fe24
commit
f2c11eb870
@ -69,6 +69,23 @@ ClDevice::~ClDevice() {
|
||||
device.decRefInternal();
|
||||
}
|
||||
|
||||
void ClDevice::incRefInternal() {
|
||||
if (deviceInfo.parentDevice == nullptr) {
|
||||
BaseObject<_cl_device_id>::incRefInternal();
|
||||
return;
|
||||
}
|
||||
auto pParentDevice = static_cast<ClDevice *>(deviceInfo.parentDevice);
|
||||
pParentDevice->incRefInternal();
|
||||
}
|
||||
|
||||
unique_ptr_if_unused<ClDevice> ClDevice::decRefInternal() {
|
||||
if (deviceInfo.parentDevice == nullptr) {
|
||||
return BaseObject<_cl_device_id>::decRefInternal();
|
||||
}
|
||||
auto pParentDevice = static_cast<ClDevice *>(deviceInfo.parentDevice);
|
||||
return pParentDevice->decRefInternal();
|
||||
}
|
||||
|
||||
void ClDevice::allocateSyncBufferHandler() {
|
||||
TakeOwnershipWrapper<ClDevice> lock(*this);
|
||||
if (syncBufferHandler.get() == nullptr) {
|
||||
|
@ -51,6 +51,9 @@ class ClDevice : public BaseObject<_cl_device_id> {
|
||||
explicit ClDevice(Device &device, Platform *platformId);
|
||||
~ClDevice() override;
|
||||
|
||||
void incRefInternal();
|
||||
unique_ptr_if_unused<ClDevice> decRefInternal();
|
||||
|
||||
unsigned int getEnabledClVersion() const { return enabledClVersion; };
|
||||
unsigned int getSupportedClVersion() const;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "shared/source/program/sync_buffer_handler.h"
|
||||
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
|
||||
|
||||
#include "opencl/source/api/api.h"
|
||||
#include "opencl/test/unit_test/fixtures/enqueue_handler_fixture.h"
|
||||
@ -171,17 +172,20 @@ TEST(SyncBufferHandlerDeviceTest, GivenRootDeviceWhenAllocateSyncBufferIsCalledT
|
||||
}
|
||||
|
||||
TEST(SyncBufferHandlerDeviceTest, GivenSubDeviceWhenAllocateSyncBufferIsCalledTwiceThenTheObjectIsCreatedOnlyOnce) {
|
||||
const size_t testUsedBufferSize = 100;
|
||||
MockClDevice rootDevice{new MockDevice};
|
||||
ClDevice subDevice{*rootDevice.createSubDevice(0), platform()};
|
||||
subDevice.allocateSyncBufferHandler();
|
||||
auto syncBufferHandler = reinterpret_cast<MockSyncBufferHandler *>(subDevice.syncBufferHandler.get());
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
||||
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
|
||||
auto rootDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
|
||||
auto &subDevice = rootDevice->subDevices[0];
|
||||
subDevice->allocateSyncBufferHandler();
|
||||
auto syncBufferHandler = reinterpret_cast<MockSyncBufferHandler *>(subDevice->syncBufferHandler.get());
|
||||
|
||||
const size_t testUsedBufferSize = 100;
|
||||
ASSERT_NE(syncBufferHandler->usedBufferSize, testUsedBufferSize);
|
||||
syncBufferHandler->usedBufferSize = testUsedBufferSize;
|
||||
|
||||
subDevice.allocateSyncBufferHandler();
|
||||
syncBufferHandler = reinterpret_cast<MockSyncBufferHandler *>(subDevice.syncBufferHandler.get());
|
||||
subDevice->allocateSyncBufferHandler();
|
||||
syncBufferHandler = reinterpret_cast<MockSyncBufferHandler *>(subDevice->syncBufferHandler.get());
|
||||
|
||||
EXPECT_EQ(testUsedBufferSize, syncBufferHandler->usedBufferSize);
|
||||
}
|
||||
|
@ -10,9 +10,9 @@
|
||||
#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/mock_device.h"
|
||||
|
||||
#include "opencl/source/cl_device/cl_device.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
#include "opencl/test/unit_test/mocks/mock_platform.h"
|
||||
|
||||
@ -54,7 +54,7 @@ TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThe
|
||||
EXPECT_EQ(1u, device->subdevices.at(1)->getNumAvailableDevices());
|
||||
}
|
||||
|
||||
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceRefcountsAreChangedThenChangeIsPropagatedToRootDevice) {
|
||||
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceApiRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
||||
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
|
||||
@ -89,6 +89,62 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceRefcountsAreChangedTh
|
||||
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
|
||||
}
|
||||
|
||||
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
||||
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
|
||||
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
|
||||
device->incRefInternal();
|
||||
auto subDevice = device->getDeviceById(0);
|
||||
|
||||
auto baseDeviceInternalRefCount = device->getRefInternalCount();
|
||||
auto baseSubDeviceInternalRefCount = subDevice->getRefInternalCount();
|
||||
|
||||
subDevice->incRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount + 1, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
|
||||
device->incRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount + 2, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
|
||||
subDevice->decRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount + 1, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
|
||||
device->decRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
}
|
||||
|
||||
TEST(SubDevicesTest, givenClDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(2);
|
||||
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
|
||||
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
|
||||
device->incRefInternal();
|
||||
auto &subDevice = device->subDevices[0];
|
||||
|
||||
auto baseDeviceInternalRefCount = device->getRefInternalCount();
|
||||
auto baseSubDeviceInternalRefCount = subDevice->getRefInternalCount();
|
||||
|
||||
subDevice->incRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount + 1, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
|
||||
device->incRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount + 2, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
|
||||
subDevice->decRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount + 1, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
|
||||
device->decRefInternal();
|
||||
EXPECT_EQ(baseDeviceInternalRefCount, device->getRefInternalCount());
|
||||
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
|
||||
}
|
||||
|
||||
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceCreationFailThenWholeDeviceIsDestroyed) {
|
||||
DebugManagerStateRestore restorer;
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(10);
|
||||
|
Reference in New Issue
Block a user