NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ssa.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/basic/types.h>
31 #include <nvbio/basic/popcount.h>
32 #include <nvbio/basic/cuda/arch.h>
33 #include <nvbio/basic/cuda/ldg.h>
34 #include <vector_types.h>
35 #include <vector_functions.h>
36 #include <cuda_runtime.h>
37 #include <vector>
38 #include <stdexcept>
39 #include <thrust/device_vector.h>
40 
41 namespace nvbio {
42 
45 
86 
89 
90 struct SSA_value_multiple_device;
91 
92 template <uint32 K, typename index_type = uint32>
94 
98 template <typename SSAIterator, typename BitmaskIterator, typename BlockIterator>
100 {
104 
108  SSAIterator ssa,
109  BitmaskIterator bitmask,
110  BlockIterator blocks) : m_ssa( ssa ), m_bitmask( bitmask ), m_blocks( blocks ) {}
111 
117  NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool fetch(const uint32 i, uint32& r) const;
118 
123  NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool has(const uint32 i) const;
124 
125  SSAIterator m_ssa;
126  BitmaskIterator m_bitmask;
127  BlockIterator m_blocks;
128 };
129 
135 {
137  const uint32*,
138  const uint32*,
143 
147 
154  const uint32 n,
155  const int32* sa,
156  const uint32 K);
157 
162  template <typename FMIndexType>
164  const FMIndexType& fmi,
165  const uint32 K);
166 
170  {
171  return context_type( &m_ssa[0], &m_bitmask[0], &m_blocks[0] );
172  }
173 
176  std::vector<uint32> m_ssa;
177  std::vector<uint32> m_bitmask;
178  std::vector<uint32> m_blocks;
179 
180 private:
181  uint32 index(const uint32 i) const;
182 };
183 
185 {
192 
197 
201 
205  {
207  }
208 
214 };
215 
219 template <uint32 K, typename Iterator = const uint32*>
221 {
222  typedef typename std::iterator_traits<Iterator>::value_type index_type;
224 
228 
232  const Iterator ssa) : m_ssa( ssa ) {}
233 
240 
246 
247  Iterator m_ssa;
248 };
249 
254 template <uint32 K, typename index_type = uint32>
256 {
257  typedef index_type value_type;
262 
266 
272  const index_type n,
273  const index_type* sa);
274 
279  template <typename FMIndexType>
281  const FMIndexType& fmi);
282 
288 
294 
297  context_type get_context() const { return context_type( &m_ssa[0] ); }
298 
299  index_type m_n;
300  std::vector<index_type> m_ssa;
301 };
302 
303 template <uint32 K, typename index_type>
305 {
306  typedef index_type value_type;
310 
314 
319 
320 #ifdef __CUDACC__
321  template <typename FMIndexType>
326  const FMIndexType& fmi);
327  #endif
328 
332 
333  #ifdef __CUDACC__
334  template <typename FMIndexType>
335  void init(const FMIndexType& fmi);
336  #endif
337 
340  context_type get_context() const { return context_type( thrust::raw_pointer_cast(&m_ssa[0]) ); }
341 
342  index_type m_n;
343  thrust::device_vector<index_type> m_ssa;
344 };
345 
348 inline
350 
353 inline
355 
358 template <uint32 K, typename index_type>
360 
361 
364 
365 } // namespace nvbio
366 
367 #include <nvbio/fmindex/ssa_inl.h>