Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ cunumpy = [ "py.typed", "*.pyi", "LLM_GUIDE.md", "cuda/include/cunumpy/*.cuh" ]
# agent worktrees and scratch scripts are local copies, not part of the project
extend-exclude = [ ".claude" ]
# formatting: `ruff format`; import sorting: the isort rules of `ruff check`
lint.extend-select = [ "I" ]
lint.extend-select = [ "I", "TID252" ]
lint.isort.known-first-party = [ "cunumpy" ]

[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"
6 changes: 3 additions & 3 deletions src/cunumpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import warnings as _warnings
from importlib.metadata import PackageNotFoundError, version

from . import algorithms, cuda, kernels, memory, mpi, petsc, profiling, rng, xp
from ._scipy_backend import scipy
from .xp import (
from cunumpy import algorithms, cuda, kernels, memory, mpi, petsc, profiling, rng, xp
from cunumpy._scipy_backend import scipy
from cunumpy.xp import (
as_device_array,
assert_same_backend,
backend_info,
Expand Down
20 changes: 10 additions & 10 deletions src/cunumpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ from typing import Any
import numpy as np
from numpy import *

from . import algorithms as algorithms
from . import cuda as cuda
from . import kernels as kernels
from . import memory as memory
from . import mpi as mpi
from . import petsc as petsc
from . import profiling as profiling
from . import rng as rng
from . import xp as xp
from ._scipy_backend import scipy as scipy
from cunumpy import algorithms as algorithms
from cunumpy import cuda as cuda
from cunumpy import kernels as kernels
from cunumpy import memory as memory
from cunumpy import mpi as mpi
from cunumpy import petsc as petsc
from cunumpy import profiling as profiling
from cunumpy import rng as rng
from cunumpy import xp as xp
from cunumpy._scipy_backend import scipy as scipy

def to_numpy(array: Any) -> np.ndarray: ...
def to_cupy(array: Any) -> Any: ...
Expand Down
4 changes: 2 additions & 2 deletions src/cunumpy/_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import array_api_compat.numpy as np

from .xp import assert_same_backend, get_array_backend, get_array_module
from cunumpy.xp import assert_same_backend, get_array_backend, get_array_module


def _integer_keys(keys: Any) -> tuple[Any, Any]:
Expand Down Expand Up @@ -77,7 +77,7 @@ def cell_offsets(sorted_cells: Any, n_cells: int) -> Any:
def _sum_kernel(dtype: Any) -> Any:
name = np.dtype(dtype).name
if name not in _SUM_KERNELS:
from ._cuda_kernel import CudaKernel
from cunumpy._cuda_kernel import CudaKernel

ctype = "float" if name == "float32" else "double"
_SUM_KERNELS[name] = CudaKernel(
Expand Down
10 changes: 5 additions & 5 deletions src/cunumpy/_cuda_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ def verify_layout(
RuntimeError
If CuPy is not available.
"""
from .xp import cupy_available
from cunumpy.xp import cupy_available

if not cupy_available():
raise RuntimeError("verify_layout() compiles a CUDA kernel and needs CuPy")
Expand Down Expand Up @@ -1768,7 +1768,7 @@ def __host_args__(self) -> Any:
"or set host_copies = True for a read-only host evaluation "
"from host copies",
)
from .xp import to_numpy
from cunumpy.xp import to_numpy

value = to_numpy(value)
host_values.append(value)
Expand Down Expand Up @@ -2093,7 +2093,7 @@ def debug_active(self) -> bool:
"""
if self._debug is not None:
return self._debug
from ._device import get_cuda_debug
from cunumpy._device import get_cuda_debug

return get_cuda_debug()

Expand Down Expand Up @@ -2234,7 +2234,7 @@ def compile(self) -> Any:
If CuPy or a GPU is not available.
"""
if self._raw_kernel is None:
from .xp import cupy_available
from cunumpy.xp import cupy_available

if not cupy_available():
raise RuntimeError(
Expand Down Expand Up @@ -2403,7 +2403,7 @@ def _opt_in_shared_memory(self, kernel: Any, shared_mem: int) -> None:
attribute ``max_dynamic_shared_size_bytes``; it is set once (and again
for a larger request) up to the device's opt-in limit.
"""
from ._device import (
from cunumpy._device import (
DEFAULT_SHARED_MEMORY_PER_BLOCK,
max_shared_memory_per_block,
)
Expand Down
4 changes: 2 additions & 2 deletions src/cunumpy/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import array_api_compat.numpy as np

from ._mpi_serial import local_rank
from .xp import array_backend, cupy_available
from cunumpy._mpi_serial import local_rank
from cunumpy.xp import array_backend, cupy_available


def set_device(device_id: int) -> None:
Expand Down
10 changes: 5 additions & 5 deletions src/cunumpy/_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@

import array_api_compat

from ._cuda_kernel import CudaKernel, _compile_in_threads
from ._kernel import (
from cunumpy._cuda_kernel import CudaKernel, _compile_in_threads
from cunumpy._kernel import (
CompiledHostKernel,
HostImplementations,
PyccelKernel,
resolve_host_args,
)
from ._transfers import _ACTIVE as _COUNTERS
from ._transfers import _record
from .xp import get_backend
from cunumpy._transfers import _ACTIVE as _COUNTERS
from cunumpy._transfers import _record
from cunumpy.xp import get_backend

__all__ = ["Kernel", "KernelCatalog"]

Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

import numpy as np

from ._cuda_kernel import (
from cunumpy._cuda_kernel import (
CudaKernel,
CudaParameter,
_scalar_checker,
Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def pressure(rho, T, gamma):
import array_api_compat
import numpy

from .xp import use_backend
from cunumpy.xp import use_backend

__all__ = ["fuse"]

Expand Down
6 changes: 3 additions & 3 deletions src/cunumpy/_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import array_api_compat
import numpy as np

from ._transfers import _ACTIVE as _COUNTERS
from ._transfers import _record
from .xp import _cupy_backend, _to_cupy, _to_numpy, is_gpu, to_cupy, to_numpy
from cunumpy._transfers import _ACTIVE as _COUNTERS
from cunumpy._transfers import _record
from cunumpy.xp import _cupy_backend, _to_cupy, _to_numpy, is_gpu, to_cupy, to_numpy

__all__ = ["CompiledHostKernel", "KernelArguments", "PyccelKernel", "resolve_host_args"]

Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np

from .xp import _cupy_backend, to_cupy
from cunumpy.xp import _cupy_backend, to_cupy

__all__ = ["DeviceMirror"]

Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_morton.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import numpy as np

from ._philox import _module
from cunumpy._philox import _module

__all__ = [
"MAX_MORTON_LEVELS",
Expand Down
10 changes: 5 additions & 5 deletions src/cunumpy/_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import array_api_compat
import array_api_compat.numpy as np

from ._mpi_serial import (
from cunumpy._mpi_serial import (
_LOCAL_RANK_VARIABLES, # noqa: F401 - re-exported
)
from ._transfers import _ACTIVE as _COUNTERS
from ._transfers import _describe, _record
from .xp import array_backend, cupy_available, to_numpy
from cunumpy._transfers import _ACTIVE as _COUNTERS
from cunumpy._transfers import _describe, _record
from cunumpy.xp import array_backend, cupy_available, to_numpy

_logger = logging.getLogger(__name__)

Expand All @@ -43,7 +43,7 @@ def synchronize_for_mpi(*arrays: Any, stream: Any = None, event: Any = None) ->
devices = {a.device.id for a in arrays if array_api_compat.is_cupy_array(a)}
if not devices:
return
from ._streams import HostEvent, HostStream
from cunumpy._streams import HostEvent, HostStream

if isinstance(event, HostEvent) or isinstance(stream, HostStream):
raise TypeError("device buffers require a CUDA producer stream or event")
Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dataclasses import dataclass
from types import ModuleType

from .xp import array_backend, synchronize
from cunumpy.xp import array_backend, synchronize


def _nvtx_module() -> ModuleType | None:
Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_random_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import numpy as np

from .xp import get_backend
from cunumpy.xp import get_backend

__all__ = ["BIT_GENERATORS", "RandomStreams", "random_streams"]

Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_scipy_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from types import ModuleType
from typing import Any

from .xp import get_backend
from cunumpy.xp import get_backend

__all__ = ["SUBMODULES", "ScipyNamespace", "scipy"]

Expand Down
4 changes: 2 additions & 2 deletions src/cunumpy/_staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import array_api_compat
import numpy as np

from ._transfers import _ACTIVE as _COUNTERS
from ._transfers import _record
from cunumpy._transfers import _ACTIVE as _COUNTERS
from cunumpy._transfers import _record

__all__ = ["HostStaging", "StagedCopy"]

Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Any

from .xp import get_backend
from cunumpy.xp import get_backend


class HostEvent:
Expand Down
4 changes: 2 additions & 2 deletions src/cunumpy/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
charge = xp.algorithms.segment_sum(q, cell, n_cells)
"""

from ._algorithms import (
from cunumpy._algorithms import (
SegmentPlan,
cell_offsets,
segment_boundaries,
segment_sum,
sort_by_key,
)
from ._morton import (
from cunumpy._morton import (
MAX_MORTON_LEVELS,
morton_decode,
morton_encode,
Expand Down
6 changes: 3 additions & 3 deletions src/cunumpy/cuda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use ``import cupy; cupy.cuda`` for CuPy's module.
"""

from .._cuda_kernel import (
from cunumpy._cuda_kernel import (
DEBUG_OPTIONS,
CudaArguments,
CudaKernel,
Expand All @@ -41,7 +41,7 @@
resolve_includes,
write_cuda_header,
)
from .._device import (
from cunumpy._device import (
DEFAULT_SHARED_MEMORY_PER_BLOCK,
bind_local_device,
cuda_debug,
Expand All @@ -56,7 +56,7 @@
set_device_for_rank,
stream,
)
from .._streams import (
from cunumpy._streams import (
HostEvent,
HostStream,
create_event,
Expand Down
2 changes: 1 addition & 1 deletion src/cunumpy/cuda_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
The public names are in :mod:`cunumpy.cuda`.
"""

from ._deprecated import alias_module
from cunumpy._deprecated import alias_module

alias_module(__name__, "cunumpy._cuda_kernel", "cunumpy.cuda")
2 changes: 1 addition & 1 deletion src/cunumpy/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
The public names are in :mod:`cunumpy.kernels`.
"""

from ._deprecated import alias_module
from cunumpy._deprecated import alias_module

alias_module(__name__, "cunumpy._dispatch", "cunumpy.kernels")
2 changes: 1 addition & 1 deletion src/cunumpy/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
The public names are in :mod:`cunumpy.kernels`.
"""

from ._deprecated import alias_module
from cunumpy._deprecated import alias_module

alias_module(__name__, "cunumpy._kernel", "cunumpy.kernels")
10 changes: 5 additions & 5 deletions src/cunumpy/kernel_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_parity(name, kernel):
import array_api_compat
import numpy as np

from . import _fake_cupy
from ._cuda_kernel import (
from cunumpy import _fake_cupy
from cunumpy._cuda_kernel import (
CudaKernel,
CudaParameter,
CudaStructArguments,
Expand All @@ -66,9 +66,9 @@ def test_parity(name, kernel):
_split_top_level,
_strip_comments,
)
from ._dispatch import Kernel
from ._emulation import emulate_cuda_kernel, emulation_compiler
from .xp import cupy_available, get_backend, to_numpy, use_backend
from cunumpy._dispatch import Kernel
from cunumpy._emulation import emulate_cuda_kernel, emulation_compiler
from cunumpy.xp import cupy_available, get_backend, to_numpy, use_backend

# the pytest objects are created on first access, see __getattr__
__all__ = [
Expand Down
8 changes: 4 additions & 4 deletions src/cunumpy/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
:mod:`cunumpy.kernel_testing`.
"""

from ._cuda_kernel import PyccelStructArguments
from ._dispatch import Kernel, KernelCatalog
from ._fusion import fuse
from ._kernel import (
from cunumpy._cuda_kernel import PyccelStructArguments
from cunumpy._dispatch import Kernel, KernelCatalog
from cunumpy._fusion import fuse
from cunumpy._kernel import (
HOST_IMPLEMENTATIONS,
CompiledHostKernel,
HostImplementations,
Expand Down
4 changes: 2 additions & 2 deletions src/cunumpy/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
:mod:`cunumpy.cuda`.
"""

from ._mirror import DeviceMirror
from ._staging import HostStaging, StagedCopy
from cunumpy._mirror import DeviceMirror
from cunumpy._staging import HostStaging, StagedCopy

__all__ = ["DeviceMirror", "HostStaging", "StagedCopy"]
Loading
Loading