-
Notifications
You must be signed in to change notification settings - Fork 751
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
[SYCL] Implementation of fallback assert #3767
Merged
bader
merged 205 commits into
intel:sycl
from
s-kanaev:private/s-kanaev/assert-abort-impl
Sep 1, 2021
Merged
Changes from 1 commit
Commits
Show all changes
205 commits
Select commit
Hold shift + click to select a range
2911ea7
[SYCL] [DOC] Prepare design-document for assert feature
b69a1cd
Remove redundant file
15ea88e
Fix typo
ca08fec
Address some review comments. Add description of built-ins.
1f8d9a9
Fix links
2ee590c
Clarify that assertion failure message is printed by DPCPP Runtime
77699a2
Clarify that fallback assert impl is synchronous
001a573
Fix typo in level-zero ext draft
32b6479
Address some review comments.
b8637c2
Add exception extension
b0cd85f
Use error-code instead of distinct exception.
8c03648
[SYCL] Add OpenCL extension for assert error code
121c945
[SYCL] Add Level-Zero extension for assert error code
13b40fd
Merge branch 'private/s-kanaev/assert-ocl-l0' into private/s-kanaev/a…
a4b4884
Remove draft files
c06db5f
Remove unwanted part
823124a
Merge branch 'private/s-kanaev/assert-ocl-l0' into private/s-kanaev/a…
a99368b
Add limitations on submit to same queue after exception thrown.
78d7fcb
Add format of assert message
6882e95
Clarify where kernel wrapping takes place
32663e0
Changes to SYCL specification
2b84a83
Elaborate on limitations
423107b
Fix link
7611511
Add sequence describing how DPCPP RT gets to know about assert failure
a31b808
Add notes on property set usage
257054a
Address comments
3f50173
Fix typo and format note
c1326aa
Fix typo
5095b1a
Add extension to README
5078fcc
Note on how property set gets to be set
4dc7b1f
Merge branch 'sycl' into private/s-kanaev/assert-abort
9bcac02
Partially remove mentioning of async exception throw
7ec3ac8
Add Assert.md to index
8cbfde7
Remove the rest of exception throws
cc085f5
Address review comments
8835bf8
Document program-scope variable approach
8835756
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
ecb8659
Remove L0 and OCL extensions.
4c91fa3
[SYCL] Add PoC for using global variable
07debdb
Address comments
995e4d8
Fix typo
b57ac48
Fix typo
d2f13ff
Address review comments
e97abb3
Merge branch 'private/s-kanaev/assert-abort' into private/s-kanaev/as…
6fdcf87
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
6281bc5
Switch to __devicelib_assert_read
a5461f3
Remove use of NDEBUG from suggested changes
32a32f4
Reorder text to increase readability
2a7955f
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
3113d64
Merge branch 'private/s-kanaev/assert-abort' into private/s-kanaev/as…
eb49adb
Put variable into namespace
641d071
Address review comment
dc058a9
Address review comments
16fd8f0
Add aspect
c1e31dd
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
4a55261
Merge branch 'private/s-kanaev/assert-abort' into private/s-kanaev/as…
7fce041
Worked on implementation
3f3e1f5
Worked on implementation
c02de94
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
1490e91
Worked on implementation
44004d4
Worked on implementation
fc97981
Fix code style issues. Code clean-up
d2038be
Add doc
490b697
Fix code style issue
0d05368
Add missing file
8e64d96
Elaborate on preprocessor macro function
e1a7f45
Add missing symbols
e6e0e94
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
8a9effd
Fix runtime issues
2d2018b
Report CUDA device as of no support for assert
2c66765
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
5e3647a
Disable fallback assert in unit-tests
4d204f8
Address some review comments
6be5ac5
Add FIXME comments in devicelib
6de4d5c
Move AssertHappenedMem out of namespace
e39e15f
Updated comment
60a2121
Update document
436e8a6
Update document
7c2ea4b
[PI] Get to know if extension is present w/ variable ext name for bac…
acce48c
Add atomic operations
a64d966
Updated document
26c1c9c
Clang format fix
a302871
Add missing change
0284064
Fix style issues
89b93a9
Fix style issue and typo
30237e8
Fix build issues
7bac294
Fix ABI tests
c846ad5
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
3e70b01
Rename AssertFlagCopier => AssertInfoCopier
04b39ab
Move buffer delete to distinct host task
acb8662
Fix cuda build
07b43a7
Eliminate 'unused capture' warning
22e5376
Fix failing unit tests
966756b
Rename CAS and make it static inline
415b35e
Fix style issue.
c96534d
Fix cuda build
2365eb4
Disable fallback assert in L0 dynamic batch test
565a1fd
Merge branch 'sycl' into private/s-kanaev/assert-abort-impl
0368946
Uncomment lines after FE changes
dedf682
Workaround FE restriction
1144198
Remove unwanted changes
954a24c
Remove unwanted comment
0088a7d
Add missing file
0994acc
Fix style issues
2ae9346
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
1c429d8
Update PI
d264d16
Copy assert message elements
293123a
Fix warning as error for msvc: 'fprintf' : format string '%lu' requir…
dm-vodopyanov cfbbbef
Merge remote-tracking branch 'upstream/sycl' into private/s-kanaev/as…
dm-vodopyanov 51a8c9c
Fix "_GLOBAL__sub_I_fallback_cassert.cpp is undefined" error on Linux
dm-vodopyanov 88af340
Temporarily enable CUDA support + fix clang-format
dm-vodopyanov 17378c3
More fixes
dm-vodopyanov 2368040
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
a68f6d4
Fix checker host-task
2a4ecb3
Fix assert message
6b501bb
Fix style issue
d6fbb25
Remove call to spirv printf
52d854c
Use proper naming in libdevice
0b66b0e
Fix comment
e7ef209
Enable querying device binary property set
81a1dc2
Guard builds for CUDA target
3448969
Fix style issues
c8ec496
Revert "Enable querying device binary property set"
eb4bdc7
Overcome msvc behaviour
6cb0a43
Fix message style
9f9421b
Fix style issue
9cc989a
Fix build issue
7eec090
Overcome msvc behaviour. pt2
66c816c
Move AssertInfoCopier kernel name class to detail namespace
b9c39bb
Add structure layout description
f797224
Eliminate ABI break
901fe80
Store assert usage info in the event instead of runtime fetching.
0b011d3
Use postprocessor lambda instead of storing additional data in event
2b2b897
Resolve style issue
a02420d
Reuse assert info buffer in per-queue manner to eliminate deadlock si…
8b0b8fd
Fix symbols dump test
4774852
Don't emit assert post-processing for host
c6d3698
Remove unwanted change
84138b7
Revert unwanted change
dc63e89
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
7f7ca75
Make the global variable of internal linkage
f6ee7af
Remove redundant lines
ef7677e
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
e6d74e9
Check if kernel uses assert
553efba
Don't disable asserts in unit-tests.
377a598
Allocate device binary images in-place, not in cache
22dd99f
Fix style issue
5854804
Fix unit-test
5cf7587
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
a3532d6
Fix style issue
41cf02f
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
d64c439
Workaround for interference with reductions feature
a5bffb6
Remove redundant comment
5950432
Enforce assert copier after kernels built from source
6df5886
Fixed typo
c1767b6
Fix style issue
d9caaaf
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
82a14e1
Fix style issue
3397542
Fix required wg size unit-test
743451d
Fix required wg size unit-test
7478ac2
[SYCL] Make cmake file for unit-tests more robust
07f0871
Revert "Fix required wg size unit-test"
6aa3d96
Revert "Fix required wg size unit-test"
8a30c3e
Revert "Fix unit-test"
433d340
[SYCL] Eliminate use of dereference of past-the-end iterator in unit …
69fa419
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
764afb4
Revert "Make the global variable of internal linkage"
c63f1e9
Address review comments on libdevice
211c4d1
Address review comment
a84695c
Add unit-test
b6c768e
Report exceptions during wait for host-tasks dependencies
cc090c6
Remove additional API and use unified extension name instead
d10d7f4
Disable test for CUDA
a51611d
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
c8514aa
Fix style issue
661f2b8
Fix ABI test after API remove
1b270cb
Fix atomic_fence test failure
b952457
Fix test
8f51b2c
Merge branch 'sycl' into private/s-kanaev/assert-abort-impl
75dc44d
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
9a2fec9
Fix merge issues
35dafd0
Merge branch 'private/s-kanaev/assert-abort-impl' of github.com:s-kan…
fc78175
Fix ABI test
4f2db4e
[SYCL] Remove backend-specific code form device_impl::isAssertFailSup…
e156acd
[SYCL] Eliminate use of literal in device_impl::isAssertFailSupported
c305bb5
[SYCL] Update test to positive
4d9be64
[SYCL] Move assert unit-test to misc
8433cd0
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
ab30424
Fix styling
d694e62
Revert "[SYCL] Move assert unit-test to misc"
afc47dc
Fix styling
e153824
Fix test
9325bdc
Fix styling
9c8a3fd
Attempt to fix test
28b802c
Fix test on windows and cuda
0a7a72b
Rename macro
eed89bd
Employ macro instead of literal in cuda plugin
4478f3b
Update comment
1c12c0d
Fix test return. Add wait in test to ensure assert trigger on host an…
decb7be
Update sycl/doc/extensions/C-CXX-StandardLibrary/DeviceLibExtensions.rst
585babf
Change macro description
ba5717e
Fix endif comments
6c7a94d
Fix wording in Assert.md
295ac91
Add comments to test
a2f2473
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/asse…
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
Add unit-test
Signed-off-by: Sergey Kanaev <sergey.kanaev@intel.com>
- Loading branch information
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_sycl_unittest(AssertTests OBJECT | ||
assert.cpp | ||
) | ||
|
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,360 @@ | ||
//==---------- assert.cpp --- Check assert helpers enqueue -----------------==// | ||
// | ||
// 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 <helpers/PiImage.hpp> | ||
#include <helpers/PiMock.hpp> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <chrono> | ||
#include <set> | ||
#include <thread> | ||
|
||
class TestKernel; | ||
|
||
__SYCL_INLINE_NAMESPACE(cl) { | ||
namespace sycl { | ||
namespace detail { | ||
template <> struct KernelInfo<TestKernel> { | ||
static constexpr unsigned getNumParams() { return 0; } | ||
static const kernel_param_desc_t &getParamDesc(int) { | ||
static kernel_param_desc_t Dummy; | ||
return Dummy; | ||
} | ||
static constexpr const char *getName() { return "TestKernel"; } | ||
static constexpr bool isESIMD() { return false; } | ||
static constexpr bool callsThisItem() { return false; } | ||
static constexpr bool callsAnyThisFreeFunction() { return false; } | ||
}; | ||
|
||
static constexpr const kernel_param_desc_t Signatures[] = { | ||
{ kernel_param_kind_t::kind_accessor, 4062, 0 } | ||
}; | ||
|
||
template <> struct KernelInfo<::sycl::detail::AssertInfoCopier> { | ||
static constexpr const char* getName() { | ||
return "_ZTSN2cl4sycl6detail16AssertInfoCopierE"; | ||
} | ||
static constexpr unsigned getNumParams() { return 1; } | ||
static constexpr const kernel_param_desc_t& getParamDesc(unsigned Idx) { | ||
assert(!Idx); | ||
return Signatures[Idx]; | ||
} | ||
static constexpr bool isESIMD() { return 0; } | ||
static constexpr bool callsThisItem() { return 0; } | ||
static constexpr bool callsAnyThisFreeFunction() { return 0; } | ||
}; | ||
} // namespace detail | ||
} // namespace sycl | ||
} // __SYCL_INLINE_NAMESPACE(cl) | ||
|
||
static sycl::unittest::PiImage generateDefaultImage() { | ||
using namespace sycl::unittest; | ||
|
||
static const std::string KernelName = "TestKernel"; | ||
static const std::string CopierKernelName = | ||
"_ZTSN2cl4sycl6detail16AssertInfoCopierE"; | ||
|
||
PiPropertySet PropSet; | ||
|
||
setKernelUsesAssert({KernelName}, PropSet); | ||
|
||
std::vector<unsigned char> Bin{0, 1, 2, 3, 4, 5}; // Random data | ||
|
||
PiArray<PiOffloadEntry> Entries = makeEmptyKernels({KernelName}); | ||
|
||
PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format | ||
__SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec | ||
"", // Compile options | ||
"", // Link options | ||
std::move(Bin), | ||
std::move(Entries), | ||
std::move(PropSet)}; | ||
|
||
return Img; | ||
} | ||
|
||
static sycl::unittest::PiImage generateCopierKernelImage() { | ||
using namespace sycl::unittest; | ||
|
||
static const std::string CopierKernelName = | ||
"_ZTSN2cl4sycl6detail16AssertInfoCopierE"; | ||
|
||
PiPropertySet PropSet; | ||
|
||
std::vector<unsigned char> Bin{10, 11, 12, 13, 14, 15}; // Random data | ||
|
||
PiArray<PiOffloadEntry> Entries = makeEmptyKernels({CopierKernelName}); | ||
|
||
PiImage Img{PI_DEVICE_BINARY_TYPE_SPIRV, // Format | ||
__SYCL_PI_DEVICE_BINARY_TARGET_SPIRV64, // DeviceTargetSpec | ||
"", // Compile options | ||
"", // Link options | ||
std::move(Bin), | ||
std::move(Entries), | ||
std::move(PropSet)}; | ||
|
||
return Img; | ||
} | ||
|
||
sycl::unittest::PiImage Imgs[] = { generateDefaultImage(), | ||
generateCopierKernelImage() }; | ||
sycl::unittest::PiImageArray<2> ImgArray{Imgs}; | ||
|
||
static int KernelLaunchCounter = 0; | ||
static std::mutex WaitedEventsMutex; | ||
static std::set<int> WaitedEvents; | ||
static constexpr int PauseWaitOnIdx = 1; | ||
static std::atomic<bool> StartedWait{false}; | ||
static std::atomic<bool> ContinueWait{false}; | ||
static std::atomic<bool> PausedWaitDone{false}; | ||
|
||
// Mock redifinitions | ||
static pi_result redefinedProgramCreate(pi_context, const void *, size_t, | ||
pi_program *) { | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedProgramGetInfo(pi_program program, | ||
pi_program_info param_name, | ||
size_t param_value_size, | ||
void *param_value, | ||
size_t *param_value_size_ret) { | ||
if (param_name == PI_PROGRAM_INFO_NUM_DEVICES) { | ||
auto value = reinterpret_cast<unsigned int *>(param_value); | ||
*value = 1; | ||
} | ||
|
||
if (param_name == PI_PROGRAM_INFO_BINARY_SIZES) { | ||
auto value = reinterpret_cast<size_t *>(param_value); | ||
value[0] = 1; | ||
} | ||
|
||
if (param_name == PI_PROGRAM_INFO_BINARIES) { | ||
auto value = reinterpret_cast<unsigned char *>(param_value); | ||
value[0] = 1; | ||
} | ||
|
||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedProgramBuild( | ||
pi_program prog, pi_uint32, const pi_device *, const char *, | ||
void (*pfn_notify)(pi_program program, void *user_data), void *user_data) { | ||
if (pfn_notify) { | ||
pfn_notify(prog, user_data); | ||
} | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedKernelCreate(pi_program program, | ||
const char *kernel_name, | ||
pi_kernel *ret_kernel) { | ||
*ret_kernel = reinterpret_cast<pi_kernel>(new int[1]); | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedKernelSetExecInfo(pi_kernel kernel, | ||
pi_kernel_exec_info value_name, | ||
size_t param_value_size, | ||
const void *param_value) { | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedKernelGetInfo(pi_kernel kernel, | ||
pi_kernel_info param_name, | ||
size_t param_value_size, | ||
void *param_value, | ||
size_t *param_value_size_ret) { | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedKernelGetGroupInfo(pi_kernel kernel, pi_device device, | ||
pi_kernel_group_info param_name, | ||
size_t param_value_size, | ||
void *param_value, | ||
size_t *param_value_size_ret) { | ||
if (param_name == PI_KERNEL_GROUP_INFO_COMPILE_WORK_GROUP_SIZE) { | ||
if (param_value_size_ret) { | ||
*param_value_size_ret = 3 * sizeof(size_t); | ||
} else if (param_value) { | ||
auto size = static_cast<size_t *>(param_value); | ||
size[0] = 1; | ||
size[1] = 1; | ||
size[2] = 1; | ||
} | ||
} | ||
|
||
return PI_SUCCESS; | ||
} | ||
|
||
|
||
static pi_result redefinedEnqueueKernelLaunch(pi_queue, pi_kernel, pi_uint32, | ||
const size_t *, const size_t *, | ||
const size_t *LocalSize, | ||
pi_uint32 N, const pi_event *Deps, | ||
pi_event *RetEvent) { | ||
int *Ret = new int[1]; | ||
*Ret = KernelLaunchCounter++; | ||
printf("Enqueued %i\n", *Ret); | ||
|
||
if (PauseWaitOnIdx == *Ret) { | ||
// It should be copier kernel. Check if it depends on user's one. | ||
EXPECT_EQ(N, 1U); | ||
int EventIdx = reinterpret_cast<int *>(Deps[0])[0]; | ||
EXPECT_EQ(EventIdx, 0); | ||
} | ||
|
||
*RetEvent = reinterpret_cast<pi_event>(Ret); | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedEventsWait(pi_uint32 num_events, | ||
const pi_event *event_list) { | ||
assert(num_events == 1); | ||
|
||
int EventIdx = reinterpret_cast<int *>(event_list[0])[0]; | ||
printf("Waiting for event %i\n", EventIdx); | ||
|
||
{ | ||
std::lock_guard<std::mutex> Lock{WaitedEventsMutex}; | ||
WaitedEvents.insert(EventIdx); | ||
} | ||
|
||
if (PauseWaitOnIdx == EventIdx) { | ||
StartedWait = true; | ||
while (!ContinueWait) | ||
; | ||
|
||
// fail so that host-task isn't going to be executed | ||
return PI_ERROR_UNKNOWN; | ||
} | ||
|
||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result | ||
redefinedMemBufferCreate(pi_context context, pi_mem_flags flags, size_t size, | ||
void *host_ptr, pi_mem *ret_mem, | ||
const pi_mem_properties *properties = nullptr) { | ||
*ret_mem = nullptr; | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedMemRelease(pi_mem mem) { return PI_SUCCESS; } | ||
|
||
static pi_result redefinedProgramRetain(pi_program program) { | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedKernelRetain(pi_kernel kernel) { return PI_SUCCESS; } | ||
|
||
static pi_result redefinedKernelRelease(pi_kernel kernel) { | ||
delete[] reinterpret_cast<int *>(kernel); | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedKernelSetArg(pi_kernel kernel, pi_uint32 arg_index, | ||
size_t arg_size, const void *arg_value) { | ||
return PI_SUCCESS; | ||
} | ||
|
||
static pi_result redefinedEnqueueMemBufferMap( | ||
pi_queue command_queue, pi_mem buffer, pi_bool blocking_map, | ||
pi_map_flags map_flags, size_t offset, size_t size, | ||
pi_uint32 num_events_in_wait_list, const pi_event *event_wait_list, | ||
pi_event *event, void **ret_map) { | ||
return PI_SUCCESS; | ||
} | ||
|
||
static void setupMock(sycl::unittest::PiMock &Mock) { | ||
using namespace sycl::detail; | ||
Mock.redefine<PiApiKind::piProgramCreate>(redefinedProgramCreate); | ||
Mock.redefine<PiApiKind::piProgramGetInfo>(redefinedProgramGetInfo); | ||
Mock.redefine<PiApiKind::piProgramBuild>(redefinedProgramBuild); | ||
Mock.redefine<PiApiKind::piKernelCreate>(redefinedKernelCreate); | ||
Mock.redefine<PiApiKind::piKernelSetExecInfo>(redefinedKernelSetExecInfo); | ||
Mock.redefine<PiApiKind::piKernelGetInfo>(redefinedKernelGetInfo); | ||
Mock.redefine<PiApiKind::piKernelGetGroupInfo>(redefinedKernelGetGroupInfo); | ||
Mock.redefine<PiApiKind::piEnqueueKernelLaunch>(redefinedEnqueueKernelLaunch); | ||
Mock.redefine<PiApiKind::piMemBufferCreate>(redefinedMemBufferCreate); | ||
Mock.redefine<PiApiKind::piMemRelease>(redefinedMemRelease); | ||
Mock.redefine<PiApiKind::piProgramRetain>(redefinedProgramRetain); | ||
Mock.redefine<PiApiKind::piKernelRetain>(redefinedKernelRetain); | ||
Mock.redefine<PiApiKind::piKernelRelease>(redefinedKernelRelease); | ||
Mock.redefine<PiApiKind::piKernelSetArg>(redefinedKernelSetArg); | ||
Mock.redefine<PiApiKind::piEnqueueMemBufferMap>(redefinedEnqueueMemBufferMap); | ||
Mock.redefine<PiApiKind::piEventsWait>(redefinedEventsWait); | ||
} | ||
|
||
TEST(Assert, Test) { | ||
sycl::platform Plt{sycl::default_selector()}; | ||
if (Plt.is_host()) { | ||
std::cerr << "Test is not supported on host, skipping\n"; | ||
return; // test is not supported on host. | ||
} | ||
|
||
sycl::unittest::PiMock Mock{Plt}; | ||
|
||
setupMock(Mock); | ||
romanovvlad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
std::atomic<bool> ErrorCaptured{false}; | ||
|
||
const sycl::device Dev = Plt.get_devices()[0]; | ||
sycl::queue Queue{Dev, [&](sycl::exception_list EL) { | ||
for (auto &EPtr : EL) | ||
try { | ||
std::rethrow_exception(EPtr); | ||
} catch (sycl::exception &E) { | ||
if (E.get_cl_code() == PI_ERROR_UNKNOWN) | ||
ErrorCaptured = true; | ||
} | ||
}}; | ||
|
||
const sycl::context Ctx = Queue.get_context(); | ||
|
||
sycl::kernel_bundle KernelBundle = | ||
sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {Dev}); | ||
auto ExecBundle = sycl::build(KernelBundle); | ||
Queue.submit([&](sycl::handler &H) { | ||
H.use_kernel_bundle(ExecBundle); | ||
H.single_task<TestKernel>([]{}); | ||
}); | ||
|
||
while (!StartedWait) | ||
; | ||
|
||
ContinueWait = true; | ||
|
||
// Can't return from redefinedEventsWait and report atomically. Hence, here | ||
// is this wait. Single second wait should be more than enough. | ||
{ | ||
using namespace std::chrono_literals; | ||
std::this_thread::sleep_for(1000ms); | ||
} | ||
|
||
Queue.throw_asynchronous(); | ||
|
||
while (!ErrorCaptured) | ||
; | ||
|
||
// Host-task didn't finish as we returned PI_ERROR_UNKNOWN | ||
EXPECT_EQ(ErrorCaptured, true); | ||
// Two kernels to be enqueued: the test kernel and assert info copier | ||
EXPECT_EQ(KernelLaunchCounter, 2); | ||
s-kanaev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{ | ||
std::lock_guard<std::mutex> Lock{WaitedEventsMutex}; | ||
// Host-task was waiting on the Copier kernel | ||
EXPECT_EQ(WaitedEvents.count(1) != 0, true); | ||
EXPECT_EQ(WaitedEvents.size(), 1LU); | ||
} | ||
} | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT. It doesn't look reasonable to have a separate executable for just assert. Are there plans to extend this suite with more tests in future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some failure when multiple
PiImageArray
instances are defined within single application. I'm going to investigate it eventually later. Hence, the assert unit-test will reside in a distinct executable within this patch.