kokkos/llvm-project

Add RAJA check for dereferencing struct pointers in a RAJA loop

Opened this issue · 2 comments

This would be a check to see if a RAJA lambda has captured a pointer to a struct and then dereferences it within the kernel. This is the same basic problem that we have when implicitly dereferencing members off of the "this" pointer.

So something like:

struct mystruct* mystruct_ptr = ... ;

struct mystruct mystruct_captured = ...;

RAJA::for_all (RAJA::RangeSegment(0, n, [=](int i) {
...
data[i] += mystruct_ptr->myfield; // catch this dereference

data[i] += mystruct_captured.myfield; // this shouldn't be caught since it's not a pointer dereference
...
} );

Kokkos could also use this check. @bryujin how does RAJA feel about allowing pointer dereferences in lambdas in general? Are some types designed explicitly as wrappers similar to Kokkos::View or are certain dereferences allowed?

It's very common to have derefences for simple types, such as arrays of doubles, ints, etc, so I would advocate a general flagging of pointer dereferencing. RAJA does not require the use of a Views construct, and generally relies on the user to get their data to the appropriate memory space.

For my use case, structs are usually holding metadata and are unlikely to be moving back and forth between memory spaces.