Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions opencl/extensions/public/cl_ext_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,18 @@ typedef cl_bitfield cl_device_feature_capabilities_intel;

/* For GPU devices, version 1.0.0: */
#define CL_DEVICE_FEATURE_FLAG_DP4A_INTEL (1 << 0)

/****************************************
* cl_khr_pci_bus_info extension *
***************************************/
#define cl_khr_pci_bus_info 1

// New queries for clGetDeviceInfo:
#define CL_DEVICE_PCI_BUS_INFO_KHR 0x410F

typedef struct _cl_device_pci_bus_info_khr {
cl_uint pci_domain;
cl_uint pci_bus;
cl_uint pci_device;
cl_uint pci_function;
} cl_device_pci_bus_info_khr;
5 changes: 5 additions & 0 deletions opencl/source/cl_device/cl_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,9 @@ void ClDevice::getQueueFamilyName(char *outputName, size_t maxOutputNameLength,
Platform *ClDevice::getPlatform() const {
return castToObject<Platform>(platformId);
}
bool ClDevice::isPciBusInfoValid() const {
return deviceInfo.pciBusInfo.pci_domain != PhysicalDevicePciBusInfo::InvalidValue && deviceInfo.pciBusInfo.pci_bus != PhysicalDevicePciBusInfo::InvalidValue &&
deviceInfo.pciBusInfo.pci_device != PhysicalDevicePciBusInfo::InvalidValue && deviceInfo.pciBusInfo.pci_function != PhysicalDevicePciBusInfo::InvalidValue;
}

} // namespace NEO
1 change: 1 addition & 0 deletions opencl/source/cl_device/cl_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ClDevice : public BaseObject<_cl_device_id> {
DeviceBitfield getDeviceBitfield() const;
bool isDeviceEnqueueSupported() const;
bool arePipesSupported() const;
bool isPciBusInfoValid() const;

static cl_command_queue_capabilities_intel getQueueFamilyCapabilitiesAll();
MOCKABLE_VIRTUAL cl_command_queue_capabilities_intel getQueueFamilyCapabilities(EngineGroupType type);
Expand Down
15 changes: 15 additions & 0 deletions opencl/source/cl_device/cl_device_caps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ void ClDevice::initializeCaps() {
deviceExtensions += sharingFactory.getExtensions(driverInfo.get());
}

PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue);

if (driverInfo) {
pciBusInfo = driverInfo->getPciBusInfo();
}

deviceInfo.pciBusInfo.pci_domain = pciBusInfo.pciDomain;
deviceInfo.pciBusInfo.pci_bus = pciBusInfo.pciBus;
deviceInfo.pciBusInfo.pci_device = pciBusInfo.pciDevice;
deviceInfo.pciBusInfo.pci_function = pciBusInfo.pciFunction;

if (isPciBusInfoValid()) {
deviceExtensions += "cl_khr_pci_bus_info ";
}

deviceExtensions += hwHelper.getExtensions();
deviceInfo.deviceExtensions = deviceExtensions.c_str();

