AnyDSL / thorin

The Higher-Order Intermediate Representation
https://anydsl.github.io
GNU Lesser General Public License v3.0
150 stars 15 forks source link

Error "currently only pointers to arrays supported" only when partial evaluation is not used #52

Open ergawy opened 8 years ago

ergawy commented 8 years ago

The following code,

extern "thorin" {
    fn nvvm(i32, (i32, i32, i32), (i32, i32, i32), fn() -> ()) -> ();
}

extern "C" {
    fn thorin_alloc(i32, i64) -> &i8;
}

fn get_element_addr(mut data: &[i8], idx: i32) -> &[i8] { data }

fn call_me() -> () {
    let d_in_buf = thorin_alloc(1, 10i64) as &[i8];

    with nvvm(0, (1,1,1), (1,1,1)) {
        //@get_element_addr(d_in_buf, 0);
        get_element_addr(d_in_buf, 0);
    }
}

fn main() -> i32 {
    call_me();
    0
}

produces this compilation runtime error:

E:\anydsl\thorin\src\thorin\be\llvm\runtime.cpp: 90: currently only pointers to arrays supported as kernel argument at 'broken.impala:6 col 5 - 37'; argument has different type: qs8*

This happens only if _get_elementaddr is called without partial evaluation.

richardmembarth commented 8 years ago

This is actually not a bug ... we expect pointers on the GPU to reside in the global address space, e.g. &[1][i8]. In case you modify your example to use the correct address space, we can generate code for it:

extern "thorin" {
    fn nvvm(i32, (i32, i32, i32), (i32, i32, i32), fn() -> ()) -> ();
}

extern "C" {
    fn thorin_alloc(i32, i64) -> &i8;
}

fn get_element_addr(mut data: &[1][i8], idx: i32) -> &[1][i8] { data }

fn call_me() -> () {
    let d_in_buf = thorin_alloc(1, 10i64) as &[1][i8];

    with nvvm(0, (1,1,1), (1,1,1)) {
        //@get_element_addr(d_in_buf, 0);
        get_element_addr(d_in_buf, 0);
    }
}

fn main() -> i32 {
    call_me();
    0
}

Our current type system doesn't recognize that you're passing a CPU pointer to the GPU, but that is on our agenda.

leissa commented 8 years ago

We should keep this issue open until our type system can deal with this.