File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 14
14
15
15
#include " paddle/fluid/lite/core/target_wrapper.h"
16
16
#include < cstring>
17
+ #include < memory>
17
18
18
19
namespace paddle {
19
20
namespace lite {
20
21
22
+ const int MALLOC_ALIGN = 64 ;
23
+
21
24
void * TargetWrapper<TARGET(kHost )>::Malloc(size_t size) {
22
- return new char [size];
25
+ size_t offset = sizeof (void *) + MALLOC_ALIGN - 1 ;
26
+ char * p = static_cast <char *>(malloc (offset + size));
27
+ if (!p) {
28
+ return nullptr ;
29
+ }
30
+ void * r = reinterpret_cast <void *>(reinterpret_cast <size_t >(p + offset) &
31
+ (~(MALLOC_ALIGN - 1 )));
32
+ static_cast <void **>(r)[-1 ] = p;
33
+ memset (r, 0 , size);
34
+ return r;
23
35
}
24
36
void TargetWrapper<TARGET(kHost )>::Free(void * ptr) {
25
- delete[] static_cast <char *>(ptr);
37
+ if (ptr) {
38
+ free (static_cast <void **>(ptr)[-1 ]);
39
+ }
26
40
}
27
41
void TargetWrapper<TARGET(kHost )>::MemcpySync(void * dst, const void * src,
28
42
size_t size, IoDirection dir) {
You can’t perform that action at this time.
0 commit comments