From 63609cca550a61a48f331ffe9a8753ac341da92a Mon Sep 17 00:00:00 2001 From: Alex Reinking Date: Fri, 6 Sep 2024 11:19:27 -0700 Subject: [PATCH] Document how to find Halide from a pip installation (#8411) --- README.md | 9 +++++++++ doc/HalideCMakePackage.md | 12 ++++++++---- python_bindings/src/halide/__init__.py | 8 ++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9a51a7f26d12..91b1f9493def 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,15 @@ Currently, we provide wheels for: Windows x86-64, macOS x86-64, macOS arm64, and Linux x86-64. The Linux wheels are built for manylinux_2_28, which makes them broadly compatible (Debian 10, Ubuntu 18.10, Fedora 29). +*For C++ usage of the pip package:* On Linux and macOS, CMake's `find_package` +command should find Halide as long as you're in the same virtual environment you +installed it in. On Windows, you will need to add the virtual environment root +directory to `CMAKE_PREFIX_PATH`. This can be done by running +`set CMAKE_PREFIX_PATH=%VIRTUAL_ENV%` in `cmd`. + +Other build systems can find the Halide root path by running `python -c +"import halide; print(halide.install_dir())"`. + ## Homebrew Alternatively, if you use macOS, you can install Halide via diff --git a/doc/HalideCMakePackage.md b/doc/HalideCMakePackage.md index c1814f7f954c..4edf35e2404f 100644 --- a/doc/HalideCMakePackage.md +++ b/doc/HalideCMakePackage.md @@ -71,14 +71,18 @@ vendor-specific extensions to C++. This is not necessary to simply use Halide, but we do not allow such extensions in the Halide repo. Finally, we use [`find_package`][find_package] to locate Halide on your system. -If Halide is not globally installed, you will need to add the root of the Halide -installation directory to [`CMAKE_PREFIX_PATH`][cmake_prefix_path] at the CMake -command line. +When using the pip package on Linux and macOS, CMake's `find_package` +command should find Halide as long as you're in the same virtual environment you +installed it in. On Windows, you will need to add the virtual environment root +directory to [`CMAKE_PREFIX_PATH`][cmake_prefix_path]: ```shell -$ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/path/to/Halide-install" +$ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=%VIRTUAL_ENV% ``` +If `find_package` cannot find Halide, set `CMAKE_PREFIX_PATH` to the Halide +installation directory. + ## JIT mode To use Halide in JIT mode (like the [tutorials][halide-tutorials] do, for diff --git a/python_bindings/src/halide/__init__.py b/python_bindings/src/halide/__init__.py index d146b6ffb528..d75844d4460e 100644 --- a/python_bindings/src/halide/__init__.py +++ b/python_bindings/src/halide/__init__.py @@ -11,7 +11,15 @@ def patch_dll_dirs(): del patch_dll_dirs from .halide_ import * +# noinspection PyUnresolvedReferences from .halide_ import _, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9 + + +def install_dir(): + import os + return os.path.dirname(__file__) + + from ._generator_helpers import ( _create_python_generator, _generatorcontext_enter,