Search code examples
c++gpuhalide

Halide::Buffer on GPU


I already have an application that takes input images, copies them to GPU, and then some CUDA filters are applied to that image. So, when I want to implement a new filter, I only write the filter itself (ie. kernel), since the CPU-GPU copying logic is already there.

Now I want to try out Halide for writing image filters for CUDA, and I encounter a problem that Halide::Buffer, which represents input image, is allocated on CPU, so I would have to change my existing copying logic.

Is there any way to initialize Halide::Buffer with data that is already on the GPU, and to avoid additional copying.


Solution

  • Yes, you can construct a buffer with no host allocation of the correct size with the Halide::Buffer(nullptr, ... sizes ...) constructor, and then call Buffer::device_wrap_native to associate the cuda pointer with it.