-
Notifications
You must be signed in to change notification settings - Fork 801
[SYCL] Relax restrictions on non-OpenCL devices during queue creation #5882
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
againull
merged 12 commits into
intel:sycl
from
s-kanaev:private/s-kanaev/lift-limitation
Jul 13, 2022
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a635572
[SYCL] Lift limitation on default context containing a device for queue
db7debc
Merge remote-tracking branch 'public/sycl' into private/s-kanaev/lift…
b46beea
Lift limitation for any context
2bae3e3
Merge branch 'sycl' into lift_limitation
sergey-semenov 0c93efc
Add device check
sergey-semenov e88782e
Apply the check to default context handling as well
sergey-semenov 2d5809a
Merge branch 'sycl' into lift_limitation
sergey-semenov c17f77d
Limit the changes to non-opencl backends
sergey-semenov c9c106f
Add a unit test & adjust error message
sergey-semenov 631b952
Skip the test on host
sergey-semenov 4864094
Use GTEST_SKIP
sergey-semenov c593f8f
Rename helper function
sergey-semenov 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| add_sycl_unittest(QueueTests OBJECT | ||
| DeviceCheck.cpp | ||
| EventClear.cpp | ||
| USM.cpp | ||
| Wait.cpp | ||
|
|
||
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,170 @@ | ||
| //==----------------- DeviceCheck.cpp --- queue 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 <CL/sycl.hpp> | ||
| #include <detail/config.hpp> | ||
| #include <detail/device_impl.hpp> | ||
| #include <gtest/gtest.h> | ||
| #include <helpers/PiMock.hpp> | ||
| #include <helpers/ScopedEnvVar.hpp> | ||
|
|
||
| using namespace sycl; | ||
|
|
||
| namespace { | ||
|
|
||
| inline constexpr auto EnableDefaultContextsName = | ||
| "SYCL_ENABLE_DEFAULT_CONTEXTS"; | ||
|
|
||
| pi_result redefinedContextCreate(const pi_context_properties *properties, | ||
| pi_uint32 num_devices, | ||
| const pi_device *devices, | ||
| void (*pfn_notify)(const char *errinfo, | ||
| const void *private_info, | ||
| size_t cb, void *user_data), | ||
| void *user_data, pi_context *ret_context) { | ||
| *ret_context = reinterpret_cast<pi_context>(1); | ||
| return PI_SUCCESS; | ||
| } | ||
|
|
||
| pi_result redefinedContextRelease(pi_context context) { return PI_SUCCESS; } | ||
|
|
||
| pi_device ParentDevice = nullptr; | ||
| pi_platform PiPlatform = nullptr; | ||
|
|
||
| pi_result redefinedDeviceGetInfo(pi_device device, pi_device_info param_name, | ||
| size_t param_value_size, void *param_value, | ||
| size_t *param_value_size_ret) { | ||
| if (param_name == PI_DEVICE_INFO_PARTITION_PROPERTIES) { | ||
| if (param_value) { | ||
| auto *Result = | ||
| reinterpret_cast<pi_device_partition_property *>(param_value); | ||
| *Result = PI_DEVICE_PARTITION_EQUALLY; | ||
| } | ||
| if (param_value_size_ret) | ||
| *param_value_size_ret = sizeof(pi_device_partition_property); | ||
| } else if (param_name == PI_DEVICE_INFO_MAX_COMPUTE_UNITS) { | ||
| auto *Result = reinterpret_cast<pi_uint32 *>(param_value); | ||
| *Result = 2; | ||
| } else if (param_name == PI_DEVICE_INFO_PARENT_DEVICE) { | ||
| auto *Result = reinterpret_cast<pi_device *>(param_value); | ||
| *Result = (device == ParentDevice) ? nullptr : ParentDevice; | ||
| } else if (param_name == PI_DEVICE_INFO_PLATFORM) { | ||
| auto *Result = reinterpret_cast<pi_platform *>(param_value); | ||
| *Result = PiPlatform; | ||
| } else if (param_name == PI_DEVICE_INFO_EXTENSIONS) { | ||
| if (param_value_size_ret) { | ||
| *param_value_size_ret = 0; | ||
| } | ||
| } | ||
| return PI_SUCCESS; | ||
| } | ||
|
|
||
| pi_result redefinedDevicePartition( | ||
| pi_device device, const pi_device_partition_property *properties, | ||
| pi_uint32 num_devices, pi_device *out_devices, pi_uint32 *out_num_devices) { | ||
| if (out_devices) { | ||
| for (pi_uint32 I = 0; I < num_devices; ++I) { | ||
| out_devices[I] = reinterpret_cast<pi_device>(1); | ||
| } | ||
| } | ||
| if (out_num_devices) | ||
| *out_num_devices = num_devices; | ||
| return PI_SUCCESS; | ||
| } | ||
|
|
||
| pi_result redefinedDeviceRetain(pi_device device) { return PI_SUCCESS; } | ||
|
|
||
| pi_result redefinedDeviceRelease(pi_device device) { return PI_SUCCESS; } | ||
|
|
||
| pi_result redefinedQueueCreate(pi_context context, pi_device device, | ||
| pi_queue_properties properties, | ||
| pi_queue *queue) { | ||
| return PI_SUCCESS; | ||
| } | ||
|
|
||
| pi_result redefinedQueueRelease(pi_queue queue) { return PI_SUCCESS; } | ||
|
|
||
| // Check that the device is verified to be either a member of the context or a | ||
| // descendant of its member. | ||
| TEST(QueueDeviceCheck, CheckDeviceRestriction) { | ||
| unittest::ScopedEnvVar EnableDefaultContexts( | ||
| EnableDefaultContextsName, "1", | ||
| detail::SYCLConfig<detail::SYCL_ENABLE_DEFAULT_CONTEXTS>::reset); | ||
|
|
||
| platform Plt{default_selector()}; | ||
| if (Plt.is_host()) { | ||
| std::cout << "The test is not supported on host, skipping" << std::endl; | ||
sergey-semenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| GTEST_SKIP(); | ||
| } | ||
| PiPlatform = detail::getSyclObjImpl(Plt)->getHandleRef(); | ||
| // Create default context normally to avoid issues during its release, which | ||
| // takes plase after Mock is destroyed. | ||
| context DefaultCtx = Plt.ext_oneapi_get_default_context(); | ||
| device Dev = DefaultCtx.get_devices()[0]; | ||
|
|
||
| unittest::PiMock Mock{Plt}; | ||
| Mock.redefine<detail::PiApiKind::piContextCreate>(redefinedContextCreate); | ||
| Mock.redefine<detail::PiApiKind::piContextRelease>(redefinedContextRelease); | ||
| Mock.redefine<detail::PiApiKind::piDeviceGetInfo>(redefinedDeviceGetInfo); | ||
| Mock.redefine<detail::PiApiKind::piDevicePartition>(redefinedDevicePartition); | ||
| Mock.redefine<detail::PiApiKind::piDeviceRelease>(redefinedDeviceRelease); | ||
| Mock.redefine<detail::PiApiKind::piDeviceRetain>(redefinedDeviceRetain); | ||
| Mock.redefine<detail::PiApiKind::piQueueCreate>(redefinedQueueCreate); | ||
| Mock.redefine<detail::PiApiKind::piQueueRelease>(redefinedQueueRelease); | ||
|
|
||
| // Device is a member of the context. | ||
| { | ||
| queue Q{Dev}; | ||
| EXPECT_EQ(Q.get_context().get_platform(), Plt); | ||
| EXPECT_EQ(Q.get_context(), DefaultCtx); | ||
| queue Q2{DefaultCtx, Dev}; | ||
| } | ||
| // Device is a descendant of a member of the context. | ||
| { | ||
| ParentDevice = detail::getSyclObjImpl(Dev)->getHandleRef(); | ||
| std::vector<device> Subdevices = | ||
| Dev.create_sub_devices<info::partition_property::partition_equally>(2); | ||
| queue Q{Subdevices[0]}; | ||
| // OpenCL backend does not support using a descendant here yet. | ||
| EXPECT_EQ(Q.get_context() == DefaultCtx, | ||
| Q.get_backend() != backend::opencl); | ||
| try { | ||
| queue Q2{DefaultCtx, Subdevices[0]}; | ||
| EXPECT_NE(Q.get_backend(), backend::opencl); | ||
| } catch (sycl::invalid_object_error &e) { | ||
| EXPECT_EQ(Q.get_backend(), backend::opencl); | ||
| EXPECT_EQ(std::strcmp( | ||
| e.what(), | ||
| "Queue cannot be constructed with the given context and " | ||
| "device since the device is not a member of the context " | ||
| "(descendants of devices from the context are not " | ||
| "supported on OpenCL yet). -33 (PI_ERROR_INVALID_DEVICE)"), | ||
| 0); | ||
| } | ||
| } | ||
| // Device is neither of the two. | ||
| { | ||
| ParentDevice = nullptr; | ||
| device Device = detail::createSyclObjFromImpl<device>( | ||
| std::make_shared<detail::device_impl>(reinterpret_cast<pi_device>(0x01), | ||
| detail::getSyclObjImpl(Plt))); | ||
| queue Q{Device}; | ||
| EXPECT_NE(Q.get_context(), DefaultCtx); | ||
| try { | ||
| queue Q2{DefaultCtx, Device}; | ||
| EXPECT_TRUE(false); | ||
| } catch (sycl::invalid_object_error &e) { | ||
| EXPECT_NE( | ||
| std::strstr(e.what(), | ||
| "Queue cannot be constructed with the given context and " | ||
| "device"), | ||
| nullptr); | ||
| } | ||
| } | ||
| } | ||
| } // anonymous namespace | ||
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.