{"action":"created","issue":{"url":"https://api.github.com/repos/halide/Halide/issues/2204","repository_url":"https://api.github.com/repos/halide/Halide","labels_url":"https://api.github.com/repos/halide/Halide/issues/2204/labels{/name}","comments_url":"https://api.github.com/repos/halide/Halide/issues/2204/comments","events_url":"https://api.github.com/repos/halide/Halide/issues/2204/events","html_url":"https://github.com/halide/Halide/pull/2204","id":243888077,"number":2204,"title":"Cross buffer copy","user":{"login":"abadams","id":515398,"avatar_url":"https://avatars0.githubusercontent.com/u/515398?v=4","gravatar_id":"","url":"https://api.github.com/users/abadams","html_url":"https://github.com/abadams","followers_url":"https://api.github.com/users/abadams/followers","following_url":"https://api.github.com/users/abadams/following{/other_user}","gists_url":"https://api.github.com/users/abadams/gists{/gist_id}","starred_url":"https://api.github.com/users/abadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abadams/subscriptions","organizations_url":"https://api.github.com/users/abadams/orgs","repos_url":"https://api.github.com/users/abadams/repos","events_url":"https://api.github.com/users/abadams/events{/privacy}","received_events_url":"https://api.github.com/users/abadams/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-07-19T00:18:01Z","updated_at":"2017-07-27T16:16:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/halide/Halide/pulls/2204","html_url":"https://github.com/halide/Halide/pull/2204","diff_url":"https://github.com/halide/Halide/pull/2204.diff","patch_url":"https://github.com/halide/Halide/pull/2204.patch"},"body":"Add the ability to explicitly schedule when and how host<->device buffer copies occur. See the new generator test for example usage.\r\n\r\nThis is done by using a Func to represent the copy. The Func is stored in the destination memory space (only), and the computation it does is the act of copying. The Func must have a definition of the form:\r\n\r\nfoo(\\_) = bar(\\_);\r\n\r\nThe Funcs returned by Func::in() are suitable. You then say foo.copy_to_host() or foo.copy_to_device() in the schedule, which specifies that the Func's \"computation\", such as it is, is done by a call to a new runtime function which copies from one buffer_t to another (whether on host or device). This is implemented by rewriting its definition to be an extern stage that calls this new cross-device buffer copy runtime function.\r\n\r\nSeveral new mechanisms are added to make this work:\r\n\r\n- The PR adds support for extern stages with split store_at/compute_at with GPU outputs. This will be necessary for doing device<->host copies into circular buffers asynchronously. Previously these just failed and leaked in mysterious ways. To do this we need a way to create aliased crops of device allocations, and another call to clean up any resources associated with said crops. Two new calls are added to the device interface to do this. OpenCL and CUDA support for these is added in the PR. Cuda is just pointer math. OpenCL requires a call to clCreateSubBuffer. The ability to crop GPU allocations is not exposed via Halide::Runtime::Buffer yet.\r\n\r\n- The PR introduces the idea of proxy expressions for extern stages. Not exposed to the front-end, but we could imagine doing so. An extern stage with a proxy expression uses the proxy for all bounds computation purposes instead of making any dynamic bounds queries. The idea is that whenever we have a Func that gets rewritten by the schedule to use an equivalent extern stage, we'll move its original definition into the proxy expression for bounds purposes.\r\n\r\nThe ultimate goal of this work is to combine it with async to overlap communication and computation, via asynchronous host<->device copies writing into a circular buffer. For example the following schedule would stage copies of a host producer into a device consumer asyncronously through a device-side circular buffer of 8 scanlines:\r\n\r\n    producer.in(consumer).copy_to_device().async().store_root().compute_at(consumer, y).fold_storage(y, 8);"},"comment":{"url":"https://api.github.com/repos/halide/Halide/issues/comments/318411530","html_url":"https://github.com/halide/Halide/pull/2204#issuecomment-318411530","issue_url":"https://api.github.com/repos/halide/Halide/issues/2204","id":318411530,"user":{"login":"abadams","id":515398,"avatar_url":"https://avatars0.githubusercontent.com/u/515398?v=4","gravatar_id":"","url":"https://api.github.com/users/abadams","html_url":"https://github.com/abadams","followers_url":"https://api.github.com/users/abadams/followers","following_url":"https://api.github.com/users/abadams/following{/other_user}","gists_url":"https://api.github.com/users/abadams/gists{/gist_id}","starred_url":"https://api.github.com/users/abadams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abadams/subscriptions","organizations_url":"https://api.github.com/users/abadams/orgs","repos_url":"https://api.github.com/users/abadams/repos","events_url":"https://api.github.com/users/abadams/events{/privacy}","received_events_url":"https://api.github.com/users/abadams/received_events","type":"User","site_admin":false},"created_at":"2017-07-27T16:16:30Z","updated_at":"2017-07-27T16:16:30Z","body":"builds are finally green. ptal"}}
{"actor":{"display_login":"abadams"}}