thorin
thorin copied to clipboard
Error "currently only pointers to arrays supported" only when partial evaluation is not used
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_element_addr is called without partial evaluation.
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.
We should keep this issue open until our type system can deal with this.