[][src]Function emu_core::spawn::spawn

pub fn spawn(num_threads: u32) -> Spawner

Constructs a Spawner with the given number of threads spawned

Each spawn(n) will spawn a new dimension of threads of size n. In other words, for each thread already spawned, n threads are spawned. If more than 3 dimensions are added, all dimensions are collapsed into the "x" dimension where the size of the "x" dimension is now the product of all sizes of dimensions so far. Until 3 dimensions of threads have been spawned, threads will be spawned on dimensions "x", "y", and "z" in that order.

This can be used in conjunction with Spawner as follows. spawn returns a Spawner which lets you .spawn more dimensions of threads.

// don't forget - this should always be the first thing you call
// don't assume there is a device available without calling this
// if there isn't one, you will recieve a runtime panic

// move data to a device
let data = vec![1.0; 1 << 20];
let mut data_on_gpu: DeviceBox<[f32]> = data.as_device_boxed_mut()?;

// compile a kernel
let kernel: GlslKernel = GlslKernel::new()
    .param_mut::<[f32], _>("float[] data")
    .param::<f32, _>("float scalar")
uint index = (1 << 10) * gl_GlobalInvocationID.x + gl_GlobalInvocationID.y;
data[index] = data[index] * scalar;
let c = compile::<GlslKernel, GlslKernelCompile, _, GlobalCache>(kernel)?.finish()?;

// run the compiled kernel
unsafe {
    spawn(1 << 10)
        .spawn(1 << 10)
        .launch(call!(c, &mut data_on_gpu, &DeviceBox::new(10.0f32)?))?;

// download data from the GPU and check the result
assert_eq!(futures::executor::block_on(data_on_gpu.get())?, vec![10.0; 1 << 20].into_boxed_slice());