-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DO NOT MERGE] detect model test2 for dynamic shape #18372
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4ea200e
clear cache when tid == 1 and cache size exceeds max capacity
LeoZhao-Intel 2088f4c
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
LeoZhao-Intel 3d2e563
add more logs to print blob status
LeoZhao-Intel 14c5b2e
1. Add new interface in AnalysisConfig to set mkldnn thread id
LeoZhao-Intel 29ca760
change to use VLOG(2)
LeoZhao-Intel 76db898
detect model test for dynamic shape
luotao1 6a97049
load input data one by one
luotao1 1a47373
each iteration use new threads
luotao1 c0419de
Merge branch 'develop' into detect_model
luotao1 d27c757
fix input_slot_all memory leak
luotao1 f6ed3d1
Merge branch 'cache_clearing' of https://github.com/LeoZhao-Intel/Pad…
luotao1 634d8c6
change KeyBlob from vector to map for speedup
luotao1 2de7f41
PaddlePaddle memory leak test=develop
pawelpiotrowicz 4826196
use input_shape to setBlob
luotao1 29af2e3
Merge branch 'develop' into detect_model_test
luotao1 725f451
refine device_context, make blobMap etc more cleaner
luotao1 e8305ea
add MkldnnPreRun and MkldnnPostRun interface
luotao1 266a201
add EnableMKLDNN(int mkldnn_input_shape_cache_size = 1) inferace
luotao1 0d8f70a
Merge branch 'develop' into detect_model_test
luotao1 0e9aec9
Merge branch 'pawepiot/paddlepaddle_memory_leak' of https://github.co…
luotao1 086f347
Revert "PaddlePaddle memory leak test=develop"
luotao1 6d5a841
make unit-test support head-checker
luotao1 d91c910
use static variable to do cache instead of tread local in thread freq…
LeoZhao-Intel 1008c2a
Merge branch 'develop' into detect_model_test
luotao1 d6597b9
use marco to control code given it is specific for mkldnn
LeoZhao-Intel 7251426
Merge branch 'mt_memoryleak' of https://github.com/LeoZhao-Intel/Padd…
luotao1 b03d25a
Merge branch 'develop' into detect_model_test
luotao1 91dec55
Merge branch 'develop' into detect_model_test
luotao1 3a5cdc4
Merge branch 'develop' into detect_model_test
luotao1 be64967
Merge branch 'develop' into detect_model_test
luotao1 5480edf
fix conflict with develop
luotao1 1f9ca7d
Merge branch 'develop' into detect_model_test
luotao1 1ba6599
Merge branch 'develop' into detect_model_test
luotao1 65e3865
checkout develop paddle/fluid/operators/mkldnn/pool_mkldnn_op.cc
luotao1 330207c
clean detect unit-test
luotao1 d4997de
Merge branch 'develop' into detect_model_test
luotao1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
paddle/fluid/inference/tests/api/analyzer_detect_tester.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. */ | ||
|
||
// #include <gperftools/heap-checker.h> | ||
#include <gtest/gtest.h> | ||
#include <fstream> | ||
#include <iostream> | ||
#include "paddle/fluid/inference/tests/api/tester_helper.h" | ||
DEFINE_string(infer_shape, "", "data shape file"); | ||
DEFINE_int32(sample, 1, "number of sample"); | ||
|
||
namespace paddle { | ||
namespace inference { | ||
namespace analysis { | ||
|
||
struct Record { | ||
std::vector<float> data; | ||
std::vector<int32_t> shape; | ||
}; | ||
|
||
Record ProcessALine(const std::string &line, const std::string &shape_line) { | ||
VLOG(3) << "process a line"; | ||
std::vector<std::string> columns; | ||
|
||
Record record; | ||
std::vector<std::string> data_strs; | ||
split(line, ' ', &data_strs); | ||
for (auto &d : data_strs) { | ||
record.data.push_back(std::stof(d)); | ||
} | ||
|
||
std::vector<std::string> shape_strs; | ||
split(shape_line, ' ', &shape_strs); | ||
for (auto &s : shape_strs) { | ||
record.shape.push_back(std::stoi(s)); | ||
} | ||
// VLOG(3) << "data size " << record.data.size(); | ||
// VLOG(3) << "data shape size " << record.shape.size(); | ||
// LOG(INFO) << "data shape size " << record.shape[3]; | ||
return record; | ||
} | ||
|
||
void SetConfig(AnalysisConfig *cfg) { | ||
cfg->SetModel(FLAGS_infer_model + "/model", FLAGS_infer_model + "/params"); | ||
cfg->DisableGpu(); | ||
cfg->SwitchIrDebug(); | ||
cfg->SwitchSpecifyInputNames(false); | ||
cfg->SetCpuMathLibraryNumThreads(FLAGS_paddle_num_threads); | ||
} | ||
|
||
void SetInput(std::vector<std::vector<PaddleTensor>> *inputs, | ||
const std::string &line, const std::string &shape_line) { | ||
auto record = ProcessALine(line, shape_line); | ||
|
||
PaddleTensor input; | ||
input.shape = record.shape; | ||
input.dtype = PaddleDType::FLOAT32; | ||
size_t input_size = record.data.size() * sizeof(float); | ||
input.data.Resize(input_size); | ||
memcpy(input.data.data(), record.data.data(), input_size); | ||
std::vector<PaddleTensor> input_slots; | ||
input_slots.assign({input}); | ||
(*inputs).emplace_back(input_slots); | ||
} | ||
|
||
// Easy for profiling independently. | ||
// ocr, mobilenet and se_resnext50 | ||
void profile(bool use_mkldnn = false) { | ||
AnalysisConfig cfg; | ||
SetConfig(&cfg); | ||
if (use_mkldnn) { | ||
cfg.EnableMKLDNN(); | ||
cfg.SetMkldnnCacheCapacity(10); | ||
} | ||
// cfg.pass_builder()->TurnOnDebug(); | ||
std::vector<std::vector<PaddleTensor>> outputs; | ||
std::vector<std::vector<PaddleTensor>> input_slots_all; | ||
|
||
Timer run_timer; | ||
double elapsed_time = 0; | ||
|
||
int iterations = FLAGS_sample; | ||
int num_times = FLAGS_repeat; | ||
auto predictor = CreatePaddlePredictor<AnalysisConfig>(cfg); | ||
outputs.resize(iterations); | ||
|
||
std::vector<std::thread> threads; | ||
|
||
for (int j = 0; j < num_times; j++) { | ||
std::ifstream file(FLAGS_infer_data); | ||
std::ifstream infer_file(FLAGS_infer_shape); | ||
std::string line; | ||
std::string shape_line; | ||
|
||
for (int i = 0; i < iterations; i++) { | ||
threads.emplace_back([&, i]() { | ||
std::getline(file, line); | ||
std::getline(infer_file, shape_line); | ||
SetInput(&input_slots_all, line, shape_line); | ||
|
||
run_timer.tic(); | ||
predictor->Run(input_slots_all[0], &outputs[0], FLAGS_batch_size); | ||
elapsed_time += run_timer.toc(); | ||
}); | ||
threads[0].join(); | ||
threads.clear(); | ||
if (i % 100 == 0) LOG(INFO) << i << " samples"; | ||
std::vector<std::vector<PaddleTensor>>().swap(input_slots_all); | ||
} | ||
|
||
file.close(); | ||
infer_file.close(); | ||
} | ||
|
||
auto batch_latency = elapsed_time / (iterations * num_times); | ||
PrintTime(FLAGS_batch_size, num_times, FLAGS_num_threads, 0, batch_latency, | ||
iterations, VarType::FP32); | ||
} | ||
|
||
TEST(Analyzer_vis, profile) { profile(); } | ||
|
||
#ifdef PADDLE_WITH_MKLDNN | ||
TEST(Analyzer_vis, profile_mkldnn) { profile(true /* use_mkldnn */); } | ||
#endif | ||
|
||
} // namespace analysis | ||
} // namespace inference | ||
} // namespace paddle | ||
|
||
// following lines are used for pprof | ||
// int main(int argc, char **argv) { | ||
// HeapLeakChecker heap_checker("test_foo"); | ||
// FLAGS_infer_model = "third_party/inference_demo/face_model/densebox"; | ||
// FLAGS_infer_data = | ||
// "third_party/inference_demo/face_model/detect_input.txt"; | ||
// FLAGS_infer_shape = "third_party/inference_demo/face_model/shape.txt"; | ||
// FLAGS_paddle_num_threads = 4; | ||
// FLAGS_repeat = 1; | ||
// FLAGS_batch_size = 1; | ||
// FLAGS_sample = 10; | ||
// paddle::inference::analysis::profile(true); | ||
// std::cout << heap_checker.NoLeaks() << std::endl; | ||
// } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove followings
main
function if you do not want to use pprof.