{"id":2387,"library":"apache-tvm-ffi","title":"Apache TVM FFI","description":"apache-tvm-ffi provides the foundational Foreign Function Interface (FFI) layer for the Apache TVM deep learning compiler stack, enabling Python to bind to and interact with C++ types and functions. It is currently at version 0.1.10 and receives frequent, minor updates.","status":"active","version":"0.1.10","language":"en","source_language":"en","source_url":"https://github.com/apache/tvm-ffi","tags":["FFI","TVM","Apache","deep learning","compiler"],"install":[{"cmd":"pip install apache-tvm-ffi","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"tvm_ffi","correct":"import tvm_ffi"},{"note":"The `device` function is a direct export from the top-level `tvm_ffi` module, not a submodule.","wrong":"import tvm_ffi.device","symbol":"device","correct":"from tvm_ffi import device"},{"symbol":"Object","correct":"from tvm_ffi.runtime_base import Object"},{"symbol":"Function","correct":"from tvm_ffi.runtime_base import Function"}],"quickstart":{"code":"import tvm_ffi\n\n# tvm_ffi provides low-level FFI bindings, often used with TVM itself.\n# A simple interaction is with device context management.\n\n# Create a CPU device context\ncpu_ctx = tvm_ffi.device(\"cpu\", 0)\nprint(f\"CPU context: {cpu_ctx}\")\nassert str(cpu_ctx) == \"cpu(0)\"\n\n# Attempt to create a GPU device context (may fail if no GPU is present)\ntry:\n    gpu_ctx = tvm_ffi.device(\"cuda\", 0)\n    print(f\"CUDA context: {gpu_ctx}\")\n    assert str(gpu_ctx) == \"cuda(0)\"\nexcept tvm_ffi.TVMError as e:\n    print(f\"Could not create CUDA context: {e}\")\n\n# The tvm_ffi.Object is a base class for runtime objects\nfrom tvm_ffi.runtime_base import Object\n\nclass MyTVMObject(Object):\n    # Custom runtime objects inherit from tvm_ffi.runtime_base.Object\n    # This is often extended in C++ and exposed via FFI.\n    pass\n\n# Note: Direct instantiation of Object in Python is usually for type hinting\n# or for objects returned from FFI calls.\n# obj = MyTVMObject() # This would typically require C++ backend setup\n","lang":"python","description":"Demonstrates basic device context creation using `tvm_ffi.device` and shows the `tvm_ffi.runtime_base.Object` base class for extending FFI objects."},"warnings":[{"fix":"Re-evaluate your dataclass integration with `tvm-ffi`. You may need to remove or refactor custom Python-side field descriptor logic, as the underlying infrastructure is no longer available.","message":"The Python-side field descriptor infrastructure for dataclasses was removed. If you were using `tvm-ffi` to define dataclasses with specific FFI-related field descriptors, this API has been removed.","severity":"breaking","affected_versions":">=0.1.10"},{"fix":"Remove any direct calls to `tvm_ffi.Function.__init__` or rework code that assumed its presence. `tvm_ffi.Function` objects are typically obtained from FFI calls or registered C++ functions rather than being instantiated directly in Python.","message":"The `tvm_ffi.Function.__init__` constructor, which was briefly introduced, was reverted. If you implemented code relying on a custom `__init__` for `tvm_ffi.Function` objects, it will break.","severity":"breaking","affected_versions":">=0.1.9"},{"fix":"Ensure you have a clear understanding of its role within the TVM ecosystem. For general TVM usage, you might interact with higher-level `tvm` library constructs, which internally use `apache-tvm-ffi`.","message":"The `apache-tvm-ffi` library is a low-level FFI binding for TVM's C++ runtime. It is not typically used as a standalone application library but rather as a foundational component for deeper integration with TVM or custom C++ extensions. Its API surface can be complex and requires understanding of TVM's C++ backend.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}