-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmisc.h
99 lines (82 loc) · 3.02 KB
/
misc.h
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
#ifndef MISC_H
#define MISC_H
#include <vector>
#include <iostream>
#include <stdio.h>
#include <cassert>
#include <fstream>
#define LINE_SIZE 1
#define CUDA_ERR { \
cudaError_t err; \
if ((err = cudaGetLastError()) != cudaSuccess) { \
printf("CUDA error: %d : %s : %s, line %d\n", err, cudaGetErrorString(err), __FILE__, __LINE__); \
exit(1); \
} \
}
#define MAX_SMEM 98304
template<typename T>
void create_dummy_weights_lstm(std::vector<T *> &weights, uint32_t input, uint32_t hidden) {
// DUMMY INPUT WEIGHTS
weights.push_back((T *)malloc(sizeof(T) * input * hidden));
weights.push_back((T *)malloc(sizeof(T) * input * hidden));
weights.push_back((T *)malloc(sizeof(T) * input * hidden));
weights.push_back((T *)malloc(sizeof(T) * input * hidden));
// DUMMY HIDDEN WEIGHTS
weights.push_back((T *)malloc(sizeof(T) * hidden * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden * hidden));
// DUMMY BIASES
weights.push_back((T *)malloc(sizeof(T) * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden));
uint32_t i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < input * hidden; j++) {
weights.at(i)[j] = 1 / 1024.;
}
}
for (i = 4; i < 8; i++) {
for (j = 0; j < hidden * hidden; j++) {
weights.at(i)[j] = 1 / 1024.;
}
}
for (i = 8; i < 12; i++) {
for (j = 0; j < hidden; j++) {
weights.at(i)[j] = 0.5;
}
}
}
template<typename T>
void create_dummy_weights_gru(std::vector<T *> &weights, uint32_t input, uint32_t hidden) {
// DUMMY INPUT WEIGHTS
weights.push_back((T *)malloc(sizeof(T) * input * hidden));
weights.push_back((T *)malloc(sizeof(T) * input * hidden));
weights.push_back((T *)malloc(sizeof(T) * input * hidden));
// DUMMY HIDDEN WEIGHTS
weights.push_back((T *)malloc(sizeof(T) * hidden * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden * hidden));
// DUMMY BIASES
weights.push_back((T *)malloc(sizeof(T) * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden));
weights.push_back((T *)malloc(sizeof(T) * hidden));
uint32_t i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < input * hidden; j++) {
weights.at(i)[j] = 1./256.;
}
}
for (i = 3; i < 6; i++) {
for (j = 0; j < hidden * hidden; j++) {
weights.at(i)[j] = 1./256.;
}
}
for (i = 7; i < 9; i++) {
for (j = 0; j < hidden; j++) {
weights.at(i)[j] = 0.5;
}
}
}
#endif