-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Update stream rebind #51412
Closed
Closed
Update stream rebind #51412
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c9bc323
update ReBind stream. test=develop
heavengate 6725f2f
update rebind stream support parallel. test=develop
heavengate 3dcbf84
remove log and add comments. test=develop
heavengate adba8b0
remove log and add comments. test=develop
heavengate cc0e5af
Merge branch 'update_stream_rebind' of https://github.com/heavengate/…
heavengate 09a1f94
fix format. test=develop
heavengate 545b534
update test. test=develop
heavengate d39de97
fix unittest. test=develop
heavengate 577e6e0
unittest timeout 120. test=develop
heavengate 851802c
set unittest EXCLUSIVE. test=develop
heavengate a589bc9
fix format. test=develop
heavengate 6db7e32
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
heavengate 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
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
100 changes: 100 additions & 0 deletions
100
paddle/fluid/inference/tests/api/trt_rebind_stream_test.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,100 @@ | ||
/* 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 <glog/logging.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include "gflags/gflags.h" | ||
#include "paddle/fluid/inference/tests/api/trt_test_helper.h" | ||
|
||
namespace paddle { | ||
namespace inference { | ||
|
||
TEST(ReBindStream_single, use_gpu) { | ||
std::string model_dir = FLAGS_infer_model + "/mobilenet"; | ||
AnalysisConfig config; | ||
config.EnableUseGpu(100, 0); | ||
config.SetModel(model_dir); | ||
config.EnableTensorRtEngine(); | ||
|
||
cudaStream_t stream1, stream2, stream3; | ||
cudaStreamCreateWithFlags(&stream1, cudaStreamNonBlocking); | ||
cudaStreamCreateWithFlags(&stream2, cudaStreamNonBlocking); | ||
cudaStreamCreateWithFlags(&stream3, cudaStreamNonBlocking); | ||
|
||
config.SetExecStream(stream1); | ||
auto predictor = paddle_infer::CreatePredictor(config); | ||
auto x_t = predictor->GetInputHandle("x"); | ||
x_t->Reshape({1, 3, 224, 224}); | ||
float x_data[3 * 224 * 224] = {0}; | ||
x_t->CopyFromCpu(x_data); | ||
ASSERT_TRUE(predictor->Run()); | ||
ASSERT_TRUE(paddle_infer::experimental::InternalUtils::RunWithExternalStream( | ||
predictor.get(), stream2)); | ||
ASSERT_TRUE(paddle_infer::experimental::InternalUtils::RunWithExternalStream( | ||
predictor.get(), stream3)); | ||
} | ||
|
||
TEST(ReBindStream_multi, use_gpu) { | ||
std::string model_dir = FLAGS_infer_model + "/mobilenet"; | ||
AnalysisConfig config1; | ||
config1.EnableUseGpu(100, 0); | ||
config1.SetModel(model_dir); | ||
config1.EnableTensorRtEngine(); | ||
AnalysisConfig config2; | ||
config2.EnableUseGpu(100, 0); | ||
config2.EnableTensorRtEngine(); | ||
config2.SetModel(model_dir); | ||
|
||
cudaStream_t stream1, stream2, stream3; | ||
cudaStreamCreate(&stream1); | ||
cudaStreamCreate(&stream2); | ||
cudaStreamCreate(&stream3); | ||
|
||
config1.SetExecStream(stream1); | ||
config2.SetExecStream(stream1); | ||
auto predictor1 = paddle_infer::CreatePredictor(config1); | ||
auto predictor2 = paddle_infer::CreatePredictor(config2); | ||
|
||
std::vector<float> x1(3 * 224 * 224, 1.0); | ||
auto x_t1 = predictor1->GetInputHandle("x"); | ||
x_t1->Reshape({1, 3, 224, 224}); | ||
x_t1->CopyFromCpu(x1.data()); | ||
std::vector<float> x2(3 * 224 * 224, 2.0); | ||
auto x_t2 = predictor2->GetInputHandle("x"); | ||
x_t2->Reshape({1, 3, 224, 224}); | ||
x_t2->CopyFromCpu(x2.data()); | ||
|
||
ASSERT_TRUE(predictor1->Run()); | ||
cudaStreamSynchronize(stream1); | ||
ASSERT_TRUE(predictor2->Run()); | ||
cudaStreamSynchronize(stream1); | ||
|
||
ASSERT_TRUE(paddle_infer::experimental::InternalUtils::RunWithExternalStream( | ||
predictor1.get(), stream2)); | ||
cudaDeviceSynchronize(); | ||
ASSERT_TRUE(paddle_infer::experimental::InternalUtils::RunWithExternalStream( | ||
predictor2.get(), stream2)); | ||
cudaDeviceSynchronize(); | ||
|
||
ASSERT_TRUE(paddle_infer::experimental::InternalUtils::RunWithExternalStream( | ||
predictor1.get(), stream3)); | ||
cudaStreamSynchronize(stream3); | ||
ASSERT_TRUE(paddle_infer::experimental::InternalUtils::RunWithExternalStream( | ||
predictor2.get(), stream3)); | ||
cudaStreamSynchronize(stream3); | ||
} | ||
|
||
} // namespace inference | ||
} // namespace paddle |
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.
Rebind加锁后,这里的Check还是要去掉吗?