Class: SGC::CU::CUStream

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.createCUStream .create(flags) ⇒ CUStream

Create and return a stream with flags.

Parameters:

  • flags (Integer) (defaults to: 0)

    Currently flags must be set to zero.

Returns:

  • (CUStream)

    A CUDA stream created with flags.



39
40
41
42
43
44
# File 'lib/cuda/driver/stream.rb', line 39

def self.create(flags = 0)
    p = FFI::MemoryPointer.new(:CUStream)
    status = API::cuStreamCreate(p, flags)
    Pvt::handle_error(status, "Failed to create stream: flags = #{flags}.")
    new(p)
end

.wait_event(event) ⇒ Object .wait_event(event, flags) ⇒ Object

Let all future operations submitted to any stream in this context wait until event (CUEvent) complete before beginning execution.

Parameters:

  • event (CUEvent)

    The event to wait for.

  • flags (Integer) (defaults to: 0)

    Currently flags must be set to zero.



94
95
96
97
98
# File 'lib/cuda/driver/stream.rb', line 94

def self.wait_event(event, flags = 0)
    status = API::cuStreamWaitEvent(nil, event.to_api, flags)
    Pvt::handle_error(status, "Failed to make any stream's future operations to wait event: flags = #{flags}.")
    nil
end

Instance Method Details

#destroyObject

Destroy this CUDA stream.



48
49
50
51
52
# File 'lib/cuda/driver/stream.rb', line 48

def destroy
    status = API::cuStreamDestroy(self.to_api)
    Pvt::handle_error(status, "Failed to destroy stream.")
    nil
end

#queryBoolean

Return true if all operations in this CUDA stream have completed. Otherwise, return false.

Returns:

  • (Boolean)

    Return true if all operations in this CUDA stream have completed. Otherwise, return false.

Raises:

  • (CUStandardError)


56
57
58
59
60
61
62
63
64
65
# File 'lib/cuda/driver/stream.rb', line 56

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

#synchronizeCUStream

Block the calling CPU thread until all operations in this CUDA stream complete.

Returns:



70
71
72
73
74
# File 'lib/cuda/driver/stream.rb', line 70

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

#wait_event(event) ⇒ CUStream #wait_event(event, flags) ⇒ CUStream

Let all future operations submitted to this CUDA stream wait until event (CUEvent) complete before beginning execution.

Parameters:

  • event (CUEvent)

    The event to wait for.

  • flags (Integer) (defaults to: 0)

    Currently flags must be set to zero.

Returns:



83
84
85
86
87
# File 'lib/cuda/driver/stream.rb', line 83

def wait_event(event, flags = 0)
    status = API::cuStreamWaitEvent(self.to_api, event.to_api, flags)
    Pvt::handle_error(status, "Failed to make stream's future operations to wait event: flags = #{flags}.")
    self
end