Skip to content

[SYCL] Cache devices so they actually compare == when they should. #2092

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 19 commits into from
Aug 24, 2020

Conversation

jbrodman
Copy link
Contributor

Platform device enumeration was creating new device impls every time for the same devices. This was making it impossible for devices that really should compare equal to compare equal.

Example:
queue q1;
queue q2;

Each q uses the default selector to select the same device - yet they would not compare equal.

Signed-off-by: James Brodman [email protected]

@jbrodman jbrodman requested a review from AGindinson July 10, 2020 18:59
@jbrodman jbrodman requested a review from a team as a code owner July 10, 2020 18:59
@jbrodman jbrodman requested review from rbegam and removed request for rbegam July 10, 2020 18:59
jbrodman added 3 commits July 10, 2020 15:03
Signed-off-by: James Brodman <[email protected]>
…e it involves control characters

Signed-off-by: James Brodman <[email protected]>
Signed-off-by: James Brodman <[email protected]>
Copy link
Contributor

@keryell keryell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This semantics is simpler to the user.
Note that triSYCL uses weak pointers instead of shared pointers because otherwise the devices might never been released...
https://github.com/triSYCL/triSYCL/blob/master/include/triSYCL/detail/cache.hpp

@jbrodman
Copy link
Contributor Author

Note to self: Update this to also fix platforms (same place, same issue).

@jbrodman jbrodman requested a review from romanovvlad August 13, 2020 20:02
Signed-off-by: James Brodman <[email protected]>
Signed-off-by: James Brodman <[email protected]>
Signed-off-by: James Brodman <[email protected]>
Signed-off-by: James Brodman <[email protected]>
Signed-off-by: James Brodman <[email protected]>
Signed-off-by: James Brodman <[email protected]>
@jbrodman
Copy link
Contributor Author

I think I've addressed all your points, @romanovvlad. Good suggestions.

MDevices.emplace_back(createSyclObjFromImpl<device>(
std::make_shared<device_impl>(Dev, Plugin)));
if (!DeviceIds.empty()) {
auto Platform =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto Platform =
std::shared_ptr<detail::platform_impl> Platform =

if (!DeviceIds.empty()) {
auto Platform =
platform_impl::getPlatformFromPiDevice(DeviceIds[0], Plugin);
for (auto Dev : DeviceIds) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto Dev : DeviceIds) {
for (RT::PiDevice Dev : DeviceIds) {

@@ -406,8 +407,10 @@ template <> struct get_device_info<device, info::device::parent_device> {
"No parent for device because it is not a subdevice",
PI_INVALID_DEVICE);

// Get the platform of this device
auto Platform = platform_impl::getPlatformFromPiDevice(dev, Plugin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto Platform = platform_impl::getPlatformFromPiDevice(dev, Plugin);
std::shared_ptr<detail::platform_impl> Platform = platform_impl::getPlatformFromPiDevice(dev, Plugin);

Comment on lines 27 to 31
static PlatformImplPtr HostImpl;
static std::once_flag HostImplInit;

std::call_once(HostImplInit,
[]() { HostImpl = std::make_shared<platform_impl>(); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static PlatformImplPtr HostImpl;
static std::once_flag HostImplInit;
std::call_once(HostImplInit,
[]() { HostImpl = std::make_shared<platform_impl>(); });
static PlatformImplPtr HostImpl = std::make_shared<platform_impl>();;


PlatformImplPtr Result;
{
const std::lock_guard<std::mutex> guard(PlatformMapMutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const std::lock_guard<std::mutex> guard(PlatformMapMutex);
const std::lock_guard<std::mutex> Guard(PlatformMapMutex);

const std::lock_guard<std::mutex> Guard(MDeviceMapMutex);

// If we've already seen this device, return the impl
for (const auto &Device : MDeviceCache) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const auto &Device : MDeviceCache) {
for (const std::shared_ptr<device_impl>&Device : MDeviceCache) {

}

// Otherwise make the impl
auto Result = std::make_shared<device_impl>(PiDevice, PlatformImpl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto Result = std::make_shared<device_impl>(PiDevice, PlatformImpl);
std::shared_ptr<detail::device_impl> Result = std::make_shared<device_impl>(PiDevice, PlatformImpl);

std::make_shared<device_impl>(
PiDevice, std::make_shared<platform_impl>(*this)));
});
auto PlatformImpl = getOrMakePlatformImpl(MPlatform, *MPlugin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto PlatformImpl = getOrMakePlatformImpl(MPlatform, *MPlugin);
PlatformImplPtr PlatformImpl = getOrMakePlatformImpl(MPlatform, *MPlugin);

@@ -14,6 +14,8 @@
#include <detail/platform_info.hpp>
#include <detail/plugin.hpp>

#include <map>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you do not need this header anymore.

@@ -39,8 +39,8 @@ TEST(PiMockTest, ConstructFromQueue) {
detail::getSyclObjImpl(Mock.getPlatform())->getPlugin().getPiPlugin();
EXPECT_EQ(&MockedQueuePiPlugin, &PiMockPlugin)
<< "The mocked object and the PiMock instance must share the same plugin";
ASSERT_FALSE(&NormalPiPlugin == &MockedQueuePiPlugin)
<< "Normal and mock platforms must not share the same plugin";
EXPECT_EQ(&NormalPiPlugin, &MockedQueuePiPlugin)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it breaks design of the plugin mock.
@AGindinson Could you please comment?

@jbrodman
Copy link
Contributor Author

No clue what's up with the interop task test on windows

@bader
Copy link
Contributor

bader commented Aug 21, 2020

No clue what's up with the interop task test on windows

@alexbatashev, I see this failure second time. Please, revert #2342 and investigate this failure.

@romanovvlad romanovvlad merged commit d392b51 into intel:sycl Aug 24, 2020
jsji pushed a commit that referenced this pull request Aug 11, 2023
The -opaque-pointers flag is no longer supported.

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@ff8c3e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants