Skip to content

Commit b0e3d86

Browse files
refactor: Add OV detection mechanism for ULLS light
Related-To: NEO-13922 Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent b60c02d commit b0e3d86

File tree

10 files changed

+111
-4
lines changed

10 files changed

+111
-4
lines changed

shared/source/os_interface/linux/os_context_linux.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
#include "shared/source/helpers/ptr_math.h"
1616
#include "shared/source/os_interface/linux/drm_neo.h"
1717
#include "shared/source/os_interface/linux/ioctl_helper.h"
18+
#include "shared/source/os_interface/linux/os_library_linux.h"
1819
#include "shared/source/os_interface/os_context.h"
1920
#include "shared/source/os_interface/os_interface.h"
2021
#include "shared/source/os_interface/product_helper.h"
2122
#include "shared/source/os_interface/sys_calls_common.h"
23+
#include "shared/source/release_helper/release_helper.h"
2224

2325
namespace NEO {
2426

@@ -34,6 +36,7 @@ OsContextLinux::OsContextLinux(Drm &drm, uint32_t rootDeviceIndex, uint32_t cont
3436
drm(drm) {
3537
pagingFence.fill(0u);
3638
fenceVal.fill(0u);
39+
this->isOpenVinoLoaded();
3740
}
3841

3942
bool OsContextLinux::initializeContext(bool allocateInterrupt) {
@@ -88,11 +91,18 @@ bool OsContextLinux::initializeContext(bool allocateInterrupt) {
8891
return true;
8992
}
9093

94+
void OsContextLinux::isOpenVinoLoaded() {
95+
std::call_once(this->ovLoadedFlag, [this]() {
96+
this->ovLoaded = NEO::Linux::isLibraryLoaded("libopenvino_intel_gpu_plugin.so");
97+
});
98+
}
99+
91100
bool OsContextLinux::isDirectSubmissionSupported() const {
92101
auto &rootDeviceEnvironment = this->getDrm().getRootDeviceEnvironment();
93102
auto &productHelper = rootDeviceEnvironment.getHelper<ProductHelper>();
103+
const auto releaseHelper = rootDeviceEnvironment.getReleaseHelper();
94104

95-
return this->getDrm().isVmBindAvailable() && productHelper.isDirectSubmissionSupported(rootDeviceEnvironment.getReleaseHelper());
105+
return (this->getDrm().isVmBindAvailable() || (this->ovLoaded && releaseHelper && releaseHelper->isDirectSubmissionLightSupported())) && productHelper.isDirectSubmissionSupported(rootDeviceEnvironment.getReleaseHelper());
96106
}
97107

98108
Drm &OsContextLinux::getDrm() const {

shared/source/os_interface/linux/os_context_linux.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class OsContextLinux : public OsContext {
5050

5151
protected:
5252
bool initializeContext(bool allocateInterrupt) override;
53+
void isOpenVinoLoaded();
5354

5455
unsigned int engineFlag = 0;
5556
std::vector<uint32_t> drmContextIds;
@@ -58,7 +59,9 @@ class OsContextLinux : public OsContext {
5859
std::array<uint64_t, EngineLimits::maxHandleCount> pagingFence;
5960
std::array<uint64_t, EngineLimits::maxHandleCount> fenceVal;
6061

62+
std::once_flag ovLoadedFlag{};
6163
Drm &drm;
6264
bool contextHangDetected = false;
65+
bool ovLoaded = false;
6366
};
6467
} // namespace NEO

shared/source/os_interface/linux/os_library_linux.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 Intel Corporation
2+
* Copyright (C) 2019-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -10,6 +10,7 @@
1010
#include "shared/source/helpers/debug_helpers.h"
1111
#include "shared/source/os_interface/linux/sys_calls.h"
1212

13+
#include <cstring>
1314
#include <dlfcn.h>
1415
#include <link.h>
1516

@@ -81,5 +82,22 @@ std::string OsLibrary::getFullPath() {
8182
}
8283
return std::string();
8384
}
85+
86+
bool isLibraryLoaded(const std::string &libraryName) {
87+
auto handle = SysCalls::dlopen(0, RTLD_LAZY);
88+
struct link_map *map = nullptr;
89+
int retVal = NEO::SysCalls::dlinfo(handle, RTLD_DI_LINKMAP, &map);
90+
if (retVal == 0 && map != nullptr) {
91+
while (map) {
92+
if (strstr(map->l_name, libraryName.c_str())) {
93+
dlclose(handle);
94+
return true;
95+
}
96+
map = map->l_next;
97+
}
98+
}
99+
dlclose(handle);
100+
return false;
101+
}
84102
} // namespace Linux
85103
} // namespace NEO

shared/source/os_interface/linux/os_library_linux.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 Intel Corporation
2+
* Copyright (C) 2019-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -25,5 +25,8 @@ class OsLibrary : public NEO::OsLibrary {
2525
void *getProcAddress(const std::string &procName) override;
2626
std::string getFullPath() override;
2727
};
28+
29+
bool isLibraryLoaded(const std::string &libraryName);
30+
2831
} // namespace Linux
2932
} // namespace NEO

