Skip to content

Commit c71814f

Browse files
Rbiessyhjabird
andauthored
Add test to print device information (#126)
* Add test to print device information * Do not create queue Co-authored-by: HJA Bird <9040797+hjabird@users.noreply.github.com> * Rename file and test --------- Co-authored-by: HJA Bird <9040797+hjabird@users.noreply.github.com>
1 parent b71b680 commit c71814f

File tree

5 files changed

+118
-50
lines changed

5 files changed

+118
-50
lines changed

test/bench/utils/device_context.hpp

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,55 +25,29 @@
2525

2626
#include <benchmark/benchmark.h>
2727

28+
#include "common/sycl_utils.hpp"
29+
2830
void add_device_context(sycl::queue queue) {
2931
namespace info = sycl::info::device;
30-
using sycl::info::device_type;
3132
sycl::device dev = queue.get_device();
3233
sycl::platform platform = dev.get_info<info::platform>();
3334

34-
std::string device_type_str;
35-
switch (dev.get_info<info::device_type>()) {
36-
case device_type::cpu:
37-
device_type_str = "CPU";
38-
break;
39-
case device_type::gpu:
40-
device_type_str = "GPU";
41-
break;
42-
case device_type::accelerator:
43-
device_type_str = "accelerator";
44-
break;
45-
case device_type::custom:
46-
device_type_str = "custom";
47-
break;
48-
case device_type::host:
49-
device_type_str = "host";
50-
break;
51-
default:
52-
device_type_str = "unknown";
53-
break;
54-
};
55-
56-
bool supports_double = dev.get_info<info::double_fp_config>().empty();
57-
58-
auto subgroup_sizes = dev.get_info<info::sub_group_sizes>();
59-
std::stringstream subgroup_sizes_str;
60-
subgroup_sizes_str << "[";
61-
for (std::size_t i = 0; i < subgroup_sizes.size(); ++i) {
62-
if (i > 0) {
63-
subgroup_sizes_str << ", ";
64-
}
65-
subgroup_sizes_str << subgroup_sizes[i];
66-
}
67-
subgroup_sizes_str << "]";
35+
std::string device_type_str = get_device_type(dev);
36+
std::string supports_double_str = dev.has(sycl::aspect::fp64) ? "yes" : "no";
37+
std::string supports_usm_str = dev.has(sycl::aspect::usm_device_allocations) ? "yes" : "no";
38+
std::string subgroup_sizes_str = get_device_subgroup_sizes(dev);
39+
std::string local_memory_size_str = std::to_string(dev.get_info<sycl::info::device::local_mem_size>()) + "B";
6840

6941
benchmark::AddCustomContext("Device type", device_type_str);
7042
benchmark::AddCustomContext("Platform", platform.get_info<sycl::info::platform::name>());
7143
benchmark::AddCustomContext("Name", dev.get_info<info::name>());
7244
benchmark::AddCustomContext("Vendor", dev.get_info<info::vendor>());
7345
benchmark::AddCustomContext("Version", dev.get_info<info::version>());
7446
benchmark::AddCustomContext("Driver version", dev.get_info<info::driver_version>());
75-
benchmark::AddCustomContext("Double supported", (supports_double ? "no" : "yes"));
76-
benchmark::AddCustomContext("Subgroup sizes", subgroup_sizes_str.str());
47+
benchmark::AddCustomContext("Double supported", supports_double_str);
48+
benchmark::AddCustomContext("USM supported", supports_usm_str);
49+
benchmark::AddCustomContext("Subgroup sizes", subgroup_sizes_str);
50+
benchmark::AddCustomContext("Local memory size", local_memory_size_str);
7751
}
7852

7953
#endif // PORTFFT_TEST_BENCH_UTILS_DEVICE_CONTEXT_HPP

test/common/sycl_utils.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define PORTFFT_TEST_COMMON_SYCL_UTILS_HPP
2323

2424
#include <memory>
25+
#include <sstream>
26+
#include <string>
2527

2628
#include <sycl/sycl.hpp>
2729

@@ -40,4 +42,44 @@ inline std::shared_ptr<T> make_shared(std::size_t size, sycl::queue queue) {
4042
});
4143
}
4244

