refactor: Unify GTPin initialization logic between APIs
Add support for new GTPin loading logic in OCL path, similar to existing in L0 - invoking exposed, dedicated API call (OpenGTPinOCL). - Move logic to shared, including unit tests - Check whether instrumentation is required on context creation and if yes, make a call to OpenGTPinOCL function. Handle potential errors gracefully without exiting. Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
parent
c43b827702
commit
1afaf37f78
|
@ -11,12 +11,12 @@
|
|||
#include "shared/source/execution_environment/execution_environment.h"
|
||||
#include "shared/source/os_interface/debug_env_reader.h"
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
#include "shared/source/pin/pin.h"
|
||||
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/core/source/driver/driver_imp.h"
|
||||
#include "level_zero/tools/source/metrics/metric.h"
|
||||
#include "level_zero/tools/source/pin/pin.h"
|
||||
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
@ -81,8 +81,9 @@ void DriverImp::initialize(ze_result_t *result) {
|
|||
}
|
||||
|
||||
if ((*result == ZE_RESULT_SUCCESS) && envVariables.pin) {
|
||||
*result = PinContext::init();
|
||||
if (*result != ZE_RESULT_SUCCESS) {
|
||||
std::string gtpinFuncName{"OpenGTPin"};
|
||||
if (false == NEO::PinContext::init(gtpinFuncName)) {
|
||||
*result = ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
||||
delete GlobalDriver;
|
||||
GlobalDriverHandle = nullptr;
|
||||
GlobalDriver = nullptr;
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pin.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pin.h
|
||||
)
|
||||
|
||||
add_subdirectories()
|
|
@ -1,18 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_pin.h
|
||||
)
|
||||
target_include_directories(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(WIN32)
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_pin.h
|
||||
)
|
||||
target_include_directories(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
endif()
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2022-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/test/common/mocks/mock_os_library.h"
|
||||
|
||||
#include "level_zero/tools/source/pin/pin.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace ult {
|
||||
|
||||
TEST(PinInitializationTest, GivenValidLibraryPinContextInitSucceeds) {
|
||||
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 0; };
|
||||
auto newPtr = new MockOsLibrary(reinterpret_cast<void *>(openPinHandler), false);
|
||||
MockOsLibrary::loadLibraryNewObject = newPtr;
|
||||
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_SUCCESS);
|
||||
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
delete newPtr;
|
||||
}
|
||||
|
||||
TEST(PinInitializationTest, GivenBadLibraryNamePinContextInitFAILS) {
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
|
||||
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
}
|
||||
|
||||
TEST(PinInitializationTest, GivenBadProcAddressPinContextInitFAILS) {
|
||||
auto newPtr = new MockOsLibrary(nullptr, false);
|
||||
MockOsLibrary::loadLibraryNewObject = newPtr;
|
||||
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
|
||||
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
delete newPtr;
|
||||
}
|
||||
|
||||
TEST(PinInitializationTest, GivenBadPinHandlerPinContextInitFAILS) {
|
||||
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 1; };
|
||||
auto newPtr = new MockOsLibrary(reinterpret_cast<void *>(openPinHandler), false);
|
||||
MockOsLibrary::loadLibraryNewObject = newPtr;
|
||||
L0::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
EXPECT_EQ(L0::PinContext::init(), ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE);
|
||||
L0::PinContext::osLibraryLoadFunction = NEO::OsLibrary::load;
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
delete newPtr;
|
||||
}
|
||||
|
||||
} // namespace ult
|
|
@ -400,6 +400,7 @@ cl_context CL_API_CALL clCreateContext(const cl_context_properties *properties,
|
|||
size_t, void *),
|
||||
void *userData,
|
||||
cl_int *errcodeRet) {
|
||||
gtPinTryNotifyInit();
|
||||
TRACING_ENTER(ClCreateContext, &properties, &numDevices, &devices, &funcNotify, &userData, &errcodeRet);
|
||||
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
@ -457,6 +458,7 @@ cl_context CL_API_CALL clCreateContextFromType(const cl_context_properties *prop
|
|||
size_t, void *),
|
||||
void *userData,
|
||||
cl_int *errcodeRet) {
|
||||
gtPinTryNotifyInit();
|
||||
TRACING_ENTER(ClCreateContextFromType, &properties, &deviceType, &funcNotify, &userData, &errcodeRet);
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
API_ENTER(&retVal);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "opencl/source/kernel/kernel.h"
|
||||
#include "opencl/source/kernel/multi_device_kernel.h"
|
||||
#include "opencl/source/mem_obj/buffer.h"
|
||||
#include "opencl/source/platform/platform.h"
|
||||
#include "opencl/source/program/program.h"
|
||||
|
||||
#include "CL/cl.h"
|
||||
|
@ -281,4 +282,12 @@ void gtpinRemoveCommandQueue(void *pCmdQueue) {
|
|||
}
|
||||
}
|
||||
|
||||
void gtPinTryNotifyInit() {
|
||||
if (platformsImpl->empty()) {
|
||||
return;
|
||||
}
|
||||
auto &pPlatform = *(*platformsImpl)[0];
|
||||
pPlatform.tryNotifyGtpinInit();
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2018-2022 Intel Corporation
|
||||
* Copyright (C) 2018-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
|
|
@ -28,4 +28,6 @@ inline bool gtpinIsGTPinInitialized() { return isGTPinInitialized; }
|
|||
void *gtpinGetIgcInit();
|
||||
void gtpinSetIgcInit(void *pIgcInitPtr);
|
||||
void gtpinRemoveCommandQueue(void *pCmdQueue);
|
||||
|
||||
void gtPinTryNotifyInit();
|
||||
} // namespace NEO
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/helpers/get_info.h"
|
||||
#include "shared/source/helpers/hw_info.h"
|
||||
#include "shared/source/os_interface/debug_env_reader.h"
|
||||
#include "shared/source/pin/pin.h"
|
||||
#include "shared/source/source_level_debugger/source_level_debugger.h"
|
||||
|
||||
#include "opencl/source/api/api.h"
|
||||
|
@ -185,6 +187,17 @@ bool Platform::initialize(std::vector<std::unique_ptr<Device>> devices) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Platform::tryNotifyGtpinInit() {
|
||||
auto notifyGTPin = []() {
|
||||
EnvironmentVariableReader envReader;
|
||||
if (envReader.getSetting("ZET_ENABLE_PROGRAM_INSTRUMENTATION", false)) {
|
||||
const std::string gtpinFuncName{"OpenGTPinOCL"};
|
||||
PinContext::init(gtpinFuncName);
|
||||
}
|
||||
};
|
||||
std::call_once(this->oclInitGTPinOnce, notifyGTPin);
|
||||
}
|
||||
|
||||
void Platform::fillGlobalDispatchTable() {
|
||||
sharingFactory.fillGlobalDispatchTable();
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ class Platform : public BaseObject<_cl_platform_id> {
|
|||
|
||||
MOCKABLE_VIRTUAL bool initialize(std::vector<std::unique_ptr<Device>> devices);
|
||||
bool isInitialized();
|
||||
void tryNotifyGtpinInit();
|
||||
|
||||
size_t getNumDevices() const;
|
||||
ClDevice **getClDevices();
|
||||
|
@ -71,6 +72,7 @@ class Platform : public BaseObject<_cl_platform_id> {
|
|||
ClDeviceVector clDevices;
|
||||
ExecutionEnvironment &executionEnvironment;
|
||||
std::once_flag initializeExtensionsWithVersionOnce;
|
||||
std::once_flag oclInitGTPinOnce;
|
||||
};
|
||||
|
||||
extern std::vector<std::unique_ptr<Platform>> *platformsImpl;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "shared/source/memory_manager/surface.h"
|
||||
#include "shared/source/memory_manager/unified_memory_manager.h"
|
||||
#include "shared/source/os_interface/os_context.h"
|
||||
#include "shared/source/pin/pin.h"
|
||||
#include "shared/test/common/device_binary_format/patchtokens_tests.h"
|
||||
#include "shared/test/common/fixtures/memory_management_fixture.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
|
@ -22,8 +23,10 @@
|
|||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/mocks/mock_cpu_page_fault_manager.h"
|
||||
#include "shared/test/common/mocks/mock_device.h"
|
||||
#include "shared/test/common/mocks/mock_io_functions.h"
|
||||
#include "shared/test/common/mocks/mock_memory_manager.h"
|
||||
#include "shared/test/common/mocks/mock_modules_zebin.h"
|
||||
#include "shared/test/common/mocks/mock_os_library.h"
|
||||
#include "shared/test/common/test_macros/hw_test.h"
|
||||
|
||||
#include "opencl/source/api/api.h"
|
||||
|
@ -2503,4 +2506,61 @@ TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenGtpinRemoveCommandQueueIsCa
|
|||
EXPECT_EQ(0u, kernelExecQueue.size());
|
||||
}
|
||||
|
||||
uint32_t gtpinInitTimesCalled = 0u;
|
||||
|
||||
TEST(GTPinInitNotifyTests, givenAvailablePlatformsAndNoEnvironmentVariableSetWhenTryingToNotifyGtpinInitializationThenGtpinDoesNotGetNotified) {
|
||||
platformsImpl->clear();
|
||||
constructPlatform();
|
||||
ASSERT_FALSE(platformsImpl->empty());
|
||||
|
||||
VariableBackup<uint32_t> gtpinCounterBackup(>pinInitTimesCalled, 0u);
|
||||
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { gtpinInitTimesCalled++; return 0; };
|
||||
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
||||
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
||||
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
|
||||
gtPinTryNotifyInit();
|
||||
EXPECT_EQ(0u, gtpinInitTimesCalled);
|
||||
platformsImpl->clear();
|
||||
}
|
||||
|
||||
TEST(GTPinInitNotifyTests, givenNoPlatformsAvailableAndEnvironmentVariableSetWhenTryingToNotifyGtpinInitializationThenGtpinDoesNotGetNotified) {
|
||||
platformsImpl->clear();
|
||||
ASSERT_TRUE(platformsImpl->empty());
|
||||
|
||||
VariableBackup<uint32_t> gtpinCounterBackup(>pinInitTimesCalled, 0u);
|
||||
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
|
||||
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_INSTRUMENTATION", "1"}};
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
|
||||
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { gtpinInitTimesCalled++; return 0; };
|
||||
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
||||
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
||||
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
|
||||
gtPinTryNotifyInit();
|
||||
EXPECT_EQ(0u, gtpinInitTimesCalled);
|
||||
platformsImpl->clear();
|
||||
}
|
||||
|
||||
TEST(GTPinInitNotifyTests, givenAvailablePlatformsAndEnvironmentVariableSetWhenTryingToNotifyGtpinInitializationThenGtpinGetsNotified) {
|
||||
platformsImpl->clear();
|
||||
constructPlatform();
|
||||
ASSERT_FALSE(platformsImpl->empty());
|
||||
|
||||
VariableBackup<uint32_t> gtpinCounterBackup(>pinInitTimesCalled, 0u);
|
||||
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
|
||||
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_INSTRUMENTATION", "1"}};
|
||||
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
|
||||
|
||||
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { gtpinInitTimesCalled++; return 0; };
|
||||
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
||||
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
||||
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
|
||||
gtPinTryNotifyInit();
|
||||
EXPECT_EQ(1u, gtpinInitTimesCalled);
|
||||
platformsImpl->clear();
|
||||
}
|
||||
|
||||
} // namespace ULT
|
||||
|
|
|
@ -143,6 +143,7 @@ append_sources_from_properties(CORE_SOURCES
|
|||
NEO_DEVICE_BINARY_FORMAT
|
||||
NEO_UNIFIED_MEMORY
|
||||
NEO_CORE_RELEASE_HELPER
|
||||
NEO_GTPIN
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
@ -205,4 +206,13 @@ get_property(NEO_SRCS_ENABLE_CORE GLOBAL PROPERTY NEO_SRCS_ENABLE_CORE)
|
|||
target_sources(ocloc_lib PRIVATE ${NEO_SRCS_ENABLE_CORE})
|
||||
if(UNIX)
|
||||
set_property(GLOBAL APPEND PROPERTY NEO_CORE_SRCS_LINK ${CORE_SRCS_LINK_LINUX})
|
||||
target_include_directories(${NEO_SHARED_RELEASE_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/pin/linux)
|
||||
if(NOT NEO_SKIP_UNIT_TESTS)
|
||||
target_include_directories(${NEO_SHARED_MOCKABLE_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/pin/linux)
|
||||
endif()
|
||||
else()
|
||||
target_include_directories(${NEO_SHARED_RELEASE_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/pin/windows)
|
||||
if(NOT NEO_SKIP_UNIT_TESTS)
|
||||
target_include_directories(${NEO_SHARED_MOCKABLE_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/pin/windows)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(NEO_GTPIN
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pin.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pin.h
|
||||
)
|
||||
|
||||
set_property(GLOBAL PROPERTY NEO_GTPIN ${NEO_GTPIN})
|
||||
add_subdirectories()
|
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(UNIX)
|
||||
list(APPEND NEO_GTPIN
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_pin.h
|
||||
)
|
||||
include_directories(${NEO_SHARED_DIRECTORY}/pin/)
|
||||
endif()
|
|
@ -5,14 +5,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/pin/pin.h"
|
||||
|
||||
#include "level_zero/tools/source/pin/pin.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace NEO {
|
||||
|
||||
typedef uint32_t (*OpenGTPin_fn)(void *gtPinInit);
|
||||
|
||||
const std::string PinContext::gtPinLibraryFilename = "libgtpin.so";
|
||||
|
||||
} // namespace L0
|
||||
} // namespace NEO
|
|
@ -9,39 +9,34 @@
|
|||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
|
||||
#include "level_zero/source/inc/ze_intel_gpu.h"
|
||||
|
||||
#include "os_pin.h"
|
||||
|
||||
const std::string gtPinOpenFunctionName = "OpenGTPin";
|
||||
|
||||
namespace L0 {
|
||||
namespace NEO {
|
||||
|
||||
PinContext::OsLibraryLoadPtr PinContext::osLibraryLoadFunction(NEO::OsLibrary::load);
|
||||
|
||||
ze_result_t PinContext::init() {
|
||||
bool PinContext::init(const std::string >PinOpenFunctionName) {
|
||||
NEO::OsLibrary *hGtPinLibrary = nullptr;
|
||||
|
||||
hGtPinLibrary = PinContext::osLibraryLoadFunction(gtPinLibraryFilename.c_str());
|
||||
hGtPinLibrary = PinContext::osLibraryLoadFunction(PinContext::gtPinLibraryFilename.c_str());
|
||||
|
||||
if (hGtPinLibrary == nullptr) {
|
||||
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Unable to find gtpin library %s\n", gtPinLibraryFilename.c_str());
|
||||
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
||||
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Unable to find gtpin library %s\n", PinContext::gtPinLibraryFilename.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
OpenGTPin_fn openGTPin = reinterpret_cast<OpenGTPin_fn>(hGtPinLibrary->getProcAddress(gtPinOpenFunctionName.c_str()));
|
||||
if (openGTPin == nullptr) {
|
||||
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "Unable to find gtpin library open function symbol %s\n", gtPinOpenFunctionName.c_str());
|
||||
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t openResult = openGTPin(nullptr);
|
||||
if (openResult != 0) {
|
||||
PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "gtpin library open %s failed with status %u\n", gtPinOpenFunctionName.c_str(), openResult);
|
||||
return ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE;
|
||||
return false;
|
||||
}
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
} // namespace NEO
|
|
@ -8,14 +8,11 @@
|
|||
#pragma once
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
#include <level_zero/ze_api.h>
|
||||
#include <level_zero/zet_api.h>
|
||||
|
||||
namespace L0 {
|
||||
namespace NEO {
|
||||
|
||||
class PinContext {
|
||||
public:
|
||||
static ze_result_t init();
|
||||
static bool init(const std::string >PinOpenFunctionName);
|
||||
using OsLibraryLoadPtr = std::add_pointer<NEO::OsLibrary *(const std::string &)>::type;
|
||||
static OsLibraryLoadPtr osLibraryLoadFunction;
|
||||
|
||||
|
@ -23,4 +20,4 @@ class PinContext {
|
|||
static const std::string gtPinLibraryFilename;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
} // namespace NEO
|
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# Copyright (C) 2020-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND NEO_GTPIN
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_pin.h
|
||||
)
|
||||
include_directories(${NEO_SHARED_DIRECTORY}/pin/)
|
||||
endif()
|
|
@ -5,14 +5,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/pin/pin.h"
|
||||
|
||||
#include "level_zero/tools/source/pin/pin.h"
|
||||
|
||||
namespace L0 {
|
||||
namespace NEO {
|
||||
|
||||
typedef uint32_t(__fastcall *OpenGTPin_fn)(void *gtPinInit);
|
||||
|
||||
const std::string PinContext::gtPinLibraryFilename = "gtpin.dll";
|
||||
|
||||
} // namespace L0
|
||||
} // namespace NEO
|
|
@ -4,7 +4,7 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
target_sources(neo_shared_tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_pin.cpp
|
||||
)
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (C) 2022-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/pin/pin.h"
|
||||
#include "shared/test/common/mocks/mock_os_library.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace ULT {
|
||||
|
||||
TEST(PinInitializationTest, GivenValidLibraryPinContextInitSucceeds) {
|
||||
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 0; };
|
||||
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
||||
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
||||
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
std::string mockGTPinFunctionName{"aaa"};
|
||||
EXPECT_TRUE(NEO::PinContext::init(mockGTPinFunctionName));
|
||||
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
}
|
||||
|
||||
TEST(PinInitializationTest, GivenBadLibraryNamePinContextInitFAILS) {
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
std::string mockGTPinFunctionName{"aaa"};
|
||||
EXPECT_FALSE(NEO::PinContext::init(mockGTPinFunctionName));
|
||||
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
}
|
||||
|
||||
TEST(PinInitializationTest, GivenBadProcAddressPinContextInitFAILS) {
|
||||
MockOsLibrary mockLibraryObject(nullptr, false);
|
||||
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
||||
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
std::string mockGTPinFunctionName{"aaa"};
|
||||
EXPECT_FALSE(NEO::PinContext::init(mockGTPinFunctionName));
|
||||
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
}
|
||||
|
||||
TEST(PinInitializationTest, GivenBadPinHandlerPinContextInitFAILS) {
|
||||
uint32_t (*openPinHandler)(void *) = [](void *arg) -> uint32_t { return 1; };
|
||||
MockOsLibrary mockLibraryObject(reinterpret_cast<void *>(openPinHandler), false);
|
||||
MockOsLibrary::loadLibraryNewObject = &mockLibraryObject;
|
||||
NEO::PinContext::osLibraryLoadFunction = MockOsLibrary::load;
|
||||
std::string mockGTPinFunctionName{"aaa"};
|
||||
EXPECT_FALSE(NEO::PinContext::init(mockGTPinFunctionName));
|
||||
|
||||
MockOsLibrary::loadLibraryNewObject = nullptr;
|
||||
}
|
||||
|
||||
} // namespace ULT
|
Loading…
Reference in New Issue