diff --git a/sycl/include/syclcompat/device.hpp b/sycl/include/syclcompat/device.hpp index 4017ee177a279..4e227a635c44e 100644 --- a/sycl/include/syclcompat/device.hpp +++ b/sycl/include/syclcompat/device.hpp @@ -425,6 +425,12 @@ class device_ext : public sycl::device { } void get_device_info(device_info &out) const { + if (_dev_info) { + out = *_dev_info; + return; + } + + std::lock_guard lock(m_mutex); device_info prop; prop.set_name(get_info().c_str()); @@ -439,8 +445,8 @@ class device_ext : public sycl::device { // max_work_item_sizes is an enum class element get_info()); #else - // SYCL 2020-conformant code, max_work_item_sizes is a struct templated - // by an int + // SYCL 2020-conformant code, max_work_item_sizes is a struct + // templated by an int get_info>()); #endif prop.set_host_unified_memory(has(sycl::aspect::usm_host_allocations)); @@ -512,8 +518,8 @@ Use 64 bits as memory_bus_width default value." prop.set_max_nd_range_size(max_nd_range_size); #endif - // Estimates max register size per work group, feel free to update the value - // according to device properties. + // Estimates max register size per work group, feel free to update the + // value according to device properties. prop.set_max_register_size_per_work_group(65536); prop.set_global_mem_cache_size( @@ -526,13 +532,16 @@ Use 64 bits as memory_bus_width default value." prop.set_image3d_max(get_info(), get_info(), get_info()); + + _dev_info = prop; out = prop; } device_info get_device_info() const { - device_info prop; - get_device_info(prop); - return prop; + if (!_dev_info) { + this->get_device_info(*_dev_info); + } + return _dev_info.value(); } 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." std::vector> _queues; mutable std::mutex m_mutex; std::vector _events; + mutable std::optional _dev_info; }; namespace detail { diff --git a/sycl/test-e2e/syclcompat/device/device.cpp b/sycl/test-e2e/syclcompat/device/device.cpp index 60298e48a4106..180db72afc9f8 100644 --- a/sycl/test-e2e/syclcompat/device/device.cpp +++ b/sycl/test-e2e/syclcompat/device/device.cpp @@ -159,12 +159,19 @@ void test_device_ext_api() { auto major = dev_.get_major_version(); test_major_version(dev_, major); dev_.get_minor_version(); - dev_.get_max_compute_units(); dev_.get_max_clock_frequency(); dev_.get_integrated(); + + int max_cu = dev_.get_max_compute_units(); + int max_wg_size = dev_.get_max_work_group_size(); + size_t global_mem_size = dev_.get_global_mem_size(); + syclcompat::device_info Info; dev_.get_device_info(Info); - Info = dev_.get_device_info(); + assert(Info.get_max_compute_units() == max_cu); + assert(Info.get_max_work_group_size() == max_wg_size); + assert(Info.get_global_mem_size() == global_mem_size); + dev_.reset(); auto QueuePtr = dev_.default_queue(); dev_.queues_wait_and_throw();