Extended CUDA Library (ecuda)  2.0
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
algorithm.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015, Scott Zuyderduyn
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 The views and conclusions contained in the software and documentation are those
26 of the authors and should not be interpreted as representing official policies,
27 either expressed or implied, of the FreeBSD Project.
28 */
29 
30 //----------------------------------------------------------------------------
31 // algorithm.hpp
32 //
33 // CUDA implementations from STL header <algorithm>.
34 //
35 // Author: Scott D. Zuyderduyn, Ph.D. (scott.zuyderduyn@utoronto.ca)
36 //----------------------------------------------------------------------------
37 
38 #ifndef ECUDA_ALGORITHM_HPP
39 #define ECUDA_ALGORITHM_HPP
40 
41 #include <iterator>
42 #include <vector>
43 
44 #include "global.hpp"
45 
46 namespace ecuda {
47 
48 template<typename T> __HOST__ __DEVICE__ inline const T& min( const T& a, const T& b ) { return b < a ? b : a; }
49 template<typename T,class Compare> __HOST__ __DEVICE__ inline const T& min( const T& a, const T& b, Compare cmp ) { return cmp(b,a) ? b : a; }
50 
51 template<typename T> __HOST__ __DEVICE__ inline const T& max( const T& a, const T& b ) { return b > a ? b : a; }
52 template<typename T,class Compare> __HOST__ __DEVICE__ inline const T& max( const T& a, const T& b, Compare cmp ) { return cmp(a,b) ? b : a; }
53 
54 template<typename T> __HOST__ __DEVICE__ inline void swap( T& a, T& b ) __NOEXCEPT__ { T tmp = a; a = b; b = tmp; } // equivalent to std::swap
55 
56 } // namespace ecuda
57 
58 #include "iterator.hpp"
59 #include "type_traits.hpp"
60 
61 #include "algo/copy.hpp" // equivalent to std::copy
62 #include "algo/equal.hpp" // equivalent to std::equal
63 #include "algo/fill.hpp" // equivalent to std::fill
64 #include "algo/lexicographical_compare.hpp" // equivalent to std::lexicographical_compare
65 #include "algo/max_element.hpp" // equivalent to std::max_element
66 #include "algo/find.hpp" // equivalent to std::find
67 #include "algo/find_if.hpp" // equivalent to std::find_if
68 #include "algo/find_if_not.hpp" // equivalent to std::find_if_not (NOTE: C++11 only)
69 #include "algo/for_each.hpp" // equivalent to std::for_each
70 #include "algo/count.hpp" // equivalent to std::count
71 #include "algo/count_if.hpp" // equivalent to std::count_if
72 #include "algo/mismatch.hpp" // equivalent to std::mismatch
73 #include "algo/reverse.hpp" // equivalent to std::reverse
74 
75 namespace ecuda {
76 
78 template<class InputIterator,class UnaryPredicate>
79 inline __HOST__ __DEVICE__
80 bool any_of( InputIterator first, InputIterator last, UnaryPredicate p )
81 {
82  return ecuda::find_if( first, last, p ) != last;
83 }
84 
86 template<class InputIterator,class UnaryPredicate>
87 inline __HOST__ __DEVICE__
88 bool none_of( InputIterator first, InputIterator last, UnaryPredicate p )
89 {
90  return ecuda::find_if( first, last, p ) == last;
91 }
92 
93 } // namespace ecuda
94 
95 #endif
ECUDA_SUPPRESS_HD_WARNINGS __HOST__ __DEVICE__ bool none_of(InputIterator first, InputIterator last, UnaryPredicate p)
Definition: algorithm.hpp:88
ECUDA_SUPPRESS_HD_WARNINGS __HOST__ __DEVICE__ bool any_of(InputIterator first, InputIterator last, UnaryPredicate p)
Definition: algorithm.hpp:80
ECUDA_SUPPRESS_HD_WARNINGS __HOST__ __DEVICE__ InputIterator find_if(InputIterator first, InputIterator last, UnaryPredicate p)
Definition: find_if.hpp:94
#define __NOEXCEPT__
Definition: global.hpp:140
#define __HOST__
Definition: global.hpp:150
__HOST__ __DEVICE__ void swap(T &a, T &b) __NOEXCEPT__
Definition: algorithm.hpp:54
__HOST__ __DEVICE__ const T & min(const T &a, const T &b)
Definition: algorithm.hpp:48
__HOST__ __DEVICE__ const T & max(const T &a, const T &b)
Definition: algorithm.hpp:51
#define __DEVICE__
Definition: global.hpp:151
#define ECUDA_SUPPRESS_HD_WARNINGS
Definition: global.hpp:58