未验证 提交 fb2a7b23 编写于 作者: T tensor-tang 提交者: GitHub

fix aligned-new error in jitkernel (#15626)

* fix aligned-new error in jitkernel

test=develop

* override genbase new to fix mis-align

test=develop
上级 08ad72d0
...@@ -17,7 +17,13 @@ ...@@ -17,7 +17,13 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include "paddle/fluid/memory/allocation/cpu_allocator.h" // for posix_memalign
#include "paddle/fluid/platform/cpu_info.h" #include "paddle/fluid/platform/cpu_info.h"
#include "paddle/fluid/platform/enforce.h"
#ifndef _WIN32
#define posix_memalign_free free
#endif
DEFINE_bool(dump_jitcode, false, "Whether to dump the jitcode to file"); DEFINE_bool(dump_jitcode, false, "Whether to dump the jitcode to file");
...@@ -40,6 +46,17 @@ void GenBase::dumpCode(const unsigned char* code) const { ...@@ -40,6 +46,17 @@ void GenBase::dumpCode(const unsigned char* code) const {
} }
} }
void* GenBase::operator new(size_t size) {
void* ptr;
constexpr size_t alignment = 32ul;
PADDLE_ENFORCE_EQ(posix_memalign(&ptr, alignment, size), 0,
"GenBase Alloc %ld error!", size);
PADDLE_ENFORCE(ptr, "Fail to allocate GenBase CPU memory: size = %d .", size);
return ptr;
}
void GenBase::operator delete(void* ptr) { posix_memalign_free(ptr); }
std::vector<int> packed_groups(int n, int k, int* block_out, int* rest_out) { std::vector<int> packed_groups(int n, int k, int* block_out, int* rest_out) {
int block; int block;
int max_num_regs; int max_num_regs;
......
...@@ -42,6 +42,11 @@ class GenBase : public Kernel { ...@@ -42,6 +42,11 @@ class GenBase : public Kernel {
return reinterpret_cast<Func>(const_cast<unsigned char*>(code)); return reinterpret_cast<Func>(const_cast<unsigned char*>(code));
} }
void* operator new(size_t size);
void operator delete(void* ptr);
void* operator new[](size_t size) { return operator new(size); }
void operator delete[](void* ptr) { operator delete(ptr); }
protected: protected:
void dumpCode(const unsigned char* code) const; void dumpCode(const unsigned char* code) const;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册