1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#pragma once
#include "../types.h"
namespace intgemm {
// See also: RegisterRowMajorAccess is RowMajorAccess<Register> but without the
// compiler warning. That is defined in dot.h.
template <class T> class RowMajorAccess {
public:
typedef T Content;
RowMajorAccess(Content *data, Index cols)
: data_(data), cols_(cols) {}
RowMajorAccess<Content> Add(Index row, Index col) const {
return RowMajorAccess<Content>(data_ + row * cols_ + col, cols_);
}
const Content &Front() const { return *data_; }
Content &Front() { return *data_; }
private:
Content *data_;
Index cols_;
};
template <class T> class ColMajorAccess {
public:
typedef T Content;
ColMajorAccess(Content *data, Index rows)
: data_(data), rows_(rows) {}
ColMajorAccess<Content> Add(Index row, Index col) const {
return ColMajorAccess<Content>(data_ + row + col * rows_, rows_);
}
const Content &Front() const { return *data_; }
Content &Front() { return *data_; }
private:
Content *data_;
Index rows_;
};
template <class AT, class BT, class CT> class Access {
public:
typedef AT A;
typedef BT B;
typedef CT C;
typedef typename A::Content AContent;
typedef typename B::Content BContent;
typedef typename C::Content CContent;
Access(A a, B b, C c) : a_(a), b_(b), c_(c) {}
Access AAdd(Index row, Index col) const {
return Access(a_.Add(row, col), b_, c_);
}
Access BAdd(Index row, Index col) const {
return Access(a_, b_.Add(row, col), c_);
}
Access CAdd(Index row, Index col) const {
return Access(a_, b_, c_.Add(row, col));
}
AContent &AFront() { return a_.Front(); }
const AContent &AFront() const { return a_.Front(); }
BContent &BFront() { return b_.Front(); }
const BContent &BFront() const { return b_.Front(); }
CContent &CFront() { return c_.Front(); }
const CContent &CFront() const { return c_.Front(); }
private:
A a_;
B b_;
C c_;
};
} // namespace intgemm
|