shared/source/release_helper/release_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ReleaseHelper {
5959
virtual uint32_t getStackSizePerRay() const = 0;
6060
virtual bool isLocalOnlyAllowed() const = 0;
6161
virtual bool isDummyBlitWaRequired() const = 0;
62+
virtual bool isDirectSubmissionLightSupported() const = 0;
6263
virtual const SizeToPreferredSlmValueArray &getSizeToPreferredSlmValue(bool isHeapless) const = 0;
6364
virtual bool isNumRtStacksPerDssFixedValue() const = 0;
6465
virtual bool getFtrXe2Compression() const = 0;
@@ -100,6 +101,7 @@ class ReleaseHelperHw : public ReleaseHelper {
100101
uint32_t getStackSizePerRay() const override;
101102
bool isLocalOnlyAllowed() const override;
102103
bool isDummyBlitWaRequired() const override;
104+
bool isDirectSubmissionLightSupported() const override;
103105
const SizeToPreferredSlmValueArray &getSizeToPreferredSlmValue(bool isHeapless) const override;
104106
bool isNumRtStacksPerDssFixedValue() const override;
105107
bool getFtrXe2Compression() const override;

shared/source/release_helper/release_helper_base.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ bool ReleaseHelperHw<releaseType>::isDirectSubmissionSupported() const {
6464
return false;
6565
}
6666

67+
template <ReleaseType releaseType>
68+
bool ReleaseHelperHw<releaseType>::isDirectSubmissionLightSupported() const {
69+
return false;
70+
}
71+
6772
template <ReleaseType releaseType>
6873
bool ReleaseHelperHw<releaseType>::isRcsExposureDisabled() const {
6974
return false;

shared/test/common/mocks/linux/mock_os_context_linux.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023-2024 Intel Corporation
2+
* Copyright (C) 2023-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -14,6 +14,7 @@ class MockOsContextLinux : public OsContextLinux {
1414
using OsContextLinux::drmContextIds;
1515
using OsContextLinux::drmVmIds;
1616
using OsContextLinux::fenceVal;
17+
using OsContextLinux::ovLoaded;
1718
using OsContextLinux::pagingFence;
1819

1920
MockOsContextLinux(Drm &drm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)

shared/test/common/mocks/mock_release_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class MockReleaseHelper : public ReleaseHelper {
4141
ADDMETHOD_CONST_NOBASE(isDummyBlitWaRequired, bool, false, ());
4242
ADDMETHOD_CONST_NOBASE(isNumRtStacksPerDssFixedValue, bool, true, ());
4343
ADDMETHOD_CONST_NOBASE(getFtrXe2Compression, bool, false, ());
44+
ADDMETHOD_CONST_NOBASE(isDirectSubmissionLightSupported, bool, false, ());
4445

4546
const SizeToPreferredSlmValueArray &getSizeToPreferredSlmValue(bool isHeapless) const override {
4647
static SizeToPreferredSlmValueArray sizeToPreferredSlmValue = {};

shared/test/unit_test/direct_submission/linux/drm_direct_submission_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
1717
#include "shared/source/os_interface/linux/os_context_linux.h"
1818
#include "shared/source/os_interface/linux/sys_calls.h"
19+
#include "shared/source/release_helper/release_helper.h"
1920
#include "shared/source/utilities/wait_util.h"
2021
#include "shared/test/common/cmd_parse/hw_parse.h"
2122
#include "shared/test/common/helpers/debug_manager_state_restore.h"
@@ -52,6 +53,7 @@ struct DrmDirectSubmissionTest : public DrmMemoryManagerBasic {
5253
true,
5354
executionEnvironment);
5455
device.reset(MockDevice::create<MockDevice>(&executionEnvironment, 0u));
56+
executionEnvironment.rootDeviceEnvironments[0]->initReleaseHelper();
5557
osContext = std::make_unique<OsContextLinux>(*executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>(), device->getRootDeviceIndex(), 0u,
5658
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
5759
PreemptionMode::ThreadGroup, device->getDeviceBitfield()));

shared/test/unit_test/os_interface/linux/os_context_linux_tests.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@
88
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
99
#include "shared/source/os_interface/linux/ioctl_helper.h"
1010
#include "shared/source/os_interface/linux/os_context_linux.h"
11+
#include "shared/source/os_interface/linux/sys_calls.h"
12+
#include "shared/source/os_interface/product_helper.h"
13+
#include "shared/source/release_helper/release_helper.h"
1114
#include "shared/test/common/helpers/engine_descriptor_helper.h"
15+
#include "shared/test/common/helpers/variable_backup.h"
1216
#include "shared/test/common/libult/linux/drm_mock.h"
1317
#include "shared/test/common/mocks/linux/mock_os_context_linux.h"
1418
#include "shared/test/common/mocks/mock_execution_environment.h"
19+
#include "shared/test/common/mocks/mock_os_library.h"
1520
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
21+
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
1622

1723
#include "gtest/gtest.h"
1824

25+
#include <link.h>
1926
#include <memory>
2027

2128
using namespace NEO;
@@ -134,4 +141,59 @@ TEST(OSContextLinux, givenPerContextVmsAndBindCompleteWhenGetFenceAddressAndValT
134141

135142
EXPECT_GT(fenceAddressToWait, 0u);
136143
EXPECT_GT(fenceValToWait, 0u);
144+
}
145+
146+
TEST(OSContextLinux, WhenCreateOsContextLinuxThenCheckIfOVLoaded) {
147+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
148+
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
149+
drm.requirePerContextVM = true;
150+
151+
{
152+
VariableBackup<decltype(SysCalls::sysCallsDlinfo)> mockDlinfo(&SysCalls::sysCallsDlinfo, [](void *handle, int request, void *info) -> int {
153+
return -2;
154+
});
155+
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
156+
EXPECT_FALSE(osContext.ovLoaded);
157+
}
158+
{
159+
VariableBackup<decltype(SysCalls::sysCallsDlinfo)> mockDlinfo(&SysCalls::sysCallsDlinfo, [](void *handle, int request, void *info) -> int {
160+
return 0;
161+
});
162+
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
163+
EXPECT_FALSE(osContext.ovLoaded);
164+
}
165+
{
166+
VariableBackup<decltype(SysCalls::sysCallsDlinfo)> mockDlinfo(&SysCalls::sysCallsDlinfo, [](void *handle, int request, void *info) -> int {
167+
static char name[] = "libexample.so";
168+
static link_map map{};
169+
map.l_name = name;
170+
*static_cast<link_map **>(info) = &map;
171+
return 0;
172+
});
173+
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
174+
EXPECT_FALSE(osContext.ovLoaded);
175+
}
176+
{
177+
VariableBackup<decltype(SysCalls::sysCallsDlinfo)> mockDlinfo(&SysCalls::sysCallsDlinfo, [](void *handle, int request, void *info) -> int {
178+
static char name[] = "libopenvino_intel_gpu_plugin.so";
179+
static link_map map{};
180+
map.l_name = name;
181+
*static_cast<link_map **>(info) = &map;
182+
return 0;
183+
});
184+
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
185+
EXPECT_TRUE(osContext.ovLoaded);
186+
}
187+
}
188+
189+
TEST(OSContextLinux, givenOVLoadedWhenCheckForDirectSubmissionSupportThenProperValueIsReturned) {
190+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
191+
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
192+
drm.requirePerContextVM = true;
193+
MockOsContextLinux osContext(drm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
194+
osContext.ovLoaded = true;
195+
auto directSubmissionSupported = osContext.isDirectSubmissionSupported();
196+
197+
auto &productHelper = executionEnvironment->rootDeviceEnvironments[0]->getProductHelper();
198+
EXPECT_EQ(directSubmissionSupported, productHelper.isDirectSubmissionSupported(executionEnvironment->rootDeviceEnvironments[0]->getReleaseHelper()) && executionEnvironment->rootDeviceEnvironments[0]->getReleaseHelper()->isDirectSubmissionLightSupported());
137199
}

0 commit comments

Comments
 (0)