# This file was generated by stubgen-pyx v0.2.6 from cuda_core/cuda/core/_device_resources.pyx

from __future__ import annotations

from collections.abc import Sequence as SequenceABC
from dataclasses import dataclass

from cuda.core._device import Device
from cuda.core.typing import WorkqueueSharingScopeType


@dataclass
class SMResourceOptions:
    """Customizable :obj:`SMResource.split` options.

    Each field accepts a scalar (for a single group) or a ``Sequence``
    (for multiple groups). ``count`` drives the number of groups; other
    ``Sequence`` fields must match its length.

    Attributes
    ----------
    count : int or Sequence[int], optional
        Requested SM count per group. ``None`` means discovery mode
        (auto-detect). (Default to ``None``)
    coscheduled_sm_count : int or Sequence[int], optional
        Minimum number of SMs guaranteed to be co-scheduled in each
        group. (Default to ``None``)
    preferred_coscheduled_sm_count : int or Sequence[int], optional
        Preferred co-scheduled SM count; the driver tries to satisfy
        this but may fall back to ``coscheduled_sm_count``.
        (Default to ``None``)
    backfill : bool or Sequence[bool], optional
        If ``True``, allow the driver to relax the co-scheduling
        constraint when assigning SMs. This enables requesting
        arbitrary aligned SM counts that the driver would otherwise
        reject due to hardware topology constraints.
        (Default to ``False``)
    """
    count: int | SequenceABC[int] | None = None
    coscheduled_sm_count: int | SequenceABC[int] | None = None
    preferred_coscheduled_sm_count: int | SequenceABC[int] | None = None
    backfill: bool | SequenceABC[bool] = False

@dataclass
class WorkqueueResourceOptions:
    """Customizable :obj:`WorkqueueResource.configure` options.

    Attributes
    ----------
    sharing_scope : :class:`~cuda.core.typing.WorkqueueSharingScopeType` | str, optional
        Workqueue sharing scope. Accepted values: ``"device_ctx"`` or
        ``"green_ctx_balanced"``.
    concurrency_limit : int, optional
        Expected maximum number of concurrent stream-ordered
        workloads. Must be ``>= 1`` when set. The effective
        driver-side cap is ``CUDA_DEVICE_MAX_CONNECTIONS``
        (typically ``[1, 32]``); configurations may exceed
        this cap, but the driver will not guarantee that work
        submission remains non-overlapping. (Default to ``None``)
    """
    sharing_scope: WorkqueueSharingScopeType | str | None = None
    concurrency_limit: int | None = None

    def __post_init__(self):
        ...

class SMResource:
    """Represent an SM (streaming multiprocessor) resource partition.

    Instances are returned by :obj:`DeviceResources.sm` or
    :meth:`SMResource.split` and cannot be instantiated directly.
    """

    def __init__(self, *args, **kwargs):
        ...

    @property
    def handle(self) -> int:
        """Return the address of the underlying ``CUdevResource`` struct."""

    @property
    def sm_count(self) -> int:
        """Total SMs available in this resource."""

    @property
    def min_partition_size(self) -> int:
        """Minimum SM count required to create a partition."""

    @property
    def coscheduled_alignment(self) -> int:
        """Number of SMs guaranteed to be co-scheduled."""

    @property
    def flags(self) -> int:
        """Raw flags from the underlying SM resource."""

    def split(self, options: SMResourceOptions, *, dry_run: bool=False) -> tuple[list[SMResource], SMResource]:
        """Split this SM resource into groups and a remainder.

        Parameters
        ----------
        options : :obj:`SMResourceOptions`
            Split configuration (count, co-scheduling constraints).
        dry_run : bool, optional
            If ``True``, return filled-in metadata without creating
            usable resource objects. (Default to ``False``)

        Returns
        -------
        tuple[list[:obj:`SMResource`], :obj:`SMResource`]
            ``(groups, remainder)`` where each group holds a disjoint
            SM partition and *remainder* holds any unassigned SMs.
        """

class WorkqueueResource:
    """Represent a workqueue resource for a device or green context.

    Merges ``CU_DEV_RESOURCE_TYPE_WORKQUEUE_CONFIG`` and
    ``CU_DEV_RESOURCE_TYPE_WORKQUEUE`` under one user-facing type.
    Instances are returned by :obj:`DeviceResources.workqueue` and
    cannot be instantiated directly.
    """

    def __init__(self, *args, **kwargs) -> None:
        ...

    @property
    def handle(self) -> int:
        """Return the address of the underlying config ``CUdevResource`` struct."""

    @property
    def sharing_scope(self) -> WorkqueueSharingScopeType:
        """Current sharing scope of this workqueue resource.

        Returns the :class:`~cuda.core.typing.WorkqueueSharingScopeType`
        member corresponding to the driver-populated
        ``wqConfig.sharingScope`` field. It can be updated via
        :meth:`configure` with
        :attr:`WorkqueueResourceOptions.sharing_scope`.
        """

    @property
    def concurrency_limit(self) -> int:
        """Current expected maximum concurrent stream-ordered workloads.

        Reflects the driver-populated ``wqConfig.wqConcurrencyLimit`` field.
        When first queried from a device, this matches the driver-reported
        cap (typically ``CUDA_DEVICE_MAX_CONNECTIONS``). It can be updated
        via :meth:`configure` with
        :attr:`WorkqueueResourceOptions.concurrency_limit`.
        """

    @property
    def device(self) -> Device:
        """The :class:`~cuda.core.Device` this workqueue resource is available on."""

    def configure(self, options: WorkqueueResourceOptions) -> None:
        """Configure the workqueue resource in place.

        Parameters
        ----------
        options : :obj:`WorkqueueResourceOptions`
            Configuration options (sharing scope, concurrency limit).
        """

class DeviceResources:
    """Namespace for hardware resource queries.

    When obtained via :obj:`Device.resources`, queries return full device
    resources. When obtained via :obj:`Context.resources` or
    :obj:`Stream.resources`, queries return the resources provisioned for
    that context.

    This class cannot be instantiated directly.
    """

    def __init__(self, *args, **kwargs) -> None:
        ...

    @property
    def sm(self) -> SMResource:
        """Return the :obj:`SMResource` for this device or context."""

    @property
    def workqueue(self) -> WorkqueueResource:
        """Return the :obj:`WorkqueueResource` for this device or context."""
__all__ = ['DeviceResources', 'SMResource', 'SMResourceOptions', 'WorkqueueResource', 'WorkqueueResourceOptions']