def _ctc_check_compile(ctc_lib_path): preamble = """ #include <string.h> #include "ctc.h" """ body = """ ctcOptions options; memset(&options, 0, sizeof(ctcOptions)); options.loc = CTC_CPU; options.num_threads = 1; """ params = [f"-I{os.path.dirname(__file__)}"] if ctc_lib_path is not None: params.extend([f"-I{os.path.join(config.ctc__root, 'include')}"]) params.extend([f"-L{ctc_lib_path}"]) params.extend(["-l", "warpctc"]) compiler_res = GCC_compiler.try_flags(params, preamble=preamble, body=body, try_run=False, output=True) avail, out, err = (compiler_res if isinstance(compiler_res, tuple) else (compiler_res, None, None)) if not avail: return ( False, ("cannot compile with warp-ctc. " "We got this error:\n" + str(err)), ) return True, None
def test_linking_patch(listdir_mock, platform): libs = ["openblas", "m", "mkl_core", "mkl_rt"] lib_dirs = ['"mock_dir"'] with patch("sys.platform", platform): if platform == "win32": assert GCC_compiler.linking_patch(lib_dirs, libs) == [ "-lopenblas", "-lm", '"' + os.path.join(lib_dirs[0].strip('"'), "mkl_core.1.dll") + '"', '"' + os.path.join(lib_dirs[0].strip('"'), "mkl_rt.1.1.dll") + '"', ] else: GCC_compiler.linking_patch(lib_dirs, libs) == [ "-lopenblas", "-lm", "-lmkl_core", "-lmkl_rt", ]
def check_force_gemv_init(): if check_force_gemv_init._force_init_beta is None: from aesara.link.c.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 initialize 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_patch_ldflags(listdir_mock): mkl_path = "some_path" flag_list = [ "-lm", "-lopenblas", f"-L {mkl_path}", "-l mkl_core", "-lmkl_rt" ] assert GCC_compiler.patch_ldflags(flag_list) == [ "-lm", "-lopenblas", f"-L {mkl_path}", '"' + os.path.join(mkl_path, "mkl_core.1.dll") + '"', '"' + os.path.join(mkl_path, "mkl_rt.1.0.dll") + '"', ]
def test_gxx_support(): """Check if openMP is supported.""" from aesara.link.c.cmodule import GCC_compiler 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_flag_detection(): # Check that the code detecting blas flags does not raise any exception. # It used to happen on python 3 because of improper string handling, # but was not detected because that path is not usually taken, # so we test it here directly. GCC_compiler.try_flags(["-lblas"])
def test_compiler_error(): with pytest.raises( CompileError), tempfile.TemporaryDirectory() as dir_name: GCC_compiler.compile_str("module_name", "blah", location=dir_name)
"setup. This mean Aesara can not use the cvm:" "our c execution engine for Aesara function. If you" "want to remove this warning, use the Aesara flag" "'cxx=' (set to an empty string) to disable all c" "code generation.") raise ImportError("The file lazylinker_c.c is not available.") code = open(cfile).read() loc = os.path.join(config.compiledir, dirname) if not os.path.exists(loc): try: os.mkdir(loc) except OSError as e: assert e.errno == errno.EEXIST assert os.path.exists(loc) args = GCC_compiler.compile_args() GCC_compiler.compile_str(dirname, code, location=loc, preargs=args) # Save version into the __init__.py file. init_py = os.path.join(loc, "__init__.py") with open(init_py, "w") as f: f.write(f"_version = {version}\n") # If we just compiled the module for the first time, then it was # imported at the same time: we need to make sure we do not # reload the now outdated __init__.pyc below. init_pyc = os.path.join(loc, "__init__.pyc") if os.path.isfile(init_pyc): os.remove(init_pyc) try_import() try_reload() from lazylinker_ext import lazylinker_ext as lazy_c