From 45156acfceb55bf7a20e89a1fa894cd7ea757025 Mon Sep 17 00:00:00 2001 From: Amol Lele <19983848+leleamol@users.noreply.github.com> Date: Wed, 23 Jan 2019 09:59:23 -0800 Subject: [PATCH 1/2] Removed the unnecessary WaitAll statements --- cpp-package/example/inference/inception_inference.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cpp-package/example/inference/inception_inference.cpp b/cpp-package/example/inference/inception_inference.cpp index 7005e745b2f4..d76347039aa4 100644 --- a/cpp-package/example/inference/inception_inference.cpp +++ b/cpp-package/example/inference/inception_inference.cpp @@ -299,21 +299,26 @@ void Predictor::PredictImage(const std::string& image_file) { * */ image_data.CopyTo(&(executor->arg_dict()["data"])); - NDArray::WaitAll(); // Run the forward pass. executor->Forward(false); // The output is available in executor->outputs. auto array = executor->outputs[0].Copy(global_ctx); - NDArray::WaitAll(); /* * Find out the maximum accuracy and the index associated with that accuracy. * This is done by using the argmax operator on NDArray. */ auto predicted = array.ArgmaxChannel(); - NDArray::WaitAll(); + + /* + * Wait until all the previous write operations on the 'predicted' + * NDArray to be complete before we read it. + * This method guarantees that all previous write operations that pushed into the backend engine + * for execution are actually finished. + */ + predicted.WaitToRead(); int best_idx = predicted.At(0, 0); float best_accuracy = array.At(0, best_idx); From acfb818c71327d0291e24e3936dce394518fae28 Mon Sep 17 00:00:00 2001 From: Amol Lele <19983848+leleamol@users.noreply.github.com> Date: Wed, 23 Jan 2019 10:45:00 -0800 Subject: [PATCH 2/2] Removed the WaitAll() calls wherever they are not necessary. --- cpp-package/example/inference/inception_inference.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/cpp-package/example/inference/inception_inference.cpp b/cpp-package/example/inference/inception_inference.cpp index d76347039aa4..78487e6ee0cd 100644 --- a/cpp-package/example/inference/inception_inference.cpp +++ b/cpp-package/example/inference/inception_inference.cpp @@ -215,7 +215,6 @@ void Predictor::LoadMeanImageData() { mean_image_data.SyncCopyFromCPU( NDArray::LoadToMap(mean_image_file)["mean_img"].GetData(), input_shape.Size()); - NDArray::WaitAll(); } @@ -244,7 +243,6 @@ void Predictor::LoadDefaultMeanImageData() { } mean_image_data = NDArray(input_shape, global_ctx, false); mean_image_data.SyncCopyFromCPU(array.data(), input_shape.Size()); - NDArray::WaitAll(); } @@ -273,7 +271,6 @@ NDArray Predictor::LoadInputImage(const std::string& image_file) { } NDArray image_data = NDArray(input_shape, global_ctx, false); image_data.SyncCopyFromCPU(array.data(), input_shape.Size()); - NDArray::WaitAll(); return image_data; }