@@ -25,12 +25,15 @@ from ._backend cimport ( # noqa: E211
2525 DPCTLCString_Delete,
2626 DPCTLDefaultSelector_Create,
2727 DPCTLDevice_AreEq,
28+ DPCTLDevice_CanAccessPeer,
2829 DPCTLDevice_Copy,
2930 DPCTLDevice_CreateFromSelector,
3031 DPCTLDevice_CreateSubDevicesByAffinity,
3132 DPCTLDevice_CreateSubDevicesByCounts,
3233 DPCTLDevice_CreateSubDevicesEqually,
3334 DPCTLDevice_Delete,
35+ DPCTLDevice_DisablePeerAccess,
36+ DPCTLDevice_EnablePeerAccess,
3437 DPCTLDevice_GetBackend,
3538 DPCTLDevice_GetComponentDevices,
3639 DPCTLDevice_GetCompositeDevice,
@@ -103,6 +106,7 @@ from ._backend cimport ( # noqa: E211
103106 _device_type,
104107 _global_mem_cache_type,
105108 _partition_affinity_domain_type,
109+ _peer_access,
106110)
107111
108112from .enum_types import backend_type, device_type, global_mem_cache_type
@@ -1792,6 +1796,108 @@ cdef class SyclDevice(_SyclDevice):
17921796 raise ValueError (" Internal error: NULL device vector encountered" )
17931797 return _get_devices(cDVRef)
17941798
1799+ def can_access_peer (self , peer ):
1800+ """ Returns ``True`` if `self` can enable peer access
1801+ to `peer`, ``False`` otherwise.
1802+
1803+ Args:
1804+ peer (dpctl.SyclDevice):
1805+ The :class:`dpctl.SyclDevice` instance to
1806+ check.
1807+
1808+ Returns:
1809+ bool:
1810+ ``True`` if `self` can enable peer access
1811+ to `peer`, otherwise ``False``.
1812+ """
1813+ cdef SyclDevice p_dev
1814+ if not isinstance (peer, SyclDevice):
1815+ raise TypeError (
1816+ " second argument must be a `dpctl.SyclDevice`, got "
1817+ f" {type(peer)}"
1818+ )
1819+ p_dev = < SyclDevice> peer
1820+ return DPCTLDevice_CanAccessPeer(
1821+ self ._device_ref,
1822+ p_dev.get_device_ref(),
1823+ _peer_access._access_supported
1824+ )
1825+
1826+ def can_access_peer_atomics_supported (self , peer ):
1827+ """ Returns ``True`` if `self` can enable peer access
1828+ to and can atomically modify memory on `peer`, ``False`` otherwise.
1829+
1830+ Args:
1831+ peer (dpctl.SyclDevice):
1832+ The :class:`dpctl.SyclDevice` instance to
1833+ check.
1834+
1835+ Returns:
1836+ bool:
1837+ ``True`` if `self` can enable peer access
1838+ to and can atomically modify memory on `peer`,
1839+ otherwise ``False``.
1840+ """
1841+ cdef SyclDevice p_dev
1842+ if not isinstance (peer, SyclDevice):
1843+ raise TypeError (
1844+ " second argument must be a `dpctl.SyclDevice`, got "
1845+ f" {type(peer)}"
1846+ )
1847+ p_dev = < SyclDevice> peer
1848+ return DPCTLDevice_CanAccessPeer(
1849+ self ._device_ref,
1850+ p_dev.get_device_ref(),
1851+ _peer_access._atomics_supported
1852+ )
1853+
1854+ def enable_peer_access (self , peer ):
1855+ """ Enables this device (`self`) to access USM device allocations
1856+ located on `peer`.
1857+
1858+ Args:
1859+ peer (dpctl.SyclDevice):
1860+ The :class:`dpctl.SyclDevice` instance to
1861+ enable peer access to.
1862+
1863+ Raises:
1864+ ValueError:
1865+ If the ``DPCTLDevice_GetComponentDevices`` call returned
1866+ ``NULL`` instead of a ``DPCTLDeviceVectorRef`` object.
1867+ """
1868+ cdef SyclDevice p_dev
1869+ if not isinstance (peer, SyclDevice):
1870+ raise TypeError (
1871+ " second argument must be a `dpctl.SyclDevice`, got "
1872+ f" {type(peer)}"
1873+ )
1874+ p_dev = < SyclDevice> peer
1875+ DPCTLDevice_EnablePeerAccess(self ._device_ref, p_dev.get_device_ref())
1876+ return
1877+
1878+ def disable_peer_access (self , peer ):
1879+ """ Disables peer access to `peer` from `self`.
1880+
1881+ Args:
1882+ peer (dpctl.SyclDevice):
1883+ The :class:`dpctl.SyclDevice` instance to
1884+ disable peer access to.
1885+
1886+ Raises:
1887+ ValueError:
1888+ If the ``DPCTLDevice_GetComponentDevices`` call returned
1889+ ``NULL`` instead of a ``DPCTLDeviceVectorRef`` object.
1890+ """
1891+ cdef SyclDevice p_dev
1892+ if not isinstance (peer, SyclDevice):
1893+ raise TypeError (
1894+ " second argument must be a `dpctl.SyclDevice`, got "
1895+ f" {type(peer)}"
1896+ )
1897+ p_dev = < SyclDevice> peer
1898+ DPCTLDevice_DisablePeerAccess(self ._device_ref, p_dev.get_device_ref())
1899+ return
1900+
17951901 @property
17961902 def profiling_timer_resolution (self ):
17971903 """ Profiling timer resolution.
0 commit comments