Skip to content

Commit

Permalink
Commit oneTBB source code 6bfd29b
Browse files Browse the repository at this point in the history
  • Loading branch information
tbbdev committed Oct 28, 2022
1 parent 7673da2 commit bd619c5
Show file tree
Hide file tree
Showing 22 changed files with 843 additions and 118 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 8 additions & 2 deletions cmake/compilers/AppleClang.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2021 Intel Corporation
# Copyright (c) 2020-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.
Expand Down Expand Up @@ -32,9 +32,15 @@ if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag)
endif()

# Enable Intel(R) Transactional Synchronization Extensions (-mrtm) and WAITPKG instructions support (-mwaitpkg) on relevant processors
if (NOT "${CMAKE_OSX_ARCHITECTURES}" MATCHES "^arm64$" AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64|AMD64)") # OSX systems are 64-bit only
if (CMAKE_OSX_ARCHITECTURES)
set(_tbb_target_architectures "${CMAKE_OSX_ARCHITECTURES}")
else()
set(_tbb_target_architectures "${CMAKE_SYSTEM_PROCESSOR}")
endif()
if ("${_tbb_target_architectures}" MATCHES "(x86_64|amd64|AMD64)") # OSX systems are 64-bit only
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},12.0>>:-mwaitpkg>)
endif()
unset(_tbb_target_architectures)

# TBB malloc settings
set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions)
Expand Down
23 changes: 8 additions & 15 deletions include/oneapi/tbb/concurrent_queue.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -148,10 +148,7 @@ class concurrent_queue {

// Clear the queue. not thread-safe.
void clear() {
while (!empty()) {
T value;
try_pop(value);
}
my_queue_representation->clear(my_allocator);
}

// Return allocator object
Expand Down Expand Up @@ -375,12 +372,12 @@ class concurrent_bounded_queue {
}

// 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);
}
Expand Down Expand Up @@ -410,10 +407,7 @@ class concurrent_bounded_queue {

// Clear the queue. not thread-safe.
void clear() {
while (!empty()) {
T value;
try_pop(value);
}
my_queue_representation->clear(my_allocator);
}

// Return allocator object
Expand Down Expand Up @@ -482,7 +476,7 @@ class concurrent_bounded_queue {
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);
Expand All @@ -508,7 +502,6 @@ class concurrent_bounded_queue {
} 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 ) {
Expand Down
21 changes: 20 additions & 1 deletion include/oneapi/tbb/concurrent_unordered_map.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -223,6 +223,16 @@ concurrent_unordered_map( std::initializer_list<std::pair<Key, T>>, std::size_t,
-> concurrent_unordered_map<std::remove_const_t<Key>, T, Hash,
std::equal_to<std::remove_const_t<Key>>, Alloc>;

#if __APPLE__ && __TBB_CLANG_VERSION == 100000
// An explicit deduction guide is required for copy/move constructor with allocator for APPLE LLVM 10.0.0
// due to an issue with generating an implicit deduction guide for these constructors under several strange surcumstances.
// Currently the issue takes place because the last template parameter for Traits is boolean, it should not affect the deduction guides
// The issue reproduces only on this version of the compiler
template <typename Key, typename T, typename Hash, typename KeyEq, typename Alloc>
concurrent_unordered_map( concurrent_unordered_map<Key, T, Hash, KeyEq, Alloc>, Alloc )
-> concurrent_unordered_map<Key, T, Hash, KeyEq, Alloc>;
#endif

#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT

template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
Expand Down Expand Up @@ -372,6 +382,15 @@ concurrent_unordered_multimap( std::initializer_list<std::pair<Key, T>>, std::si
-> concurrent_unordered_multimap<std::remove_const_t<Key>, T, Hash,
std::equal_to<std::remove_const_t<Key>>, Alloc>;

#if __APPLE__ && __TBB_CLANG_VERSION == 100000
// An explicit deduction guide is required for copy/move constructor with allocator for APPLE LLVM 10.0.0
// due to an issue with generating an implicit deduction guide for these constructors under several strange surcumstances.
// Currently the issue takes place because the last template parameter for Traits is boolean, it should not affect the deduction guides
// The issue reproduces only on this version of the compiler
template <typename Key, typename T, typename Hash, typename KeyEq, typename Alloc>
concurrent_unordered_multimap( concurrent_unordered_multimap<Key, T, Hash, KeyEq, Alloc>, Alloc )
-> concurrent_unordered_multimap<Key, T, Hash, KeyEq, Alloc>;
#endif
#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT

template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
Expand Down
20 changes: 19 additions & 1 deletion include/oneapi/tbb/concurrent_unordered_set.h
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -163,6 +163,15 @@ template <typename T, typename Hash, typename Alloc,
concurrent_unordered_set( std::initializer_list<T>, std::size_t, Hash, Alloc )
-> concurrent_unordered_set<T, Hash, std::equal_to<T>, Alloc>;

#if __APPLE__ && __TBB_CLANG_VERSION == 100000
// An explicit deduction guide is required for copy/move constructor with allocator for APPLE LLVM 10.0.0
// due to an issue with generating an implicit deduction guide for these constructors under several strange surcumstances.
// Currently the issue takes place because the last template parameter for Traits is boolean, it should not affect the deduction guides
// The issue reproduces only on this version of the compiler
template <typename T, typename Hash, typename KeyEq, typename Alloc>
concurrent_unordered_set( concurrent_unordered_set<T, Hash, KeyEq, Alloc>, Alloc )
-> concurrent_unordered_set<T, Hash, KeyEq, Alloc>;
#endif
#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT

template <typename Key, typename Hash, typename KeyEqual, typename Allocator>
Expand Down Expand Up @@ -292,6 +301,15 @@ template <typename T, typename Hash, typename Alloc,
concurrent_unordered_multiset( std::initializer_list<T>, std::size_t, Hash, Alloc )
-> concurrent_unordered_multiset<T, Hash, std::equal_to<T>, Alloc>;

#if __APPLE__ && __TBB_CLANG_VERSION == 100000
// An explicit deduction guide is required for copy/move constructor with allocator for APPLE LLVM 10.0.0
// due to an issue with generating an implicit deduction guide for these constructors under several strange surcumstances.
// Currently the issue takes place because the last template parameter for Traits is boolean, it should not affect the deduction guides
// The issue reproduces only on this version of the compiler
template <typename T, typename Hash, typename KeyEq, typename Alloc>
concurrent_unordered_multiset( concurrent_unordered_multiset<T, Hash, KeyEq, Alloc>, Alloc )
-> concurrent_unordered_multiset<T, Hash, KeyEq, Alloc>;
#endif
#endif // __TBB_CPP17_DEDUCTION_GUIDES_PRESENT

template <typename Key, typename Hash, typename KeyEqual, typename Allocator>
Expand Down
64 changes: 30 additions & 34 deletions include/oneapi/tbb/detail/_concurrent_queue_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class micro_queue {
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);
Expand All @@ -189,7 +189,7 @@ class micro_queue {
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;
}
Expand Down Expand Up @@ -276,36 +276,38 @@ class micro_queue {
}
}

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:
Expand Down Expand Up @@ -430,18 +432,12 @@ struct concurrent_queue_rep {
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 ) {
Expand All @@ -457,7 +453,7 @@ struct concurrent_queue_rep {
}
}).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);
Expand Down
33 changes: 10 additions & 23 deletions include/oneapi/tbb/partitioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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);
}
};

Expand Down
14 changes: 10 additions & 4 deletions include/oneapi/tbb/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit bd619c5

Please sign in to comment.