You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by sk...@apache.org on 2019/01/25 19:14:52 UTC

[incubator-mxnet] branch master updated: [MXNET-1301] Remove the unnecessary WaitAll statements from inception_inference example (#13972)

This is an automated email from the ASF dual-hosted git repository.

skm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new f1c063e  [MXNET-1301] Remove the unnecessary WaitAll statements from inception_inference example (#13972)
f1c063e is described below

commit f1c063ebc017d175bd8f6f4d5027f8e178388c58
Author: Amol Lele <19...@users.noreply.github.com>
AuthorDate: Fri Jan 25 11:14:33 2019 -0800

    [MXNET-1301] Remove the unnecessary WaitAll statements from inception_inference example (#13972)
    
    * Removed the unnecessary WaitAll statements
    
    * Removed the WaitAll() calls wherever they are not necessary.
---
 cpp-package/example/inference/inception_inference.cpp | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/cpp-package/example/inference/inception_inference.cpp b/cpp-package/example/inference/inception_inference.cpp
index 7005e74..78487e6 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;
 }
 
@@ -299,21 +296,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);