This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
[SYCL] new tests for SYCL 2020 callable device selector interfaces #1119
Merged
againull
merged 7 commits into
intel:intel
from
cperkinsintel:cperkins-sycl2020-callable-device-selectors-test
Aug 5, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8655e1f
new tests for SYCL 2020 callable device selector interfaces
cperkinsintel 7d76393
everybody's favorite
cperkinsintel 8ef0279
Merge branch 'intel' into cperkins-sycl2020-callable-device-selectors…
cperkinsintel f866779
reviewer feedback
cperkinsintel fd5ea16
overlooked ref
cperkinsintel e3ad2b9
reviewer feedback, setup context with potentially multiple devices
cperkinsintel 760ac33
(hopefully last) reviewer feedback
cperkinsintel 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %t.out | ||
|
||
#include <sycl/sycl.hpp> | ||
using namespace sycl; | ||
|
||
auto exception_handler_lambda = [](exception_list elist) { | ||
// nop | ||
}; | ||
|
||
void handle_exceptions_f(exception_list elist) { | ||
// nop | ||
} | ||
|
||
auto refuse_any_device_lambda = [](const device &d) { return -1; }; | ||
|
||
int refuse_any_device_f(const device &d) { return -1; } | ||
|
||
int main() { | ||
// Ensure these compile correctly. That exception handler does not | ||
// end up specialized against device selector. | ||
queue exception_queue_01(exception_handler_lambda); | ||
queue exception_queue_02(handle_exceptions_f); | ||
|
||
// Set up callable device selector. | ||
std::vector<device> deviceList = device::get_devices(); | ||
device &lastDevice = deviceList.back(); | ||
auto select_last_device = [&lastDevice](const device &d) { | ||
return d == lastDevice; | ||
}; | ||
|
||
// Instantiate platform via callable Device Selector. | ||
platform lastPlatform(select_last_device); | ||
|
||
// Test each of the four queue constructors that take callable Device | ||
// Selectors: q(device selector) q(dev selector , async handler) | ||
// q(context , dev selector) q(context, dev selector , async handler) | ||
queue lastQueue(select_last_device); | ||
assert(lastQueue.get_device().get_platform() == lastPlatform && | ||
"Queue and platform created by selecting same device, should result " | ||
"in matching platforms."); | ||
|
||
queue lastQueueWithHandler(select_last_device, exception_handler_lambda); | ||
assert(lastQueueWithHandler.get_device() == lastDevice && | ||
"Queue created by selecting a device should have that same device."); | ||
|
||
// Create a context. | ||
platform plt; | ||
std::vector<device> platformDevices = plt.get_devices(); | ||
context ctx(platformDevices); | ||
// Set up a callable device selector to select the last device from the | ||
// context. | ||
device &lastPlatformDevice = platformDevices.back(); | ||
auto select_last_platform_device = [&lastPlatformDevice](const device &d) { | ||
return d == lastPlatformDevice; | ||
}; | ||
// Test queue constructors that use devices from a context. | ||
queue lastQueueViaContext(ctx, select_last_platform_device); | ||
assert(lastQueueViaContext.get_device() == lastPlatformDevice && | ||
"Queue created by selecting a device should have that same device."); | ||
|
||
queue lastQueueViaContextWithHandler(ctx, select_last_platform_device, | ||
handle_exceptions_f); | ||
assert(lastQueueViaContextWithHandler.get_device() == lastPlatformDevice && | ||
"Queue created by selecting a device should have that same device."); | ||
|
||
// Device constructor. | ||
device matchingDevice(select_last_device); | ||
assert(matchingDevice == lastDevice && "Incorrect selected device."); | ||
|
||
// Check exceptions and failures. | ||
try { | ||
platform refusedPlatform(refuse_any_device_lambda); | ||
assert(false && | ||
"Declined device selection should have resulted in an exception."); | ||
} catch (sycl::exception &e) { | ||
assert(e.code() == sycl::errc::runtime && "Incorrect error code."); | ||
} | ||
|
||
try { | ||
queue refusedQueue(refuse_any_device_f); | ||
assert(false && | ||
"Declined device selection should have resulted in an exception."); | ||
} catch (sycl::exception &e) { | ||
assert(e.code() == sycl::errc::runtime && "Incorrect error code."); | ||
} | ||
|
||
try { | ||
device refusedDevice(refuse_any_device_f); | ||
assert(false && | ||
"Declined device selection should have resulted in an exception."); | ||
} catch (sycl::exception &e) { | ||
assert(e.code() == sycl::errc::runtime && "Incorrect error code."); | ||
} | ||
|
||
return 0; | ||
} |
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.
If the above suggestion is implemented, then we can use
p
/q
/d
as the variables' names.