wsl/hsakmt: add sub-allocator

Reviewed-by: Shane Xiao <shane.xiao@amd.com>
Reviewed-by: lyndonli <Lyndon.Li@amd.com>
Signed-off-by: tiancyin <tianci.yin@amd.com>
Цей коміт міститься в:
tiancyin
2024-10-22 15:02:36 +08:00
зафіксовано Frank Min
джерело b062a23dfa
коміт b4df74f198
5 змінених файлів з 190 додано та 18 видалено
+29 -1
Переглянути файл
@@ -51,7 +51,6 @@
#include <deque>
#include <utility>
#include "core/util/utils.h"
namespace wsl {
@@ -233,6 +232,35 @@ template <typename Allocator> class SimpleHeap {
return reinterpret_cast<void*>(base);
}
/* Return block-base the ptr belongs to if the ptr is a valid ptr which is allocated
* from this simpleheap and the block-base is allocated from block_allocator_*/
void* block_base(void* ptr) {
if (ptr == nullptr)
return nullptr;
uintptr_t base = reinterpret_cast<uintptr_t>(ptr);
// Find fragment and validate.
auto frag_map_it = block_list_.upper_bound(base);
if (frag_map_it == block_list_.begin())
return nullptr;
frag_map_it--;
auto& frag_map = frag_map_it->second;
auto fragment = frag_map.find(base);
if (fragment == frag_map.end() || isFree(fragment->second))
return nullptr;
return reinterpret_cast<void*>(frag_map_it->first);
}
void reset() {
free_list_.clear();
block_list_.clear();
block_cache_.clear();
in_use_size_ = 0;
cache_size_ = 0;
}
bool free(void* ptr) {
if (ptr == nullptr) return true;