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

Support copying the overlapping region from one buffer to another. #8463

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mcourteaux
Copy link
Contributor

@mcourteaux mcourteaux commented Nov 5, 2024

TLDR: This PR makes it possible to copy from a smaller buffer to a bigger buffer as well (i.e. blit a buffer onto another buffer). Use case: workaround for #8235: realize pipeline to a buffer that acts as a crop, and then copy the result back.


This PR makes it possible to copy from any buffer to any other buffer with the same number of dimensions. This is in contrast to the original functionality where it tries to copy from src to the entire number of elements in the dst buffer (even if src is smaller).

  • Added a dst_begin in device_copy.
  • @derek-gerstmann I modified a few things in the Vulkan backend cleaning up those multidimensional copies (the tests passed on my machine, but please have a look at what I did in that backend if you can). I also brought it more in line with the other backends.
  • I brought the Metal backend also more in line with the others regarding how we deal with the src_begin and dst_begin values.
  • I added tests to test this behavior.
  • I validated it myself for my own pipelines, as a application-side workaround to deal with OpenCL error with CL_MISALIGNED_SUB_BUFFER_OFFSET #8235 where I make new a new buffer that acts as a crop (but is not), and copy the result back to the original buffer after the pipeline is done.

Irrelevant: my clang-format for some reason wanted to move two things in Halide::Runtime::Buffer, which is compatible with the one on the automatic test here. It seems to be the difference between clang-format-17 (github test) and clang-format-18 (my machine).

…stead of being restricted to copy to the entire dst buffer).
@mcourteaux
Copy link
Contributor Author

One of the build bots died? Can we restart one build specifically manually? Or will everything have to rerun?

@steven-johnson
Copy link
Contributor

One of the build bots died? Can we restart one build specifically manually? Or will everything have to rerun?

Sorry, I had to restart the buildmaster. You may need to rerun everything :-/

@mcourteaux mcourteaux requested review from halidebuildbots and removed request for halidebuildbots November 6, 2024 14:53
@mcourteaux mcourteaux marked this pull request as draft November 7, 2024 14:50
@mcourteaux
Copy link
Contributor Author

mcourteaux commented Nov 7, 2024

I ran into a crash on my application. Will try to figure out what that is before I reopen for review. It seems to be an out-of-memory issue which is not reported as such.

Copy link
Member

Choose a reason for hiding this comment

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

This is just to satisfy the formatter right?

Copy link
Contributor Author

@mcourteaux mcourteaux Nov 9, 2024

Choose a reason for hiding this comment

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

Yes. I put a comment on it in the PR. I have clang-format-18, but the build bots still run clang-format-17. Version 18 wants this change for some reason.

auto result = cuda_do_multidimensional_copy(user_context, c, c.src + c.src_begin, c.dst, dst->dimensions, from_host, to_host, stream);
auto result = cuda_do_multidimensional_copy(
user_context, c, c.src + c.src_begin, c.dst + c.dst_begin,
dst->dimensions, from_host, to_host, stream);
Copy link
Member

Choose a reason for hiding this comment

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

Adds offset for destination as well as source.

Copy link
Contributor Author

@mcourteaux mcourteaux Nov 9, 2024

Choose a reason for hiding this comment

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

Yes? I don't really know if you have a comment or are just describing.

@mcourteaux
Copy link
Contributor Author

Update, I tested this again, and I got this:

Error: OpenCL error: CL_MEM_OBJECT_ALLOCATION_FAILURE buffer copy failed

This seems the correct error for this case. Will reopen.

@mcourteaux mcourteaux marked this pull request as ready for review November 22, 2024 13:07
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.

3 participants