1 // ==========================================================================
2 //                 SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2013 NVIDIA Corporation
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 //       notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above copyright
13 //       notice, this list of conditions and the following disclaimer in the
14 //       documentation and/or other materials provided with the distribution.
15 //     * Neither the name of NVIDIA Corporation nor the names of
16 //       its contributors may be used to endorse or promote products derived
17 //       from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30 //
31 // ==========================================================================
32 // Author: Enrico Siragusa <enrico.siragusa@fu-berlin.de>
33 // ==========================================================================
34 
35 #ifndef SEQAN_BASIC_DEVICE_H
36 #define SEQAN_BASIC_DEVICE_H
37 
38 namespace seqan {
39 
40 // ============================================================================
41 // Tags
42 // ============================================================================
43 
44 // ----------------------------------------------------------------------------
45 // Execution space tags
46 // ----------------------------------------------------------------------------
47 
48 struct ExecHost_;
49 struct ExecDevice_;
50 
51 typedef Tag<ExecHost_>   ExecHost;
52 typedef Tag<ExecDevice_> ExecDevice;
53 
54 // ============================================================================
55 // Metafunctions
56 // ============================================================================
57 
58 // ----------------------------------------------------------------------------
59 // Metafunction Device
60 // ----------------------------------------------------------------------------
61 
62 /*!
63  * @mfn Device
64  * @headerfile <seqan/basic.h>
65  * @brief Converts a given type into one that lives on a device.
66  *
67  * @signature Device<TObject>::Type;
68  * @tparam TObject The type to be converted into a device type.
69  * @return Type The resulting device type.
70  *
71  * This metafunction is used to convert host containers into device containers.
72  *
73  * @see View
74  */
75 
76 template <typename TObject = void>
77 struct Device
78 {
79     typedef TObject Type;
80 };
81 
82 template <typename TObject>
83 struct Device<TObject const>
84 {
85     typedef typename Device<TObject>::Type const    Type;
86 };
87 
88 // ----------------------------------------------------------------------------
89 // Metafunction IsDevice
90 // ----------------------------------------------------------------------------
91 
92 /*!
93  * @mfn IsDevice
94  * @headerfile <seqan/basic.h>
95  * @brief Tests if a given type is a device type.
96  *
97  * @signature IsDevice<TObject>::Type;
98  * @tparam TObject The type to be tested for being a device type.
99  * @return Type @link LogicalValuesTags#True @endlink or @link LogicalValuesTags#False @endlink.
100  *
101  * @see Device
102  */
103 
104 template <typename TObject>
105 struct IsDevice : public False {};
106 
107 template <typename TObject>
108 struct IsDevice<TObject const> : public IsDevice<TObject> {};
109 
110 // ----------------------------------------------------------------------------
111 // Metafunction IfDevice
112 // ----------------------------------------------------------------------------
113 
114 template <typename TObject, typename T1, typename T2>
115 struct IfDevice
116 {
117     typedef typename If<IsDevice<TObject>, T1, T2>::Type  Type;
118 };
119 
120 // ----------------------------------------------------------------------------
121 // Metafunction ExecSpace
122 // ----------------------------------------------------------------------------
123 
124 template <typename TObject>
125 struct ExecSpace
126 {
127     typedef typename If<IsDevice<TObject>, ExecDevice, ExecHost>::Type   Type;
128 };
129 
130 // ----------------------------------------------------------------------------
131 // Metafunction ExecSpec
132 // ----------------------------------------------------------------------------
133 
134 template <typename TObject, typename TSpec = void>
135 struct ExecSpec
136 {
137     typedef typename IfDevice<TObject, Device<TSpec>, TSpec>::Type   Type;
138 };
139 
140 // ----------------------------------------------------------------------------
141 // Metafunction CtaSize
142 // ----------------------------------------------------------------------------
143 
144 template <typename TObject, typename TSpec = void>
145 struct CtaSize
146 {
147     static const unsigned VALUE = 256;
148 };
149 
150 }  // namespace seqan
151 
152 #endif  // #ifndef SEQAN_BASIC_DEVICE_H
153