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

from __future__ import annotations

from collections import namedtuple
from typing import Any, Callable

from cuda.bindings import cydriver
from cuda.bindings import driver as driver
from cuda.bindings import nvrtc as nvrtc
from cuda.bindings import runtime as runtime


class CUDAError(Exception):
    ...

class NVRTCError(CUDAError):
    ...

class Transaction:
    """
    A context manager for transactional operations with undo capability.

    The Transaction class allows you to register undo actions (callbacks) that will be executed
    if the transaction is not committed before exiting the context. This is useful for managing
    resources or operations that need to be rolled back in case of errors or early exits.

    Usage:
        with Transaction() as txn:
            txn.append(some_cleanup_function, arg1, arg2)
            # ... perform operations ...
            txn.commit()  # Disarm undo actions; nothing will be rolled back on exit

    Methods:
        append(fn, *args, **kwargs): Register an undo action to be called on rollback.
        commit(): Disarm all undo actions; nothing will be rolled back on exit.
    """

    def __init__(self) -> None:
        ...

    def __enter__(self):
        ...

    def __exit__(self, exc_type, exc, tb):
        ...

    def append(self, fn: Callable[..., Any], /, *args: Any, **kwargs) -> None:
        """
        Register an undo action (runs if the with-block exits without commit()).
        Values are bound now via partial so late mutations don't bite you.
        """

    def commit(self) -> None:
        """
        Disarm all undo actions. After this, exiting the with-block does nothing.
        """
_keep_driver_in_stub: 'driver.CUresult'
_keep_nvrtc_in_stub: 'nvrtc.nvrtcResult'
_keep_runtime_in_stub: 'runtime.cudaError_t'
ComputeCapability = namedtuple('ComputeCapability', ('major', 'minor'))
_fork_warning_checked = False

def _check_driver_error(error: cydriver.CUresult) -> int:
    ...

def _check_runtime_error(error) -> int:
    ...

def _check_nvrtc_error(error, handle=None) -> int:
    ...

def check_or_create_options(cls: type, options: object, options_description: str='', keep_none: bool=False) -> object:
    """
    Create the specified options dataclass from a dictionary of options or None.
    """

def _parse_fill_value(value) -> tuple:
    """Parse a fill/memset value into (raw_value, element_size).

    Parameters
    ----------
    value : int or buffer-protocol object
        - int: Must be in range [0, 256). Treated as 1-byte fill.
        - bytes or buffer-protocol: Must be 1, 2, or 4 bytes.

    Returns
    -------
    tuple of (int, int)
        (raw_value, element_size) where element_size is 1, 2, or 4.

    Raises
    ------
    OverflowError
        If int value is outside [0, 256).
    TypeError
        If value is not an int and does not support the buffer protocol.
    ValueError
        If value byte length is not 1, 2, or 4.
    """

def cast_to_3_tuple(label: str, cfg: int | tuple[int, ...]) -> tuple[int, int, int]:
    ...

def handle_return(result: tuple[Any, ...], handle: object=None) -> Any:
    ...

def _handle_boolean_option(option: bool) -> str:
    """
    Convert a boolean option to a string representation.
    """

def precondition(checker: Callable[..., None], what: str='') -> Callable[..., Any]:
    """
    A decorator that adds checks to ensure any preconditions are met.

    Args:
        checker: The function to call to check whether the preconditions are met. It has
        the same signature as the wrapped function with the addition of the keyword argument `what`.
        what: A string that is passed in to `checker` to provide context information.

    Returns:
        Callable: A decorator that creates the wrapping.
    """

def is_sequence(obj: object) -> bool:
    """
    Check if the given object is a sequence (list or tuple).
    """

def is_nested_sequence(obj: object) -> bool:
    """
    Check if the given object is a nested sequence (list or tuple with atleast one list or tuple element).
    """

def reset_fork_warning() -> None:
    """Reset the fork warning check flag for testing purposes.

    This function is intended for use in tests to allow multiple test runs
    to check the warning behavior.
    """

def check_multiprocessing_start_method() -> None:
    """Check if multiprocessing start method is 'fork' and warn if so."""