Skip to content

Commit d33ebfe

Browse files
committed
[XPU] avoid malloc redundant memory when creating context in comm manager
1 parent 90a82ae commit d33ebfe

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

paddle/phi/backends/xpu/xpu_context.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,11 @@ XPUContext::XPUContext() : DeviceContext() {
263263
}
264264
}
265265

266-
XPUContext::XPUContext(const XPUPlace& place) : DeviceContext() {
267-
if (std::getenv("XPU_CDNN_CLUSTER_PARALLEL") != nullptr) {
266+
XPUContext::XPUContext(const XPUPlace& place, bool is_comm_context) : DeviceContext() {
267+
if (is_comm_context) { // for communication context init, with gm_size=1 and l3_size=1
268+
impls_.push_back(std::make_unique<Impl>(place));
269+
impls_[0]->Init(1, 1);
270+
} else if (std::getenv("XPU_CDNN_CLUSTER_PARALLEL") != nullptr) {
268271
int default_num_stream = 4;
269272
if (std::getenv("XPU_CDNN_CLUSTER_PARALLEL_STREAM_NUMBER") != nullptr) {
270273
default_num_stream =

paddle/phi/backends/xpu/xpu_context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class XPUContext : public DeviceContext,
3838
public:
3939
XPUContext();
4040

41-
explicit XPUContext(const XPUPlace&);
41+
// is_comm_context = 1 for init comm context with gm_size=1 and l3_size=1
42+
explicit XPUContext(const XPUPlace&, bool is_comm_context = 0);
4243

4344
virtual ~XPUContext();
4445

paddle/phi/core/distributed/comm_context_manager.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ void CommContextManager::CreateBKCLCommContext(
211211
std::make_unique<BKCLCommContext>(rank, size, bkcl_id);
212212

213213
if (CommContextManager::device_id != -1) {
214+
bool is_comm_context = 1;
214215
std::unique_ptr<phi::XPUContext> dev_ctx(
215-
new phi::XPUContext(phi::XPUPlace(CommContextManager::device_id)));
216+
new phi::XPUContext(phi::XPUPlace(CommContextManager::device_id), is_comm_context));
216217
dev_ctx->SetAllocator(phi::memory_utils::GetAllocator(
217218
CommContextManager::device_id, dev_ctx->stream()));
218219
dev_ctx->SetHostAllocator(phi::memory_utils::GetHostAllocator());

0 commit comments

Comments
 (0)