mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 22:12:59 +08:00
Added DeviceId filtering under Linux
Change-Id: Ie4b91d139beb8f31d50737d829e9d8fe801dcfa1 Signed-off-by: Koska <andrzej.koska@intel.com> Related-To: NEO-3239
This commit is contained in:
committed by
sys_ocldev
parent
68d152a3d9
commit
1f6dde3f02
@@ -23,6 +23,8 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
bool (*Drm::pIsi915Version)(int fd) = Drm::isi915Version;
|
||||
int (*Drm::pClose)(int fd) = ::close;
|
||||
const DeviceDescriptor deviceDescriptorTable[] = {
|
||||
#define DEVICE(devId, gt, gtType) {devId, >::hwInfo, >::setupHardwareInfo, gtType},
|
||||
#include "devices.inl"
|
||||
@@ -71,7 +73,7 @@ int Drm::getDeviceFd(const int devType) {
|
||||
const char *pathPrefix;
|
||||
unsigned int startNum;
|
||||
const unsigned int maxDrmDevices = 64;
|
||||
|
||||
if (DebugManager.flags.ForceDeviceId.get() == "unk") {
|
||||
switch (devType) {
|
||||
case 0:
|
||||
startNum = 128;
|
||||
@@ -82,7 +84,6 @@ int Drm::getDeviceFd(const int devType) {
|
||||
pathPrefix = "/dev/dri/card";
|
||||
break;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < maxDrmDevices; i++) {
|
||||
snprintf(fullPath, PATH_MAX, "%s%u", pathPrefix, i + startNum);
|
||||
int fd = ::open(fullPath, O_RDWR);
|
||||
@@ -93,6 +94,19 @@ int Drm::getDeviceFd(const int devType) {
|
||||
::close(fd);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const char *cardType[] = {"-render", "-card"};
|
||||
for (auto param : cardType) {
|
||||
snprintf(fullPath, PATH_MAX, "/dev/dri/by-path/pci-0000:%s%s", DebugManager.flags.ForceDeviceId.get().c_str(), param);
|
||||
int fd = ::open(fullPath, O_RDWR);
|
||||
if (fd >= 0) {
|
||||
if (pIsi915Version(fd)) {
|
||||
return fd;
|
||||
}
|
||||
pClose(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,9 @@ class Drm {
|
||||
MemoryInfo *getMemoryInfo() const {
|
||||
return memoryInfo.get();
|
||||
}
|
||||
static bool (*pIsi915Version)(int fd);
|
||||
static bool isi915Version(int fd);
|
||||
static int (*pClose)(int fd);
|
||||
|
||||
protected:
|
||||
int getQueueSliceCount(drm_i915_gem_context_param_sseu *sseu);
|
||||
@@ -97,7 +100,6 @@ class Drm {
|
||||
std::unique_ptr<EngineInfo> engineInfo;
|
||||
std::unique_ptr<MemoryInfo> memoryInfo;
|
||||
|
||||
static bool isi915Version(int fd);
|
||||
static int getDeviceFd(const int devType);
|
||||
static int openDevice();
|
||||
static Drm *create(int32_t deviceOrdinal);
|
||||
|
||||
@@ -48,6 +48,55 @@ void initializeTestedDevice() {
|
||||
}
|
||||
}
|
||||
|
||||
int openRetVal = 0;
|
||||
int testOpen(const char *fullPath, int, ...) {
|
||||
return openRetVal;
|
||||
};
|
||||
|
||||
TEST(DrmTest, GivenSelectedNotExistingDeviceWhenGetDeviceFdThenFail) {
|
||||
DebugManagerStateRestore stateRestore;
|
||||
DebugManager.flags.ForceDeviceId.set("1234");
|
||||
struct DrmTest : public NEO::Drm {
|
||||
using NEO::Drm::getDeviceFd;
|
||||
};
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
openFull = testOpen;
|
||||
openRetVal = -1;
|
||||
int fd = DrmTest::getDeviceFd(0);
|
||||
EXPECT_EQ(fd, -1);
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenSelectedExistingDeviceWhenGetDeviceFdThenReturnFd) {
|
||||
DebugManagerStateRestore stateRestore;
|
||||
DebugManager.flags.ForceDeviceId.set("1234");
|
||||
struct DrmTest : public NEO::Drm {
|
||||
using NEO::Drm::getDeviceFd;
|
||||
};
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
openRetVal = 1023; // fakeFd
|
||||
openFull = testOpen;
|
||||
int fd = DrmTest::getDeviceFd(0);
|
||||
EXPECT_NE(fd, -1);
|
||||
}
|
||||
|
||||
TEST(DrmTest, GivenSelectedIncorectDeviceWhenGetDeviceFdThenFail) {
|
||||
DebugManagerStateRestore stateRestore;
|
||||
DebugManager.flags.ForceDeviceId.set("1234");
|
||||
struct DrmTest : public NEO::Drm {
|
||||
using NEO::Drm::getDeviceFd;
|
||||
};
|
||||
VariableBackup<decltype(openFull)> backupOpenFull(&openFull);
|
||||
VariableBackup<decltype(Drm::pIsi915Version)> backupIsi915Version(&Drm::pIsi915Version);
|
||||
VariableBackup<decltype(Drm::pClose)> backupClose(&Drm::pClose);
|
||||
openFull = testOpen;
|
||||
openRetVal = 1023;
|
||||
Drm::pIsi915Version = [](int x) -> bool { return false; };
|
||||
Drm::pClose = [](int x) -> int { return 0; };
|
||||
|
||||
int fd = DrmTest::getDeviceFd(0);
|
||||
EXPECT_EQ(fd, -1);
|
||||
}
|
||||
|
||||
TEST_F(DrmTests, getReturnsNull) {
|
||||
auto drm = Drm::get(0);
|
||||
EXPECT_EQ(drm, nullptr);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <iostream>
|
||||
|
||||
int (*c_open)(const char *pathname, int flags, ...) = nullptr;
|
||||
int (*openFull)(const char *pathname, int flags, ...) = nullptr;
|
||||
int (*c_ioctl)(int fd, unsigned long int request, ...) = nullptr;
|
||||
|
||||
int fakeFd = 1023;
|
||||
@@ -36,6 +37,9 @@ int ioctlSeq[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
size_t ioctlCnt = 0;
|
||||
|
||||
int open(const char *pathname, int flags, ...) {
|
||||
if (openFull != nullptr) {
|
||||
return openFull(pathname, flags);
|
||||
}
|
||||
if (c_open == nullptr) {
|
||||
c_open = (int (*)(const char *, int, ...))dlsym(RTLD_NEXT, "open");
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ int ioctl(int fd, unsigned long int request, ...) throw();
|
||||
}
|
||||
|
||||
extern int (*c_open)(const char *pathname, int flags, ...);
|
||||
extern int (*openFull)(const char *pathname, int flags, ...);
|
||||
extern int (*c_ioctl)(int __fd, unsigned long int __request, ...);
|
||||
|
||||
extern int fakeFd;
|
||||
|
||||
Reference in New Issue
Block a user