提交 43a362c6 编写于 作者: H hong19860320

fix bus error which occurs in some armv7 devices

test=develop
上级 51b5fdde
......@@ -14,15 +14,29 @@
#include "paddle/fluid/lite/core/target_wrapper.h"
#include <cstring>
#include <memory>
namespace paddle {
namespace lite {
const int MALLOC_ALIGN = 64;
void* TargetWrapper<TARGET(kHost)>::Malloc(size_t size) {
return new char[size];
size_t offset = sizeof(void*) + MALLOC_ALIGN - 1;
char* p = static_cast<char*>(malloc(offset + size));
if (!p) {
return nullptr;
}
void* r = reinterpret_cast<void*>(reinterpret_cast<size_t>(p + offset) &
(~(MALLOC_ALIGN - 1)));
static_cast<void**>(r)[-1] = p;
memset(r, 0, size);
return r;
}
void TargetWrapper<TARGET(kHost)>::Free(void* ptr) {
delete[] static_cast<char*>(ptr);
if (ptr) {
free(static_cast<void**>(ptr)[-1]);
}
}
void TargetWrapper<TARGET(kHost)>::MemcpySync(void* dst, const void* src,
size_t size, IoDirection dir) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册