halide 19.0.0__cp310-cp310-macosx_11_0_arm64.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-darwin.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/lib/cmake/Halide/FindHalide_LLVM.cmake +152 -0
  27. halide/lib/cmake/Halide/FindV8.cmake +33 -0
  28. halide/lib/cmake/Halide/Halide-shared-deps.cmake +0 -0
  29. halide/lib/cmake/Halide/Halide-shared-targets-release.cmake +29 -0
  30. halide/lib/cmake/Halide/Halide-shared-targets.cmake +154 -0
  31. halide/lib/cmake/Halide/HalideConfig.cmake +162 -0
  32. halide/lib/cmake/Halide/HalideConfigVersion.cmake +65 -0
  33. halide/lib/cmake/HalideHelpers/FindHalide_WebGPU.cmake +27 -0
  34. halide/lib/cmake/HalideHelpers/Halide-Interfaces-release.cmake +116 -0
  35. halide/lib/cmake/HalideHelpers/Halide-Interfaces.cmake +236 -0
  36. halide/lib/cmake/HalideHelpers/HalideGeneratorHelpers.cmake +1056 -0
  37. halide/lib/cmake/HalideHelpers/HalideHelpersConfig.cmake +28 -0
  38. halide/lib/cmake/HalideHelpers/HalideHelpersConfigVersion.cmake +54 -0
  39. halide/lib/cmake/HalideHelpers/HalideTargetHelpers.cmake +99 -0
  40. halide/lib/cmake/HalideHelpers/MutexCopy.ps1 +31 -0
  41. halide/lib/cmake/HalideHelpers/TargetExportScript.cmake +55 -0
  42. halide/lib/cmake/Halide_Python/Halide_Python-targets-release.cmake +30 -0
  43. halide/lib/cmake/Halide_Python/Halide_Python-targets.cmake +125 -0
  44. halide/lib/cmake/Halide_Python/Halide_PythonConfig.cmake +26 -0
  45. halide/lib/cmake/Halide_Python/Halide_PythonConfigVersion.cmake +65 -0
  46. halide/lib/libHalide.dylib +0 -0
  47. halide/lib/libHalidePyStubs.a +0 -0
  48. halide/lib/libHalide_GenGen.a +0 -0
  49. halide/lib/libautoschedule_adams2019.so +0 -0
  50. halide/lib/libautoschedule_anderson2021.so +0 -0
  51. halide/lib/libautoschedule_li2018.so +0 -0
  52. halide/lib/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 +5 -0
  84. halide-19.0.0.dist-info/licenses/LICENSE.txt +233 -0
