feature: Add External Semaphore experimental [3/N]

Related-To: NEO-11488

Signed-off-by: Raiyan Latif <raiyan.latif@intel.com>
This commit is contained in:
Raiyan Latif
2024-12-05 17:30:07 +00:00
committed by Compute-Runtime-Automation
parent 263d84f0ed
commit 06c94d47f9
28 changed files with 763 additions and 15 deletions

View File

@@ -129,6 +129,7 @@ append_sources_from_properties(CORE_SOURCES
NEO_CORE_OS_INTERFACE
NEO_CORE_PAGE_FAULT_MANAGER
NEO_CORE_PROGRAM
NEO_CORE_SEMAPHORE
NEO_CORE_SKU_INFO_BASE
NEO_CORE_SRCS_BUILT_INS
NEO_CORE_SRCS_BUILT_INS_OPS

View File

@@ -8,6 +8,7 @@ set(NEO_CORE_GLOBAL_FACTORIES
${CMAKE_CURRENT_SOURCE_DIR}/create_os_context_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/create_os_time_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/discover_devices_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/external_semaphore_helper_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/init_os_interface_${DRIVER_MODEL}.cpp
)
@@ -22,6 +23,7 @@ set(NEO_CORE_OS_INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/device_factory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_factory.h
${CMAKE_CURRENT_SOURCE_DIR}/driver_info.h
${CMAKE_CURRENT_SOURCE_DIR}/external_semaphore_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/product_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/product_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/product_helper.inl

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/device/device.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/driver_model_type.h"
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/helpers/topology_map.h"
#include "shared/source/os_interface/os_interface.h"
#include <limits>
#include <memory>
#include <string>
namespace NEO {
class ExternalSemaphoreHelper {
public:
enum Type {
OpaqueFd,
OpaqueWin32,
OpaqueWin32Kmt,
D3d12Fence,
D3d11Fence,
KeyedMutex,
KeyedMutexKmt,
TimelineSemaphoreFd,
TimelineSemaphoreWin32
};
static std::unique_ptr<ExternalSemaphoreHelper> create(OSInterface *osInterface);
virtual ~ExternalSemaphoreHelper() = default;
virtual bool importSemaphore(void *extHandle, int fd, uint32_t flags, const char *name, NEO::ExternalSemaphoreHelper::Type type, bool isNative, void *syncHandle) = 0;
virtual bool semaphoreWait(const CommandStreamReceiver *csr, void *syncHandle) = 0;
virtual bool semaphoreSignal(const CommandStreamReceiver *csr, void *syncHandle) = 0;
virtual bool isSupported(ExternalSemaphoreHelper::Type type) = 0;
Type getType() { return type; }
OSInterface *osInterface = nullptr;
private:
Type type;
};
} // namespace NEO

View File

@@ -0,0 +1,20 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/external_semaphore_helper.h"
#include <limits>
#include <memory>
#include <string>
namespace NEO {
std::unique_ptr<ExternalSemaphoreHelper> ExternalSemaphoreHelper::create(OSInterface *osInterface) {
return nullptr;
}
} // namespace NEO

View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/external_semaphore_helper.h"
#include "shared/source/os_interface/windows/external_semaphore_helper_windows.h"
#include <limits>
#include <memory>
#include <string>
namespace NEO {
std::unique_ptr<ExternalSemaphoreHelper> ExternalSemaphoreHelper::create(OSInterface *osInterface) {
if (osInterface) {
if (osInterface->getDriverModel()->getDriverModelType() == DriverModelType::wddm) {
return ExternalSemaphoreHelperWindows::create(osInterface);
}
}
return nullptr;
}
} // namespace NEO

View File

@@ -0,0 +1,21 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/external_semaphore_helper.h"
#include "shared/source/os_interface/windows/external_semaphore_helper_windows.h"
#include <limits>
#include <memory>
#include <string>
namespace NEO {
std::unique_ptr<ExternalSemaphoreHelper> ExternalSemaphoreHelper::create(OSInterface *osInterface) {
return ExternalSemaphoreHelperWindows::create(osInterface);
}
} // namespace NEO

View File

@@ -64,6 +64,8 @@ set(NEO_CORE_OS_INTERFACE_WDDM
${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_time_wddm.h
${CMAKE_CURRENT_SOURCE_DIR}/driver_info_windows.h
${CMAKE_CURRENT_SOURCE_DIR}/external_semaphore_helper_windows.cpp
${CMAKE_CURRENT_SOURCE_DIR}/external_semaphore_helper_windows.h
${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface.h
${CMAKE_CURRENT_SOURCE_DIR}/gdi_interface_logging.cpp

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/windows/external_semaphore_helper_windows.h"
#include "shared/source/os_interface/os_library.h"
#include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
#include "shared/source/os_interface/windows/gdi_interface.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
#include <memory>
namespace NEO {
std::unique_ptr<ExternalSemaphoreHelperWindows> ExternalSemaphoreHelperWindows::create(OSInterface *osInterface) {
auto extSemHelperWindows = std::make_unique<ExternalSemaphoreHelperWindows>();
extSemHelperWindows->osInterface = osInterface;
return extSemHelperWindows;
}
bool ExternalSemaphoreHelperWindows::importSemaphore(void *extHandle, int fd, uint32_t flags, const char *name, ExternalSemaphoreHelper::Type type, bool isNative, void *syncHandle) {
switch (type) {
case ExternalSemaphoreHelper::D3d12Fence:
case ExternalSemaphoreHelper::OpaqueWin32:
break;
default:
return false;
}
HANDLE syncNtHandle = nullptr;
auto wddm = this->osInterface->getDriverModel()->as<Wddm>();
syncNtHandle = reinterpret_cast<HANDLE>(extHandle);
D3DKMT_OPENSYNCOBJECTFROMNTHANDLE2 open = {};
open.hNtHandle = syncNtHandle;
open.hDevice = wddm->getDeviceHandle();
open.Flags.NoGPUAccess = (type == ExternalSemaphoreHelper::D3d12Fence);
auto status = wddm->getGdi()->openSyncObjectFromNtHandle2(&open);
if (status != STATUS_SUCCESS) {
return false;
}
return true;
}
bool ExternalSemaphoreHelperWindows::semaphoreWait(const CommandStreamReceiver *csr, void *syncHandle) {
return false;
}
bool ExternalSemaphoreHelperWindows::semaphoreSignal(const CommandStreamReceiver *csr, void *syncHandle) {
return false;
}
bool ExternalSemaphoreHelperWindows::isSupported(ExternalSemaphoreHelper::Type type) {
switch (type) {
case ExternalSemaphoreHelper::OpaqueWin32:
case ExternalSemaphoreHelper::D3d12Fence:
return true;
default:
return false;
}
}
} // namespace NEO

View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/device/device.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/helpers/topology_map.h"
#include "shared/source/os_interface/external_semaphore_helper.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/semaphore/external_semaphore.h"
#include <limits>
#include <memory>
#include <string>
namespace NEO {
class ExternalSemaphoreHelperWindows : public ExternalSemaphoreHelper {
public:
static std::unique_ptr<ExternalSemaphoreHelperWindows> create(OSInterface *osInterface);
~ExternalSemaphoreHelperWindows() override{};
bool importSemaphore(void *extHandle, int fd, uint32_t flags, const char *name, ExternalSemaphoreHelper::Type type, bool isNative, void *syncHandle) override;
bool semaphoreWait(const CommandStreamReceiver *csr, void *syncHandle) override;
bool semaphoreSignal(const CommandStreamReceiver *csr, void *syncHandle) override;
bool isSupported(ExternalSemaphoreHelper::Type type) override;
};
} // namespace NEO

View File

@@ -65,6 +65,7 @@ bool Gdi::getAllProcAddresses() {
signalSynchronizationObjectFromCpu = gdiDll->getProcAddress("D3DKMTSignalSynchronizationObjectFromCpu");
waitForSynchronizationObjectFromGpu = gdiDll->getProcAddress("D3DKMTWaitForSynchronizationObjectFromGpu");
signalSynchronizationObjectFromGpu = gdiDll->getProcAddress("D3DKMTSignalSynchronizationObjectFromGpu");
openSyncObjectFromNtHandle2 = gdiDll->getProcAddress("D3DKMTOpenSyncObjectFromNtHandle2");
createPagingQueue = gdiDll->getProcAddress("D3DKMTCreatePagingQueue");
destroyPagingQueue = gdiDll->getProcAddress("D3DKMTDestroyPagingQueue");
lock2 = gdiDll->getProcAddress("D3DKMTLock2");

View File

@@ -52,6 +52,7 @@ class Gdi {
DEFINE_THK_WRAPPER(IN CONST D3DKMT_SIGNALSYNCHRONIZATIONOBJECTFROMCPU *, signalSynchronizationObjectFromCpu);
DEFINE_THK_WRAPPER(IN CONST D3DKMT_WAITFORSYNCHRONIZATIONOBJECTFROMGPU *, waitForSynchronizationObjectFromGpu);
DEFINE_THK_WRAPPER(IN CONST D3DKMT_SIGNALSYNCHRONIZATIONOBJECTFROMGPU *, signalSynchronizationObjectFromGpu);
DEFINE_THK_WRAPPER(IN OUT D3DKMT_OPENSYNCOBJECTFROMNTHANDLE2 *, openSyncObjectFromNtHandle2);
DEFINE_THK_WRAPPER(IN OUT D3DKMT_CREATEPAGINGQUEUE *, createPagingQueue);
DEFINE_THK_WRAPPER(IN OUT D3DDDI_DESTROYPAGINGQUEUE *, destroyPagingQueue);
DEFINE_THK_WRAPPER(IN OUT D3DKMT_LOCK2 *, lock2);

View File

@@ -0,0 +1,14 @@
#
# Copyright (C) 2024 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(NEO_CORE_SEMAPHORE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/external_semaphore.h
${CMAKE_CURRENT_SOURCE_DIR}/external_semaphore.cpp
)
set_property(GLOBAL PROPERTY NEO_CORE_SEMAPHORE ${NEO_CORE_SEMAPHORE})
add_subdirectories()

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/semaphore/external_semaphore.h"
#include "shared/source/device/device.h"
#include "shared/source/os_interface/external_semaphore_helper.h"
namespace NEO {
std::unique_ptr<ExternalSemaphore> ExternalSemaphore::create(OSInterface *osInterface, ExternalSemaphoreHelper::Type type, void *handle, int fd) {
auto extSemaphore = std::make_unique<ExternalSemaphore>();
extSemaphore->externalSemaphoreHelper = ExternalSemaphoreHelper::create(osInterface);
if (extSemaphore->externalSemaphoreHelper == nullptr) {
return nullptr;
}
bool result = extSemaphore->externalSemaphoreHelper->importSemaphore(handle, fd, 0, nullptr, type, false, extSemaphore->getHandle());
if (result == false) {
return nullptr;
}
return extSemaphore;
}
bool ExternalSemaphore::enqueueWait(CommandStreamReceiver *csr) {
return false;
}
bool ExternalSemaphore::enqueueSignal(CommandStreamReceiver *csr) {
return false;
}
} // namespace NEO

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/command_stream/queue_throttle.h"
#include "shared/source/command_stream/task_count_helper.h"
#include "shared/source/os_interface/external_semaphore_helper.h"
#include "shared/source/os_interface/os_interface.h"
#include <array>
#include <atomic>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <queue>
#include <unordered_map>
namespace NEO {
class CommandStreamReceiver;
class Thread;
class ExternalSemaphore {
public:
static std::unique_ptr<ExternalSemaphore> create(OSInterface *osInterface, ExternalSemaphoreHelper::Type type, void *handle, int fd);
void *getHandle() { return syncHandle; }
bool enqueueWait(CommandStreamReceiver *csr);
bool enqueueSignal(CommandStreamReceiver *csr);
protected:
void *syncHandle;
std::unique_ptr<ExternalSemaphoreHelper> externalSemaphoreHelper;
};
} // namespace NEO