@@ -217,6 +217,28 @@ cdef void _init_helper(_SyclDevice device, DPCTLSyclDeviceRef DRef) except *:
217
217
raise RuntimeError (" Descriptor 'max_work_item_sizes3d' not available" )
218
218
219
219
220
+ cdef bint _check_peer_access(SyclDevice dev, SyclDevice peer) except * :
221
+ """
222
+ Check peer access ahead of time to avoid errors from unified runtime or
223
+ compiler implementation.
224
+ """
225
+ cdef list _peer_access_backends = [
226
+ _backend_type._CUDA,
227
+ _backend_type._HIP,
228
+ _backend_type._LEVEL_ZERO
229
+ ]
230
+ cdef _backend_type BTy1 = DPCTLDevice_GetBackend(dev._device_ref)
231
+ cdef _backend_type BTy2 = DPCTLDevice_GetBackend(peer.get_device_ref())
232
+ if (
233
+ BTy1 == BTy2 and
234
+ BTy1 in _peer_access_backends and
235
+ BTy2 in _peer_access_backends and
236
+ dev != peer
237
+ ):
238
+ return True
239
+ return False
240
+
241
+
220
242
@ functools.lru_cache (maxsize = None )
221
243
def _cached_filter_string (d : SyclDevice ):
222
244
"""
@@ -1819,13 +1841,8 @@ cdef class SyclDevice(_SyclDevice):
1819
1841
Raises:
1820
1842
TypeError:
1821
1843
If ``peer`` is not :class:`dpctl.SyclDevice`.
1822
- ValueError:
1823
- If the backend associated with this device or ``peer`` does not
1824
- support peer access.
1825
1844
"""
1826
1845
cdef SyclDevice p_dev
1827
- cdef _backend_type BTy1
1828
- cdef _backend_type BTy2
1829
1846
1830
1847
if not isinstance (peer, SyclDevice):
1831
1848
raise TypeError (
@@ -1834,29 +1851,13 @@ cdef class SyclDevice(_SyclDevice):
1834
1851
)
1835
1852
p_dev = < SyclDevice> peer
1836
1853
1837
- _peer_access_backends = [
1838
- _backend_type._CUDA,
1839
- _backend_type._HIP,
1840
- _backend_type._LEVEL_ZERO
1841
- ]
1842
- BTy1 = DPCTLDevice_GetBackend(self ._device_ref)
1843
- if BTy1 not in _peer_access_backends:
1844
- raise ValueError (
1845
- " Peer access not supported for this device backend "
1846
- f" {_backend_type_to_filter_string_part(BTy1)}"
1854
+ if _check_peer_access(self , p_dev):
1855
+ return DPCTLDevice_CanAccessPeer(
1856
+ self ._device_ref,
1857
+ p_dev.get_device_ref(),
1858
+ _peer_access._access_supported
1847
1859
)
1848
- BTy2 = DPCTLDevice_GetBackend(p_dev.get_device_ref())
1849
- if BTy2 not in _peer_access_backends:
1850
- raise ValueError (
1851
- " Peer access not supported for peer device backend "
1852
- f" {_backend_type_to_filter_string_part(BTy2)}"
1853
- )
1854
-
1855
- return DPCTLDevice_CanAccessPeer(
1856
- self ._device_ref,
1857
- p_dev.get_device_ref(),
1858
- _peer_access._access_supported
1859
- )
1860
+ return False
1860
1861
1861
1862
def can_access_peer_atomics_supported (self , peer ):
1862
1863
""" Returns ``True`` if this device (``self``) can concurrently access
@@ -1883,13 +1884,8 @@ cdef class SyclDevice(_SyclDevice):
1883
1884
Raises:
1884
1885
TypeError:
1885
1886
If ``peer`` is not :class:`dpctl.SyclDevice`.
1886
- ValueError:
1887
- If the backend associated with this device or ``peer`` does not
1888
- support peer access.
1889
1887
"""
1890
1888
cdef SyclDevice p_dev
1891
- cdef _backend_type BTy1
1892
- cdef _backend_type BTy2
1893
1889
1894
1890
if not isinstance (peer, SyclDevice):
1895
1891
raise TypeError (
@@ -1898,29 +1894,13 @@ cdef class SyclDevice(_SyclDevice):
1898
1894
)
1899
1895
p_dev = < SyclDevice> peer
1900
1896
1901
- _peer_access_backends = [
1902
- _backend_type._CUDA,
1903
- _backend_type._HIP,
1904
- _backend_type._LEVEL_ZERO
1905
- ]
1906
- BTy1 = DPCTLDevice_GetBackend(self ._device_ref)
1907
- if BTy1 not in _peer_access_backends:
1908
- raise ValueError (
1909
- " Peer access not supported for this device backend "
1910
- f" {_backend_type_to_filter_string_part(BTy1)}"
1897
+ if _check_peer_access(self , p_dev):
1898
+ return DPCTLDevice_CanAccessPeer(
1899
+ self ._device_ref,
1900
+ p_dev.get_device_ref(),
1901
+ _peer_access._atomics_supported
1911
1902
)
1912
- BTy2 = DPCTLDevice_GetBackend(p_dev.get_device_ref())
1913
- if BTy2 not in _peer_access_backends:
1914
- raise ValueError (
1915
- " Peer access not supported for peer device backend "
1916
- f" {_backend_type_to_filter_string_part(BTy2)}"
1917
- )
1918
-
1919
- return DPCTLDevice_CanAccessPeer(
1920
- self ._device_ref,
1921
- p_dev.get_device_ref(),
1922
- _peer_access._atomics_supported
1923
- )
1903
+ return False
1924
1904
1925
1905
def enable_peer_access (self , peer ):
1926
1906
""" Enables this device (``self``) to access USM device allocations
@@ -1944,8 +1924,6 @@ cdef class SyclDevice(_SyclDevice):
1944
1924
support peer access.
1945
1925
"""
1946
1926
cdef SyclDevice p_dev
1947
- cdef _backend_type BTy1
1948
- cdef _backend_type BTy2
1949
1927
1950
1928
if not isinstance (peer, SyclDevice):
1951
1929
raise TypeError (
@@ -1954,27 +1932,13 @@ cdef class SyclDevice(_SyclDevice):
1954
1932
)
1955
1933
p_dev = < SyclDevice> peer
1956
1934
1957
- _peer_access_backends = [
1958
- _backend_type._CUDA,
1959
- _backend_type._HIP,
1960
- _backend_type._LEVEL_ZERO
1961
- ]
1962
- BTy1 = (
1963
- DPCTLDevice_GetBackend(self ._device_ref)
1964
- )
1965
- if BTy1 not in _peer_access_backends:
1966
- raise ValueError (
1967
- " Peer access not supported for this device backend "
1968
- f" {_backend_type_to_filter_string_part(BTy1)}"
1935
+ if _check_peer_access(self , p_dev):
1936
+ DPCTLDevice_EnablePeerAccess(
1937
+ self ._device_ref,
1938
+ p_dev.get_device_ref()
1969
1939
)
1970
- BTy2 = DPCTLDevice_GetBackend(p_dev.get_device_ref())
1971
- if BTy2 not in _peer_access_backends:
1972
- raise ValueError (
1973
- " Peer access not supported for peer device backend "
1974
- f" {_backend_type_to_filter_string_part(BTy2)}"
1975
- )
1976
-
1977
- DPCTLDevice_EnablePeerAccess(self ._device_ref, p_dev.get_device_ref())
1940
+ else :
1941
+ raise ValueError (" Peer access cannot be enabled for these devices" )
1978
1942
return
1979
1943
1980
1944
def disable_peer_access (self , peer ):
@@ -1998,8 +1962,6 @@ cdef class SyclDevice(_SyclDevice):
1998
1962
support peer access.
1999
1963
"""
2000
1964
cdef SyclDevice p_dev
2001
- cdef _backend_type BTy1
2002
- cdef _backend_type BTy2
2003
1965
2004
1966
if not isinstance (peer, SyclDevice):
2005
1967
raise TypeError (
@@ -2008,25 +1970,13 @@ cdef class SyclDevice(_SyclDevice):
2008
1970
)
2009
1971
p_dev = < SyclDevice> peer
2010
1972
2011
- _peer_access_backends = [
2012
- _backend_type._CUDA,
2013
- _backend_type._HIP,
2014
- _backend_type._LEVEL_ZERO
2015
- ]
2016
- BTy1 = DPCTLDevice_GetBackend(self ._device_ref)
2017
- if BTy1 not in _peer_access_backends:
2018
- raise ValueError (
2019
- " Peer access not supported for this device backend "
2020
- f" {_backend_type_to_filter_string_part(BTy1)}"
1973
+ if _check_peer_access(self , p_dev):
1974
+ DPCTLDevice_DisablePeerAccess(
1975
+ self ._device_ref,
1976
+ p_dev.get_device_ref()
2021
1977
)
2022
- BTy2 = DPCTLDevice_GetBackend(p_dev.get_device_ref())
2023
- if BTy2 not in _peer_access_backends:
2024
- raise ValueError (
2025
- " Peer access not supported for peer device backend "
2026
- f" {_backend_type_to_filter_string_part(BTy2)}"
2027
- )
2028
-
2029
- DPCTLDevice_DisablePeerAccess(self ._device_ref, p_dev.get_device_ref())
1978
+ else :
1979
+ raise ValueError (" Peer access cannot be enabled for these devices" )
2030
1980
return
2031
1981
2032
1982
@property
0 commit comments