2 Star 0 Fork 0

huangzhenyu/npu_cache_allocator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
EventPool.cpp 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
huangzhenyu 提交于 2024-02-07 20:32 . add files
//
// Created by hzy on 2024/2/7.
//
#include "EventPool.h"
EventPool::Event EventPool::get(int device) {
auto& pool = pools_[device];
auto destructor = [&pool](c10_npu::NPUEvent* event) {
std::lock_guard<std::mutex> g(pool.mutex_);
pool.event_pool_.push_back(std::unique_ptr<c10_npu::NPUEvent>(event));
};
// Try to acquire an event from the per-device pool.
{
std::lock_guard<std::mutex> g(pool.mutex_);
if (!pool.event_pool_.empty()) {
auto* event = pool.event_pool_.back().release();
pool.event_pool_.pop_back();
return Event(event, destructor);
}
}
// otherwise, allocate a new event that will be returned to the pool on
// destruction.
return Event(std::make_unique<c10_npu::NPUEvent>(ACL_EVENT_CAPTURE_STREAM_PROGRESS).release(), destructor);
}
void EventPool::empty_cache() {
for (auto &pool : pools_) {
std::lock_guard<std::mutex> g(pool.mutex_);
pool.event_pool_.clear();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/heziiop/npu_cache_allocator.git
[email protected]:heziiop/npu_cache_allocator.git
heziiop
npu_cache_allocator
npu_cache_allocator
master

搜索帮助