Merged
fix(machine): Fix the incorrect memory pool free #5394
W4termyAdd on Aug 11
fix(machine): Fix the incorrect memory pool free #5394
Merged
Merged fromW4termy/pyptofix-intf-pub-cxx17intocann/pyptomaster
Total: 2 files changed+5-12
| @@ -68,16 +68,9 @@ uint8_t* KernelBundleDevCache::GetOrAllocCellMatch(uint64_t key, uint64_t bytes) | |||
| 68 | 68 | ||
| 69 | KernelBundleDevCache::~KernelBundleDevCache() | 69 | KernelBundleDevCache::~KernelBundleDevCache() |
| 70 | { | 70 | { |
| 71 | - // Release every cached device buffer at once. Runs only on a normal process exit; the STs use os._exit(0), | 71 | + // No free here: DevMemoryPool is a static destroyed before this one, and its DestroyPool() has already |
| 72 | - // which skips static destructors (the OS reclaims device memory on process death). | 72 | + // released every block. Freeing again would only hit an empty addrToBlock_ and raise FREE_FAILED. |
| 73 | - dynamic::DeviceMemoryUtils devMem(true); | ||
| 74 | - for (auto& kv : cache_) { | ||
| 75 | - devMem.Free(kv.second); | ||
| 76 | - } | ||
| 77 | cache_.clear(); | 73 | cache_.clear(); |
| 78 | - for (auto& kv : cellMatchCache_) { | ||
| 79 | - devMem.Free(kv.second.addr); | ||
| 80 | - } | ||
| 81 | cellMatchCache_.clear(); | 74 | cellMatchCache_.clear(); |
| 82 | } | 75 | } |
| 83 | 76 | ||
| @@ -14,7 +14,7 @@ | |||
| 14 | * | 14 | * |
| 15 | * The packed base-0 control-flow cache is copied host->device once per bundle (keyed by LoadedBundle::bundleKey, | 15 | * The packed base-0 control-flow cache is copied host->device once per bundle (keyed by LoadedBundle::bundleKey, |
| 16 | * a content digest -- NOT hashKey, which is equal across shape variants of one op) and reused across launches. | 16 | * a content digest -- NOT hashKey, which is equal across shape variants of one op) and reused across launches. |
| 17 | - * All cached device buffers are released together in the singleton destructor at process exit. | 17 | + * Cached device buffers live for the whole process; DevMemoryPool releases them at teardown. |
| 18 | */ | 18 | */ |
| 19 | 19 | ||
| 20 | #pragma once | 20 | #pragma once |
| @@ -31,12 +31,12 @@ public: | |||
| 31 | static KernelBundleDevCache& Instance(); | 31 | static KernelBundleDevCache& Instance(); |
| 32 | 32 | ||
| 33 | // Return the device pointer holding `hostCtrlCache` for `key`, copying host->device once and caching it for | 33 | // Return the device pointer holding `hostCtrlCache` for `key`, copying host->device once and caching it for |
| 34 | - // reuse. Returns nullptr when `hostCtrlCache` is empty. Freed only in the destructor at exit. | 34 | + // reuse. Returns nullptr when `hostCtrlCache` is empty. Held until process exit. |
| 35 | uint8_t* GetOrCopy(uint64_t key, const std::vector<uint8_t>& hostCtrlCache); | 35 | uint8_t* GetOrCopy(uint64_t key, const std::vector<uint8_t>& hostCtrlCache); |
| 36 | 36 | ||
| 37 | // Return a device buffer of at least `bytes` for bundle `key`'s cell-match metadata pool, allocated once and | 37 | // Return a device buffer of at least `bytes` for bundle `key`'s cell-match metadata pool, allocated once and |
| 38 | // reused (grown if a later launch needs more). Returns nullptr when bytes==0. The device inits the pool in | 38 | // reused (grown if a later launch needs more). Returns nullptr when bytes==0. The device inits the pool in |
| 39 | - // place, so no host->device copy here. Freed in the destructor. | 39 | + // place, so no host->device copy here. Held until process exit. |
| 40 | uint8_t* GetOrAllocCellMatch(uint64_t key, uint64_t bytes); | 40 | uint8_t* GetOrAllocCellMatch(uint64_t key, uint64_t bytes); |
| 41 | 41 | ||
| 42 | KernelBundleDevCache(const KernelBundleDevCache&) = delete; | 42 | KernelBundleDevCache(const KernelBundleDevCache&) = delete; |