From 0267af380e93147b8ff010e454badc48f2954d74 Mon Sep 17 00:00:00 2001 From: huafengchun Date: Thu, 11 Jul 2024 02:57:26 +0000 Subject: [PATCH] fix vmm free error --- ggml/src/ggml-cann.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml-cann.cpp b/ggml/src/ggml-cann.cpp index 676149b526205b..78426141a1653e 100644 --- a/ggml/src/ggml-cann.cpp +++ b/ggml/src/ggml-cann.cpp @@ -183,6 +183,7 @@ struct ggml_cann_pool_vmm : public ggml_cann_pool { size_t pool_size = 0; size_t granularity; std::vector handles; + std::vector map_offsets; explicit ggml_cann_pool_vmm(int device) : device(device), @@ -191,7 +192,9 @@ struct ggml_cann_pool_vmm : public ggml_cann_pool { ~ggml_cann_pool_vmm() { if (pool_addr != 0) { - ACL_CHECK(aclrtUnmapMem(pool_addr)); + for(auto& offset : map_offsets){ + ACL_CHECK(aclrtUnmapMem(offset)); + } for (auto& handle : handles) { ACL_CHECK(aclrtFreePhysical(handle)); } @@ -233,6 +236,7 @@ struct ggml_cann_pool_vmm : public ggml_cann_pool { ACL_CHECK(aclrtMapMem((char*)pool_addr + pool_size, reserve_size, 0, handle, 0)); handles.push_back(handle); + map_offsets.push_back((char*)pool_addr + pool_size); // add to the pool pool_size += reserve_size;