未验证 提交 00bd7f44 编写于 作者: H huzhiqiang 提交者: GitHub

[Framework]Dynamic memory malloc to reduce memory usage (#3948)

上级 ea1e61fb
...@@ -30,7 +30,6 @@ void* TargetWrapper<TARGET(kHost)>::Malloc(size_t size) { ...@@ -30,7 +30,6 @@ void* TargetWrapper<TARGET(kHost)>::Malloc(size_t size) {
void* r = reinterpret_cast<void*>(reinterpret_cast<size_t>(p + offset) & void* r = reinterpret_cast<void*>(reinterpret_cast<size_t>(p + offset) &
(~(MALLOC_ALIGN - 1))); (~(MALLOC_ALIGN - 1)));
static_cast<void**>(r)[-1] = p; static_cast<void**>(r)[-1] = p;
memset(r, 0, size);
return r; return r;
} }
void TargetWrapper<TARGET(kHost)>::Free(void* ptr) { void TargetWrapper<TARGET(kHost)>::Free(void* ptr) {
......
...@@ -155,6 +155,7 @@ TEST(nearest_interp_image2d, compute) { ...@@ -155,6 +155,7 @@ TEST(nearest_interp_image2d, compute) {
auto *x_data = x.mutable_data<float, cl::Buffer>(TARGET(kOpenCL)); auto *x_data = x.mutable_data<float, cl::Buffer>(TARGET(kOpenCL));
auto *y_data = y.mutable_data<float, cl::Buffer>(TARGET(kOpenCL)); auto *y_data = y.mutable_data<float, cl::Buffer>(TARGET(kOpenCL));
auto *y_data_ref = y_ref.mutable_data<float>(TARGET(kARM)); auto *y_data_ref = y_ref.mutable_data<float>(TARGET(kARM));
memset(reinterpret_cast<char *>(y_data_ref), 0, y_ref.numel());
auto *mapped_x = static_cast<float *>(TargetWrapperCL::Map( auto *mapped_x = static_cast<float *>(TargetWrapperCL::Map(
x_data, 0, sizeof(float) * x_dim.production())); x_data, 0, sizeof(float) * x_dim.production()));
auto *mapped_y = static_cast<float *>(TargetWrapperCL::Map( auto *mapped_y = static_cast<float *>(TargetWrapperCL::Map(
......
...@@ -120,6 +120,10 @@ bool test_gemm_int8(bool tra, ...@@ -120,6 +120,10 @@ bool test_gemm_int8(bool tra,
auto dc_fp32 = tc_fp32.mutable_data<float>(); auto dc_fp32 = tc_fp32.mutable_data<float>();
auto dc_basic_int8 = tc_basic_int8.mutable_data<int8_t>(); auto dc_basic_int8 = tc_basic_int8.mutable_data<int8_t>();
auto dc_basic_fp32 = tc_basic_fp32.mutable_data<float>(); auto dc_basic_fp32 = tc_basic_fp32.mutable_data<float>();
// set intial input to be 0
memset(reinterpret_cast<char*>(dc_basic_fp32),
0,
tc_basic_fp32.numel() * sizeof(float));
auto dbias = tbias.mutable_data<float>(); auto dbias = tbias.mutable_data<float>();
if (FLAGS_check_result) { if (FLAGS_check_result) {
......
...@@ -108,6 +108,10 @@ bool test_gemv_int8(bool tra, ...@@ -108,6 +108,10 @@ bool test_gemv_int8(bool tra,
auto dc_basic_int8 = tc_basic_int8.mutable_data<int8_t>(); auto dc_basic_int8 = tc_basic_int8.mutable_data<int8_t>();
auto dc_basic_fp32 = tc_basic_fp32.mutable_data<float>(); auto dc_basic_fp32 = tc_basic_fp32.mutable_data<float>();
auto dbias = tbias.mutable_data<float>(); auto dbias = tbias.mutable_data<float>();
// set intial input to be 0
memset(reinterpret_cast<char*>(dc_basic_fp32),
0,
tc_basic_fp32.numel() * sizeof(float));
paddle::lite_api::ActivationType act = paddle::lite_api::ActivationType act =
paddle::lite_api::ActivationType::kIndentity; paddle::lite_api::ActivationType::kIndentity;
......
...@@ -92,6 +92,7 @@ bool test_sgemm_c4( ...@@ -92,6 +92,7 @@ bool test_sgemm_c4(
auto db_c4 = tb_c4.mutable_data<float>(); auto db_c4 = tb_c4.mutable_data<float>();
auto dc_basic = tc_basic.mutable_data<float>(); auto dc_basic = tc_basic.mutable_data<float>();
auto dbias = tbias.mutable_data<float>(); auto dbias = tbias.mutable_data<float>();
memset(reinterpret_cast<char*>(dc_basic), 0, tc_basic.numel());
// trans A, B to c4 // trans A, B to c4
basic_trans_mat_to_c4(da, da_c4, k, m, k, true); basic_trans_mat_to_c4(da, da_c4, k, m, k, true);
......
...@@ -84,6 +84,7 @@ bool test_sgemv(bool tra, ...@@ -84,6 +84,7 @@ bool test_sgemv(bool tra,
auto db = tb.mutable_data<float>(); auto db = tb.mutable_data<float>();
auto dc = tc.mutable_data<float>(); auto dc = tc.mutable_data<float>();
auto dc_basic = tc_basic.mutable_data<float>(); auto dc_basic = tc_basic.mutable_data<float>();
memset(reinterpret_cast<char*>(dc_basic), 0, tc_basic.numel());
auto dbias = tbias.mutable_data<float>(); auto dbias = tbias.mutable_data<float>();
paddle::lite_api::ActivationType act = paddle::lite_api::ActivationType act =
paddle::lite_api::ActivationType::kIndentity; paddle::lite_api::ActivationType::kIndentity;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册