-
Notifications
You must be signed in to change notification settings - Fork 791
[SYCL] Update the kernel function pointer on function copy/move #20389
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
Open
slawekptak
wants to merge
4
commits into
intel:sycl
Choose a base branch
from
slawekptak:no_handler_update_lambda_ptr_host_kernel
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2708774
[SYCL] Update the kernel function pointer on function copy/move
slawekptak aa5910c
Add a test for capturing kernel arguments, if the kernel lambda is de…
slawekptak 6613b2f
Change test to use malloc_device
slawekptak 0980dbc
Leave the int kernel arg type
slawekptak 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,113 @@ | ||
//==------------ KernelArgs.cpp ------ Kernel arguments unit tests ---------==// | ||
// | ||
// 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 <helpers/CommandSubmitWrappers.hpp> | ||
#include <helpers/MockDeviceImage.hpp> | ||
#include <helpers/MockKernelInfo.hpp> | ||
#include <helpers/UrMock.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <condition_variable> | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
using namespace sycl; | ||
|
||
class TestKernelWithIntPtr; | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace detail { | ||
|
||
template <> | ||
struct KernelInfo<TestKernelWithIntPtr> : public unittest::MockKernelInfoBase { | ||
static constexpr unsigned getNumParams() { return 1; } | ||
static constexpr const char *getName() { return "TestKernelWithIntPtr"; } | ||
static constexpr int64_t getKernelSize() { return sizeof(int); } | ||
|
||
static constexpr const detail::kernel_param_desc_t &getParamDesc(int Index) { | ||
return Index == 0 ? IntParamDesc : Dummy; | ||
} | ||
|
||
private: | ||
static constexpr detail::kernel_param_desc_t IntParamDesc = { | ||
detail::kernel_param_kind_t::kind_std_layout, 0, 0}; | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace _V1 | ||
} // namespace sycl | ||
|
||
static sycl::unittest::MockDeviceImage Img = | ||
sycl::unittest::generateDefaultImage({"TestKernelWithIntPtr"}); | ||
static sycl::unittest::MockDeviceImageArray<1> ImgArray{&Img}; | ||
|
||
static int ArgInt = 123; | ||
|
||
ur_result_t redefined_urKernelSetArgValue(void *pParams) { | ||
auto params = *static_cast<ur_kernel_set_arg_value_params_t *>(pParams); | ||
|
||
int ArgValue = *static_cast<const int *>(*params.ppArgValue); | ||
EXPECT_EQ(ArgValue, ArgInt); | ||
|
||
return UR_RESULT_SUCCESS; | ||
} | ||
|
||
void runKernelWithArgs(queue &Queue, int ArgI) { | ||
// Pack to 1-byte boundaries, so the kernel size is not padded | ||
#pragma pack(push, 1) | ||
auto KernelLambda = [=]([[maybe_unused]] nd_item<1> i) { | ||
[[maybe_unused]] volatile int ArgILocal = ArgI; | ||
}; | ||
#pragma pack(pop) | ||
|
||
Queue.parallel_for<TestKernelWithIntPtr>(nd_range<1>{32, 32}, KernelLambda); | ||
// Erase the memory to make sure the lambda is not accessible | ||
std::memset(&KernelLambda, 0, sizeof(KernelLambda)); | ||
} | ||
|
||
// This test checks, if the kernel lambda is copied properly, | ||
// so the arguments extraction can happen after the local copy | ||
// of the kernel lambda is deallocated. | ||
TEST(KernelArgsTest, KernelCopy) { | ||
sycl::unittest::UrMock<> Mock; | ||
mock::getCallbacks().set_before_callback("urKernelSetArgValue", | ||
&redefined_urKernelSetArgValue); | ||
|
||
platform Plt = sycl::platform(); | ||
|
||
context Ctx{Plt}; | ||
queue Queue{Ctx, default_selector_v, property::queue::in_order()}; | ||
|
||
std::mutex CvMutex; | ||
std::condition_variable Cv; | ||
bool ready = false; | ||
|
||
// The kernel submission is queued behind a host task, | ||
// to force the scheduler-based submission. | ||
Queue.submit([&](sycl::handler &CGH) { | ||
CGH.host_task([&] { | ||
std::unique_lock<std::mutex> lk(CvMutex); | ||
Cv.wait(lk, [&ready] { return ready; }); | ||
}); | ||
}); | ||
|
||
// The kernel lambda is defined in a separate function, | ||
// so it will be deallocated before the argument extraction | ||
// and kernel submission happens. | ||
runKernelWithArgs(Queue, ArgInt); | ||
|
||
{ | ||
std::unique_lock<std::mutex> lk(CvMutex); | ||
ready = true; | ||
} | ||
Cv.notify_one(); | ||
|
||
Queue.wait(); | ||
} |
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.