Skip to content

Commit 1823054

Browse files
Linux: pass adapter BDF to GmmLib
Resolves: NEO-5785 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent dfb935f commit 1823054

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

opencl/source/dll/linux/os_interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -16,8 +16,8 @@ bool OSInterface::osEnableLocalMemory = true;
1616

1717
void OSInterface::setGmmInputArgs(void *args) {
1818
auto gmmInArgs = reinterpret_cast<GMM_INIT_IN_ARGS *>(args);
19-
20-
gmmInArgs->FileDescriptor = this->get()->getDrm()->getFileDescriptor();
19+
auto adapterBDF = this->get()->getDrm()->getAdapterBDF();
20+
gmmInArgs->FileDescriptor = adapterBDF.Data;
2121
gmmInArgs->ClientType = GMM_CLIENT::GMM_OCL_VISTA;
2222
}
2323

opencl/test/unit_test/linux/os_interface_linux_tests.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,27 @@ namespace NEO {
1818
extern GMM_INIT_IN_ARGS passedInputArgs;
1919
extern bool copyInputArgs;
2020

21-
TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenProperFileDescriptorIsSet) {
21+
TEST(OsInterfaceTest, whenOsInterfaceSetupsGmmInputArgsThenFileDescriptorIsSetWithValueOfAdapterBdf) {
2222
MockExecutionEnvironment executionEnvironment;
2323
auto rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get();
2424
auto osInterface = new OSInterface();
2525
rootDeviceEnvironment->osInterface.reset(osInterface);
2626

2727
auto drm = new DrmMock(fakeFd, *rootDeviceEnvironment);
28+
drm->setPciPath("01:23.4");
29+
2830
osInterface->get()->setDrm(drm);
2931

3032
GMM_INIT_IN_ARGS gmmInputArgs = {};
3133
EXPECT_EQ(0u, gmmInputArgs.FileDescriptor);
3234
osInterface->setGmmInputArgs(&gmmInputArgs);
3335
EXPECT_NE(0u, gmmInputArgs.FileDescriptor);
3436

35-
auto expectedFileDescriptor = drm->getFileDescriptor();
36-
EXPECT_EQ(static_cast<uint32_t>(expectedFileDescriptor), gmmInputArgs.FileDescriptor);
37+
ADAPTER_BDF expectedAdapterBDF{};
38+
expectedAdapterBDF.Bus = 0x1;
39+
expectedAdapterBDF.Device = 0x23;
40+
expectedAdapterBDF.Function = 0x4;
41+
EXPECT_EQ(expectedAdapterBDF.Data, gmmInputArgs.FileDescriptor);
3742
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, gmmInputArgs.ClientType);
3843
}
3944

opencl/test/unit_test/os_interface/linux/drm_tests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ TEST(DrmTest, WhenGettingDeviceIdThenCorrectIdReturned) {
3838
delete pDrm;
3939
}
4040

41+
TEST(DrmTest, GivenValidPciPathWhenGettingAdapterBdfThenCorrectValuesAreReturned) {
42+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
43+
executionEnvironment->prepareRootDeviceEnvironments(1);
44+
DrmMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
45+
46+
{
47+
drm.setPciPath("ab:cd.e");
48+
auto adapterBdf = drm.getAdapterBDF();
49+
EXPECT_EQ(0xabu, adapterBdf.Bus);
50+
EXPECT_EQ(0xcdu, adapterBdf.Device);
51+
EXPECT_EQ(0xeu, adapterBdf.Function);
52+
}
53+
54+
{
55+
drm.setPciPath("01:23.4");
56+
auto adapterBdf = drm.getAdapterBDF();
57+
EXPECT_EQ(0x1u, adapterBdf.Bus);
58+
EXPECT_EQ(0x23u, adapterBdf.Device);
59+
EXPECT_EQ(0x4u, adapterBdf.Function);
60+
}
61+
}
62+
4163
TEST(DrmTest, GivenInvalidPciPathWhenFrequencyIsQueriedThenReturnError) {
4264
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
4365
executionEnvironment->prepareRootDeviceEnvironments(1);

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,4 +558,21 @@ Drm::~Drm() {
558558
this->printIoctlStatistics();
559559
}
560560

561+
ADAPTER_BDF Drm::getAdapterBDF() const {
562+
563+
ADAPTER_BDF adapterBDF{};
564+
constexpr int pciBusInfoTokensNum = 3;
565+
566+
uint32_t bus, device, function;
567+
568+
if (std::sscanf(hwDeviceId->getPciPath(), "%02x:%02x.%01x", &bus, &device, &function) != pciBusInfoTokensNum) {
569+
return {};
570+
}
571+
adapterBDF.Bus = bus;
572+
adapterBDF.Function = function;
573+
adapterBDF.Device = device;
574+
575+
return adapterBDF;
576+
}
577+
561578
} // namespace NEO

shared/source/os_interface/linux/drm_neo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#pragma once
9+
#include "shared/source/gmm_helper/gmm_lib.h"
910
#include "shared/source/helpers/basic_math.h"
1011
#include "shared/source/os_interface/linux/cache_info.h"
1112
#include "shared/source/os_interface/linux/engine_info.h"
@@ -95,6 +96,7 @@ class Drm {
9596

9697
MOCKABLE_VIRTUAL void checkPreemptionSupport();
9798
inline int getFileDescriptor() const { return hwDeviceId->getFileDescriptor(); }
99+
ADAPTER_BDF getAdapterBDF() const;
98100
int createDrmVirtualMemory(uint32_t &drmVmId);
99101
void destroyDrmVirtualMemory(uint32_t drmVmId);
100102
uint32_t createDrmContext(uint32_t drmVmId, bool isDirectSubmission);

0 commit comments

Comments
 (0)