Repository: IntelPython/numba-dpex (language: python)

Issue:
Code reorganization: Removes ocl kernel API, moves math, print into kernel_api_impl
- [X] Have you provided a meaningful PR description?

The PR sifts through the mounds of tech debt accumulated over the years and cleans up whatever possible.

**Summary of changes:**

* **Remove the legacy OCL-like kernel API implementation**

  It was the starting point of numba-dpex (_aka_ numba-dppy _aka_ numba-pydppl _aka_ pydppl _aka_ dppy, I forget the chronology). Now thanks to the target-specific overload-based `kernel_api_impl` all features in the `ocldecl` and `oclimpl` modules have been cleanly implemented as a SYCL-like API and thus are no longer needed.

* **Remove `core.types.array.Array`**
  
  Has been superseded by `USMNdArray` and was no longer needed.

* **Minor fixes to imports**

  Minor linter highlighted fixes.

* **Move `printimpl` into `kernel_api_impl.spirv`**

   Each backend for `kernel_api` should provide its own `print` implementation that will be registered to the backend's typing and target contexts. Thus, the module belongs inside `kernel_api_impl.spirv`. 

* **Move `ocl.mathimpl` and `ocl.mathdecl` into `kernel_api_impl.spirv.math`**

   Moves the standard lib `math` module support from top-level `ocl` module into `kernel_api_impl.spirv.math` and gets rid of `ocl` completely. Each back end for `kernel_api` has to provide its implementation of the math functions, so the code belongs inside each back end. The code itself is not very well designed and not much can be done right now.

- [X] Have you tested your changes locally for CPU and GPU devices?
- [X] Have you made sure that new changes do not introduce compiler warnings?
- [ ] If this PR is a work in progress, are you filing the PR as a draft?

#Fixes #795


Discussion / hints:
<!-- add-pr-comment:add-pr-comment -->

Documentation preview: [show](https://intelpython.github.io/numba-dpex/pull/1420).

Fix patch:
diff --git a/numba_dpex/parfor_diagnostics.py b/numba_dpex/core/parfors/parfor_diagnostics.py
similarity index 100%
rename from numba_dpex/parfor_diagnostics.py
rename to numba_dpex/core/parfors/parfor_diagnostics.py
diff --git a/numba_dpex/core/pipelines/dpjit_compiler.py b/numba_dpex/core/pipelines/dpjit_compiler.py
index 84aa27159e..72b682cbab 100644
--- a/numba_dpex/core/pipelines/dpjit_compiler.py
+++ b/numba_dpex/core/pipelines/dpjit_compiler.py
@@ -19,13 +19,13 @@
 )
 
 from numba_dpex.core.exceptions import UnsupportedCompilationModeError
+from numba_dpex.core.parfors.parfor_diagnostics import ExtendedParforDiagnostics
 from numba_dpex.core.parfors.parfor_pass import ParforPass
 from numba_dpex.core.passes import (
     DumpParforDiagnostics,
     NoPythonBackend,
     ParforLegalizeCFDPass,
 )
-from numba_dpex.parfor_diagnostics import ExtendedParforDiagnostics
 
 
 class _DpjitPassBuilder(object):
