提交 1437d6c4 编写于 作者: T tangshihua

bugfix map fd

Signed-off-by: Ntangshihua <tangshihua@huawei.com>
上级 82644f24
......@@ -42,6 +42,14 @@ MockIDevice::~MockIDevice()
}
}
MockIPreparedModel::~MockIPreparedModel()
{
for (auto ash : m_ashmems) {
ash.second->UnmapAshmem();
ash.second->CloseAshmem();
}
}
MockIDevice *MockIDevice::GetInstance()
{
static MockIDevice iDevice;
......@@ -148,6 +156,11 @@ int32_t MockIDevice::IsModelCacheSupported(bool& isSupported)
int32_t MockIDevice::AllocateBuffer(uint32_t length, SharedBuffer &buffer)
{
std::lock_guard<std::mutex> lock(m_mtx);
for(auto ash:m_ashmems){
if(ash.second->GetAshmemSize() <= 0){
ash.second->CloseAshmem();
}
}
sptr<Ashmem> ashptr = Ashmem::CreateAshmem("allocateBuffer", length);
if (ashptr == nullptr) {
LOGE("[NNRtTest] Create shared memory failed.");
......@@ -174,7 +187,6 @@ int32_t MockIDevice::ReleaseBuffer(const SharedBuffer &buffer)
std::lock_guard<std::mutex> lock(m_mtx);
auto ash = m_ashmems[buffer.fd];
ash->UnmapAshmem();
ash->CloseAshmem();
return HDF_SUCCESS;
}
......@@ -233,12 +245,16 @@ int32_t MockIPreparedModel::ExportModelCache(std::vector<SharedBuffer>& modelCac
return HDF_FAILURE;
}
int fd = cache->GetAshmemFd();
m_ashmems[fd] = cache;
ret = cache->WriteToAshmem(buffer, size, 0);
cache->UnmapAshmem();
if (!ret) {
LOGE("[NNRtTest] Write cache failed.");
return HDF_FAILURE;
}
// SharedBuffer: fd, bufferSize, offset, dataSize
modelCache.emplace_back(SharedBuffer {cache->GetAshmemFd(), cache->GetAshmemSize(), 0, cache->GetAshmemSize()});
return HDF_SUCCESS;
......
......@@ -111,6 +111,9 @@ public:
std::vector<std::vector<int32_t>>& outputsDims, std::vector<bool>& isOutputBufferEnough) override;
int32_t GetVersion(uint32_t &majorVersion, uint32_t &minorVersion) override;
MockIPreparedModel() = default;
virtual ~MockIPreparedModel();
private:
std::unordered_map<int, sptr<Ashmem>> m_ashmems;
};
} // namespace V1_0
......
......@@ -42,6 +42,14 @@ MockIDevice::~MockIDevice()
}
}
MockIPreparedModel::~MockIPreparedModel()
{
for (auto ash : m_ashmems) {
ash.second->UnmapAshmem();
ash.second->CloseAshmem();
}
}
MockIDevice *MockIDevice::GetInstance()
{
static MockIDevice iDevice;
......@@ -148,6 +156,11 @@ int32_t MockIDevice::IsModelCacheSupported(bool& isSupported)
int32_t MockIDevice::AllocateBuffer(uint32_t length, SharedBuffer &buffer)
{
std::lock_guard<std::mutex> lock(m_mtx);
for(auto ash:m_ashmems){
if(ash.second->GetAshmemSize() <= 0){
ash.second->CloseAshmem();
}
}
sptr<Ashmem> ashptr = Ashmem::CreateAshmem("allocateBuffer", length);
if (ashptr == nullptr) {
LOGE("[NNRtTest] Create shared memory failed.");
......@@ -238,6 +251,8 @@ int32_t MockIPreparedModel::ExportModelCache(std::vector<SharedBuffer>& modelCac
LOGE("[NNRtTest] Map fd to write cache failed.");
return HDF_FAILURE;
}
int fd = cache->GetAshmemFd();
m_ashmems[fd] = cache;
ret = cache->WriteToAshmem(buffer, size, 0);
cache->UnmapAshmem();
......
......@@ -115,6 +115,9 @@ public:
int32_t GetInputDimRanges(std::vector<std::vector<uint32_t>>& minInputDims, std::vector<std::vector<uint32_t>>& maxInputDims) override;
int32_t GetVersion(uint32_t &majorVersion, uint32_t &minorVersion) override;
MockIPreparedModel() = default;
virtual ~MockIPreparedModel();
private:
std::unordered_map<int, sptr<Ashmem>> m_ashmems;
};
} // namespace V2_0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册