Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
67ccff7
kernel library guide
cyx-6 Oct 18, 2025
57d6c03
fix lint
cyx-6 Oct 18, 2025
58ce14c
add licence
cyx-6 Oct 18, 2025
f18fec2
add index
cyx-6 Oct 18, 2025
c2a5a17
upd
cyx-6 Oct 20, 2025
aa3c715
fix
cyx-6 Oct 20, 2025
f8b8b92
fix
cyx-6 Oct 20, 2025
507d17e
upd
cyx-6 Oct 20, 2025
d87c16a
add orcjit
yaoyaoding Nov 9, 2025
501b635
add more tests
yaoyaoding Nov 10, 2025
6ce56a1
fix tests
yaoyaoding Nov 10, 2025
d27a5b0
wip
yaoyaoding Nov 10, 2025
cf2da5d
fix
yaoyaoding Nov 10, 2025
76d13d5
fix cmakelists.txt
yaoyaoding Nov 10, 2025
b57756d
fix
yaoyaoding Nov 10, 2025
331404b
fix tests on macos
yaoyaoding Nov 10, 2025
c15f037
Update addons/tvm-ffi-orcjit/pyproject.toml
yaoyaoding Nov 10, 2025
1bc971c
Update addons/tvm-ffi-orcjit/examples/quick-start/compile.sh
yaoyaoding Nov 10, 2025
c9dc320
Update addons/tvm-ffi-orcjit/README.md
yaoyaoding Nov 10, 2025
b855a9e
wip
yaoyaoding Nov 11, 2025
0dfc2d1
use the right way to define object
yaoyaoding Nov 11, 2025
5af6c77
move include to src
yaoyaoding Nov 11, 2025
b9eb2aa
update cmakelists.txt
yaoyaoding Nov 11, 2025
d161749
Merge commit '7f3f8726156ab6e33f781562afafd9c6f219551f' into guide
cyx-6 Nov 14, 2025
b78c6db
refactor
cyx-6 Nov 15, 2025
df71054
test with empty commit
yaoyaoding Nov 17, 2025
00e6bdb
add more links; some modifications
yaoyaoding Nov 17, 2025
3e968b2
fix
cyx-6 Nov 18, 2025
3e36d6d
upd
cyx-6 Nov 18, 2025
2d6c522
upd
cyx-6 Nov 18, 2025
b6eae62
fix
cyx-6 Nov 18, 2025
5f24604
upd
cyx-6 Nov 18, 2025
264dfad
upd
cyx-6 Nov 18, 2025
f961dd3
Merge commit '264dfad84c1ce172ac8e6f430f6ddeb013eb1224' into orcjit
cyx-6 Nov 19, 2025
3d98e3b
wip
cyx-6 Nov 19, 2025
876213f
fix
cyx-6 Nov 19, 2025
90933d7
wip
cyx-6 Nov 20, 2025
6d7061b
upd
cyx-6 Nov 20, 2025
4a5793e
Merge commit 'db53ce4f4f8f2afc9cfd8070b5c7b092dcd04176' into orcjit
cyx-6 Nov 20, 2025
c831c7a
upd
cyx-6 Nov 20, 2025
9868ad4
upd
cyx-6 Nov 24, 2025
3f04278
fix
cyx-6 Nov 24, 2025
6ae4991
upd
cyx-6 Nov 24, 2025
9496a0c
fix
cyx-6 Nov 24, 2025
289b2ec
Merge commit 'dcacb98d189241d52ef51c1d63fb0e9f6c98a4b0' into orcjit
cyx-6 Dec 4, 2025
2f504dd
wip
cyx-6 Dec 4, 2025
3066c29
fix
cyx-6 Dec 4, 2025
cbcd811
fix
cyx-6 Dec 4, 2025
5464735
fix
cyx-6 Dec 4, 2025
5aa9c61
fix
cyx-6 Dec 4, 2025
316ea61
wip
cyx-6 Dec 23, 2025
fa51933
Merge branch 'apache:main' into orcjit
cyx-6 Jan 20, 2026
70f09eb
wip
cyx-6 Jan 21, 2026
b023f3b
test
cyx-6 Jan 22, 2026
0e9a878
wiip
cyx-6 Jan 22, 2026
eab6cad
wip
cyx-6 Jan 23, 2026
6053e18
wip
cyx-6 Jan 24, 2026
6335983
fix
cyx-6 Jan 24, 2026
8cee2ed
segfault
cyx-6 Jan 24, 2026
95675d1
fixed
cyx-6 Jan 24, 2026
9de9d61
auto find orcrt_lib
cyx-6 Jan 26, 2026
c854e1f
segfault
cyx-6 Jan 26, 2026
acac060
fix
cyx-6 Jan 26, 2026
7875512
dev
cyx-6 Mar 9, 2026
0b8eb52
test
cyx-6 Mar 9, 2026
20f949b
test llvm20
cyx-6 Mar 9, 2026
5e90963
debug
cyx-6 Mar 9, 2026
8650a68
debug
cyx-6 Mar 9, 2026
02373b0
Static LLVM linking and bundled liborc_rt for tvm-ffi-orcjit
cyx-6 Mar 10, 2026
91fae9c
fix: use {project} placeholder for cibuildwheel before-all script path
cyx-6 Mar 10, 2026
09648d8
fix: use CIBW_BEFORE_ALL_LINUX env var with correct project path
cyx-6 Mar 10, 2026
b535230
fix: install libxml2, zlib, zstd in conda env for LLVM system-libs
cyx-6 Mar 10, 2026
16c4f0f
fix: add LDFLAGS=-L/opt/llvm/lib so linker finds conda system libs
cyx-6 Mar 10, 2026
007e334
fix: drop --system-libs from LLVM static linking
cyx-6 Mar 10, 2026
9012aa0
fix: drop system-libs and target manylinux_2_35 for conda LLVM compat
cyx-6 Mar 10, 2026
99c6b6a
fix: use full Docker image path for manylinux_2_35
cyx-6 Mar 10, 2026
a37a389
fix: use conda clang as compiler to avoid too-recent glibc symbols
cyx-6 Mar 10, 2026
d1f62e7
debug: add auditwheel show and try manylinux_2_34 platform tag
cyx-6 Mar 10, 2026
8ae8524
debug: dump too-recent glibc symbols and try manylinux_2_35
cyx-6 Mar 10, 2026
bd6b71a
clean: remove debug objdump from repair command
cyx-6 Mar 10, 2026
eb207d6
remove unnecessary CC/CXX conda clang override
cyx-6 Mar 10, 2026
1ab02b3
comment
cyx-6 Mar 10, 2026
b455586
static-link zlib, zstd, and libstdc++ for manylinux_2_28 support
cyx-6 Mar 10, 2026
dd73005
fix: install zlib-static and libzstd-devel via yum
cyx-6 Mar 10, 2026
87b69a9
use manylinux_2_34 build image with system zlib-static/libzstd-devel
cyx-6 Mar 10, 2026
f9c15ab
fix: use libzstd-static package name on AlmaLinux 9
cyx-6 Mar 10, 2026
ec8a7aa
fix: enable CRB repo for libzstd-static on AlmaLinux 9
cyx-6 Mar 10, 2026
2340120
fix: revert to manylinux_2_28, build zstd from source
cyx-6 Mar 10, 2026
572ca74
fix: use conda zlib (PIC), build zstd with -fPIC
cyx-6 Mar 10, 2026
35d2fba
fix: handle __cxa_atexit per JITDylib, add object lifetime warning, a…
cyx-6 Mar 10, 2026
d204ca8
fix: pass Python_EXECUTABLE to cmake in CI test phase
cyx-6 Mar 10, 2026
988fc5e
fix: install apache-tvm-ffi in CIBW_BEFORE_TEST_LINUX via uv
cyx-6 Mar 10, 2026
e2ae9da
chore: remove redundant orcjit CI workflows
cyx-6 Mar 10, 2026
2ab7a18
fix: use LLJIT::deinitialize() and defaultLinkOrder() for __cxa_atexi…
cyx-6 Mar 11, 2026
b5da945
fix: unify InitFiniPlugin to PostFixupPasses, fix .fini_array livenes…
cyx-6 Mar 11, 2026
8a45eb4
chore: remove ref-counted object warning, fix example aarch64 build
cyx-6 Mar 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/orcjit-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