diff --git a/numba_dpex/core/itanium_mangler.py b/numba_dpex/core/utils/itanium_mangler.py
similarity index 100%
rename from numba_dpex/core/itanium_mangler.py
rename to numba_dpex/core/utils/itanium_mangler.py
diff --git a/numba_dpex/debuginfo.py b/numba_dpex/debuginfo.py
deleted file mode 100644
index cef6f682b7..0000000000
--- a/numba_dpex/debuginfo.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# SPDX-FileCopyrightText: 2020 - 2024 Intel Corporation
-#
-# SPDX-License-Identifier: Apache-2.0
-
-import numba as nb
-from llvmlite import ir
-from numba.core.debuginfo import DIBuilder
-
-from numba_dpex.numba_support import numba_version
-
-
-class DpexDIBuilder(DIBuilder):
-    def __init__(self, module, filepath, linkage_name, cgctx):
-        args = []
-
-        if numba_version > (0, 54):
-            args.append(cgctx)
-
-        DIBuilder.__init__(self, module, filepath, *args)
-        self.linkage_name = linkage_name
-
-    if numba_version > (0, 54):
-
-        def mark_subprogram(self, function, qualname, argnames, argtypes, line):
-            name = qualname
-            argmap = dict(zip(argnames, argtypes))
-            di_subp = self._add_subprogram(
-                name=name,
-                linkagename=self.linkage_name,
-                line=line,
-                function=function,
-                argmap=argmap,
-            )
-            function.set_metadata("dbg", di_subp)
-            # disable inlining for this function for easier debugging
-            function.attributes.add("noinline")
-
-    else:
-
-        def mark_subprogram(self, function, name, line):
-            di_subp = self._add_subprogram(
-                name=name, linkagename=self.linkage_name, line=line
-            )
-            function.set_metadata("dbg", di_subp)
-            # disable inlining for this function for easier debugging
-            function.attributes.add("noinline")
-
-    def _di_compile_unit(self):
-        di = super()._di_compile_unit()
-        operands = dict(di.operands)
-        operands["language"] = ir.DIToken("DW_LANG_C_plus_plus")
-        operands["producer"] = "numba-dpex"
-        di.operands = tuple(operands.items())
-        return di
diff --git a/numba_dpex/kernel_api_impl/spirv/overloads/_atomic_ref_overloads.py b/numba_dpex/kernel_api_impl/spirv/overloads/_atomic_ref_overloads.py
index ae5c2980df..98bf7200ae 100644
--- a/numba_dpex/kernel_api_impl/spirv/overloads/_atomic_ref_overloads.py
+++ b/numba_dpex/kernel_api_impl/spirv/overloads/_atomic_ref_overloads.py
@@ -11,9 +11,9 @@
 from numba.core import cgutils, types
 from numba.extending import intrinsic, overload, overload_method
 
-from numba_dpex.core import itanium_mangler as ext_itanium_mangler
 from numba_dpex.core.types import USMNdArray
 from numba_dpex.core.types.kernel_api.atomic_ref import AtomicRefType
+from numba_dpex.core.utils import itanium_mangler as ext_itanium_mangler
 from numba_dpex.kernel_api import (
     AddressSpace,
     AtomicRef,
diff --git a/numba_dpex/kernel_api_impl/spirv/overloads/spv_fn_declarations.py b/numba_dpex/kernel_api_impl/spirv/overloads/spv_fn_declarations.py
index cb226ea34c..924f5efb72 100644
--- a/numba_dpex/kernel_api_impl/spirv/overloads/spv_fn_declarations.py
+++ b/numba_dpex/kernel_api_impl/spirv/overloads/spv_fn_declarations.py
@@ -12,7 +12,7 @@
 from llvmlite import ir as llvmir
 from numba.core import cgutils, types
 
-from numba_dpex.core import itanium_mangler as ext_itanium_mangler
+from numba_dpex.core.utils import itanium_mangler as ext_itanium_mangler
 from numba_dpex.kernel_api_impl.spirv.target import CC_SPIR_FUNC
 
 _SUPPORT_CONVERGENT = True
diff --git a/numba_dpex/ocl/_declare_function.py b/numba_dpex/ocl/_declare_function.py
index 4a38e7faa7..ba0088700d 100644
--- a/numba_dpex/ocl/_declare_function.py
+++ b/numba_dpex/ocl/_declare_function.py
@@ -5,7 +5,7 @@
 from llvmlite import ir as llvmir
 from numba.core import cgutils, types
 
-from numba_dpex.core.itanium_mangler import mangle_c
+from numba_dpex.core.utils.itanium_mangler import mangle_c
 
 # -----------------------------------------------------------------------------
 
diff --git a/numba_dpex/ocl/mathimpl.py b/numba_dpex/ocl/mathimpl.py
index 4cf5719e99..9b95e24ecc 100644
--- a/numba_dpex/ocl/mathimpl.py
+++ b/numba_dpex/ocl/mathimpl.py
@@ -9,7 +9,7 @@
 from numba.core import types
 from numba.core.imputils import Registry
 
-from numba_dpex.core.itanium_mangler import mangle
+from numba_dpex.core.utils.itanium_mangler import mangle
 
 from ._declare_function import _declare_function
 


Test patch:
diff --git a/numba_dpex/tests/core/test_itanium_mangler_extension.py b/numba_dpex/tests/core/test_itanium_mangler_extension.py
index 3244dc58a3..68c7b7150c 100644
--- a/numba_dpex/tests/core/test_itanium_mangler_extension.py
+++ b/numba_dpex/tests/core/test_itanium_mangler_extension.py
@@ -6,7 +6,7 @@
 from numba import float32, float64, int32, int64, uint32, uint64
 from numba.core import types
 
-import numba_dpex.core.itanium_mangler as itanium_mangler
+import numba_dpex.core.utils.itanium_mangler as itanium_mangler
 from numba_dpex.utils import address_space
 
 list_of_dtypes = [