Extension Type
New Feature
Feature Description
Hi,
I was thinking of this the other day, so I'm throwing the idea here for discussions.
Usually we are naming kernels using a class that is passed to the parallel_for
defaultQueue.submit([&](sycl::handler& cgh) {
sycl::accessor accA{bufA, cgh, sycl::read_only};
sycl::accessor accB{bufB, cgh, sycl::read_only};
sycl::accessor accR{bufR, cgh, sycl::write_only};
cgh.parallel_for<vector_add_1>(
sycl::range{dataSize}, [=](sycl::id<1> globalId) {
accR[globalId] = accA[globalId] + accB[globalId];
});
});
Which does work. However, it require the user to always declare the class in advance. Additionally with the advent of free functions the free function commands #922 I'm wondering if we should provide an alternative naming mechanism relying on attributes rather than class. Such as
defaultQueue.submit([&](sycl::handler& cgh) {
sycl::accessor accA{bufA, cgh, sycl::read_only};
sycl::accessor accB{bufB, cgh, sycl::read_only};
sycl::accessor accR{bufR, cgh, sycl::write_only};
cgh.parallel_for(
sycl::range{dataSize}, [=] (sycl::id<1> globalId) [[sycl::named_kernel("vector_add_1")]] {
accR[globalId] = accA[globalId] + accB[globalId];
});
});
or if i borrow a snippet from #922
khr::launch(myQueue, range<2> { N, M }, [=](id<2> index) [[sycl::named_kernel("foo")]] {
size_t i = index[0];
size_t j = index[1];
b[i * M + j] = i * 2014 + j * 42;
});
If not quite sure about the handling of the templated cases though. I see two options:
1 - passing a constexpr const char* to the attribute ?
2 - allow passing extra types to the attribute such as [[sycl::named_kernel("foo", T)]] ?
3 - Why not also accept a class as an argument to allow the usage of classes for naming as done currently ?
One question also is whether we allow having the same name twice or not ? (can be quite hard with linkage i think, but maybe we could allow the same name if it is in the same translation unit)
Is it a good approach ? Maybe ? But making kernel naming simpler for usage with profiling tools would be wonderful as the current class approach tends to generate very long names in some cases or could be more complex for newcomers. We could consider such a attribute as a shortcut for forward declaration + passing the class name if want to keep it simple.
Related Functionality in C++
Not stricly c++ but clang provides the clang::annotate_type attribute which could be use to annotate lambdas:
From (https://github.com/oneapi-src/SYCLomatic/blob/f350c9d684edb1268f5e8fe9eea0666a680060fd/clang/test/SemaCXX/cxx2b-deducing-this.cpp#L318) documentation :
const auto l16 = [=]() [[clang::annotate_type("foo")]] [[clang::annotate_type("bar")]] {
return x;
};
Related Functionality in Other Languages
clCreateKernel(program, "my_kernel", ...); maybe ?
Related SYCL Extensions
#922 Since unless I missed it there is no clear way to name a kernel for profiling tools.
Extension Type
New Feature
Feature Description
Hi,
I was thinking of this the other day, so I'm throwing the idea here for discussions.
Usually we are naming kernels using a class that is passed to the parallel_for
defaultQueue.submit([&](sycl::handler& cgh) { sycl::accessor accA{bufA, cgh, sycl::read_only}; sycl::accessor accB{bufB, cgh, sycl::read_only}; sycl::accessor accR{bufR, cgh, sycl::write_only}; cgh.parallel_for<vector_add_1>( sycl::range{dataSize}, [=](sycl::id<1> globalId) { accR[globalId] = accA[globalId] + accB[globalId]; }); });Which does work. However, it require the user to always declare the class in advance. Additionally with the advent of free functions the free function commands #922 I'm wondering if we should provide an alternative naming mechanism relying on attributes rather than class. Such as
defaultQueue.submit([&](sycl::handler& cgh) { sycl::accessor accA{bufA, cgh, sycl::read_only}; sycl::accessor accB{bufB, cgh, sycl::read_only}; sycl::accessor accR{bufR, cgh, sycl::write_only}; cgh.parallel_for( sycl::range{dataSize}, [=] (sycl::id<1> globalId) [[sycl::named_kernel("vector_add_1")]] { accR[globalId] = accA[globalId] + accB[globalId]; }); });or if i borrow a snippet from #922
If not quite sure about the handling of the templated cases though. I see two options:
1 - passing a
constexpr const char*to the attribute ?2 - allow passing extra types to the attribute such as
[[sycl::named_kernel("foo", T)]]?3 - Why not also accept a class as an argument to allow the usage of classes for naming as done currently ?
One question also is whether we allow having the same name twice or not ? (can be quite hard with linkage i think, but maybe we could allow the same name if it is in the same translation unit)
Is it a good approach ? Maybe ? But making kernel naming simpler for usage with profiling tools would be wonderful as the current class approach tends to generate very long names in some cases or could be more complex for newcomers. We could consider such a attribute as a shortcut for forward declaration + passing the class name if want to keep it simple.
Related Functionality in C++
Not stricly c++ but clang provides the
clang::annotate_typeattribute which could be use to annotate lambdas:From (https://github.com/oneapi-src/SYCLomatic/blob/f350c9d684edb1268f5e8fe9eea0666a680060fd/clang/test/SemaCXX/cxx2b-deducing-this.cpp#L318) documentation :
Related Functionality in Other Languages
clCreateKernel(program, "my_kernel", ...);maybe ?Related SYCL Extensions
#922 Since unless I missed it there is no clear way to name a kernel for profiling tools.