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 cuda_core/cuda/core/_launcher.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# This file was generated by stubgen-pyx v0.2.23 from cuda_core/cuda/core/_launcher.pyx

from collections.abc import Callable

from cuda.core._launch_config import LaunchConfig
from cuda.core._module import Kernel
from cuda.core._stream import Stream
from cuda.core._utils.pycompat import BufferProtocol
from cuda.core.graph import GraphBuilder
from cuda.core.typing import IsStreamType

Expand All @@ -27,7 +30,7 @@ def launch(stream: Stream | GraphBuilder | IsStreamType, config: LaunchConfig, k
launching kernel.

"""
def host_launch(stream: Stream | GraphBuilder | IsStreamType, fn, *, user_data=None) -> None:
def host_launch(stream: Stream | GraphBuilder | IsStreamType, fn: Callable[..., object], *, user_data: int | BufferProtocol | None=None) -> None:
"""Enqueue a host function on a stream in stream order.

The function runs on a driver-owned thread once all work enqueued on the
Expand Down
5 changes: 4 additions & 1 deletion cuda_core/cuda/core/_launcher.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ from math import prod
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Callable

from cuda.core._utils.pycompat import BufferProtocol
from cuda.core.graph import GraphBuilder
from cuda.core.typing import IsStreamType

Expand Down Expand Up @@ -70,7 +73,7 @@ def launch(
HANDLE_RETURN(cydriver.cuLaunchKernelEx(&drv_cfg, func_handle, args_ptr, NULL))


def host_launch(stream: Stream | GraphBuilder | IsStreamType, fn, *, user_data=None) -> None:
def host_launch(stream: Stream | GraphBuilder | IsStreamType, fn: Callable[..., object], *, user_data: int | BufferProtocol | None = None) -> None:
"""Enqueue a host function on a stream in stream order.

The function runs on a driver-owned thread once all work enqueued on the
Expand Down
4 changes: 3 additions & 1 deletion cuda_core/cuda/core/graph/_graph_builder.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# This file was generated by stubgen-pyx v0.2.23 from cuda_core/cuda/core/graph/_graph_builder.pyx

from collections.abc import Callable
from dataclasses import dataclass
from typing import overload

from cuda.core._stream import Stream
from cuda.core._utils.cuda_utils import driver
from cuda.core._utils.pycompat import BufferProtocol
from cuda.core.graph._graph_definition import GraphCondition, GraphDefinition
from cuda.core.graph._subclasses import (ChildGraphNode, EventRecordNode,
EventWaitNode,
Expand Down Expand Up @@ -408,7 +410,7 @@ class GraphBuilder:
child : :obj:`~graph.GraphBuilder`
The child graph builder. Must have finished building.
"""
def callback(self, fn, *, user_data=None) -> None:
def callback(self, fn: Callable[..., object], *, user_data: int | BufferProtocol | None=None) -> None:
"""Add a host callback to the graph during stream capture.

The callback runs on the host CPU when the graph reaches this point
Expand Down
5 changes: 4 additions & 1 deletion cuda_core/cuda/core/graph/_graph_builder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ from cuda.core._utils.cuda_utils import (
)

if TYPE_CHECKING:
from collections.abc import Callable
from typing import overload

from cuda.core._utils.pycompat import BufferProtocol

from cuda.core.graph._graph_definition import GraphDefinition
else:
# Cython applies a method decorator by rebinding the type's dict entry, so
Expand Down Expand Up @@ -947,7 +950,7 @@ cdef class GraphBuilder:
)
)

def callback(self, fn, *, user_data=None) -> None:
def callback(self, fn: Callable[..., object], *, user_data: int | BufferProtocol | None = None) -> None:
"""Add a host callback to the graph during stream capture.

The callback runs on the host CPU when the graph reaches this point
Expand Down
5 changes: 4 additions & 1 deletion cuda_core/cuda/core/graph/_graph_definition.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# This file was generated by stubgen-pyx v0.2.23 from cuda_core/cuda/core/graph/_graph_definition.pyx

"""GraphDefinition: explicit CUDA graph definition."""
from collections.abc import Callable

from cuda.core._device import Device
from cuda.core._event import Event
from cuda.core._launch_config import LaunchConfig
from cuda.core._memory._buffer import Buffer
from cuda.core._module import Kernel
from cuda.core._utils.cuda_utils import driver
from cuda.core._utils.pycompat import BufferProtocol
from cuda.core.graph._graph_builder import (Graph, GraphCompleteOptions,
GraphDebugPrintOptions)
from cuda.core.graph._graph_node import GraphNode
Expand Down Expand Up @@ -127,7 +130,7 @@ class GraphDefinition:

See :meth:`GraphNode.wait` for full documentation.
"""
def callback(self, fn, *, user_data=None) -> HostCallbackNode:
def callback(self, fn: Callable[..., object], *, user_data: int | BufferProtocol | None=None) -> HostCallbackNode:
"""Add an entry-point host callback node (no dependencies).

See :meth:`GraphNode.callback` for full documentation.
Expand Down
5 changes: 4 additions & 1 deletion cuda_core/cuda/core/graph/_graph_definition.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ from cuda.core._utils.cuda_utils import driver
from cuda.core.typing import GraphMemoryType

if TYPE_CHECKING:
from collections.abc import Callable

from cuda.core._device import Device
from cuda.core._event import Event
from cuda.core._launch_config import LaunchConfig
from cuda.core._memory._buffer import Buffer
from cuda.core._module import Kernel
from cuda.core._utils.pycompat import BufferProtocol
from cuda.core.graph._graph_builder import (
Graph,
GraphCompleteOptions,
Expand Down Expand Up @@ -250,7 +253,7 @@ cdef class GraphDefinition:
"""
return self._entry.wait(event)

def callback(self, fn, *, user_data=None) -> HostCallbackNode:
def callback(self, fn: Callable[..., object], *, user_data: int | BufferProtocol | None = None) -> HostCallbackNode:
"""Add an entry-point host callback node (no dependencies).

See :meth:`GraphNode.callback` for full documentation.
Expand Down
5 changes: 3 additions & 2 deletions cuda_core/cuda/core/graph/_graph_node.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

"""GraphNode base class — factory, properties, and builder methods."""
import weakref
from collections.abc import Iterable
from collections.abc import Callable, Iterable

from cuda.core._device import Device
from cuda.core._event import Event
from cuda.core._launch_config import LaunchConfig
from cuda.core._memory._buffer import Buffer
from cuda.core._module import Kernel
from cuda.core._utils.cuda_utils import driver
from cuda.core._utils.pycompat import BufferProtocol
from cuda.core.graph._adjacency_set_proxy import AdjacencySetProxy
from cuda.core.graph._graph_definition import GraphCondition, GraphDefinition
from cuda.core.graph._subclasses import (AllocNode, ChildGraphNode, EmptyNode,
Expand Down Expand Up @@ -297,7 +298,7 @@ class GraphNode:
EventWaitNode
A new EventWaitNode representing the event wait operation.
"""
def callback(self, fn, *, user_data=None) -> object:
def callback(self, fn: Callable[..., object], *, user_data: int | BufferProtocol | None=None) -> object:
"""Add a host callback node depending on this node.

The callback runs on the host CPU when the graph reaches this node.
Expand Down
5 changes: 4 additions & 1 deletion cuda_core/cuda/core/graph/_graph_node.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ from cuda.core._utils.cuda_utils import driver
from cuda.core.typing import GraphMemoryType

if TYPE_CHECKING:
from collections.abc import Callable

from cuda.core._device import Device
from cuda.core._utils.pycompat import BufferProtocol

__all__ = ['GraphNode']

Expand Down Expand Up @@ -495,7 +498,7 @@ cdef class GraphNode:
"""
return GN_wait_event(self, event)

def callback(self, fn, *, user_data=None) -> object:
def callback(self, fn: Callable[..., object], *, user_data: int | BufferProtocol | None = None) -> object:
"""Add a host callback node depending on this node.

The callback runs on the host CPU when the graph reaches this node.
Expand Down
2 changes: 1 addition & 1 deletion cuda_core/examples/host_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ################################################################################

# /// script
# dependencies = ["cuda_bindings", "cuda_core"]
# dependencies = ["cuda_core"]

@coderabbitai coderabbitai Bot Oct 30, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major · Stability & Availability · Quick win

important: Restore the example’s runtime dependencies.

In an isolated script environment, cuda_core alone does not install cuda-bindings, and importing cuda.core raises ImportError. Select a compatible extra such as cuda_core[cu12] or cuda_core[cu13]. (raw.githubusercontent.com)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change originated from this comment. @mdboom do you agree with coderabbit that the cuda_bindings dependency is required after all?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codex GPT-6.1-Sol ultra agrees with CodeRabbit:

One finding: [P2] Removing cuda_bindings breaks isolated execution of the example (line 13). Plain cuda-core does not install bindings; those come through the optional cu12/cu13 extras. Importing cuda.core explicitly requires them.

So I agree with CodeRabbit’s linked comment. Whether the script imports bindings directly doesn’t determine its complete runtime dependencies. I’d restore the original dependency list; selecting cuda_core[cu12] or [cu13] is another option if choosing a CUDA major is intended.

No other findings. The annotations match the callback implementation, all four stubs agree with their sources, and annotation_typing=False preserves runtime argument handling.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

# ///

import ctypes
Expand Down
Loading