Skip to content

Commit f2798cf

Browse files
committed
cuda.core: rename EventOptions to bare-adjective form (#1945)
Address review feedback on #1986: align EventOptions field names with the convention used elsewhere in the API (option name = bare adjective, property name = is_/uses_ prefix). - EventOptions.enable_timing -> EventOptions.timing_enabled (matches Event.is_timing_enabled) - EventOptions.use_blocking_sync -> EventOptions.blocking_sync (matches Event.uses_blocking_sync) Same pattern as ipc_enabled / Event.is_ipc_enabled and StreamOptions.nonblocking / Stream.is_nonblocking. Made-with: Cursor
1 parent 0c321a9 commit f2798cf

6 files changed

Lines changed: 42 additions & 49 deletions

File tree

cuda_core/cuda/core/_event.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ cdef class EventOptions:
4444
4545
Attributes
4646
----------
47-
enable_timing : bool, optional
47+
timing_enabled : bool, optional
4848
Event will record timing data. (Default to False)
49-
use_blocking_sync : bool, optional
49+
blocking_sync : bool, optional
5050
If True, the event uses blocking synchronization: a CPU
5151
thread that calls :meth:`Event.sync` blocks (yields) until
5252
the event has completed. Otherwise (the default), the CPU
5353
thread busy-waits until the event has completed.
5454
(Default to False)
5555
ipc_enabled : bool, optional
5656
Event will be suitable for interprocess use.
57-
Note that enable_timing must be False. (Default to False)
57+
Note that timing_enabled must be False. (Default to False)
5858
5959
"""
6060

61-
enable_timing: bool | None = False
62-
use_blocking_sync: bool | None = False
61+
timing_enabled: bool | None = False
62+
blocking_sync: bool | None = False
6363
ipc_enabled: bool | None = False
6464

6565

@@ -79,8 +79,8 @@ cdef class Event:
7979
8080
# To create events and record the timing:
8181
s = Device().create_stream()
82-
e1 = Device().create_event({"enable_timing": True})
83-
e2 = Device().create_event({"enable_timing": True})
82+
e1 = Device().create_event({"timing_enabled": True})
83+
e2 = Device().create_event({"timing_enabled": True})
8484
s.record(e1)
8585
# ... run some GPU works ...
8686
s.record(e2)
@@ -104,10 +104,10 @@ cdef class Event:
104104
cdef bint uses_blocking_sync = False
105105
cdef bint ipc_enabled = False
106106
self._ipc_descriptor = None
107-
if not opts.enable_timing:
107+
if not opts.timing_enabled:
108108
flags |= cydriver.CUevent_flags.CU_EVENT_DISABLE_TIMING
109109
timing_enabled = False
110-
if opts.use_blocking_sync:
110+
if opts.blocking_sync:
111111
flags |= cydriver.CUevent_flags.CU_EVENT_BLOCKING_SYNC
112112
uses_blocking_sync = True
113113
if opts.ipc_enabled:
@@ -167,7 +167,7 @@ cdef class Event:
167167
if not self.is_timing_enabled or not other.is_timing_enabled:
168168
explanation = (
169169
"Both Events must be created with timing enabled in order to subtract them; "
170-
"use EventOptions(enable_timing=True) when creating both events."
170+
"use EventOptions(timing_enabled=True) when creating both events."
171171
)
172172
else:
173173
explanation = (
@@ -244,7 +244,7 @@ cdef class Event:
244244
def sync(self):
245245
"""Synchronize until the event completes.
246246
247-
If the event was created with ``use_blocking_sync=True``, the
247+
If the event was created with ``blocking_sync=True``, the
248248
calling CPU thread blocks (yields) until the event has been
249249
completed by the device. Otherwise (the default) the CPU
250250
thread busy-waits until the event has completed.

cuda_core/docs/source/release/1.0.0-notes.rst

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,10 @@ Breaking changes
4646

4747
- ``LaunchConfig.cooperative_launch`` -> :attr:`LaunchConfig.is_cooperative`
4848
(also renames the constructor keyword argument).
49-
- ``Event.is_timing_disabled`` -> :attr:`Event.is_timing_enabled` (boolean
50-
polarity is flipped to avoid the double-negative form
51-
``not event.is_timing_disabled``).
52-
- ``Event.is_sync_busy_waited`` -> :attr:`Event.uses_blocking_sync`. The
53-
new name accurately describes the underlying ``CU_EVENT_BLOCKING_SYNC``
54-
flag: when True, the calling CPU thread blocks (yields) on
55-
:meth:`Event.sync` instead of busy-waiting. The previous name was
56-
inverted with respect to its semantics.
57-
- ``EventOptions.busy_waited_sync`` -> ``EventOptions.use_blocking_sync``
58-
(constructor keyword argument and dataclass attribute), to match the
59-
renamed :attr:`Event.uses_blocking_sync` property.
49+
- ``Event.is_timing_disabled`` -> :attr:`Event.is_timing_enabled`.
50+
- ``Event.is_sync_busy_waited`` -> :attr:`Event.uses_blocking_sync`.
51+
- ``EventOptions.enable_timing`` -> ``EventOptions.timing_enabled``
52+
and ``EventOptions.busy_waited_sync`` -> ``EventOptions.blocking_sync``.
6053

6154
- Renamed graph allocation methods to match :meth:`MemoryResource.allocate` /
6255
:meth:`MemoryResource.deallocate`
@@ -115,10 +108,10 @@ Breaking changes
115108
``if_else``, ``while_loop``, and ``switch`` methods (verb describing the
116109
control-flow construct, not an abbreviation of "condition") and matches
117110
Python's own ``if/then/else`` vocabulary.
118-
- :class:`~graph.GraphCondition` now defines ``__int__`` returning the
119-
underlying ``CUgraphConditionalHandle`` value, so a condition may be
120-
passed directly as a kernel argument to ``launch()`` without first
121-
extracting ``.handle``.
111+
- A :class:`~graph.GraphCondition` may be passed directly as a kernel
112+
argument to ``launch()``; the launcher unwraps it to the underlying
113+
``CUgraphConditionalHandle`` value. Previously, ``.handle`` had to be
114+
extracted explicitly.
122115

123116

124117
Fixes and enhancements

cuda_core/tests/graph/test_graph_definition_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ def _run_heat_graph(dev, k_heat, k_countdown, host_ptr):
215215
# Definitions
216216
g = GraphDefinition()
217217
condition = g.create_condition(default_value=1)
218-
event_start = dev.create_event(EventOptions(enable_timing=True))
219-
event_end = dev.create_event(EventOptions(enable_timing=True))
218+
event_start = dev.create_event(EventOptions(timing_enabled=True))
219+
event_end = dev.create_event(EventOptions(timing_enabled=True))
220220
results = {}
221221

222222
def capture_result():

cuda_core/tests/graph/test_graph_definition_lifetime.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_event_record_node_keeps_event_alive(init_cuda):
174174
g = GraphDefinition()
175175
alloc = g.allocate(1024)
176176

177-
event = dev.create_event(EventOptions(enable_timing=False))
177+
event = dev.create_event(EventOptions(timing_enabled=False))
178178
node = alloc.record(event)
179179

180180
del event
@@ -191,7 +191,7 @@ def test_event_wait_node_keeps_event_alive(init_cuda):
191191
g = GraphDefinition()
192192
alloc = g.allocate(1024)
193193

194-
event = dev.create_event(EventOptions(enable_timing=False))
194+
event = dev.create_event(EventOptions(timing_enabled=False))
195195
node = alloc.wait(event)
196196

197197
del event
@@ -206,7 +206,7 @@ def test_event_record_node_preserves_metadata(init_cuda):
206206
dev = Device()
207207
g = GraphDefinition()
208208

209-
event = dev.create_event(EventOptions(enable_timing=True, use_blocking_sync=True))
209+
event = dev.create_event(EventOptions(timing_enabled=True, blocking_sync=True))
210210
node = g.record(event)
211211

212212
reconstructed = node.event
@@ -221,7 +221,7 @@ def test_event_wait_node_preserves_metadata(init_cuda):
221221
dev = Device()
222222
g = GraphDefinition()
223223

224-
event = dev.create_event(EventOptions(enable_timing=False))
224+
event = dev.create_event(EventOptions(timing_enabled=False))
225225
node = g.wait(event)
226226

227227
reconstructed = node.event
@@ -235,7 +235,7 @@ def test_event_metadata_survives_gc(init_cuda):
235235
dev = Device()
236236
g = GraphDefinition()
237237

238-
event = dev.create_event(EventOptions(enable_timing=True, use_blocking_sync=True))
238+
event = dev.create_event(EventOptions(timing_enabled=True, blocking_sync=True))
239239
node = g.record(event)
240240

241241
del event
@@ -252,7 +252,7 @@ def test_event_survives_graph_instantiation_and_execution(init_cuda):
252252
dev = Device()
253253
g = GraphDefinition()
254254

255-
event = dev.create_event(EventOptions(enable_timing=False))
255+
event = dev.create_event(EventOptions(timing_enabled=False))
256256
rec = g.record(event)
257257
rec.wait(event)
258258

@@ -277,7 +277,7 @@ def test_event_survives_graph_clone_and_execution(init_cuda):
277277
dev = Device()
278278
g = GraphDefinition()
279279

280-
event = dev.create_event(EventOptions(enable_timing=False))
280+
event = dev.create_event(EventOptions(timing_enabled=False))
281281
rec = g.record(event)
282282
rec.wait(event)
283283

cuda_core/tests/memory_ipc/test_event_ipc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_event_is_monadic(ipc_device):
114114

115115
@pytest.mark.flaky(reruns=2)
116116
@pytest.mark.parametrize(
117-
"options", [{"ipc_enabled": True, "enable_timing": True}, EventOptions(ipc_enabled=True, enable_timing=True)]
117+
"options", [{"ipc_enabled": True, "timing_enabled": True}, EventOptions(ipc_enabled=True, timing_enabled=True)]
118118
)
119119
def test_event_timing_disabled(ipc_device, options):
120120
"""Check that IPC-enabled events cannot be created with timing enabled."""
@@ -131,10 +131,10 @@ class TestIpcEventProperties:
131131
"""
132132

133133
@pytest.mark.flaky(reruns=2)
134-
@pytest.mark.parametrize("use_blocking_sync", [True, False])
134+
@pytest.mark.parametrize("blocking_sync", [True, False])
135135
@pytest.mark.parametrize("use_options_cls", [True, False])
136136
@pytest.mark.parametrize("use_option_kw", [True, False])
137-
def test_main(self, ipc_device, use_blocking_sync, use_options_cls, use_option_kw):
137+
def test_main(self, ipc_device, blocking_sync, use_options_cls, use_option_kw):
138138
device = ipc_device
139139
stream = device.create_stream()
140140

@@ -145,9 +145,9 @@ def test_main(self, ipc_device, use_blocking_sync, use_options_cls, use_option_k
145145

146146
# Create an event and send it.
147147
options = (
148-
EventOptions(ipc_enabled=True, use_blocking_sync=use_blocking_sync)
148+
EventOptions(ipc_enabled=True, blocking_sync=blocking_sync)
149149
if use_options_cls
150-
else {"ipc_enabled": True, "use_blocking_sync": use_blocking_sync}
150+
else {"ipc_enabled": True, "blocking_sync": blocking_sync}
151151
)
152152
e = stream.record(options=options) if use_option_kw else stream.record(None, options)
153153
q_out.put(e)

cuda_core/tests/test_event.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_event_init_disabled():
2323

2424
@pytest.mark.skipif(Device().compute_capability.major < 7, reason="__nanosleep is only available starting Volta (sm70)")
2525
def test_timing_success(init_cuda):
26-
options = EventOptions(enable_timing=True)
26+
options = EventOptions(timing_enabled=True)
2727
device = Device()
2828
stream = device.create_stream()
2929

@@ -49,27 +49,27 @@ def test_timing_success(init_cuda):
4949

5050

5151
def test_uses_blocking_sync(init_cuda):
52-
options = EventOptions(enable_timing=False, use_blocking_sync=True)
52+
options = EventOptions(timing_enabled=False, blocking_sync=True)
5353
stream = Device().create_stream()
5454
event = stream.record(options=options)
5555
assert event.uses_blocking_sync is True
5656

57-
options = EventOptions(enable_timing=False)
57+
options = EventOptions(timing_enabled=False)
5858
stream = Device().create_stream()
5959
event = stream.record(options=options)
6060
assert event.uses_blocking_sync is False
6161

6262

6363
def test_sync(init_cuda):
64-
options = EventOptions(enable_timing=False)
64+
options = EventOptions(timing_enabled=False)
6565
stream = Device().create_stream()
6666
event = stream.record(options=options)
6767
event.sync()
6868
assert event.is_done is True
6969

7070

7171
def test_is_done(init_cuda):
72-
options = EventOptions(enable_timing=False)
72+
options = EventOptions(timing_enabled=False)
7373
stream = Device().create_stream()
7474
event = stream.record(options=options)
7575
# Without a sync, the captured work might not have yet completed
@@ -80,8 +80,8 @@ def test_is_done(init_cuda):
8080
def test_error_timing_disabled():
8181
device = Device()
8282
device.set_current()
83-
enabled = EventOptions(enable_timing=True)
84-
disabled = EventOptions(enable_timing=False)
83+
enabled = EventOptions(timing_enabled=True)
84+
disabled = EventOptions(timing_enabled=False)
8585
stream = device.create_stream()
8686

8787
event1 = stream.record(options=enabled)
@@ -102,7 +102,7 @@ def test_error_timing_disabled():
102102
def test_error_timing_recorded():
103103
device = Device()
104104
device.set_current()
105-
enabled = EventOptions(enable_timing=True)
105+
enabled = EventOptions(timing_enabled=True)
106106
stream = device.create_stream()
107107

108108
event1 = stream.record(options=enabled)
@@ -123,7 +123,7 @@ def test_error_timing_incomplete():
123123
device = Device()
124124
device.set_current()
125125
latch = LatchKernel(device)
126-
enabled = EventOptions(enable_timing=True)
126+
enabled = EventOptions(timing_enabled=True)
127127
stream = device.create_stream()
128128

129129
event1 = stream.record(options=enabled)

0 commit comments

Comments
 (0)