1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
/*############################################################################
# Copyright (C) Intel Corporation
#
# SPDX-License-Identifier: MIT
############################################################################*/
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <algorithm>
#include <array>
#include <fstream>
#include <string>
#include <vector>
#include "vpl/mfx.h"
#ifdef __linux__
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include "dlfcn.h"
#include "va/va.h"
#include "va/va_drm.h"
#endif
typedef struct gpuinfo {
unsigned int deviceid;
std::array<char, 128> name;
std::array<char, 8> arch;
std::array<char, 32> codename;
} gpuinfo;
gpuinfo get_gpuinfo(unsigned int deviceid) {
gpuinfo result;
gpuinfo gpunames[] = { { 0x56C0, "Intel® Data Center GPU Flex 170", "Xe HPG", "ATS-M150" },
{ 0x56C1, "Intel® Data Center GPU Flex 140", "Xe HPG", "ATS-M75" },
{ 0x5694, "Intel® Arc(TM) A350M Graphics", "Xe HPG", "DG2" },
{ 0x5693, "Intel® Arc(TM) A370M Graphics", "Xe HPG", "DG2" },
{ 0x5692, "Intel® Arc(TM) A550M Graphics", "Xe HPG", "DG2" },
{ 0x5691, "Intel® Arc(TM) A730M Graphics", "Xe HPG", "DG2" },
{ 0x56A1, "Intel® Arc(TM) A750 Graphics", "Xe HPG", "DG2" },
{ 0x56A0, "Intel® Arc(TM) A770 Graphics", "Xe HPG", "DG2" },
{ 0x56A5, "Intel® Arc(TM) A380 Graphics", "Xe HPG", "DG2" },
{ 0x56A6, "Intel® Arc(TM) A310 Graphics", "Xe HPG", "DG2" },
{ 0x4905, "Intel® Iris® Xe MAX Graphics", "Xe MAX", "DG1" },
{ 0x9A60, "Intel® UHD Graphics GT1", "Xe", "Tiger Lake" },
{ 0x9A68, "Intel® UHD Graphics GT1", "Xe", "Tiger Lake" },
{ 0x9A70, "Intel® UHD Graphics GT1", "Xe", "Tiger Lake" },
{ 0x9A40, "Intel® Iris® Xe Graphics GT2", "Xe", "Tiger Lake" },
{ 0x9A49, "Intel® Iris® Xe Graphics GT2", "Xe", "Tiger Lake" },
{ 0x9A78, "Intel® UHD Graphics GT2", "Xe", "Tiger Lake" },
{ 0x9AC0, "Intel® UHD Graphics GT2", "Xe", "Tiger Lake" },
{ 0x9AC9, "Intel® UHD Graphics GT2", "Xe", "Tiger Lake" },
{ 0x9AD9, "Intel® UHD Graphics GT2", "Xe", "Tiger Lake" },
{ 0x9AF8, "Intel® UHD Graphics GT2", "Xe", "Tiger Lake" } };
gpuinfo unknown = { 0x0000, "unknown", "na", "na" };
uint32_t n = (sizeof(gpunames[0]) > 0) ? (sizeof(gpunames) / sizeof(gpunames[0])) : 1;
int resultidx = -1;
for (uint32_t i = 0; i < n; i++) {
if (gpunames[i].deviceid == deviceid) {
resultidx = i;
break;
}
}
if (resultidx >= 0) {
result = gpunames[resultidx];
}
else {
result = unknown;
}
return result;
}
#define STRING_OPTION(x) \
case x: \
return #x
const char *_print_Impl(mfxIMPL impl) {
switch (impl) {
STRING_OPTION(MFX_IMPL_TYPE_SOFTWARE);
STRING_OPTION(MFX_IMPL_TYPE_HARDWARE);
}
return "<unknown implementation>";
}
const char *_print_AccelMode(mfxAccelerationMode mode) {
switch (mode) {
STRING_OPTION(MFX_ACCEL_MODE_NA);
STRING_OPTION(MFX_ACCEL_MODE_VIA_D3D9);
STRING_OPTION(MFX_ACCEL_MODE_VIA_D3D11);
STRING_OPTION(MFX_ACCEL_MODE_VIA_VAAPI);
STRING_OPTION(MFX_ACCEL_MODE_VIA_VAAPI_DRM_MODESET);
STRING_OPTION(MFX_ACCEL_MODE_VIA_VAAPI_GLX);
STRING_OPTION(MFX_ACCEL_MODE_VIA_VAAPI_X11);
STRING_OPTION(MFX_ACCEL_MODE_VIA_VAAPI_WAYLAND);
STRING_OPTION(MFX_ACCEL_MODE_VIA_HDDLUNITE);
}
return "<unknown acceleration mode>";
}
const char *_print_MediaAdapterType(mfxMediaAdapterType type) {
switch (type) {
STRING_OPTION(MFX_MEDIA_UNKNOWN);
STRING_OPTION(MFX_MEDIA_INTEGRATED);
STRING_OPTION(MFX_MEDIA_DISCRETE);
}
return "<unknown media adapter type>";
}
bool show_MFXLoad_info() {
mfxLoader loader = MFXLoad();
if (loader == NULL) {
return false;
}
//Loop over implementations found by MFXLoad
int i = 0;
mfxImplDescription *idesc;
while (MFX_ERR_NONE == MFXEnumImplementations(loader,
i,
MFX_IMPLCAPS_IMPLDESCSTRUCTURE,
reinterpret_cast<mfxHDL *>(&idesc))) {
printf("\nImplementation #%d: %s\n", i, idesc->ImplName);
// get path if supported (available starting with API 2.4)
mfxHDL hImplPath = nullptr;
if (MFX_ERR_NONE == MFXEnumImplementations(loader, i, MFX_IMPLCAPS_IMPLPATH, &hImplPath)) {
if (hImplPath) {
printf("%2sLibrary path: %s\n", "", reinterpret_cast<mfxChar *>(hImplPath));
MFXDispReleaseImplDescription(loader, hImplPath);
}
}
printf(" AccelerationMode: %s\n", _print_AccelMode(idesc->AccelerationMode));
printf(" ApiVersion: %hu.%hu\n", idesc->ApiVersion.Major, idesc->ApiVersion.Minor);
printf(" Impl: %s\n", _print_Impl(idesc->Impl));
printf(" ImplName: %s\n", idesc->ImplName);
/* mfxDeviceDescription */
mfxDeviceDescription *dev = &idesc->Dev;
printf(" MediaAdapterType: %s\n",
_print_MediaAdapterType((mfxMediaAdapterType)dev->MediaAdapterType));
for (int subdevice = 0; subdevice < dev->NumSubDevices; subdevice++) {
printf(" Index: %u\n", dev->SubDevices[subdevice].Index);
printf(" SubDeviceID: %s\n", dev->SubDevices[subdevice].SubDeviceID);
}
#ifdef ONEVPL_EXPERIMENTAL
mfxExtendedDeviceId *idescDevice;
mfxStatus sts = MFXEnumImplementations(loader,
i,
MFX_IMPLCAPS_DEVICE_ID_EXTENDED,
reinterpret_cast<mfxHDL *>(&idescDevice));
if (sts == MFX_ERR_NONE) {
printf(" VendorID: 0x%04X\n", idescDevice->VendorID);
printf(" DeviceID: 0x%04X \n", idescDevice->DeviceID);
gpuinfo g = get_gpuinfo(idescDevice->DeviceID);
std::string gpuname(std::begin(g.name), std::end(g.name));
std::string gpuarch(std::begin(g.arch), std::end(g.arch));
std::string gpucodename(std::begin(g.codename), std::end(g.codename));
printf(" GPU name: %s (arch=%s codename=%s)\n",
gpuname.c_str(),
gpuarch.c_str(),
gpucodename.c_str());
printf(" PCI BDF: %04X:%02X:%02X.%02X\n",
idescDevice->PCIDomain,
idescDevice->PCIBus,
idescDevice->PCIDevice,
idescDevice->PCIFunction);
if (idescDevice->LUIDValid) {
printf(" DeviceLUID: ");
for (mfxU32 idx = 0; idx < 8; idx++) {
printf("%02x", idescDevice->DeviceLUID[7 - idx]);
}
printf("\n");
printf(" LUIDDeviceNodeMask: 0x%04X\n", idescDevice->LUIDDeviceNodeMask);
}
printf(" DRMRenderNodeNum: %d\n", idescDevice->DRMRenderNodeNum);
printf("DeviceName: %s\n", idescDevice->DeviceName);
MFXDispReleaseImplDescription(loader, idescDevice);
}
#endif
i++;
}
MFXUnload(loader);
return (i > 0) ? true : false;
}
int main() {
bool check_gpu_caps = true;
void *libva_handle = dlopen("libva.so", RTLD_NOW | RTLD_GLOBAL);
if (!libva_handle) {
printf("could not open libva.so\n");
check_gpu_caps = false;
}
void *libvadrm_handle = dlopen("libva-drm.so", RTLD_NOW | RTLD_GLOBAL);
if (!libvadrm_handle) {
printf("could not open libva-drm.so\n");
check_gpu_caps = false;
}
if (check_gpu_caps) {
printf("------------------------------------\n");
printf("Looking for GPU interfaces available to OS...\n");
int nGPUadapters = 0;
std::vector<std::string> rns = { "/dev/dri/renderD128", "/dev/dri/renderD129",
"/dev/dri/renderD130", "/dev/dri/renderD131",
"/dev/dri/renderD132", "/dev/dri/renderD133",
"/dev/dri/renderD134", "/dev/dri/renderD135" };
for (size_t i = 0; i < rns.size(); i++) {
std::ifstream rn(rns[i].c_str());
if (rn.good()) {
printf("FOUND: %s\n", rns[i].c_str());
nGPUadapters++;
}
}
printf("GPU interfaces found: %d\n", nGPUadapters);
if (!nGPUadapters) {
printf("No GPU adapters found. Possible reasons:\n");
printf(" * No GPU HW available\n");
printf(" * GPU not enabled in BIOS\n");
printf(" * Unsupported kernel version. Check 'uname -r'\n");
printf(" * i915 module not started. Check 'lsmod'\n");
printf(" * problem initializing i915. Check 'dmesg'\n");
}
printf("------------------------------------\n\n\n");
}
else {
printf("------------------------------------\n");
printf("Could not initialize libva. Is libva installed?\n");
printf("GPU media capabilities cannot work without libva\n");
printf("------------------------------------\n\n\n");
}
printf("------------------------------------\n");
printf("Available implementation details:\n");
if (!show_MFXLoad_info()) {
printf("No oneVPL implementations found. Is environment configured?\n");
}
printf("------------------------------------\n");
if (libva_handle)
dlclose(libva_handle);
if (libvadrm_handle)
dlclose(libvadrm_handle);
return 0;
}
|