From 9bd6b3f65b10d983280949248d0ab2b39e46a7d4 Mon Sep 17 00:00:00 2001 From: HexToString <506181616@qq.com> Date: Fri, 12 Mar 2021 03:44:24 +0000 Subject: [PATCH] fix 2.0 api --- CMakeLists.txt | 4 +- core/general-server/op/general_infer_op.cpp | 3 + core/general-server/op/general_reader_op.cpp | 2 + .../general-server/op/general_response_op.cpp | 9 ++- core/predictor/framework/infer.h | 57 ++++++++++++------- core/predictor/framework/infer_data.h | 9 +-- core/predictor/framework/service.cpp | 4 ++ core/predictor/op/op.cpp | 1 + core/predictor/src/pdserving.cpp | 8 +++ 9 files changed, 68 insertions(+), 29 deletions(-) mode change 100644 => 100755 core/predictor/framework/service.cpp mode change 100644 => 100755 core/predictor/op/op.cpp mode change 100644 => 100755 core/predictor/src/pdserving.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6228877f..c10e0187 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,9 @@ set(PADDLE_SERVING_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(PADDLE_SERVING_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) SET(PADDLE_SERVING_INSTALL_DIR ${CMAKE_BINARY_DIR}/output) SET(CMAKE_INSTALL_RPATH "\$ORIGIN" "${CMAKE_INSTALL_RPATH}") - +SET(CMAKE_BUILD_TYPE "Debug") +SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb") +SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") include(system) project(paddle-serving CXX C) diff --git a/core/general-server/op/general_infer_op.cpp b/core/general-server/op/general_infer_op.cpp index 84fae0b9..7bec67f6 100755 --- a/core/general-server/op/general_infer_op.cpp +++ b/core/general-server/op/general_infer_op.cpp @@ -80,9 +80,12 @@ int GeneralInferOp::inference() { } int64_t end = timeline.TimeStampUS(); + std::cout << "GeneralInferOp ---ysl" << std::endl; + LOG(ERROR) << "GeneralInferOp ---ysl"; CopyBlobInfo(input_blob, output_blob); AddBlobInfo(output_blob, start); AddBlobInfo(output_blob, end); + std::cout << "GeneralInferOp ---ysl222" << std::endl; return 0; } DEFINE_OP(GeneralInferOp); diff --git a/core/general-server/op/general_reader_op.cpp b/core/general-server/op/general_reader_op.cpp index 6f8947db..0f789ae3 100755 --- a/core/general-server/op/general_reader_op.cpp +++ b/core/general-server/op/general_reader_op.cpp @@ -244,6 +244,8 @@ int GeneralReaderOp::inference() { AddBlobInfo(res, end); VLOG(2) << "(logid=" << log_id << ") read data from client success"; + LOG(ERROR) << "GeneralReaderOp ---ysl"; + std::cout << "GeneralReaderOp ---ysl" << std::endl; return 0; } DEFINE_OP(GeneralReaderOp); diff --git a/core/general-server/op/general_response_op.cpp b/core/general-server/op/general_response_op.cpp index e424ada5..27a0f86f 100755 --- a/core/general-server/op/general_response_op.cpp +++ b/core/general-server/op/general_response_op.cpp @@ -139,7 +139,12 @@ int GeneralResponseOp::inference() { } else if (dtype == paddle::PaddleDType::FLOAT32) { VLOG(2) << "(logid=" << log_id << ") Prepare float var [" << model_config->_fetch_name[idx] << "]."; + float *data_ptr = static_cast(in->at(idx).data.data()); + std::cout<<" response op ---- for"< { ~FluidInferEngine() {} int infer_impl1(const void* in, void* out, uint32_t batch_size = -1) { + LOG(ERROR) << "come in infer_impl1 ---ysl"; FluidFamilyCore* core =DBReloadableInferEngine::get_core(); if (!core || !core->get()) { LOG(ERROR) << "Failed get fluid core in infer_impl()"; @@ -603,6 +604,7 @@ class FluidInferEngine : public CloneDBReloadableInferEngine { //set inputHandle const BatchTensor* batchTensor_pointer_in = reinterpret_cast(in); + std::cout<<"input tensor: "<count()<count();++i){ Tensor tensor_in_batchTensor = (*batchTensor_pointer_in)[i]; auto lod_tensor_in = core->GetInputHandle(tensor_in_batchTensor.name); @@ -615,55 +617,68 @@ class FluidInferEngine : public CloneDBReloadableInferEngine { }else if(tensor_in_batchTensor.type == INT64){ int64_t* data = reinterpret_cast(origin_data); lod_tensor_in->CopyFromCpu(data); - }else if(tensor_in_batchTensor.type == INT32){ + }/*else if(tensor_in_batchTensor.type == INT32){ int32_t* data = reinterpret_cast(origin_data); lod_tensor_in->CopyFromCpu(data); - } + }*/ } if (!core->Run()) { LOG(ERROR) << "Failed run fluid family core"; return -1; } - + LOG(ERROR) << "Run infer_impl1 ---ysl"; //get out and copy to void* out BatchTensor* batchTensor_pointer_out = reinterpret_cast(out); + LOG(ERROR) << "reinterpret_cast infer_impl1 ---ysl"; std::vector outnames = core->GetOutputNames(); for (int i = 0; i < outnames.size(); ++i){ auto lod_tensor_out = core->GetOutputHandle(outnames[i]); std::vector output_shape = lod_tensor_out->shape(); int out_num = std::accumulate(output_shape.begin(), output_shape.end(), 1, std::multiplies()); int dataType = lod_tensor_out->type(); - void* databuf_data = NULL; + char* databuf_data = NULL; size_t databuf_size = 0; if(dataType == FLOAT32){ float* data_out = new float[out_num]; lod_tensor_out->CopyToCpu(data_out); - databuf_data = reinterpret_cast(data_out); - databuf_size = sizeof(float); - }else if (dataType == INT64){ + for ( int j = 0; j < out_num; j++ ) + {std::cout << "ysl----data_out[+ " << j << "]) : ";std::cout << *(data_out + j) << std::endl;} + databuf_data = reinterpret_cast(data_out); + databuf_size = out_num*sizeof(float); + }else if(dataType == INT64){ int64_t* data_out = new int64_t[out_num]; lod_tensor_out->CopyToCpu(data_out); - databuf_data = reinterpret_cast(data_out); - databuf_size = sizeof(int64_t); - }else if (dataType == INT32){ + for ( int j = 0; j < out_num; j++ ) + {std::cout << "ysl----data_out[+ " << j << "]) : ";std::cout << *(data_out + j) << std::endl;} + databuf_data = reinterpret_cast(data_out); + databuf_size = out_num*sizeof(int64_t); + }/*else (dataType == INT32){ int32_t* data_out = new int32_t[out_num]; lod_tensor_out->CopyToCpu(data_out); - databuf_data = reinterpret_cast(data_out); - databuf_size = sizeof(int32_t); - } - Tensor tensor_out; - tensor_out.name = outnames[i]; - tensor_out.type = DataType(dataType); - tensor_out.shape.assign(output_shape.begin(), output_shape.end()); + for ( int j = 0; j < out_num; j++ ) + {std::cout << "ysl----data_out[+ " << j << "]) : ";std::cout << *(data_out + j) << std::endl;} + databuf_data = reinterpret_cast(data_out); + databuf_size = out_num*sizeof(int32_t); + }*/ + Tensor* tensor_out = new Tensor(); + tensor_out->name = outnames[i]; + std::cout<< "i am test ----outnames:"<type = DataType(dataType); + tensor_out->shape.assign(output_shape.begin(), output_shape.end()); std::vector> out_lod = lod_tensor_out->lod(); for (int li = 0; li < out_lod.size(); ++li) { std::vector lod_element; lod_element.assign(out_lod[li].begin(), out_lod[li].end()); - tensor_out.lod.push_back(lod_element); + tensor_out->lod.push_back(lod_element); } - tensor_out.data = DataBuf(databuf_data,databuf_size); - batchTensor_pointer_out->push_back_owned(tensor_out); - } + LOG(ERROR) << "DataBuf infer_impl1 ---ysl"; + DataBuf* newData = new DataBuf(databuf_data,databuf_size,false); + tensor_out->data = *newData; + batchTensor_pointer_out->push_back(*tensor_out); + LOG(ERROR) << "push_back infer_impl1 ---ysl"; + } + LOG(ERROR) << "return infer_impl1 ---ysl"; + std::cout << (*batchTensor_pointer_in)[0].shape.size()<< "(*batchTensor_pointer_in)[0].shape.size()"<full_name(), workflow_time.u_elapsed()); // return tls data to object pool + std::cout<<"ysl ------- _execute_workflow------"<return_dag_view(dv); TRACEPRINTF("(logid=%" PRIu64 ") finish to return dag view", log_id); + std::cout<<"ysl ------- _execute_workflow return_dag_view------"<