From 33d2111ad136a949fdff4a556100c4c126c05280 Mon Sep 17 00:00:00 2001 From: Marmaduke Woodman Date: Wed, 24 May 2017 16:53:55 +0200 Subject: [PATCH 1/6] WIP numba kernel executor --- loopy/target/numba.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/loopy/target/numba.py b/loopy/target/numba.py index 6946063ee..512e30248 100644 --- a/loopy/target/numba.py +++ b/loopy/target/numba.py @@ -103,6 +103,16 @@ class NumbaTarget(TargetBase): def get_device_ast_builder(self): return NumbaJITASTBuilder(self) + def get_kernel_executor_cache_key(self, *args, **kwargs): + return 'default' + + def get_kernel_executor(self, knl, *args, **kwargs): + from loopy import generate_code + code, _ = generate_code(knl) + ns = {} + exec(code, ns) + return ns[knl.name] + # {{{ types @memoize_method -- GitLab From 7b1d9b538f3520fd501fff71a3eae36354101822 Mon Sep 17 00:00:00 2001 From: Marmaduke Woodman Date: Thu, 25 May 2017 11:18:45 +0200 Subject: [PATCH 2/6] numba exec: None cache key & test --- loopy/target/numba.py | 2 +- test/test_target.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/loopy/target/numba.py b/loopy/target/numba.py index 512e30248..c36f4e40f 100644 --- a/loopy/target/numba.py +++ b/loopy/target/numba.py @@ -104,7 +104,7 @@ class NumbaTarget(TargetBase): return NumbaJITASTBuilder(self) def get_kernel_executor_cache_key(self, *args, **kwargs): - return 'default' + return None def get_kernel_executor(self, knl, *args, **kwargs): from loopy import generate_code diff --git a/test/test_target.py b/test/test_target.py index b656383e7..52eb38ea6 100644 --- a/test/test_target.py +++ b/test/test_target.py @@ -224,6 +224,16 @@ def test_numba_cuda_target(): print(lp.generate_code_v2(knl).all_code()) +def test_numba_call(): + target = lp.NumbaTarget() + knl = lp.make_kernel("{ [i]: 0<=i 1: exec(sys.argv[1]) -- GitLab From 8950734448fd515156f3e6f1a3ebeb793e692af2 Mon Sep 17 00:00:00 2001 From: Marmaduke Woodman Date: Thu, 25 May 2017 11:25:00 +0200 Subject: [PATCH 3/6] numba exec: cache jit funcs on hash(knl) --- loopy/target/numba.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/loopy/target/numba.py b/loopy/target/numba.py index c36f4e40f..46fa8c6ce 100644 --- a/loopy/target/numba.py +++ b/loopy/target/numba.py @@ -93,6 +93,7 @@ class NumbaTarget(TargetBase): from warnings import warn warn("The Numba targets are not yet feature-complete", LoopyWarning, stacklevel=2) + self._code_cache = {} def split_kernel_at_global_barriers(self): return False @@ -107,11 +108,13 @@ class NumbaTarget(TargetBase): return None def get_kernel_executor(self, knl, *args, **kwargs): - from loopy import generate_code - code, _ = generate_code(knl) - ns = {} - exec(code, ns) - return ns[knl.name] + if knl not in self._code_cache: + from loopy import generate_code + code, _ = generate_code(knl) + ns = {} + exec(code, ns) + self._code_cache[knl] = ns[knl.name] + return self._code_cache[knl] # {{{ types -- GitLab From 1989f112806b5a2a6931d253869591b1290114eb Mon Sep 17 00:00:00 2001 From: Marmaduke Woodman Date: Thu, 25 May 2017 11:36:07 +0200 Subject: [PATCH 4/6] numba call: clarify name s/code/jit_func/ --- loopy/target/numba.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/loopy/target/numba.py b/loopy/target/numba.py index 46fa8c6ce..816143710 100644 --- a/loopy/target/numba.py +++ b/loopy/target/numba.py @@ -93,7 +93,7 @@ class NumbaTarget(TargetBase): from warnings import warn warn("The Numba targets are not yet feature-complete", LoopyWarning, stacklevel=2) - self._code_cache = {} + self._jit_func_cache = {} def split_kernel_at_global_barriers(self): return False @@ -108,13 +108,13 @@ class NumbaTarget(TargetBase): return None def get_kernel_executor(self, knl, *args, **kwargs): - if knl not in self._code_cache: + if knl not in self._jit_func_cache: from loopy import generate_code code, _ = generate_code(knl) ns = {} exec(code, ns) - self._code_cache[knl] = ns[knl.name] - return self._code_cache[knl] + self._jit_func_cache[knl] = ns[knl.name] + return self._jit_func_cache[knl] # {{{ types -- GitLab From 8df882cdd56f0630f1483a7ec7615658fc110063 Mon Sep 17 00:00:00 2001 From: Marmaduke Woodman Date: Thu, 25 May 2017 14:39:41 +0200 Subject: [PATCH 5/6] numba exec: skip test if numba not avail --- test/test_target.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_target.py b/test/test_target.py index 52eb38ea6..415efc603 100644 --- a/test/test_target.py +++ b/test/test_target.py @@ -225,6 +225,10 @@ def test_numba_cuda_target(): def test_numba_call(): + try: + import numba + except ImportError: + pytest.skip("Numba not available.") target = lp.NumbaTarget() knl = lp.make_kernel("{ [i]: 0<=i Date: Thu, 25 May 2017 14:54:48 +0200 Subject: [PATCH 6/6] ignore unused import --- test/test_target.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_target.py b/test/test_target.py index 415efc603..046e6df57 100644 --- a/test/test_target.py +++ b/test/test_target.py @@ -226,7 +226,7 @@ def test_numba_cuda_target(): def test_numba_call(): try: - import numba + import numba # noqa except ImportError: pytest.skip("Numba not available.") target = lp.NumbaTarget() -- GitLab