@@ -80,3 +80,63 @@ def test_is_done(init_cuda):
80
80
# Without a sync, the captured work might not have yet completed
81
81
# Therefore this check should never raise an exception
82
82
assert event .is_done in (True , False )
83
+
84
+
85
+ def test_error_timing_disabled ():
86
+ device = Device ()
87
+ device .set_current ()
88
+ enabled = EventOptions (enable_timing = True )
89
+ disabled = EventOptions (enable_timing = False )
90
+ stream = device .create_stream ()
91
+
92
+ event1 = stream .record (options = enabled )
93
+ event2 = stream .record (options = disabled )
94
+ stream .sync ()
95
+ with pytest .raises (RuntimeError , match = "^Both Events must be created with timing enabled" ):
96
+ event2 - event1
97
+
98
+ event1 = stream .record (options = disabled )
99
+ event2 = stream .record (options = disabled )
100
+ stream .sync ()
101
+ with pytest .raises (RuntimeError , match = "^Both Events must be created with timing enabled" ):
102
+ event2 - event1
103
+
104
+ event1 = stream .record (options = enabled )
105
+ event2 = stream .record (options = enabled )
106
+ stream .sync ()
107
+ event2 - event1
108
+
109
+
110
+ def test_error_timing_recorded ():
111
+ device = Device ()
112
+ device .set_current ()
113
+ enabled = EventOptions (enable_timing = True )
114
+ stream = device .create_stream ()
115
+
116
+ event1 = stream .record (options = enabled )
117
+ event2 = device .create_event (options = enabled )
118
+ event3 = device .create_event (options = enabled )
119
+
120
+ stream .sync ()
121
+ with pytest .raises (RuntimeError , match = "^Both Events must be recorded" ):
122
+ event2 - event1
123
+ with pytest .raises (RuntimeError , match = "^Both Events must be recorded" ):
124
+ event1 - event2
125
+ with pytest .raises (RuntimeError , match = "^Both Events must be recorded" ):
126
+ event3 - event2
127
+
128
+
129
+ def test_error_timing_incomplete ():
130
+ device = Device ()
131
+ device .set_current ()
132
+ enabled = EventOptions (enable_timing = True )
133
+ stream = device .create_stream ()
134
+
135
+ event1 = stream .record (options = enabled )
136
+ event2 = device .create_event (options = enabled )
137
+ stream .wait (event2 )
138
+ event3 = stream .record (options = enabled )
139
+
140
+ # event3 will never complete because the stream is waiting on event2 which is never recorded
141
+ with pytest .raises (RuntimeError , match = "^One or both events have not completed." ):
142
+ event3 - event1
0 commit comments