select.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 select.h
  29. ///
  30. #pragma once
  31. #include <nvBowtie/bowtie2/cuda/defs.h>
  32. #include <nvBowtie/bowtie2/cuda/seed_hit.h>
  33. #include <nvBowtie/bowtie2/cuda/seed_hit_deque_array.h>
  34. #include <nvBowtie/bowtie2/cuda/scoring_queues.h>
  35. #include <nvBowtie/bowtie2/cuda/params.h>
  36. #include <nvbio/basic/cuda/pingpong_queues.h>
  37. #include <nvbio/io/alignments.h>
  38. namespace nvbio {
  39. namespace bowtie2 {
  40. namespace cuda {
  41. template <typename ScoringScheme> struct BaseScoringPipelineState;
  42. template <typename ScoringScheme> struct BestApproxScoringPipelineState;
  43. ///@addtogroup nvBowtie
  44. ///@{
  45. /// \defgroup Select
  46. ///
  47. /// The functions in this module implement a pipeline stage in which, for all the active reads in the
  48. /// \ref ScoringQueues, a group of seed hits is selected for a new round of \ref Scoring.
  49. /// In terms of inputs and outputs, this stage takes the set of input ScoringQueues::active_reads, and
  50. /// fills the ScoringQueues::hits with a new set of hits, writing the HitQueues::read_id, HitQueues::seed,
  51. /// and HitQueues::loc fields. The hits' location specified by the HitQueues::loc field is expressed in
  52. /// Suffix Array coordinates.
  53. /// Finally, this stage is also responsible for producing a new set of ScoringQueues::active_reads.
  54. ///
  55. /// \b inputs:
  56. /// - SeedHitDequeArray
  57. /// - ScoringQueues::active_reads
  58. ///
  59. /// \b outputs:
  60. /// - SeedHitDequeArray
  61. /// - ScoringQueues::active_reads
  62. /// - HitQueues::read_id
  63. /// - HitQueues::seed
  64. /// - HitQueues::loc
  65. ///
  66. ///@addtogroup Select
  67. ///@{
  68. ///
  69. /// Initialize the hit-selection pipeline
  70. ///
  71. void select_init(
  72. const uint32 count,
  73. const char* read_names,
  74. const uint32* read_names_idx,
  75. const SeedHitDequeArrayDeviceView hits,
  76. uint32* trys,
  77. uint32* rseeds,
  78. const ParamsPOD params);
  79. ///
  80. /// Initialize the hit-selection pipeline
  81. ///
  82. void select_init(BestApproxScoringPipelineState<EditDistanceScoringScheme>& pipeline, const ParamsPOD& params);
  83. ///
  84. /// Initialize the hit-selection pipeline
  85. ///
  86. void select_init(BestApproxScoringPipelineState<SmithWatermanScoringScheme<> >& pipeline, const ParamsPOD& params);
  87. ///
  88. /// a context class for the select_kernel
  89. ///
  90. struct SelectBestApproxContext
  91. {
  92. // constructor
  93. //
  94. // \param trys the per-read vector of extension trys
  95. //
  96. SelectBestApproxContext(uint32* trys) : m_trys( trys ) {}
  97. // stopping function
  98. //
  99. // \return true iff we can stop the hit selection process
  100. //
  101. NVBIO_FORCEINLINE NVBIO_DEVICE
  102. bool stop(const uint32 read_id) const { return m_trys[ read_id ] == 0; }
  103. private:
  104. uint32* m_trys;
  105. };
  106. ///
  107. /// select next hit extensions from the top seed ranges
  108. ///
  109. __global__
  110. void select_n_from_top_range_kernel(
  111. const uint32 begin,
  112. const uint32 count,
  113. const uint32 n_reads,
  114. const SeedHit* hit_data,
  115. const uint32* hit_range_scan,
  116. uint32* loc_queue,
  117. uint32* seed_queue,
  118. uint32* read_info);
  119. ///
  120. /// Prepare for a round of seed extension by selecting the next SA row from each
  121. /// of the seed-hit deque arrays (SeedHitDequeArray) bound to the active-reads in
  122. /// the scoring queues (ScoringQueues::active_reads).
  123. ///
  124. void select(
  125. const SelectBestApproxContext context,
  126. const BestApproxScoringPipelineState<EditDistanceScoringScheme>& pipeline,
  127. const ParamsPOD params);
  128. ///
  129. /// Prepare for a round of seed extension by selecting the next SA row from each
  130. /// of the seed-hit deque arrays (SeedHitDequeArray) bound to the active-reads in
  131. /// the scoring queues (ScoringQueues::active_reads).
  132. ///
  133. void select(
  134. const SelectBestApproxContext context,
  135. const BestApproxScoringPipelineState<SmithWatermanScoringScheme<> >& pipeline,
  136. const ParamsPOD params);
  137. ///
  138. /// Select next hit extensions for all-mapping
  139. ///
  140. void select_all(
  141. const uint64 begin,
  142. const uint32 count,
  143. const uint32 n_reads,
  144. const uint32 n_hit_ranges,
  145. const uint64 n_hits,
  146. const SeedHitDequeArrayDeviceView hits,
  147. const uint32* hit_count_scan,
  148. const uint64* hit_range_scan,
  149. HitQueuesDeviceView scoring_queues);
  150. ///@} // group Select
  151. ///@} // group nvBowtie
  152. } // namespace cuda
  153. } // namespace bowtie2
  154. } // namespace nvbio