mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
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:
committed by
Compute-Runtime-Automation
parent
c43b827702
commit
1afaf37f78
@@ -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()
|
||||
|
||||
14
shared/source/pin/CMakeLists.txt
Normal file
14
shared/source/pin/CMakeLists.txt
Normal file
@@ -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()
|
||||
13
shared/source/pin/linux/CMakeLists.txt
Normal file
13
shared/source/pin/linux/CMakeLists.txt
Normal file
@@ -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()
|
||||
15
shared/source/pin/linux/os_pin.h
Normal file
15
shared/source/pin/linux/os_pin.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/pin/pin.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
typedef uint32_t (*OpenGTPin_fn)(void *gtPinInit);
|
||||
const std::string PinContext::gtPinLibraryFilename = "libgtpin.so";
|
||||
|
||||
} // namespace NEO
|
||||
42
shared/source/pin/pin.cpp
Normal file
42
shared/source/pin/pin.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pin.h"
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
|
||||
#include "os_pin.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
PinContext::OsLibraryLoadPtr PinContext::osLibraryLoadFunction(NEO::OsLibrary::load);
|
||||
|
||||
bool PinContext::init(const std::string >PinOpenFunctionName) {
|
||||
NEO::OsLibrary *hGtPinLibrary = nullptr;
|
||||
|
||||
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", 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 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 false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
23
shared/source/pin/pin.h
Normal file
23
shared/source/pin/pin.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class PinContext {
|
||||
public:
|
||||
static bool init(const std::string >PinOpenFunctionName);
|
||||
using OsLibraryLoadPtr = std::add_pointer<NEO::OsLibrary *(const std::string &)>::type;
|
||||
static OsLibraryLoadPtr osLibraryLoadFunction;
|
||||
|
||||
private:
|
||||
static const std::string gtPinLibraryFilename;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
13
shared/source/pin/windows/CMakeLists.txt
Normal file
13
shared/source/pin/windows/CMakeLists.txt
Normal file
@@ -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()
|
||||
15
shared/source/pin/windows/os_pin.h
Normal file
15
shared/source/pin/windows/os_pin.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/pin/pin.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
typedef uint32_t(__fastcall *OpenGTPin_fn)(void *gtPinInit);
|
||||
const std::string PinContext::gtPinLibraryFilename = "gtpin.dll";
|
||||
|
||||
} // namespace NEO
|
||||
10
shared/test/unit_test/pin/CMakeLists.txt
Normal file
10
shared/test/unit_test/pin/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Copyright (C) 2022-2023 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
target_sources(neo_shared_tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_pin.cpp
|
||||
)
|
||||
56
shared/test/unit_test/pin/test_pin.cpp
Normal file
56
shared/test/unit_test/pin/test_pin.cpp
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user