Skip to content

[SYCL] Fix performance regression in parallel_for with using id class #5385

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

Conversation

aobolensk
Copy link
Contributor

In #5118 conversion for user defined types which are implicitly converted from sycl::items was added. It caused regression in case when sycl::id type is used, because with this change it converts to sycl::item but in fact it is not needed. That is why sycl::id class case should be checked explicitly.

@aobolensk aobolensk requested a review from a team as a code owner January 25, 2022 08:17
@aobolensk aobolensk requested a review from v-klochkov January 25, 2022 08:17
@vladimirlaz vladimirlaz changed the title Fix performance regression in parallel_for with using id class [SYCL] Fix performance regression in parallel_for with using id class Jan 25, 2022
@aobolensk aobolensk force-pushed the perf_regression_user_defined_type_conversion branch from c2a3033 to 78f2888 Compare January 25, 2022 12:01
@vladimirlaz
Copy link
Contributor

@aobolensk is it possible to add test? Generate some IR and check that type is actually used?

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 seems useful but please all the _t and _v versions of the type traits.

@aobolensk
Copy link
Contributor Author

This seems useful but please all the _t and _v versions of the type traits.

Done

vladimirlaz
vladimirlaz previously approved these changes Jan 26, 2022
@bader
Copy link
Contributor

bader commented Jan 27, 2022

@keryell, does it look good now?

Comment on lines 920 to 927
using type = typename std::conditional_t<
std::is_same<id<Dims>, LambdaArgType>::value, LambdaArgType,
typename std::conditional_t<
std::is_convertible<nd_item<Dims>, LambdaArgType>::value,
nd_item<Dims>,
typename std::conditional_t<
std::is_convertible<item<Dims>, LambdaArgType>::value,
item<Dims>, LambdaArgType>>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

We are using at least C++17, right?

Suggested change
using type = typename std::conditional_t<
std::is_same<id<Dims>, LambdaArgType>::value, LambdaArgType,
typename std::conditional_t<
std::is_convertible<nd_item<Dims>, LambdaArgType>::value,
nd_item<Dims>,
typename std::conditional_t<
std::is_convertible<item<Dims>, LambdaArgType>::value,
item<Dims>, LambdaArgType>>>;
using type = typename std::conditional_t<
std::is_same_v<id<Dims>, LambdaArgType>, LambdaArgType,
typename std::conditional_t<
std::is_convertible_v<nd_item<Dims>, LambdaArgType>,
nd_item<Dims>,
typename std::conditional_t<
std::is_convertible_v<item<Dims>, LambdaArgType>,
item<Dims>, LambdaArgType>>>;

Perhaps you can try whether you can remove the typename and see whether it still compiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to replace std::is_same with std::is_same_v too, but it leads to basic_tests/stdcpp_compat.cpp failure (https://github.com/intel/llvm/runs/4948816096?check_suite_focus=true)

Copy link
Contributor

Choose a reason for hiding this comment

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

By looking at the compilation line in your CI test I can see: "/__w/llvm/llvm/build/bin/clang" "--driver-mode=g++" "-Xsycl-target-backend=amdgcn-amd-amdhsa" "--offload-arch=gfx906" "-D_GLIBCXX_ASSERTIONS=1" "-std=c++14"
C++14 whaaaat? :-)
@bader do you still have some old C++14 while SYCL 2020 is requiring at least C++17?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.
https://github.com/intel/llvm/blob/sycl/sycl/test/basic_tests/stdcpp_compat.cpp#L13 - as you can see this comment says that some features can be unavailable. We are trying to transition old codes written in SYCL-1.2.1 softly.
New code requiring c++17 features can be added under #ifdef __cplusplus >= 201703L.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this is a good opportunity to extend https://github.com/intel/llvm/blob/54ede407edeb93b7e9334d1e725f48bf981b2965/sycl/include/CL/sycl/detail/stl_type_traits.hpp with a few _v ones in the meantime?

Copy link
Contributor Author

@aobolensk aobolensk Feb 7, 2022

Choose a reason for hiding this comment

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

@bader do we need to add missing _v functions to stl_type_traits.hpp or we are going to leave it as it is now?

Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to add missing _v functions to stl_type_traits.hpp

@aobolensk, I think this is what @keryell requests. Do you have any objections?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we need to add missing _v functions to stl_type_traits.hpp

@aobolensk, I think this is what @keryell requests. Do you have any objections?

@bader No objections. I will add it.

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.

Thanks for the simplifications!

@bader bader merged commit a5760aa into intel:sycl Feb 8, 2022
wenju-he added a commit to wenju-he/llvm that referenced this pull request Apr 14, 2022
…id class (intel#5385)"

This reverts commit a5760aa.

Test is kept to check that id is converted from item within kernel.
againull pushed a commit that referenced this pull request Apr 18, 2022
…id class (#5385)" (#6013)

This reverts commit a5760aa.

Test is kept to check that id is converted from item within kernel.
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