mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
Revert "refactor: Unify GTPin initialization logic between APIs"
This reverts commit 68a5108e05.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
68a5108e05
commit
65df34bbc7
14
level_zero/tools/source/pin/CMakeLists.txt
Normal file
14
level_zero/tools/source/pin/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# 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()
|
||||
18
level_zero/tools/source/pin/linux/CMakeLists.txt
Normal file
18
level_zero/tools/source/pin/linux/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# 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()
|
||||
|
||||
18
level_zero/tools/source/pin/linux/os_pin.h
Normal file
18
level_zero/tools/source/pin/linux/os_pin.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "level_zero/tools/source/pin/pin.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
typedef uint32_t (*OpenGTPin_fn)(void *gtPinInit);
|
||||
|
||||
const std::string PinContext::gtPinLibraryFilename = "libgtpin.so";
|
||||
|
||||
} // namespace L0
|
||||
47
level_zero/tools/source/pin/pin.cpp
Normal file
47
level_zero/tools/source/pin/pin.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pin.h"
|
||||
|
||||
#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 {
|
||||
|
||||
PinContext::OsLibraryLoadPtr PinContext::osLibraryLoadFunction(NEO::OsLibrary::load);
|
||||
|
||||
ze_result_t PinContext::init() {
|
||||
NEO::OsLibrary *hGtPinLibrary = nullptr;
|
||||
|
||||
hGtPinLibrary = PinContext::osLibraryLoadFunction(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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
26
level_zero/tools/source/pin/pin.h
Normal file
26
level_zero/tools/source/pin/pin.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
#include <level_zero/ze_api.h>
|
||||
#include <level_zero/zet_api.h>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class PinContext {
|
||||
public:
|
||||
static ze_result_t init();
|
||||
using OsLibraryLoadPtr = std::add_pointer<NEO::OsLibrary *(const std::string &)>::type;
|
||||
static OsLibraryLoadPtr osLibraryLoadFunction;
|
||||
|
||||
private:
|
||||
static const std::string gtPinLibraryFilename;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
17
level_zero/tools/source/pin/windows/CMakeLists.txt
Normal file
17
level_zero/tools/source/pin/windows/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# 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()
|
||||
18
level_zero/tools/source/pin/windows/os_pin.h
Normal file
18
level_zero/tools/source/pin/windows/os_pin.h
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "level_zero/tools/source/pin/pin.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
typedef uint32_t(__fastcall *OpenGTPin_fn)(void *gtPinInit);
|
||||
|
||||
const std::string PinContext::gtPinLibraryFilename = "gtpin.dll";
|
||||
|
||||
} // namespace L0
|
||||
10
level_zero/tools/test/unit_tests/sources/pin/CMakeLists.txt
Normal file
10
level_zero/tools/test/unit_tests/sources/pin/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (C) 2022-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_pin.cpp
|
||||
)
|
||||
56
level_zero/tools/test/unit_tests/sources/pin/test_pin.cpp
Normal file
56
level_zero/tools/test/unit_tests/sources/pin/test_pin.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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
|
||||
Reference in New Issue
Block a user