Expand Down
6 changes: 6 additions & 0 deletions opencl/source/cl_device/cl_device_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ cl_int ClDevice::getDeviceInfo(cl_device_info paramName,
retSize = srcSize = sizeof(cl_device_feature_capabilities_intel);
break;
}
case CL_DEVICE_PCI_BUS_INFO_KHR:
if (isPciBusInfoValid()) {
src = &deviceInfo.pciBusInfo;
retSize = srcSize = sizeof(deviceInfo.pciBusInfo);
}
break;
default:
if (getDeviceInfoForImage(paramName, src, srcSize, retSize) && !getSharedDeviceInfo().imageSupport) {
src = &value;
Expand Down
1 change: 1 addition & 0 deletions opencl/source/cl_device/cl_device_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct ClDeviceInfo {
cl_uint internalDriverVersion;
cl_uint grfSize;
bool preemptionSupported;
cl_device_pci_bus_info_khr pciBusInfo;
/* Extensions supported */
bool nv12Extension;
bool vmeExtension;
Expand Down
54 changes: 40 additions & 14 deletions opencl/test/unit_test/device/device_caps_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_driver_info.h"
#include "shared/test/common/mocks/mock_sip.h"

#include "opencl/source/platform/extensions.h"
Expand Down Expand Up @@ -1219,31 +1219,57 @@ HWTEST_F(DeviceGetCapsTest, givenDeviceThatHasHighNumberOfExecutionUnitsWhenMaxW
EXPECT_EQ(device->getSharedDeviceInfo().maxWorkGroupSize / hwHelper.getMinimalSIMDSize(), device->getDeviceInfo().maxNumOfSubGroups);
}

class DriverInfoMock : public DriverInfo {
public:
DriverInfoMock(){};
TEST_F(DeviceGetCapsTest, givenSystemWithDriverInfoWhenGettingNameAndVersionThenReturnValuesFromDriverInfo) {
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));

const static std::string testDeviceName;
const static std::string testVersion;
const std::string testDeviceName = "testDeviceName";
const std::string testVersion = "testVersion";

std::string getDeviceName(std::string defaultName) override { return testDeviceName; };
std::string getVersion(std::string defaultVersion) override { return testVersion; };
};
DriverInfoMock *driverInfoMock = new DriverInfoMock();
driverInfoMock->setDeviceName(testDeviceName);
driverInfoMock->setVersion(testVersion);

device->driverInfo.reset(driverInfoMock);
device->initializeCaps();

const auto &caps = device->getDeviceInfo();

const std::string DriverInfoMock::testDeviceName = "testDeviceName";
const std::string DriverInfoMock::testVersion = "testVersion";
EXPECT_STREQ(testDeviceName.c_str(), caps.name);
EXPECT_STREQ(testVersion.c_str(), caps.driverVersion);
}

TEST_F(DeviceGetCapsTest, givenNoPciBusInfoThenPciBusInfoExtensionNotAvailable) {
const PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue);

DriverInfoMock *driverInfoMock = new DriverInfoMock();
driverInfoMock->setPciBusInfo(pciBusInfo);

TEST_F(DeviceGetCapsTest, givenSystemWithDriverInfoWhenGettingNameAndVersionThenReturnValuesFromDriverInfo) {
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
device->driverInfo.reset(driverInfoMock);
device->initializeCaps();

const auto &caps = device->getDeviceInfo();
EXPECT_THAT(caps.deviceExtensions, testing::Not(testing::HasSubstr("cl_khr_pci_bus_info")));
}

TEST_F(DeviceGetCapsTest, givenPciBusInfoThenPciBusInfoExtensionAvailable) {
const PhysicalDevicePciBusInfo pciBusInfo(1, 2, 3, 4);

DriverInfoMock *driverInfoMock = new DriverInfoMock();
driverInfoMock->setPciBusInfo(pciBusInfo);

auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
device->driverInfo.reset(driverInfoMock);
device->initializeCaps();

const auto &caps = device->getDeviceInfo();

EXPECT_STREQ(DriverInfoMock::testDeviceName.c_str(), caps.name);
EXPECT_STREQ(DriverInfoMock::testVersion.c_str(), caps.driverVersion);
EXPECT_THAT(caps.deviceExtensions, testing::HasSubstr("cl_khr_pci_bus_info"));

EXPECT_EQ(caps.pciBusInfo.pci_domain, pciBusInfo.pciDomain);
EXPECT_EQ(caps.pciBusInfo.pci_bus, pciBusInfo.pciBus);
EXPECT_EQ(caps.pciBusInfo.pci_device, pciBusInfo.pciDevice);
EXPECT_EQ(caps.pciBusInfo.pci_function, pciBusInfo.pciFunction);
}

