Repository navigation
[dev] add tvm-ffi as a new workspace module #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| VILA (Vision Infrastructure Library Assembler) is a C++ infrastructure library for computer vision applications. It provides JSON-based configuration, logging with WPP support, reflection registry, error handling (Status/StatusOr), profiling tools, and a template DAG library. | ||
|
|
||
| ## Build Systems | ||
|
|
||
| ### Bazel (Primary) | ||
|
|
||
| ```bash | ||
| # Build all tests | ||
| bazelisk test //tests/clim/... //tests/vila/... | ||
|
|
||
| # Build a specific test | ||
| bazelisk test //tests/clim:argparse_test | ||
|
|
||
| # Build with specific config (e.g., SYCL) | ||
| bazelisk build --config=sycl //... | ||
|
|
||
| # Run using legacy WORKSPACE (on Windows) | ||
| bazelisk --output_base="C:/temp/_vila_workspace" build --noenable_bzlmod //... | ||
| ``` | ||
|
|
||
| **Legacy WORKSPACE setup (Windows)** requires loading three workspace files in sequence: | ||
| ```bazel | ||
| load("@vila//vila:workspace0.bzl", vila_workspace0 = "workspace") | ||
| vila_workspace0() | ||
| load("@vila//vila:workspace1.bzl", vila_workspace1 = "workspace") | ||
| vila_workspace1() | ||
| load("@vila//vila:workspace2.bzl", vila_workspace2 = "workspace") | ||
| ``` | ||
|
|
||
| ### CMake | ||
|
|
||
| ```bash | ||
| mkdir build && cmake -Bbuild -S. -GNinja | ||
| cmake --build build --config Release | ||
|
|
||
| # With testing enabled | ||
| cmake -Bbuild -S. -GNinja -DVILA_ENABLE_TESTING=ON | ||
| ``` | ||
|
|
||
| ## Code Style | ||
|
|
||
| - **Style**: Based on Google C++ Style (see `.clang-format`) | ||
| - **Clang-tidy**: Configured in `.clang-tidy`, targets `clim/` and `vila/` headers only (excludes generated files) | ||
| - **Pre-commit hooks**: Run via `pre-commit run -s HEAD^ -o HEAD` (see `.pre-commit-config.yaml`) | ||
| - **Spell checking**: Codespell configured with words bag at `.github/WORDS_BAG.txt` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| clim/ # Header-only utility library (math, strings, containers, etc.) | ||
| ├── argparse/ # Command-line argument parsing | ||
| ├── container/ # Bounding boxes, ring buffers, etc. | ||
| ├── filter/ # Kalman and alpha-beta filters | ||
| ├── hash/ # CityHash, MurmurHash | ||
| ├── math/ # Quaternion, numerical utilities | ||
| ├── os/ # OS utilities (aligned malloc, barriers) | ||
| ├── path/ # Cross-platform path handling | ||
| ├── reflection/ # Reflection registry | ||
| ├── string/ # String splitting, stripping, const_string | ||
| ├── vt/ # Vector math (GEMM, neural network ops) | ||
| └── zip/ # Zip utility functions | ||
|
|
||
| vila/ # Core library components | ||
| ├── config/ # JSON-based configuration system | ||
| ├── graph/ # Template header-only DAG (dag.h, graph.h, route.h, traversal.h) | ||
| ├── hook/ # Windows DLL hooking (detours) | ||
| ├── logging/ # Logger with WPP support (code_location, logger) | ||
| ├── profiling/ # ITT, timer, trace utilities | ||
| ├── status/ # Status and StatusOr error handling | ||
| ├── widget/ # (UI components) | ||
| └── bazel/ # Bazel-specific build rules and toolchains | ||
|
|
||
| python/ # Python bindings via nanobind/pybind11 | ||
| tests/ # GoogleTest-based C++ tests | ||
| ``` | ||
|
|
||
| ## Key Dependencies (via Bazel) | ||
|
|
||
| - `fmt` (12.1.0) - Formatting library | ||
| - `spdlog` - Logging library | ||
| - `googletest` - Testing framework | ||
| - `google_benchmark` - Benchmarking | ||
| - `rules_foreign_cc` - CMake/ ninja build support | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| # C++ tests (Bazel) | ||
| bazelisk test //tests/clim/... //tests/vila/... | ||
|
|
||
| # Python tests | ||
| pip install -e python[test] | ||
| pytest --cov=python/vila python/tests | ||
| ``` | ||
|
|
||
| ## Windows-Specific Notes | ||
|
|
||
| - Default C++ standard: C++17 | ||
| - Windows WPP logging disabled by default (see commit ed44f79) | ||
| - Windows-specific configs use `select()` with `//conditions:default` since some build configs are Windows-only | ||
| - The `range_test` is Windows-only and requires C++20 | ||
|
|
||
| ## Editor Setup | ||
|
|
||
| The project includes `.vscode/` settings for convenience with bazelized projects. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,3 +26,6 @@ dist/ | |
| /external | ||
| /bazel-* | ||
| htmlcov/ | ||
|
|
||
| # AI | ||
| .claude/settings.local.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| apache-tvm-ffi==0.1.9 | ||
| numpy==2.2.6 | ||
| typing-extensions==4.15.0 |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||||
| /** | ||||||||
| * Copyright (C) 2026 The VILA Authors. | ||||||||
| * | ||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||
| * you may not use this file except in compliance with the License. | ||||||||
| * You may obtain a copy of the License at | ||||||||
| * | ||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||
| * | ||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||
| * See the License for the specific language governing permissions and | ||||||||
| * limitations under the License. | ||||||||
| */ | ||||||||
|
|
||||||||
| // This file demonstrates how to use TVM FFI to export C++ functions | ||||||||
| // that can be called from Python via tvm_ffi.load_module(). | ||||||||
| // | ||||||||
| // TVM FFI provides a simple mechanism to create shared libraries (.dll on Windows, | ||||||||
| // .so on Linux) that can be loaded dynamically from Python. Functions exported | ||||||||
| // using TVM_FFI_DLL_EXPORT_TYPED_FUNC are automatically discoverable. | ||||||||
| // | ||||||||
| // Key concepts: | ||||||||
| // 1. TVM_FFI_DLL_EXPORT_TYPED_FUNC(ExportName, FunctionPtr) | ||||||||
| // - ExportName: the name exposed to Python (e.g., "add_one_tensor") | ||||||||
| // - FunctionPtr: a C++ function pointer with matching signature | ||||||||
| // 2. The C++ function takes a tvm::ffi::Tensor and returns a tvm::ffi::Tensor | ||||||||
| // 3. TVM FFI automatically converts numpy arrays to Tensor via DLPack | ||||||||
| // | ||||||||
| // Example usage in Python: | ||||||||
| // import tvm_ffi | ||||||||
| // import numpy as np | ||||||||
| // mod = tvm_ffi.load_module("path/to/tvm_ffi_call.dll") | ||||||||
| // func = mod.add_one_tensor | ||||||||
| // x = np.array([1.0, 2.0, 3.0], dtype=np.float32) | ||||||||
| // result = func(x) # Returns array([2.0, 3.0, 4.0], dtype=np.float32) | ||||||||
|
|
||||||||
| #include <tvm/ffi/tvm_ffi.h> | ||||||||
|
|
||||||||
| #include <cstring> | ||||||||
| #include <cstdint> | ||||||||
|
||||||||
| #include <cstdint> | |
| #include <cstdint> | |
| #include <cstdlib> |
Check warning on line 87 in tests/vila/tvm_ffi_call.cpp
SonarQubeCloud / SonarCloud Code Analysis
Replace the redundant type with "auto".
See more on https://sonarcloud.io/project/issues?id=llteco_vila&issues=AZ1T7Dbid1Sm4qOx1umN&open=AZ1T7Dbid1Sm4qOx1umN&pullRequest=12
Check warning on line 88 in tests/vila/tvm_ffi_call.cpp
SonarQubeCloud / SonarCloud Code Analysis
Replace the redundant type with "auto".
See more on https://sonarcloud.io/project/issues?id=llteco_vila&issues=AZ1T7Dbid1Sm4qOx1umO&open=AZ1T7Dbid1Sm4qOx1umO&pullRequest=12
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WORKSPACE previously enabled SYCL via
sycl = True, but this change forcessycl = Falsewhile addingtvm_ffi = True. This looks unrelated to the PR’s stated goal (adding tvm-ffi) and will change developer builds unexpectedly. Consider preserving the priorsycl = Truesetting (or omit the argument to keep the existing behavior) and only addtvm_ffi = True.