huajsj commented on a change in pull request #10234:
URL: https://github.com/apache/tvm/pull/10234#discussion_r806551025
##########
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:
seems like not need to use atomic, because 'data_ready_' already
protected by 'mutex_' and for exit_state, there is only a single 'writing' in
ExitNotify then no race condition can happen. although atomic is very light
weight but it still involved additional perf cost, if not necessary we may need
to avoid use it here.
##########
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:
std::contiditon_variable already used a mutex to protect data_ready_,
to cooperate with such mechanism we may need use mutex at this function too.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
fixed.
##########
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:
the first one is the runtime index, second one is the output index in
the runtime, we use such 2 index value to located a output data in pipeline
forwarding.
##########
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:
the first one is the runtime index, second one is the output index in
the runtime, we use such 2 index value to located a output data in pipeline
forwarding. merged these 2 value into a ModuleOutputPair structure to make it
more readable.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]