static bool getPlanarYuvHeightCalled = false;
Expand Down
31 changes: 31 additions & 0 deletions opencl/test/unit_test/device/device_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "shared/test/common/helpers/ult_hw_config.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_driver_info.h"
#include "shared/test/common/mocks/ult_device_factory.h"

#include "opencl/source/command_stream/tbx_command_stream_receiver.h"
Expand Down Expand Up @@ -147,6 +148,36 @@ TEST_F(DeviceTest, WhenRetainingThenReferenceIsOneAndApiIsUsed) {
ASSERT_EQ(1, pClDevice->getReference());
}

TEST_F(DeviceTest, givenNoPciBusInfoThenIsPciBusInfoValidReturnsFalse) {
PhysicalDevicePciBusInfo invalidPciBusInfoList[] = {
PhysicalDevicePciBusInfo(0, 1, 2, PhysicalDevicePciBusInfo::InvalidValue),
PhysicalDevicePciBusInfo(0, 1, PhysicalDevicePciBusInfo::InvalidValue, 3),
PhysicalDevicePciBusInfo(0, PhysicalDevicePciBusInfo::InvalidValue, 2, 3),
PhysicalDevicePciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, 1, 2, 3)};

for (auto pciBusInfo : invalidPciBusInfoList) {
auto driverInfo = new DriverInfoMock();
driverInfo->setPciBusInfo(pciBusInfo);

pClDevice->driverInfo.reset(driverInfo);
pClDevice->initializeCaps();

EXPECT_FALSE(pClDevice->isPciBusInfoValid());
}
}

TEST_F(DeviceTest, givenPciBusInfoThenIsPciBusInfoValidReturnsTrue) {
PhysicalDevicePciBusInfo pciBusInfo(0, 1, 2, 3);

auto driverInfo = new DriverInfoMock();
driverInfo->setPciBusInfo(pciBusInfo);

pClDevice->driverInfo.reset(driverInfo);
pClDevice->initializeCaps();

EXPECT_TRUE(pClDevice->isPciBusInfoValid());
}

