Skip to content
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

Padding issues with kokkos #94

Open
s-sajid-ali opened this issue Oct 20, 2022 · 0 comments
Open

Padding issues with kokkos #94

s-sajid-ali opened this issue Oct 20, 2022 · 0 comments

Comments

@s-sajid-ali
Copy link
Member

Currently we are unable to use Kokkos padded arrays on GPUs due to an underlying bug in Kokkos.

In the meantime, this issue is used to document the following fix as communicated by the Kokkos developers:

template<class ViewT>
typename ViewT::HostMirror create_padded_host_mirror(ViewT v) {
  bool use_padding = false;
  if(std::is_same<typename ViewT::array_layout, Kokkos::LayoutLeft>::value)
    if(v.stride(1)!=v.extent(0)) use_padding = true;
  if(std::is_same<typename ViewT::array_layout, Kokkos::LayoutRight>::value)
    if(v.stride(ViewT::rank-2)!=v.extent(ViewT::rank-1)) use_padding = true;

  typename ViewT::HostMirror h_v;
  if(use_padding) {
    auto alloc = Kokkos::view_alloc(Kokkos::AllowPadding, "deviceview");
    h_v = typename ViewT::HostMirror(alloc, v.layout());
  } else
    h_v = Kokkos::create_mirror_view(v);
  for(int r=0; r<ViewT::rank; r++)
    if(h_v.stride(r) != v.stride(r)) throw std::runtime_error("Was not able to create correct padded host mirror.");
  return h_v;
}

template<class view_t_1, class view_t_2>
void padded_deep_copy(view_t_1 a, view_t_2 b) {
  Kokkos::deep_copy(Kokkos::View<typename view_t_1::value_type*,
                                 typename view_t_1::device_type>(a.data(), a.span()),
                    Kokkos::View<typename view_t_2::value_type*,
                                 typename view_t_2::device_type>(b.data(), b.span()));
}
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

No branches or pull requests

1 participant