https://github.com/halide/Halide
Revision 76bb84ddcbb6051ec13cc5f9729043063a3b2faa authored by Steven Johnson on 16 May 2023, 18:25:08 UTC, committed by GitHub on 16 May 2023, 18:25:08 UTC
* Allow autoconversion from `Buffer<T>` -> `Buffer<const T>&`

When you are intermixing CPU and GPU calls in a single piece of code, it's preferable to pass `Buffer<>` by nonconst reference, so that lazy host<->device copies are done efficiently.

However, many callers prefer to define input Buffers as `Buffer<const T>` (as they should), but the fact that this form didn't easily allow autoconversion from caller (whihc may well have constructed the buffer as non-const) to callee (due to incompatible type references) led some users to just pass by a copy, since these autoconverted. This had a couple of undesirable effects:
- Making a copy cost a small but nonzero amount of code (managing refcounts, etc)
- More importantly, lazy copies in the callee got 'lost' to the caller, since the `halide_buffer_t` in the callee was a copy, thus any added `device` value or change in dirty bits was never seen.

This could previously be worked around by adding explicit calls to `.as_const()`, but that is ugly and awkward.

This change adds an ugly-but-safe implicit-conversion overload, to allow converting `Buffer<T>&` to `Buffer<const T>&`, iff T isn't already const. This will allow cleaning up downstream code to pass by references more consistently, without needing to add `.as_const()` warts.

* Also add convenience conversions for Buffer<void>&
1 parent f121abf
History
Tip revision: 76bb84ddcbb6051ec13cc5f9729043063a3b2faa authored by Steven Johnson on 16 May 2023, 18:25:08 UTC
Allow autoconversion from `Buffer<T>` -> `Buffer<const T>&` and to `Buffer<void>&` (#7571)
Tip revision: 76bb84d
File Mode Size
.github
apps
cmake
dependencies
doc
packaging
python_bindings
src
test
tools
tutorial
util
.clang-format -rw-r--r-- 1.4 KB
.clang-format-ignore -rw-r--r-- 375 bytes
.clang-tidy -rw-r--r-- 2.2 KB
.gitattributes -rw-r--r-- 342 bytes
.gitignore -rw-r--r-- 4.9 KB
.gitmodules -rw-r--r-- 0 bytes
CMakeLists.txt -rw-r--r-- 5.6 KB
CMakePresets.json -rw-r--r-- 5.6 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.5 KB
LICENSE.txt -rw-r--r-- 14.4 KB
MANIFEST.in -rw-r--r-- 159 bytes
Makefile -rw-r--r-- 105.2 KB
README.md -rw-r--r-- 16.4 KB
README_cmake.md -rw-r--r-- 76.2 KB
README_python.md -rw-r--r-- 32.2 KB
README_rungen.md -rw-r--r-- 12.1 KB
README_vulkan.md -rw-r--r-- 11.4 KB
README_webassembly.md -rw-r--r-- 10.5 KB
README_webgpu.md -rw-r--r-- 4.4 KB
pyproject.toml -rw-r--r-- 195 bytes
requirements.txt -rw-r--r-- 129 bytes
run-clang-format.sh -rwxr-xr-x 1.4 KB
run-clang-tidy.sh -rwxr-xr-x 3.1 KB
setup.py -rw-r--r-- 1.2 KB

README.md

back to top