Skip to content

[SYCL] Fix return type of the accessor::get_pointer and local_accessor::get_pointer. #8493

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 40 commits into from
Mar 22, 2023

Conversation

mmoadeli
Copy link
Contributor

@mmoadeli mmoadeli commented Feb 28, 2023

  • accessor::get_pointer and local_accessor::get_pointer return std::add_pointer_t<value_type>
  • Modifies multi_ptr ctors accepting local_accessor.
  • Improves existing test to check the return type of get_pointer.

@mmoadeli mmoadeli requested a review from a team as a code owner February 28, 2023 17:51
@mmoadeli mmoadeli requested a review from bso-intel February 28, 2023 17:51
@mmoadeli mmoadeli marked this pull request as draft February 28, 2023 18:35
@mmoadeli mmoadeli temporarily deployed to aws February 28, 2023 21:22 — with GitHub Actions Inactive
@mmoadeli mmoadeli marked this pull request as ready for review March 1, 2023 11:32
@mmoadeli mmoadeli temporarily deployed to aws March 1, 2023 16:03 — with GitHub Actions Inactive
@mmoadeli mmoadeli temporarily deployed to aws March 3, 2023 12:24 — with GitHub Actions Inactive
@mmoadeli mmoadeli temporarily deployed to aws March 6, 2023 12:25 — with GitHub Actions Inactive
@mmoadeli mmoadeli temporarily deployed to aws March 7, 2023 16:33 — with GitHub Actions Inactive
@mmoadeli mmoadeli temporarily deployed to aws March 7, 2023 22:11 — with GitHub Actions Inactive
@@ -1148,6 +1154,9 @@ class multi_ptr<const void, Space, access::decorated::legacy> {

static constexpr access::address_space address_space = Space;

using decorated_type =
typename detail::DecoratedType<const void, Space>::type;

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be removed. It is defined publicly, but is not part of the specification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@steffenlarsen , thanks, done.

@@ -1006,6 +1009,9 @@ class multi_ptr<void, Space, access::decorated::legacy> {

static constexpr access::address_space address_space = Space;

using decorated_type =
typename detail::DecoratedType<const void, Space>::type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same applies to this. The places in this class that uses it should be able to use pointer_t instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@steffenlarsen , thanks, done.

@mmoadeli mmoadeli temporarily deployed to aws March 20, 2023 23:09 — with GitHub Actions Inactive
@mmoadeli mmoadeli temporarily deployed to aws March 20, 2023 23:17 — with GitHub Actions Inactive
mmoadeli and others added 4 commits March 21, 2023 10:42
Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
Co-authored-by: Steffen Larsen <steffen.larsen@intel.com>
access::placeholder::true_t>;
using local_accessor_t = local_accessor<int, size>;

auto ptr = buffer.get_access<access_mode::read_write, target::device>(cgh);
auto ptr = buffer.get_host_access(cgh);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I understand this change. ptr would be a host_accessor. Why do we compare its get_multi_ptr result to a host_task accessor's accessor_t?

Also, if you would like to check the type of the access::target::host_task it would be best to add it here rather than replace the one for access::target::device, just to avoid reducing our test coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @steffenlarsen, I reverted those changes and added a new test for get_pointer.

@mmoadeli mmoadeli temporarily deployed to aws March 21, 2023 11:29 — with GitHub Actions Inactive
Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Tiny nit, otherwise LGTM!

static_assert(std::is_same_v<decltype(target_local_ptr), local_ptr<int>>);
static_assert(
std::is_same_v<decltype(local_pointer), std::add_pointer_t<int>>);
}
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
}
}

@mmoadeli mmoadeli temporarily deployed to aws March 21, 2023 13:28 — with GitHub Actions Inactive
@mmoadeli
Copy link
Contributor Author

/verify with intel/llvm-test-suite#1670

@mmoadeli mmoadeli temporarily deployed to aws March 21, 2023 14:24 — with GitHub Actions Inactive
@mmoadeli mmoadeli temporarily deployed to aws March 21, 2023 15:10 — with GitHub Actions Inactive
@bader bader merged commit 3fdbfeb into intel:sycl Mar 22, 2023
@Wanzizhu
Copy link

Wanzizhu commented Apr 6, 2023

hi, @mmoadeli, as this is a change that breaking backward compatibility, kernel code using local_accssor will not be backward compatible, do you have any idea/advice for this issue?

@steffenlarsen
Copy link
Contributor

Hi @Wanzizhu ! The get_pointer interface on local_accessor was not in line with the SYCL 2020 specification. The appropriate alternative to the old non-conformant behavior is to call the get_multi_ptr<sycl::access::decorated::legacy>() member function which returns the same as the old non-conformant API did.

@Wanzizhu
Copy link

Wanzizhu commented Apr 6, 2023

hi, @steffenlarsen , i tried get_multi_ptr, and found code still run into issue when using compiler 2023.1.0. Git commit show it's a [feature|https://github.com//pull/8249] that added on Feb 27. Could you please provided a solution both working on old/new compiler ?

error: no member named 'get_multi_ptr' in 'sycl::local_accessor<float, 1>'
    T *lmem = scratch_.get_multi_ptr().get();

@mmoadeli
Copy link
Contributor Author

mmoadeli commented Apr 6, 2023

@Wanzizhu
get_pointer' is a bit tricky when it comes to local_accessors and accessor specialization with target::local`

Accessor specialization with target::local have below signature
local_ptr<DataT> get_pointer() const noexcept;

while get_pointer in local_accessor: has below signature
std::add_pointer_t<value_type> get_pointer() const noexcept;

Depending on which you use, you may need to update your code accordingly.

@steffenlarsen
Copy link
Contributor

@Wanzizhu - The get_multi_ptr member is new to the next release. An alternative that should work for 2023.1 and current open-source is to change it to sycl::local_ptr<T>(LocalPtrVar.get_pointer()). In your given case, that would be something like:

T *lmem = sycl::local_ptr<T>(scratch_.get_pointer()).get();

This is slightly less performant than get_multi_ptr() but should work for both. Eventually, you can simplify the mentioned code as just

T *lmem = scratch_.get_pointer();

If you wanted to use the more performant paths, you could have a function like:

// Getting a multi_ptr from a local_accessor.
template <typename T, int Dims> sycl::local_ptr<T> getMultiPtr(sycl::local_accessor<T, Dims> &LAcc) {
  if constexpr (std::is_same_v<decltype(LAcc.get_pointer()), sycl::local_ptr<T>>)
    return LAcc.get_pointer();
  else
    return LAcc.get_multi_ptr<sycl::access::decorated::legacy>();
}

// Getting a raw pointer from a local_accessor
template <typename T, int Dims> T *getPtr(sycl::local_accessor<T, Dims> &LAcc) {
  if constexpr (std::is_same_v<decltype(LAcc.get_pointer()), sycl::local_ptr<T>>)
    return LAcc.get_pointer().get();
  else
    return LAcc.get_pointer();
}

@Wanzizhu
Copy link

Wanzizhu commented Apr 6, 2023

thanks, i wil take this solution.

@mmoadeli mmoadeli deleted the get_pointer branch July 7, 2023 10:42
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.

5 participants