Changes imported from Abseil "staging" branch:
- f59c2332341d6b1a3e045d61eb0065f7a226f807 Avoid preprocessing '__CUDACC_VER__ >= 70000' on CUDA 9,... by Abseil Team <absl-team@google.com> - 12dd22cf967603e9a12d58abfe877989d61844e3 Internal change. by Greg Falcon <gfalcon@google.com> GitOrigin-RevId: f59c2332341d6b1a3e045d61eb0065f7a226f807 Change-Id: If4f5274e6d638a2ac86f1377e6ac0481dc584f19
This commit is contained in:
		
							parent
							
								
									6280bddf55
								
							
						
					
					
						commit
						4972c72c5c
					
				
					 13 changed files with 70 additions and 21 deletions
				
			
		|  | @ -181,21 +181,21 @@ | ||||||
| // __SIZEOF_INT128__ but not all versions actually support __int128.
 | // __SIZEOF_INT128__ but not all versions actually support __int128.
 | ||||||
| #ifdef ABSL_HAVE_INTRINSIC_INT128 | #ifdef ABSL_HAVE_INTRINSIC_INT128 | ||||||
| #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set | #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set | ||||||
| #elif (defined(__clang__) && defined(__SIZEOF_INT128__) &&               \ | #elif defined(__SIZEOF_INT128__) | ||||||
|        !defined(__aarch64__)) ||                                         \ | #if (defined(__clang__) && !defined(__aarch64__)) ||      \ | ||||||
|     (defined(__CUDACC__) && defined(__SIZEOF_INT128__) &&                \ |     (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \ | ||||||
|      __CUDACC_VER_MAJOR__ >= 9) ||                                       \ |     (!defined(__clang__) && !defined(__CUDACC__) && defined(__GNUC__)) | ||||||
|     (!defined(__clang__) && !defined(__CUDACC__) && defined(__GNUC__) && \ |  | ||||||
|      defined(__SIZEOF_INT128__)) |  | ||||||
| #define ABSL_HAVE_INTRINSIC_INT128 1 | #define ABSL_HAVE_INTRINSIC_INT128 1 | ||||||
|  | #elif defined(__CUDACC__) | ||||||
| // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
 | // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
 | ||||||
| // std::string explaining that it has been removed starting with CUDA 9. We can't
 | // std::string explaining that it has been removed starting with CUDA 9. We use
 | ||||||
| // compare both variants in a single boolean expression because there is no
 | // nested #ifs because there is no short-circuiting in the preprocessor.
 | ||||||
| // short-circuiting in the preprocessor.
 | // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
 | ||||||
| #elif defined(__CUDACC__) && defined(__SIZEOF_INT128__) && \ | #if __CUDACC_VER__ >= 70000 | ||||||
|     __CUDACC_VER__ >= 7000 |  | ||||||
| #define ABSL_HAVE_INTRINSIC_INT128 1 | #define ABSL_HAVE_INTRINSIC_INT128 1 | ||||||
| #endif | #endif  // __CUDACC_VER__ >= 70000
 | ||||||
|  | #endif  // defined(__CUDACC__)
 | ||||||
|  | #endif  // ABSL_HAVE_INTRINSIC_INT128
 | ||||||
| 
 | 
 | ||||||
| // ABSL_HAVE_EXCEPTIONS
 | // ABSL_HAVE_EXCEPTIONS
 | ||||||
| //
 | //
 | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ | ||||||
| // See the License for the specific language governing permissions and
 | // See the License for the specific language governing permissions and
 | ||||||
| // limitations under the License.
 | // limitations under the License.
 | ||||||
| 
 | 
 | ||||||
|  | #include "absl/base/attributes.h" | ||||||
| #include "absl/base/config.h" | #include "absl/base/config.h" | ||||||
| 
 | 
 | ||||||
| #if ABSL_HAVE_MMAP | #if ABSL_HAVE_MMAP | ||||||
|  |  | ||||||
|  | @ -83,11 +83,6 @@ void RegisterSpinLockProfiler(void (*fn)(const void *contendedlock, | ||||||
|   submit_profile_data.Store(fn); |   submit_profile_data.Store(fn); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static inline bool IsCooperative( |  | ||||||
|     base_internal::SchedulingMode scheduling_mode) { |  | ||||||
|   return scheduling_mode == base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // Uncommon constructors.
 | // Uncommon constructors.
 | ||||||
| SpinLock::SpinLock(base_internal::SchedulingMode mode) | SpinLock::SpinLock(base_internal::SchedulingMode mode) | ||||||
|     : lockword_(IsCooperative(mode) ? kSpinLockCooperative : 0) { |     : lockword_(IsCooperative(mode) ? kSpinLockCooperative : 0) { | ||||||
|  |  | ||||||
|  | @ -151,6 +151,12 @@ class LOCKABLE SpinLock { | ||||||
|   enum { kWaitTimeMask =                      // Includes kSpinLockSleeper.
 |   enum { kWaitTimeMask =                      // Includes kSpinLockSleeper.
 | ||||||
|     ~(kSpinLockHeld | kSpinLockCooperative | kSpinLockDisabledScheduling) }; |     ~(kSpinLockHeld | kSpinLockCooperative | kSpinLockDisabledScheduling) }; | ||||||
| 
 | 
 | ||||||
|  |   // Returns true if the provided scheduling mode is cooperative.
 | ||||||
|  |   static constexpr bool IsCooperative( | ||||||
|  |       base_internal::SchedulingMode scheduling_mode) { | ||||||
|  |     return scheduling_mode == base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   uint32_t TryLockInternal(uint32_t lock_value, uint32_t wait_cycles); |   uint32_t TryLockInternal(uint32_t lock_value, uint32_t wait_cycles); | ||||||
|   void InitLinkerInitializedAndCooperative(); |   void InitLinkerInitializedAndCooperative(); | ||||||
|   void SlowLock() ABSL_ATTRIBUTE_COLD; |   void SlowLock() ABSL_ATTRIBUTE_COLD; | ||||||
|  |  | ||||||
|  | @ -14,6 +14,8 @@ | ||||||
| 
 | 
 | ||||||
| #include "absl/base/internal/sysinfo.h" | #include "absl/base/internal/sysinfo.h" | ||||||
| 
 | 
 | ||||||
|  | #include "absl/base/attributes.h" | ||||||
|  | 
 | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
| #include <shlwapi.h> | #include <shlwapi.h> | ||||||
| #include <windows.h> | #include <windows.h> | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ | ||||||
| #include <vector> | #include <vector> | ||||||
| 
 | 
 | ||||||
| #include "gtest/gtest.h" | #include "gtest/gtest.h" | ||||||
|  | #include "absl/base/attributes.h" | ||||||
| #include "absl/base/internal/spinlock.h" | #include "absl/base/internal/spinlock.h" | ||||||
| #include "absl/base/macros.h" | #include "absl/base/macros.h" | ||||||
| #include "absl/synchronization/internal/per_thread_sem.h" | #include "absl/synchronization/internal/per_thread_sem.h" | ||||||
|  |  | ||||||
|  | @ -23,6 +23,7 @@ | ||||||
| #include <vector> | #include <vector> | ||||||
| 
 | 
 | ||||||
| #include "gtest/gtest.h" | #include "gtest/gtest.h" | ||||||
|  | #include "absl/base/attributes.h" | ||||||
| #include "absl/base/internal/low_level_scheduling.h" | #include "absl/base/internal/low_level_scheduling.h" | ||||||
| #include "absl/base/internal/scheduling_mode.h" | #include "absl/base/internal/scheduling_mode.h" | ||||||
| #include "absl/base/internal/spinlock.h" | #include "absl/base/internal/spinlock.h" | ||||||
|  | @ -53,7 +54,6 @@ namespace { | ||||||
| 
 | 
 | ||||||
| static constexpr int kArrayLength = 10; | static constexpr int kArrayLength = 10; | ||||||
| static uint32_t values[kArrayLength]; | static uint32_t values[kArrayLength]; | ||||||
| 
 |  | ||||||
| static SpinLock static_spinlock(base_internal::kLinkerInitialized); | static SpinLock static_spinlock(base_internal::kLinkerInitialized); | ||||||
| static SpinLock static_cooperative_spinlock( | static SpinLock static_cooperative_spinlock( | ||||||
|     base_internal::kLinkerInitialized, |     base_internal::kLinkerInitialized, | ||||||
|  | @ -61,6 +61,7 @@ static SpinLock static_cooperative_spinlock( | ||||||
| static SpinLock static_noncooperative_spinlock( | static SpinLock static_noncooperative_spinlock( | ||||||
|     base_internal::kLinkerInitialized, base_internal::SCHEDULE_KERNEL_ONLY); |     base_internal::kLinkerInitialized, base_internal::SCHEDULE_KERNEL_ONLY); | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| // Simple integer hash function based on the public domain lookup2 hash.
 | // Simple integer hash function based on the public domain lookup2 hash.
 | ||||||
| // http://burtleburtle.net/bob/c/lookup2.c
 | // http://burtleburtle.net/bob/c/lookup2.c
 | ||||||
| static uint32_t Hash32(uint32_t a, uint32_t c) { | static uint32_t Hash32(uint32_t a, uint32_t c) { | ||||||
|  | @ -187,11 +188,9 @@ TEST(SpinLock, WaitCyclesEncoding) { | ||||||
|     SpinLockTest::DecodeWaitCycles(before_max_value); |     SpinLockTest::DecodeWaitCycles(before_max_value); | ||||||
|   EXPECT_GT(expected_max_value_decoded, before_max_value_decoded); |   EXPECT_GT(expected_max_value_decoded, before_max_value_decoded); | ||||||
| } | } | ||||||
| 
 |  | ||||||
| TEST(SpinLockWithThreads, StaticSpinLock) { | TEST(SpinLockWithThreads, StaticSpinLock) { | ||||||
|   ThreadedTest(&static_spinlock); |   ThreadedTest(&static_spinlock); | ||||||
| } | } | ||||||
| 
 |  | ||||||
| TEST(SpinLockWithThreads, StackSpinLock) { | TEST(SpinLockWithThreads, StackSpinLock) { | ||||||
|   SpinLock spinlock; |   SpinLock spinlock; | ||||||
|   ThreadedTest(&spinlock); |   ThreadedTest(&spinlock); | ||||||
|  |  | ||||||
|  | @ -21,6 +21,7 @@ | ||||||
| 
 | 
 | ||||||
| #include <string.h> | #include <string.h> | ||||||
| 
 | 
 | ||||||
|  | #include "absl/base/attributes.h" | ||||||
| #include "absl/base/internal/spinlock.h" | #include "absl/base/internal/spinlock.h" | ||||||
| #include "absl/base/internal/thread_identity.h" | #include "absl/base/internal/thread_identity.h" | ||||||
| #include "absl/synchronization/internal/per_thread_sem.h" | #include "absl/synchronization/internal/per_thread_sem.h" | ||||||
|  |  | ||||||
|  | @ -28,6 +28,7 @@ | ||||||
| // (2) When a new edge (x->y) is inserted, do nothing if rank[x] < rank[y].
 | // (2) When a new edge (x->y) is inserted, do nothing if rank[x] < rank[y].
 | ||||||
| // (3) Otherwise: adjust ranks in the neighborhood of x and y.
 | // (3) Otherwise: adjust ranks in the neighborhood of x and y.
 | ||||||
| 
 | 
 | ||||||
|  | #include "absl/base/attributes.h" | ||||||
| // This file is a no-op if the required LowLevelAlloc support is missing.
 | // This file is a no-op if the required LowLevelAlloc support is missing.
 | ||||||
| #include "absl/base/internal/low_level_alloc.h" | #include "absl/base/internal/low_level_alloc.h" | ||||||
| #ifndef ABSL_LOW_LEVEL_ALLOC_MISSING | #ifndef ABSL_LOW_LEVEL_ALLOC_MISSING | ||||||
|  |  | ||||||
|  | @ -69,8 +69,22 @@ void ThreadTwo(absl::Mutex* mutex, absl::CondVar* condvar, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Launch thread 1 and thread 2, and block on their completion.
 | // Launch thread 1 and thread 2, and block on their completion.
 | ||||||
|  | // If any of 'mutex', 'condvar', or 'notification' is nullptr, use a locally
 | ||||||
|  | // constructed instance instead.
 | ||||||
| void RunTests(absl::Mutex* mutex, absl::CondVar* condvar, | void RunTests(absl::Mutex* mutex, absl::CondVar* condvar, | ||||||
|               absl::Notification* notification) { |               absl::Notification* notification) { | ||||||
|  |   absl::Mutex default_mutex; | ||||||
|  |   absl::CondVar default_condvar; | ||||||
|  |   absl::Notification default_notification; | ||||||
|  |   if (!mutex) { | ||||||
|  |     mutex = &default_mutex; | ||||||
|  |   } | ||||||
|  |   if (!condvar) { | ||||||
|  |     condvar = &default_condvar; | ||||||
|  |   } | ||||||
|  |   if (!notification) { | ||||||
|  |     notification = &default_notification; | ||||||
|  |   } | ||||||
|   bool state = false; |   bool state = false; | ||||||
|   std::thread thread_one(ThreadOne, mutex, condvar, notification, &state); |   std::thread thread_one(ThreadOne, mutex, condvar, notification, &state); | ||||||
|   std::thread thread_two(ThreadTwo, mutex, condvar, notification, &state); |   std::thread thread_two(ThreadTwo, mutex, condvar, notification, &state); | ||||||
|  | @ -85,6 +99,33 @@ void TestLocals() { | ||||||
|   RunTests(&mutex, &condvar, ¬ification); |   RunTests(&mutex, &condvar, ¬ification); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Global variables during start and termination
 | ||||||
|  | //
 | ||||||
|  | // In a translation unit, static storage duration variables are initialized in
 | ||||||
|  | // the order of their definitions, and destroyed in the reverse order of their
 | ||||||
|  | // definitions.  We can use this to arrange for tests to be run on these objects
 | ||||||
|  | // before they are created, and after they are destroyed.
 | ||||||
|  | 
 | ||||||
|  | class ConstructorTestRunner { | ||||||
|  |  public: | ||||||
|  |   ConstructorTestRunner(absl::Mutex* mutex, absl::CondVar* condvar, | ||||||
|  |                         absl::Notification* notification) { | ||||||
|  |     RunTests(mutex, condvar, notification); | ||||||
|  |   } | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | class DestructorTestRunner { | ||||||
|  |  public: | ||||||
|  |   DestructorTestRunner(absl::Mutex* mutex, absl::CondVar* condvar, | ||||||
|  |                        absl::Notification* notification) | ||||||
|  |       : mutex_(mutex), condvar_(condvar), notification_(notification) {} | ||||||
|  |   ~DestructorTestRunner() { RunTests(mutex_, condvar_, notification_); } | ||||||
|  |  private: | ||||||
|  |   absl::Mutex* mutex_; | ||||||
|  |   absl::CondVar* condvar_; | ||||||
|  |   absl::Notification* notification_; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| }  // namespace
 | }  // namespace
 | ||||||
| 
 | 
 | ||||||
| int main() { | int main() { | ||||||
|  |  | ||||||
|  | @ -249,7 +249,6 @@ static const struct { | ||||||
|   { 0,                           "Signal on " }, |   { 0,                           "Signal on " }, | ||||||
|   { 0,                           "SignalAll on " }, |   { 0,                           "SignalAll on " }, | ||||||
| }; | }; | ||||||
| 
 |  | ||||||
| static absl::base_internal::SpinLock synch_event_mu( | static absl::base_internal::SpinLock synch_event_mu( | ||||||
|     absl::base_internal::kLinkerInitialized); |     absl::base_internal::kLinkerInitialized); | ||||||
| // protects synch_event
 | // protects synch_event
 | ||||||
|  |  | ||||||
|  | @ -875,6 +875,7 @@ class SCOPED_LOCKABLE ReleasableMutexLock { | ||||||
| 
 | 
 | ||||||
| #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX | #ifdef ABSL_INTERNAL_USE_NONPROD_MUTEX | ||||||
| #else | #else | ||||||
|  | 
 | ||||||
| inline CondVar::CondVar() : cv_(0) {} | inline CondVar::CondVar() : cv_(0) {} | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,7 @@ | ||||||
| #include "absl/time/clock.h" | #include "absl/time/clock.h" | ||||||
| 
 | 
 | ||||||
|  | #include "absl/base/attributes.h" | ||||||
|  | 
 | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
| #include <windows.h> | #include <windows.h> | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue