Skip to content

Commit a7c0dbf

Browse files
steffenlarsenbb-sycl
authored andcommitted
[SYCL] Adds regression test for PCI address BDF format (intel#991)
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 4fcc69b commit a7c0dbf

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
3+
4+
//==- device_pci_address_bdf_format.cpp - SYCL PCI address BDF format test -==//
5+
//
6+
// Tests the BDF format of the PCI address reported through the corresponding
7+
// query.
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include <CL/sycl.hpp>
16+
17+
#include <iostream>
18+
#include <regex>
19+
#include <string>
20+
21+
using namespace cl::sycl;
22+
23+
#ifdef _WIN32
24+
#define setenv(name, value, overwrite) _putenv_s(name, value)
25+
#endif
26+
27+
int main(int argc, char **argv) {
28+
// Must be enabled at the beginning of the application
29+
// to obtain the PCI address
30+
setenv("SYCL_ENABLE_PCI", "1", 0);
31+
32+
// Expected format is "{domain}:{bus}:{device}.{function} where:
33+
// * {domain} is a 4 character hexadecimal value.
34+
// * {bus} is a 2 character hexadecimal value.
35+
// * {device} is a 2 character hexadecimal value.
36+
// * {function} is a 1 character hexadecimal value.
37+
const std::regex ExpectedBDFFormat{
38+
"^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}.[0-9a-fA-F]$"};
39+
40+
for (const auto &plt : platform::get_platforms()) {
41+
if (plt.has(aspect::host))
42+
continue;
43+
for (const auto &dev : plt.get_devices()) {
44+
if (!dev.has(aspect::ext_intel_pci_address))
45+
continue;
46+
47+
std::string PCIAddress =
48+
dev.get_info<info::device::ext_intel_pci_address>();
49+
std::cout << "PCI address = " << PCIAddress << std::endl;
50+
assert(std::regex_match(PCIAddress, ExpectedBDFFormat));
51+
}
52+
}
53+
std::cout << "Passed!" << std::endl;
54+
return 0;
55+
}

0 commit comments

Comments
 (0)