1 // Copyright (c) 2020 Robert Vaser 2 3 #ifndef SIMD_ALIGNMENT_ENGINE_HPP_ 4 #define SIMD_ALIGNMENT_ENGINE_HPP_ 5 6 #include <cstdint> 7 #include <memory> 8 #include <string> 9 #include <vector> 10 11 #include "spoa/alignment_engine.hpp" 12 #include "spoa/architectures.hpp" 13 14 namespace spoa { 15 16 class Graph; 17 18 std::unique_ptr<AlignmentEngine> CreateSimdAlignmentEngine( // for dispatcher 19 AlignmentType type, 20 AlignmentSubtype subtype, 21 std::int8_t m, 22 std::int8_t n, 23 std::int8_t g, 24 std::int8_t e, 25 std::int8_t q, 26 std::int8_t c); 27 28 template<Architecture A> 29 class SimdAlignmentEngine: public AlignmentEngine { 30 public: 31 SimdAlignmentEngine(const SimdAlignmentEngine&) = delete; 32 SimdAlignmentEngine& operator=(const SimdAlignmentEngine&) = delete; 33 34 SimdAlignmentEngine(SimdAlignmentEngine&&) = default; 35 SimdAlignmentEngine& operator=(SimdAlignmentEngine&&) = delete; 36 37 ~SimdAlignmentEngine() = default; 38 39 static std::unique_ptr<AlignmentEngine> Create( 40 AlignmentType type, 41 AlignmentSubtype subtype, 42 std::int8_t m, 43 std::int8_t n, 44 std::int8_t g, 45 std::int8_t e, 46 std::int8_t q, 47 std::int8_t c); 48 49 void Prealloc( 50 std::uint32_t max_sequence_len, 51 std::uint8_t alphabet_size) override; 52 53 Alignment Align( 54 const char* sequence, std::uint32_t sequence_len, 55 const Graph& graph, 56 std::int32_t* score) override; 57 58 friend std::unique_ptr<AlignmentEngine> CreateSimdAlignmentEngine( 59 AlignmentType type, 60 AlignmentSubtype subtype, 61 std::int8_t m, 62 std::int8_t n, 63 std::int8_t g, 64 std::int8_t e, 65 std::int8_t q, 66 std::int8_t c); 67 68 private: 69 SimdAlignmentEngine( 70 AlignmentType type, 71 AlignmentSubtype subtype, 72 std::int8_t m, 73 std::int8_t n, 74 std::int8_t g, 75 std::int8_t e, 76 std::int8_t q, 77 std::int8_t c); 78 79 template<typename T> 80 Alignment Linear( 81 std::uint32_t sequence_len, 82 const Graph& graph, 83 std::int32_t* score) noexcept; 84 85 template<typename T> 86 Alignment Affine( 87 std::uint32_t sequence_len, 88 const Graph& graph, 89 std::int32_t* score) noexcept; 90 91 template<typename T> 92 Alignment Convex( 93 std::uint32_t sequence_len, 94 const Graph& graph, 95 std::int32_t* score) noexcept; 96 97 void Realloc( 98 std::uint64_t matrix_width, 99 std::uint64_t matrix_height, 100 std::uint8_t num_codes); 101 102 template<typename T> 103 void Initialize( 104 const char* sequence, 105 const Graph& graph, 106 std::uint64_t normal_matrix_width, 107 std::uint64_t matrix_width, 108 std::uint64_t matrix_height) noexcept; 109 110 struct Implementation; 111 std::unique_ptr<Implementation> pimpl_; 112 }; 113 114 } // namespace spoa 115 116 #endif // SIMD_ALIGNMENT_ENGINE_HPP_ 117