提交 0e797879 编写于 作者: 李寅

Swap out unused memory

上级 0102ad55
......@@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <unistd.h>
#include <sys/mman.h>
#include <memory>
#include "mace/ops/sgemm.h"
#include "mace/core/runtime/cpu/cpu_runtime.h"
#if defined(MACE_ENABLE_NEON)
#include <arm_neon.h>
#endif
......@@ -26,6 +27,28 @@
#define vaddvq_f32(v) ((v)[0] + (v)[1] + (v)[2] + (v)[3])
#endif
namespace {
inline void AdviseFree(void *addr, size_t length) {
int page_size = getpagesize();
void *addr_aligned =
reinterpret_cast<void *>(
(reinterpret_cast<uintptr_t>(addr) + page_size - 1)
& (~(page_size - 1)));
uintptr_t delta =
reinterpret_cast<uintptr_t>(addr_aligned)
- reinterpret_cast<uintptr_t>(addr);
if (length >= delta + page_size) {
size_t len_aligned = (length - delta) & (~(page_size - 1));
int ret = madvise(addr_aligned, len_aligned, MADV_DONTNEED);
if (ret != 0) {
LOG(ERROR) << "Advise free failed: " << strerror(errno);
}
}
}
} // namespace
namespace mace {
namespace ops {
......@@ -80,9 +103,17 @@ void SGemm::operator()(const MatrixMap<const float> &lhs,
if (!lhs.is_const() || !packed_) {
PackLhs(lhs, packed_lhs_.get());
if (lhs.is_const()) {
AdviseFree(reinterpret_cast<void *>(const_cast<float *>(lhs.data())),
lhs.size() * sizeof(float));
}
}
if (!rhs.is_const() || !packed_) {
PackRhs(rhs, packed_rhs_.get());
if (rhs.is_const()) {
AdviseFree(reinterpret_cast<void *>(const_cast<float *>(rhs.data())),
rhs.size() * sizeof(float));
}
}
packed_ = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册