Search code examples
halide

Construct a halide::runtime:buffer from halide::buffer


In lesson_10:AOT compilation part 2, it said that "Halide::Runtime::Buffer also has constructors that wrap existing data instead of allocating new memory", but in the docs of halide::runtime::buffer, I can't find a constructor takes Buffer as its param, is it possible convert a halide::buffer to halide::runtime::buffer?


Solution

  • You are probably looking for the Halide::Buffer<T>::get() method, which returns a Halide::Runtime::Buffer<T>*. This is a pointer to the underlying runtime buffer that the frontend buffer wraps. You should note the following:

    A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.

    Also, most methods of Runtime::Buffer<T> are available through Buffer<T> simply by using the -> operator, which calls get() internally and is overloaded here.