HWTEST_F(DeviceTest, WhenDeviceIsCreatedThenActualEngineTypeIsSameAsDefault) {
HardwareInfo hwInfo = *defaultHwInfo;
if (hwInfo.capabilityTable.defaultEngineType == aub_stream::EngineType::ENGINE_CCS) {
Expand Down
43 changes: 43 additions & 0 deletions opencl/test/unit_test/device/get_device_info_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "shared/source/helpers/get_info.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_driver_info.h"

#include "opencl/source/cl_device/cl_device_info_map.h"
#include "opencl/source/helpers/cl_hw_helper.h"
Expand Down Expand Up @@ -994,6 +995,48 @@ TEST(GetDeviceInfoTest, givenDeviceWithSubDevicesWhenGettingNumberOfComputeUnits
EXPECT_EQ(sizeof(numComputeUnits), retSize);
}

TEST(GetDeviceInfoTest, givenPciBusInfoWhenGettingPciBusInfoForDeviceThenPciBusInfoIsReturned) {
PhysicalDevicePciBusInfo pciBusInfo(0, 1, 2, 3);

auto driverInfo = new DriverInfoMock();
driverInfo->setPciBusInfo(pciBusInfo);

auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
device->driverInfo.reset(driverInfo);
device->initializeCaps();

cl_device_pci_bus_info_khr devicePciBusInfo;

size_t sizeReturned = 0;
auto retVal = device->getDeviceInfo(CL_DEVICE_PCI_BUS_INFO_KHR, 0, nullptr, &sizeReturned);

ASSERT_EQ(retVal, CL_SUCCESS);
ASSERT_EQ(sizeReturned, sizeof(devicePciBusInfo));

retVal = device->getDeviceInfo(CL_DEVICE_PCI_BUS_INFO_KHR, sizeof(devicePciBusInfo), &devicePciBusInfo, nullptr);
ASSERT_EQ(CL_SUCCESS, retVal);

EXPECT_EQ(devicePciBusInfo.pci_domain, pciBusInfo.pciDomain);
EXPECT_EQ(devicePciBusInfo.pci_bus, pciBusInfo.pciBus);
EXPECT_EQ(devicePciBusInfo.pci_device, pciBusInfo.pciDevice);
EXPECT_EQ(devicePciBusInfo.pci_function, pciBusInfo.pciFunction);
}

TEST(GetDeviceInfoTest, givenPciBusInfoIsNotAvailableWhenGettingPciBusInfoForDeviceThenInvalidValueIsReturned) {
PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue);

auto driverInfo = new DriverInfoMock();
driverInfo->setPciBusInfo(pciBusInfo);

auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
device->driverInfo.reset(driverInfo);
device->initializeCaps();

auto retVal = device->getDeviceInfo(CL_DEVICE_PCI_BUS_INFO_KHR, 0, nullptr, nullptr);

ASSERT_EQ(retVal, CL_INVALID_VALUE);
}

struct DeviceAttributeQueryTest : public ::testing::TestWithParam<uint32_t /*cl_device_info*/> {
void SetUp() override {
param = GetParam();
Expand Down
47 changes: 47 additions & 0 deletions opencl/test/unit_test/linux/main_linux_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/basic_math.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/os_interface/linux/allocator_helper.h"
#include "shared/source/os_interface/linux/os_interface.h"
#include "shared/source/os_interface/linux/sys_calls.h"
Expand Down Expand Up @@ -716,3 +717,49 @@ TEST(PlatformsDestructor, whenGlobalPlatformsDestructorIsCalledThenGlobalPlatfor
EXPECT_EQ(nullptr, platformsImpl);
platformsImpl = new std::vector<std::unique_ptr<Platform>>;
}

TEST_F(DrmTests, givenInvalidPciPathThenPciBusInfoIsNotAvailable) {
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, false);
VariableBackup<decltype(entryIndex)> backupEntryIndex(&entryIndex, 0u);

openFull = openWithCounter;
entryIndex = 1;
openCounter = 1;

const uint32_t invVal = PhysicalDevicePciBusInfo::InvalidValue;

auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
ASSERT_NE(drm, nullptr);
EXPECT_EQ(drm->getPciBusInfo().pciDomain, invVal);
EXPECT_EQ(drm->getPciBusInfo().pciBus, invVal);
EXPECT_EQ(drm->getPciBusInfo().pciDevice, invVal);
EXPECT_EQ(drm->getPciBusInfo().pciFunction, invVal);
}

TEST_F(DrmTests, givenValidPciPathThenPciBusInfoIsAvailable) {
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
VariableBackup<decltype(failOnOpenDir)> backupOpenDir(&failOnOpenDir, false);
VariableBackup<decltype(entryIndex)> backupEntryIndex(&entryIndex, 0u);

openFull = openWithCounter;
entryIndex = 4;
openCounter = 2;

auto drm = DrmWrap::createDrm(*rootDeviceEnvironment);
ASSERT_NE(drm, nullptr);
EXPECT_EQ(drm->getPciBusInfo().pciDomain, 0u);
EXPECT_EQ(drm->getPciBusInfo().pciBus, 0u);
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 2u);
EXPECT_EQ(drm->getPciBusInfo().pciFunction, 1u);

entryIndex = 5;
openCounter = 1;

drm = DrmWrap::createDrm(*rootDeviceEnvironment);
ASSERT_NE(drm, nullptr);
EXPECT_EQ(drm->getPciBusInfo().pciDomain, 0u);
EXPECT_EQ(drm->getPciBusInfo().pciBus, 3u);
EXPECT_EQ(drm->getPciBusInfo().pciDevice, 0u);
EXPECT_EQ(drm->getPciBusInfo().pciFunction, 0u);
}
8 changes: 5 additions & 3 deletions opencl/test/unit_test/linux/mock_os_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ DIR *opendir(const char *name) {
int closedir(DIR *dirp) {
return 0u;
}
uint32_t entryIndex = 0u;
const uint32_t numEntries = 4u;

struct dirent entries[] = {
{0, 0, 0, 0, "."},
{0, 0, 0, 0, "pci-0000:test1-render"},
{0, 0, 0, 0, "pci-0000:test2-render"},
{0, 0, 0, 0, "pci-0000:1234-render"},

{0, 0, 0, 0, "pci-0000:0:2.1-render"},
{0, 0, 0, 0, "pci-0000:3:0.0-render"},
};

uint32_t entryIndex = 0u;
const uint32_t numEntries = sizeof(entries) / sizeof(entries[0]);

struct dirent *readdir(DIR *dir) {
if (entryIndex >= numEntries) {
entryIndex = 0;
Expand Down
10 changes: 5 additions & 5 deletions opencl/test/unit_test/os_interface/windows/driver_info_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MockDriverInfoWindows : public DriverInfoWindows {

static MockDriverInfoWindows *create(std::string path) {

auto result = new MockDriverInfoWindows("");
auto result = new MockDriverInfoWindows("", PhysicalDevicePciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue));
result->reader = new TestedRegistryReader(path);
result->registryReader.reset(result->reader);

Expand Down Expand Up @@ -152,7 +152,7 @@ struct DriverInfoWindowsTest : public ::testing::Test {
DriverInfoWindows::createRegistryReaderFunc = [](const std::string &) -> std::unique_ptr<SettingsReader> {
return std::make_unique<MockRegistryReader>();
};
driverInfo = std::make_unique<MockDriverInfoWindows>("");
driverInfo = std::make_unique<MockDriverInfoWindows>("", PhysicalDevicePciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue));
}

VariableBackup<decltype(DriverInfoWindows::createRegistryReaderFunc)> createFuncBackup{&DriverInfoWindows::createRegistryReaderFunc};
Expand All @@ -178,7 +178,7 @@ TEST_F(DriverInfoWindowsTest, GivenDriverInfoWhenThenReturnNonNullptr) {
};

TEST(DriverInfo, givenDriverInfoWhenGetStringReturnNotMeaningEmptyStringThenEnableSharingSupport) {
MockDriverInfoWindows driverInfo("");
MockDriverInfoWindows driverInfo("", PhysicalDevicePciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue));
MockRegistryReader *registryReaderMock = new MockRegistryReader();

driverInfo.registryReader.reset(registryReaderMock);
Expand All @@ -190,7 +190,7 @@ TEST(DriverInfo, givenDriverInfoWhenGetStringReturnNotMeaningEmptyStringThenEnab
};

TEST(DriverInfo, givenDriverInfoWhenGetStringReturnMeaningEmptyStringThenDisableSharingSupport) {
MockDriverInfoWindows driverInfo("");
MockDriverInfoWindows driverInfo("", PhysicalDevicePciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue));
MockRegistryReader *registryReaderMock = new MockRegistryReader();
registryReaderMock->returnString = "<>";
driverInfo.registryReader.reset(registryReaderMock);
Expand All @@ -206,7 +206,7 @@ TEST(DriverInfo, givenFullPathToRegistryWhenCreatingDriverInfoWindowsThenTheRegi
std::string registryPath = "Path\\In\\Registry";
std::string fullRegistryPath = "\\REGISTRY\\MACHINE\\" + registryPath;
std::string expectedTrimmedRegistryPath = registryPath;
MockDriverInfoWindows driverInfo(std::move(fullRegistryPath));
MockDriverInfoWindows driverInfo(std::move(fullRegistryPath), PhysicalDevicePciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue));

EXPECT_STREQ(expectedTrimmedRegistryPath.c_str(), driverInfo.path.c_str());
};
Expand Down
Loading