halide 19.0.0__cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. halide/__init__.py +39 -0
  2. halide/_generator_helpers.py +835 -0
  3. halide/bin/adams2019_retrain_cost_model +0 -0
  4. halide/bin/adams2019_weightsdir_to_weightsfile +0 -0
  5. halide/bin/anderson2021_retrain_cost_model +0 -0
  6. halide/bin/anderson2021_weightsdir_to_weightsfile +0 -0
  7. halide/bin/featurization_to_sample +0 -0
  8. halide/bin/gengen +0 -0
  9. halide/bin/get_host_target +0 -0
  10. halide/halide_.cpython-310-x86_64-linux-gnu.so +0 -0
  11. halide/imageio.py +60 -0
  12. halide/include/Halide.h +35293 -0
  13. halide/include/HalideBuffer.h +2618 -0
  14. halide/include/HalidePyTorchCudaHelpers.h +64 -0
  15. halide/include/HalidePyTorchHelpers.h +120 -0
  16. halide/include/HalideRuntime.h +2221 -0
  17. halide/include/HalideRuntimeCuda.h +89 -0
  18. halide/include/HalideRuntimeD3D12Compute.h +91 -0
  19. halide/include/HalideRuntimeHexagonDma.h +104 -0
  20. halide/include/HalideRuntimeHexagonHost.h +157 -0
  21. halide/include/HalideRuntimeMetal.h +112 -0
  22. halide/include/HalideRuntimeOpenCL.h +119 -0
  23. halide/include/HalideRuntimeQurt.h +32 -0
  24. halide/include/HalideRuntimeVulkan.h +137 -0
  25. halide/include/HalideRuntimeWebGPU.h +44 -0
  26. halide/lib64/cmake/Halide/FindHalide_LLVM.cmake +152 -0
  27. halide/lib64/cmake/Halide/FindV8.cmake +33 -0
  28. halide/lib64/cmake/Halide/Halide-shared-deps.cmake +0 -0
  29. halide/lib64/cmake/Halide/Halide-shared-targets-release.cmake +29 -0
  30. halide/lib64/cmake/Halide/Halide-shared-targets.cmake +154 -0
  31. halide/lib64/cmake/Halide/HalideConfig.cmake +162 -0
  32. halide/lib64/cmake/Halide/HalideConfigVersion.cmake +65 -0
  33. halide/lib64/cmake/HalideHelpers/FindHalide_WebGPU.cmake +27 -0
  34. halide/lib64/cmake/HalideHelpers/Halide-Interfaces-release.cmake +116 -0
  35. halide/lib64/cmake/HalideHelpers/Halide-Interfaces.cmake +236 -0
  36. halide/lib64/cmake/HalideHelpers/HalideGeneratorHelpers.cmake +1056 -0
  37. halide/lib64/cmake/HalideHelpers/HalideHelpersConfig.cmake +28 -0
  38. halide/lib64/cmake/HalideHelpers/HalideHelpersConfigVersion.cmake +54 -0
  39. halide/lib64/cmake/HalideHelpers/HalideTargetHelpers.cmake +99 -0
  40. halide/lib64/cmake/HalideHelpers/MutexCopy.ps1 +31 -0
  41. halide/lib64/cmake/HalideHelpers/TargetExportScript.cmake +55 -0
  42. halide/lib64/cmake/Halide_Python/Halide_Python-targets-release.cmake +30 -0
  43. halide/lib64/cmake/Halide_Python/Halide_Python-targets.cmake +125 -0
  44. halide/lib64/cmake/Halide_Python/Halide_PythonConfig.cmake +26 -0
  45. halide/lib64/cmake/Halide_Python/Halide_PythonConfigVersion.cmake +65 -0
  46. halide/lib64/libHalide.so +0 -0
  47. halide/lib64/libHalidePyStubs.a +0 -0
  48. halide/lib64/libHalide_GenGen.a +0 -0
  49. halide/lib64/libautoschedule_adams2019.so +0 -0
  50. halide/lib64/libautoschedule_anderson2021.so +0 -0
  51. halide/lib64/libautoschedule_li2018.so +0 -0
  52. halide/lib64/libautoschedule_mullapudi2016.so +0 -0
  53. halide/share/doc/Halide/LICENSE.txt +233 -0
  54. halide/share/doc/Halide/README.md +439 -0
  55. halide/share/doc/Halide/doc/BuildingHalideWithCMake.md +626 -0
  56. halide/share/doc/Halide/doc/CodeStyleCMake.md +393 -0
  57. halide/share/doc/Halide/doc/FuzzTesting.md +104 -0
  58. halide/share/doc/Halide/doc/HalideCMakePackage.md +812 -0
  59. halide/share/doc/Halide/doc/Hexagon.md +73 -0
  60. halide/share/doc/Halide/doc/Python.md +844 -0
  61. halide/share/doc/Halide/doc/RunGen.md +283 -0
  62. halide/share/doc/Halide/doc/Testing.md +125 -0
  63. halide/share/doc/Halide/doc/Vulkan.md +287 -0
  64. halide/share/doc/Halide/doc/WebAssembly.md +228 -0
  65. halide/share/doc/Halide/doc/WebGPU.md +128 -0
  66. halide/share/tools/RunGen.h +1470 -0
  67. halide/share/tools/RunGenMain.cpp +642 -0
  68. halide/share/tools/adams2019_autotune_loop.sh +227 -0
  69. halide/share/tools/anderson2021_autotune_loop.sh +591 -0
  70. halide/share/tools/halide_benchmark.h +240 -0
  71. halide/share/tools/halide_image.h +31 -0
  72. halide/share/tools/halide_image_info.h +318 -0
  73. halide/share/tools/halide_image_io.h +2794 -0
  74. halide/share/tools/halide_malloc_trace.h +102 -0
  75. halide/share/tools/halide_thread_pool.h +161 -0
  76. halide/share/tools/halide_trace_config.h +559 -0
  77. halide-19.0.0.data/data/share/cmake/Halide/HalideConfig.cmake +6 -0
  78. halide-19.0.0.data/data/share/cmake/Halide/HalideConfigVersion.cmake +65 -0
  79. halide-19.0.0.data/data/share/cmake/HalideHelpers/HalideHelpersConfig.cmake +6 -0
  80. halide-19.0.0.data/data/share/cmake/HalideHelpers/HalideHelpersConfigVersion.cmake +54 -0
  81. halide-19.0.0.dist-info/METADATA +301 -0
  82. halide-19.0.0.dist-info/RECORD +84 -0
  83. halide-19.0.0.dist-info/WHEEL +6 -0
  84. halide-19.0.0.dist-info/licenses/LICENSE.txt +233 -0
