Skip to content

Conversation

xFile3160
Copy link

The following patches include changes onto Halide for exporting the halide vulkan memory allocator such that an existing app could just override vkInstance, vkQueue, vkDevice, vkPhysicalDevice without worrying about custom memory allocator (see #8715).
I wrote also a demo application to prove the idea and flow.

alexreinking and others added 8 commits December 16, 2024 21:17
…ory allocator with custom Vulkan context

Summary:
In a situation where you'd want to set your own context (aka: you are integrating Halide in a system or app owning
already Vulkan resources), the existing APIs expose the halide memory allocator as opaque handle, which does not
allow an easy plug & play with a different allocator (like VMA). The changes proposed in this patch, would allow
to set your own vkDevice, vkInstance, vkQueue, vkPhysicalDevice directly into Halide and use its own memory allocator,
allowing integration in existing apps/systems.
The behavior changed is:
1. use halide_vulkan_acquire_context with *allocator set to nullptr. (need to override the function).
2. use halide_vulkan_export_memory_allocator to retrieve the instance of the allocator and save it in your app.
3. use halide_vulkan_memory_allocator_release to properly release shader and allocator resources. (need to override).

Test Plan:
Simple app for testing provided in the apps folder: apps/vulkan_wrap_native_to_halide
Summary:
To test out the flow of the functions and verify correctness.

Test Plan:
Build Halide with patch shaid: 1a6a9a7
Instructions to build:
 cmake -G Ninja -S . -B build \
  -DCMAKE_BUILD_TYPE=Debug \
  -DCMAKE_OSX_ARCHITECTURES=arm64 \
  -DCMAKE_OSX_SYSROOT="$(xcrun --sdk macosx --show-sdk-path)" \
  -DLLVM_DIR="$(brew --prefix llvm@19)/lib/cmake/llvm" \
  -DHalide_WASM_BACKEND=wabt \
  -DWITH_PYTHON_BINDINGS=OFF \
  -DWITH_TUTORIALS=OFF \
  -DBUILD_SHARED_LIBS=OFF \
  -DHalide_BUNDLE_STATIC=ON
Then build:
 cmake --build build -j32
Then install:
 cmake --install build --prefix "$PWD/install"

Then build the test app but first modify hardcoded paths in CMakeLists.txt
cd apps/external_vk_demo
mkdir build
cd build
cmake ../
make
./demo_main
@alexreinking
Copy link
Member

Why are a bunch of my commits in this branch?

@xFile3160
Copy link
Author

I don't knew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants