-
Notifications
You must be signed in to change notification settings - Fork 94
Open
Description
At Tensor.cpp
void Tensor::activate() {
NNTR_THROW_IF(!is_virtual, std::invalid_argument)
<< "non-virtual tensor cannot call activate()";
#if defined(_WIN32)
NNTR_THROW_IF(true, std::invalid_argument)
<< "[Error/VirtualTensor] virtual tensor is not supported on Windows";
#else
auto file_offset = getFileOffset();
size_t off = (file_offset / 4096) * 4096;
size_t diff = file_offset - off;
size_t len = getMemoryBytes() + diff;
mapped_ptr = mmap(NULL, len, PROT_READ, MAP_PRIVATE, this->fd, off);
#ifdef __ANDROID__
madvise(mapped_ptr, len, MADV_WILLNEED);
#endif
if (mapped_ptr == MAP_FAILED) {
std::cerr << "[activate] mmap failed: " << strerror(errno) << std::endl;
}
itensor_->activate((void *)&((uint8_t *)mapped_ptr)[diff]);
#endif
}
void Tensor::deactivate() {
NNTR_THROW_IF(!is_virtual, std::invalid_argument)
<< "non-virtual tensor cannot call deactivate()";
#if defined(_WIN32)
NNTR_THROW_IF(true, std::invalid_argument)
<< "[Error/VirtualTensor] virtual tensor is not supported on Windows";
#else
if (mapped_ptr == nullptr) {
return;
};
auto file_offset = getFileOffset();
size_t off = (file_offset / 4096) * 4096;
size_t diff = file_offset - off;
size_t len = getMemoryBytes() + diff;
auto ret_munmap = munmap((void *)mapped_ptr, len);
const size_t error_buflen = 100;
char error_buf[error_buflen];
NNTR_THROW_IF(ret_munmap == -1, std::runtime_error)
<< "[deactivate] munmap failed: "
<< SAFE_STRERROR(errno, error_buf, error_buflen);
mapped_ptr = nullptr;
itensor_->deactivate();
#endif
}we didn't implement auto release mapped_ptr
i will fix & close this issue
Metadata
Metadata
Assignees
Labels
No labels