Skip to content

Commit

Permalink
fix vmm free error
Browse files Browse the repository at this point in the history
  • Loading branch information
hipudding committed Jul 11, 2024
1 parent b12a40f commit 0267af3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ggml/src/ggml-cann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ struct ggml_cann_pool_vmm : public ggml_cann_pool {
size_t pool_size = 0;
size_t granularity;
std::vector<aclrtDrvMemHandle> handles;
std::vector<void*> map_offsets;

explicit ggml_cann_pool_vmm(int device) :
device(device),
Expand All @@ -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));
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0267af3

Please sign in to comment.