Skip to content

Commit 95df4ec

Browse files
[NFCI][SYCL] Generalize device_impl's properties caching (#18476)
I think this is better than a simpler #18450 as it allows much easier experiments/tuning on what should be cached and how.
1 parent 45db185 commit 95df4ec

File tree

7 files changed

+261
-119
lines changed

7 files changed

+261
-119
lines changed

sycl/gdb/libsycl.so-gdb.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ def range_common_array(self):
374374
class SYCLDevice(SYCLValue):
375375
"""Provides information about a sycl::device from a gdb.Value."""
376376

377-
IMPL_OFFSET_TO_DEVICE_TYPE = 0x18
378-
IMPL_OFFSET_TO_PLATFORM = 0x28
377+
IMPL_OFFSET_TO_PLATFORM = 0x18
379378
PLATFORM_OFFSET_TO_BACKEND = 0x20
380379

381380
def __init__(self, gdb_value):
@@ -384,14 +383,6 @@ def __init__(self, gdb_value):
384383
def impl_ptr(self):
385384
return self.gdb_value()["impl"]["_M_ptr"]
386385

387-
def device_type(self):
388-
char_ptr = SYCLType.char_type().pointer()
389-
device_addr = self.impl_ptr().cast(char_ptr)
390-
device_type_addr = device_addr + self.IMPL_OFFSET_TO_DEVICE_TYPE
391-
uint32t_ptr = gdb.lookup_type("uint32_t").pointer()
392-
device_type = device_type_addr.cast(uint32t_ptr).dereference()
393-
return device_type
394-
395386
def backend(self):
396387
char_ptr = SYCLType.char_type().pointer()
397388
impl_ptr = self.impl_ptr().cast(char_ptr)

sycl/source/detail/device_impl.cpp

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,15 @@ namespace detail {
2424
device_impl::device_impl(ur_device_handle_t Device, platform_impl &Platform,
2525
device_impl::private_tag)
2626
: MDevice(Device), MPlatform(Platform.shared_from_this()),
27-
MDeviceHostBaseTime(std::make_pair(0, 0)) {
28-
const AdapterPtr &Adapter = Platform.getAdapter();
29-
30-
// TODO catch an exception and put it to list of asynchronous exceptions
31-
MType = get_info_impl<UR_DEVICE_INFO_TYPE>();
32-
33-
// No need to set MRootDevice when MAlwaysRootDevice is true
34-
// TODO: Is get_info aligned with this?
35-
if (!Platform.MAlwaysRootDevice) {
36-
// TODO catch an exception and put it to list of asynchronous exceptions
37-
MRootDevice = get_info_impl<UR_DEVICE_INFO_PARENT_DEVICE>();
38-
}
39-
40-
// TODO catch an exception and put it to list of asynchronous exceptions
27+
// No need to set MRootDevice when MAlwaysRootDevice is true
28+
MRootDevice(Platform.MAlwaysRootDevice
29+
? nullptr
30+
: get_info_impl<UR_DEVICE_INFO_PARENT_DEVICE>()),
31+
// TODO catch an exception and put it to list of asynchronous exceptions:
32+
MCache{*this} {
4133
// Interoperability Constructor already calls DeviceRetain in
4234
// urDeviceCreateWithNativeHandle.
43-
Adapter->call<UrApiKind::urDeviceRetain>(MDevice);
44-
45-
MUseNativeAssert = get_info_impl<UR_DEVICE_INFO_USE_NATIVE_ASSERT>();
35+
getAdapter()->call<UrApiKind::urDeviceRetain>(MDevice);
4636
}
4737

4838
device_impl::~device_impl() {
@@ -415,7 +405,7 @@ bool device_impl::has(aspect Aspect) const {
415405
case aspect::ext_oneapi_srgb:
416406
return get_info<info::device::ext_oneapi_srgb>();
417407
case aspect::ext_oneapi_native_assert:
418-
return useNativeAssert();
408+
return get_info_impl<UR_DEVICE_INFO_USE_NATIVE_ASSERT>();
419409
case aspect::ext_oneapi_cuda_async_barrier: {
420410
return get_info_impl_nocheck<UR_DEVICE_INFO_ASYNC_BARRIER>().value_or(0);
421411
}
@@ -649,24 +639,6 @@ bool device_impl::has(aspect Aspect) const {
649639
return false; // This device aspect has not been implemented yet.
650640
}
651641

652-
bool device_impl::useNativeAssert() const { return MUseNativeAssert; }
653-
654-
std::string device_impl::getDeviceName() const {
655-
std::call_once(MDeviceNameFlag,
656-
[this]() { MDeviceName = get_info<info::device::name>(); });
657-
658-
return MDeviceName;
659-
}
660-
661-
ext::oneapi::experimental::architecture device_impl::getDeviceArch() const {
662-
std::call_once(MDeviceArchFlag, [this]() {
663-
MDeviceArch =
664-
get_info<ext::oneapi::experimental::info::device::architecture>();
665-
});
666-
667-
return MDeviceArch;
668-
}
669-
670642
// On the first call this function queries for device timestamp
671643
// along with host synchronized timestamp and stores it in member variable
672644
// MDeviceHostBaseTime. Subsequent calls to this function would just retrieve

0 commit comments

Comments
 (0)