Skip to content

Typed Arrays? #98

Closed
Closed
@ghost

Description

Hi folks,

Thanks for such an awesome official binding, this has opened up a lot of possibilities for Rust and Machine Learning experimentation for me, on my AMD card.

One head-scratching thing for me though, is why Arrays aren't typed in the Rust API? The Arrays are constructed with a typed slice/array, so the information is there at compile time. And, there are methods to get type, so type is clearly stored/available at runtime.

But, there's a big difference between doing a runtime match over the results of an array's get_type method, and building a true generic dispatch. For example, here's what I have right now for a left-rotate:

fn gpu_rotl(x: &af::Array, n: u8) -> af::Array {
    let t = x.get_type();
    let dsize : u8 = match t {
        af::DType::U8 => 8,
        af::DType::U16 => 16,
        af::DType::U32 => 32,
        af::DType::U64 => 64,
        _ => panic!("Array passed to rotl is not of unsigned integer type: {:?}", t),
    };
    let ls = af::shiftl(x, &n, false);
    let rsn = dsize - n;
    let rs = af::shiftr(x, &rsn, false);
    af::bitor(&ls, &rs)
}

AFAIK, the above will result in a runtime match. But, if it were typed appropriately, it might be possible to get a compiled static-dispatch. I imagine that would be better for ArrayFire's JIT, because there wouldn't be a context switch from the GPU operations to the CPU to decide the next action, there would just be a hard-compiled set of operations.

At the very least, appropriate typing would help catch bugs. But I think this might be a performance issue, too?

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Bugs

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions