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
|
#ifndef NERV_FASTNN_MODELSYNC_H
#define NERV_FASTNN_MODELSYNC_H
#define STRLEN 1024
#include "../threads/lib/THThread.h"
#include "matrix/matrix.h"
#include "stdlib.h"
#include "stdbool.h"
typedef struct NnetParallelOptions_
{
int num_threads;
int merge_size;
int num_merge;
int num_procs;
int threadid;
int myid;
int thread_level;
char merge_func[STRLEN];
char log_file[STRLEN];
} NnetParallelOptions;
typedef struct ModelSync_
{
THMutex *model_mutex;
THMutex *state_mutex;
bool initialized_;
int dim_;
int pos_;
float *data_;
float *free_data_;
int refcount;
int threadcount;
}ModelSync;
ModelSync *ModelSync_new(void);
ModelSync *ModelSync_newWithId(long id);
int ModelSync_free(ModelSync *self);
long ModelSync_id(ModelSync *self);
int ModelSync_lockmodel(ModelSync *self);
int ModelSync_unlockmodel(ModelSync *self);
int ModelSync_lockstate(ModelSync *self);
int ModelSync_unlockstate(ModelSync *self);
int ModelSync_initBuffer(ModelSync *self);
int ModelSync_weightfromd(ModelSync *self, Matrix *dm);
int ModelSync_weighttod(ModelSync *self, Matrix *dm);
int ModelSync_threadcount(ModelSync *self);
void ModelSync_syncinc(ModelSync *self);
void ModelSync_syncdec(ModelSync *self);
typedef struct Xent_
{
size_t frames_;
size_t correct_;
double loss_;
double entropy_;
int refcount;
} Xent;
Xent* Xent_new();
Xent* Xent_newWithId(long id);
Xent* Xent_newWithParm(size_t frames_, size_t correct_, double loss_, double entropy_);
long Xent_id(Xent *xent);
Xent* Xent_add(Xent *a, Xent *b);
void Xent_free(Xent *xent);
typedef struct Mse_
{
size_t frames_;
double loss_;
int refcount;
} Mse;
Mse* Mse_new();
Mse* Mse_newWithId(long id);
Mse* Mse_newWithParm(size_t frames_, double loss_);
long Mse_id(Mse *mse);
Mse* Mse_add(Mse *a, Mse *b);
void Mse_free(Mse *mse);
typedef struct NnetUpdateState_
{
int num_utter;
int num_nolabel;
int num_other_error;
long total_frames;
Xent xent;
Mse mse;
} NnetUpdateState;
typedef struct GlobalOption_
{
int batch_size;
float lrate;
bool bp;
char tr_scp[STRLEN];
char cv_scp[STRLEN];
char transf[STRLEN];
char network[STRLEN];
int refcount;
}GlobalOption;
GlobalOption* GlobalOption_new();
GlobalOption* GlobalOption_newWithParm(int batch_size, float lrate, bool bp, const char *tr_scp, const char *cv_scp, const char *transf, const char *network);
GlobalOption* GlobalOption_newWithId(long id);
long GlobalOption_id(GlobalOption *option);
void GlobalOption_free(GlobalOption *option);
#endif
|