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>
Цей коміт міститься в:
@@ -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;
|
||||
|
||||
|
||||
Посилання в новій задачі
Заблокувати користувача