[][src]Crate em

Emu is a framework/compiler for GPU acceleration, GPU programming. It is first and foremost a procedural macro that looks at a subset of safe Rust code and attempts to offload parts of it to a GPU. As an example of how you could use Emu, let's start off with a simple vector-by-scalar multiplication. We can implement this in pure Rust as follows.

fn main() {
    let mut data = vec![0.1; 1000];

    for i in 0..1000 {
        data[i] = data[i] * 10.0;
    }
}

Emu let's you run parts of your program on the GPU by declaring things you want the GPU to do. These declarations can tell the GPU to load data, launch computation, etc. Here are appropriate declarations for this program.

fn main() {
    let mut data = vec![0.1; 1000];

    gpu_do!(load(data));
    gpu_do!(launch());
    for i in 0..1000 {
        data[i] = data[i] * 10.0;
    }
    gpu_do!(read(data));
}

But these declarations don't actually do anything. They are really just declarations. To actually have Emu interpret these declarations and do something, we need to be able to tell Emu to use the GPU for a piece of code. We do this by tagging the function we are working on with #[gpu_use]. Here's how to do that.

#[gpu_use]
fn main() {
    let mut data = vec![0.1; 1000];

    gpu_do!(load(data));
    gpu_do!(launch());
    for i in 0..1000 {
        data[i] = data[i] * 10.0;
    }
    gpu_do!(read(data));
}

And now Emu will actually look through your code, load data onto the GPU, launch code on the GPU, and read back from the GPU. This example should give you a sense of how you can use Emu and what Emu tries to do. Ultimately, what Emu comes down to is to parts.

  1. Passing - passing the GPU around (function to function), with #[gpu_use]
  2. Accelerating - using the GPU to load/read data, launch with gpu_do!()

You've actually seen both passing and accelerating in the above example. But to get a better idea of how to do passing and accelerating you should look at the documentation for #[gpu_use] and gpu_do!() respectively.

  1. Passing - look at docs for #[gpu_use]
  2. Accelerating - look at docs for gpu_do!()

Once you understand, passing and accelerating, you understand Emu. These are the main high-level ideas of GPU programming with Emu. Looking at their documentation should help you understand them better.

Re-exports

pub use ocl;

Macros

get_buffer_key

A macro for getting key to access a Buffer in the buffers field of a Gpu.

gpu_do

A macro for declaring a thing that the GPU should do.

Structs

Gpu

A container that holds information needed for interacting with a GPU using OpenCL.

Attribute Macros

gpu_use

A procedural macro for using the GPU to store data and accelerate parts of code in the tagged function.