1 // ========================================================================== 2 // SeqAn - The Library for Sequence Analysis 3 // ========================================================================== 4 // Copyright (c) 2006-2018, Knut Reinert, FU Berlin 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions are met: 9 // 10 // * Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // * Redistributions in binary form must reproduce the above copyright 13 // notice, this list of conditions and the following disclaimer in the 14 // documentation and/or other materials provided with the distribution. 15 // * Neither the name of Knut Reinert or the FU Berlin nor the names of 16 // its contributors may be used to endorse or promote products derived 17 // from this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE 23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 // DAMAGE. 30 // 31 // ========================================================================== 32 // Author: Rene Rahn <rene.rahn@fu-berlin.de> 33 // ========================================================================== 34 35 #ifndef INCLUDE_SEQAN_DP_PARALLEL_DP_PARALLEL_SCOUT_SIMD_H_ 36 #define INCLUDE_SEQAN_DP_PARALLEL_DP_PARALLEL_SCOUT_SIMD_H_ 37 38 namespace seqan 39 { 40 41 // ============================================================================ 42 // Forwards 43 // ============================================================================ 44 45 // ============================================================================ 46 // Tags, Classes, Enums 47 // ============================================================================ 48 49 // ---------------------------------------------------------------------------- 50 // Class DPScoutState_; DPTiled 51 // ---------------------------------------------------------------------------- 52 53 // The overloaded DPScoutState which simply stores the pointers to the corresponding buffer. 54 template <typename TBuffer, typename TThreadContext, typename TSimdSpec> 55 class DPScoutState_<DPTiled<TBuffer, TThreadContext, TSimdSpec> > : 56 public DPScoutState_<DPTiled<TBuffer, TThreadContext, void> >, 57 public DPScoutState_<TSimdSpec> 58 { 59 public: 60 61 DPScoutState_() = default; 62 DPScoutState_(TBuffer & horBuffer,TBuffer & verBuffer)63 DPScoutState_(TBuffer & horBuffer, TBuffer & verBuffer) : 64 DPScoutState_<DPTiled<TBuffer, TThreadContext, void> >(horBuffer, verBuffer), 65 DPScoutState_<TSimdSpec>() 66 {} 67 DPScoutState_(TBuffer & horBuffer,TBuffer & verBuffer,TThreadContext && pThreadContext)68 DPScoutState_(TBuffer & horBuffer, TBuffer & verBuffer, TThreadContext && pThreadContext) : 69 DPScoutState_<DPTiled<TBuffer, TThreadContext, void> >(horBuffer, verBuffer, std::move(pThreadContext)), 70 DPScoutState_<TSimdSpec>() 71 {} 72 }; 73 74 // ---------------------------------------------------------------------------- 75 // Class DPScout_; DPTiled 76 // ---------------------------------------------------------------------------- 77 78 // Overloaded DPScout to store the corresponding buffer for the current dp tile. 79 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TSimdSpec> 80 class DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > > : 81 public DPScout_<TDPCell, SimdAlignmentScout<TSimdSpec>> 82 { 83 public: 84 using TBase = DPScout_<TDPCell, SimdAlignmentScout<TSimdSpec> >; 85 86 DPScoutState_<DPTiled<TBuffer, TThreadContext, TSimdSpec> > state; 87 size_t horizontalPos; 88 size_t verticalPos; 89 bool forceTracking; 90 DPScout_(DPScoutState_<DPTiled<TBuffer,TThreadContext,TSimdSpec>> & state,bool const pForceTracking)91 DPScout_(DPScoutState_<DPTiled<TBuffer, TThreadContext, TSimdSpec> > & state, 92 bool const pForceTracking) : 93 TBase(static_cast<DPScoutState_<TSimdSpec>&>(state)), 94 state(state), 95 forceTracking(pForceTracking) 96 {} 97 DPScout_(DPScoutState_<DPTiled<TBuffer,TThreadContext,TSimdSpec>> & state)98 DPScout_(DPScoutState_<DPTiled<TBuffer, TThreadContext, TSimdSpec> > & state) : DPScout_(state, false) 99 {} 100 }; 101 102 // ============================================================================ 103 // Metafunctions 104 // ============================================================================ 105 106 // ---------------------------------------------------------------------------- 107 // Metafunction ScoutSpecForSimdAlignment_ 108 // ---------------------------------------------------------------------------- 109 110 template<typename TAlignmentAlgorithm, typename TBuffer, typename TThreadContext> 111 struct ScoutSpecForAlignmentAlgorithm_<TAlignmentAlgorithm, 112 DPScoutState_<DPTiled<TBuffer, TThreadContext, SimdAlignEqualLength> > > 113 { 114 using Type = DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<SimdAlignEqualLength> >; 115 }; 116 117 template<typename TAlignmentAlgorithm, typename TBuffer, typename TThreadContext, typename TTraits> 118 struct ScoutSpecForAlignmentAlgorithm_<TAlignmentAlgorithm, 119 DPScoutState_<DPTiled<TBuffer, 120 TThreadContext, 121 SimdAlignVariableLength<TTraits> > > > 122 { 123 using Type = DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<SimdAlignVariableLength<TTraits> > >; 124 }; 125 126 // ============================================================================ 127 // Functions 128 // ============================================================================ 129 130 // ---------------------------------------------------------------------------- 131 // Function isTrackingEnabled() 132 // ---------------------------------------------------------------------------- 133 134 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TSimdSpec> 135 inline bool 136 isTrackingEnabled(DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > > const & dpScout, 137 True const & /*unused*/, 138 True const & /*unused*/) 139 { 140 // TODO(rrahn): Implement me! 141 return (dpScout.forceTracking); 142 } 143 144 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TSimdSpec> 145 inline bool 146 isTrackingEnabled(DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > > const & dpScout, 147 True const & /*unused*/, 148 False const & /*unused*/) 149 { 150 // TODO(rrahn): Implement me! 151 return (dpScout.forceTracking); 152 } 153 154 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TSimdSpec> 155 inline bool 156 isTrackingEnabled(DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > > const & dpScout, 157 False const & /*unused*/, 158 True const & /*unused*/) 159 { 160 // TODO(rrahn): Implement me! 161 return (dpScout.forceTracking); 162 } 163 164 // ---------------------------------------------------------------------------- 165 // Function _scoutBestScore() 166 // ---------------------------------------------------------------------------- 167 168 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TSimdSpec, 169 typename TTraceMatrixNavigator, 170 typename TIsLastColumn, 171 typename TIsLastRow> 172 inline void 173 _scoutBestScore(DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > > & dpScout, 174 TDPCell const & activeCell, 175 TTraceMatrixNavigator const & navigator, 176 TIsLastColumn const & isLastColumn, 177 TIsLastRow const & isLastRow) 178 { 179 using TScoutBase = typename DPScout_<TDPCell, 180 DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec>>>::TBase; 181 _scoutBestScore(static_cast<TScoutBase&>(dpScout), activeCell, navigator, isLastColumn, isLastRow); 182 } 183 184 // ---------------------------------------------------------------------------- 185 // Function maxHostCoordinate() 186 // ---------------------------------------------------------------------------- 187 188 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TSimdSpec, 189 typename TDimension> 190 inline auto 191 maxHostCoordinate(DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > > const & dpScout, 192 TDimension const dimension) 193 { 194 using TScoutBase = typename DPScout_<TDPCell, 195 DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > >::TBase; 196 return maxHostCoordinate(static_cast<TScoutBase const &>(dpScout), dimension); 197 } 198 199 // ---------------------------------------------------------------------------- 200 // Function _setSimdLane() 201 // ---------------------------------------------------------------------------- 202 203 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TSimdSpec, 204 typename TPosition> 205 inline void 206 _setSimdLane(DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > > & dpScout, 207 TPosition const pos) 208 { 209 using TScoutBase = typename DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<TSimdSpec> > >::TBase; 210 _setSimdLane(static_cast<TScoutBase&>(dpScout), pos); 211 } 212 213 // ---------------------------------------------------------------------------- 214 // Function _preInitScoutHorizontal() 215 // ---------------------------------------------------------------------------- 216 217 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits> 218 inline void 219 _preInitScoutHorizontal(DPScout_<TDPCell, DPTiled<TBuffer, TThreadContext, SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > > & scout) 220 { 221 using TScoutBase = typename DPScout_<TDPCell, 222 DPTiled<TBuffer, 223 TThreadContext, 224 SimdAlignmentScout<SimdAlignVariableLength<TTraits>>>>::TBase; 225 _preInitScoutHorizontal(static_cast<TScoutBase&>(scout)); 226 scout.horizontalPos = 0; 227 } 228 229 // ---------------------------------------------------------------------------- 230 // Function _preInitScoutVertical() 231 // ---------------------------------------------------------------------------- 232 233 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits> 234 inline void 235 _preInitScoutVertical(DPScout_<TDPCell, 236 DPTiled<TBuffer, 237 TThreadContext, 238 SimdAlignmentScout<SimdAlignVariableLength<TTraits>>>> & scout) 239 { 240 using TScoutBase = typename DPScout_<TDPCell, 241 DPTiled<TBuffer, 242 TThreadContext, 243 SimdAlignmentScout<SimdAlignVariableLength<TTraits>>>>::TBase; 244 _preInitScoutVertical(static_cast<TScoutBase&>(scout)); 245 scout.verticalPos = 0; 246 } 247 248 // ---------------------------------------------------------------------------- 249 // Function _reachedHorizontalEndPoint() 250 // ---------------------------------------------------------------------------- 251 252 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits, typename TIter> 253 inline bool 254 _reachedHorizontalEndPoint(DPScout_<TDPCell, 255 DPTiled<TBuffer, 256 TThreadContext, 257 SimdAlignmentScout<SimdAlignVariableLength<TTraits>>>> & scout, 258 TIter const & hIt) 259 { 260 using TScoutBase = typename DPScout_<TDPCell, 261 DPTiled<TBuffer, 262 TThreadContext, 263 SimdAlignmentScout<SimdAlignVariableLength<TTraits>>>>::TBase; 264 return _reachedHorizontalEndPoint(static_cast<TScoutBase&>(scout), hIt); 265 } 266 267 // ---------------------------------------------------------------------------- 268 // Function _reachedVerticalEndPoint() 269 // ---------------------------------------------------------------------------- 270 271 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits, typename TIter> 272 inline bool 273 _reachedVerticalEndPoint(DPScout_<TDPCell, 274 DPTiled<TBuffer, 275 TThreadContext, 276 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > > & scout, 277 TIter const & vIt) 278 { 279 using TScoutBase = typename DPScout_<TDPCell, 280 DPTiled<TBuffer, 281 TThreadContext, 282 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > >::TBase; 283 return _reachedVerticalEndPoint(static_cast<TScoutBase&>(scout), vIt); 284 } 285 286 // ---------------------------------------------------------------------------- 287 // Function _nextHorizontalEndPos() 288 // ---------------------------------------------------------------------------- 289 290 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits> 291 inline void 292 _nextHorizontalEndPos(DPScout_<TDPCell, 293 DPTiled<TBuffer, 294 TThreadContext, 295 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > > & scout) 296 { 297 using TScoutBase = typename DPScout_<TDPCell, 298 DPTiled<TBuffer, 299 TThreadContext, 300 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > >::TBase; 301 _nextHorizontalEndPos(static_cast<TScoutBase&>(scout)); 302 } 303 304 // ---------------------------------------------------------------------------- 305 // Function _nextVerticalEndPos() 306 // ---------------------------------------------------------------------------- 307 308 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits> 309 inline void 310 _nextVerticalEndPos(DPScout_<TDPCell, 311 DPTiled<TBuffer, 312 TThreadContext, 313 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > > & scout) 314 { 315 using TScoutBase = typename DPScout_<TDPCell, 316 DPTiled<TBuffer, 317 TThreadContext, 318 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > >::TBase; 319 _nextVerticalEndPos(static_cast<TScoutBase&>(scout)); 320 } 321 322 // ---------------------------------------------------------------------------- 323 // Function _incHorizontalPos() 324 // ---------------------------------------------------------------------------- 325 326 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits> 327 inline void 328 _incHorizontalPos(DPScout_<TDPCell, 329 DPTiled<TBuffer, 330 TThreadContext, 331 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > > & scout) 332 { 333 using TScoutBase = typename DPScout_<TDPCell, 334 DPTiled<TBuffer, 335 TThreadContext, 336 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > >::TBase; 337 _incHorizontalPos(static_cast<TScoutBase&>(scout)); 338 ++scout.horizontalPos; 339 } 340 341 // ---------------------------------------------------------------------------- 342 // Function _incVerticalPos() 343 // ---------------------------------------------------------------------------- 344 345 template <typename TDPCell, typename TBuffer, typename TThreadContext, typename TTraits> 346 inline void 347 _incVerticalPos(DPScout_<TDPCell, 348 DPTiled<TBuffer, 349 TThreadContext, 350 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > > & scout) 351 { 352 using TScoutBase = typename DPScout_<TDPCell, 353 DPTiled<TBuffer, 354 TThreadContext, 355 SimdAlignmentScout<SimdAlignVariableLength<TTraits> > > >::TBase; 356 _incVerticalPos(static_cast<TScoutBase&>(scout)); 357 ++scout.verticalPos; 358 } 359 360 } // namespace seqan 361 362 #endif // #ifndef INCLUDE_SEQAN_DP_PARALLEL_DP_PARALLEL_SCOUT_SIMD_H_ 363