Conversation
… pool implementation Signed-off-by: Ceng23333 <441651826@qq.com>
PanZezhong1725
requested changes
Oct 21, 2025
| # Memory Statistics Functions | ||
| # ============================================================================== | ||
|
|
||
| def print_memory_stats(title="Memory Statistics", show_detailed=False): |
Collaborator
There was a problem hiding this comment.
这个函数和matmul有关吗,为什么会在matmul的测试脚本里
| thread_local Runtime *ContextImpl::current_runtime_ = nullptr; | ||
|
|
||
| Runtime *ContextImpl::getCurrentRuntime() { | ||
| if (current_runtime_ == nullptr) { |
Collaborator
There was a problem hiding this comment.
context的构造器应该已经保证了一定有建好的runtime,什么时候get current runtime会是nullptr?
Collaborator
Author
There was a problem hiding this comment.
这种闭包用法会出现current runtime未初始化
`
const int allocations_per_thread = 100;
std::vector<std::thread> threads;
std::atomic<int> success_count{0};
std::atomic<int> failure_count{0};
for (int i = 0; i < num_threads_; ++i) {
threads.emplace_back([&, i]() {
try {
for (int j = 0; j < allocations_per_thread; ++j) {
// Allocate memory of random size
size_t size = 64 + (j % 1024);
spdlog::debug("Thread {}: ConcurrentAllocations: Allocating memory of size {}", i, size);
auto memory = context::allocateMemory(size);
spdlog::debug("Thread {}: ConcurrentAllocations: Memory allocated successfully", i);
if (memory && memory->size() == size) {
success_count++;
} else {
failure_count++;
}
// Small delay to increase chance of race conditions
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
} catch (const std::exception &e) {
failure_count++;
std::cerr << "Thread " << i << " failed: " << e.what() << std::endl;
}
});
}
`
Collaborator
There was a problem hiding this comment.
明白了,创建新的线程的时候会是nullptr。这是个bug,要不单独提pr修复一下吧
| : ptr(p), size(s), ref_count(1), is_freed(false) {} | ||
| }; | ||
|
|
||
| class MemoryPool { |
Collaborator
There was a problem hiding this comment.
include目录下都是会暴露给外部的接口,这个设计是要把memory pool的接口暴露给外部吗?什么情况下用户或者上层框架需要直接和memory pool交互?
| stats_.allocation[static_cast<size_t>(StatType::AGGREGATE)].increase(1); | ||
| stats_.requested_bytes[static_cast<size_t>(StatType::AGGREGATE)].increase(size); | ||
|
|
||
| INFINICORE_CHECK_ERROR(infinirtMallocAsync(&ptr, size, context::getStream())); |
Collaborator
There was a problem hiding this comment.
你这不还是用的原生的mallocAsync接口,那你的内存池用哪了?
|
|
||
| namespace infinicore { | ||
|
|
||
| MemoryPool &MemoryPool::instance() { |
Collaborator
There was a problem hiding this comment.
为什么memory pool是 singleton的设计
Signed-off-by: Ceng23333 <441651826@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add memory usage stats from allocator && mem ref count, mem pool implementation
#513