Class: SGC::CU::CUEvent

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.createCUEvent .create(flags) ⇒ CUEvent

Create and return an event with flags (CUEventFlags).

Examples:

Create events with flags.

CUEvent.create                    #=> event
CUEvent.create(:DEFAULT)          #=> event
CUEvent.create(:BLOCKING_SYNC)    #=> event

Returns:

  • (CUEvent)

    An event created with flags.



46
47
48
49
50
51
52
53
# File 'lib/cuda/driver/event.rb', line 46

def self.create(*flags)
    flags.empty? == false or flags = :DEFAULT
    p = FFI::MemoryPointer.new(:CUEvent)
    f = CUEventFlags.value(flags)
    status = API::cuEventCreate(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 (CUEvent) to event_end (CUEvent).

Parameters:

  • event_start (CUEvent)

    The event corresponds to the start time.

  • event_end (CUEvent)

    The event corresponds to the end time.

Returns:

  • (Numeric)

    The elapsed time in ms.



102
103
104
105
106
# File 'lib/cuda/driver/event.rb', line 102

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

Instance Method Details

#destroyObject

Destroy this event.



57
58
59
60
61
# File 'lib/cuda/driver/event.rb', line 57

def destroy
    status = API::cuEventDestroy(self.to_api)
    Pvt::handle_error(status, "Failed to destroy event.")
    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:

  • (CUStandardError)


65
66
67
68
69
70
71
72
73
74
# File 'lib/cuda/driver/event.rb', line 65

def query
    status = API::cuEventQuery(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 CUStandardError, "Error handling fails to catch this error."
end

#record(stream = 0) ⇒ CUEvent

Record this event asynchronously on stream.

Parameters:

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

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

Returns:



81
82
83
84
85
86
# File 'lib/cuda/driver/event.rb', line 81

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

#synchronizeCUEvent

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

Returns:



91
92
93
94
95
# File 'lib/cuda/driver/event.rb', line 91

def synchronize
    status = API::cuEventSynchronize(self.to_api)
    Pvt::handle_error(status, "Failed to synchronize event.")
    self
end