Skip to content

NEW: Create an Event without recording to Stream #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 5, 2025
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
24 changes: 23 additions & 1 deletion cuda_core/cuda/core/experimental/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

import threading
from typing import Union
from typing import Optional, Union

from cuda.core.experimental._context import Context, ContextOptions
from cuda.core.experimental._event import Event, EventOptions
from cuda.core.experimental._memory import Buffer, MemoryResource, _DefaultAsyncMempool, _SynchronousMemoryResource
from cuda.core.experimental._stream import Stream, StreamOptions, default_stream
from cuda.core.experimental._utils import ComputeCapability, CUDAError, driver, handle_return, precondition, runtime
Expand Down Expand Up @@ -1198,6 +1199,27 @@ def create_stream(self, obj=None, options: StreamOptions = None) -> Stream:
"""
return Stream._init(obj=obj, options=options)

@precondition(_check_context_initialized)
def create_event(self, options: Optional[EventOptions] = None) -> Event:
"""Create an Event object without recording it to a Stream.

Note
----
Device must be initialized.

Parameters
----------
options : :obj:`EventOptions`, optional
Customizable dataclass for event creation options.

Returns
-------
:obj:`~_event.Event`
Newly created event object.

"""
return Event._init(options)

@precondition(_check_context_initialized)
def allocate(self, size, stream=None) -> Buffer:
"""Allocate device memory from a specified stream.
Expand Down
1 change: 1 addition & 0 deletions cuda_core/docs/source/release/0.2.0-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ New features
- Expose :class:`ObjectCode` as a public API, which allows loading cubins from memory or disk. For loading other kinds of code types, please continue using :class:`Program`.
- A C++ helper function ``get_cuda_native_handle()`` is provided in the new ``include/utility.cuh`` header to retrive the underlying CUDA C objects (ex: ``CUstream``) from a Python object returned by the ``.handle`` attribute (ex: :attr:`Stream.handle`).
- For objects such as :class:`Program` and :class:`Linker` that could dispatch to different backends, a new ``.backend`` attribute is provided to query this information.
- An :class:`~_event.Event` may now be created without recording it to a :class:`Stream` using the :meth:`Device.create_event`` method.

Limitations
-----------
Expand Down
7 changes: 7 additions & 0 deletions cuda_core/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def test_device_create_stream(init_cuda):
assert stream.handle


def test_device_create_event(init_cuda):
device = Device()
event = device.create_event()
assert event is not None
assert event.handle


def test_pci_bus_id():
device = Device()
bus_id = handle_return(runtime.cudaDeviceGetPCIBusId(13, device.device_id))
Expand Down
Loading