diff --git a/src/base/kaldi-math.cc b/src/base/kaldi-math.cc index cf06875030b..991e46a590c 100644 --- a/src/base/kaldi-math.cc +++ b/src/base/kaldi-math.cc @@ -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) { diff --git a/src/base/kaldi-utils.cc b/src/base/kaldi-utils.cc index 1ae1dc0b758..432da426bc3 100644 --- a/src/base/kaldi-utils.cc +++ b/src/base/kaldi-utils.cc @@ -45,6 +45,8 @@ std::string CharToString(const char &c) { void Sleep(float seconds) { #if defined(_MSC_VER) || defined(MINGW) ::Sleep(static_cast(seconds * 1000.0)); +#elif defined(__CYGWIN__) + sleep(static_cast(seconds)); #else usleep(static_cast(seconds * 1000000.0)); #endif diff --git a/src/base/kaldi-utils.h b/src/base/kaldi-utils.h index bd2da25dce7..ad606b963f4 100644 --- a/src/base/kaldi-utils.h +++ b/src/base/kaldi-utils.h @@ -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. @@ -136,6 +126,9 @@ template<> class KaldiCompileTimeAssert { #ifdef _MSC_VER #define KALDI_STRCASECMP _stricmp +#elif defined(__CYGWIN__) +#include +#define KALDI_STRCASECMP strcasecmp #else #define KALDI_STRCASECMP strcasecmp #endif diff --git a/src/cudamatrix/cu-matrix.cc b/src/cudamatrix/cu-matrix.cc index 34290561cc5..20bc46e8154 100644 --- a/src/cudamatrix/cu-matrix.cc +++ b/src/cudamatrix/cu-matrix.cc @@ -101,7 +101,7 @@ void CuMatrix::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; diff --git a/src/cudamatrix/cu-packed-matrix.cc b/src/cudamatrix/cu-packed-matrix.cc index 64f8afe0616..ad2a5694e18 100644 --- a/src/cudamatrix/cu-packed-matrix.cc +++ b/src/cudamatrix/cu-packed-matrix.cc @@ -91,7 +91,7 @@ void CuPackedMatrix::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; diff --git a/src/cudamatrix/cu-vector.cc b/src/cudamatrix/cu-vector.cc index f85d20d37f1..08417c8fffb 100644 --- a/src/cudamatrix/cu-vector.cc +++ b/src/cudamatrix/cu-vector.cc @@ -1015,7 +1015,7 @@ void CuVector::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; diff --git a/src/fstext/lattice-weight-test.cc b/src/fstext/lattice-weight-test.cc index 8bcbeb4eba3..ae768e711f7 100644 --- a/src/fstext/lattice-weight-test.cc +++ b/src/fstext/lattice-weight-test.cc @@ -34,11 +34,12 @@ typedef CompactLatticeWeightCommonDivisorTpl 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()); @@ -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; diff --git a/src/makefiles/cygwin.mk b/src/makefiles/cygwin.mk index c58cd3a42da..d2b9c0e6474 100644 --- a/src/makefiles/cygwin.mk +++ b/src/makefiles/cygwin.mk @@ -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) diff --git a/src/matrix/kaldi-matrix.cc b/src/matrix/kaldi-matrix.cc index fcfe0616b64..d24a29556f7 100644 --- a/src/matrix/kaldi-matrix.cc +++ b/src/matrix/kaldi-matrix.cc @@ -50,9 +50,8 @@ void MatrixBase::Invert(Real *log_det, Real *det_sign, KaldiBlasInt result = -1; KaldiBlasInt l_work = std::max(1, N); Real *p_work; - void *temp; if ((p_work = static_cast( - KALDI_MEMALIGN(16, sizeof(Real)*l_work, &temp))) == NULL) { + aligned_alloc(16, sizeof(Real)*l_work))) == NULL) { delete[] pivot; throw std::bad_alloc(); } @@ -75,7 +74,7 @@ void MatrixBase::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; } @@ -103,7 +102,7 @@ void MatrixBase::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); @@ -710,9 +709,8 @@ void MatrixBase::LapackGesvd(VectorBase *s, MatrixBase *U_in, l_work = static_cast(work_query); Real *p_work; - void *temp; if ((p_work = static_cast( - KALDI_MEMALIGN(16, sizeof(Real)*l_work, &temp))) == NULL) + aligned_alloc(16, sizeof(Real)*l_work))) == NULL) throw std::bad_alloc(); // perform svd @@ -729,7 +727,7 @@ void MatrixBase::LapackGesvd(VectorBase *s, MatrixBase *U_in, if (result != 0) { KALDI_WARN << "CLAPACK sgesvd_ : some weird convergence not satisfied"; } - KALDI_MEMALIGN_FREE(p_work); + free(p_work); } #endif @@ -794,7 +792,6 @@ inline void Matrix::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))) @@ -804,7 +801,7 @@ inline void Matrix::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::data_ = static_cast (data); MatrixBase::num_rows_ = rows; MatrixBase::num_cols_ = cols; @@ -1127,7 +1124,7 @@ template void Matrix::Destroy() { // we need to free the data block if it was defined if (NULL != MatrixBase::data_) - KALDI_MEMALIGN_FREE( MatrixBase::data_); + free( MatrixBase::data_); MatrixBase::data_ = NULL; MatrixBase::num_rows_ = MatrixBase::num_cols_ = MatrixBase::stride_ = 0; diff --git a/src/matrix/kaldi-vector.cc b/src/matrix/kaldi-vector.cc index 8cedc9c0487..2bdae2f8efc 100644 --- a/src/matrix/kaldi-vector.cc +++ b/src/matrix/kaldi-vector.cc @@ -173,11 +173,10 @@ inline void Vector::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 (data); this->dim_ = dim; } else { @@ -279,7 +278,7 @@ template void Vector::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; } diff --git a/src/matrix/packed-matrix.cc b/src/matrix/packed-matrix.cc index 80bf5891998..9963eaf16fc 100644 --- a/src/matrix/packed-matrix.cc +++ b/src/matrix/packed-matrix.cc @@ -67,9 +67,8 @@ inline void PackedMatrix::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 (data); this->num_rows_ = r; } else { @@ -226,7 +225,7 @@ Real PackedMatrix::Trace() const { template void PackedMatrix::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; } diff --git a/src/matrix/sp-matrix.cc b/src/matrix/sp-matrix.cc index 224ef39fb6e..5ecb79f0bf5 100644 --- a/src/matrix/sp-matrix.cc +++ b/src/matrix/sp-matrix.cc @@ -222,9 +222,8 @@ void SpMatrix::Invert(Real *logdet, Real *det_sign, bool need_inverse) { KaldiBlasInt rows = static_cast(this->num_rows_); KaldiBlasInt* p_ipiv = new KaldiBlasInt[rows]; Real *p_work; // workspace for the lapack function - void *temp; if ((p_work = static_cast( - KALDI_MEMALIGN(16, sizeof(Real) * rows, &temp))) == NULL) { + aligned_alloc(16, sizeof(Real) * rows))) == NULL) { delete[] p_ipiv; throw std::bad_alloc(); } @@ -277,7 +276,7 @@ void SpMatrix::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 @@ -292,7 +291,7 @@ void SpMatrix::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. diff --git a/src/nnetbin/cuda-gpu-available.cc b/src/nnetbin/cuda-gpu-available.cc index 89fd26be86f..390468d3046 100644 --- a/src/nnetbin/cuda-gpu-available.cc +++ b/src/nnetbin/cuda-gpu-available.cc @@ -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); } diff --git a/src/util/kaldi-io.cc b/src/util/kaldi-io.cc index d577c1e9a89..5ede0836243 100644 --- a/src/util/kaldi-io.cc +++ b/src/util/kaldi-io.cc @@ -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 +#include #ifdef KALDI_CYGWIN_COMPAT #include "util/kaldi-cygwin-io-inl.h" @@ -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); @@ -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"); @@ -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"); diff --git a/src/util/parse-options.h b/src/util/parse-options.h index 12ed62bb55d..3d76b692c7d 100644 --- a/src/util/parse-options.h +++ b/src/util/parse-options.h @@ -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 "