pub struct Stream { /* private fields */ }
Expand description

A stream of work for the device to perform.

See the module-level documentation for more information.

Implementations

Create a new stream with the given flags and optional priority.

By convention, priority follows a convention where lower numbers represent greater priorities. That is, work in a stream with a lower priority number may pre-empt work in a stream with a higher priority number. Context::get_stream_priority_range can be used to get the range of valid priority values; if priority is set outside that range, it will be automatically clamped to the lowest or highest number in the range.

Examples
use cust::stream::{Stream, StreamFlags};

// With default priority
let stream = Stream::new(StreamFlags::NON_BLOCKING, None)?;

// With specific priority
let priority = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;

Return the flags which were used to create this stream.

Return the priority of this stream.

If this stream was created without a priority, returns the default priority. If the stream was created with a priority outside the valid range, returns the clamped priority.

Examples
use cust::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;
println!("{}", stream.get_priority()?);

Add a callback to a stream.

The callback will be executed after all previously queued items in the stream have been completed. Subsequently queued items will not execute until the callback is finished.

Callbacks must not make any CUDA API calls.

Examples
use cust::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;

// ... queue up some work on the stream

stream.add_callback(Box::new(|| {
    println!("Work is done!");
}));

// ... queue up some more work on the stream

Wait until a stream’s tasks are completed.

Waits until the device has completed all operations scheduled for this stream.

Examples
use cust::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;

// ... queue up some work on the stream

// Wait for the work to be completed.
stream.synchronize()?;

Make the stream wait on an event.

All future work submitted to the stream will wait for the event to complete. Synchronization is performed on the device, if possible. The event may originate from different context or device than the stream.

Example
use cust::stream::{Stream, StreamFlags, StreamWaitEventFlags};
use cust::event::{Event, EventFlags};

let stream_0 = Stream::new(StreamFlags::NON_BLOCKING, None)?;
let stream_1 = Stream::new(StreamFlags::NON_BLOCKING, None)?;
let event = Event::new(EventFlags::DEFAULT)?;

// do some work on stream_0 ...

// record an event
event.record(&stream_0)?;

// wait until the work on stream_0 is finished before continuing stream_1
stream_1.wait_event(event, StreamWaitEventFlags::DEFAULT)?;
}

Destroy a Stream, returning an error.

Destroying a stream can return errors from previous asynchronous work. This function destroys the given stream and returns the error and the un-destroyed stream on failure.

Example
use cust::stream::{Stream, StreamFlags};

let stream = Stream::new(StreamFlags::NON_BLOCKING, 1i32.into())?;
match Stream::drop(stream) {
    Ok(()) => println!("Successfully destroyed"),
    Err((e, stream)) => {
        println!("Failed to destroy stream: {:?}", e);
        // Do something with stream
    },
}

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.