NVBIO
Main Page
Modules
Classes
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
nvbio
qgram
qgroup.h
Go to the documentation of this file.
1
/*
2
* nvbio
3
* Copyright (c) 2011-2014, NVIDIA CORPORATION. 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
* * Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* * Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* * Neither the name of the NVIDIA CORPORATION nor the
13
* names of its contributors may be used to endorse or promote products
14
* derived from this software without specific prior written permission.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
* DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#pragma once
29
30
#include <
nvbio/qgram/qgram.h
>
31
#include <
nvbio/basic/types.h
>
32
#include <
nvbio/basic/numbers.h
>
33
#include <
nvbio/basic/packedstream.h
>
34
#include <
nvbio/basic/cuda/primitives.h
>
35
#include <
nvbio/basic/thrust_view.h
>
36
#include <thrust/host_vector.h>
37
#include <thrust/device_vector.h>
38
#include <thrust/scatter.h>
39
#include <thrust/for_each.h>
40
#include <thrust/iterator/constant_iterator.h>
41
59
60
namespace
nvbio {
61
64
77
80
template
<
typename
index_iterator>
81
struct
QGroupIndexViewCore
82
{
83
static
const
uint32
WORD_SIZE
= 32;
84
85
// class typedefs
86
typedef
index_iterator
vector_type
;
87
typedef
uint32
coord_type
;
88
89
// plain view typedefs
90
typedef
QGroupIndexViewCore<index_iterator>
plain_view_type
;
91
typedef
QGroupIndexViewCore<index_iterator>
const_plain_view_type
;
92
93
// unary functor typedefs
94
typedef
uint64
argument_type
;
95
typedef
uint2
result_type
;
96
99
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
100
QGroupIndexViewCore
(
101
const
uint32
_Q = 0,
102
const
uint32
_symbol_size = 0,
103
const
uint32
_n_qgrams = 0,
104
const
uint32
_n_unique_qgrams = 0,
105
vector_type
_I = NULL,
106
vector_type
_S = NULL,
107
vector_type
_SS = NULL,
108
vector_type
_P = NULL) :
109
Q
(_Q),
110
symbol_size
(_symbol_size),
111
n_qgrams
(_n_qgrams),
112
n_unique_qgrams
(_n_unique_qgrams),
113
I
(_I),
114
S
(_S),
115
SS
(_SS),
116
P
(_P) {}
117
120
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
121
uint2
range
(
const
uint64
g)
const
122
{
123
const
uint32
i =
uint32
( g /
WORD_SIZE
);
124
const
uint32
j =
uint32
( g %
WORD_SIZE
);
125
126
// check whether the j-th bit of I[i] is set
127
if
((
I
[i] & (1u << j)) == 0u)
128
return
make_uint2( 0u, 0u );
129
130
// compute j' such that bit j is the j'-th set bit in I[i]
131
const
uint32
j_prime =
popc
(
I
[i] & ((1u << j) - 1u) );
132
133
return
make_uint2(
134
SS
[
S
[i] + j_prime ],
135
SS
[
S
[i] + j_prime + 1u ] );
136
}
137
140
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
141
uint2
operator()
(
const
uint64
g)
const
{
return
range
( g ); }
142
145
NVBIO_FORCEINLINE
NVBIO_HOST_DEVICE
146
uint32
locate
(
const
uint32
i)
const
{
return
P
[i]; }
147
148
149
uint32
Q
;
150
uint32
symbol_size
;
151
uint32
n_qgrams
;
152
uint32
n_unique_qgrams
;
153
vector_type
I
;
154
vector_type
S
;
155
vector_type
SS
;
156
vector_type
P
;
157
};
158
159
typedef
QGroupIndexViewCore<uint32*>
QGroupIndexView
;
160
typedef
QGroupIndexViewCore<const uint32*>
ConstQGroupIndexView
;
161
164
struct
QGroupIndexHost
165
{
166
static
const
uint32
WORD_SIZE
= 32;
167
168
typedef
host_tag
system_tag
;
169
170
typedef
thrust::host_vector<uint32>
vector_type
;
171
typedef
uint32
coord_type
;
172
typedef
QGroupIndexView
plain_view_type
;
173
typedef
ConstQGroupIndexView
const_plain_view_type
;
174
177
uint64
used_host_memory
()
const
178
{
179
return
I
.size() *
sizeof
(
uint32
) +
180
S
.size() *
sizeof
(
uint32
) +
181
SS
.size() *
sizeof
(
uint32
) +
182
P
.size() *
sizeof
(
uint32
);
183
}
184
187
uint64
used_device_memory
()
const
{
return
0u; }
188
189
uint32
Q
;
190
uint32
n_qgrams
;
191
uint32
n_unique_qgrams
;
192
vector_type
I
;
193
vector_type
S
;
194
vector_type
SS
;
195
vector_type
P
;
196
};
197
200
struct
QGroupIndexDevice
201
{
202
static
const
uint32
WORD_SIZE
= 32;
203
204
typedef
device_tag
system_tag
;
205
206
typedef
thrust::device_vector<uint32>
vector_type
;
207
typedef
uint32
coord_type
;
208
typedef
QGroupIndexView
view_type
;
209
220
template
<
typename
string
_type>
221
void
build
(
222
const
uint32
q,
223
const
uint32
symbol_sz,
224
const
uint32
string_len,
225
const
string_type
string
);
226
229
uint64
used_host_memory
()
const
{
return
0u; }
230
233
uint64
used_device_memory
()
const
234
{
235
return
I
.size() *
sizeof
(
uint32
) +
236
S
.size() *
sizeof
(
uint32
) +
237
SS
.size() *
sizeof
(
uint32
) +
238
P
.size() *
sizeof
(
uint32
);
239
}
240
241
uint32
Q
;
242
uint32
symbol_size
;
243
uint32
n_qgrams
;
244
uint32
n_unique_qgrams
;
245
vector_type
I
;
246
vector_type
S
;
247
vector_type
SS
;
248
vector_type
P
;
249
};
250
253
inline
254
QGroupIndexView
plain_view
(
const
QGroupIndexView
qgram) {
return
qgram; }
255
258
inline
259
ConstQGroupIndexView
plain_view
(
const
ConstQGroupIndexView
qgram) {
return
qgram; }
260
263
inline
264
QGroupIndexView
plain_view
(
QGroupIndexDevice
& qgroup)
265
{
266
return
QGroupIndexView
(
267
qgroup.
Q
,
268
qgroup.
symbol_size
,
269
qgroup.
n_qgrams
,
270
qgroup.
n_unique_qgrams
,
271
nvbio::plain_view
( qgroup.
I
),
272
nvbio::plain_view
( qgroup.
S
),
273
nvbio::plain_view
( qgroup.
SS
),
274
nvbio::plain_view
( qgroup.
P
) );
275
}
276
279
inline
280
ConstQGroupIndexView
plain_view
(
const
QGroupIndexDevice
& qgroup)
281
{
282
return
ConstQGroupIndexView
(
283
qgroup.
Q
,
284
qgroup.
symbol_size
,
285
qgroup.
n_qgrams
,
286
qgroup.
n_unique_qgrams
,
287
nvbio::plain_view
( qgroup.
I
),
288
nvbio::plain_view
( qgroup.
S
),
289
nvbio::plain_view
( qgroup.
SS
),
290
nvbio::plain_view
( qgroup.
P
) );
291
}
292
293
template
<>
struct
plain_view_subtype
<
QGroupIndexHost
> {
typedef
QGroupIndexView
type
; };
294
template
<>
struct
plain_view_subtype
<
QGroupIndexDevice
> {
typedef
QGroupIndexView
type
; };
295
template
<>
struct
plain_view_subtype
<
const
QGroupIndexHost
> {
typedef
ConstQGroupIndexView
type
; };
296
template
<>
struct
plain_view_subtype
<
const
QGroupIndexDevice
> {
typedef
ConstQGroupIndexView
type
; };
297
300
301
}
// namespace nvbio
302
303
#include <
nvbio/qgram/qgroup_inl.h
>
Generated on Wed Feb 25 2015 08:33:01 for NVBIO by
1.8.4