def test_missing_compilers(): from loopy.target.c import ExecutableCTarget, CTarget from loopy.target.c.c_execution import CCompiler from codepy.toolchain import GCCToolchain def __test(evalfunc, target, **targetargs): n = 10 knl = lp.make_kernel( "{[i]: 0 <= i < n}", """ a[i] = b[i] """, [ lp.GlobalArg("a", shape=(n, ), dtype=np.int32), lp.GlobalArg("b", shape=(n, ), dtype=np.int32) ], target=target(**targetargs)) knl = lp.fix_parameters(knl, n=n) return evalfunc(knl) assert __test(lambda knl: lp.generate_code_v2(knl).device_code(), CTarget) from pytools.prefork import ExecError def eval_tester(knl): return np.allclose( knl(a=np.zeros(10, dtype=np.int32), b=np.arange(10, dtype=np.int32))[1], np.arange(10)) import os path_store = os.environ["PATH"] ccomp = None try: # test with path wiped out such that we can't find gcc with pytest.raises(ExecError): os.environ["PATH"] = "" ccomp = CCompiler() __test(eval_tester, ExecutableCTarget, compiler=ccomp) finally: # make sure we restore the path os.environ["PATH"] = path_store # and, with the path restored we should now be able to properly execute with # the default (non-guessed) toolchain! __test(eval_tester, ExecutableCTarget, compiler=ccomp) # and test that we will fail if we remove a required attribute del ccomp.toolchain.undefines with pytest.raises(AttributeError): __test(eval_tester, ExecutableCTarget, compiler=ccomp) # next test that some made up compiler can be specified ccomp = CCompiler(cc="foo") assert isinstance(ccomp.toolchain, GCCToolchain) assert ccomp.toolchain.cc == "foo" # and that said made up compiler errors out with pytest.raises(ExecError): __test(eval_tester, ExecutableCTarget, compiler=ccomp)
def test_missing_compilers(): from loopy.target.c import ExecutableCTarget, CTarget from loopy.target.c.c_execution import CCompiler from codepy.toolchain import GCCToolchain def __test(evalfunc, target, **targetargs): n = 10 knl = lp.make_kernel('{[i]: 0 <= i < n}', """ a[i] = b[i] """, [lp.GlobalArg('a', shape=(n,), dtype=np.int32), lp.GlobalArg('b', shape=(n,), dtype=np.int32)], target=target(**targetargs)) knl = lp.fix_parameters(knl, n=n) return evalfunc(knl) assert __test(lambda knl: lp.generate_code_v2(knl).device_code(), CTarget) from pytools.prefork import ExecError def eval_tester(knl): return np.allclose(knl(a=np.zeros(10, dtype=np.int32), b=np.arange(10, dtype=np.int32))[1], np.arange(10)) import os path_store = os.environ["PATH"] try: # test with path wiped out such that we can't find gcc with pytest.raises(ExecError): os.environ["PATH"] = '' __test(eval_tester, ExecutableCTarget) finally: # make sure we restore the path regardless for future testing os.environ["PATH"] = path_store # next test that some made up compiler can be specified ccomp = CCompiler(cc='foo') assert isinstance(ccomp.toolchain, GCCToolchain) assert ccomp.toolchain.cc == 'foo' # and that said made up compiler errors out with pytest.raises(ExecError): __test(eval_tester, ExecutableCTarget, compiler=ccomp)
def __init__(self, compiler=None, fortran_abi=False): super(ExecutableCTarget, self).__init__(fortran_abi=fortran_abi) from loopy.target.c.c_execution import CCompiler self.compiler = compiler or CCompiler()
def __init__(self, compiler=CCompiler(), fortran_abi=False): super(ExecutableCTarget, self).__init__(fortran_abi=fortran_abi) self.compiler = compiler