Skip to content

Commit

Permalink
[PyTorch] Make tls_local_dispatch_key_set inlineable (reapply) (pytor…
Browse files Browse the repository at this point in the history
…ch#49412)

Summary:
Pull Request resolved: pytorch#49412

FLAGS_disable_variable_dispatch had to go, but it looks like the only user was some benchmarks anyway.
ghstack-source-id: 118669590

Test Plan:
Small (order of 0.1% improvement) on Internal benchmarks. Wait for
GitHub CI since this was reverted before due to CI break

Reviewed By: ezyang

Differential Revision: D25547962

fbshipit-source-id: 58424b1da230fdc5d27349af762126a5512fce43
  • Loading branch information
swolchok authored and hwangdeyu committed Dec 23, 2020
1 parent 51e4cc9 commit e70d3f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
20 changes: 3 additions & 17 deletions c10/core/impl/LocalDispatchKeySet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
namespace c10 {
namespace impl {

C10_DEFINE_bool(disable_variable_dispatch, false, "This flag forcibly disables the Variable code paths from executing, which currently breaks profiling in the process.");

namespace {

/// In the CAFFE2_FB_LIMITED_MOBILE_CAPABILITY build setting,
/// thread_local is not supported.
#ifndef CAFFE2_FB_LIMITED_MOBILE_CAPABILITY
Expand All @@ -18,25 +14,15 @@ thread_local PODLocalDispatchKeySet raw_local_dispatch_key_set;

#else // defined(CAFFE2_FB_LIMITED_MOBILE_CAPABILITY)

static PODLocalDispatchKeySet raw_local_dispatch_key_set;
PODLocalDispatchKeySet raw_local_dispatch_key_set;

#endif

} // anonymous namespace

#ifdef _MSC_VER
LocalDispatchKeySet tls_local_dispatch_key_set() {
// Hack until variable performance is fixed
//
// ezyang: I'm pretty unhappy about this implementation, it looks wrong
// to me, as it seems to be performing a mutation on
// raw_local_dispatch_key_set. I can't conveniently test the correct
// version though...
if (FLAGS_disable_variable_dispatch) {
raw_local_dispatch_key_set.set_excluded(
raw_local_dispatch_key_set.excluded() | autograd_dispatch_keyset);
}
return raw_local_dispatch_key_set;
}
#endif // _MSC_VER

void _force_tls_local_dispatch_key_set(LocalDispatchKeySet key_set) {
raw_local_dispatch_key_set = PODLocalDispatchKeySet {
Expand Down
19 changes: 17 additions & 2 deletions c10/core/impl/LocalDispatchKeySet.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
namespace c10 {
namespace impl {

C10_DECLARE_bool(disable_variable_dispatch);

// POD version of LocalDispatchKeySet. Declared here just so that
// we can put it in the guards.
struct C10_API PODLocalDispatchKeySet {
Expand Down Expand Up @@ -54,7 +52,24 @@ struct C10_API LocalDispatchKeySet {
DispatchKeySet excluded_;
};

// thread_local variables cannot be C10_API on Windows.
#ifdef _MSC_VER
C10_API LocalDispatchKeySet tls_local_dispatch_key_set();
#else // _MSC_VER
/// In the CAFFE2_FB_LIMITED_MOBILE_CAPABILITY build setting,
/// thread_local is not supported.
#ifndef CAFFE2_FB_LIMITED_MOBILE_CAPABILITY
extern C10_API thread_local PODLocalDispatchKeySet raw_local_dispatch_key_set;
#else // defined(CAFFE2_FB_LIMITED_MOBILE_CAPABILITY)
extern C10_API PODLocalDispatchKeySet raw_local_dispatch_key_set;
#endif

inline C10_API LocalDispatchKeySet tls_local_dispatch_key_set() {
// Don't let people fiddle with the thread_local directly just
// because they include this header.
return raw_local_dispatch_key_set;
}
#endif // _MSC_VER

// Internal, use ThreadLocalStateGuard
C10_API void _force_tls_local_dispatch_key_set(LocalDispatchKeySet key_set);
Expand Down

0 comments on commit e70d3f0

Please sign in to comment.