-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHELPER CODE.cpp
More file actions
163 lines (120 loc) · 8 KB
/
HELPER CODE.cpp
File metadata and controls
163 lines (120 loc) · 8 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
** Count flop of SpGEMM between A and B in CSC format
**/
// For some reason expect CSC, CSC?
long long int get_flop(csr_matrix & A, csr_matrix & B) {
//(const CSC<IT,NT> & A, const CSC<IT,NT> & B, IT *maxnnzc)
long long int flop = 0; // total flop (multiplication) needed to generate C
int *maxnnzc = my_malloc<int>(B.cols);
#pragma omp parallel
{
long long int tflop=0; //thread private flop
#pragma omp for
for (int i=0; i < B.cols; ++i) { // for all columns of B
long long int locmax = 0;
for (int j = B.IA[i]; j < B.IA[i+1]; ++j) { // For all the nonzeros of the inth column
int inner = B.JA[j]; // get the row id of B (or column id of A)
int npins = A.IA[inner+1] - A.IA[inner]; // get the number of nonzeros in A's corresponding column
locmax += npins;
}
maxnnzc[i] = locmax;
tflop += locmax;
}
#pragma omp critical
{
flop += tflop;
}
}
my_free<int>(maxnnzc);
return flop * 2;
}
void make_empty()
{
if(nnz > 0) {
my_free<IT>(colids);
my_free<NT>(values);
nnz = 0;
}
if(rows > 0) {
my_free<IT>(rowptr);
rows = 0;
}
cols = 0;
}
/*
* Symbolic phase for Hash SpGEMM.
*/
template <class IT, class NT>
tore::CSR, Store::CSC,
void inference_csr_csc(grb::Matrix<VT> * X[2], grb::Matrix<VT> * W[][2], grb::Matrix<VT> * Y[2],
const int layers, const double bias, struct hashes<IT> &private_hash) {
// Write this algorithm using graphBlas structures (!)
inline void hash_symbolic_kernel(const IT *arpt, const IT *acol, const IT *brpt, const IT *bcol, BIN<IT, NT> &bin)
{
#pragma omp parallel
{
IT tid = omp_get_thread_num();
IT start_row = bin.rows_offset[tid];
IT end_row = bin.rows_offset[tid + 1];
IT *check = bin.local_hash_table_id[tid];
for (IT i = start_row; i < end_row; ++i) {
IT nz = 0;
IT bid = bin.bin_id[i];
if (bid > 0) {
IT ht_size = MIN_HT_S << (bid - 1); // determine hash table size for i-th row
for (IT j = 0; j < ht_size; ++j) { // initialize hash table
check[j] = -1;
}
for (IT j = arpt[i]; j < arpt[i + 1]; ++j) {
IT t_acol = acol[j];
for (IT k = brpt[t_acol]; k < brpt[t_acol + 1]; ++k) {
IT key = bcol[k];
IT hash = (key * HASH_SCAL) & (ht_size - 1);
while (1) { // Loop for hash probing
if (check[hash] == key) { // if the key is already inserted, it's ok
break;
}
else if (check[hash] == -1) { // if the key has not been inserted yet, then it's added.
check[hash] = key;
nz++;
break;
}
else { // linear probing: check next entry
hash = (hash + 1) & (ht_size - 1); //hash = (hash + 1) % ht_size
}
}
}
}
}
bin.row_nz[i] = nz;
}
}
}
//////////////////////
How it works now?
1.
:/media/Data/Filip-Pawlowski/graph-challenge/INPUTS$ ./built_with_limits.py "WEIGHTS-HPEC/neuron1024/*-l?.tsv" 20 20
2.
f80050752@f80050752-HP-EliteBook-820-G2:/media/Data/Filip-Pawlowski/graph-challenge/INPUTS$ ./transpose-mnist.py 9 20 20
3.
offset = 800
f80050752@f80050752-HP-EliteBook-820-G2:/media/Data/Filip-Pawlowski/graph-challenge/INPUTS$ ./built_with_limits.py "MNIST-HPEC/sparse-images-1024.tsv" 2 20
4.
Permute the weight matrices (!)
I mean, partition
f80050752@f80050752-HP-EliteBook-820-G2:/media/Data/Filip-Pawlowski/graph-challenge/PARTITIONING/mondriaan-master/tools$ ./Mondriaan ../../../INPUTS/WEIGHTS-HPEC/neuron1024/test_20_20/n1024-l1.mtx 2 0.03
but I actually made a batch for this!
f80050752@f80050752-HP-EliteBook-820-G2:/media/Data/Filip-Pawlowski/graph-challenge/PARTITIONING/mondriaan-master/tools$ ./mondriaan_loop.py 9
but first setup the name of the folder (!)
Run this 20 by 20 weight matrices on input
in C
in Python
Compare if results match
=====================================
COMPARE RESULTS
its much easier to test the code just by changing the input ... in that way we can test MANY different cases.... (scenarios)
TODO:
- makes sure this works for (2 and more) processors
- maybe make input "basically" dense --- should make it easier to find the error?
- after the error is found, make a safety check, backup the code, call it milestone 1 achived, and move on to writing mroe efficient code OR potentially, benchmark the current solution (!)