From 5ea603dc8055a65f50f89d90973403e8cef78ffc Mon Sep 17 00:00:00 2001 From: dujinhang Date: Sat, 28 Oct 2023 20:12:44 +0800 Subject: [PATCH] [fix] lack of synchronization with 'max_split_size_mb' variable. --- torch_npu/csrc/core/npu/NPUCachingAllocator.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/torch_npu/csrc/core/npu/NPUCachingAllocator.cpp b/torch_npu/csrc/core/npu/NPUCachingAllocator.cpp index 8b16502c81..cc631b4748 100644 --- a/torch_npu/csrc/core/npu/NPUCachingAllocator.cpp +++ b/torch_npu/csrc/core/npu/NPUCachingAllocator.cpp @@ -1058,6 +1058,9 @@ class DeviceCachingAllocator { key.size = (key.size < CachingAllocatorConfig::max_split_size()) ? CachingAllocatorConfig::max_split_size() : key.size; auto it = pool.blocks.lower_bound(&key); + + c10_npu::npuSynchronizeDevice(true); + if (it == pool.blocks.end() || (*it)->stream != p.stream()) { // No single block is large enough; free multiple oversize blocks, starting with the largest if (it == pool.blocks.begin()){ -- Gitee