name: OrcJIT Build

on:
push:
paths:
- "addons/tvm-ffi-orcjit/**"
- ".github/workflows/orcjit-build.yml"
workflow_dispatch:

jobs:
build_wheels:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- {arch: x86_64, build: "cp312-manylinux_x86_64"}

steps:
- uses: actions/checkout@v5
with:
submodules: recursive

- name: Build and test wheels
uses: pypa/cibuildwheel@v3.1.4
with:
package-dir: addons/tvm-ffi-orcjit
output-dir: wheelhouse
env:
CIBW_BUILD: ${{ matrix.build }}
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
CIBW_BUILD_VERBOSITY: 1
CIBW_BEFORE_ALL_LINUX: bash {project}/addons/tvm-ffi-orcjit/tools/install_llvm.sh
CIBW_TEST_REQUIRES: pytest
CIBW_BEFORE_TEST_LINUX: >-
uv pip install apache-tvm-ffi &&
cd {project}/addons/tvm-ffi-orcjit/tests &&
cmake -B build -DCMAKE_CXX_COMPILER=/opt/llvm/bin/clang++ -DPython_EXECUTABLE=$(which python) &&
cmake --build build &&
cmake --install build &&
cd {project}/addons/tvm-ffi-orcjit/examples/quick-start &&
cmake -B build -DCMAKE_CXX_COMPILER=/opt/llvm/bin/clang++ -DPython_EXECUTABLE=$(which python) &&
cmake --build build
CIBW_TEST_COMMAND: >-
pytest {project}/addons/tvm-ffi-orcjit/tests -v &&
cd {project}/addons/tvm-ffi-orcjit/examples/quick-start &&
python run.py

- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.arch }}
path: wheelhouse/*.whl
164 changes: 164 additions & 0 deletions addons/tvm-ffi-orcjit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
cmake_minimum_required(VERSION 3.20)
project(
tvm_ffi_orcjit
VERSION 0.1.0
LANGUAGES C CXX
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Find dependencies
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

# Find tvm-ffi package using the same method as quickstart example
find_package(
Python
COMPONENTS Interpreter
REQUIRED
)

# Get the cmake directory for tvm-ffi
execute_process(
COMMAND "${Python_EXECUTABLE}" -m tvm_ffi.config --cmakedir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE tvm_ffi_ROOT
)
message(STATUS "tvm_ffi_ROOT: ${tvm_ffi_ROOT}")

find_package(tvm_ffi CONFIG REQUIRED)

# Source files
set(SOURCES src/ffi/orcjit_session.cc src/ffi/orcjit_dylib.cc)

# Build shared library
add_library(tvm_ffi_orcjit SHARED ${SOURCES})

target_include_directories(
tvm_ffi_orcjit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ${LLVM_INCLUDE_DIRS}
)

# Compile definitions
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
target_compile_definitions(tvm_ffi_orcjit PRIVATE ${LLVM_DEFINITIONS_LIST})

# ---- Static LLVM Linking via llvm-config ----
# Allow overriding via env: LLVM_CONFIG_PATH
if(DEFINED ENV{LLVM_CONFIG_PATH})
set(LLVM_CONFIG_EXE "$ENV{LLVM_CONFIG_PATH}")
else()
find_program(
LLVM_CONFIG_EXE
NAMES llvm-config-${LLVM_VERSION_MAJOR} llvm-config
HINTS ${LLVM_TOOLS_BINARY_DIR} "${LLVM_DIR}/../../../bin"
)
endif()
if(NOT LLVM_CONFIG_EXE)
message(FATAL_ERROR "llvm-config not found, required for static LLVM linking")
endif()
message(STATUS "Using llvm-config: ${LLVM_CONFIG_EXE}")

execute_process(
COMMAND ${LLVM_CONFIG_EXE} --link-static --libs Core OrcJIT Support native
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _llvm_static_libs
)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --link-static --ldflags
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _llvm_static_ldflags
)
message(STATUS "LLVM static libs: ${_llvm_static_libs}")
message(STATUS "LLVM static ldflags: ${_llvm_static_ldflags}")

separate_arguments(_llvm_static_libs_list NATIVE_COMMAND "${_llvm_static_libs}")
separate_arguments(_llvm_static_ldflags_list NATIVE_COMMAND "${_llvm_static_ldflags}")

# Find static zlib and zstd to avoid runtime dependencies on target systems.
# This enables manylinux_2_28 compatibility.
cmake_path(GET LLVM_DIR PARENT_PATH _llvm_prefix)
cmake_path(GET _llvm_prefix PARENT_PATH _llvm_prefix)
cmake_path(GET _llvm_prefix PARENT_PATH _llvm_prefix)
find_library(ZLIB_STATIC NAMES libz.a HINTS "${_llvm_prefix}/lib" REQUIRED)
find_library(ZSTD_STATIC NAMES libzstd.a HINTS "${_llvm_prefix}/lib" "${_llvm_prefix}/lib64" REQUIRED)
message(STATUS "Static zlib: ${ZLIB_STATIC}")
message(STATUS "Static zstd: ${ZSTD_STATIC}")

target_link_libraries(
tvm_ffi_orcjit
PRIVATE tvm_ffi::header tvm_ffi::shared ${_llvm_static_ldflags_list}
${_llvm_static_libs_list} ${ZLIB_STATIC} ${ZSTD_STATIC}
)

# Statically link libstdc++ and libgcc to avoid GLIBCXX version requirements
# on the target system, enabling manylinux_2_28 support.
target_link_options(tvm_ffi_orcjit PRIVATE -static-libstdc++ -static-libgcc)

# ---- Find and bundle liborc_rt ----
# Allow overriding via env: CLANG_PATH
if(DEFINED ENV{CLANG_PATH})
set(CLANG_EXE "$ENV{CLANG_PATH}")
else()
find_program(
CLANG_EXE
NAMES clang-${LLVM_VERSION_MAJOR} clang
HINTS ${LLVM_TOOLS_BINARY_DIR} "${LLVM_DIR}/../../../bin"
)
endif()

if(NOT CLANG_EXE)
message(FATAL_ERROR "clang not found. Required to locate liborc_rt library.")
endif()

execute_process(
COMMAND ${CLANG_EXE} -print-runtime-dir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE _clang_runtime_dir
ERROR_QUIET
RESULT_VARIABLE _clang_runtime_dir_rc
)

cmake_host_system_information(RESULT _host_arch QUERY OS_PLATFORM)
set(ORC_RT_PATH "")

if(_clang_runtime_dir_rc EQUAL 0 AND _clang_runtime_dir)
# Try arch-specific name in the exact directory first
if(EXISTS "${_clang_runtime_dir}/liborc_rt-${_host_arch}.a")
set(ORC_RT_PATH "${_clang_runtime_dir}/liborc_rt-${_host_arch}.a")
elseif(EXISTS "${_clang_runtime_dir}/liborc_rt.a")
set(ORC_RT_PATH "${_clang_runtime_dir}/liborc_rt.a")
else()
# The reported runtime dir may not exist (e.g. clang reports
# aarch64-unknown-linux-gnu/ but files live in linux/). Resolve
# the parent and search recursively from there.
cmake_path(GET _clang_runtime_dir PARENT_PATH _clang_runtime_parent)
if(EXISTS "${_clang_runtime_parent}")
file(GLOB_RECURSE _orc_rt_candidates "${_clang_runtime_parent}/liborc_rt*.a")
if(_orc_rt_candidates)
list(GET _orc_rt_candidates 0 ORC_RT_PATH)
endif()
endif()
endif()
endif()

if(NOT ORC_RT_PATH)
message(FATAL_ERROR "Could not find liborc_rt. "
"Ensure clang runtime libraries are installed (e.g. libclang-rt-dev).")
endif()

message(STATUS "Found liborc_rt: ${ORC_RT_PATH}")
# Copy into build dir for editable installs (where _lib_dir resolves to CMAKE_BINARY_DIR)
file(COPY "${ORC_RT_PATH}" DESTINATION "${CMAKE_BINARY_DIR}")
install(FILES "${ORC_RT_PATH}" DESTINATION lib)

# Installation rules
install(
TARGETS tvm_ffi_orcjit
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
Loading
Loading