forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add add_halide_python_extension_library() rule (halide#6979)
* Add add_halide_python_extension_library() rule This adds a rule to create a single Python extension library from one (or more) halide_library rules. This allows you to package multiple Halide filters into a single Python module, which is nice because (1) being able to organize is good, and (2) all the filters in a single Python extension module share the same Halide runtime, including (e.g.) thread pools and method overrides. (It also removes the just-recently-added PYTHON_EXTENSION_LIBRARY option from the add_halide_library rule, as this new rule is better and more flexible in pretty much every way.) This modifies the content of our `python_extension` output in such a way that existing uses should be completely unaffected, but defining the right preprocessor macros allows us to split the function wrappers up from the method-definition declaration, so we don't have to generate any new code artifiacts to make this work. Partially addresses halide#6956. * Omits -D in target_compile_definitions * be explicit about setting to empty * Add quotes * Add comments re BUILD_INTERFACE * Add MODULE_NAME comment * Remove "defined in HalideGeneratorHelpers.cmake" * Add comment re add_halide_runtime() * osx, macos, darwin, oh m * blankity blank blank * Use OBJECT library instead * Add comment about X-macros * Update HalideGeneratorHelpers.cmake
- Loading branch information
1 parent
bedd63a
commit 5b31623
Showing
7 changed files
with
274 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
python_bindings/test/correctness/multi_method_module_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import numpy as np | ||
|
||
import multi_method_module | ||
|
||
def test_simple(): | ||
buffer_input = np.ndarray([2, 2], dtype=np.uint8) | ||
buffer_input[0, 0] = 123 | ||
buffer_input[0, 1] = 123 | ||
buffer_input[1, 0] = 123 | ||
buffer_input[1, 1] = 123 | ||
|
||
func_input = np.ndarray([2, 2], dtype=np.uint8) | ||
func_input[0, 0] = 0 | ||
func_input[0, 1] = 1 | ||
func_input[1, 0] = 1 | ||
func_input[1, 1] = 2 | ||
|
||
float_arg = 3.5 | ||
|
||
simple_output = np.ndarray([2, 2], dtype=np.float32) | ||
|
||
multi_method_module.simple(buffer_input, func_input, float_arg, simple_output) | ||
|
||
assert simple_output[0, 0] == 3.5 + 123 | ||
assert simple_output[0, 1] == 4.5 + 123 | ||
assert simple_output[1, 0] == 4.5 + 123 | ||
assert simple_output[1, 1] == 5.5 + 123 | ||
|
||
def test_user_context(): | ||
output = bytearray("\0\0\0\0", "ascii") | ||
multi_method_module.user_context(None, ord('q'), output) | ||
assert output == bytearray("qqqq", "ascii") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_simple() | ||
test_user_context() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.