NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
checksums.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 
32 #include <nvbio/basic/types.h>
33 #include <crc/crc.h>
34 #include <thrust/device_vector.h>
35 #include <thrust/sort.h>
36 
37 namespace nvbio {
38 namespace bowtie2 {
39 namespace cuda {
40 
41 struct SeedHit;
42 
43 // compute a checksum of a device sequence
44 //
45 template <typename Iterator>
47  Iterator begin,
48  Iterator end)
49 {
50  typedef typename thrust::iterator_traits<Iterator>::value_type value_type;
51 
52  const uint32 n = uint32( end - begin );
53 
54  // copy values to a temporary vector
55  thrust::device_vector<value_type> debug_copy_dvec( n );
57  begin,
58  end,
59  debug_copy_dvec.begin() );
60 
61  // sort temporary vector
62  thrust::sort( debug_copy_dvec.begin(), debug_copy_dvec.end() );
63 
64  // copy to the host
65  thrust::host_vector<value_type> debug_copy_hvec( debug_copy_dvec );
66 
67  // compute a crc
68  const char* ptr = (const char*)thrust::raw_pointer_cast( &debug_copy_hvec.front() );
69  return crcCalc( ptr, sizeof(value_type)*n );
70 }
71 
72 // compute a checksum for the returned SA ranges
73 //
74 void hits_checksum(
75  const uint32 n_reads,
76  SeedHitDequeArray& hit_deques,
77  uint64& crc,
78  uint64& sum);
79 
80 } // namespace cuda
81 } // namespace bowtie2
82 } // namespace nvbio