From e697e9bde6c83968edcd79b949334542d1ab25d1 Mon Sep 17 00:00:00 2001 From: Paul Nathan Stickney Date: Sun, 27 Oct 2019 18:04:44 -0700 Subject: [PATCH 001/165] #537: regisry: eliminate T-lambda in Auto Registry - Replace the T-lambda with a strong type-erased proxy. This avoids signifcant T-cost. Uses unique_ptr because shared_ptr is also T-costly. (Working on find a middle-ground with C++ and type-erasure as well.. Base + Proxy + Impl seems okay, if not verbose.) --- src/vt/registry/auto/auto_registry_common.h | 56 +++++++++++++++---- .../auto/auto_registry_general_impl.h | 19 +++++-- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/vt/registry/auto/auto_registry_common.h b/src/vt/registry/auto/auto_registry_common.h index d4d0810ca5..bc26eed4c6 100644 --- a/src/vt/registry/auto/auto_registry_common.h +++ b/src/vt/registry/auto/auto_registry_common.h @@ -76,7 +76,7 @@ using AutoActiveIndexType = std::size_t; using AutoActiveObjGroupType = objgroup::ActiveObjAnyType; using HandlerManagerType = vt::HandlerManager; -using AutoHandlerType = int32_t; +using AutoHandlerType = HandlerType; using NumArgsType = int16_t; enum struct RegistryTypeEnum { @@ -97,25 +97,54 @@ enum struct RegistryTypeEnum { static struct NumArgsTagType { } NumArgsTag { }; #pragma GCC diagnostic pop +struct RegistrarGenInfoBase { + /// Return the registered handler type. + virtual HandlerType getRegisteredIndex() = 0; + virtual ~RegistrarGenInfoBase() {} +}; + +struct RegistrarGenInfo : RegistrarGenInfoBase { + RegistrarGenInfo() { + } + + explicit RegistrarGenInfo(RegistrarGenInfoBase* owned_proxy) + : proxy_(owned_proxy) + { + } + + // Using unique_ptr; can expand later. + RegistrarGenInfo(RegistrarGenInfo const& in) = delete; + + RegistrarGenInfo(RegistrarGenInfo&& in) { + proxy_.swap(in.proxy_); + } + + virtual HandlerType getRegisteredIndex() { + return proxy_->getRegisteredIndex(); + } +private: + std::unique_ptr proxy_ = nullptr; +}; + template struct AutoRegInfo { - using GenFnType = std::function; - FnT activeFunT; NumArgsType args_ = 1; AutoHandlerType obj_idx_ = -1; - GenFnType gen_obj_idx_ = nullptr; + RegistrarGenInfo gen_obj_idx_; #if backend_check_enabled(trace_enabled) trace::TraceEntryIDType event_id; AutoRegInfo( - FnT const& in_active_fun_t, GenFnType in_gen, + FnT const& in_active_fun_t, + RegistrarGenInfo in_gen, trace::TraceEntryIDType const& in_event_id - ) : activeFunT(in_active_fun_t), gen_obj_idx_(in_gen), event_id(in_event_id) + ) : activeFunT(in_active_fun_t), gen_obj_idx_(std::move(in_gen)), event_id(in_event_id) { } AutoRegInfo( NumArgsTagType, - FnT const& in_active_fun_t, trace::TraceEntryIDType const& in_event_id, + FnT const& in_active_fun_t, + trace::TraceEntryIDType const& in_event_id, NumArgsType const& in_args ) : activeFunT(in_active_fun_t), args_(in_args), event_id(in_event_id) { } @@ -123,19 +152,22 @@ struct AutoRegInfo { return event_id; } #else - explicit AutoRegInfo(FnT const& in_active_fun_t, GenFnType in_gen) - : activeFunT(in_active_fun_t), gen_obj_idx_(in_gen) + explicit AutoRegInfo( + FnT const& in_active_fun_t, + RegistrarGenInfo in_gen + ) : activeFunT(in_active_fun_t), gen_obj_idx_(std::move(in_gen)) { } AutoRegInfo( NumArgsTagType, - FnT const& in_active_fun_t, NumArgsType const& in_args + FnT const& in_active_fun_t, + NumArgsType const& in_args ) : activeFunT(in_active_fun_t), args_(in_args) { } #endif AutoHandlerType getObjIdx() { - if (obj_idx_ == -1 and gen_obj_idx_ != nullptr) { - obj_idx_ = gen_obj_idx_(); + if (obj_idx_ == -1) { + obj_idx_ = gen_obj_idx_.getRegisteredIndex(); } return obj_idx_; } diff --git a/src/vt/registry/auto/auto_registry_general_impl.h b/src/vt/registry/auto/auto_registry_general_impl.h index b584e22fa3..ee0bb65ba5 100644 --- a/src/vt/registry/auto/auto_registry_general_impl.h +++ b/src/vt/registry/auto/auto_registry_general_impl.h @@ -51,17 +51,24 @@ #include "vt/registry/auto/auto_registry_general.h" #include "vt/objgroup/type_registry/registry.h" +#include + namespace vt { namespace auto_registry { +template +struct RegistrarGenInfoImpl : RegistrarGenInfoBase { + virtual HandlerType getRegisteredIndex() { + return objgroup::registry::makeObjIdx(); + } +}; + template RegistrarGen::RegistrarGen() { RegT& reg = getAutoRegistryGen(); index = reg.size(); - auto fn = ActFnT::getFunction(); - auto gen_fn = []() -> AutoHandlerType { - return objgroup::registry::makeObjIdx(); - }; + FnT fn = reinterpret_cast(ActFnT::getFunction()); + RegistrarGenInfo indexAccessor{new RegistrarGenInfoImpl()}; #if backend_check_enabled(trace_enabled) using Tn = typename ActFnT::ActFnType; @@ -72,9 +79,9 @@ RegistrarGen::RegistrarGen() { parsed_type_name.getNamespace(), parsed_type_name.getFuncParams() ); - reg.emplace_back(InfoT{reinterpret_cast(fn), gen_fn, trace_ep}); + reg.emplace_back(InfoT{fn, std::move(indexAccessor), trace_ep}); #else - reg.emplace_back(InfoT{reinterpret_cast(fn), gen_fn}); + reg.emplace_back(InfoT{fn, std::move(indexAccessor)}); #endif } From e5e802dd36c94698c4463e6ebb00dde545bc6030 Mon Sep 17 00:00:00 2001 From: Paul Nathan Stickney Date: Sun, 10 Nov 2019 12:37:34 -0800 Subject: [PATCH 002/165] #537: override and idiom updates - Specifies the 'override' keyword as appropriate - Still using unique_ptr.swap as there were.. issues.. attempting to use it in an initializer position. --- src/vt/registry/auto/auto_registry_common.h | 2 +- src/vt/registry/auto/auto_registry_general_impl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vt/registry/auto/auto_registry_common.h b/src/vt/registry/auto/auto_registry_common.h index bc26eed4c6..fdb71db39b 100644 --- a/src/vt/registry/auto/auto_registry_common.h +++ b/src/vt/registry/auto/auto_registry_common.h @@ -119,7 +119,7 @@ struct RegistrarGenInfo : RegistrarGenInfoBase { proxy_.swap(in.proxy_); } - virtual HandlerType getRegisteredIndex() { + virtual HandlerType getRegisteredIndex() override { return proxy_->getRegisteredIndex(); } private: diff --git a/src/vt/registry/auto/auto_registry_general_impl.h b/src/vt/registry/auto/auto_registry_general_impl.h index ee0bb65ba5..6d82cba5bd 100644 --- a/src/vt/registry/auto/auto_registry_general_impl.h +++ b/src/vt/registry/auto/auto_registry_general_impl.h @@ -57,7 +57,7 @@ namespace vt { namespace auto_registry { template struct RegistrarGenInfoImpl : RegistrarGenInfoBase { - virtual HandlerType getRegisteredIndex() { + virtual HandlerType getRegisteredIndex() override { return objgroup::registry::makeObjIdx(); } }; From d70b70c50d801a2ce5e077ef59749ceed5011295 Mon Sep 17 00:00:00 2001 From: Paul Nathan Stickney Date: Sun, 10 Nov 2019 13:15:03 -0800 Subject: [PATCH 003/165] #537: make RegistrarGenInfo ownership taking explicit - Adds static method to make ownership taking explicit and hides lifetime-taking ctor. --- src/vt/registry/auto/auto_registry_common.h | 16 ++++++++++++---- .../registry/auto/auto_registry_general_impl.h | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/vt/registry/auto/auto_registry_common.h b/src/vt/registry/auto/auto_registry_common.h index fdb71db39b..35ea291179 100644 --- a/src/vt/registry/auto/auto_registry_common.h +++ b/src/vt/registry/auto/auto_registry_common.h @@ -104,12 +104,14 @@ struct RegistrarGenInfoBase { }; struct RegistrarGenInfo : RegistrarGenInfoBase { - RegistrarGenInfo() { + + /// Create a new object. + /// Takes complete ownership of the supplied object (pointer). + static RegistrarGenInfo takeOwnership(RegistrarGenInfoBase *owned_proxy) { + return RegistrarGenInfo(owned_proxy); } - explicit RegistrarGenInfo(RegistrarGenInfoBase* owned_proxy) - : proxy_(owned_proxy) - { + RegistrarGenInfo() { } // Using unique_ptr; can expand later. @@ -122,6 +124,12 @@ struct RegistrarGenInfo : RegistrarGenInfoBase { virtual HandlerType getRegisteredIndex() override { return proxy_->getRegisteredIndex(); } + +private: + explicit RegistrarGenInfo(RegistrarGenInfoBase* owned_proxy) + : proxy_(owned_proxy) { + } + private: std::unique_ptr proxy_ = nullptr; }; diff --git a/src/vt/registry/auto/auto_registry_general_impl.h b/src/vt/registry/auto/auto_registry_general_impl.h index 6d82cba5bd..00c0d2a009 100644 --- a/src/vt/registry/auto/auto_registry_general_impl.h +++ b/src/vt/registry/auto/auto_registry_general_impl.h @@ -68,7 +68,8 @@ RegistrarGen::RegistrarGen() { index = reg.size(); FnT fn = reinterpret_cast(ActFnT::getFunction()); - RegistrarGenInfo indexAccessor{new RegistrarGenInfoImpl()}; + RegistrarGenInfo indexAccessor = RegistrarGenInfo::takeOwnership( + new RegistrarGenInfoImpl()); #if backend_check_enabled(trace_enabled) using Tn = typename ActFnT::ActFnType; From c52fb04c41238c22aef142b5921a599cf6c09af9 Mon Sep 17 00:00:00 2001 From: Paul Nathan Stickney Date: Sun, 27 Oct 2019 19:12:19 -0700 Subject: [PATCH 004/165] #521: eliminate lambda-closure (and VirtualMsgPtr entirely) - Folded VirtualMsgPtr into MsgSharedPtr making 'to' and 'toVirtual' synonyms. If the wrapped message type has a non-trivial destructor then a proxy 'deref' object is is used so that all derefs will apply to the original T-type (and thus invoke the delete-expression appropriately). This type-erasure ensures that 'messageDeref' is always invoked upon the correct T for expeted delete-expr behavior. - Remove unused code and unified methods - Ensure move contructor and added move-assignment operator (steal resources!!!!) - Remove messageDeref> templates; if having a MsgSharedPtr, use it.. --- src/vt/messaging/message/refs.h | 6 - src/vt/messaging/message/refs.impl.h | 10 - src/vt/messaging/message/smart_ptr.h | 274 +++++++++++-------- src/vt/messaging/message/smart_ptr_virtual.h | 104 ------- src/vt/messaging/pending_send.cc | 2 +- src/vt/objgroup/manager.cc | 2 +- src/vt/objgroup/manager.fwd.h | 1 - src/vt/objgroup/manager.h | 2 +- 8 files changed, 158 insertions(+), 243 deletions(-) delete mode 100644 src/vt/messaging/message/smart_ptr_virtual.h diff --git a/src/vt/messaging/message/refs.h b/src/vt/messaging/message/refs.h index ccea1bba36..26d70383dd 100644 --- a/src/vt/messaging/message/refs.h +++ b/src/vt/messaging/message/refs.h @@ -51,15 +51,9 @@ namespace vt { -template