defs.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. ///\file defs.h
  29. ///
  30. /// \defgroup nvBowtie nvBowtie
  31. /// see \ref nvBowtieArch
  32. #pragma once
  33. //#define NVBIO_CUDA_DEBUG
  34. //#define NVBIO_CUDA_NON_BLOCKING_ASSERTS
  35. //#define NVBIO_CUDA_ASSERTS
  36. #define USE_TEX 1
  37. #define USE_TEX_READS 1
  38. #define USE_UINT4_PACKING 0
  39. #if USE_TEX
  40. #define TEX_STATEMENT(x) x
  41. #define TEX_SELECTOR( vec, tex ) tex
  42. #else
  43. #define TEX_STATEMENT(x)
  44. #define TEX_SELECTOR( vec, tex ) vec
  45. #endif
  46. #if USE_TEX_READS
  47. #define READ_TEX_STATEMENT(x) x
  48. #define READ_TEX_SELECTOR( vec, tex ) tex
  49. #else
  50. #define READ_TEX_STATEMENT(x)
  51. #define READ_TEX_SELECTOR( vec, tex ) vec
  52. #endif
  53. #define USE_WARP_SYNCHRONOUS_QUEUES 1
  54. #define USE_REVERSE_INDEX 0
  55. #define DO_OPTIONAL_SYNCHRONIZE 1
  56. #define DO_DEVICE_TIMING 0
  57. #define DP_REPORT_MULTIPLE 0
  58. #include <nvbio/basic/cuda/arch.h>
  59. #include <nvbio/basic/pod.h>
  60. #include <nvbio/io/sequence/sequence.h> // FIXME: for PE_POLICY!
  61. #include <algorithm>
  62. namespace nvbio {
  63. namespace bowtie2 {
  64. namespace cuda {
  65. ///@addtogroup nvBowtie
  66. ///@{
  67. ///@addtogroup Defs
  68. ///@{
  69. enum EndType { kSingleEnd = 0u, kPairedEnds = 1u };
  70. // We assume reads contain, on average, this many bps
  71. enum { AVG_READ_LENGTH = 175 };
  72. // The device will launch blocks of size BLOCKDIM.
  73. enum { BLOCKDIM = 96 };
  74. // The device will launch blocks of size BLOCKDIM.
  75. enum { SCORE_MATE_BLOCKDIM = 128 };
  76. // Edit distance kernel band size.
  77. // for N errors we need band length 2*N+1
  78. enum { MAX_BAND_LEN = 63 };
  79. // We allow for at most this read length
  80. enum { MAXIMUM_READ_LENGTH = 512 };
  81. // We allow for at most this insert length
  82. enum { MAXIMUM_INSERT_LENGTH = 1024 };
  83. // We allow for at most this band length
  84. enum { MAXIMUM_BAND_LENGTH = 31 };
  85. // We allow at most MAXIMUM_BAND_LENGTH*MAXIMUM_BAND_LEN_MULT errors
  86. enum { MAXIMUM_BAND_LEN_MULT = 4 };
  87. enum { BANDED_DP_CHECKPOINTS = 16 };
  88. enum { FULL_DP_CHECKPOINTS = 64 };
  89. // Maximum number of words allocated for local memory strings
  90. enum { LMEM_CACHE_WORDS = 64 };
  91. struct edit_distance_scoring_tag {};
  92. struct smith_waterman_scoring_tag {};
  93. ///
  94. /// A helper class to track debugging info
  95. ///
  96. struct DebugState
  97. {
  98. uint32 read_id;
  99. bool select;
  100. bool locate;
  101. bool score;
  102. bool score_bad;
  103. bool score_info;
  104. bool reduce;
  105. bool traceback;
  106. bool asserts;
  107. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool show_select (const uint32 id) const { return select && id == read_id; }
  108. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool show_locate (const uint32 id) const { return locate && id == read_id; }
  109. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool show_score (const uint32 id, const bool good) const { return score && id == read_id && (score_bad || good); }
  110. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool show_score_info (const uint32 id) const { return score_info && id == read_id; }
  111. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool show_reduce (const uint32 id) const { return reduce && id == read_id; }
  112. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE bool show_traceback (const uint32 id) const { return traceback && id == read_id; }
  113. };
  114. enum {
  115. HIT_STATS_RANGES = 0,
  116. HIT_STATS_MAX_RANGE = 1,
  117. HIT_STATS_TOTAL = 2,
  118. HIT_STATS_MAX = 3,
  119. HIT_STATS_TOP = 4,
  120. HIT_STATS_TOP_MAX = 5,
  121. HIT_STATS_BINS = 6,
  122. HIT_STATS_TOP_BINS = 6 + 32,
  123. };
  124. ///@} // group Defs
  125. ///
  126. /// A simple POD struct to represent a read id and its top flag status in a packed uint32
  127. ///
  128. struct packed_read
  129. {
  130. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  131. packed_read() {}
  132. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  133. packed_read(const uint32 _read_id, const uint32 _top_flag = 1u) :
  134. read_id( _read_id ), top_flag(_top_flag) {}
  135. uint32 read_id:31, top_flag:1;
  136. };
  137. ///
  138. /// A simple POD struct to represent a seed's information in a packed uint32:
  139. /// - position in read
  140. /// - FM-index direction
  141. /// - reverse-complement flag
  142. /// - top flag
  143. ///
  144. struct packed_seed
  145. {
  146. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  147. packed_seed() {}
  148. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  149. packed_seed(const uint32 _pos_in_read, const uint32 _index_dir, const uint32 _rc, const uint32 _top_flag) :
  150. pos_in_read(_pos_in_read), index_dir(_index_dir), rc(_rc), top_flag(_top_flag) {}
  151. uint32 pos_in_read:12, index_dir:1, rc:1, top_flag:1;
  152. };
  153. /// pack-read functor, converting an integer read id into a packed_read
  154. ///
  155. struct pack_read
  156. {
  157. typedef uint32 argument_type;
  158. typedef packed_read result_type;
  159. /// default constructor
  160. ///
  161. pack_read() : top_flag(0u) {}
  162. /// constructor
  163. ///
  164. /// \param _top_flag top flag
  165. ///
  166. pack_read(const uint32 _top_flag) : top_flag(_top_flag) {}
  167. /// functor operator
  168. ///
  169. NVBIO_FORCEINLINE NVBIO_HOST_DEVICE
  170. packed_read operator() (const uint32 i) const { return packed_read(i, top_flag); }
  171. uint32 top_flag;
  172. };
  173. ///@} // group nvBowtie
  174. } // namespace cuda
  175. } // namespace bowtie2
  176. } // namespace nvbio