Skip to content

Commit e927ca9

Browse files
committed
Update
[ghstack-poisoned]
1 parent f9bd0f4 commit e927ca9

4 files changed

Lines changed: 37 additions & 13 deletions

File tree

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
#pragma once
22

3-
#include <c10/core/Device.h>
4-
#include <c10/macros/Macros.h>
3+
#include <c10/xpu/PeerToPeerAccess.h>
4+
5+
#include <ATen/Context.h>
56

67
namespace at::xpu {
78
namespace detail {
8-
void init_p2p_access_cache(c10::DeviceIndex num_devices);
9+
// Initialize the peer-to-peer access cache for XPU devices.
10+
inline void init_p2p_access_cache(c10::DeviceIndex num_devices) {
11+
c10::xpu::detail::init_p2p_access_cache(num_devices);
12+
}
913
} // namespace detail
1014

11-
TORCH_XPU_API bool get_p2p_access(
15+
// Query if peer-to-peer access is available between two devices.
16+
// This wrapper ensures XPU lazy initialization before forwarding to c10.
17+
inline bool get_p2p_access(
1218
c10::DeviceIndex dev,
13-
c10::DeviceIndex dev_to_access);
19+
c10::DeviceIndex dev_to_access) {
20+
at::globalContext().lazyInitDevice(c10::DeviceType::XPU);
21+
return c10::xpu::get_p2p_access(dev, dev_to_access);
22+
}
1423

1524
} // namespace at::xpu

c10/xpu/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ configure_file(
1515
${CMAKE_BINARY_DIR}/c10/xpu/impl/xpu_cmake_macros.h)
1616

1717
set(C10_XPU_SRCS
18+
PeerToPeerAccess.cpp
1819
XPUCachingAllocator.cpp
1920
XPUFunctions.cpp
2021
XPUStream.cpp
2122
impl/XPUGuardImpl.cpp
2223
)
2324
set(C10_XPU_HEADERS
25+
PeerToPeerAccess.h
2426
XPUCachingAllocator.h
2527
XPUDeviceProp.h
2628
XPUException.h
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#include <ATen/xpu/PeerToPeerAccess.h>
2-
#include <ATen/xpu/XPUContext.h>
3-
4-
#include <c10/util/Exception.h>
51
#include <c10/util/irange.h>
2+
#include <c10/xpu/PeerToPeerAccess.h>
63
#include <c10/xpu/XPUCachingAllocator.h>
74

8-
namespace at::xpu {
5+
namespace c10::xpu {
96

107
// p2pAccessEnabled_ is a flattened 2D matrix of size [num_devices x
118
// num_devices].
@@ -35,8 +32,6 @@ void init_p2p_access_cache(c10::DeviceIndex num_devices) {
3532
} // namespace detail
3633

3734
bool get_p2p_access(c10::DeviceIndex dev, c10::DeviceIndex dev_to_access) {
38-
at::globalContext().lazyInitDevice(c10::DeviceType::XPU);
39-
4035
check_device_index(dev);
4136
check_device_index(dev_to_access);
4237

@@ -60,4 +55,4 @@ bool get_p2p_access(c10::DeviceIndex dev, c10::DeviceIndex dev_to_access) {
6055
return static_cast<bool>(cache);
6156
}
6257

63-
} // namespace at::xpu
58+
} // namespace c10::xpu

c10/xpu/PeerToPeerAccess.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <c10/core/Device.h>
4+
#include <c10/macros/Macros.h>
5+
#include <c10/xpu/XPUMacros.h>
6+
7+
namespace c10::xpu {
8+
namespace detail {
9+
// Initialize the peer-to-peer access cache for XPU devices.
10+
C10_XPU_API void init_p2p_access_cache(c10::DeviceIndex num_devices);
11+
} // namespace detail
12+
13+
// Query if peer-to-peer access is available between two devices.
14+
C10_XPU_API bool get_p2p_access(
15+
c10::DeviceIndex dev,
16+
c10::DeviceIndex dev_to_access);
17+
18+
} // namespace c10::xpu

0 commit comments

Comments
 (0)