Skip to content

Commit bd619c5

Browse files
committed
Commit oneTBB source code 6bfd29b
1 parent 7673da2 commit bd619c5

22 files changed

+843
-118
lines changed

README.md

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

cmake/compilers/AppleClang.cmake

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020-2021 Intel Corporation
1+
# Copyright (c) 2020-2022 Intel Corporation
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -32,9 +32,15 @@ if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag)
3232
endif()
3333

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

3945
# TBB malloc settings
4046
set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions)

include/oneapi/tbb/concurrent_queue.h

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2021 Intel Corporation
2+
Copyright (c) 2005-2022 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -148,10 +148,7 @@ class concurrent_queue {
148148

149149
// Clear the queue. not thread-safe.
150150
void clear() {
151-
while (!empty()) {
152-
T value;
153-
try_pop(value);
154-
}
151+
my_queue_representation->clear(my_allocator);
155152
}
156153

157154
// Return allocator object
@@ -375,12 +372,12 @@ class concurrent_bounded_queue {
375372
}
376373

377374
// Attempt to dequeue an item from head of queue.
378-
/** Does not wait for item to become available.
379-
Returns true if successful; false otherwise. */
380-
bool pop( T& result ) {
381-
return internal_pop(&result);
375+
void pop( T& result ) {
376+
internal_pop(&result);
382377
}
383378

379+
/** Does not wait for item to become available.
380+
Returns true if successful; false otherwise. */
384381
bool try_pop( T& result ) {
385382
return internal_pop_if_present(&result);
386383
}
@@ -410,10 +407,7 @@ class concurrent_bounded_queue {
410407

411408
// Clear the queue. not thread-safe.
412409
void clear() {
413-
while (!empty()) {
414-
T value;
415-
try_pop(value);
416-
}
410+
my_queue_representation->clear(my_allocator);
417411
}
418412

419413
// Return allocator object
@@ -482,7 +476,7 @@ class concurrent_bounded_queue {
482476
return true;
483477
}
484478

485-
bool internal_pop( void* dst ) {
479+
void internal_pop( void* dst ) {
486480
std::ptrdiff_t target;
487481
// This loop is a single pop operation; abort_counter should not be re-read inside
488482
unsigned old_abort_counter = my_abort_counter.load(std::memory_order_relaxed);
@@ -508,7 +502,6 @@ class concurrent_bounded_queue {
508502
} while (!my_queue_representation->choose(target).pop(dst, target, *my_queue_representation, my_allocator));
509503

510504
r1::notify_bounded_queue_monitor(my_monitors, cbq_slots_avail_tag, target);
511-
return true;
512505
}
513506

514507
bool internal_pop_if_present( void* dst ) {

include/oneapi/tbb/concurrent_unordered_map.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2021 Intel Corporation
2+
Copyright (c) 2005-2022 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -223,6 +223,16 @@ concurrent_unordered_map( std::initializer_list<std::pair<Key, T>>, std::size_t,
223223
-> concurrent_unordered_map<std::remove_const_t<Key>, T, Hash,
224224
std::equal_to<std::remove_const_t<Key>>, Alloc>;
225225

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

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

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

377396
template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>

include/oneapi/tbb/concurrent_unordered_set.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2021 Intel Corporation
2+
Copyright (c) 2005-2022 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -163,6 +163,15 @@ template <typename T, typename Hash, typename Alloc,
163163
concurrent_unordered_set( std::initializer_list<T>, std::size_t, Hash, Alloc )
164164
-> concurrent_unordered_set<T, Hash, std::equal_to<T>, Alloc>;
165165

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

168177
template <typename Key, typename Hash, typename KeyEqual, typename Allocator>
@@ -292,6 +301,15 @@ template <typename T, typename Hash, typename Alloc,
292301
concurrent_unordered_multiset( std::initializer_list<T>, std::size_t, Hash, Alloc )
293302
-> concurrent_unordered_multiset<T, Hash, std::equal_to<T>, Alloc>;
294303

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

297315
template <typename Key, typename Hash, typename KeyEqual, typename Allocator>

include/oneapi/tbb/detail/_concurrent_queue_base.h

+30-34
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class micro_queue {
173173
tail_counter.fetch_add(queue_rep_type::n_queue);
174174
}
175175

176-
bool pop( void* dst, ticket_type k, queue_rep_type& base, queue_allocator_type& allocator) {
176+
bool pop( void* dst, ticket_type k, queue_rep_type& base, queue_allocator_type& allocator ) {
177177
k &= -queue_rep_type::n_queue;
178178
spin_wait_until_eq(head_counter, k);
179179
d1::call_itt_notify(d1::acquired, &head_counter);
@@ -189,7 +189,7 @@ class micro_queue {
189189
k + queue_rep_type::n_queue, index == items_per_page - 1 ? p : nullptr );
190190
if (p->mask.load(std::memory_order_relaxed) & (std::uintptr_t(1) << index)) {
191191
success = true;
192-
assign_and_destroy_item( dst, *p, index );
192+
assign_and_destroy_item(dst, *p, index);
193193
} else {
194194
--base.n_invalid_entries;
195195
}
@@ -276,36 +276,38 @@ class micro_queue {
276276
}
277277
}
278278

279-
padded_page* get_tail_page() {
280-
return tail_page.load(std::memory_order_relaxed);
281-
}
282-
283279
padded_page* get_head_page() {
284280
return head_page.load(std::memory_order_relaxed);
285281
}
286282

287-
void set_tail_page( padded_page* pg ) {
288-
tail_page.store(pg, std::memory_order_relaxed);
289-
}
290-
291-
void clear(queue_allocator_type& allocator ) {
292-
padded_page* curr_page = head_page.load(std::memory_order_relaxed);
293-
std::size_t index = head_counter.load(std::memory_order_relaxed);
283+
void clear(queue_allocator_type& allocator, padded_page* new_head = nullptr, padded_page* new_tail = nullptr) {
284+
padded_page* curr_page = get_head_page();
285+
size_type index = (head_counter.load(std::memory_order_relaxed) / queue_rep_type::n_queue) % items_per_page;
294286
page_allocator_type page_allocator(allocator);
295287

296-
while (curr_page) {
297-
for (; index != items_per_page - 1; ++index) {
298-
curr_page->operator[](index).~value_type();
288+
while (curr_page && is_valid_page(curr_page)) {
289+
while (index != items_per_page) {
290+
if (curr_page->mask.load(std::memory_order_relaxed) & (std::uintptr_t(1) << index)) {
291+
page_allocator_traits::destroy(page_allocator, &curr_page->operator[](index));
292+
}
293+
++index;
299294
}
300-
padded_page* next_page = curr_page->next;
301-
page_allocator_traits::destroy(page_allocator, curr_page);
302-
page_allocator_traits::deallocate(page_allocator, curr_page, 1);
303-
curr_page = next_page;
295+
296+
index = 0;
297+
padded_page* next_page = curr_page->next;
298+
page_allocator_traits::destroy(page_allocator, curr_page);
299+
page_allocator_traits::deallocate(page_allocator, curr_page, 1);
300+
curr_page = next_page;
304301
}
302+
head_counter.store(0, std::memory_order_relaxed);
303+
tail_counter.store(0, std::memory_order_relaxed);
304+
head_page.store(new_head, std::memory_order_relaxed);
305+
tail_page.store(new_tail, std::memory_order_relaxed);
306+
}
305307

308+
void clear_and_invalidate(queue_allocator_type& allocator) {
306309
padded_page* invalid_page = reinterpret_cast<padded_page*>(std::uintptr_t(1));
307-
head_page.store(invalid_page, std::memory_order_relaxed);
308-
tail_page.store(invalid_page, std::memory_order_relaxed);
310+
clear(allocator, invalid_page, invalid_page);
309311
}
310312

311313
private:
@@ -430,18 +432,12 @@ struct concurrent_queue_rep {
430432
concurrent_queue_rep& operator=( const concurrent_queue_rep& ) = delete;
431433

432434
void clear( queue_allocator_type& alloc ) {
433-
page_allocator_type page_allocator(alloc);
434-
for (size_type i = 0; i < n_queue; ++i) {
435-
padded_page* tail_page = array[i].get_tail_page();
436-
if( is_valid_page(tail_page) ) {
437-
__TBB_ASSERT(array[i].get_head_page() == tail_page, "at most one page should remain" );
438-
page_allocator_traits::destroy(page_allocator, static_cast<padded_page*>(tail_page));
439-
page_allocator_traits::deallocate(page_allocator, static_cast<padded_page*>(tail_page), 1);
440-
array[i].set_tail_page(nullptr);
441-
} else {
442-
__TBB_ASSERT(!is_valid_page(array[i].get_head_page()), "head page pointer corrupt?");
443-
}
435+
for (size_type index = 0; index < n_queue; ++index) {
436+
array[index].clear(alloc);
444437
}
438+
head_counter.store(0, std::memory_order_relaxed);
439+
tail_counter.store(0, std::memory_order_relaxed);
440+
n_invalid_entries.store(0, std::memory_order_relaxed);
445441
}
446442

447443
void assign( const concurrent_queue_rep& src, queue_allocator_type& alloc, item_constructor_type construct_item ) {
@@ -457,7 +453,7 @@ struct concurrent_queue_rep {
457453
}
458454
}).on_exception( [&] {
459455
for (size_type i = 0; i < queue_idx + 1; ++i) {
460-
array[i].clear(alloc);
456+
array[i].clear_and_invalidate(alloc);
461457
}
462458
head_counter.store(0, std::memory_order_relaxed);
463459
tail_counter.store(0, std::memory_order_relaxed);

include/oneapi/tbb/partitioner.h

+10-23
Original file line numberDiff line numberDiff line change
@@ -311,27 +311,6 @@ struct adaptive_mode : partition_type_base<Partition> {
311311
}
312312
};
313313

314-
//! Helper type for checking availability of proportional_split constructor
315-
template <typename T> using supports_proportional_splitting = typename std::is_constructible<T, T&, proportional_split&>;
316-
317-
//! A helper class to create a proportional_split object for a given type of Range.
318-
/** If the Range has proportional_split constructor,
319-
then created object splits a provided value in an implemenation-defined proportion;
320-
otherwise it represents equal-size split. */
321-
// TODO: check if this helper can be a nested class of proportional_mode.
322-
template <typename Range, typename = void>
323-
struct proportion_helper {
324-
static proportional_split get_split(std::size_t) { return proportional_split(1,1); }
325-
};
326-
327-
template <typename Range>
328-
struct proportion_helper<Range, typename std::enable_if<supports_proportional_splitting<Range>::value>::type> {
329-
static proportional_split get_split(std::size_t n) {
330-
std::size_t right = n / 2;
331-
std::size_t left = n - right;
332-
return proportional_split(left, right);
333-
}
334-
};
335314

336315
//! Provides proportional splitting strategy for partition objects
337316
template <typename Partition>
@@ -357,8 +336,16 @@ struct proportional_mode : adaptive_mode<Partition> {
357336
}
358337
template <typename Range>
359338
proportional_split get_split() {
360-
// Create a proportion for the number of threads expected to handle "this" subrange
361-
return proportion_helper<Range>::get_split( self().my_divisor / my_partition::factor );
339+
// Create the proportion from partitioner internal resources (threads) that would be used:
340+
// - into proportional_mode constructor to split the partitioner
341+
// - if Range supports the proportional_split constructor it would use proposed proportion,
342+
// otherwise, the tbb::proportional_split object will be implicitly (for Range implementor)
343+
// casted to tbb::split
344+
345+
std::size_t n = self().my_divisor / my_partition::factor;
346+
std::size_t right = n / 2;
347+
std::size_t left = n - right;
348+
return proportional_split(left, right);
362349
}
363350
};
364351

include/oneapi/tbb/version.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717
#ifndef __TBB_version_H
1818
#define __TBB_version_H
1919

20-
#include "detail/_config.h"
21-
#include "detail/_namespace_injection.h"
20+
// Exclude all includes during .rc files compilation
21+
#ifndef RC_INVOKED
22+
#include "detail/_config.h"
23+
#include "detail/_namespace_injection.h"
24+
#else
25+
#define __TBB_STRING_AUX(x) #x
26+
#define __TBB_STRING(x) __TBB_STRING_AUX(x)
27+
#endif
2228

2329
// Product version
2430
#define TBB_VERSION_MAJOR 2021
2531
// Update version
26-
#define TBB_VERSION_MINOR 7
32+
#define TBB_VERSION_MINOR 8
2733
// "Patch" version for custom releases
2834
#define TBB_VERSION_PATCH 0
2935
// Suffix string
@@ -34,7 +40,7 @@
3440
// OneAPI oneTBB specification version
3541
#define ONETBB_SPEC_VERSION "1.0"
3642
// Full interface version
37-
#define TBB_INTERFACE_VERSION 12070
43+
#define TBB_INTERFACE_VERSION 12080
3844
// Major interface version
3945
#define TBB_INTERFACE_VERSION_MAJOR (TBB_INTERFACE_VERSION/1000)
4046
// Minor interface version

0 commit comments

Comments
 (0)