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

FileHandle::read_async()/FileHandle::write_async() CUstream and StreamFuture #491

Open
Jacobfaib opened this issue Oct 4, 2024 · 3 comments

Comments

@Jacobfaib
Copy link
Contributor

Jacobfaib commented Oct 4, 2024

TL;DR: Is it possible to expose a fire-and-forget-like version of the async read/write functions if a CUstream functions are given?


FileHandle::read_async() (and write_async()) state that these functions return a StreamFuture which

must be kept alive until all data has been read to disk

Ostensibly this is so that stream synchronization can be RAII-ified (StreamFuture indeed synchronizes the stream in its dtor).

But, if I pass a non-null CUstream then why must I keep the StreamFuture alive? If I have given kvikio a stream, then surely kvikio may assume that I will perform other things on the same stream.

For reference, I am thinking of the following possible workflow:

void *read_gpu_data(std::size_t nbytes, CUstream stream)
{
  auto f = kvikio::FileHandle{"data.txt", "r"};

  void *dev_ptr = allocate_gpu_pointer(nbytes);
  f.read_async(dev_ptr, nbytes, 0, stream);
  return dev_ptr;
}

void do_work()
{
  std::size_t nbytes = 1234;

  auto *dev_ptr = read_gpu_data(nbytes, stream);
  my_kernel<<<..., stream>>>(dev_ptr, ...);
}

In this example, if I want to keep the GPU pipeline alive, I also need to ferry around the StreamFuture object...

The other overload taking pointers is also not ergonomic, because it requires that bytes_read_p is non-NULL. I know the values of all my parameters right now, and I don't care about how many bytes were read by the GPU task (because I'm passing the pointer on to the kernel).

@madsbk
Copy link
Member

madsbk commented Oct 7, 2024

The other overload taking pointers is also not ergonomic, because it requires that bytes_read_p is non-NULL.

This is the reason why KvikIO introduce the StreamFuture object. The only async API cuFile provides takes the arguments as pointers. There is no way to provide the arguments by value :/

@Jacobfaib
Copy link
Contributor Author

This is the reason why KvikIO introduce the StreamFuture object. The only async API cuFile provides takes the arguments as pointers. There is no way to provide the arguments by value :/

Hmmm, perhaps kvikio could provide a "default" pointer to use here in that case. Some kind of internal static pointer that kvikio registers appropriately with cuFile which can be used as a default if this pointer is NULL.

@madsbk
Copy link
Member

madsbk commented Oct 8, 2024

But to handle errors, we would need to have a bytes_read_p per call. We could use cuStreamAddCallback to clean up bytes_read_p et al. but what about the FileHandle?
In your example, the clean up of FileHandle also needs to be delayed. Is this required?

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

2 participants