-
Notifications
You must be signed in to change notification settings - Fork 797
[SYCL] Employ cached kernel #847
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f6cc4d5
[SYCL] Fetch cached version of kernel if possible
e2d00fa
[SYCL] Improve test for program caching
9e2c902
[SYCL] Add test for kernel caching
f4b10a9
[SYCL] Merge kernel and program cache tests
0be17bb
[SYCL] Fix typo in comment
f4c9554
[SYCL] Clarification of restriction to kernels caching
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,176 @@ | ||
// RUN: %clangxx -fsycl %s -o %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
//==------------- kernel_cache.cpp - SYCL kernel/program 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> | ||
|
||
class Functor { | ||
public: | ||
void operator()(cl::sycl::item<1> Item) { (void)Item; } | ||
}; | ||
|
||
struct TestContext { | ||
int Data; | ||
cl::sycl::queue Queue; | ||
cl::sycl::buffer<int, 1> Buf; | ||
|
||
TestContext() : Data(0), Buf(&Data, cl::sycl::range<1>(1)) {} | ||
|
||
cl::sycl::program | ||
getProgram(const cl::sycl::string_class &BuildOptions = "") { | ||
cl::sycl::program Prog(Queue.get_context()); | ||
|
||
Prog.build_with_kernel_type<class SingleTask>(BuildOptions); | ||
|
||
assert(Prog.get_state() == cl::sycl::program_state::linked && | ||
"Linked state was expected"); | ||
|
||
assert(Prog.has_kernel<class SingleTask>() && | ||
"Expecting SingleTask kernel exists"); | ||
|
||
return std::move(Prog); | ||
} | ||
|
||
cl::sycl::program getCompiledProgram() { | ||
cl::sycl::program Prog(Queue.get_context()); | ||
|
||
Prog.compile_with_kernel_type<class SingleTask>(); | ||
|
||
assert(Prog.get_state() == cl::sycl::program_state::compiled && | ||
"Compiled state was expected"); | ||
|
||
return std::move(Prog); | ||
} | ||
|
||
cl::sycl::kernel getKernel(cl::sycl::program &Prog) { | ||
auto Kernel = Prog.get_kernel<class SingleTask>(); | ||
|
||
Queue.submit([&](cl::sycl::handler &CGH) { | ||
auto acc = Buf.get_access<cl::sycl::access::mode::read_write>(CGH); | ||
CGH.single_task<class SingleTask>(Kernel, [=]() { acc[0] = acc[0] + 1; }); | ||
}); | ||
|
||
return std::move(Kernel); | ||
} | ||
}; | ||
|
||
namespace pi = cl::sycl::detail::pi; | ||
namespace RT = cl::sycl::RT; | ||
|
||
static void testProgramCachePositive() { | ||
TestContext TestCtx; | ||
|
||
auto Prog = TestCtx.getProgram(); | ||
|
||
auto *CLProg = cl::sycl::detail::getSyclObjImpl(Prog)->getHandleRef(); | ||
|
||
auto *Ctx = cl::sycl::detail::getRawSyclObjImpl(Prog.get_context()); | ||
|
||
assert(Ctx->getCachedPrograms().size() == 1 && | ||
"Expecting only a single element in program cache"); | ||
assert(Ctx->getCachedPrograms().begin()->second == | ||
pi::cast<pi_program>(CLProg) && | ||
"Invalid data in programs cache"); | ||
} | ||
|
||
static void testProgramCacheNegativeCustomBuildOptions() { | ||
TestContext TestCtx; | ||
|
||
auto Prog = TestCtx.getProgram("-g"); | ||
|
||
auto *Ctx = cl::sycl::detail::getRawSyclObjImpl(Prog.get_context()); | ||
|
||
assert(Ctx->getCachedPrograms().size() == 0 && | ||
"Expecting empty program cache"); | ||
} | ||
|
||
static void testKernelCachePositive() { | ||
TestContext TestCtx; | ||
|
||
auto Prog = TestCtx.getProgram(); | ||
auto Kernel = TestCtx.getKernel(Prog); | ||
|
||
if (!TestCtx.Queue.is_host()) { | ||
auto *CLProg = cl::sycl::detail::getSyclObjImpl(Prog)->getHandleRef(); | ||
auto *CLKernel = cl::sycl::detail::getSyclObjImpl(Kernel)->getHandleRef(); | ||
|
||
auto *Ctx = cl::sycl::detail::getRawSyclObjImpl(Prog.get_context()); | ||
|
||
assert(Ctx->getCachedKernels().size() == 1 && | ||
"Expecting only a single element in kernels cache"); | ||
assert(Ctx->getCachedKernels().begin()->first == | ||
pi::cast<pi_program>(CLProg) && | ||
"Invalid program key in kernels cache"); | ||
assert(Ctx->getCachedKernels().begin()->second.size() == 1 && | ||
"Expecting only a single kernel for the program"); | ||
assert(Ctx->getCachedKernels().begin()->second.begin()->second == | ||
pi::cast<pi_kernel>(CLKernel) && | ||
"Invalid data in kernels cache"); | ||
} | ||
} | ||
|
||
void testKernelCacheNegativeLinkedProgram() { | ||
TestContext TestCtx; | ||
|
||
auto Prog1 = TestCtx.getCompiledProgram(); | ||
auto Prog2 = TestCtx.getCompiledProgram(); | ||
|
||
auto LinkedProg = cl::sycl::program({Prog1, Prog2}); | ||
|
||
auto Kernel = TestCtx.getKernel(LinkedProg); | ||
|
||
if (!TestCtx.Queue.is_host()) { | ||
auto *Ctx = cl::sycl::detail::getRawSyclObjImpl(LinkedProg.get_context()); | ||
|
||
assert(Ctx->getCachedKernels().size() == 0 && | ||
"Unexpected data in kernels cache"); | ||
} | ||
} | ||
|
||
void testKernelCacheNegativeOCLProgram() { | ||
TestContext TestCtx; | ||
|
||
auto SyclProg = TestCtx.getProgram(); | ||
|
||
auto OclProg = cl::sycl::program(TestCtx.Queue.get_context(), SyclProg.get()); | ||
|
||
auto Kernel = TestCtx.getKernel(OclProg); | ||
|
||
if (!TestCtx.Queue.is_host()) { | ||
auto *Ctx = cl::sycl::detail::getRawSyclObjImpl(OclProg.get_context()); | ||
|
||
assert(Ctx->getCachedKernels().size() == 0 && | ||
"Unexpected data in kernels cache"); | ||
} | ||
} | ||
|
||
void testKernelCacheNegativeCustomBuildOptions() { | ||
TestContext TestCtx; | ||
|
||
auto Prog = TestCtx.getProgram("-g"); | ||
auto Kernel = TestCtx.getKernel(Prog); | ||
|
||
if (!TestCtx.Queue.is_host()) { | ||
auto *Ctx = cl::sycl::detail::getRawSyclObjImpl(Prog.get_context()); | ||
assert(Ctx->getCachedKernels().size() == 0 && | ||
"Unexpected data in kernels cache"); | ||
} | ||
} | ||
|
||
int main() { | ||
testProgramCachePositive(); | ||
testProgramCacheNegativeCustomBuildOptions(); | ||
|
||
testKernelCachePositive(); | ||
testKernelCacheNegativeLinkedProgram(); | ||
testKernelCacheNegativeOCLProgram(); | ||
testKernelCacheNegativeCustomBuildOptions(); | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.