def check_force_gemv_init(): if check_force_gemv_init._force_init_beta is None: from theano.gof.cmodule import GCC_compiler """ Test issue 1569. Namely when evaluating beta*y + alpha*dot(A, x) where we set y * beta = zeros of the correct dimensions we do not actually set y = zeros and instead let the BLAS perform beta*y with uninitialized memory for speed. Occasionally the memory contains values that are equivalent to NaN in which case the product beta*y contains NaN's for correctly implemented BLAS libraries. In this situation, since we are introducing the NaN's, we need to test whether the BLAS performs correctly. If it *does*, i.e. it actually performs the multiplication beta*y which will result in NaN's in the result, then we need intialize the memory to zeros. """ test_code = """ #include <math.h> extern "C" void dgemv_(char*, const int*, const int*, const double *, const double *, const int*, const double *, const int*, const double *, double *, const int *); int main() { double A[2][2] = {{1., 1.}, {1., 1.}}; double x[2] = {1., 1.}; double y[2] = {NAN, NAN}; const int s = 2; const int inc = 1; const double alpha = 1.0; const double beta = 0.0; dgemv_("T", &s, &s, &alpha, A, &s, x, &inc, &beta, &y, &inc); return (isnan(y[0]) || isnan(y[1]) ? 1 : 0; } """ res = GCC_compiler.try_compile_tmp( test_code, tmp_prefix="check_beta_", flags=ldflags(libs=True, flags=True, libs_dir=True), try_run=True, ) if res: if res[0]: check_force_gemv_init._force_init_beta = res[1] else: check_force_gemv_init._force_init_beta = False else: check_force_gemv_init._force_init_beta = False return check_force_gemv_init._force_init_beta
def check_force_gemv_init(): if check_force_gemv_init._force_init_beta is None: from theano.gof.cmodule import GCC_compiler """ Test issue 1569. Namely when evaluating beta*y + alpha*dot(A, x) where we set y * beta = zeros of the correct dimensions we do not actually set y = zeros and instead let the BLAS perform beta*y with uninitialized memory for speed. Occasionally the memory contains values that are equivalent to NaN in which case the product beta*y contains NaN's for correctly implemented BLAS libraries. In this situation, since we are introducing the NaN's, we need to test whether the BLAS performs correctly. If it *does*, i.e. it actually performs the multiplication beta*y which will result in NaN's in the result, then we need intialize the memory to zeros. """ test_code = """ #include <math.h> extern "C" void dgemv_(char*, const int*, const int*, const double *, const double *, const int*, const double *, const int*, const double *, double *, const int *); int main() { double A[2][2] = {{1., 1.}, {1., 1.}}; double x[2] = {1., 1.}; double y[2] = {NAN, NAN}; const int s = 2; const int inc = 1; const double alpha = 1.0; const double beta = 0.0; dgemv_("T", &s, &s, &alpha, A, &s, x, &inc, &beta, &y, &inc); return (isnan(y[0]) || isnan(y[1]) ? 1 : 0; } """ res = GCC_compiler.try_compile_tmp(test_code, tmp_prefix='check_beta_', flags=ldflags(libs=True, flags=True, libs_dir=True), try_run=True) if res: if res[0]: check_force_gemv_init._force_init_beta = res[1] else: check_force_gemv_init._force_init_beta = False else: check_force_gemv_init._force_init_beta = False return check_force_gemv_init._force_init_beta
def test_gxx_support(): code = """ #include <omp.h> int main( int argc, const char* argv[] ) { int res[10]; for(int i=0; i < 10; i++){ res[i] = i; } } """ default_openmp = GCC_compiler.try_compile_tmp( src_code=code, tmp_prefix="test_omp_", flags=["-fopenmp"], try_run=False ) return default_openmp
def test_gxx_support(): code = """ #include <omp.h> int main( int argc, const char* argv[] ) { int res[10]; for(int i=0; i < 10; i++){ res[i] = i; } } """ default_openmp = GCC_compiler.try_compile_tmp(src_code=code, tmp_prefix='test_omp_', flags=['-fopenmp'], try_run=False) return default_openmp