Skip to content

Commit 27f553b

Browse files
committed
Add the check of CPU results and GPU results in multi-thread unittest.
1 parent 9cba062 commit 27f553b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

paddle/fluid/inference/tests/book/test_inference_fit_a_line.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ TEST(inference, fit_a_line) {
3232
// The input data should be >= 0
3333
int64_t batch_size = 10;
3434
SetupTensor<float>(
35-
input, {batch_size, 13}, static_cast<float>(0), static_cast<float>(10));
35+
&input, {batch_size, 13}, static_cast<float>(0), static_cast<float>(10));
3636
std::vector<paddle::framework::LoDTensor*> cpu_feeds;
3737
cpu_feeds.push_back(&input);
3838

@@ -51,7 +51,7 @@ TEST(inference, fit_a_line) {
5151
cpu_fetchs2.push_back(&output2);
5252

5353
// Run inference on CUDA GPU
54-
LOG(INFO) << "--- CPU Runs: ---";
54+
LOG(INFO) << "--- GPU Runs: ---";
5555
TestInference<paddle::platform::CUDAPlace>(dirname, cpu_feeds, cpu_fetchs2);
5656
LOG(INFO) << output2.dims();
5757

@@ -79,10 +79,8 @@ TEST(multi_thread_inference, fit_a_line) {
7979
// The second dim of the input tensor should be 13
8080
// The input data should be >= 0
8181
int64_t batch_size = 10;
82-
SetupTensor<float>(*input,
83-
{batch_size, 13},
84-
static_cast<float>(0),
85-
static_cast<float>(10));
82+
SetupTensor<float>(
83+
input, {batch_size, 13}, static_cast<float>(0), static_cast<float>(10));
8684
cpu_feeds[i].push_back(input);
8785
}
8886

@@ -112,6 +110,7 @@ TEST(multi_thread_inference, fit_a_line) {
112110
dirname, cpu_feeds, cpu_fetchs2, num_threads);
113111

114112
for (int i = 0; i < num_threads; ++i) {
113+
CheckError<float>(*cpu_fetchs1[i][0], *cpu_fetchs2[i][0]);
115114
delete cpu_fetchs2[i][0];
116115
}
117116
#endif

paddle/fluid/inference/tests/test_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License. */
1515
#pragma once
1616

1717
#include <time.h>
18+
#include <cstdint>
1819
#include <map>
1920
#include <string>
2021
#include <vector>
@@ -28,7 +29,7 @@ void SetupTensor(paddle::framework::LoDTensor* input,
2829
const T lower,
2930
const T upper) {
3031
T* input_ptr = input->mutable_data<T>(dims, paddle::platform::CPUPlace());
31-
unsigned int seed = time(NULL);
32+
unsigned int seed = reinterpret_cast<std::uintptr_t>(input);
3233
for (int i = 0; i < input->numel(); ++i) {
3334
input_ptr[i] = (static_cast<T>(rand_r(&seed)) / static_cast<T>(RAND_MAX)) *
3435
(upper - lower) +

0 commit comments

Comments
 (0)