Skip to content
Merged
4 changes: 2 additions & 2 deletions src/base/kaldi-math.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ int32 RoundUpToNearestPowerOfTwo(int32 n) {
static std::mutex _RandMutex;

int Rand(struct RandomState* state) {
#ifdef _MSC_VER
// On Windows, just call Rand()
#if defined(_MSC_VER) || defined(__CYGWIN__)
// On Windows and Cygwin, just call Rand()
return rand();
#else
if (state) {
Expand Down
2 changes: 2 additions & 0 deletions src/base/kaldi-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ std::string CharToString(const char &c) {
void Sleep(float seconds) {
#if defined(_MSC_VER) || defined(MINGW)
::Sleep(static_cast<int>(seconds * 1000.0));
#elif defined(__CYGWIN__)
sleep(static_cast<int>(seconds));
#else
usleep(static_cast<int>(seconds * 1000000.0));
#endif
Expand Down
13 changes: 3 additions & 10 deletions src/base/kaldi-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@
#endif
#endif

#ifdef _MSC_VER
# define KALDI_MEMALIGN(align, size, pp_orig) \
(*(pp_orig) = _aligned_malloc(size, align))
# define KALDI_MEMALIGN_FREE(x) _aligned_free(x)
#else
# define KALDI_MEMALIGN(align, size, pp_orig) \
(!posix_memalign(pp_orig, align, size) ? *(pp_orig) : NULL)
# define KALDI_MEMALIGN_FREE(x) free(x)
#endif

#ifdef __ICC
#pragma warning(disable: 383) // ICPC remark we don't want.
#pragma warning(disable: 810) // ICPC remark we don't want.
Expand Down Expand Up @@ -136,6 +126,9 @@ template<> class KaldiCompileTimeAssert<true> {

#ifdef _MSC_VER
#define KALDI_STRCASECMP _stricmp
#elif defined(__CYGWIN__)
#include <strings.h>
#define KALDI_STRCASECMP strcasecmp
#else
#define KALDI_STRCASECMP strcasecmp
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/cudamatrix/cu-matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void CuMatrix<Real>::Destroy() {
} else
#endif
{
if (this->data_ != NULL) KALDI_MEMALIGN_FREE(this->data_);
if (this->data_ != NULL) free(this->data_);
}
this->data_ = NULL;
this->num_rows_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/cudamatrix/cu-packed-matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void CuPackedMatrix<Real>::Destroy() {
} else
#endif
{
if (this->data_ != NULL) KALDI_MEMALIGN_FREE(this->data_);
if (this->data_ != NULL) free(this->data_);
}
this->data_ = NULL;
this->num_rows_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/cudamatrix/cu-vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ void CuVector<Real>::Destroy() {
} else
#endif
{
if (this->data_ != NULL) KALDI_MEMALIGN_FREE(this->data_);
if (this->data_ != NULL) free(this->data_);
}
this->data_ = NULL;
this->dim_ = 0;
Expand Down
9 changes: 5 additions & 4 deletions src/fstext/lattice-weight-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ typedef CompactLatticeWeightCommonDivisorTpl<LatticeWeight, int32>


LatticeWeight RandomLatticeWeight() {
if (kaldi::Rand() % 3 == 0) {
int tmp = kaldi::Rand() % 4;
if (tmp == 0) {
return LatticeWeight::Zero();
} else if (kaldi::Rand() % 3 == 0) {
} else if (tmp == 1) {
return LatticeWeight( 1, 2); // sometimes return special values..
} else if (kaldi::Rand() % 3 == 0) {
} else if (tmp == 2) {
return LatticeWeight( 2, 1); // this tests more thoroughly certain properties...
} else {
return LatticeWeight( 100 * kaldi::RandGauss(), 100 * kaldi::RandGauss());
Expand Down Expand Up @@ -107,7 +108,7 @@ void LatticeWeightTest() {
s1 << l1;
std::istringstream s2(s1.str());
s2 >> l2;
KALDI_ASSERT(ApproxEqual(l1, l2));
KALDI_ASSERT(ApproxEqual(l1, l2, 0.001));
std::cout << s1.str() << '\n';
{
std::ostringstream s1b;
Expand Down
4 changes: 2 additions & 2 deletions src/makefiles/cygwin.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ ifndef OPENFSTLIBS
$(error OPENFSTLIBS not defined.)
endif

CXXFLAGS = -std=c++11 -I.. -I$(OPENFSTINC) $(EXTRA_CXXFLAGS) \
CXXFLAGS = -std=c++11 -U__STRICT_ANSI__ -I.. -I$(OPENFSTINC) $(EXTRA_CXXFLAGS) \
-Wall -Wno-sign-compare -Wno-unused-local-typedefs \
-Wno-deprecated-declarations -Winit-self \
-DKALDI_DOUBLEPRECISION=$(DOUBLE_PRECISION) \
-DHAVE_CLAPACK -I../../tools/CLAPACK/ \
-msse -msse2 \
-msse -msse2 -O -Wa,-mbig-obj \
-g # -O0 -DKALDI_PARANOID

ifeq ($(KALDI_FLAVOR), dynamic)
Expand Down
17 changes: 7 additions & 10 deletions src/matrix/kaldi-matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ void MatrixBase<Real>::Invert(Real *log_det, Real *det_sign,
KaldiBlasInt result = -1;
KaldiBlasInt l_work = std::max<KaldiBlasInt>(1, N);
Real *p_work;
void *temp;
if ((p_work = static_cast<Real*>(
KALDI_MEMALIGN(16, sizeof(Real)*l_work, &temp))) == NULL) {
aligned_alloc(16, sizeof(Real)*l_work))) == NULL) {
delete[] pivot;
throw std::bad_alloc();
}
Expand All @@ -75,7 +74,7 @@ void MatrixBase<Real>::Invert(Real *log_det, Real *det_sign,
if (det_sign) *det_sign = 0;
delete[] pivot;
#ifndef HAVE_ATLAS
KALDI_MEMALIGN_FREE(p_work);
free(p_work);
#endif
return;
}
Expand Down Expand Up @@ -103,7 +102,7 @@ void MatrixBase<Real>::Invert(Real *log_det, Real *det_sign,
if (inverse_needed) clapack_Xgetri2(&M, data_, &LDA, pivot, p_work, &l_work,
&result);
delete[] pivot;
KALDI_MEMALIGN_FREE(p_work);
free(p_work);
#else
if (inverse_needed)
clapack_Xgetri(num_rows_, data_, stride_, pivot, &result);
Expand Down Expand Up @@ -710,9 +709,8 @@ void MatrixBase<Real>::LapackGesvd(VectorBase<Real> *s, MatrixBase<Real> *U_in,

l_work = static_cast<KaldiBlasInt>(work_query);
Real *p_work;
void *temp;
if ((p_work = static_cast<Real*>(
KALDI_MEMALIGN(16, sizeof(Real)*l_work, &temp))) == NULL)
aligned_alloc(16, sizeof(Real)*l_work))) == NULL)
throw std::bad_alloc();

// perform svd
Expand All @@ -729,7 +727,7 @@ void MatrixBase<Real>::LapackGesvd(VectorBase<Real> *s, MatrixBase<Real> *U_in,
if (result != 0) {
KALDI_WARN << "CLAPACK sgesvd_ : some weird convergence not satisfied";
}
KALDI_MEMALIGN_FREE(p_work);
free(p_work);
}

#endif
Expand Down Expand Up @@ -794,7 +792,6 @@ inline void Matrix<Real>::Init(const MatrixIndexT rows,
MatrixIndexT skip, stride;
size_t size;
void *data; // aligned memory block
void *temp; // memory block to be really freed

// compute the size of skip and real cols
skip = ((16 / sizeof(Real)) - cols % (16 / sizeof(Real)))
Expand All @@ -804,7 +801,7 @@ inline void Matrix<Real>::Init(const MatrixIndexT rows,
* sizeof(Real);

// allocate the memory and set the right dimensions and parameters
if (NULL != (data = KALDI_MEMALIGN(16, size, &temp))) {
if (NULL != (data = aligned_alloc(16, size))) {
MatrixBase<Real>::data_ = static_cast<Real *> (data);
MatrixBase<Real>::num_rows_ = rows;
MatrixBase<Real>::num_cols_ = cols;
Expand Down Expand Up @@ -1127,7 +1124,7 @@ template<typename Real>
void Matrix<Real>::Destroy() {
// we need to free the data block if it was defined
if (NULL != MatrixBase<Real>::data_)
KALDI_MEMALIGN_FREE( MatrixBase<Real>::data_);
free( MatrixBase<Real>::data_);
MatrixBase<Real>::data_ = NULL;
MatrixBase<Real>::num_rows_ = MatrixBase<Real>::num_cols_
= MatrixBase<Real>::stride_ = 0;
Expand Down
5 changes: 2 additions & 3 deletions src/matrix/kaldi-vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ inline void Vector<Real>::Init(const MatrixIndexT dim) {
}
MatrixIndexT size;
void *data;
void *free_data;

size = dim * sizeof(Real);

if ((data = KALDI_MEMALIGN(16, size, &free_data)) != NULL) {
if ((data = aligned_alloc(16, size)) != NULL) {
this->data_ = static_cast<Real*> (data);
this->dim_ = dim;
} else {
Expand Down Expand Up @@ -279,7 +278,7 @@ template<typename Real>
void Vector<Real>::Destroy() {
/// we need to free the data block if it was defined
if (this->data_ != NULL)
KALDI_MEMALIGN_FREE(this->data_);
free(this->data_);
this->data_ = NULL;
this->dim_ = 0;
}
Expand Down
5 changes: 2 additions & 3 deletions src/matrix/packed-matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ inline void PackedMatrix<Real>::Init(MatrixIndexT r) {
}

void *data; // aligned memory block
void *temp;

if ((data = KALDI_MEMALIGN(16, size * sizeof(Real), &temp)) != NULL) {
if ((data = aligned_alloc(16, size * sizeof(Real))) != NULL) {
this->data_ = static_cast<Real *> (data);
this->num_rows_ = r;
} else {
Expand Down Expand Up @@ -226,7 +225,7 @@ Real PackedMatrix<Real>::Trace() const {
template<typename Real>
void PackedMatrix<Real>::Destroy() {
// we need to free the data block if it was defined
if (data_ != NULL) KALDI_MEMALIGN_FREE(data_);
if (data_ != NULL) free(data_);
data_ = NULL;
num_rows_ = 0;
}
Expand Down
7 changes: 3 additions & 4 deletions src/matrix/sp-matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ void SpMatrix<Real>::Invert(Real *logdet, Real *det_sign, bool need_inverse) {
KaldiBlasInt rows = static_cast<int>(this->num_rows_);
KaldiBlasInt* p_ipiv = new KaldiBlasInt[rows];
Real *p_work; // workspace for the lapack function
void *temp;
if ((p_work = static_cast<Real*>(
KALDI_MEMALIGN(16, sizeof(Real) * rows, &temp))) == NULL) {
aligned_alloc(16, sizeof(Real) * rows))) == NULL) {
delete[] p_ipiv;
throw std::bad_alloc();
}
Expand Down Expand Up @@ -277,7 +276,7 @@ void SpMatrix<Real>::Invert(Real *logdet, Real *det_sign, bool need_inverse) {
}
if (!need_inverse) {
delete [] p_ipiv;
KALDI_MEMALIGN_FREE(p_work);
free(p_work);
return; // Don't need what is computed next.
}
// NOTE: Even though "U" is for upper, lapack assumes column-wise storage
Expand All @@ -292,7 +291,7 @@ void SpMatrix<Real>::Invert(Real *logdet, Real *det_sign, bool need_inverse) {
}

delete [] p_ipiv;
KALDI_MEMALIGN_FREE(p_work);
free(p_work);
}
#else
// in the ATLAS case, these are not implemented using a library and we back off to something else.
Expand Down
2 changes: 1 addition & 1 deletion src/nnetbin/cuda-gpu-available.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void TestGpuComputation() {

int main(int argc, char *argv[]) try {
char hostname[100] = "UNKNOWN-HOSTNAME";
#ifndef _MSC_VER
#if !defined(_MSC_VER) && !defined(__CYGWIN__)
if (gethostname(hostname, 100)) {
KALDI_WARN << "Cannot get hostname, " << strerror(errno);
}
Expand Down
8 changes: 5 additions & 3 deletions src/util/kaldi-io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "util/kaldi-holder.h"
#include "util/kaldi-pipebuf.h"
#include "util/kaldi-table.h" // for Classify{W,R}specifier
#include <stdio.h>
#include <stdlib.h>

#ifdef KALDI_CYGWIN_COMPAT
#include "util/kaldi-cygwin-io-inl.h"
Expand All @@ -34,7 +36,7 @@
#define MapOsPath(x) x
#endif // KALDI_CYGWIN_COMPAT

#ifdef _MSC_VER
#ifdef _MSC_VER
static FILE *popen(const char* command, const char* mode) {
#ifdef KALDI_CYGWIN_COMPAT
return kaldi::CygwinCompatPopen(command, mode);
Expand Down Expand Up @@ -280,7 +282,7 @@ class PipeOutputImpl: public OutputImplBase {
KALDI_ASSERT(wxfilename.length() != 0 && wxfilename[0] == '|'); // should
// start with '|'
std::string cmd_name(wxfilename, 1);
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__CYGWIN__)
f_ = popen(cmd_name.c_str(), (binary ? "wb" : "w"));
#else
f_ = popen(cmd_name.c_str(), "w");
Expand Down Expand Up @@ -457,7 +459,7 @@ class PipeInputImpl: public InputImplBase {
KALDI_ASSERT(rxfilename.length() != 0 &&
rxfilename[rxfilename.length()-1] == '|'); // should end with '|'
std::string cmd_name(rxfilename, 0, rxfilename.length()-1);
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__CYGWIN__)
f_ = popen(cmd_name.c_str(), (binary ? "rb" : "r"));
#else
f_ = popen(cmd_name.c_str(), "r");
Expand Down
2 changes: 1 addition & 1 deletion src/util/parse-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ParseOptions : public OptionsItf {
explicit ParseOptions(const char *usage) :
print_args_(true), help_(false), usage_(usage), argc_(0), argv_(NULL),
prefix_(""), other_parser_(NULL) {
#ifndef _MSC_VER // This is just a convenient place to set the stderr to line
#if !defined(_MSC_VER) && !defined(__CYGWIN__) // This is just a convenient place to set the stderr to line
setlinebuf(stderr); // buffering mode, since it's called at program start.
#endif // This helps ensure different programs' output is not mixed up.
RegisterStandard("config", &config_, "Configuration file to read (this "
Expand Down