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
|
#pragma once
#include "../aligned.h"
#include "../tile/access.h"
#include <random>
// Yes both due to debacle.
#include <stdint.h>
#include <cstdint>
namespace intgemm {
struct TestMatrices8 {
typedef Access<RowMajorAccess<int8_t>, ColMajorAccess<int8_t>, RowMajorAccess<int32_t> > AccessT;
explicit TestMatrices8(Tile shape_in) :
shape(shape_in),
A(shape.A_rows * shape.inner),
B(shape.inner * shape.B_cols),
C(shape.A_rows * shape.B_cols) {
std::mt19937 gen;
std::uniform_int_distribution<int8_t> dist(-127,127);
for (int8_t &it : A) it = dist(gen);
for (int8_t &it : B) it = dist(gen);
// C is uninitialized.
}
AccessT Accessor() {
return AccessT(
RowMajorAccess<int8_t>(A.begin(), shape.inner),
ColMajorAccess<int8_t>(B.begin(), shape.inner),
RowMajorAccess<int32_t>(C.begin(), shape.B_cols));
}
Tile shape;
AlignedVector<int8_t> A;
AlignedVector<int8_t> B;
// Uninitialized; for using tests to write to.
AlignedVector<int32_t> C;
};
struct TestMatricesUnquantizeAndWriteRowMajorAccess {
typedef Access<RowMajorAccess<int8_t>, ColMajorAccess<int8_t>, UnquantizeAndWriteRowMajorAccess<float>> AccessT;
explicit TestMatricesUnquantizeAndWriteRowMajorAccess(Tile shape_in, float unquant_mult) :
shape(shape_in),
A(shape.A_rows * shape.inner),
B(shape.inner * shape.B_cols),
C(shape.A_rows * shape.B_cols),
unquant_mult_(unquant_mult) {
std::mt19937 gen;
std::uniform_int_distribution<int8_t> dist(-127,127);
for (int8_t &it : A) it = dist(gen);
for (int8_t &it : B) it = dist(gen);
// C is uninitialized.
}
AccessT Accessor() {
return AccessT(
RowMajorAccess<int8_t>(A.begin(), shape.inner),
ColMajorAccess<int8_t>(B.begin(), shape.inner),
UnquantizeAndWriteRowMajorAccess<float>(C.begin(), shape.B_cols, {unquant_mult_}));
}
Tile shape;
AlignedVector<int8_t> A;
AlignedVector<int8_t> B;
// Uninitialized; for using tests to write to.
AlignedVector<float> C;
private:
float unquant_mult_;
};
} // namespace intgemm
|