-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Support unnamed lambda kernels
Add support for kernels without kernel name. Requires compiling with -DUNNAMED_LAMBDA_EXT. Uses new __unique_stable_name compiler built-in. Signed-off-by: Roland Schulz <roland.schulz@intel.com> Signed-off-by: Alexey Bader <alexey.bader@intel.com>
- Loading branch information
1 parent
9127dce
commit 5c4a84b
Showing
9 changed files
with
118 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// RUN: %clangxx -fsycl %s -o %t.out -lOpenCL -DUNNAMED_LAMBDA_EXT | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
//==-- kernel_unnamed.cpp - SYCL kernel naming variants test ------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
|
||
#define GOLD 10 | ||
static int NumTestCases = 0; | ||
|
||
template <class F> | ||
void foo(cl::sycl::queue &deviceQueue, cl::sycl::buffer<int, 1> &buf, F f) { | ||
deviceQueue.submit([&](cl::sycl::handler &cgh) { | ||
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh); | ||
cgh.single_task([=]() { acc[0] = f(acc[0], GOLD); }); | ||
}); | ||
} | ||
|
||
namespace nm { | ||
struct Wrapper { | ||
|
||
int test() { | ||
int arr[] = {0}; | ||
{ | ||
// Simple test | ||
cl::sycl::queue deviceQueue; | ||
cl::sycl::buffer<int, 1> buf(arr, 1); | ||
deviceQueue.submit([&](cl::sycl::handler &cgh) { | ||
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh); | ||
cgh.single_task([=]() { acc[0] += GOLD; }); | ||
}); | ||
++NumTestCases; | ||
|
||
// Test lambdas with different ordinal because of macro expansion | ||
#ifdef __SYCL_DEVICE_ONLY__ | ||
[] {}(); | ||
#endif | ||
deviceQueue.submit([&](cl::sycl::handler &cgh) { | ||
auto acc = buf.get_access<cl::sycl::access::mode::read_write>(cgh); | ||
cgh.single_task([=]() { acc[0] += GOLD; }); | ||
}); | ||
++NumTestCases; | ||
|
||
// Test lambda passed to function | ||
foo(deviceQueue, buf, [](int a, int b) { return a + b; }); | ||
++NumTestCases; | ||
} | ||
return arr[0]; | ||
} | ||
}; | ||
} // namespace nm | ||
|
||
int main() { | ||
nm::Wrapper w; | ||
int res = w.test(); | ||
assert (res == GOLD * NumTestCases && "Wrong result"); | ||
} |
Should this get marked in some way with what it is closing?