Class: SGC::Cuda::CudaEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/cuda/runtime/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.createCudaEvent .create(flags) ⇒ CudaEvent

Create and return an event with flags.

Returns:

  • (CudaEvent)

    An event created with flags.



38
39
40
41
42
43
44
45
# File 'lib/cuda/runtime/event.rb', line 38

def self.create(*flags)
    flags.empty? == false or flags = :DEFAULT
    p = FFI::MemoryPointer.new(:CudaEvent)
    f = CudaEventFlags.value(flags)
    status = API::cudaEventCreateWithFlags(p, f)
    Pvt::handle_error(status, "Failed to create event: flags = #{flags}")
    new(p)
end

.elapsed_time(event_start, event_end) ⇒ Numeric

Compute the elapsed time (ms) from event_start to event_end.

Parameters:

  • event_start (CudaEvent)

    The event corresponds to the start time.

  • event_end (CudaEvent)

    The event corresponds to the end time.

Returns:

  • (Numeric)

    The elapsed time in ms.



95
96
97
98
99
# File 'lib/cuda/runtime/event.rb', line 95

def self.elapsed_time(event_start, event_end)
    t = FFI::MemoryPointer.new(:float)
    API::cudaEventElapsedTime(t, event_start.to_api, event_end.to_api)
    t.read_float
end

Instance Method Details

#destroyObject

Destroy this event.



49
50
51
52
53
54
# File 'lib/cuda/runtime/event.rb', line 49

def destroy
    status = API::cudaEventDestroy(self.to_api)
    Pvt::handle_error(status, "Failed to destroy event.")
    API::write_cudaevent(@pevent, 0)
    nil
end

#queryBoolean

Return true if this event has been recorded. Otherwise, return false.

Returns:

  • (Boolean)

    Return true if this event has been recorded. Otherwise, return false.

Raises:

  • (CudaStandardError)


58
59
60
61
62
63
64
65
66
67
# File 'lib/cuda/runtime/event.rb', line 58

def query
    status = API::cudaEventQuery(self.to_api)
    if status == Pvt::CUDA_SUCCESS
        return true
    elsif status == Pvt::CUDA_ERROR_NOT_READY
        return false
    end
    Pvt::handle_error(status, "Failed to query event.")
    raise CudaStandardError, "Error handling fails to catch this error."
end

#record(stream = 0) ⇒ CudaEvent

Record this event asynchronously on stream.

Parameters:

  • stream (Integer, CudaStream) (defaults to: 0)

    The CUDA stream to record this event on. Setting stream on anything other than an instance of CudaStream will record on any stream.

Returns:



74
75
76
77
78
79
# File 'lib/cuda/runtime/event.rb', line 74

def record(stream = 0)
    s = Pvt::parse_stream(stream)
    status = API::cudaEventRecord(self.to_api, s)
    Pvt::handle_error(status, "Failed to record event.")
    self
end

#synchronizeCudaEvent

Block the calling CPU thread until this event has been recorded.

Returns:



84
85
86
87
88
# File 'lib/cuda/runtime/event.rb', line 84

def synchronize
    status = API::cudaEventSynchronize(self.to_api)
    Pvt::handle_error(status)
    self
end