You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ma...@apache.org on 2022/05/17 19:51:08 UTC
[tvm] branch main updated: [BYOC] Threadsafe initialization of JSONRuntime module (#11339)
This is an automated email from the ASF dual-hosted git repository.
masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 2f7d732972 [BYOC] Threadsafe initialization of JSONRuntime module (#11339)
2f7d732972 is described below
commit 2f7d732972f3605bd094609ab9ce5b7d5d80eac9
Author: apeskov <pe...@gmail.com>
AuthorDate: Tue May 17 22:51:03 2022 +0300
[BYOC] Threadsafe initialization of JSONRuntime module (#11339)
Signed-off-by: Alexander Peskov <pe...@gmail.com>
---
src/runtime/contrib/json/json_runtime.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/runtime/contrib/json/json_runtime.h b/src/runtime/contrib/json/json_runtime.h
index 0c6d0f6d71..374a440e29 100644
--- a/src/runtime/contrib/json/json_runtime.h
+++ b/src/runtime/contrib/json/json_runtime.h
@@ -88,8 +88,11 @@ class JSONRuntimeBase : public ModuleNode {
// The function to initialize constant tensors.
return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) {
ICHECK_EQ(args.size(), 1U);
- this->Init(args[0]);
- this->initialized_ = true;
+ std::lock_guard<std::mutex> guard(this->initialize_mutex_);
+ if (!this->initialized_) {
+ this->Init(args[0]);
+ this->initialized_ = true;
+ }
*rv = 0;
});
} else {
@@ -270,6 +273,8 @@ class JSONRuntimeBase : public ModuleNode {
std::vector<uint32_t> const_idx_;
/*! \brief Indicate if the engine has been initialized. */
bool initialized_{false};
+ /*! \brief Initializer mutex*/
+ std::mutex initialize_mutex_;
};
} // namespace json