Class: Cumo::CUDA::Event
- Inherits:
-
Object
- Object
- Cumo::CUDA::Event
- Defined in:
- lib/cumo/cuda/event.rb
Overview
Constant Summary collapse
- LIVE =
ObjectSpace::WeakMap.new
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Class Method Summary collapse
-
.finalizer(ptr) ⇒ Object
A handle may be given out again after a destroy, so an event that is still owned by a live object is not the one this finalizer was for.
Instance Method Summary collapse
- #destroy ⇒ Object
- #done? ⇒ Boolean
-
#handle ⇒ Object
The handle of an event that has not been destroyed.
-
#initialize(blocking: false, timing: true) ⇒ Event
constructor
blocking: makes synchronize sleep rather than spin; timing: false makes a lighter event that cannot be timed.
-
#record(stream = Stream.current) ⇒ Object
Records the event on a stream, the current one by default, after everything queued on it so far.
- #synchronize ⇒ Object
Constructor Details
#initialize(blocking: false, timing: true) ⇒ Event
blocking: makes synchronize sleep rather than spin; timing: false makes a lighter event that cannot be timed.
24 25 26 27 28 29 30 31 |
# File 'lib/cumo/cuda/event.rb', line 24 def initialize(blocking: false, timing: true) flags = Runtime::CUDA_EVENT_DEFAULT flags |= Runtime::CUDA_EVENT_BLOCKING_SYNC if blocking flags |= Runtime::CUDA_EVENT_DISABLE_TIMING unless timing @ptr = Runtime.cudaEventCreateWithFlags(flags) LIVE[@ptr] = self ObjectSpace.define_finalizer(self, self.class.finalizer(@ptr)) end |
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
14 15 16 |
# File 'lib/cumo/cuda/event.rb', line 14 def ptr @ptr end |
Class Method Details
.finalizer(ptr) ⇒ Object
A handle may be given out again after a destroy, so an event that is still owned by a live object is not the one this finalizer was for.
18 19 20 |
# File 'lib/cumo/cuda/event.rb', line 18 def self.finalizer(ptr) proc { Runtime.cudaEventDestroy(ptr) rescue nil unless LIVE[ptr] } end |
Instance Method Details
#destroy ⇒ Object
56 57 58 59 60 61 |
# File 'lib/cumo/cuda/event.rb', line 56 def destroy return if @ptr.nil? Runtime.cudaEventDestroy(@ptr) ObjectSpace.undefine_finalizer(self) @ptr = nil end |
#done? ⇒ Boolean
52 53 54 |
# File 'lib/cumo/cuda/event.rb', line 52 def done? Runtime.cudaEventQuery(handle) end |
#handle ⇒ Object
The handle of an event that has not been destroyed.
34 35 36 37 |
# File 'lib/cumo/cuda/event.rb', line 34 def handle raise ArgumentError, "the event is destroyed" if @ptr.nil? @ptr end |
#record(stream = Stream.current) ⇒ Object
Records the event on a stream, the current one by default, after everything queued on it so far.
41 42 43 44 45 |
# File 'lib/cumo/cuda/event.rb', line 41 def record(stream = Stream.current) raise TypeError, "record takes a Stream, got a #{stream.class}" unless stream.is_a?(Stream) Runtime.cudaEventRecord(handle, stream.handle) self end |
#synchronize ⇒ Object
47 48 49 50 |
# File 'lib/cumo/cuda/event.rb', line 47 def synchronize Runtime.cudaEventSynchronize(handle) self end |