已合并
release gil when AclSetCompileopt #23629
huangyunlong创建于 2025年8月4日
release gil when AclSetCompileopt #23629
已合并
huangyunlong创建于 2025年8月4日
refs/pull/23629/head合入到v2.7.1
2 个文件变更+17-9
Atest/npu/test_pin_memory_withoutsetdevice.py+16-0
@@ -0,0 +1,16 @@
1+import torch
2+from torch.testing._internal.common_utils import TestCase, run_tests
3+ 
4+import torch_npu
5+ 
6+ 
7+class TestPinMemory(TestCase):
8+ 
9+ def test_pin_memory(self):
10+ # pin_memory -> getPinnedMemoryAllocator -> Initialize -> InitAclops -> aclSetCompileopt
11+ # now pin_memory hold gil, aclSetCompileopt will fail if we don't release gil
12+ pin_tensor = torch.tensor((2, 3), pin_memory=True)
13+ 
14+ 
15+if __name__ == '__main__':
16+ run_tests()
Mtorch_npu/csrc/framework/LazyInitAclops.cpp+1-9
@@ -191,18 +191,10 @@ void LazyInitAclops()
191 }191 }
192}192}
193 193 
194-void InitAclopsCore()
195-{
196- SetPrecisionMode();
197- MakeCompileCacheDirAndSetOption();
198- GetAndSetDefaultJitCompileByAcl();
199- SetHF32DefaultValue();
200-}
201- 
202void InitAclops()194void InitAclops()
203{195{
204 RECORD_FUNCTION("InitAclops", std::vector<c10::IValue>({}));196 RECORD_FUNCTION("InitAclops", std::vector<c10::IValue>({}));
205- InitAclopsCore();197+ LazyInitAclopsCore();
206 ASCEND_LOGI("Init for aclops finished.")198 ASCEND_LOGI("Init for aclops finished.")
207}199}
208 200