@@ -0,0 +1,812 @@
1
+ # Using Halide from your CMake build
2
+
3
+ This is a detailed guide to building your own Halide programs with the official
4
+ CMake package. If you need directions for building Halide,
5
+ see [BuildingHalideWithCMake.md]. If you are looking for Halide's CMake coding
6
+ guidelines, see [CodeStyleCMake.md].
7
+
8
+ This document assumes some basic familiarity with CMake but tries to be explicit
9
+ in all its examples. To learn more about CMake, consult the
10
+ [documentation][cmake-docs] and engage with the community on
11
+ the [CMake Discourse][cmake-discourse].
12
+
13
+ <!-- TOC -->
14
+ * [Using Halide from your CMake build](#using-halide-from-your-cmake-build)
15
+ * [A basic CMake project](#a-basic-cmake-project)
16
+ * [JIT mode](#jit-mode)
17
+ * [AOT mode](#aot-mode)
18
+ * [Autoschedulers](#autoschedulers)
19
+ * [RunGenMain](#rungenmain)
20
+ * [Halide package documentation](#halide-package-documentation)
21
+ * [Components](#components)
22
+ * [Variables](#variables)
23
+ * [Imported targets](#imported-targets)
24
+ * [Functions](#functions)
25
+ * [`add_halide_generator`](#add_halide_generator)
26
+ * [`add_halide_library`](#add_halide_library)
27
+ * [`add_halide_python_extension_library`](#add_halide_python_extension_library)
28
+ * [`add_halide_runtime`](#add_halide_runtime)
29
+ * [Cross compiling](#cross-compiling)
30
+ * [Use `add_halide_generator`](#use-add_halide_generator)
31
+ * [Use a super-build](#use-a-super-build)
32
+ * [Use `ExternalProject` directly](#use-externalproject-directly)
33
+ * [Use an emulator or run on device](#use-an-emulator-or-run-on-device)
34
+ * [Bypass CMake](#bypass-cmake)
35
+ <!-- TOC -->
36
+
37
+ # A basic CMake project
38
+
39
+ There are two main ways to use Halide in your application: as a **JIT compiler**
40
+ for dynamic pipelines or an **ahead-of-time (AOT) compiler** for static
41
+ pipelines. CMake provides robust support for both use cases.
42
+
43
+ No matter how you intend to use Halide, you will need some basic CMake
44
+ boilerplate.
45
+
46
+ ```cmake
47
+ cmake_minimum_required(VERSION 3.28)
48
+ project(HalideExample)
49
+
50
+ set(CMAKE_CXX_STANDARD 17) # or newer
51
+ set(CMAKE_CXX_STANDARD_REQUIRED YES)
52
+ set(CMAKE_CXX_EXTENSIONS NO)
53
+
54
+ find_package(Halide REQUIRED)
55
+ ```
56
+
57
+ The [`cmake_minimum_required`][cmake_minimum_required] command is required to be
58
+ the first command executed in a CMake program. It disables all the deprecated
59
+ behavior ("policies" in CMake lingo) from earlier versions. The
60
+ [`project`][project] command sets the name of the project (and accepts arguments
61
+ for versioning, language support, etc.) and is required by CMake to be called
62
+ immediately after setting the minimum version.
63
+
64
+ The next three variables set the project-wide C++ standard. The first,
65
+ [`CMAKE_CXX_STANDARD`][cmake_cxx_standard], simply sets the standard version.
66
+ Halide requires at least C++17. The second,
67
+ [`CMAKE_CXX_STANDARD_REQUIRED`][cmake_cxx_standard_required], tells CMake to
68
+ fail if the compiler cannot provide the requested standard version. Lastly,
69
+ [`CMAKE_CXX_EXTENSIONS`][cmake_cxx_extensions] tells CMake to disable
70
+ vendor-specific extensions to C++. This is not necessary to simply use Halide,
71
+ but we do not allow such extensions in the Halide repo.
72
+
73
+ Finally, we use [`find_package`][find_package] to locate Halide on your system.
74
+ When using the pip package on Linux and macOS, CMake's `find_package`
75
+ command should find Halide as long as you're in the same virtual environment you
76
+ installed it in. On Windows, you will need to add the virtual environment root
77
+ directory to [`CMAKE_PREFIX_PATH`][cmake_prefix_path]:
78
+
79
+ ```shell
80
+ $ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%VIRTUAL_ENV%
81
+ ```
82
+
83
+ If `find_package` cannot find Halide, set `CMAKE_PREFIX_PATH` to the Halide
84
+ installation directory.
85
+
86
+ ## JIT mode
87
+
88
+ To use Halide in JIT mode (like the [tutorials][halide-tutorials] do, for
89
+ example), you can simply link to `Halide::Halide`.
90
+
91
+ ```cmake
92
+ # ... same project setup as before ...
93
+ add_executable(my_halide_app main.cpp)
94
+ target_link_libraries(my_halide_app PRIVATE Halide::Halide)
95
+ ```
96
+
97
+ Then `Halide.h` will be available to your code and everything should just work.
98
+ That's it!
99
+
100
+ ## AOT mode
101
+
102
+ Using Halide in AOT mode is more complicated so we'll walk through it step by
103
+ step. Note that this only applies to Halide generators, so it might be useful to
104
+ re-read the [tutorial on generators][halide-generator-tutorial]. Assume (like in
105
+ the tutorial) that you have a source file named `my_generators.cpp` and that in
106
+ it, you have generator classes `MyFirstGenerator` and `MySecondGenerator` with
107
+ registered names `my_first_generator` and `my_second_generator` respectively.
108
+
109
+ Then the first step is to add a **generator executable** to your build:
110
+
111
+ ```cmake
112
+ # ... same project setup as before ...
113
+ add_halide_generator(my_generators SOURCES my_generators.cpp)
114
+ ```
115
+
116
+ Using the generator executable, we can add a Halide library corresponding to
117
+ `MyFirstGenerator`.
118
+
119
+ ```cmake
120
+ # ... continuing from above
121
+ add_halide_library(my_first_generator FROM my_generators)
122
+ ```
123
+
124
+ This will create a static library target in CMake that corresponds to the output
125
+ of running your generator. The second generator in the file requires generator
126
+ parameters to be passed to it. These are also easy to handle:
127
+
128
+ ```cmake
129
+ # ... continuing from above
130
+ add_halide_library(my_second_generator FROM my_generators
131
+ PARAMS parallel=false scale=3.0 rotation=ccw output.type=uint16)
132
+ ```
133
+
134
+ Adding multiple configurations is easy, too:
135
+
136
+ ```cmake
137
+ # ... continuing from above
138
+ add_halide_library(my_second_generator_2 FROM my_generators
139
+ GENERATOR my_second_generator
140
+ PARAMS scale=9.0 rotation=ccw output.type=float32)
141
+
142
+ add_halide_library(my_second_generator_3 FROM my_generators
143
+ GENERATOR my_second_generator
144
+ PARAMS parallel=false output.type=float64)
145
+ ```
146
+
147
+ Here, we had to specify which generator to use (`my_second_generator`) since it
148
+ uses the target name by default. The functions in these libraries will be named
149
+ after the target names, `my_second_generator_2` and `my_second_generator_3`, by
150
+ default, but it is possible to control this via the `FUNCTION_NAME` parameter.
151
+
152
+ Each one of these targets, `<GEN>`, carries an associated `<GEN>.runtime`
153
+ target, which is also a static library containing the Halide runtime. It is
154
+ transitively linked through `<GEN>` to targets that link to `<GEN>`. On an
155
+ operating system like Linux, where weak linking is available, this is not an
156
+ issue. However, on Windows, this can fail due to symbol redefinitions. In these
157
+ cases, you must declare that two Halide libraries share a runtime, like so:
158
+
159
+ ```cmake
160
+ # ... updating above
161
+ add_halide_library(my_second_generator_2 FROM my_generators
162
+ GENERATOR my_second_generator
163
+ USE_RUNTIME my_first_generator.runtime
164
+ PARAMS scale=9.0 rotation=ccw output.type=float32)
165
+
166
+ add_halide_library(my_second_generator_3 FROM my_generators
167
+ GENERATOR my_second_generator
168
+ USE_RUNTIME my_first_generator.runtime
169
+ PARAMS parallel=false output.type=float64)
170
+ ```
171
+
172
+ This will even work correctly when different combinations of targets are
173
+ specified for each halide library. A "greatest common denominator" target will
174
+ be chosen that is compatible with all of them (or the build will fail).
175
+
176
+ ### Autoschedulers
177
+
178
+ When the autoschedulers are included in the release package, they are very
179
+ simple to apply to your own generators. For example, we could update the
180
+ definition of the `my_first_generator` library above to use the `Adams2019`
181
+ autoscheduler:
182
+
183
+ ```cmake
184
+ add_halide_library(my_second_generator FROM my_generators
185
+ AUTOSCHEDULER Halide::Adams2019)
186
+ ```
187
+
188
+ ### RunGenMain
189
+
190
+ Halide provides a generic driver for generators to be used during development
191
+ for benchmarking and debugging. Suppose you have a generator executable called
192
+ `my_gen` and a generator within called `my_filter`. Then you can pass a variable
193
+ name to the `REGISTRATION` parameter of `add_halide_library` which will contain
194
+ the name of a generated C++ source that should be linked to `Halide::RunGenMain`
195
+ and `my_filter`.
196
+
197
+ For example:
198
+
199
+ ```cmake
200
+ add_halide_library(my_filter FROM my_gen
201
+ REGISTRATION filter_reg_cpp)
202
+ add_executable(runner ${filter_reg_cpp})
203
+ target_link_libraries(runner PRIVATE my_filter Halide::RunGenMain)
204
+ ```
205
+
206
+ Then you can run, debug, and benchmark your generator through the `runner`
207
+ executable. Learn how to interact with these executables
208
+ in [RunGen.md](./RunGen.md).
209
+
210
+ # Halide package documentation
211
+
212
+ Halide provides a CMake _package configuration_ module. The intended way to use
213
+ the CMake build is to run `find_package(Halide ...)` in your `CMakeLists.txt`
214
+ file. Closely read the [`find_package` documentation][find_package] before
215
+ proceeding.
216
+
217
+ ## Components
218
+
219
+ The Halide package script understands a handful of optional components when
220
+ loading the package.
221
+
222
+ First, if you plan to use the Halide Image IO library, you will want to include
223
+ the `png` and `jpeg` components when loading Halide.
224
+
225
+ Second, Halide releases can contain a variety of configurations: static, shared,
226
+ debug, release, etc. CMake handles Debug/Release configurations automatically,
227
+ but generally only allows one type of library to be loaded.
228
+
229
+ The package understands two components, `static` and `shared`, that specify
230
+ which type of library you would like to load. For example, if you want to make
231
+ sure that you link against shared Halide, you can write:
232
+
233
+ ```cmake
234
+ find_package(Halide REQUIRED COMPONENTS shared)
235
+ ```
236
+
237
+ If the shared libraries are not available, this will result in a failure.
238
+
239
+ If no component is specified, then the `Halide_SHARED_LIBS` variable is checked.
240
+ If it is defined and set to true, then the shared libraries will be loaded or
241
+ the package loading will fail. Similarly, if it is defined and set to false, the
242
+ static libraries will be loaded.
243
+
244
+ If no component is specified and `Halide_SHARED_LIBS` is _not_ defined, then the
245
+ [`BUILD_SHARED_LIBS`][build_shared_libs] variable will be inspected. If it is
246
+ **not defined** or **defined and set to true**, then it will attempt to load the
247
+ shared libs and fall back to the static libs if they are not available.
248
+ Similarly, if `BUILD_SHARED_LIBS` is **defined and set to false**, then it will
249
+ try the static libs first then fall back to the shared libs.
250
+
251
+ To ensure that the Python bindings are available, include the `Python`
252
+ component.
253
+
254
+ ## Variables
255
+
256
+ Variables that control package loading:
257
+
258
+ | Variable | Description |
259
+ |-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
260
+ | `Halide_SHARED_LIBS` | override `BUILD_SHARED_LIBS` when loading the Halide package via `find_package`. Has no effect when using Halide via `add_subdirectory` as a Git or `FetchContent` submodule. |
261
+ | `Halide_RUNTIME_NO_THREADS` | skip linking of Threads library to runtime. Should be set if your toolchain does not support it (e.g. baremetal). |
262
+ | `Halide_RUNTIME_NO_DL_LIBS` | skip linking of DL library to runtime. Should be set if your toolchain does not support it (e.g. baremetal). |
263
+
264
+ Variables set by the package:
265
+
266
+ | Variable | Description |
267
+ |----------------------------|--------------------------------------------------------------------|
268
+ | `Halide_VERSION` | The full version string of the loaded Halide package |
269
+ | `Halide_VERSION_MAJOR` | The major version of the loaded Halide package |
270
+ | `Halide_VERSION_MINOR` | The minor version of the loaded Halide package |
271
+ | `Halide_VERSION_PATCH` | The patch version of the loaded Halide package |
272
+ | `Halide_VERSION_TWEAK` | The tweak version of the loaded Halide package |
273
+ | `Halide_HOST_TARGET` | The Halide target triple corresponding to "host" for this build. |
274
+ | `Halide_CMAKE_TARGET` | The Halide target triple corresponding to the active CMake target. |
275
+ | `Halide_ENABLE_EXCEPTIONS` | Whether Halide was compiled with exception support |
276
+ | `Halide_ENABLE_RTTI` | Whether Halide was compiled with RTTI |
277
+ | `WITH_AUTOSCHEDULERS` | Whether the autoschedulers are available |
278
+
279
+ Variables that control package behavior:
280
+
281
+ | Variable | Description |
282
+ |---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
283
+ | `Halide_PYTHON_LAUNCHER` | Semicolon separated list containing a command to launch the Python interpreter. Can be used to set environment variables for Python generators. |
284
+ | `Halide_NO_DEFAULT_FLAGS` | Off by default. When enabled, suppresses recommended compiler flags that would be added by `add_halide_generator` |
285
+
286
+ ## Imported targets
287
+
288
+ Halide defines the following targets that are available to users:
289
+
290
+ | Imported target | Description |
291
+ |----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
292
+ | `Halide::Halide` | this is the JIT-mode library to use when using Halide from C++. |
293
+ | `Halide::Generator` | this is the target to use when manually defining a generator executable. It supplies a `main()` function. |
294
+ | `Halide::Runtime` | adds include paths to the Halide runtime headers |
295
+ | `Halide::Tools` | adds include paths to the Halide tools, including the benchmarking utility. |
296
+ | `Halide::ImageIO` | adds include paths to the Halide image IO utility. Depends on `PNG::PNG` and `JPEG::JPEG` if they exist or were loaded through the corresponding package components. |
297
+ | `Halide::ThreadPool` | adds include paths to the Halide _simple_ thread pool utility library. This is not the same as the runtime's thread pool and is intended only for use by tests. Depends on `Threads::Threads`. |
298
+ | `Halide::RunGenMain` | used with the `REGISTRATION` parameter of `add_halide_library` to create simple runners and benchmarking tools for Halide libraries. |
299
+
300
+ The following targets only guaranteed when requesting the `Python` component
301
+ (`Halide_Python_FOUND` will be true):
302
+
303
+ | Imported target | Description |
304
+ |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
305
+ | `Halide::Python` | this is a Python 3 package that can be referenced as `$<TARGET_FILE_DIR:Halide::Python>/..` when setting up `PYTHONPATH` for Python tests or the like from CMake. |
306
+
307
+ The following targets only guaranteed when `WITH_AUTOSCHEDULERS` is true:
308
+
309
+ | Imported target | Description |
310
+ |-------------------------|-----------------------------------------------------------------|
311
+ | `Halide::Adams2019` | the Adams et.al. 2019 autoscheduler (no GPU support) |
312
+ | `Halide::Anderson2021` | the Anderson, et.al. 2021 autoscheduler (full GPU support) |
313
+ | `Halide::Li2018` | the Li et.al. 2018 gradient autoscheduler (limited GPU support) |
314
+ | `Halide::Mullapudi2016` | the Mullapudi et.al. 2016 autoscheduler (no GPU support) |
315
+
316
+ ## Functions
317
+
318
+ The Halide package provides several useful functions for dealing with AOT
319
+ compilation steps.
320
+
321
+ ### `add_halide_generator`
322
+
323
+ This function aids in creating cross-compilable builds that use Halide
324
+ generators.
325
+
326
+ ```
327
+ add_halide_generator(
328
+ target
329
+ [PACKAGE_NAME package-name]
330
+ [PACKAGE_NAMESPACE namespace]
331
+ [EXPORT_FILE export-file]
332
+ [PYSTUB generator-name]
333
+ [LINK_LIBRARIES lib1 ...]
334
+ [[SOURCES] source1 ...]
335
+ )
336
+ ```
337
+
338
+ Every named argument is optional, and the function uses the following default
339
+ arguments:
340
+
341
+ - If `PACKAGE_NAME` is not provided, it defaults to
342
+ `${PROJECT_NAME}-halide_generators`.
343
+ - If `PACKAGE_NAMESPACE` is not provided, it defaults to
344
+ `${PROJECT_NAME}::halide_generators::`.
345
+ - If `EXPORT_FILE` is not provided, it defaults to
346
+ `${PROJECT_BINARY_DIR}/cmake/${ARG_PACKAGE_NAME}-config.cmake`
347
+
348
+ This function guarantees that a Halide generator target named
349
+ `<namespace><target>` is available. It will first search for a package named
350
+ `<package-name>` using `find_package`; if it is found, it is assumed that it
351
+ provides the target. Otherwise, it will create an executable target named
352
+ `target` and an `ALIAS` target `<namespace><target>`. This function also creates
353
+ a custom target named `<package-name>` if it does not exist and
354
+ `<target>` would exist. In this case, `<package-name>` will depend on
355
+ `<target>`, this enables easy building of _just_ the Halide generators managed
356
+ by this function.
357
+
358
+ After the call, `<PACKAGE_NAME>_FOUND` will be set to true if the host
359
+ generators were imported (and hence won't be built). Otherwise, it will be set
360
+ to false. This variable may be used to conditionally set properties on
361
+ `<target>`.
362
+
363
+ Please
364
+ see [test/integration/xc](https://github.com/halide/Halide/tree/main/test/integration/xc)
365
+ for a simple example
366
+ and [apps/hannk](https://github.com/halide/Halide/tree/main/apps/hannk) for a
367
+ complete app that uses it extensively.
368
+
369
+ The `SOURCES` keyword marks the beginning of sources to be used to build
370
+ `<target>`, if it is not loaded. All unparsed arguments will be interpreted as
371
+ sources.
372
+
373
+ The `LINK_LIBRARIES` argument lists libraries that should be linked to
374
+ `<target>` when it is being built in the present build system.
375
+
376
+ If `PYSTUB` is specified, then a Python Extension will be built that wraps the
377
+ Generator with CPython glue to allow use of the Generator Python 3. The result
378
+ will be a shared library of the form
379
+ `<target>_pystub.<soabi>.so`, where `<soabi>` describes the specific Python
380
+ version and platform (e.g., `cpython-310-darwin` for Python 3.10 on macOS). See
381
+ [Python.md](Python.md) for examples of use.
382
+
383
+ ### `add_halide_library`
384
+
385
+ This is the main function for managing generators in AOT compilation. The full
386
+ signature follows:
387
+
388
+ ```
389
+ add_halide_library(<target> FROM <generator-target>
390
+ [GENERATOR generator-name]
391
+ [FUNCTION_NAME function-name]
392
+ [NAMESPACE cpp-namespace]
393
+ [USE_RUNTIME hl-target]
394
+ [PARAMS param1 [param2 ...]]
395
+ [TARGETS target1 [target2 ...]]
396
+ [FEATURES feature1 [feature2 ...]]
397
+ [FEATURES[<triple>] feature1 [feature2 ...]]
398
+ [PLUGINS plugin1 [plugin2 ...]]
399
+ [AUTOSCHEDULER scheduler-name]
400
+ [FUNCTION_INFO_HEADER OUTVAR]
401
+ [HEADER OUTVAR]
402
+ [REGISTRATION OUTVAR]
403
+ [<extra-output> OUTVAR]
404
+ [GRADIENT_DESCENT]
405
+ [C_BACKEND]
406
+ [NO_THREADS]
407
+ [NO_DL_LIBS])
408
+
409
+ triple = <arch>-<bits>-<os>
410
+ arch = x86 | arm | powerpc | hexagon | wasm | riscv
411
+ bits = 32 | 64
412
+ os = linux | windows | osx | android | ios | qurt | noos | fuchsia | wasmrt
413
+
414
+ extra-output = ASSEMBLY | BITCODE | COMPILER_LOG | C_SOURCE | FEATURIZATION
415
+ | HLPIPE | LLVM_ASSEMBLY | PYTHON_EXTENSION | PYTORCH_WRAPPER
416
+ | SCHEDULE | STMT | STMT_HTML
417
+ ```
418
+
419
+ This function creates a called `<target>` corresponding to running the
420
+ `<generator-target>` (an executable target which links to `Halide::Generator`)
421
+ one time, using command line arguments derived from the other parameters.
422
+
423
+ The arguments `GENERATOR` and `FUNCTION_NAME` default to `<target>`. They
424
+ correspond to the `-g` and `-f` command line flags, respectively.
425
+
426
+ `NAMESPACE` is syntactic sugar to specify the C++ namespace (if any) of the
427
+ generated function; you can also specify the C++ namespace (if any) directly in
428
+ the `FUNCTION_NAME` argument, but for repeated declarations or very long
429
+ namespaces, specifying this separately can provide more readable build files.
430
+
431
+ If `USE_RUNTIME` is not specified, this function will create another target
432
+ called `<target>.runtime` which corresponds to running the generator with `-r`
433
+ and a compatible list of targets. This runtime target is an `INTERFACE`
434
+ dependency of `<target>`. If multiple runtime targets need to be linked
435
+ together, setting `USE_RUNTIME` to another Halide runtime library, `<target2>`
436
+ will prevent the generation of `<target>.runtime` and instead use
437
+ `<target2>.runtime`. This argument is most commonly used in conjunction with [
438
+ `add_halide_runtime`](#add_halide_runtime).
439
+
440
+ Parameters can be passed to a generator via the `PARAMS` argument. Parameters
441
+ should be space-separated. Similarly, `TARGETS` is a space-separated list of
442
+ targets for which to generate code in a single function. They must all share the
443
+ same platform/bits/os triple (e.g. `arm-32-linux`). Features that are in common
444
+ among all targets, including device libraries (like `cuda`) should go in
445
+ `FEATURES`. If `TARGETS` is not specified, the value of `Halide_TARGET`
446
+ specified at configure time will be used.
447
+
448
+ Every element of `TARGETS` must begin with the same `arch-bits-os` triple. This
449
+ function understands two _meta-triples_, `host` and `cmake`. The meta-triple
450
+ `host` is equal to the `arch-bits-os` triple used to compile Halide along with
451
+ all the supported instruction set extensions. On platforms that support running
452
+ both 32 and 64-bit programs, this will not necessarily equal the platform the
453
+ compiler is running on or that CMake is targeting.
454
+
455
+ The meta-triple `cmake` is equal to the `arch-bits-os` of the current CMake
456
+ target. This is useful if you want to make sure you are not unintentionally
457
+ cross-compiling, which would result in an [`IMPORTED` target][imported-target]
458
+ being created. When `TARGETS` is empty and the `host` target would not
459
+ cross-compile, then `host` will be used. Otherwise, `cmake` will be used and an
460
+ author warning will be issued.
461
+
462
+ When `CMAKE_OSX_ARCHITECTURES` is set and the `TARGETS` argument resolves to
463
+ `cmake`, the generator will be run once for each architecture and the results
464
+ will be fused together using `lipo`. This behavior extends to runtime targets.
465
+
466
+ To use an autoscheduler, set the `AUTOSCHEDULER` argument to a target named like
467
+ `Namespace::Scheduler`, for example `Halide::Adams2019`. This will set the
468
+ `autoscheduler` GeneratorParam on the generator command line to `Scheduler`
469
+ and add the target to the list of plugins. Additional plugins can be loaded by
470
+ setting the `PLUGINS` argument. If the argument to `AUTOSCHEDULER` does not
471
+ contain `::` or it does not name a target, it will be passed to the `-s` flag
472
+ verbatim.
473
+
474
+ If `GRADIENT_DESCENT` is set, then the module will be built suitably for
475
+ gradient descent calculation in TensorFlow or PyTorch. See
476
+ `Generator::build_gradient_module()` for more documentation. This corresponds to
477
+ passing `-d 1` at the generator command line.
478
+
479
+ If the `C_BACKEND` option is set, this command will invoke the configured C++
480
+ compiler on a generated source. Note that a `<target>.runtime` target is _not_
481
+ created in this case, and the `USE_RUNTIME` option is ignored. Other options
482
+ work as expected.
483
+
484
+ If `REGISTRATION` is set, the path (relative to `CMAKE_CURRENT_BINARY_DIR`)
485
+ to the generated `.registration.cpp` file will be set in `OUTVAR`. This can be
486
+ used to generate a runner for a Halide library that is useful for benchmarking
487
+ and testing, as documented above. This is equivalent to setting
488
+ `-e registration` at the generator command line.
489
+
490
+ If `HEADER` is set, the path (relative to `CMAKE_CURRENT_BINARY_DIR`) to the
491
+ generated `.h` header file will be set in `OUTVAR`. This can be used with
492
+ `install(FILES)` to conveniently deploy the generated header along with your
493
+ library.
494
+
495
+ If `FUNCTION_INFO_HEADER` is set, the path (relative to
496
+ `CMAKE_CURRENT_BINARY_DIR`) to the generated `.function_info.h` header file will
497
+ be set in `OUTVAR`. This produces a file that contains `constexpr`
498
+ descriptions of information about the generated functions (e.g., argument type
499
+ and information). It is generated separately from the normal `HEADER`
500
+ file because `HEADER` is intended to work with basic `extern "C"` linkage, while
501
+ `FUNCTION_INFO_HEADER` requires C++17 or later to use effectively.
502
+ (This can be quite useful for advanced usages, such as producing automatic call
503
+ wrappers, etc.) Examples of usage can be found in the generated file.
504
+
505
+ Each of the `extra-output` arguments directly correspond to an extra output (via
506
+ `-e`) from the generator. The value `OUTVAR` names a variable into which a
507
+ path (relative to
508
+ [`CMAKE_CURRENT_BINARY_DIR`][cmake_current_binary_dir]) to the extra file will
509
+ be written.
510
+
511
+ When `NO_THREADS` is passed, the library targets will not depend on
512
+ `Threads::Threads`. It is your responsibility to link to an equivalent target.
513
+
514
+ When `NO_DL_LIBS` is passed, the library targets will not depend on
515
+ `${CMAKE_DL_LIBS}`. It is your responsibility to link to an equivalent library.
516
+
517
+ ### `add_halide_python_extension_library`
518
+
519
+ This function wraps the outputs of one or more `add_halide_library` targets with
520
+ glue code to produce a Python Extension library.
521
+
522
+ ```
523
+ add_halide_python_extension_library(
524
+ target
525
+ [MODULE_NAME module-name]
526
+ HALIDE_LIBRARIES library1 ...
527
+ )
528
+ ```
529
+
530
+ `HALIDE_LIBRARIES` is a list of one of more `add_halide_library` targets. Each
531
+ will be added to the extension as a callable method of the module. Note that
532
+ every library specified must be built with the `PYTHON_EXTENSION` keyword
533
+ specified, and all libraries must use the same Halide runtime.
534
+
535
+ The result will be a shared library of the form `<target>.<soabi>.so`, where
536
+ `<soabi>` describes the specific Python version and platform (e.g.,
537
+ `cpython-310-darwin` for Python 3.10 on macOS.)
538
+
539
+ ### `add_halide_runtime`
540
+
541
+ This function generates a library containing a Halide runtime. Most user code
542
+ will never need to use this, as `add_halide_library()` will call it for you if
543
+ necessary. The most common use case is usually in conjunction with
544
+ `add_halide_python_extension_library()`, as a way to ensure that all the halide
545
+ libraries share an identical runtime.
546
+
547
+ ```
548
+ add_halide_runtime(
549
+ target
550
+ [TARGETS target1 [target2 ...]]
551
+ [NO_THREADS]
552
+ [NO_DL_LIBS]
553
+ )
554
+ ```
555
+
556
+ The `TARGETS`, `NO_THREADS`, and `NO_DL_LIBS` arguments have identical semantics
557
+ to the argument of the same name for [
558
+ `add_halide_library`](#add_halide_library).
559
+
560
+ # Cross compiling
561
+
562
+ Cross-compiling in CMake can be tricky, since CMake doesn't easily support
563
+ compiling for both the host platform and the cross platform within the same
564
+ build. Unfortunately, Halide generator executables are just about always
565
+ designed to run on the host platform. Each project will be set up differently
566
+ and have different requirements, but here are some suggestions for effective use
567
+ of CMake in these scenarios.
568
+
569
+ ## Use `add_halide_generator`
570
+
571
+ If you are writing new programs that use Halide, you might wish to use
572
+ `add_halide_generator`. When using this helper, you are expected to build your
573
+ project twice: once for your build host and again for your intended target.
574
+
575
+ When building the host build, you can use the `<package-name>` (see the
576
+ documentation above) target to build _just_ the generators. Then, in the target
577
+ build, set `<package-name>_ROOT` to the host build directory.
578
+
579
+ For example:
580
+
581
+ ```
582
+ $ cmake -G Ninja -S . -B build-host -DCMAKE_BUILD_TYPE=Release
583
+ $ cmake --build build-host --target <package-name>
584
+ $ cmake -G Ninja -S . -B build-target --toolchain /path/to/target-tc.cmake \
585
+ -DCMAKE_BUILD_TYPE=Release \
586
+ -D<package-name>_ROOT:FILEPATH=$PWD/build-host
587
+ $ cmake --build build-target
588
+ ```
589
+
590
+ ## Use a super-build
591
+
592
+ A CMake super-build consists of breaking down a project into subprojects that
593
+ are isolated by [toolchain][cmake-toolchains]. The basic structure is to have an
594
+ outermost project that only coordinates the sub-builds via the
595
+ [`ExternalProject`][ExternalProject] module.
596
+
597
+ One would then use Halide to build a generator executable in one self-contained
598
+ project, then export that target to be used in a separate project. The second
599
+ project would be configured with the target [toolchain][cmake-toolchains] and
600
+ would call `add_halide_library` with no `TARGETS` option and set `FROM` equal to
601
+ the name of the imported generator executable. Obviously, this is a significant
602
+ increase in complexity over a typical CMake project.
603
+
604
+ This is very compatible with the `add_halide_generator` strategy above.
605
+
606
+ ## Use `ExternalProject` directly
607
+
608
+ A lighter weight alternative to the above is to use
609
+ [`ExternalProject`][ExternalProject] directly in your parent build. Configure
610
+ the parent build with the target [toolchain][cmake-toolchains], and configure
611
+ the inner project to use the host toolchain. Then, manually create an
612
+ [`IMPORTED` target][imported-executable] for your generator executable and call
613
+ `add_halide_library` as described above.
614
+
615
+ The main drawback of this approach is that creating accurate `IMPORTED` targets
616
+ is difficult since predicting the names and locations of your binaries across
617
+ all possible platform and CMake project generators is difficult. In particular,
618
+ it is hard to predict executable extensions in cross-OS builds.
619
+
620
+ ## Use an emulator or run on device
621
+
622
+ The [`CMAKE_CROSSCOMPILING_EMULATOR`][cmake_crosscompiling_emulator] variable
623
+ allows one to specify a command _prefix_ to run a target-system binary on the
624
+ host machine. One could set this to a custom shell script that uploads the
625
+ generator executable, runs it on the device and copies back the results.
626
+
627
+ Another option is to install `qemu-user-static` to transparently emulate the
628
+ cross-built generator.
629
+
630
+ ## Bypass CMake
631
+
632
+ The previous two options ensure that the targets generated by
633
+ `add_halide_library` will be _normal_ static libraries. This approach does not
634
+ use [`ExternalProject`][ExternalProject], but instead produces `IMPORTED`
635
+ targets. The main drawback of `IMPORTED` targets is that they are considered
636
+ second-class in CMake. In particular, they cannot be installed with the typical
637
+ [`install(TARGETS)` command][install-targets]. Instead, they must be installed
638
+ using [`install(FILES)`][install-files] and the
639
+ [`$<TARGET_FILE:tgt>`][target-file] generator expression.
640
+
641
+
642
+ [BuildingHalideWithCMake.md]: ./BuildingHalideWithCMake.md
643
+
644
+ [CodeStyleCMake.md]: ./CodeStyleCMake.md
645
+
646
+ [ExternalProject]: https://cmake.org/cmake/help/latest/module/ExternalProject.html
647
+
648
+ [HalideCMakePackage.md]: ./HalideCMakePackage.md
649
+
650
+ [add_custom_command]: https://cmake.org/cmake/help/latest/command/add_custom_command.html
651
+
652
+ [add_library]: https://cmake.org/cmake/help/latest/command/add_library.html
653
+
654
+ [add_subdirectory]: https://cmake.org/cmake/help/latest/command/add_subdirectory.html
655
+
656
+ [atlas]: http://math-atlas.sourceforge.net/
657
+
658
+ [brew-cmake]: https://formulae.brew.sh/cask/cmake#default
659
+
660
+ [build_shared_libs]: https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
661
+
662
+ [cmake-apt]: https://apt.kitware.com/
663
+
664
+ [cmake-discourse]: https://discourse.cmake.org/
665
+
666
+ [cmake-docs]: https://cmake.org/cmake/help/latest/
667
+
668
+ [cmake-download]: https://cmake.org/download/
669
+
670
+ [cmake-from-source]: https://cmake.org/install/
671
+
672
+ [cmake-genex]: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html
673
+
674
+ [cmake-install]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#install-a-project
675
+
676
+ [cmake-propagation]: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#transitive-usage-requirements
677
+
678
+ [cmake-toolchains]: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
679
+
680
+ [cmake-user-interaction]: https://cmake.org/cmake/help/latest/guide/user-interaction/index.html#setting-build-variables
681
+
682
+ [cmake_binary_dir]: https://cmake.org/cmake/help/latest/variable/CMAKE_BINARY_DIR.html
683
+
684
+ [cmake_build_type]: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
685
+
686
+ [cmake_crosscompiling]: https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING.html
687
+
688
+ [cmake_crosscompiling_emulator]: https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING_EMULATOR.html
689
+
690
+ [cmake_ctest_command]: https://cmake.org/cmake/help/latest/variable/CMAKE_CTEST_COMMAND.html
691
+
692
+ [cmake_current_binary_dir]: https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_BINARY_DIR.html
693
+
694
+ [cmake_cxx_extensions]: https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_EXTENSIONS.html
695
+
696
+ [cmake_cxx_standard]: https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html
697
+
698
+ [cmake_cxx_standard_required]: https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD_REQUIRED.html
699
+
700
+ [cmake_foreach]: https://cmake.org/cmake/help/latest/command/foreach.html
701
+
702
+ [cmake_if]: https://cmake.org/cmake/help/latest/command/if.html
703
+
704
+ [cmake_lang_compiler_id]: https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
705
+
706
+ [cmake_make_program]: https://cmake.org/cmake/help/latest/variable/CMAKE_MAKE_PROGRAM.html
707
+
708
+ [cmake_minimum_required]: https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html
709
+
710
+ [cmake_prefix_path]: https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html
711
+
712
+ [cmake_presets]: https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html
713
+
714
+ [cmake_sizeof_void_p]: https://cmake.org/cmake/help/latest/variable/CMAKE_SIZEOF_VOID_P.html
715
+
716
+ [cmake_source_dir]: https://cmake.org/cmake/help/latest/variable/CMAKE_SOURCE_DIR.html
717
+
718
+ [cmake_system_name]: https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html
719
+
720
+ [doxygen-download]: https://www.doxygen.nl/download.html
721
+
722
+ [doxygen]: https://www.doxygen.nl/index.html
723
+
724
+ [eigen]: http://eigen.tuxfamily.org/index.php?title=Main_Page
725
+
726
+ [enable_testing]: https://cmake.org/cmake/help/latest/command/enable_testing.html
727
+
728
+ [fetchcontent]: https://cmake.org/cmake/help/latest/module/FetchContent.html
729
+
730
+ [find_package]: https://cmake.org/cmake/help/latest/command/find_package.html
731
+
732
+ [findcuda]: https://cmake.org/cmake/help/latest/module/FindCUDA.html
733
+
734
+ [findcudatoolkit]: https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html
735
+
736
+ [finddoxygen]: https://cmake.org/cmake/help/latest/module/FindDoxygen.html
737
+
738
+ [findjpeg]: https://cmake.org/cmake/help/latest/module/FindJPEG.html
739
+
740
+ [findopencl]: https://cmake.org/cmake/help/latest/module/FindOpenCL.html
741
+
742
+ [findpng]: https://cmake.org/cmake/help/latest/module/FindPNG.html
743
+
744
+ [findpython3]: https://cmake.org/cmake/help/latest/module/FindPython3.html
745
+
746
+ [findx11]: https://cmake.org/cmake/help/latest/module/FindX11.html
747
+
748
+ [halide-generator-tutorial]: https://halide-lang.org/tutorials/tutorial_lesson_15_generators.html
749
+
750
+ [halide-tutorials]: https://halide-lang.org/tutorials/tutorial_introduction.html
751
+
752
+ [homebrew]: https://brew.sh
753
+
754
+ [imported-executable]: https://cmake.org/cmake/help/latest/command/add_executable.html#imported-executables
755
+
756
+ [imported-target]: https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#imported-targets
757
+
758
+ [include]: https://cmake.org/cmake/help/latest/command/include.html
759
+
760
+ [install-files]: https://cmake.org/cmake/help/latest/command/install.html#files
761
+
762
+ [install-targets]: https://cmake.org/cmake/help/latest/command/install.html#targets
763
+
764
+ [libjpeg]: https://www.libjpeg-turbo.org/
765
+
766
+ [libpng]: http://www.libpng.org/pub/png/libpng.html
767
+
768
+ [lld]: https://lld.llvm.org/
769
+
770
+ [msvc-cmd]: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line
771
+
772
+ [msvc]: https://cmake.org/cmake/help/latest/variable/MSVC.html
773
+
774
+ [ninja-download]: https://github.com/ninja-build/ninja/releases
775
+
776
+ [ninja]: https://ninja-build.org/
777
+
778
+ [openblas]: https://www.openblas.net/
779
+
780
+ [project-name_binary_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT-NAME_BINARY_DIR.html
781
+
782
+ [project-name_source_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT-NAME_SOURCE_DIR.html
783
+
784
+ [project]: https://cmake.org/cmake/help/latest/command/project.html
785
+
786
+ [project_binary_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT_BINARY_DIR.html
787
+
788
+ [project_source_dir]: https://cmake.org/cmake/help/latest/variable/PROJECT_SOURCE_DIR.html
789
+
790
+ [pypi-cmake]: https://pypi.org/project/cmake/
791
+
792
+ [python]: https://www.python.org/downloads/
793
+
794
+ [target-file]: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#target-dependent-queries
795
+
796
+ [target_compile_definitions]: https://cmake.org/cmake/help/latest/command/target_compile_definitions.html
797
+
798
+ [target_compile_options]: https://cmake.org/cmake/help/latest/command/target_compile_options.html
799
+
800
+ [target_include_directories]: https://cmake.org/cmake/help/latest/command/target_include_directories.html
801
+
802
+ [target_link_libraries]: https://cmake.org/cmake/help/latest/command/target_link_libraries.html
803
+
804
+ [target_link_options]: https://cmake.org/cmake/help/latest/command/target_link_options.html
805
+
806
+ [vcpkg]: https://github.com/Microsoft/vcpkg
807
+
808
+ [vcvarsall]: https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line#vcvarsall-syntax
809
+
810
+ [venv]: https://docs.python.org/3/tutorial/venv.html
811
+
812
+ [win32]: https://cmake.org/cmake/help/latest/variable/WIN32.html