diff --git a/loopy/target/c/c_execution.py b/loopy/target/c/c_execution.py index d8b76d32afa64d308648420904f4f4bf8e2e2316..2c8ab16f2e789438bf7040909b96484c4fa93954 100644 --- a/loopy/target/c/c_execution.py +++ b/loopy/target/c/c_execution.py @@ -29,7 +29,8 @@ from loopy.target.execution import (KernelExecutorBase, _KernelInfo, ExecutionWrapperGeneratorBase, get_highlighted_code) from pytools import memoize_method from pytools.py_codegen import (Indentation) -from codepy.toolchain import guess_toolchain +from pytools.prefork import ExecError +from codepy.toolchain import guess_toolchain, ToolchainGuessError, GCCToolchain from codepy.jit import compile_from_string import six import ctypes @@ -216,7 +217,18 @@ class CCompiler(object): source_suffix='c'): # try to get a default toolchain # or subclass supplied version if available - self.toolchain = guess_toolchain() if toolchain is None else toolchain + self.toolchain = toolchain + if toolchain is None: + try: + self.toolchain = guess_toolchain() + except (ToolchainGuessError, ExecError): + # missing compiler python was built with (likely, Conda) + # use a default GCCToolchain + logger = logging.getLogger(__name__) + logger.warn('Default toolchain guessed from python config ' + 'not found, replacing with default GCCToolchain.') + self.toolchain = GCCToolchain() + self.source_suffix = source_suffix if toolchain is None: # copy in all differing values @@ -312,14 +324,14 @@ class CompiledCKernel(object): to automatically map argument types. """ - def __init__(self, knl, idi, dev_code, target, comp=CCompiler()): + def __init__(self, knl, idi, dev_code, target, comp=None): from loopy.target.c import ExecutableCTarget assert isinstance(target, ExecutableCTarget) self.target = target self.name = knl.name # get code and build self.code = dev_code - self.comp = comp + self.comp = comp if comp is not None else CCompiler() self.dll = self.comp.build(self.name, self.code) # get the function declaration for interface with ctypes