2
* Copyright 2008-2011 NVIDIA Corporation
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#include <thrust/detail/config.h>
19
#if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC
21
#include <thrust/iterator/iterator_traits.h>
22
#include <thrust/pair.h>
23
#include <thrust/detail/backend/cuda/block/set_intersection.h>
24
#include <thrust/detail/backend/cuda/detail/split_for_set_operation.h>
25
#include <thrust/detail/backend/cuda/detail/set_operation.h>
36
namespace set_intersection_detail
39
struct block_convergent_set_intersection_functor
41
__host__ __device__ __forceinline__
42
static size_t get_min_size_of_result_in_number_of_elements(size_t size_of_range1,
43
size_t size_of_range2)
45
// set_intersection could result in zero output
49
__host__ __device__ __forceinline__
50
static size_t get_max_size_of_result_in_number_of_elements(size_t size_of_range1,
51
size_t size_of_range2)
53
// set_intersection could output all of range1
54
return size_of_range1;
57
__host__ __device__ __forceinline__
58
static unsigned int get_temporary_array_size_in_number_of_bytes(unsigned int block_size)
60
return block_size * sizeof(int);
63
// operator() simply calls the block-wise function
64
template<typename RandomAccessIterator1,
65
typename RandomAccessIterator2,
66
typename RandomAccessIterator3,
67
typename StrictWeakOrdering>
68
__device__ __forceinline__
69
RandomAccessIterator3 operator()(RandomAccessIterator1 first1,
70
RandomAccessIterator1 last1,
71
RandomAccessIterator2 first2,
72
RandomAccessIterator2 last2,
74
RandomAccessIterator3 result,
75
StrictWeakOrdering comp)
77
return block::set_intersection(first1,last1,first2,last2,reinterpret_cast<int*>(temporary),result,comp);
79
}; // end block_convergent_set_intersection_functor
81
} // end namespace set_intersection_detail
84
template<typename RandomAccessIterator1,
85
typename RandomAccessIterator2,
86
typename RandomAccessIterator3,
88
RandomAccessIterator3 set_intersection(RandomAccessIterator1 first1,
89
RandomAccessIterator1 last1,
90
RandomAccessIterator2 first2,
91
RandomAccessIterator2 last2,
92
RandomAccessIterator3 result,
95
typedef typename thrust::iterator_difference<RandomAccessIterator1>::type difference1;
96
typedef typename thrust::iterator_difference<RandomAccessIterator2>::type difference2;
98
const difference1 num_elements1 = last1 - first1;
99
const difference2 num_elements2 = last2 - first2;
101
// check for trivial problem
102
if(num_elements1 == 0 || num_elements2 == 0)
105
return detail::set_operation(first1, last1,
109
detail::split_for_set_operation(),
110
set_intersection_detail::block_convergent_set_intersection_functor());
111
} // end set_intersection
113
} // end namespace cuda
114
} // end namespace backend
115
} // end namespace detail
116
} // end namespace thrust
118
#endif // THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC