Browse Source

Update contrib/libs/tbb to 2021.8.0

robot-contrib 2 years ago
parent
commit
70c82ac132

+ 1 - 0
contrib/libs/tbb/README.md

@@ -28,6 +28,7 @@ Here are [Release Notes](RELEASE_NOTES.md) and [System Requirements](SYSTEM_REQU
 * [oneTBB Developer Guide and Reference](https://oneapi-src.github.io/oneTBB)
 * [Migrating from TBB to oneTBB](https://oneapi-src.github.io/oneTBB/main/tbb_userguide/Migration_Guide.html)
 * [README for the CMake build system](cmake/README.md)
+* [oneTBB Testing Approach](https://oneapi-src.github.io/oneTBB/main/intro/testing_approach.html)
 * [Basic support for the Bazel build system](Bazel.md)
 * [oneTBB Discussions](https://github.com/oneapi-src/oneTBB/discussions)
 

+ 8 - 15
contrib/libs/tbb/include/oneapi/tbb/concurrent_queue.h

@@ -1,5 +1,5 @@
 /*
-    Copyright (c) 2005-2021 Intel Corporation
+    Copyright (c) 2005-2022 Intel Corporation
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -148,10 +148,7 @@ public:
 
     // Clear the queue. not thread-safe.
     void clear() {
-        while (!empty()) {
-            T value;
-            try_pop(value);
-        }
+        my_queue_representation->clear(my_allocator);
     }
 
     // Return allocator object
@@ -375,12 +372,12 @@ public:
     }
 
     // Attempt to dequeue an item from head of queue.
-    /** Does not wait for item to become available.
-        Returns true if successful; false otherwise. */
-    bool pop( T& result ) {
-        return internal_pop(&result);
+    void pop( T& result ) {
+        internal_pop(&result);
     }
 
+    /** Does not wait for item to become available.
+        Returns true if successful; false otherwise. */
     bool try_pop( T& result ) {
         return internal_pop_if_present(&result);
     }
@@ -410,10 +407,7 @@ public:
 
     // Clear the queue. not thread-safe.
     void clear() {
-        while (!empty()) {
-            T value;
-            try_pop(value);
-        }
+        my_queue_representation->clear(my_allocator);
     }
 
     // Return allocator object
@@ -482,7 +476,7 @@ private:
         return true;
     }
 
-    bool internal_pop( void* dst ) {
+    void internal_pop( void* dst ) {
         std::ptrdiff_t target;
         // This loop is a single pop operation; abort_counter should not be re-read inside
         unsigned old_abort_counter = my_abort_counter.load(std::memory_order_relaxed);
@@ -508,7 +502,6 @@ private:
         } while (!my_queue_representation->choose(target).pop(dst, target, *my_queue_representation, my_allocator));
 
         r1::notify_bounded_queue_monitor(my_monitors, cbq_slots_avail_tag, target);
-        return true;
     }
 
     bool internal_pop_if_present( void* dst ) {

+ 30 - 34
contrib/libs/tbb/include/oneapi/tbb/detail/_concurrent_queue_base.h

@@ -173,7 +173,7 @@ public:
         tail_counter.fetch_add(queue_rep_type::n_queue);
     }
 
-    bool pop( void* dst, ticket_type k, queue_rep_type& base, queue_allocator_type& allocator) {
+    bool pop( void* dst, ticket_type k, queue_rep_type& base, queue_allocator_type& allocator ) {
         k &= -queue_rep_type::n_queue;
         spin_wait_until_eq(head_counter, k);
         d1::call_itt_notify(d1::acquired, &head_counter);
@@ -189,7 +189,7 @@ public:
                 k + queue_rep_type::n_queue, index == items_per_page - 1 ? p : nullptr );
             if (p->mask.load(std::memory_order_relaxed) & (std::uintptr_t(1) << index)) {
                 success = true;
-                assign_and_destroy_item( dst, *p, index );
+                assign_and_destroy_item(dst, *p, index);
             } else {
                 --base.n_invalid_entries;
             }
@@ -276,36 +276,38 @@ public:
         }
     }
 
-    padded_page* get_tail_page() {
-        return tail_page.load(std::memory_order_relaxed);
-    }
-
     padded_page* get_head_page() {
         return head_page.load(std::memory_order_relaxed);
     }
 
-    void set_tail_page( padded_page* pg ) {
-        tail_page.store(pg, std::memory_order_relaxed);
-    }
-
-    void clear(queue_allocator_type& allocator ) {
-        padded_page* curr_page = head_page.load(std::memory_order_relaxed);
-        std::size_t index = head_counter.load(std::memory_order_relaxed);
+    void clear(queue_allocator_type& allocator, padded_page* new_head = nullptr, padded_page* new_tail = nullptr) {
+        padded_page* curr_page = get_head_page();
+        size_type index = (head_counter.load(std::memory_order_relaxed) / queue_rep_type::n_queue) % items_per_page;
         page_allocator_type page_allocator(allocator);
 
-        while (curr_page) {
-            for (; index != items_per_page - 1; ++index) {
-                curr_page->operator[](index).~value_type();
+        while (curr_page && is_valid_page(curr_page)) {
+            while (index != items_per_page) {
+                if (curr_page->mask.load(std::memory_order_relaxed) & (std::uintptr_t(1) << index)) {
+                    page_allocator_traits::destroy(page_allocator, &curr_page->operator[](index));
+                }
+                ++index;
             }
-                padded_page* next_page = curr_page->next;
-                page_allocator_traits::destroy(page_allocator, curr_page);
-                page_allocator_traits::deallocate(page_allocator, curr_page, 1);
-                curr_page = next_page;
+
+            index = 0;
+            padded_page* next_page = curr_page->next;
+            page_allocator_traits::destroy(page_allocator, curr_page);
+            page_allocator_traits::deallocate(page_allocator, curr_page, 1);
+            curr_page = next_page;
         }
+        head_counter.store(0, std::memory_order_relaxed);
+        tail_counter.store(0, std::memory_order_relaxed);
+        head_page.store(new_head, std::memory_order_relaxed);
+        tail_page.store(new_tail, std::memory_order_relaxed);
+    }
 
+    void clear_and_invalidate(queue_allocator_type& allocator) {
         padded_page* invalid_page = reinterpret_cast<padded_page*>(std::uintptr_t(1));
-        head_page.store(invalid_page, std::memory_order_relaxed);
-        tail_page.store(invalid_page, std::memory_order_relaxed);
+        clear(allocator, invalid_page, invalid_page);
     }
 
 private:
@@ -430,18 +432,12 @@ public:
     concurrent_queue_rep& operator=( const concurrent_queue_rep& ) = delete;
 
     void clear( queue_allocator_type& alloc ) {
-        page_allocator_type page_allocator(alloc);
-        for (size_type i = 0; i < n_queue; ++i) {
-            padded_page* tail_page = array[i].get_tail_page();
-            if( is_valid_page(tail_page) ) {
-                __TBB_ASSERT(array[i].get_head_page() == tail_page, "at most one page should remain" );
-                page_allocator_traits::destroy(page_allocator, static_cast<padded_page*>(tail_page));
-                page_allocator_traits::deallocate(page_allocator, static_cast<padded_page*>(tail_page), 1);
-                array[i].set_tail_page(nullptr);
-            } else {
-                __TBB_ASSERT(!is_valid_page(array[i].get_head_page()), "head page pointer corrupt?");
-            }
+        for (size_type index = 0; index < n_queue; ++index) {
+            array[index].clear(alloc);
         }
+        head_counter.store(0, std::memory_order_relaxed);
+        tail_counter.store(0, std::memory_order_relaxed);
+        n_invalid_entries.store(0, std::memory_order_relaxed);
     }
 
     void assign( const concurrent_queue_rep& src, queue_allocator_type& alloc, item_constructor_type construct_item ) {
@@ -457,7 +453,7 @@ public:
             }
         }).on_exception( [&] {
             for (size_type i = 0; i < queue_idx + 1; ++i) {
-                array[i].clear(alloc);
+                array[i].clear_and_invalidate(alloc);
             }
             head_counter.store(0, std::memory_order_relaxed);
             tail_counter.store(0, std::memory_order_relaxed);

+ 10 - 23
contrib/libs/tbb/include/oneapi/tbb/partitioner.h

@@ -311,27 +311,6 @@ struct adaptive_mode : partition_type_base<Partition> {
     }
 };
 
-//! Helper type for checking availability of proportional_split constructor
-template <typename T> using supports_proportional_splitting = typename std::is_constructible<T, T&, proportional_split&>;
-
-//! A helper class to create a proportional_split object for a given type of Range.
-/** If the Range has proportional_split constructor,
-    then created object splits a provided value in an implemenation-defined proportion;
-    otherwise it represents equal-size split. */
-// TODO: check if this helper can be a nested class of proportional_mode.
-template <typename Range, typename = void>
-struct proportion_helper {
-    static proportional_split get_split(std::size_t) { return proportional_split(1,1); }
-};
-
-template <typename Range>
-struct proportion_helper<Range, typename std::enable_if<supports_proportional_splitting<Range>::value>::type> {
-    static proportional_split get_split(std::size_t n) {
-        std::size_t right = n / 2;
-        std::size_t left  = n - right;
-        return proportional_split(left, right);
-    }
-};
 
 //! Provides proportional splitting strategy for partition objects
 template <typename Partition>
@@ -357,8 +336,16 @@ struct proportional_mode : adaptive_mode<Partition> {
     }
     template <typename Range>
     proportional_split get_split() {
-        // Create a proportion for the number of threads expected to handle "this" subrange
-        return proportion_helper<Range>::get_split( self().my_divisor / my_partition::factor );
+        // Create the proportion from partitioner internal resources (threads) that would be used:
+        // - into proportional_mode constructor to split the partitioner
+        // - if Range supports the proportional_split constructor it would use proposed proportion,
+        //   otherwise, the tbb::proportional_split object will be implicitly (for Range implementor)
+        //   casted to tbb::split
+
+        std::size_t n = self().my_divisor / my_partition::factor;
+        std::size_t right = n / 2;
+        std::size_t left  = n - right;
+        return proportional_split(left, right);
     }
 };
 

+ 10 - 4
contrib/libs/tbb/include/oneapi/tbb/version.h

@@ -17,13 +17,19 @@
 #ifndef __TBB_version_H
 #define __TBB_version_H
 
-#include "detail/_config.h"
-#include "detail/_namespace_injection.h"
+// Exclude all includes during .rc files compilation
+#ifndef RC_INVOKED
+    #include "detail/_config.h"
+    #include "detail/_namespace_injection.h"
+#else
+    #define __TBB_STRING_AUX(x) #x
+    #define __TBB_STRING(x) __TBB_STRING_AUX(x)
+#endif
 
 // Product version
 #define TBB_VERSION_MAJOR 2021
 // Update version
-#define TBB_VERSION_MINOR 7
+#define TBB_VERSION_MINOR 8
 // "Patch" version for custom releases
 #define TBB_VERSION_PATCH 0
 // Suffix string
@@ -34,7 +40,7 @@
 // OneAPI oneTBB specification version
 #define ONETBB_SPEC_VERSION "1.0"
 // Full interface version
-#define TBB_INTERFACE_VERSION 12070
+#define TBB_INTERFACE_VERSION 12080
 // Major interface version
 #define TBB_INTERFACE_VERSION_MAJOR (TBB_INTERFACE_VERSION/1000)
 // Minor interface version

+ 7 - 1
contrib/libs/tbb/src/tbb/tools_api/ittnotify_config.h

@@ -1,5 +1,5 @@
 /*
-    Copyright (c) 2005-2021 Intel Corporation
+    Copyright (c) 2005-2022 Intel Corporation
 
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -163,6 +163,10 @@
 #  define ITT_ARCH_ARM64  6
 #endif /* ITT_ARCH_ARM64 */
 
+#ifndef ITT_ARCH_LOONGARCH64
+#  define ITT_ARCH_LOONGARCH64  7
+#endif /* ITT_ARCH_LOONGARCH64 */
+
 #ifndef ITT_ARCH
 #  if defined _M_IX86 || defined __i386__
 #    define ITT_ARCH ITT_ARCH_IA32
@@ -176,6 +180,8 @@
 #    define ITT_ARCH ITT_ARCH_ARM64
 #  elif defined __powerpc64__
 #    define ITT_ARCH ITT_ARCH_PPC64
+#  elif defined __loongarch__
+#    define ITT_ARCH ITT_ARCH_LOONGARCH64
 #  endif
 #endif