Skip to content

Commit b68d6fe

Browse files
[SYCL][COMPAT] Enabled device_info caching within device_ext (#14630)
This patch introduces a simple memoization mechanism within `device_ext` by caching the `device_info`, which helps avoid redundant/unnecessary queries of the full device infos whenever a single device info _(`max_wg_size` for e.g.)_ is requested. API Tests in `device_ext_api` have been slightly modified to verify some of the expected new changes to `get_device_info` methods.
1 parent a075b94 commit b68d6fe

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

sycl/include/syclcompat/device.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ class device_ext : public sycl::device {
425425
}
426426

427427
void get_device_info(device_info &out) const {
428+
if (_dev_info) {
429+
out = *_dev_info;
430+
return;
431+
}
432+
433+
std::lock_guard<std::mutex> lock(m_mutex);
428434
device_info prop;
429435
prop.set_name(get_info<sycl::info::device::name>().c_str());
430436

@@ -439,8 +445,8 @@ class device_ext : public sycl::device {
439445
// max_work_item_sizes is an enum class element
440446
get_info<sycl::info::device::max_work_item_sizes>());
441447
#else
442-
// SYCL 2020-conformant code, max_work_item_sizes is a struct templated
443-
// by an int
448+
// SYCL 2020-conformant code, max_work_item_sizes is a struct
449+
// templated by an int
444450
get_info<sycl::info::device::max_work_item_sizes<3>>());
445451
#endif
446452
prop.set_host_unified_memory(has(sycl::aspect::usm_host_allocations));
@@ -512,8 +518,8 @@ Use 64 bits as memory_bus_width default value."
512518
prop.set_max_nd_range_size(max_nd_range_size);
513519
#endif
514520
515-
// Estimates max register size per work group, feel free to update the value
516-
// according to device properties.
521+
// Estimates max register size per work group, feel free to update the
522+
// value according to device properties.
517523
prop.set_max_register_size_per_work_group(65536);
518524
519525
prop.set_global_mem_cache_size(
@@ -526,13 +532,16 @@ Use 64 bits as memory_bus_width default value."
526532
prop.set_image3d_max(get_info<sycl::info::device::image3d_max_width>(),
527533
get_info<sycl::info::device::image3d_max_height>(),
528534
get_info<sycl::info::device::image3d_max_height>());
535+
536+
_dev_info = prop;
529537
out = prop;
530538
}
531539
532540
device_info get_device_info() const {
533-
device_info prop;
534-
get_device_info(prop);
535-
return prop;
541+
if (!_dev_info) {
542+
this->get_device_info(*_dev_info);
543+
}
544+
return _dev_info.value();
536545
}
537546
538547
void reset(bool print_on_async_exceptions = false, bool in_order = true) {
@@ -683,6 +692,7 @@ Use 64 bits as memory_bus_width default value."
683692
std::vector<std::shared_ptr<sycl::queue>> _queues;
684693
mutable std::mutex m_mutex;
685694
std::vector<sycl::event> _events;
695+
mutable std::optional<device_info> _dev_info;
686696
};
687697
688698
namespace detail {

sycl/test-e2e/syclcompat/device/device.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,19 @@ void test_device_ext_api() {
159159
auto major = dev_.get_major_version();
160160
test_major_version(dev_, major);
161161
dev_.get_minor_version();
162-
dev_.get_max_compute_units();
163162
dev_.get_max_clock_frequency();
164163
dev_.get_integrated();
164+
165+
int max_cu = dev_.get_max_compute_units();
166+
int max_wg_size = dev_.get_max_work_group_size();
167+
size_t global_mem_size = dev_.get_global_mem_size();
168+
165169
syclcompat::device_info Info;
166170
dev_.get_device_info(Info);
167-
Info = dev_.get_device_info();
171+
assert(Info.get_max_compute_units() == max_cu);
172+
assert(Info.get_max_work_group_size() == max_wg_size);
173+
assert(Info.get_global_mem_size() == global_mem_size);
174+
168175
dev_.reset();
169176
auto QueuePtr = dev_.default_queue();
170177
dev_.queues_wait_and_throw();

0 commit comments

Comments
 (0)