Open
Description
Is your feature request related to a problem? Please describe
When using placeholder accessors, they must be bound before use.
This trips up most of the "unused variable" diagnostics since the accessor is used as an argument to handler::require
, even if it is not used in the kernel later.
This makes it harder to diagnose erroneous dependencies between operations.
Example code, no warnings when compiled with clang++ -Wall -Wextra -fsycl
:
#include <sycl/sycl.hpp>
using sycl::access::mode;
template <class T, enum mode Mode>
using PlaceholderAccessor =
sycl::accessor<T, 1, Mode, sycl::access::target::global_buffer,
sycl::access::placeholder::true_t>;
auto myKernel(sycl::handler &cgh, PlaceholderAccessor<int, mode::write> data_1,
PlaceholderAccessor<int, mode::write> data_2) {
cgh.require(data_1);
cgh.require(data_2);
return [=](sycl::item<1> itemIdx) {
const int v = itemIdx.get_linear_id();
data_1[v] = v;
};
}
class KernelName;
int main() {
sycl::device dev{};
sycl::queue q{dev};
sycl::buffer<int, 1> buffer_1(1);
sycl::buffer<int, 1> buffer_2(1);
sycl::event e = q.submit([&](sycl::handler &cgh) {
auto kernel = myKernel(cgh, buffer_1, buffer_2);
cgh.parallel_for<KernelName>(1, kernel);
});
e.wait_and_throw();
return 0;
}
Describe the solution you would like
A compile-time warning about an unused accessor.
Describe alternatives you have considered
- Analyzing the code manually instead of hoping for the compiler to do it.
Additional context
It is a follow-up from #3078.
Not a priority for GROMACS (we ditched accessors in favor of USM a while ago), but theoretically, a helpful diagnostic.