2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2024-06-19 17:51:16 +08:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sharing.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/mem_obj/mem_obj.h"
|
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "CL/cl.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-07-04 16:41:58 +08:00
|
|
|
|
2020-05-25 21:41:13 +08:00
|
|
|
int SharingHandler::acquire(MemObj *memObj, uint32_t rootDeviceIndex) {
|
2017-12-21 07:45:38 +08:00
|
|
|
if (acquireCount == 0) {
|
2020-05-25 21:41:13 +08:00
|
|
|
UpdateData updateData{rootDeviceIndex};
|
2020-06-02 19:38:13 +08:00
|
|
|
auto graphicsAllocation = memObj->getGraphicsAllocation(rootDeviceIndex);
|
|
|
|
auto currentSharedHandle = graphicsAllocation->peekSharedHandle();
|
2017-12-21 07:45:38 +08:00
|
|
|
updateData.sharedHandle = currentSharedHandle;
|
|
|
|
updateData.memObject = memObj;
|
2018-08-14 15:48:20 +08:00
|
|
|
int result = synchronizeHandler(updateData);
|
2018-07-04 16:41:58 +08:00
|
|
|
resolveGraphicsAllocationChange(currentSharedHandle, &updateData);
|
2018-04-19 20:11:45 +08:00
|
|
|
if (result != CL_SUCCESS) {
|
|
|
|
return result;
|
|
|
|
}
|
2018-07-04 16:41:58 +08:00
|
|
|
if (updateData.synchronizationStatus != SynchronizeStatus::ACQUIRE_SUCCESFUL) {
|
|
|
|
return CL_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2024-06-19 17:51:16 +08:00
|
|
|
DEBUG_BREAK_IF(memObj->getGraphicsAllocation(rootDeviceIndex)->peekSharedHandle() != updateData.sharedHandle);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
acquireCount++;
|
2018-04-19 20:11:45 +08:00
|
|
|
return CL_SUCCESS;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-08-14 15:48:20 +08:00
|
|
|
int SharingHandler::synchronizeHandler(UpdateData &updateData) {
|
2018-04-19 20:11:45 +08:00
|
|
|
auto result = validateUpdateData(updateData);
|
|
|
|
if (result == CL_SUCCESS) {
|
|
|
|
synchronizeObject(updateData);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-08-14 15:48:20 +08:00
|
|
|
int SharingHandler::validateUpdateData(UpdateData &updateData) {
|
2018-04-19 20:11:45 +08:00
|
|
|
return CL_SUCCESS;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-07-04 16:41:58 +08:00
|
|
|
void SharingHandler::resolveGraphicsAllocationChange(osHandle currentSharedHandle, UpdateData *updateData) {
|
|
|
|
}
|
|
|
|
|
2020-05-18 20:21:14 +08:00
|
|
|
void SharingHandler::release(MemObj *memObject, uint32_t rootDeviceIndex) {
|
2017-12-21 07:45:38 +08:00
|
|
|
DEBUG_BREAK_IF(acquireCount <= 0);
|
|
|
|
acquireCount--;
|
|
|
|
if (acquireCount == 0) {
|
2020-05-18 20:21:14 +08:00
|
|
|
releaseResource(memObject, rootDeviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|