45+
/**
46+
* Return the device type as a string
47+
* @param dev SYCL device
48+
*/
49+
std::string get_device_type(sycl::device dev) {
50+
using sycl::info::device_type;
51+
switch (dev.get_info<sycl::info::device::device_type>()) {
52+
case device_type::cpu:
53+
return "CPU";
54+
case device_type::gpu:
55+
return "GPU";
56+
case device_type::accelerator:
57+
return "accelerator";
58+
case device_type::custom:
59+
return "custom";
60+
case device_type::host:
61+
return "host";
62+
default:
63+
return "unknown";
64+
};
65+
}
66+
67+
/**
68+
* Return the list of supported subgroup sizes as a string
69+
* @param dev SYCL device
70+
*/
71+
std::string get_device_subgroup_sizes(sycl::device dev) {
72+
auto subgroup_sizes = dev.get_info<sycl::info::device::sub_group_sizes>();
73+
std::stringstream subgroup_sizes_str;
74+
subgroup_sizes_str << "[";
75+
for (std::size_t i = 0; i < subgroup_sizes.size(); ++i) {
76+
if (i > 0) {
77+
subgroup_sizes_str << ", ";
78+
}
79+
subgroup_sizes_str << subgroup_sizes[i];
80+
}
81+
subgroup_sizes_str << "]";
82+
return subgroup_sizes_str.str();
83+
}
84+
4385
#endif // PORTFFT_TEST_COMMON_SYCL_UTILS_HPP

test/unit_test/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
3636
FetchContent_MakeAvailable(googletest)
3737

3838
set(PORTFFT_UNIT_TESTS
39-
fft_float.cpp
40-
transfers.cpp
39+
print_device_info.cpp
4140
descriptor.cpp
41+
transfers.cpp
42+
fft_float.cpp
4243
)
4344
if(PORTFFT_ENABLE_DOUBLE_BUILDS)
4445
list(APPEND PORTFFT_UNIT_TESTS

test/unit_test/fft_test_utils.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,15 @@ std::enable_if_t<TestMemory == test_memory::buffer> check_fft(
392392
*/
393393
template <test_memory TestMemory, typename FType, direction Dir, complex_storage Storage>
394394
void run_test(const test_params& params) {
395-
std::vector<sycl::aspect> queue_aspects;
396-
if constexpr (std::is_same_v<FType, double>) {
397-
queue_aspects.push_back(sycl::aspect::fp64);
398-
}
399-
if constexpr (TestMemory == test_memory::usm) {
400-
queue_aspects.push_back(sycl::aspect::usm_device_allocations);
401-
}
395+
// Use default selector to match with the device printed
402396
sycl::queue queue;
403-
try {
404-
queue = sycl::queue(sycl::aspect_selector(queue_aspects));
405-
} catch (sycl::exception& e) {
406-
GTEST_SKIP() << e.what();
397+
sycl::device dev = queue.get_device();
398+
if (std::is_same_v<FType, double> && !dev.has(sycl::aspect::fp64)) {
399+
GTEST_SKIP() << "Device does not support double precision";
400+
return;
401+
}
402+
if (TestMemory == test_memory::usm && !dev.has(sycl::aspect::usm_device_allocations)) {
403+
GTEST_SKIP() << "Device does not support USM";
407404
return;
408405
}
409406

test/unit_test/print_device_info.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***************************************************************************
2+
*
3+
* Copyright (C) Codeplay Software Ltd.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* Codeplay's portFFT
18+
*
19+
**************************************************************************/
20+
21+
#include <gtest/gtest.h>
22+
23+
#include "sycl_utils.hpp"
24+
25+
/**
26+
* Print information of the device selected by the default selector.
27+
* Use this as a test to print the information once when using ctest.
28+
*/
29+
void print_device_info() {
30+
namespace info = sycl::info::device;
31+
sycl::device dev;
32+
sycl::platform platform = dev.get_info<info::platform>();
33+
34+
std::string device_type_str = get_device_type(dev);
35+
std::string supports_double_str = dev.has(sycl::aspect::fp64) ? "yes" : "no";
36+
std::string supports_usm_str = dev.has(sycl::aspect::usm_device_allocations) ? "yes" : "no";
37+
std::string subgroup_sizes_str = get_device_subgroup_sizes(dev);
38+
auto local_memory_size = dev.get_info<sycl::info::device::local_mem_size>();
39+
40+
std::cout << "Running tests on:\n";
41+
std::cout << " Device type: " << device_type_str << "\n";
42+
std::cout << " Platform: " << platform.get_info<sycl::info::platform::name>() << "\n";
43+
std::cout << " Name: " << dev.get_info<info::name>() << "\n";
44+
std::cout << " Vendor: " << dev.get_info<info::vendor>() << "\n";
45+
std::cout << " Version: " << dev.get_info<info::version>() << "\n";
46+
std::cout << " Driver version: " << dev.get_info<info::driver_version>() << "\n";
47+
std::cout << " Double supported: " << supports_double_str << "\n";
48+
std::cout << " USM supported: " << supports_usm_str << "\n";
49+
std::cout << " Subgroup sizes: " << subgroup_sizes_str << "\n";
50+
std::cout << " Local memory size: " << local_memory_size << "B\n";
51+
std::cout << std::endl;
52+
}
53+
54+
TEST(print_info, device) { print_device_info(); }

0 commit comments

Comments
 (0)