diff --git a/src/common/log.h b/src/common/log.h index 282ee2780993447051143866f65907ba7ce17be3..30d1d495c755af60ce30159efb7c0ef05517d26c 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -36,16 +36,16 @@ static const char *ANDROID_LOG_TAG = #define ANDROIDLOGI(...) \ __android_log_print(ANDROID_LOG_INFO, ANDROID_LOG_TAG, __VA_ARGS__); \ - printf(__VA_ARGS__) + printf("%s\n", __VA_ARGS__); #define ANDROIDLOGW(...) \ __android_log_print(ANDROID_LOG_WARNING, ANDROID_LOG_TAG, __VA_ARGS__); \ - printf(__VA_ARGS__) + printf("%s\n", __VA_ARGS__); #define ANDROIDLOGD(...) \ __android_log_print(ANDROID_LOG_DEBUG, ANDROID_LOG_TAG, __VA_ARGS__); \ - printf(__VA_ARGS__) + printf("%s\n", __VA_ARGS__) #define ANDROIDLOGE(...) \ __android_log_print(ANDROID_LOG_ERROR, ANDROID_LOG_TAG, __VA_ARGS__); \ - printf(__VA_ARGS__) + printf("%s\n", __VA_ARGS__) #else #define ANDROIDLOGI(...) #define ANDROIDLOGW(...) @@ -88,9 +88,17 @@ struct Print { void print(LogLevel level) { // buffer_ << std::endl; if (level == kLOG_ERROR) { +#ifdef ANDROID + ANDROIDLOGE(buffer_.str().c_str()); +#else std::cerr << buffer_.str() << std::endl; +#endif } else { +#ifdef ANDROID + ANDROIDLOGI(buffer_.str().c_str()); +#else std::cout << buffer_.str() << std::endl; +#endif } } std::ostringstream buffer_; diff --git a/src/framework/executor.cpp b/src/framework/executor.cpp index f337d1d184d0d4880a28df7d066301ca0d3e1460..f1139ae4b9273a4d088088a73ff9714fc8e5220a 100644 --- a/src/framework/executor.cpp +++ b/src/framework/executor.cpp @@ -228,6 +228,20 @@ void Executor::InitMemory() { } } +static void ClearNoPersistableTensorArray(const framework::ProgramDesc *program, + framework::Scope *scope) { + for (const auto &block : program->Blocks()) { + for (const auto &var_desc : block->Vars()) { + if (!var_desc->Persistable() && + var_desc->Type() == VARTYPE_TYPE_STEP_LOD_TENSOR_ARRAY) { + auto var = scope->Var(var_desc->Name()); + auto array = var->template GetMutable(); + array->resize(1); + } + } + } +} + template void Executor::InitCombineMemory() { char *origin_data = nullptr; @@ -421,6 +435,10 @@ PMStatus Executor::Predict() { #if _OPENMP omp_set_num_threads(get_global_num_threads()); #endif + // clear all no persistable tensor array since write_to_array + // is always push back a new tensor in the array + ClearNoPersistableTensorArray(program_desc_.get(), program_.scope.get()); + #ifdef PADDLE_MOBILE_PROFILE std::vector profile(ops_of_block0_.size()); struct timespec ts; diff --git a/src/framework/operator.cpp b/src/framework/operator.cpp index d140603744ac00a46d54d668c2201d11c1e1d088..c1d7fe351fcb4121546f07a3f26f10d784c1baa8 100644 --- a/src/framework/operator.cpp +++ b/src/framework/operator.cpp @@ -102,16 +102,11 @@ void OperatorBase::Run() { for (const auto key : input_keys) { auto var_vec_in = inputs_.at(key); for (int i = 0; i < var_vec_in.size(); ++i) { - auto vari = scope_->FindVar(var_vec_in[i]); - if (vari->IsInitialized()) { - if (type_ == "feed") { - const Tensor *tensor = vari->template Get(); - if (tensor) DLOG << type_ << " input- " << key << "=" << *tensor; - } else { - const CLImage *cl_image = vari->template Get(); - if (cl_image) { - DLOG << type_ << " input- " << key << "=" << *cl_image; - } + auto var = scope_->FindVar(var_vec_in[i]); + if (var->IsInitialized() && var->template IsType()) { + const CLImage *cl_image = var->template Get(); + if (cl_image) { + DLOG << type_ << " input- " << key << "=" << *cl_image; } } } @@ -119,18 +114,11 @@ void OperatorBase::Run() { for (const auto key : GetOutKeys()) { auto var_vec_out = outputs_.at(key); for (int i = 0; i < var_vec_out.size(); ++i) { - auto vari = scope_->FindVar(var_vec_out[i]); - if (vari->IsInitialized()) { - if (type_ == "fetch") { - const Tensor *tensor = vari->template Get(); - if (tensor) { - DLOG << type_ << " output- " << key << "=" << *tensor; - } - } else { - const CLImage *cl_image = vari->template Get(); - if (cl_image) { - DLOG << type_ << " output- " << key << "=" << *cl_image; - } + auto var = scope_->FindVar(var_vec_out[i]); + if (var->IsInitialized() && var->template IsType()) { + const CLImage *cl_image = var->template Get(); + if (cl_image) { + DLOG << type_ << " output- " << key << "=" << *cl_image; } } }