masahi commented on a change in pull request #10234:
URL: https://github.com/apache/tvm/pull/10234#discussion_r806466228



##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -213,6 +209,16 @@ def get_output(self):
         """
         return self._get_output()
 
+    @property
+    def number_pipe_execute(self):
+        """Getting the times of pipeline running.

Review comment:
       running pipeline

##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -213,6 +209,16 @@ def get_output(self):
         """
         return self._get_output()
 
+    @property
+    def number_pipe_execute(self):
+        """Getting the times of pipeline running.
+        Returns
+        -------
+        count : int
+            The times of pipeline running.
+        """
+        return self._get_pipe_execute_number()

Review comment:
       You are using the term `time` or `number` throughout the code, but 
please use more specific terms. I think `time` is more like `duration` and 
`number` is more like `elapsed_time`?
   
   Please update your naming convention in all files. I won't point out each of 
them.

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -42,6 +52,75 @@ using GlobalOutputPair = std::pair<int, int>;
  * The first 'int' is the module index, and the second 'int' is the module 
output index.
  */
 using ModuleOutputPair = std::pair<int, int>;
+/*!
+ *\brief The pair includes the module index and the module input index.
+ * The first 'int' is the module index, and the second 'int' is the module 
input index.
+ */
+using ModuleInputPair = std::pair<int, int>;
+/*!\brief The data notification structure.*/
+class DataNotify {
+ private:
+  /*!\brief The 'contitional variable' is used to wait for notification.*/
+  std::condition_variable condition_;
+  /*!\brief The mutex is used to protect the 'conditional variable'.*/
+  std::mutex mutex_;
+  /*!\brief Whether a data is ready or not.*/
+  volatile bool data_ready_ = false;
+  /*!\brief Whether the thread should exit or not.*/
+  volatile bool exit_state_ = false;

Review comment:
       Use atomic

##########
File path: src/runtime/pipeline/pipeline_executor.cc
##########
@@ -242,6 +237,13 @@ std::pair<int, int> PipelineExecutor::GetInputIndex(const 
std::string& name) {
   auto gruntime = runtimes_[index.first];
   return std::make_pair(index.first, gruntime->GetInputIndex(index.second));
 }
+/*!
+ * \brief Getting the times of pipeline running.
+ * \return Returning the times of pipeline running.

Review comment:
       Not useful to repeat similar comments.

##########
File path: src/runtime/pipeline/pipeline_scheduler.cc
##########
@@ -46,6 +47,10 @@ std::vector<std::shared_ptr<BackendRuntime>> 
PipelineScheduler::PipelineInit(
     NDArray output = 
runtimes[output_pair.first]->CreateFromOutput(output_pair.second);
     output_arrays_.push_back(output);
   }
+  // Initializing and then running the work thread.
+  for (auto runtime : runtimes) {
+    runtime->Pipeline_Initialize(pipeline_config, &runtimes);

Review comment:
       InitializePipeline

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -42,6 +52,75 @@ using GlobalOutputPair = std::pair<int, int>;
  * The first 'int' is the module index, and the second 'int' is the module 
output index.
  */
 using ModuleOutputPair = std::pair<int, int>;
+/*!
+ *\brief The pair includes the module index and the module input index.
+ * The first 'int' is the module index, and the second 'int' is the module 
input index.
+ */
+using ModuleInputPair = std::pair<int, int>;
+/*!\brief The data notification structure.*/
+class DataNotify {
+ private:
+  /*!\brief The 'contitional variable' is used to wait for notification.*/
+  std::condition_variable condition_;

Review comment:
       A better name than `condition`? How about `notify_cv`.

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -42,6 +52,75 @@ using GlobalOutputPair = std::pair<int, int>;
  * The first 'int' is the module index, and the second 'int' is the module 
output index.
  */
 using ModuleOutputPair = std::pair<int, int>;
+/*!
+ *\brief The pair includes the module index and the module input index.
+ * The first 'int' is the module index, and the second 'int' is the module 
input index.
+ */
+using ModuleInputPair = std::pair<int, int>;
+/*!\brief The data notification structure.*/
+class DataNotify {
+ private:
+  /*!\brief The 'contitional variable' is used to wait for notification.*/
+  std::condition_variable condition_;
+  /*!\brief The mutex is used to protect the 'conditional variable'.*/
+  std::mutex mutex_;
+  /*!\brief Whether a data is ready or not.*/
+  volatile bool data_ready_ = false;
+  /*!\brief Whether the thread should exit or not.*/
+  volatile bool exit_state_ = false;
+  /*!\brief The index of runtime which is sending out the data notification.*/
+  int parent_idx_;
+  /*!\brief The index of runtime output interface which is sending out the 
data notification.*/
+  int parent_output_idx_;
+
+ public:
+  /*!
+   * \brief Constructing the DataNotify class.
+   * \param parent_idx The index of runtime which is sending out the data 
notification
+   * \param parent_output_idx The index of runtime output interface which is 
sending out
+   *  the data notification.
+   */
+  DataNotify(int parent_idx, int parent_output_idx) {
+    parent_idx_ = parent_idx;
+    parent_output_idx_ = parent_output_idx;
+  }
+  /*!
+   * \brief Getting the notification source.
+   * \return The first 'int' is the runtime index, and the second 'int' is the 
output index.
+   */
+  std::pair<int, int> GetNotifySource(void) {
+    return std::make_pair(parent_idx_, parent_output_idx_);
+  }
+  /*!
+   *\brief Waiting the notification.
+   *\return Returning the value 'false' when the notification is in a 'exit' 
state, else
+   * return true.
+   */
+  bool Wait(void) {
+    std::unique_lock<std::mutex> lock(mutex_);
+    condition_.wait(lock, [&] { return this->data_ready_; });
+    data_ready_ = false;
+    return !exit_state_;
+  }
+  /*!brief Sending the notification in which the related data is ready.*/
+  void Notify(void) {
+    {
+      std::lock_guard<std::mutex> lock(mutex_);
+      data_ready_ = true;

Review comment:
       Can get rid of mutex if you make `data_ready` atomic

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -42,6 +52,75 @@ using GlobalOutputPair = std::pair<int, int>;
  * The first 'int' is the module index, and the second 'int' is the module 
output index.
  */
 using ModuleOutputPair = std::pair<int, int>;
+/*!
+ *\brief The pair includes the module index and the module input index.
+ * The first 'int' is the module index, and the second 'int' is the module 
input index.
+ */
+using ModuleInputPair = std::pair<int, int>;
+/*!\brief The data notification structure.*/
+class DataNotify {
+ private:
+  /*!\brief The 'contitional variable' is used to wait for notification.*/
+  std::condition_variable condition_;
+  /*!\brief The mutex is used to protect the 'conditional variable'.*/
+  std::mutex mutex_;
+  /*!\brief Whether a data is ready or not.*/
+  volatile bool data_ready_ = false;
+  /*!\brief Whether the thread should exit or not.*/
+  volatile bool exit_state_ = false;
+  /*!\brief The index of runtime which is sending out the data notification.*/
+  int parent_idx_;
+  /*!\brief The index of runtime output interface which is sending out the 
data notification.*/
+  int parent_output_idx_;

Review comment:
       I don't understand the difference of the two.

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -386,6 +506,99 @@ class BackendRuntime {
   tvm::runtime::PackedFunc get_num_inputs_;
   tvm::runtime::PackedFunc get_input_index_;
   tvm::runtime::PackedFunc run_;
+  /*!\brief The working thread is used to execute the runtimes in pipeline.*/

Review comment:
       worker

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -189,6 +287,18 @@ class ConfigPipelineExecution {
     ICHECK(config_.find(key) != config_.end());
     return config_[key];
   }
+  /*!
+   * \brief Enumurating the binding configuration for a specify runtime.

Review comment:
       typo
   
   specified

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -42,6 +52,75 @@ using GlobalOutputPair = std::pair<int, int>;
  * The first 'int' is the module index, and the second 'int' is the module 
output index.
  */
 using ModuleOutputPair = std::pair<int, int>;
+/*!
+ *\brief The pair includes the module index and the module input index.
+ * The first 'int' is the module index, and the second 'int' is the module 
input index.
+ */
+using ModuleInputPair = std::pair<int, int>;
+/*!\brief The data notification structure.*/
+class DataNotify {
+ private:
+  /*!\brief The 'contitional variable' is used to wait for notification.*/
+  std::condition_variable condition_;
+  /*!\brief The mutex is used to protect the 'conditional variable'.*/
+  std::mutex mutex_;
+  /*!\brief Whether a data is ready or not.*/
+  volatile bool data_ready_ = false;
+  /*!\brief Whether the thread should exit or not.*/
+  volatile bool exit_state_ = false;
+  /*!\brief The index of runtime which is sending out the data notification.*/
+  int parent_idx_;
+  /*!\brief The index of runtime output interface which is sending out the 
data notification.*/
+  int parent_output_idx_;
+
+ public:
+  /*!
+   * \brief Constructing the DataNotify class.
+   * \param parent_idx The index of runtime which is sending out the data 
notification
+   * \param parent_output_idx The index of runtime output interface which is 
sending out
+   *  the data notification.
+   */
+  DataNotify(int parent_idx, int parent_output_idx) {
+    parent_idx_ = parent_idx;
+    parent_output_idx_ = parent_output_idx;
+  }
+  /*!
+   * \brief Getting the notification source.
+   * \return The first 'int' is the runtime index, and the second 'int' is the 
output index.
+   */
+  std::pair<int, int> GetNotifySource(void) {
+    return std::make_pair(parent_idx_, parent_output_idx_);
+  }
+  /*!
+   *\brief Waiting the notification.

Review comment:
       Waiting for

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -367,11 +477,21 @@ struct ParamConnectionConfig {
  *\brief Backend Runtime.
  */
 class BackendRuntime {
+  using ModuleInputPairList = 
std::vector<std::pair<std::shared_ptr<BackendRuntime>, int>>;
+
  private:
   /*\brief The index of runtime indicates the runtime position in the 
pipeline.*/
   int runtime_idx_;
   /*\brief The Runtime module of a backend graph executor.*/
   Module module_;
+  /*\brief The thread is associated with the current runtime*/
+  std::thread thread_;
+  /*\brief A list of runtime which depends on the current runtime.*/
+  std::unordered_map<int, ModuleInputPairList> childs_;
+  /*\brief A map including the runtime input index and the notification data 
struction.*/

Review comment:
       structure

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -367,11 +477,21 @@ struct ParamConnectionConfig {
  *\brief Backend Runtime.
  */
 class BackendRuntime {
+  using ModuleInputPairList = 
std::vector<std::pair<std::shared_ptr<BackendRuntime>, int>>;
+
  private:
   /*\brief The index of runtime indicates the runtime position in the 
pipeline.*/
   int runtime_idx_;
   /*\brief The Runtime module of a backend graph executor.*/
   Module module_;
+  /*\brief The thread is associated with the current runtime*/
+  std::thread thread_;
+  /*\brief A list of runtime which depends on the current runtime.*/
+  std::unordered_map<int, ModuleInputPairList> childs_;

Review comment:
       children

##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -53,6 +132,16 @@ class ConfigBindings {
   int GetGlobalOutputIndex() const { return global_output_index_; }
   /*!\brief Returning the binding configuration.*/
   std::unordered_map<int, std::string>& Get() { return bindings_; }
+  /*!
+   * \brief Enumrating the binding configuration.

Review comment:
       typo




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to