Class: Ignis::CUDA::Event
- Inherits:
-
Object
- Object
- Ignis::CUDA::Event
- Defined in:
- lib/nvruby/cuda/stream.rb
Overview
CUDA event for timing and synchronization.
Refactored to use Fiddle-based RuntimeAPI methods.
Instance Attribute Summary collapse
-
#handle ⇒ Fiddle::Pointer
readonly
Event handle.
Class Method Summary collapse
-
.elapsed_time(start_event, end_event) ⇒ Float
Calculate elapsed time between two events.
-
.release_finalizer(handle) ⇒ Proc
Create a finalizer for event cleanup.
Instance Method Summary collapse
-
#destroy! ⇒ void
Destroy the event.
- #destroyed? ⇒ Boolean
-
#initialize(blocking: false, disable_timing: false) ⇒ Event
constructor
A new instance of Event.
-
#record(stream: nil) ⇒ void
Record the event on a stream.
-
#synchronize ⇒ void
Wait for the event to complete.
- #to_ptr ⇒ Fiddle::Pointer
Constructor Details
#initialize(blocking: false, disable_timing: false) ⇒ Event
Returns a new instance of Event.
146 147 148 149 150 151 152 153 154 |
# File 'lib/nvruby/cuda/stream.rb', line 146 def initialize(blocking: false, disable_timing: false) @blocking = blocking @disable_timing = disable_timing @handle = create_event @destroyed = false captured_handle = @handle ObjectSpace.define_finalizer(self, self.class.release_finalizer(captured_handle)) end |
Instance Attribute Details
#handle ⇒ Fiddle::Pointer (readonly)
Returns Event handle.
142 143 144 |
# File 'lib/nvruby/cuda/stream.rb', line 142 def handle @handle end |
Class Method Details
.elapsed_time(start_event, end_event) ⇒ Float
Calculate elapsed time between two events.
190 191 192 193 |
# File 'lib/nvruby/cuda/stream.rb', line 190 def self.elapsed_time(start_event, end_event) RuntimeAPI.ensure_loaded! RuntimeAPI.event_elapsed_time(start_event.handle, end_event.handle) end |
.release_finalizer(handle) ⇒ Proc
Create a finalizer for event cleanup.
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/nvruby/cuda/stream.rb', line 211 def release_finalizer(handle) handle_addr = handle.to_i proc do begin RuntimeAPI.ensure_loaded! RuntimeAPI.event_destroy(Fiddle::Pointer.new(handle_addr)) rescue StandardError # Silently ignore errors during finalization end end end |
Instance Method Details
#destroy! ⇒ void
This method returns an undefined value.
Destroy the event.
197 198 199 200 201 202 203 204 205 |
# File 'lib/nvruby/cuda/stream.rb', line 197 def destroy! return if @destroyed RuntimeAPI.ensure_loaded! RuntimeAPI.event_destroy(@handle) @destroyed = true ObjectSpace.undefine_finalizer(self) end |
#destroyed? ⇒ Boolean
157 158 159 |
# File 'lib/nvruby/cuda/stream.rb', line 157 def destroyed? @destroyed end |
#record(stream: nil) ⇒ void
This method returns an undefined value.
Record the event on a stream.
164 165 166 167 168 169 170 |
# File 'lib/nvruby/cuda/stream.rb', line 164 def record(stream: nil) raise InvalidOperationError, 'Event has been destroyed' if @destroyed RuntimeAPI.ensure_loaded! stream_handle = stream&.to_ptr || Fiddle::Pointer.new(0) RuntimeAPI.event_record(@handle, stream_handle) end |
#synchronize ⇒ void
This method returns an undefined value.
Wait for the event to complete.
174 175 176 177 178 179 |
# File 'lib/nvruby/cuda/stream.rb', line 174 def synchronize raise InvalidOperationError, 'Event has been destroyed' if @destroyed RuntimeAPI.ensure_loaded! RuntimeAPI.event_synchronize(@handle) end |
#to_ptr ⇒ Fiddle::Pointer
182 183 184 |
# File 'lib/nvruby/cuda/stream.rb', line 182 def to_ptr @handle end |