Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/base/kaldi-error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,19 @@ void MessageLogger::HandleMessage(const LogMessageEnvelope &envelope,
KaldiGetStackTrace().c_str());
}
}
}

FatalMessageLogger::~FatalMessageLogger() KALDI_NOEXCEPT(false) {
// remove trailing '\n',
std::string str = ss_.str();
while (!str.empty() && str[str.length() - 1] == '\n')
str.resize(str.length() - 1);

// print the mesage (or send to logging handler),
MessageLogger::HandleMessage(envelope_, str.c_str());

// Should we throw exception, or abort?
switch (envelope.severity) {
switch (envelope_.severity) {
case LogMessageEnvelope::kAssertFailed:
abort(); // ASSERT_FAILED,
break;
Expand All @@ -221,6 +231,8 @@ void MessageLogger::HandleMessage(const LogMessageEnvelope &envelope,
abort();
}
break;
default:
abort();
}
}

Expand All @@ -229,7 +241,7 @@ void MessageLogger::HandleMessage(const LogMessageEnvelope &envelope,

void KaldiAssertFailure_(const char *func, const char *file,
int32 line, const char *cond_str) {
MessageLogger ml(LogMessageEnvelope::kAssertFailed, func, file, line);
FatalMessageLogger ml(LogMessageEnvelope::kAssertFailed, func, file, line);
ml.stream() << ": '" << cond_str << "' ";
}

Expand Down
20 changes: 14 additions & 6 deletions src/base/kaldi-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,27 @@ class MessageLogger {
/// 'KALDI_LOG << "Message,"',
inline std::ostream &stream() { return ss_; }

private:
protected:
/// The logging function,
static void HandleMessage(const LogMessageEnvelope &env, const char *msg);

private:
LogMessageEnvelope envelope_;
std::ostringstream ss_;
};

class FatalMessageLogger: public MessageLogger {
public:
FatalMessageLogger(LogMessageEnvelope::Severity severity,
const char *func, const char *file, int32 line):
MessageLogger(severity, func, file, line) {}

[[ noreturn ]] ~FatalMessageLogger() KALDI_NOEXCEPT(false);
};

// The definition of the logging macros,
#define KALDI_ERR \
::kaldi::MessageLogger(::kaldi::LogMessageEnvelope::kError, \
__func__, __FILE__, __LINE__).stream()
::kaldi::FatalMessageLogger(::kaldi::LogMessageEnvelope::kError, \
__func__, __FILE__, __LINE__).stream()
#define KALDI_WARN \
::kaldi::MessageLogger(::kaldi::LogMessageEnvelope::kWarning, \
__func__, __FILE__, __LINE__).stream()
Expand All @@ -140,8 +148,8 @@ class MessageLogger {

/***** KALDI ASSERTS *****/

void KaldiAssertFailure_(const char *func, const char *file,
int32 line, const char *cond_str);
[[noreturn]] void KaldiAssertFailure_(const char *func, const char *file,
int32 line, const char *cond_str);

// Note on KALDI_ASSERT and KALDI_PARANOID_ASSERT
// The original (simple) version of the code was this
Expand Down
2 changes: 1 addition & 1 deletion src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

# This should be incremented after any significant change to the configure
# script, i.e. any change affecting kaldi.mk or the build system as a whole.
CONFIGURE_VERSION=8
CONFIGURE_VERSION=9

if ! [ -x "$PWD/configure" ]; then
echo 'You must run "configure" from the src/ directory.'
Expand Down
8 changes: 3 additions & 5 deletions src/doc/build_setup.dox
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@

Changes that you might want to make to kaldi.mk after running "configure" are the following:
- Changing the debug level:
- The default (which creates the easiest-to-debug binaries) is enabled by the options "-g -O0 -DKALDI_PARANOID".
- For faster, but still debuggable, binaries, you can change -O0 to -O1
- If you won't need to debug the binaries, you can remove the "-g -O0 -DKALDI_PARANOID" options, which
will make it even faster.
- For maximum speed and no checking, you can replace the "-g -O0 -DKALDI_PARANOID" options with
- The default is "-O1"
- Easy to debug binaries can be enabled by uncommenting the options "-O0 -DKALDI_PARANOID".
- For maximum speed and no checking, you can replace the "-O0 -DKALDI_PARANOID" options with
"-O2 -DNDEBUG" or "-O3 -DNDEBUG"
- Changing the default precision
- To test algorithms in double precision (e.g. if you suspect that roundoff is affecting
Expand Down
2 changes: 1 addition & 1 deletion src/fstext/fstext-utils-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ bool GetLinearSymbolSequence(const Fst<Arc> &fst,
}


// see fstext-utils.sh for comment.
// see fstext-utils.h for comment.
template<class Arc>
void ConvertNbestToVector(const Fst<Arc> &fst,
vector<VectorFst<Arc> > *fsts_out) {
Expand Down
2 changes: 1 addition & 1 deletion src/fstext/lattice-weight.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LatticeWeightTpl {

inline void SetValue2(T f) { value2_ = f; }

LatticeWeightTpl() { }
LatticeWeightTpl(): value1_{}, value2_{} { }

LatticeWeightTpl(T a, T b): value1_(a), value2_(b) {}

Expand Down
91 changes: 47 additions & 44 deletions src/lm/mikolov-rnnlm-lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void CRnnLM::goToDelimiter(int delim, FILE *fi) {

void CRnnLM::restoreNet() { // will read whole network structure
FILE *fi;
int a, b, ver;
int a, b, ver, unused_size;
float fl;
char str[MAX_STRING];
double d;
Expand All @@ -580,7 +580,7 @@ void CRnnLM::restoreNet() { // will read whole network structure
}

goToDelimiter(':', fi);
fscanf(fi, "%d", &ver);
unused_size = fscanf(fi, "%d", &ver);
if ((ver == 4) && (version == 5)) {
/* we will solve this later.. */
} else {
Expand All @@ -590,71 +590,71 @@ void CRnnLM::restoreNet() { // will read whole network structure
}
}
goToDelimiter(':', fi);
fscanf(fi, "%d", &filetype);
unused_size = fscanf(fi, "%d", &filetype);
goToDelimiter(':', fi);
if (train_file_set == 0) {
fscanf(fi, "%s", train_file);
unused_size = fscanf(fi, "%s", train_file);
} else {
fscanf(fi, "%s", str);
unused_size = fscanf(fi, "%s", str);
}
goToDelimiter(':', fi);
fscanf(fi, "%s", valid_file);
unused_size = fscanf(fi, "%s", valid_file);
goToDelimiter(':', fi);
fscanf(fi, "%lf", &llogp);
unused_size = fscanf(fi, "%lf", &llogp);
goToDelimiter(':', fi);
fscanf(fi, "%d", &iter);
unused_size = fscanf(fi, "%d", &iter);
goToDelimiter(':', fi);
fscanf(fi, "%d", &train_cur_pos);
unused_size = fscanf(fi, "%d", &train_cur_pos);
goToDelimiter(':', fi);
fscanf(fi, "%lf", &logp);
unused_size = fscanf(fi, "%lf", &logp);
goToDelimiter(':', fi);
fscanf(fi, "%d", &anti_k);
unused_size = fscanf(fi, "%d", &anti_k);
goToDelimiter(':', fi);
fscanf(fi, "%d", &train_words);
unused_size = fscanf(fi, "%d", &train_words);
goToDelimiter(':', fi);
fscanf(fi, "%d", &layer0_size);
unused_size = fscanf(fi, "%d", &layer0_size);
goToDelimiter(':', fi);
fscanf(fi, "%d", &layer1_size);
unused_size = fscanf(fi, "%d", &layer1_size);
goToDelimiter(':', fi);
fscanf(fi, "%d", &layerc_size);
unused_size = fscanf(fi, "%d", &layerc_size);
goToDelimiter(':', fi);
fscanf(fi, "%d", &layer2_size);
unused_size = fscanf(fi, "%d", &layer2_size);
if (ver > 5) {
goToDelimiter(':', fi);
fscanf(fi, "%lld", &direct_size);
unused_size = fscanf(fi, "%lld", &direct_size);
}
if (ver > 6) {
goToDelimiter(':', fi);
fscanf(fi, "%d", &direct_order);
unused_size = fscanf(fi, "%d", &direct_order);
}
goToDelimiter(':', fi);
fscanf(fi, "%d", &bptt);
unused_size = fscanf(fi, "%d", &bptt);
if (ver > 4) {
goToDelimiter(':', fi);
fscanf(fi, "%d", &bptt_block);
unused_size = fscanf(fi, "%d", &bptt_block);
} else {
bptt_block = 10;
}
goToDelimiter(':', fi);
fscanf(fi, "%d", &vocab_size);
unused_size = fscanf(fi, "%d", &vocab_size);
goToDelimiter(':', fi);
fscanf(fi, "%d", &class_size);
unused_size = fscanf(fi, "%d", &class_size);
goToDelimiter(':', fi);
fscanf(fi, "%d", &old_classes);
unused_size = fscanf(fi, "%d", &old_classes);
goToDelimiter(':', fi);
fscanf(fi, "%d", &independent);
unused_size = fscanf(fi, "%d", &independent);
goToDelimiter(':', fi);
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
starting_alpha = d;
goToDelimiter(':', fi);
if (alpha_set == 0) {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
alpha = d;
} else {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
}
goToDelimiter(':', fi);
fscanf(fi, "%d", &alpha_divide);
unused_size = fscanf(fi, "%d", &alpha_divide);

// read normal vocabulary
if (vocab_max_size < vocab_size) {
Expand All @@ -666,11 +666,11 @@ void CRnnLM::restoreNet() { // will read whole network structure
}
goToDelimiter(':', fi);
for (a = 0; a < vocab_size; a++) {
// fscanf(fi, "%d%d%s%d", &b, &vocab[a].cn,
// unused_size = fscanf(fi, "%d%d%s%d", &b, &vocab[a].cn,
// vocab[a].word, &vocab[a].class_index);
fscanf(fi, "%d%d", &b, &vocab[a].cn);
unused_size = fscanf(fi, "%d%d", &b, &vocab[a].cn);
readWord(vocab[a].word, fi);
fscanf(fi, "%d", &vocab[a].class_index);
unused_size = fscanf(fi, "%d", &vocab[a].class_index);
// printf("%d %d %s %d\n", b, vocab[a].cn,
// vocab[a].word, vocab[a].class_index);
}
Expand All @@ -679,30 +679,30 @@ void CRnnLM::restoreNet() { // will read whole network structure
if (filetype == TEXT) {
goToDelimiter(':', fi);
for (a = 0; a < layer1_size; a++) {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
neu1[a].ac = d;
}
}
if (filetype == BINARY) {
fgetc(fi);
for (a = 0; a < layer1_size; a++) {
fread(&fl, 4, 1, fi);
unused_size = fread(&fl, 4, 1, fi);
neu1[a].ac = fl;
}
}
if (filetype == TEXT) {
goToDelimiter(':', fi);
for (b = 0; b < layer1_size; b++) {
for (a = 0; a < layer0_size; a++) {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
syn0[a + b * layer0_size].weight = d;
}
}
}
if (filetype == BINARY) {
for (b = 0; b < layer1_size; b++) {
for (a = 0; a < layer0_size; a++) {
fread(&fl, 4, 1, fi);
unused_size = fread(&fl, 4, 1, fi);
syn0[a + b * layer0_size].weight = fl;
}
}
Expand All @@ -712,14 +712,14 @@ void CRnnLM::restoreNet() { // will read whole network structure
if (layerc_size == 0) { // no compress layer
for (b = 0; b < layer2_size; b++) {
for (a = 0; a < layer1_size; a++) {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
syn1[a + b * layer1_size].weight = d;
}
}
} else { // with compress layer
for (b = 0; b < layerc_size; b++) {
for (a = 0; a < layer1_size; a++) {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
syn1[a + b * layer1_size].weight = d;
}
}
Expand All @@ -728,7 +728,7 @@ void CRnnLM::restoreNet() { // will read whole network structure

for (b = 0; b < layer2_size; b++) {
for (a = 0; a < layerc_size; a++) {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
sync[a + b * layerc_size].weight = d;
}
}
Expand All @@ -738,21 +738,21 @@ void CRnnLM::restoreNet() { // will read whole network structure
if (layerc_size == 0) { // no compress layer
for (b = 0; b < layer2_size; b++) {
for (a = 0; a < layer1_size; a++) {
fread(&fl, 4, 1, fi);
unused_size = fread(&fl, 4, 1, fi);
syn1[a + b * layer1_size].weight = fl;
}
}
} else { // with compress layer
for (b = 0; b < layerc_size; b++) {
for (a = 0; a < layer1_size; a++) {
fread(&fl, 4, 1, fi);
unused_size = fread(&fl, 4, 1, fi);
syn1[a + b * layer1_size].weight = fl;
}
}

for (b = 0; b < layer2_size; b++) {
for (a = 0; a < layerc_size; a++) {
fread(&fl, 4, 1, fi);
unused_size = fread(&fl, 4, 1, fi);
sync[a + b * layerc_size].weight = fl;
}
}
Expand All @@ -762,24 +762,27 @@ void CRnnLM::restoreNet() { // will read whole network structure
goToDelimiter(':', fi); // direct conenctions
long long aa;
for (aa = 0; aa < direct_size; aa++) {
fscanf(fi, "%lf", &d);
unused_size = fscanf(fi, "%lf", &d);
syn_d[aa] = d;
}
}
if (filetype == BINARY) {
long long aa;
for (aa = 0; aa < direct_size; aa++) {
fread(&fl, 4, 1, fi);
unused_size = fread(&fl, 4, 1, fi);
syn_d[aa] = fl;

/*fread(&si, 2, 1, fi);
/*unused_size = fread(&si, 2, 1, fi);
fl = si/(float)(4*256);
syn_d[aa] = fl;*/
}
}

saveWeights();

// idiom to "use" an unused variable
(void) unused_size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might be able to achieve the same thing by declaration
volatile in unused;
but your solution might be better (could get optimized better), however at the cost that you have remember to "use" the unused variable in each path through the code.


fclose(fi);
}

Expand Down
2 changes: 1 addition & 1 deletion src/makefiles/android_openblas.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $(error Android build does not support compiling with $(CXX).
Supported compilers: clang++)
endif

CXXFLAGS = -std=c++11 -I.. -I$(OPENFSTINC) $(EXTRA_CXXFLAGS) \
CXXFLAGS = -std=c++11 -I.. -I$(OPENFSTINC) -O1 $(EXTRA_CXXFLAGS) \
-Wall -Wno-sign-compare -Wno-unused-local-typedefs \
-Wno-deprecated-declarations -Winit-self -Wno-mismatched-tags \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
Expand Down
2 changes: 1 addition & 1 deletion src/makefiles/cygwin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ifndef OPENFSTLIBS
$(error OPENFSTLIBS not defined.)
endif

CXXFLAGS = -std=c++11 -U__STRICT_ANSI__ -I.. -I$(OPENFSTINC) $(EXTRA_CXXFLAGS) \
CXXFLAGS = -std=c++11 -U__STRICT_ANSI__ -I.. -I$(OPENFSTINC) -O1 $(EXTRA_CXXFLAGS) \
-Wall -Wno-sign-compare -Wno-unused-local-typedefs \
-Wno-deprecated-declarations -Winit-self \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
Expand Down
2 changes: 1 addition & 1 deletion src/makefiles/darwin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ifndef OPENFSTLIBS
$(error OPENFSTLIBS not defined.)
endif

CXXFLAGS = -std=c++11 -I.. -I$(OPENFSTINC) $(EXTRA_CXXFLAGS) \
CXXFLAGS = -std=c++11 -I.. -I$(OPENFSTINC) -O1 $(EXTRA_CXXFLAGS) \
-Wall -Wno-sign-compare -Wno-unused-local-typedefs \
-Wno-deprecated-declarations -Winit-self \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
Expand Down
Loading