Cutlass CUDA Templates for Linear Algebra Subroutines and Solvers

pair.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright notice, this list of
7 * conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright notice, this list of
9 * conditions and the following disclaimer in the documentation and/or other materials
10 * provided with the distribution.
11 * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12 * to endorse or promote products derived from this software without specific prior written
13 * permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 **************************************************************************************************/
25
30 #pragma once
31
32 namespace cutlass {
33 namespace platform {
34
36
38 template <typename T1, typename T2>
39 struct Pair {
40
41 typedef T1 first_type;
42 typedef T2 second_type;
43
44 //
45 // Data members
46 //
47
48 T1 first;
49 T1 second;
50
51 //
52 // Methods
53 //
54
56 CUTLASS_HOST_DEVICE
57 Pair() { }
58
60 CUTLASS_HOST_DEVICE
61 Pair(T1 const &first_, T2 const &second_): first(first_), second(second_) { }
62 };
63
65 template <typename T1, typename T2>
66 Pair<T1, T2> make_Pair(T1 const &first, T2 const &second) {
67 return Pair<T1, T2>(first, second);
68 }
69
71 template <typename T1, typename T2>
72 CUTLASS_HOST_DEVICE
73 bool operator==(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
74 return (lhs.first == rhs.first) && (lhs.second == rhs.second);
75 }
76
78 template <typename T1, typename T2>
79 CUTLASS_HOST_DEVICE
80 bool operator!=(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
81 return !(lhs == rhs);
82 }
83
85 template <typename T1, typename T2>
86 CUTLASS_HOST_DEVICE
87 bool operator<(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
88 if (lhs.first < rhs.first) {
89 return true;
90 }
91 else if (rhs.first < lhs.first) {
92 return false;
93 }
94 else if (rhs.second < rhs.second) {
95 return false;
96 }
97 return false;
98 }
99
101 template <typename T1, typename T2>
102 CUTLASS_HOST_DEVICE
103 bool operator<=(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
104 return !(rhs < lhs);
105 }
106
108 template <typename T1, typename T2>
109 CUTLASS_HOST_DEVICE
110 bool operator>(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
111 return (rhs < lhs);
112 }
113
115 template <typename T1, typename T2>
116 CUTLASS_HOST_DEVICE
117 bool operator>=(Pair<T1,T2> const &lhs, Pair<T1,T2> const &rhs) {
118 return !(lhs < rhs);
119 }
120
122
123 } // namespace platform
124 } // namespace cutlass
cutlass
Definition: convert.h:33
cutlass::platform::operator==
CUTLASS_HOST_DEVICE bool operator==(complex< T > const &lhs, complex< T > const &rhs)
Equality operator.
Definition: complex.h:224
cutlass::platform::make_Pair
Pair< T1, T2 > make_Pair(T1 const &first, T2 const &second)
Constructs a pair and deduces types.
Definition: pair.h:66
cutlass::platform::Pair::Pair
CUTLASS_HOST_DEVICE Pair()
Default constructor.
Definition: pair.h:57
cutlass::platform::operator>
CUTLASS_HOST_DEVICE bool operator>(Pair< T1, T2 > const &lhs, Pair< T1, T2 > const &rhs)
Lexical comparison.
Definition: pair.h:110
cutlass::platform::Pair::first_type
T1 first_type
Definition: pair.h:41
cutlass::platform::Pair::second_type
T2 second_type
Definition: pair.h:42
CUTLASS_HOST_DEVICE
#define CUTLASS_HOST_DEVICE
Definition: cutlass.h:46
cutlass::platform::Pair::second
T1 second
Definition: pair.h:49
cutlass::platform::operator!=
CUTLASS_HOST_DEVICE bool operator!=(complex< T > const &lhs, complex< T > const &rhs)
Inequality operator.
Definition: complex.h:232
cutlass::platform::Pair::Pair
CUTLASS_HOST_DEVICE Pair(T1 const &first_, T2 const &second_)
Constructs a pair.
Definition: pair.h:61
cutlass::platform::Pair
Constructs an iterator from a pair of iterators.
Definition: pair.h:39
cutlass::platform::Pair::first
T1 first
Definition: pair.h:48
cutlass::platform::operator>=
CUTLASS_HOST_DEVICE bool operator>=(Pair< T1, T2 > const &lhs, Pair< T1, T2 > const &rhs)
Lexical comparison.
Definition: pair.h:117