Let's see the following example
template<typename ViewType>
void doSomthing(ViewType &A) {
const auto A_host = Kokkos::create_mirror_view(Kokkos::HostSpace(), A);
Kokkos::deep_copy(A_host, A);
}
If ViewType is layout left or right, this is okay. When the ViewType is strided (this is generated from users' subviewing), this compiles but it gets runtime error.
terminate called after throwing an instance of 'std::runtime_error'
what(): deep_copy given views that would require a temporary allocation
Traceback functionality not available
I understand why this is not allowed in kokkos. I kind of suggest that we need to create a contiguous mirror view all the time even for the strided view because the mirroring is for communication between device and host (or other memory space). How do you think ?
even if we created a contiguous mirror view, the deep copy would still not work since it would require an extra allocation on the device if we don't want to do a billion small memcpy operations (which we don't).
With UVM removal, I have a situation that the view argument can be strided. When the view needs to be accessed from host, I need to create a mirror view and deep copy. For now I do this in two steps. 1) create conforming view allocation on device and create a host mirror view contiguous, 2) deep copy from host to the allocated device view and deep copy from the device view to the strided view. I don't think it is efficient or smart solution. I simply cannot remove users possibility of using strided view as we allow subviewing. I wonder if Kokkos can provide a more systematic solution or not.
Not really. We 'could' do this two step thing for you. But as you said: this is likely pretty inefficient. It also increases your memory high water mark in a hidden way. While Kokkos does have some internal allocations, we try to avoid this as much as possible. Hence our decision not to provide it as a feature on our side, but have users like you implement the shitty way of doing this. At least its an incentive for users to think about whether they really need to do this.
Okay. Thanks.