From 44c0fba56fb45cd01e391b06fe624efec8bae7cf Mon Sep 17 00:00:00 2001 From: akharche Date: Mon, 20 Sep 2021 21:28:46 +0300 Subject: [PATCH 01/17] Dppy vs numba debug test --- numba_dppy/examples/debug/dppy_numba_basic.py | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 numba_dppy/examples/debug/dppy_numba_basic.py diff --git a/numba_dppy/examples/debug/dppy_numba_basic.py b/numba_dppy/examples/debug/dppy_numba_basic.py new file mode 100644 index 0000000000..266d99869e --- /dev/null +++ b/numba_dppy/examples/debug/dppy_numba_basic.py @@ -0,0 +1,71 @@ +# Copyright 2020, 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import dpctl +import numpy as np +import numba +import argparse + +import numba_dppy as dppy + + +def func(param_a, param_b): + param_c = param_a + 10 # Set breakpoint + param_d = param_b * 0.5 + result = param_c + param_d + return result + + +dppy_func = dppy.func(debug=True)(func) +numba_func = numba.njit(debug=True)(func) + + +@dppy.kernel(debug=True) +def dppy_kernel(a_in_kernel, b_in_kernel, c_in_kernel): + i = dppy.get_global_id(0) + c_in_kernel[i] = dppy_func(a_in_kernel[i], b_in_kernel[i]) + + +@numba.njit(debug=True) +def numba_func_driver(a, b, c): + for i in range(len(c)): + c[i] = numba_func(a[i], b[i]) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--dppy', required=False, action='store_true', + help="Start the dppy version of functions") + + args = parser.parse_args() + + global_size = 10 + N = global_size + + a = np.arange(N, dtype=np.float32) + b = np.arange(N, dtype=np.float32) + c = np.empty_like(a) + + if args.dppy: + device = dpctl.select_default_device() + with dppy.offload_to_sycl_device(device): + dppy_kernel[global_size, dppy.DEFAULT_LOCAL_SIZE](a, b, c) + else: + numba_func_driver(a, b, c) + + print("Done...") + + +if __name__ == "__main__": + main() From 523b0e343c2d2c034b97615d3795c15cf00f4e85 Mon Sep 17 00:00:00 2001 From: akharche Date: Tue, 21 Sep 2021 20:20:04 +0300 Subject: [PATCH 02/17] Add test and commands --- .../examples/debug/commands/dppy_numba_jit | 21 +++++++++ .../examples/debug/commands/dppy_numba_kernel | 20 +++++++++ numba_dppy/examples/debug/dppy_numba_basic.py | 7 ++- numba_dppy/tests/_helper.py | 44 +++++++++++++++++-- numba_dppy/tests/test_debug_dppy_numba.py | 38 ++++++++++++++++ 5 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 numba_dppy/examples/debug/commands/dppy_numba_jit create mode 100644 numba_dppy/examples/debug/commands/dppy_numba_kernel create mode 100644 numba_dppy/tests/test_debug_dppy_numba.py diff --git a/numba_dppy/examples/debug/commands/dppy_numba_jit b/numba_dppy/examples/debug/commands/dppy_numba_jit new file mode 100644 index 0000000000..c4e04dc14e --- /dev/null +++ b/numba_dppy/examples/debug/commands/dppy_numba_jit @@ -0,0 +1,21 @@ +# Run: NUMBA_OPT=0 gdb-oneapi -q -command commands/dppy_numba_jit python +set trace-commands on +set pagination off +set breakpoint pending on +break dppy_numba_basic.py:24 +run dppy_numba_basic.py +# Expected: +# ... +# Thread 1.1 "python" hit Breakpoint 1, __main__::func$242 () at dppy_numba.py:24 +# 24 param_c = param_a + 10 # Set breakpoint +continue +# Expected: +# Thread 1.2 "python" hit Breakpoint 1, __main__::func$242 () at dppy_numba.py:24 +# 24 param_c = param_a + 10 # Set breakpoint +continue +# Expected: +# ... +# Done... +continue +echo Done\n +quit diff --git a/numba_dppy/examples/debug/commands/dppy_numba_kernel b/numba_dppy/examples/debug/commands/dppy_numba_kernel new file mode 100644 index 0000000000..c27dddfb1b --- /dev/null +++ b/numba_dppy/examples/debug/commands/dppy_numba_kernel @@ -0,0 +1,20 @@ +# Run: NUMBA_OPT=0 gdb-oneapi -q -command commands/dppy_numba_kernel python +set trace-commands on +set pagination off +set breakpoint pending on +break dppy_numba_basic.py:24 +run dppy_numba_basic.py --dppy +# Expected: +# ... +# Thread 2.1 hit Breakpoint 1, with SIMD lanes [0-7], __main__::func () at dppy_numba.py:24 +# 24 param_c = param_a + 10 # Set breakpoint +continue +# Expected: +# Thread 2.2 hit Breakpoint 1, with SIMD lanes [0-7], __main__::func () at dppy_numba.py:24 +# 24 param_c = param_a + 10 # Set breakpoint +continue +# Expected: +# ... +# Done... +echo Done\n +quit diff --git a/numba_dppy/examples/debug/dppy_numba_basic.py b/numba_dppy/examples/debug/dppy_numba_basic.py index 266d99869e..afc276adc5 100644 --- a/numba_dppy/examples/debug/dppy_numba_basic.py +++ b/numba_dppy/examples/debug/dppy_numba_basic.py @@ -45,8 +45,11 @@ def numba_func_driver(a, b, c): def main(): parser = argparse.ArgumentParser() - parser.add_argument('--dppy', required=False, action='store_true', - help="Start the dppy version of functions") + parser.add_argument('--dppy', + required=False, + action='store_true', + help="Start the dppy version of functions", + ) args = parser.parse_args() diff --git a/numba_dppy/tests/_helper.py b/numba_dppy/tests/_helper.py index 3d88d20c3c..c1d4e1fb88 100644 --- a/numba_dppy/tests/_helper.py +++ b/numba_dppy/tests/_helper.py @@ -15,8 +15,13 @@ import contextlib import unittest +import os +import re import dpctl +import numba_dppy + +from subprocess import Popen, PIPE from numba.tests.support import captured_stdout from numba_dppy import config @@ -164,14 +169,45 @@ def assert_auto_offloading(parfor_offloaded=1, parfor_offloaded_failure=0): got_parfor_offloaded = stdout.getvalue().count("Parfor offloaded to") assert parfor_offloaded == got_parfor_offloaded, ( - "Expected %d parfor(s) to be auto offloaded, instead got %d parfor(s) auto offloaded" - % (parfor_offloaded, got_parfor_offloaded) + "Expected %d parfor(s) to be auto offloaded, instead got %d parfor(s) auto offloaded" + % (parfor_offloaded, got_parfor_offloaded) ) got_parfor_offloaded_failure = stdout.getvalue().count( "Failed to offload parfor to" ) assert parfor_offloaded_failure == got_parfor_offloaded_failure, ( - "Expected %d parfor(s) to be not auto offloaded, instead got %d parfor(s) not auto offloaded" - % (parfor_offloaded_failure, got_parfor_offloaded_failure) + "Expected %d parfor(s) to be not auto offloaded, instead got %d parfor(s) not auto offloaded" + % (parfor_offloaded_failure, got_parfor_offloaded_failure) + ) + + +def make_check(text, val_to_search): + m = re.search(val_to_search, text, re.I) + got = m is not None + return got + + +@contextlib.contextmanager +def run_debug_command(command_name): + process_env = os.environ.copy() + process_env["NUMBA_OPT"] = "0" + + command_path = os.path.dirname(os.path.abspath(numba_dppy.__file__)) + "/examples/debug/commands/" + command_name + + process = Popen( + [ + "gdb-oneapi", + "-q", + "-command", + command_path, + "python", + ], + stdout=PIPE, + stderr=PIPE, + env=process_env, ) + (output, err) = process.communicate() + process.wait() + + yield str(output) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py new file mode 100644 index 0000000000..e870df9f4c --- /dev/null +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python +# Copyright 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from numba_dppy.tests._helper import skip_test, run_debug_command, make_check + + +def test_breakpoint_row_number(): + ref_output = [ + r"Thread .\.. hit Breakpoint ., with SIMD lanes [0-7], __main__::func.*at dppy_numba.py:24", + r"24 +param_c = param_a \+ 10 .*", + ] + + numba_ref_test = True + dppy_ref_test = True + + with run_debug_command("dppy_numba_jit") as command_out: + import pdb + pdb.set_trace() + for ref in ref_output: + numba_ref_test &= make_check(command_out, ref) + + with run_debug_command("commands/dppy_numba_kernel") as command_out: + for ref in ref_output: + dppy_ref_test &= make_check(command_out, ref) + + assert numba_ref_test and dppy_ref_test From c5c604007595318f88834d192b733c447bf1bab8 Mon Sep 17 00:00:00 2001 From: akharche Date: Tue, 21 Sep 2021 22:43:15 +0300 Subject: [PATCH 03/17] remove extra import --- numba_dppy/tests/test_debug_dppy_numba.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index e870df9f4c..73e38b02db 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -26,8 +26,6 @@ def test_breakpoint_row_number(): dppy_ref_test = True with run_debug_command("dppy_numba_jit") as command_out: - import pdb - pdb.set_trace() for ref in ref_output: numba_ref_test &= make_check(command_out, ref) From 1762d928ae21af8a6a318f45059c745f1af16b5c Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Wed, 22 Sep 2021 19:54:30 +0300 Subject: [PATCH 04/17] Example test for GDB using pexpect --- environment.yml | 1 + numba_dppy/tests/test_debug_dppy_numba.py | 83 +++++++++++++++++++---- 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/environment.yml b/environment.yml index 7f402a11d3..f294eb3164 100644 --- a/environment.yml +++ b/environment.yml @@ -26,6 +26,7 @@ dependencies: - black==20.8b1 - pytest-cov - pytest-xdist + - pexpect variables: CHANNELS: -c defaults -c numba -c intel -c numba/label/dev -c dppy/label/dev --override-channels CHANNELS_DEV: -c dppy/label/dev -c defaults -c numba -c intel -c numba/label/dev --override-channels diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 73e38b02db..41bc30b652 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -13,24 +13,77 @@ # See the License for the specific language governing permissions and # limitations under the License. -from numba_dppy.tests._helper import skip_test, run_debug_command, make_check +import shutil +import pytest -def test_breakpoint_row_number(): - ref_output = [ - r"Thread .\.. hit Breakpoint ., with SIMD lanes [0-7], __main__::func.*at dppy_numba.py:24", - r"24 +param_c = param_a \+ 10 .*", - ] +from numba_dppy.tests._helper import make_check, run_debug_command, skip_test +import numba_dppy + + +pytestmark = pytest.mark.skipif( + not shutil.which("gdb-oneapi"), + reason="Intel Distribution for GDB is not available", +) + + +# TODO: go to helper +class gdb: + def __init__(self): + self.spawn() + self.setup_gdb() + + def __del__(self): + self.teardown_gdb() + + def spawn(self): + import pexpect + import sys + import os + + env = os.environ.copy() + env["NUMBA_OPT"] = "0" - numba_ref_test = True - dppy_ref_test = True + self.child = pexpect.spawn("gdb-oneapi -q python", env=env, encoding="utf-8") + self.child.logfile = sys.stdout - with run_debug_command("dppy_numba_jit") as command_out: - for ref in ref_output: - numba_ref_test &= make_check(command_out, ref) + def setup_gdb(self): + self.child.expect("(gdb)", timeout=5) + self.child.sendline("set breakpoint pending on") + self.child.expect("(gdb)", timeout=5) + self.child.sendline("set style enabled off") # disable colors symbols + + def teardown_gdb(self): + self.child.expect("(gdb)", timeout=5) + self.child.sendline("quit") + self.child.expect("Quit anyway?", timeout=5) + self.child.sendline("y") + + def breakpoint(self, breakpoint): + self.child.expect("(gdb)", timeout=5) + self.child.sendline("break " + breakpoint) + + def run(self, script): + self.child.expect("(gdb)", timeout=5) + self.child.sendline("run " + self.script_path(script)) + + @staticmethod + def script_path(script): + import os + + return os.path.join( + os.path.dirname(os.path.abspath(numba_dppy.__file__)), + "examples", + "debug", + script, + ) + + +def test_breakpoint_row_number(): + app = gdb() - with run_debug_command("commands/dppy_numba_kernel") as command_out: - for ref in ref_output: - dppy_ref_test &= make_check(command_out, ref) + app.breakpoint("dppy_numba_basic.py:24") + app.run("dppy_numba_basic.py") - assert numba_ref_test and dppy_ref_test + app.child.expect("Thread .* hit Breakpoint .* at dppy_numba_basic.py:24") + app.child.expect("24\s+param_c = param_a \+ 10") From 08f8f7af5180939b2fa724c72e97ad4fa197867b Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 08:39:05 +0300 Subject: [PATCH 05/17] Update numba_dppy/tests/test_debug_dppy_numba.py Co-authored-by: Angelina Kharchevnikova --- numba_dppy/tests/test_debug_dppy_numba.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 41bc30b652..42e1cab13f 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -69,14 +69,9 @@ def run(self, script): @staticmethod def script_path(script): - import os + import pathlib - return os.path.join( - os.path.dirname(os.path.abspath(numba_dppy.__file__)), - "examples", - "debug", - script, - ) + return pathlib.Path(numba_dppy.__file__).parents[0] / 'examples/debug/' def test_breakpoint_row_number(): From 88935374f6e0b6eadc443247849b5ee941fa7d3a Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 09:03:33 +0300 Subject: [PATCH 06/17] Skip of pexpect not installed --- numba_dppy/tests/test_debug_dppy_numba.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 42e1cab13f..8ecd321b97 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -20,6 +20,7 @@ from numba_dppy.tests._helper import make_check, run_debug_command, skip_test import numba_dppy +pexpect = pytest.importorskip("pexpect") pytestmark = pytest.mark.skipif( not shutil.which("gdb-oneapi"), From f4121b6e0a59167187c56f72dc7ba5b0b763793b Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 09:04:09 +0300 Subject: [PATCH 07/17] Fix using pathlib --- numba_dppy/tests/test_debug_dppy_numba.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 8ecd321b97..5957d1ce3a 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import pathlib import shutil import pytest @@ -70,9 +71,8 @@ def run(self, script): @staticmethod def script_path(script): - import pathlib - - return pathlib.Path(numba_dppy.__file__).parents[0] / 'examples/debug/' + package_path = pathlib.Path(numba_dppy.__file__).parent + return str(package_path / "examples/debug" / script) def test_breakpoint_row_number(): From cea030a134af08dd274e9d7fe5737869e5b8530c Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 09:04:37 +0300 Subject: [PATCH 08/17] Move imports to top --- numba_dppy/tests/test_debug_dppy_numba.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 5957d1ce3a..940faf41ba 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -13,8 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import pathlib import shutil +import sys import pytest @@ -39,10 +41,6 @@ def __del__(self): self.teardown_gdb() def spawn(self): - import pexpect - import sys - import os - env = os.environ.copy() env["NUMBA_OPT"] = "0" From 1ebdbd1513de6694ad67f5eb8a087bc8105cf7d4 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 09:04:51 +0300 Subject: [PATCH 09/17] Remove unused code --- numba_dppy/tests/test_debug_dppy_numba.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 940faf41ba..1d6b2f80f6 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -20,7 +20,6 @@ import pytest -from numba_dppy.tests._helper import make_check, run_debug_command, skip_test import numba_dppy pexpect = pytest.importorskip("pexpect") @@ -30,7 +29,6 @@ reason="Intel Distribution for GDB is not available", ) - # TODO: go to helper class gdb: def __init__(self): From 4e0e055dc13a38c5e9fbd291a5d4172e6f8928f3 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 09:29:46 +0300 Subject: [PATCH 10/17] Add API selection --- numba_dppy/examples/debug/dppy_numba_basic.py | 14 +++++++++----- numba_dppy/tests/test_debug_dppy_numba.py | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/numba_dppy/examples/debug/dppy_numba_basic.py b/numba_dppy/examples/debug/dppy_numba_basic.py index afc276adc5..87bd1537c7 100644 --- a/numba_dppy/examples/debug/dppy_numba_basic.py +++ b/numba_dppy/examples/debug/dppy_numba_basic.py @@ -45,10 +45,12 @@ def numba_func_driver(a, b, c): def main(): parser = argparse.ArgumentParser() - parser.add_argument('--dppy', - required=False, - action='store_true', - help="Start the dppy version of functions", + parser.add_argument( + "--api", + required=False, + default="numba", + choices=["numba", "numba-dppy"], + help="Start the version of functions using numba or numba-dppy API", ) args = parser.parse_args() @@ -60,7 +62,9 @@ def main(): b = np.arange(N, dtype=np.float32) c = np.empty_like(a) - if args.dppy: + print("Using API:", args.api) + + if args.api == "numba-dppy": device = dpctl.select_default_device() with dppy.offload_to_sycl_device(device): dppy_kernel[global_size, dppy.DEFAULT_LOCAL_SIZE](a, b, c) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 1d6b2f80f6..08d57863af 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -70,12 +70,12 @@ def script_path(script): package_path = pathlib.Path(numba_dppy.__file__).parent return str(package_path / "examples/debug" / script) - -def test_breakpoint_row_number(): +@pytest.mark.parametrize("api", ["numba", "numba-dppy"]) +def test_breakpoint_row_number(api): app = gdb() app.breakpoint("dppy_numba_basic.py:24") - app.run("dppy_numba_basic.py") + app.run("dppy_numba_basic.py --api={api}".format(api=api)) app.child.expect("Thread .* hit Breakpoint .* at dppy_numba_basic.py:24") app.child.expect("24\s+param_c = param_a \+ 10") From 44accc5940e6d3de46031177a4df28a08960815a Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 09:31:44 +0300 Subject: [PATCH 11/17] Fix black --- numba_dppy/tests/_helper.py | 14 +++++++++----- numba_dppy/tests/test_debug_dppy_numba.py | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/numba_dppy/tests/_helper.py b/numba_dppy/tests/_helper.py index c1d4e1fb88..0678eb2fbd 100644 --- a/numba_dppy/tests/_helper.py +++ b/numba_dppy/tests/_helper.py @@ -169,16 +169,16 @@ def assert_auto_offloading(parfor_offloaded=1, parfor_offloaded_failure=0): got_parfor_offloaded = stdout.getvalue().count("Parfor offloaded to") assert parfor_offloaded == got_parfor_offloaded, ( - "Expected %d parfor(s) to be auto offloaded, instead got %d parfor(s) auto offloaded" - % (parfor_offloaded, got_parfor_offloaded) + "Expected %d parfor(s) to be auto offloaded, instead got %d parfor(s) auto offloaded" + % (parfor_offloaded, got_parfor_offloaded) ) got_parfor_offloaded_failure = stdout.getvalue().count( "Failed to offload parfor to" ) assert parfor_offloaded_failure == got_parfor_offloaded_failure, ( - "Expected %d parfor(s) to be not auto offloaded, instead got %d parfor(s) not auto offloaded" - % (parfor_offloaded_failure, got_parfor_offloaded_failure) + "Expected %d parfor(s) to be not auto offloaded, instead got %d parfor(s) not auto offloaded" + % (parfor_offloaded_failure, got_parfor_offloaded_failure) ) @@ -193,7 +193,11 @@ def run_debug_command(command_name): process_env = os.environ.copy() process_env["NUMBA_OPT"] = "0" - command_path = os.path.dirname(os.path.abspath(numba_dppy.__file__)) + "/examples/debug/commands/" + command_name + command_path = ( + os.path.dirname(os.path.abspath(numba_dppy.__file__)) + + "/examples/debug/commands/" + + command_name + ) process = Popen( [ diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 08d57863af..6c2fc07fbe 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -43,7 +43,7 @@ def spawn(self): env["NUMBA_OPT"] = "0" self.child = pexpect.spawn("gdb-oneapi -q python", env=env, encoding="utf-8") - self.child.logfile = sys.stdout + # self.child.logfile = sys.stdout def setup_gdb(self): self.child.expect("(gdb)", timeout=5) @@ -70,6 +70,7 @@ def script_path(script): package_path = pathlib.Path(numba_dppy.__file__).parent return str(package_path / "examples/debug" / script) + @pytest.mark.parametrize("api", ["numba", "numba-dppy"]) def test_breakpoint_row_number(api): app = gdb() From 664d05b9f7f2fad769942f57035f618c10468700 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 10:05:50 +0300 Subject: [PATCH 12/17] Remove unused commands --- .../examples/debug/commands/dppy_numba_jit | 21 ------------------- .../examples/debug/commands/dppy_numba_kernel | 20 ------------------ 2 files changed, 41 deletions(-) delete mode 100644 numba_dppy/examples/debug/commands/dppy_numba_jit delete mode 100644 numba_dppy/examples/debug/commands/dppy_numba_kernel diff --git a/numba_dppy/examples/debug/commands/dppy_numba_jit b/numba_dppy/examples/debug/commands/dppy_numba_jit deleted file mode 100644 index c4e04dc14e..0000000000 --- a/numba_dppy/examples/debug/commands/dppy_numba_jit +++ /dev/null @@ -1,21 +0,0 @@ -# Run: NUMBA_OPT=0 gdb-oneapi -q -command commands/dppy_numba_jit python -set trace-commands on -set pagination off -set breakpoint pending on -break dppy_numba_basic.py:24 -run dppy_numba_basic.py -# Expected: -# ... -# Thread 1.1 "python" hit Breakpoint 1, __main__::func$242 () at dppy_numba.py:24 -# 24 param_c = param_a + 10 # Set breakpoint -continue -# Expected: -# Thread 1.2 "python" hit Breakpoint 1, __main__::func$242 () at dppy_numba.py:24 -# 24 param_c = param_a + 10 # Set breakpoint -continue -# Expected: -# ... -# Done... -continue -echo Done\n -quit diff --git a/numba_dppy/examples/debug/commands/dppy_numba_kernel b/numba_dppy/examples/debug/commands/dppy_numba_kernel deleted file mode 100644 index c27dddfb1b..0000000000 --- a/numba_dppy/examples/debug/commands/dppy_numba_kernel +++ /dev/null @@ -1,20 +0,0 @@ -# Run: NUMBA_OPT=0 gdb-oneapi -q -command commands/dppy_numba_kernel python -set trace-commands on -set pagination off -set breakpoint pending on -break dppy_numba_basic.py:24 -run dppy_numba_basic.py --dppy -# Expected: -# ... -# Thread 2.1 hit Breakpoint 1, with SIMD lanes [0-7], __main__::func () at dppy_numba.py:24 -# 24 param_c = param_a + 10 # Set breakpoint -continue -# Expected: -# Thread 2.2 hit Breakpoint 1, with SIMD lanes [0-7], __main__::func () at dppy_numba.py:24 -# 24 param_c = param_a + 10 # Set breakpoint -continue -# Expected: -# ... -# Done... -echo Done\n -quit From 002d7ab17f729d925b60fcb8c178b0c53c5a7cea Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 10:06:33 +0300 Subject: [PATCH 13/17] Move print after parsing args --- numba_dppy/examples/debug/dppy_numba_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba_dppy/examples/debug/dppy_numba_basic.py b/numba_dppy/examples/debug/dppy_numba_basic.py index 87bd1537c7..4bade13c32 100644 --- a/numba_dppy/examples/debug/dppy_numba_basic.py +++ b/numba_dppy/examples/debug/dppy_numba_basic.py @@ -55,6 +55,8 @@ def main(): args = parser.parse_args() + print("Using API:", args.api) + global_size = 10 N = global_size @@ -62,8 +64,6 @@ def main(): b = np.arange(N, dtype=np.float32) c = np.empty_like(a) - print("Using API:", args.api) - if args.api == "numba-dppy": device = dpctl.select_default_device() with dppy.offload_to_sycl_device(device): From d6d1e2cf068c920e81e774bd42cf903415693ecc Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 10:07:54 +0300 Subject: [PATCH 14/17] Remove _helper.py changes --- numba_dppy/tests/_helper.py | 40 ------------------------------------- 1 file changed, 40 deletions(-) diff --git a/numba_dppy/tests/_helper.py b/numba_dppy/tests/_helper.py index 0678eb2fbd..3d88d20c3c 100644 --- a/numba_dppy/tests/_helper.py +++ b/numba_dppy/tests/_helper.py @@ -15,13 +15,8 @@ import contextlib import unittest -import os -import re import dpctl -import numba_dppy - -from subprocess import Popen, PIPE from numba.tests.support import captured_stdout from numba_dppy import config @@ -180,38 +175,3 @@ def assert_auto_offloading(parfor_offloaded=1, parfor_offloaded_failure=0): "Expected %d parfor(s) to be not auto offloaded, instead got %d parfor(s) not auto offloaded" % (parfor_offloaded_failure, got_parfor_offloaded_failure) ) - - -def make_check(text, val_to_search): - m = re.search(val_to_search, text, re.I) - got = m is not None - return got - - -@contextlib.contextmanager -def run_debug_command(command_name): - process_env = os.environ.copy() - process_env["NUMBA_OPT"] = "0" - - command_path = ( - os.path.dirname(os.path.abspath(numba_dppy.__file__)) - + "/examples/debug/commands/" - + command_name - ) - - process = Popen( - [ - "gdb-oneapi", - "-q", - "-command", - command_path, - "python", - ], - stdout=PIPE, - stderr=PIPE, - env=process_env, - ) - (output, err) = process.communicate() - process.wait() - - yield str(output) From 9c337f0095bd791f9982eeee30a6d9654385cdba Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 10:11:57 +0300 Subject: [PATCH 15/17] Fix import sort in dppy_numba_basic.py --- numba_dppy/examples/debug/dppy_numba_basic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/numba_dppy/examples/debug/dppy_numba_basic.py b/numba_dppy/examples/debug/dppy_numba_basic.py index 4bade13c32..d90a734d90 100644 --- a/numba_dppy/examples/debug/dppy_numba_basic.py +++ b/numba_dppy/examples/debug/dppy_numba_basic.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse + import dpctl -import numpy as np import numba -import argparse +import numpy as np import numba_dppy as dppy From 8f1bfcc128bffce5e5f3b475b24b7043d0f04af1 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 10:28:51 +0300 Subject: [PATCH 16/17] Fix line number and pre-commits --- numba_dppy/tests/test_debug_dppy_numba.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 6c2fc07fbe..315bc1ac5e 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -29,6 +29,7 @@ reason="Intel Distribution for GDB is not available", ) + # TODO: go to helper class gdb: def __init__(self): @@ -75,8 +76,8 @@ def script_path(script): def test_breakpoint_row_number(api): app = gdb() - app.breakpoint("dppy_numba_basic.py:24") + app.breakpoint("dppy_numba_basic.py:25") app.run("dppy_numba_basic.py --api={api}".format(api=api)) - app.child.expect("Thread .* hit Breakpoint .* at dppy_numba_basic.py:24") - app.child.expect("24\s+param_c = param_a \+ 10") + app.child.expect(r"Thread .* hit Breakpoint .* at dppy_numba_basic.py:25") + app.child.expect(r"25\s+param_c = param_a \+ 10") From 1489beee8c9379c37a913918d81be23dd6569590 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Thu, 23 Sep 2021 11:35:32 +0300 Subject: [PATCH 17/17] Fix naming validation checks --- numba_dppy/tests/test_debug_dppy_numba.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numba_dppy/tests/test_debug_dppy_numba.py b/numba_dppy/tests/test_debug_dppy_numba.py index 315bc1ac5e..28f66f6f97 100644 --- a/numba_dppy/tests/test_debug_dppy_numba.py +++ b/numba_dppy/tests/test_debug_dppy_numba.py @@ -26,7 +26,7 @@ pytestmark = pytest.mark.skipif( not shutil.which("gdb-oneapi"), - reason="Intel Distribution for GDB is not available", + reason="IntelĀ® Distribution for GDB* is not available", )