Coverage Report

Created: 2024-05-04 12:45

/proc/self/cwd/external/gemmlowp/public/map.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2015 The Gemmlowp Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// map.h: a minimalist view-existing-buffer-as-a-matrix class,
16
// which is how gemmlowp interfaces with external matrix data.
17
18
#ifndef GEMMLOWP_PUBLIC_MAP_H_
19
#define GEMMLOWP_PUBLIC_MAP_H_
20
21
#include "../internal/common.h"
22
23
namespace gemmlowp {
24
25
// The two storage orders allowed to map buffers as matrices: ColMajor
26
// means column-major, RowMajor means row-major.
27
enum class MapOrder { ColMajor, RowMajor };
28
29
// A MatrixMap is a view of an existing buffer as a matrix. It does not own
30
// the buffer.
31
template <typename tScalar, MapOrder tOrder>
32
class MatrixMap {
33
 public:
34
  typedef tScalar Scalar;
35
  static constexpr MapOrder kOrder = tOrder;
36
37
 protected:
38
  Scalar* data_;  // not owned.
39
  int rows_, cols_, stride_;
40
41
 public:
42
  MatrixMap() : data_(nullptr), rows_(0), cols_(0), stride_(0) {}
43
  MatrixMap(Scalar* data, int rows, int cols)
44
      : data_(data),
45
        rows_(rows),
46
        cols_(cols),
47
0
        stride_(kOrder == MapOrder::ColMajor ? rows : cols) {}
48
  MatrixMap(Scalar* data, int rows, int cols, int stride)
49
0
      : data_(data), rows_(rows), cols_(cols), stride_(stride) {}
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::MatrixMap(unsigned char const*, int, int, int)
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::MatrixMap(int*, int, int, int)
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::MatrixMap(int*, int, int, int)
Unexecuted instantiation: gemmlowp::MatrixMap<int const, (gemmlowp::MapOrder)0>::MatrixMap(int const*, int, int, int)
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::MatrixMap(unsigned char const*, int, int, int)
50
  MatrixMap(const MatrixMap& other)
51
      : data_(other.data_),
52
        rows_(other.rows_),
53
        cols_(other.cols_),
54
0
        stride_(other.stride_) {}
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::MatrixMap(gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0> const&)
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::MatrixMap(gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0> const&)
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::MatrixMap(gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1> const&)
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::MatrixMap(gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1> const&)
55
56
0
  int rows() const { return rows_; }
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::rows() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::rows() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::rows() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::rows() const
57
0
  int cols() const { return cols_; }
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::cols() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::cols() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::cols() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::cols() const
58
0
  int stride() const { return stride_; }
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<int const, (gemmlowp::MapOrder)0>::stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::stride() const
59
0
  int rows_stride() const { return kOrder == MapOrder::ColMajor ? 1 : stride_; }
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::rows_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<int const, (gemmlowp::MapOrder)0>::rows_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::rows_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::rows_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::rows_stride() const
60
0
  int cols_stride() const { return kOrder == MapOrder::RowMajor ? 1 : stride_; }
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::cols_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<int const, (gemmlowp::MapOrder)0>::cols_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::cols_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::cols_stride() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::cols_stride() const
61
0
  Scalar* data() const { return data_; }
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::data() const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::data() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::data() const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::data() const
62
0
  Scalar* data(int row, int col) const {
63
0
    return data_ + row * rows_stride() + col * cols_stride();
64
0
  }
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::data(int, int) const
Unexecuted instantiation: gemmlowp::MatrixMap<int const, (gemmlowp::MapOrder)0>::data(int, int) const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::data(int, int) const
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)1>::data(int, int) const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::data(int, int) const
65
  Scalar& operator()(int row, int col) const { return *data(row, col); }
66
67
  MatrixMap block(int start_row, int start_col, int block_rows,
68
0
                  int block_cols) const {
69
0
    assert(start_row >= 0);
70
0
    assert(start_row + block_rows <= rows_);
71
0
    assert(start_col >= 0);
72
0
    assert(start_col + block_cols <= cols_);
73
74
0
    return MatrixMap(data(start_row, start_col), block_rows, block_cols,
75
0
                     stride_);
76
0
  }
Unexecuted instantiation: gemmlowp::MatrixMap<int, (gemmlowp::MapOrder)0>::block(int, int, int, int) const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)0>::block(int, int, int, int) const
Unexecuted instantiation: gemmlowp::MatrixMap<unsigned char const, (gemmlowp::MapOrder)1>::block(int, int, int, int) const
77
};
78
79
enum class VectorShape { Col, Row };
80
81
// A VectorMap is a view of an existing buffer as a vector. It does not own
82
// the buffer.
83
template <typename tScalar, VectorShape tShape>
84
class VectorMap {
85
 public:
86
  typedef tScalar Scalar;
87
  static constexpr VectorShape kShape = tShape;
88
89
 protected:
90
  Scalar* data_;  // not owned.
91
  int size_;
92
93
 public:
94
  VectorMap() : data_(nullptr), size_(0) {}
95
0
  VectorMap(Scalar* data, int size) : data_(data), size_(size) {}
Unexecuted instantiation: gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)0>::VectorMap(int const*, int)
Unexecuted instantiation: gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1>::VectorMap(int const*, int)
96
  VectorMap(const VectorMap& other) = default;
97
  VectorMap& operator=(const VectorMap& other) = default;
98
99
  int size() const { return size_; }
100
  Scalar* data() const { return data_; }
101
0
  Scalar* data(int index) const { return data_ + index; }
Unexecuted instantiation: gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)0>::data(int) const
Unexecuted instantiation: gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1>::data(int) const
102
0
  Scalar& operator()(int index) const { return *data(index); }
Unexecuted instantiation: gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)0>::operator()(int) const
Unexecuted instantiation: gemmlowp::VectorMap<int const, (gemmlowp::VectorShape)1>::operator()(int) const
103
104
  VectorMap block(int start, int len) const {
105
    assert(start >= 0);
106
    assert(start + len <= size_);
107
108
    return VectorMap(data(start), len);
109
  }
110
};
111
112
// A VectorDup is a (duplicated value) vector where all components are the same.
113
template <typename tScalar, VectorShape tShape>
114
class VectorDup {
115
 public:
116
  typedef tScalar Scalar;
117
  static constexpr VectorShape kShape = tShape;
118
119
 protected:
120
  Scalar data_;
121
  int size_;
122
123
 public:
124
  VectorDup() : data_(0), size_(0) {}
125
0
  VectorDup(Scalar data, int size) : data_(data), size_(size) {}
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>::VectorDup(int, int)
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>::VectorDup(int, int)
126
0
  VectorDup(const VectorDup& other) : data_(other.data_), size_(other.size_) {}
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>::VectorDup(gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1> const&)
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>::VectorDup(gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0> const&)
127
128
  int size() const { return size_; }
129
0
  Scalar& operator()(int) const { return data_; }
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>::operator()(int) const
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>::operator()(int) const
130
131
0
  VectorDup block(int start, int len) const {
132
0
    assert(start >= 0);
133
0
    assert(start + len <= size_);
134
135
0
    (void)start;
136
0
    return VectorDup(data_, len);
137
0
  }
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)1>::block(int, int) const
Unexecuted instantiation: gemmlowp::VectorDup<int const, (gemmlowp::VectorShape)0>::block(int, int) const
138
};
139
140
}  // namespace gemmlowp
141
142
#endif  // GEMMLOWP_PUBLIC_MAP_H_