Skip to content

Commit caa1897

Browse files
dkolsen-pgialliepiper
authored andcommitted
Create wrapper to use when including <algorithm> and <memory>
Accommodate compilers that use Thrust in their implementations of C++ Standard algorithms. To avoid cycles of include files, the compiler needs to know when an include of an algorithms-related header (<algorithm>, <numeric>, or <memory>) is coming from Thrust vs from user code. Create wrapper files to use when including <algorithm> or <memory> that defines a macro that the compiler can check to know where the include is coming from. Change all includes of those files within Thrust code to include the wrapper file instead. (The same change would also be made for <numeric> if Thrust files included <numeric> anywhere.) Fix NVIDIA#1218
1 parent 2a6744c commit caa1897

File tree

13 files changed

+68
-11
lines changed

13 files changed

+68
-11
lines changed

thrust/addressof.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <thrust/detail/config.h>
99

1010
#if THRUST_CPP_DIALECT >= 2011
11-
# include <memory>
11+
# include <thrust/detail/memory_wrapper.h>
1212
#endif
1313

1414
namespace thrust

thrust/detail/algorithm_wrapper.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2020 NVIDIA Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
// When a compiler uses Thrust as part of its implementation of Standard C++
20+
// algorithms, a cycle of included files may result when Thrust code tries to
21+
// use a standard algorithm. Having a macro that is defined only when Thrust
22+
// is including an algorithms-related header gives the compiler a chance to
23+
// detect and break the cycle of includes.
24+
25+
#define THRUST_INCLUDING_ALGORITHMS_HEADER
26+
#include <algorithm>
27+
#undef THRUST_INCLUDING_ALGORITHMS_HEADER

thrust/detail/allocator/copy_construct_range.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <thrust/distance.h>
2525
#include <thrust/iterator/zip_iterator.h>
2626
#include <thrust/for_each.h>
27-
#include <memory>
27+
#include <thrust/detail/memory_wrapper.h>
2828

2929
namespace thrust
3030
{

thrust/detail/allocator/destroy_range.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <thrust/detail/allocator/allocator_traits.h>
1919
#include <thrust/detail/type_traits/pointer_traits.h>
2020
#include <thrust/for_each.h>
21-
#include <memory>
21+
#include <thrust/detail/memory_wrapper.h>
2222

2323
namespace thrust
2424
{

thrust/detail/allocator/fill_construct_range.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <thrust/detail/type_traits/pointer_traits.h>
2121
#include <thrust/for_each.h>
2222
#include <thrust/uninitialized_fill.h>
23-
#include <memory>
23+
#include <thrust/detail/memory_wrapper.h>
2424

2525
namespace thrust
2626
{

thrust/detail/internal_functional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <thrust/detail/type_traits.h>
2828
#include <thrust/iterator/detail/tuple_of_iterator_references.h>
2929
#include <thrust/detail/raw_reference_cast.h>
30-
#include <memory> // for ::new
30+
#include <thrust/detail/memory_wrapper.h> // for ::new
3131

3232
namespace thrust
3333
{

thrust/detail/memory_algorithms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <utility>
1818
#include <new>
19-
#include <memory>
19+
#include <thrust/detail/memory_wrapper.h>
2020

2121
namespace thrust
2222
{

thrust/detail/memory_wrapper.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2020 NVIDIA Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
// When a compiler uses Thrust as part of its implementation of Standard C++
20+
// algorithms, a cycle of included files may result when Thrust code tries to
21+
// use a standard algorithm. Having a macro that is defined only when Thrust
22+
// is including an algorithms-related header gives the compiler a chance to
23+
// detect and break the cycle of includes. (<memory> declares several standard
24+
// algorithms, including all of the uninitialized_* algorithms. "_ALGORITHMS_"
25+
// in the macro name is meant generically, not as a specific reference to
26+
// the header <algorithms>.)
27+
28+
#define THRUST_INCLUDING_ALGORITHMS_HEADER
29+
#include <memory>
30+
#undef THRUST_INCLUDING_ALGORITHMS_HEADER

thrust/detail/temporary_array.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ template<typename T, typename System>
3939
#include <thrust/detail/contiguous_storage.h>
4040
#include <thrust/detail/allocator/temporary_allocator.h>
4141
#include <thrust/detail/allocator/no_throw_allocator.h>
42-
#include <memory>
42+
#include <thrust/detail/memory_wrapper.h>
4343

4444
namespace thrust
4545
{

thrust/host_vector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#pragma once
2323

2424
#include <thrust/detail/config.h>
25-
#include <memory>
25+
#include <thrust/detail/memory_wrapper.h>
2626
#include <thrust/detail/vector_base.h>
2727
#include <vector>
2828
#include <utility>

0 commit comments

Comments
 (0)