-
Notifications
You must be signed in to change notification settings - Fork 790
[SYCL] Provide separate compilation support for free function kernels #18955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
34a11ca
edec2b4
c9680a2
b932fe6
6b6da56
a90c277
f1e77e9
99d9786
fa27639
7d91bdf
fd73179
c4b3eda
fb99d5e
b66ef5c
d35ecd2
0c855ba
2d6af89
19eed5d
7927adf
2b343cd
b737915
3136c0e
61429ea
e4c7946
1b6567d
feca690
134a24e
e3bbc5b
928e6c4
b0055ce
8e5786d
cf25552
43c7893
51203c1
9816ac0
21ec543
36ac956
568abf8
f42146a
26c87a5
8402046
0cf00ec
8e8868e
22a4427
f23b5a7
924a3d7
2ab3d6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// This is not meant as a standalone test but rather as a source file that will | ||
// link with SeparateCompilation.cpp to check that separate compilation works | ||
// with free function kernels. Hence the .cc suffix to exclude it from the list | ||
// of picked up tests. | ||
|
||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: Everything in every folder named |
||
#include "ProductKernel.hpp" | ||
#include <sycl/ext/oneapi/free_function_queries.hpp> | ||
|
||
using namespace sycl; | ||
|
||
// Add declarations again to test the compiler with multiple | ||
// declarations of the same free function kernel in the same translation unit | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(ext::oneapi::experimental::nd_range_kernel<1>)) | ||
void product(accessor<int, 1> accA, accessor<int, 1> accB, | ||
accessor<int, 1> result); | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(ext::oneapi::experimental::nd_range_kernel<1>)) | ||
void product(accessor<int, 1> accA, accessor<int, 1> accB, | ||
accessor<int, 1> result) { | ||
size_t id = | ||
ext::oneapi::this_work_item::get_nd_item<1>().get_global_linear_id(); | ||
result[id] = accA[id] * accB[id]; | ||
} | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(ext::oneapi::experimental::nd_range_kernel<1>)) | ||
void product(accessor<int, 1> accA, accessor<int, 1> accB, | ||
accessor<int, 1> result); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
#include <sycl/accessor.hpp> | ||
#include <sycl/kernel_bundle.hpp> | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(sycl::ext::oneapi::experimental::nd_range_kernel<1>)) | ||
void product(sycl::accessor<int, 1> accA, sycl::accessor<int, 1> accB, | ||
sycl::accessor<int, 1> result); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// RUN: %{build} %S/SumKernel.cc %S/ProductKernel.cc -o %t.out | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does it work if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the |
||
// RUN: %{run} %t.out | ||
|
||
#include "ProductKernel.hpp" | ||
#include "SumKernel.hpp" | ||
#include <cassert> | ||
#include <numeric> | ||
#include <sycl/detail/core.hpp> | ||
#include <sycl/ext/oneapi/experimental/free_function_traits.hpp> | ||
#include <sycl/kernel_bundle.hpp> | ||
|
||
using namespace sycl; | ||
|
||
// Add declarations again to test the compiler with multiple declarations of the | ||
// same free function kernel in the translation unit. | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(ext::oneapi::experimental::nd_range_kernel<1>)) | ||
void SumKernel::sum(accessor<int, 1> accA, accessor<int, 1> accB, | ||
accessor<int, 1> result); | ||
|
||
constexpr size_t SIZE = 16; | ||
|
||
int main() { | ||
int data[SIZE]; | ||
int result[SIZE]; | ||
std::iota(data, data + SIZE, 0); | ||
queue Q; | ||
kernel_bundle bundle = | ||
get_kernel_bundle<bundle_state::executable>(Q.get_context()); | ||
kernel_id sumId = ext::oneapi::experimental::get_kernel_id<SumKernel::sum>(); | ||
kernel_id productId = ext::oneapi::experimental::get_kernel_id<product>(); | ||
kernel sumKernel = bundle.get_kernel(sumId); | ||
kernel productKernel = bundle.get_kernel(productId); | ||
|
||
{ | ||
buffer<int, 1> databuf{data, SIZE}; | ||
buffer<int, 1> resultbuf{result, SIZE}; | ||
|
||
Q.submit([&](handler &h) { | ||
accessor<int, 1> accdata(databuf, h); | ||
accessor<int, 1> accresult(resultbuf, h); | ||
h.set_args(accdata, accdata, accresult); | ||
h.parallel_for(nd_range{{SIZE}, {SIZE}}, sumKernel); | ||
}); | ||
} | ||
|
||
int failed = 0; | ||
for (int i = 0; i < SIZE; ++i) { | ||
if (result[i] != 2 * data[i]) { | ||
std::cout << "Failed at index " << i << ": " << result[i] | ||
<< "!=" << (2 * data[i]) << std::endl; | ||
++failed; | ||
} | ||
} | ||
|
||
{ | ||
buffer<int, 1> databuf{data, SIZE}; | ||
buffer<int, 1> resultbuf{result, SIZE}; | ||
|
||
Q.submit([&](handler &h) { | ||
accessor<int, 1> accdata(databuf, h); | ||
accessor<int, 1> accresult(resultbuf, h); | ||
h.set_args(accdata, accdata, accresult); | ||
h.parallel_for(nd_range{{SIZE}, {SIZE}}, productKernel); | ||
}); | ||
} | ||
|
||
for (int i = 0; i < SIZE; ++i) { | ||
if (result[i] != data[i] * data[i]) { | ||
std::cout << "Failed at index " << i << ": " << result[i] | ||
<< "!=" << (data[i] * data[i]) << std::endl; | ||
++failed; | ||
} | ||
} | ||
|
||
return failed; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This is not meant as a standalone test but rather as a source file that will | ||
// link with SeparateCompilation.cpp to check that separate compilation works | ||
// with free function kernels. Hence the .cc suffix to exclude it from the list | ||
// of picked up tests. | ||
|
||
#include "SumKernel.hpp" | ||
#include <sycl/ext/oneapi/free_function_queries.hpp> | ||
|
||
using namespace sycl; | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(ext::oneapi::experimental::nd_range_kernel<1>)) | ||
void SumKernel::sum(accessor<int, 1> accA, accessor<int, 1> accB, | ||
accessor<int, 1> result) { | ||
size_t id = | ||
ext::oneapi::this_work_item::get_nd_item<1>().get_global_linear_id(); | ||
result[id] = accA[id] + accB[id]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include <sycl/accessor.hpp> | ||
#include <sycl/kernel_bundle.hpp> | ||
|
||
namespace SumKernel { | ||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(sycl::ext::oneapi::experimental::nd_range_kernel<1>)) | ||
void sum(sycl::accessor<int, 1> accA, sycl::accessor<int, 1> accB, | ||
sycl::accessor<int, 1> result); | ||
} // namespace SumKernel |
Uh oh!
There was an error while loading. Please reload this page.