@@ -0,0 +1,393 @@
1
+ # Contributing CMake code to Halide
2
+
3
+ This document specifies the coding standards we adhere to when authoring new
4
+ CMake code. If you need directions for building Halide,
5
+ see [BuildingHalideWithCMake.md]. If you are looking for Halide's CMake package
6
+ documentation, see [HalideCMakePackage.md].
7
+
8
+ This document is necessary for two major reasons. First, due to its long
9
+ history, size, and dedication to backwards compatibility, CMake is _incredibly_
10
+ difficult to learn and full of traps. Second, Halide bundles its own LLVM-based
11
+ native code generator, which CMake deeply does not expect. This means we
12
+ routinely push CMake's build model to its limit.
13
+
14
+ Therefore, we must be careful to write high-quality CMake code so that it is
15
+ clear when CMake's limitations are being tested. While not comprehensive, the
16
+ guide outlines the code quality expectations we have as they apply to CMake.
17
+
18
+ When contributing new CMake code to Halide, keep in mind that the minimum
19
+ version is 3.28. Therefore, it is not only possible, but _required_, to use
20
+ modern CMake best practices.
21
+
22
+ <!-- TOC -->
23
+ * [Contributing CMake code to Halide](#contributing-cmake-code-to-halide)
24
+ * [General guidelines and best practices](#general-guidelines-and-best-practices)
25
+ * [Prohibited commands list](#prohibited-commands-list)
26
+ * [Prohibited variables list](#prohibited-variables-list)
27
+ * [Adding tests](#adding-tests)
28
+ * [Adding apps](#adding-apps)
29
+ <!-- TOC -->
30
+
31
+ # General guidelines and best practices
32
+
33
+ The following are some common mistakes that lead to subtly broken builds.
34
+
35
+ - **Reading the build directory.** While setting up the build, the build
36
+ directory should be considered _write only_. Using the build directory as a
37
+ read/write temporary directory is acceptable as long as all temp files are
38
+ cleaned up by the end of configuration.
39
+ - **Not using [generator expressions][cmake-genex].** Declarative is better than
40
+ imperative and this is no exception. Conditionally adding to a target property
41
+ can leak unwanted details about the build environment into packages. Some
42
+ information is not accurate or available except via generator expressions,
43
+ e.g. the build configuration.
44
+ - **Using the wrong variable.** `CMAKE_SOURCE_DIR` doesn't always point to the
45
+ Halide source root. When someone uses Halide via
46
+ [`FetchContent`][FetchContent], it will point to _their_ source root instead.
47
+ The correct variable is [`Halide_SOURCE_DIR`][project-name_source_dir]. If you
48
+ want to know if the compiler is MSVC, check it directly with the
49
+ [`MSVC`][msvc] variable; don't use [`WIN32`][win32]. That will be wrong when
50
+ compiling with clang on Windows. In most cases, however, a generator
51
+ expression will be more appropriate.
52
+ - **Using directory properties.** Directory properties have vexing behavior and
53
+ are essentially deprecated from CMake 3.0+. Propagating target properties is
54
+ the way of the future.
55
+ - **Using the wrong visibility.** Target properties can be `PRIVATE`,
56
+ `INTERFACE`, or both (aka `PUBLIC`). Pick the most conservative one for each
57
+ scenario. Refer to the [transitive usage requirements][cmake-propagation] docs
58
+ for more information.
59
+ - **Needlessly expanding variables** The [`if`][cmake_if] and
60
+ [`foreach`][cmake_foreach] commands generally expand variables when provided
61
+ by name. Expanding such variables manually can unintentionally change the
62
+ behavior of the command. Use `foreach (item IN LISTS list)` instead of
63
+ `foreach (item ${list})`. Similarly, use `if (varA STREQUAL varB)` instead of
64
+ `if ("${varA}" STREQUAL "${varB}")` and _definitely_ don't use
65
+ `if (${varA} STREQUAL ${varB})` since that will fail (in the best case) if
66
+ either variable's value contains a semicolon (due to argument expansion).
67
+
68
+ ## Prohibited commands list
69
+
70
+ As mentioned above, using directory properties is brittle, and they are
71
+ therefore _not allowed_. The following functions may not appear in any new CMake
72
+ code.
73
+
74
+ | Command | Alternative |
75
+ |-------------------------------------|----------------------------------------------------------------------------------------------------|
76
+ | `add_compile_definitions` | Use [`target_compile_definitions`][target_compile_definitions] |
77
+ | `add_compile_options` | Use [`target_compile_options`][target_compile_options] |
78
+ | `add_definitions` | Use [`target_compile_definitions`][target_compile_definitions] |
79
+ | `add_link_options` | Use [`target_link_options`][target_link_options], but prefer not to use either |
80
+ | `include_directories` | Use [`target_include_directories`][target_include_directories] |
81
+ | `link_directories` | Use [`target_link_libraries`][target_link_libraries] |
82
+ | `link_libraries` | Use [`target_link_libraries`][target_link_libraries] |
83
+ | `remove_definitions` | [Generator expressions][cmake-genex] in [`target_compile_definitions`][target_compile_definitions] |
84
+ | `set_directory_properties` | Use (cache) variables or target properties |
85
+ | `set_property(DIRECTORY)` | Use (cache) variables or target properties (custom properties excluded, but require justification) |
86
+ | `target_link_libraries(target lib)` | Use [`target_link_libraries`][target_link_libraries] _with a visibility specifier_ (eg. `PRIVATE`) |
87
+
88
+ As an example, it was once common practice to write code similar to this:
89
+
90
+ ```cmake
91
+ # WRONG: do not do this
92
+ include_directories(include)
93
+ add_library(my_lib source1.cpp ..)
94
+ ```
95
+
96
+ However, this has two major pitfalls. First, it applies to _all_ targets created
97
+ in that directory, even those before the call to `include_directories` and those
98
+ created in [`include()`][include]-ed CMake files. As CMake files get larger and
99
+ more complex, this behavior gets harder to pinpoint. This is particularly vexing
100
+ when using the `link_libraries` or `add_definitions` commands. Second, this form
101
+ does not provide a way to _propagate_ the include directory to consumers of
102
+ `my_lib`. The correct way to do this is:
103
+
104
+ ```cmake
105
+ # CORRECT
106
+ add_library(my_lib source1.cpp ...)
107
+ target_sources(
108
+ my_lib
109
+ PUBLIC
110
+ FILE_SET HEADERS
111
+ BASE_DIRS include
112
+ FILES include/header1.h
113
+ )
114
+ ```
115
+
116
+ This is better in many ways. It only affects the target in question. It
117
+ propagates the include path to the targets linking to it (via `PUBLIC`). It also
118
+ correctly exports the host-filesystem-specific include path when installing or
119
+ packaging the target and installs the headers themselves, too.
120
+
121
+ If common properties need to be grouped together, use an INTERFACE target
122
+ (better) or write a function (worse).
123
+
124
+ There are also several functions that are disallowed for other reasons:
125
+
126
+ | Command | Reason | Alternative |
127
+ |---------------------------------|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
128
+ | `aux_source_directory` | Interacts poorly with incremental builds and Git | List source files explicitly |
129
+ | `build_command` | CTest internal function | Use CTest build-and-test mode via [`CMAKE_CTEST_COMMAND`][cmake_ctest_command] |
130
+ | `cmake_host_system_information` | Usually misleading information. | Inspect [toolchain][cmake-toolchains] variables and use generator expressions. |
131
+ | `cmake_policy(... OLD)` | OLD policies are deprecated by definition. | Instead, fix the code to work with the new policy. |
132
+ | `create_test_sourcelist` | We use our own unit testing solution | See the [adding tests](#adding-tests) section. |
133
+ | `define_property` | Adds unnecessary complexity | Use a cache variable. Exceptions under special circumstances. |
134
+ | `enable_language` | Halide is C/C++ only | [`FindCUDAToolkit`][FindCUDAToolkit], appropriately guarded. |
135
+ | `file(GLOB ...)` | Interacts poorly with incremental builds and Git | List source files explicitly. Allowed if not globbing for source files. |
136
+ | `fltk_wrap_ui` | Halide does not use FLTK | None |
137
+ | `include_external_msproject` | Halide must remain portable | Write a CMake package config file or find module. |
138
+ | `include_guard` | Use of recursive inclusion is not allowed | Write (recursive) functions. |
139
+ | `include_regular_expression` | Changes default dependency checking behavior | None |
140
+ | `load_cache` | Superseded by [`FetchContent`][FetchContent]/[`ExternalProject`][ExternalProject] | Use aforementioned modules |
141
+ | `macro` | CMake macros are not hygienic and are therefore error-prone | Use functions instead. |
142
+ | `site_name` | Privacy: do not want leak host name information | Provide a cache variable, generate a unique name. |
143
+ | `variable_watch` | Debugging helper | None. Not needed in production. |
144
+
145
+ Do not introduce any dependencies via [`find_package`][find_package]
146
+ without broader approval. Importantly, never introduce a new use of
147
+ `FetchContent`; prefer to add dependencies to `vcpkg.json`.
148
+
149
+ ## Prohibited variables list
150
+
151
+ Any variables that are specific to languages that are not enabled should, of
152
+ course, be avoided. But of greater concern are variables that are easy to misuse
153
+ or should not be overridden for our end-users. The following (non-exhaustive)
154
+ list of variables shall not be used in code merged into main.
155
+
156
+ | Variable | Reason | Alternative |
157
+ |---------------------------------|-----------------------------------------------|---------------------------------------------------------------------------------------------------------|
158
+ | `CMAKE_ROOT` | Code smell | Rely on `find_package` search options; include `HINTS` if necessary |
159
+ | `CMAKE_DEBUG_TARGET_PROPERTIES` | Debugging helper | None |
160
+ | `CMAKE_FIND_DEBUG_MODE` | Debugging helper | None |
161
+ | `CMAKE_RULE_MESSAGES` | Debugging helper | None |
162
+ | `CMAKE_VERBOSE_MAKEFILE` | Debugging helper | None |
163
+ | `CMAKE_BACKWARDS_COMPATIBILITY` | Deprecated | None |
164
+ | `CMAKE_BUILD_TOOL` | Deprecated | `${CMAKE_COMMAND} --build` or [`CMAKE_MAKE_PROGRAM`][cmake_make_program] (but see below) |
165
+ | `CMAKE_CACHEFILE_DIR` | Deprecated | [`CMAKE_BINARY_DIR`][cmake_binary_dir], but see below |
166
+ | `CMAKE_CFG_INTDIR` | Deprecated | `$<CONFIG>`, `$<TARGET_FILE:..>`, target resolution of [`add_custom_command`][add_custom_command], etc. |
167
+ | `CMAKE_CL_64` | Deprecated | [`CMAKE_SIZEOF_VOID_P`][cmake_sizeof_void_p] |
168
+ | `CMAKE_COMPILER_IS_*` | Deprecated | [`CMAKE_<LANG>_COMPILER_ID`][cmake_lang_compiler_id] |
169
+ | `CMAKE_HOME_DIRECTORY` | Deprecated | [`CMAKE_SOURCE_DIR`][cmake_source_dir], but see below |
170
+ | `CMAKE_DIRECTORY_LABELS` | Directory property | None |
171
+ | `CMAKE_BUILD_TYPE` | Only applies to single-config generators. | `$<CONFIG>` |
172
+ | `CMAKE_*_FLAGS*` (w/o `_INIT`) | User-only | Write a [toolchain][cmake-toolchains] file with the corresponding `_INIT` variable |
173
+ | `CMAKE_COLOR_MAKEFILE` | User-only | None |
174
+ | `CMAKE_ERROR_DEPRECATED` | User-only | None |
175
+ | `CMAKE_CONFIGURATION_TYPES` | We only support the four standard build types | None |
176
+
177
+ Of course feel free to insert debugging helpers _while developing_ but please
178
+ remove them before review. Finally, the following variables are allowed, but
179
+ their use must be motivated:
180
+
181
+ | Variable | Reason | Alternative |
182
+ |------------------------------------------------|-----------------------------------------------------|----------------------------------------------------------------------------------------------|
183
+ | [`CMAKE_SOURCE_DIR`][cmake_source_dir] | Points to global source root, not Halide's. | [`Halide_SOURCE_DIR`][project-name_source_dir] or [`PROJECT_SOURCE_DIR`][project_source_dir] |
184
+ | [`CMAKE_BINARY_DIR`][cmake_binary_dir] | Points to global build root, not Halide's | [`Halide_BINARY_DIR`][project-name_binary_dir] or [`PROJECT_BINARY_DIR`][project_binary_dir] |
185
+ | [`CMAKE_MAKE_PROGRAM`][cmake_make_program] | CMake abstracts over differences in the build tool. | Prefer CTest's build and test mode or CMake's `--build` mode |
186
+ | [`CMAKE_CROSSCOMPILING`][cmake_crosscompiling] | Often misleading. | Inspect relevant variables directly, eg. [`CMAKE_SYSTEM_NAME`][cmake_system_name] |
187
+ | [`BUILD_SHARED_LIBS`][build_shared_libs] | Could override user setting | None, but be careful to restore value when overriding for a dependency |
188
+
189
+ Any use of these functions or variables will block a PR.
190
+
191
+ # Adding tests
192
+
193
+ When adding a file to any of the folders under `test`, be aware that CI expects
194
+ that every `.c` and `.cpp` appears in the `CMakeLists.txt` file _on its own
195
+ line_, possibly as a comment. This is to avoid globbing and also to ensure that
196
+ added files are not missed.
197
+
198
+ For most test types, it should be as simple as adding to the existing lists,
199
+ which must remain in alphabetical order. Generator tests are trickier, but
200
+ following the existing examples is a safe way to go.
201
+
202
+ # Adding apps
203
+
204
+ If you're contributing a new app to Halide: great! Thank you! There are a few
205
+ guidelines you should follow when writing a new app.
206
+
207
+ - Write the app as if it were a top-level project. You should call
208
+ `find_package(Halide)` and set the C++ version to 11.
209
+ - Call [`enable_testing()`][enable_testing] and add a small test that runs the
210
+ app.
211
+ - Don't assume your app will have access to a GPU. Write your schedules to be
212
+ robust to varying buildbot hardware.
213
+ - Don't assume your app will be run on a specific OS, architecture, or bitness.
214
+ Write your apps to be robust (ideally efficient) on all supported platforms.
215
+ - If you rely on any additional packages, don't include them as `REQUIRED`,
216
+ instead test to see if their targets are available and, if not, call
217
+ `return()` before creating any targets. In this case, print a
218
+ `message(STATUS "[SKIP] ...")`, too.
219
+ - Look at the existing apps for examples.
220
+ - Test your app with ctest before opening a PR. Apps are built as part of the
221
+ test, rather than the main build.
222
+
223
+ [BuildingHalideWithCMake.md]: ./BuildingHalideWithCMake.md
224
+
225
+ [CodeStyleCMake.md]: ./CodeStyleCMake.md
226
+
227
+ [ExternalProject]: https://cmake.org/cmake/help/latest/module/ExternalProject.html
228
+
229
+ [FetchContent]: https://cmake.org/cmake/help/latest/module/FetchContent.html
230
+
231
+ [FindCUDAToolkit]: https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html
232
+
233
+ [HalideCMakePackage.md]: ./HalideCMakePackage.md
234
+
235
+ [add_custom_command]: https://cmake.org/cmake/help/latest/command/add_custom_command.html
236
+
237
+ [add_library]: https://cmake.org/cmake/help/latest/command/add_library.html
238
+
239
+ [add_subdirectory]: https://cmake.org/cmake/help/latest/command/add_subdirectory.html
240
+
241
+ [atlas]: http://math-atlas.sourceforge.net/
242
+
243
+ [brew-cmake]: https://formulae.brew.sh/cask/cmake#default
244
+
245
+ [build_shared_libs]: https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
246
+
247
+ [cmake-apt]: https://apt.kitware.com/
248
+
249
+ [cmake-discourse]: https://discourse.cmake.org/
250
+
251
+ [cmake-docs]: https://cmake.org/cmake/help/latest/
252
+
253
+ [cmake-download]: https://cmake.org/download/
254
+
255
+ [cmake-from-source]: https://cmake.org/install/
256
+
257
+ [cmake-genex]: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
258
+
259
+ [cmake-install]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#install-a-project
260
+
261
+ [cmake-propagation]: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#transitive-usage-requirements
262
+
263
+ [cmake-toolchains]: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
264
+
265
+ [cmake-user-interaction]: https://cmake.org/cmake/help/latest/guide/user-interaction/index.html#setting-build-variables
266
+
267
+ [cmake_binary_dir]: https://cmake.org/cmake/help/latest/variable/CMAKE_BINARY_DIR.html
268
+
269
+ [cmake_build_type]: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
270
+
271
+ [cmake_crosscompiling]: https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html
272
+
273
+ [cmake_crosscompiling_emulator]: https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING_EMULATOR.html
274
+
275
+ [cmake_ctest_command]: https://cmake.org/cmake/help/latest/variable/CMAKE_CTEST_COMMAND.html
276
+
277
+ [cmake_current_binary_dir]: https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_BINARY_DIR.html
278
+
279
+ [cmake_cxx_extensions]: https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_EXTENSIONS.html
280
+
281
+ [cmake_cxx_standard]: https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html
282
+
283
+ [cmake_cxx_standard_required]: https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD_REQUIRED.html
284
+
285
+ [cmake_foreach]: https://cmake.org/cmake/help/latest/command/foreach.html
286
+
287
+ [cmake_if]: https://cmake.org/cmake/help/latest/command/if.html
288
+
289
+ [cmake_lang_compiler_id]: https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
290
+
291
+ [cmake_make_program]: https://cmake.org/cmake/help/latest/variable/CMAKE_MAKE_PROGRAM.html
292
+
293
+ [cmake_minimum_required]: https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html
294
+
295
+ [cmake_prefix_path]: https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html
296
+
297
+ [cmake_presets]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
298
+
299
+ [cmake_sizeof_void_p]: https://cmake.org/cmake/help/latest/variable/CMAKE_SIZEOF_VOID_P.html
300
+
301
+ [cmake_source_dir]: https://cmake.org/cmake/help/latest/variable/CMAKE_SOURCE_DIR.html
302
+
303
+ [cmake_system_name]: https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html
304
+
305
+ [doxygen-download]: https://www.doxygen.nl/download.html
306
+
307
+ [doxygen]: https://www.doxygen.nl/index.html
308
+
309
+ [eigen]: http://eigen.tuxfamily.org/index.php?title=Main_Page
310
+
311
+ [enable_testing]: https://cmake.org/cmake/help/latest/command/enable_testing.html
312
+
313
+ [find_package]: https://cmake.org/cmake/help/latest/command/find_package.html
314
+
315
+ [findcuda]: https://cmake.org/cmake/help/latest/module/FindCUDA.html
316
+
317
+ [finddoxygen]: https://cmake.org/cmake/help/latest/module/FindDoxygen.html
318
+
319
+ [findjpeg]: https://cmake.org/cmake/help/latest/module/FindJPEG.html
320
+
321
+ [findopencl]: https://cmake.org/cmake/help/latest/module/FindOpenCL.html
322
+
323
+ [findpng]: https://cmake.org/cmake/help/latest/module/FindPNG.html
324
+
325
+ [findpython3]: https://cmake.org/cmake/help/latest/module/FindPython3.html
326
+
327
+ [findx11]: https://cmake.org/cmake/help/latest/module/FindX11.html
328
+
329
+ [halide-generator-tutorial]: https://halide-lang.org/tutorials/tutorial_lesson_15_generators.html
330
+
331
+ [halide-tutorials]: https://halide-lang.org/tutorials/tutorial_introduction.html
332
+
333
+ [homebrew]: https://brew.sh
334
+
335
+ [imported-executable]: https://cmake.org/cmake/help/latest/command/add_executable.html#imported-executables
336
+
337
+ [imported-target]: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#imported-targets
338
+
339
+ [include]: https://cmake.org/cmake/help/latest/command/include.html
340
+
341
+ [install-files]: https://cmake.org/cmake/help/latest/command/install.html#files
342
+
343
+ [install-targets]: https://cmake.org/cmake/help/latest/command/install.html#targets
344
+
345
+ [libjpeg]: https://www.libjpeg-turbo.org/
346
+
347
+ [libpng]: http://www.libpng.org/pub/png/libpng.html
348
+
349
+ [lld]: https://lld.llvm.org/
350
+
351
+ [msvc-cmd]: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line
352
+
353
+ [msvc]: https://cmake.org/cmake/help/latest/variable/MSVC.html
354
+
355
+ [ninja-download]: https://github.com/ninja-build/ninja/releases
356
+
357
+ [ninja]: https://ninja-build.org/
358
+
359
+ [openblas]: https://www.openblas.net/
360
+
361
+ [project-name_binary_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT-NAME_BINARY_DIR.html
362
+
363
+ [project-name_source_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT-NAME_SOURCE_DIR.html
364
+
365
+ [project]: https://cmake.org/cmake/help/latest/command/project.html
366
+
367
+ [project_binary_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT_BINARY_DIR.html
368
+
369
+ [project_source_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT_SOURCE_DIR.html
370
+
371
+ [pypi-cmake]: https://pypi.org/project/cmake/
372
+
373
+ [python]: https://www.python.org/downloads/
374
+
375
+ [target-file]: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#target-dependent-queries
376
+
377
+ [target_compile_definitions]: https://cmake.org/cmake/help/latest/command/target_compile_definitions.html
378
+
379
+ [target_compile_options]: https://cmake.org/cmake/help/latest/command/target_compile_options.html
380
+
381
+ [target_include_directories]: https://cmake.org/cmake/help/latest/command/target_include_directories.html
382
+
383
+ [target_link_libraries]: https://cmake.org/cmake/help/latest/command/target_link_libraries.html
384
+
385
+ [target_link_options]: https://cmake.org/cmake/help/latest/command/target_link_options.html
386
+
387
+ [vcpkg]: https://github.com/Microsoft/vcpkg
388
+
389
+ [vcvarsall]: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line#vcvarsall-syntax
390
+
391
+ [venv]: https://docs.python.org/3/tutorial/venv.html
392
+
393
+ [win32]: https://cmake.org/cmake/help/latest/variable/WIN32.html
@@ -0,0 +1,104 @@
1
+ # Fuzz testing
2
+ Halide has a set of fuzz-testing harnesses that can be used to find those
3
+ tricky to find, edge cases and bugs that would otherwise not be caught
4
+ by a regular unit-testing suite. At the moment these fuzz-tests are housed
5
+ in the `test/fuzz` directory. The fuzz testing suite use the common,
6
+ [libfuzzer](https://www.llvm.org/docs/LibFuzzer.html) interface for fuzz-tests.
7
+
8
+ ## Building fuzz tests
9
+ Fuzz testing requires specific instrumentation across the entire build;
10
+ to do this we make use of a fuzzing-specific-toolchain/preset. e.g.
11
+
12
+ ```
13
+ cmake -B build --preset linux-x64-fuzzer -DLLVM_ROOT=/path/to/llvminstall
14
+ cmake --build ./build -j$(nproc)
15
+ ```
16
+
17
+ Note that the LLVM install that you use must be built with
18
+ `-D LLVM_ENABLE_RUNTIMES="compiler-rt"` set if you want to build the fuzzer
19
+ tests (failing to do so will fail at configure time); not all prebuilt LLVM
20
+ installs include this, so you may need to build LLVM from source to run the
21
+ fuzz tests locally.
22
+
23
+ ## Using the fuzz-harnesses
24
+ Fuzz-testing harnesses are a little different to a more traditional unit-test
25
+ and don't have a definitive end of test. In other words, a fuzz test will
26
+ run:
27
+ - for an infinite amount of time (the default),
28
+ - for a user specified maximum amount of time,
29
+ - until the fuzzer finds a bug and crashes,
30
+ - you manually kill the process e.g. (ctrl-C).
31
+
32
+ Once you have built the fuzz testing suite using the commands listed above you
33
+ can list the fuzz testing harnesses using the command:
34
+
35
+ ```
36
+ ls ./build/test/fuzz/fuzz_*
37
+ ```
38
+
39
+ To run a fuzzer simply run the fuzz-testing harness with no arguments. e.g.
40
+
41
+ `./build/test/fuzz/fuzz_simplify`
42
+
43
+ By default this will run the fuzz test on a single core and discard whatever.
44
+ temporary corpus is created.
45
+
46
+ To reuse a given corpus (recommended) create a new directory to store the
47
+ corpus generated by your fuzz testing harness and pass that directory into
48
+ your fuzzer e.g.
49
+
50
+ ```
51
+ mkdir fuzz_simplify_corpus -p
52
+ ./build/test/fuzz/fuzz_simplify fuzz_simplify_corpus
53
+ ```
54
+
55
+ This will save the state of the fuzzer between runs, this way any progress
56
+ that your fuzzer makes improving code-coverage will remain persistent on
57
+ your disk.
58
+
59
+ Up until this point the fuzzer has only been running on a single core. To
60
+ speed things up a little, let's run the fuzzer in parallel across all
61
+ available cores on our machine.
62
+
63
+ ```
64
+ ./build/test/fuzz/fuzz_simplify fuzz_simplify_corpus -fork=$(nproc)
65
+ ```
66
+
67
+ ## Reproducing crashes
68
+ An important part of fuzz testing is reproducing the crashing input. To
69
+ handle this, a libfuzzer-based fuzz harness will create a crash file
70
+ whenever the fuzzer exits unexpectedly. This will look something like:
71
+
72
+ `crash-<some_random_hash>`
73
+
74
+ To reproduce a crash we simply rerun our fuzz harness with our crash
75
+ file as the first argument.
76
+
77
+ `./build/test/fuzz/fuzz_simplify crash-<some_random_hash>`
78
+
79
+ So long as your fuzz harness and library are deterministic this should
80
+ reproduce the original crash.
81
+
82
+ ## Adding new fuzz tests
83
+ A bare-bones fuzzer will look something like the following:
84
+ ```cpp
85
+ #include <stdint.h>
86
+ #include <stddef.h>
87
+ #include <my_library.h>
88
+ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
89
+ // Randomly throw data at our function and hope it doesn't crash.
90
+ foo(data, size);
91
+ return 0;
92
+ }
93
+ ```
94
+
95
+ This assumes that our function foo takes in a buffer and the size of said
96
+ buffer. But in many cases we would like to make use of more structured data.
97
+ e.g. a string or a vector of integers etc. Thankfully libfuzzer provides
98
+ a handy helper to convert a raw buffer into common structured data types,
99
+ the [FuzzedDataProvider class](https://github.com/llvm/llvm-project/blob/main/compiler-rt/include/fuzzer/FuzzedDataProvider.h).
100
+ For examples on how to use this class see `test/fuzz/simplify.cpp`.
101
+
102
+ ## Other useful materials
103
+ - [The official libfuzzer docs](https://www.llvm.org/docs/LibFuzzer.html)
104
+ - [The libfuzzer tutorial](https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md)