Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 39 additions & 5 deletions .github/workflows/release-prefab-aar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install Linux build dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang cmake ninja-build
sudo apt-get install -y clang cmake ninja-build zip

- name: Set up JDK 17
uses: actions/setup-java@v4
Expand Down Expand Up @@ -63,26 +63,60 @@ jobs:
export FREESCHED_VERSION
gradle -p android-aar assembleRelease --no-daemon

- name: Publish AAR to Maven Central (when secrets configured)
- name: Stage & publish AAR bundle to Maven Central Portal (when secrets configured)
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_VERSION: ${{ inputs.version }}
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_ID: ${{ vars.GPG_KEY_ID }}
run: |
set -euo pipefail
if [ "${EVENT_NAME}" = "workflow_dispatch" ]; then
FREESCHED_VERSION="${INPUT_VERSION:-0.2.0}"
else
FREESCHED_VERSION="${GITHUB_REF_NAME#v}"
fi
export FREESCHED_VERSION

rm -rf android-aar/build/staging-repo android-aar/build/freesched-android-*.zip
gradle -p android-aar publishReleasePublicationToLocalStagingRepository --no-daemon

STAGE_REL="io/github/freesilicon/freesched-android/${FREESCHED_VERSION}"
STAGE_DIR="android-aar/build/staging-repo/${STAGE_REL}"
for ext in aar pom; do
ls "${STAGE_DIR}/freesched-android-${FREESCHED_VERSION}.${ext}" >/dev/null
done
ls "${STAGE_DIR}/freesched-android-${FREESCHED_VERSION}-sources.jar" >/dev/null
ls "${STAGE_DIR}/freesched-android-${FREESCHED_VERSION}-javadoc.jar" >/dev/null

find android-aar/build/staging-repo -name 'maven-metadata.xml*' -delete
for f in "${STAGE_DIR}"/*; do
[ -f "$f" ] || continue
case "$f" in
*.asc|*.md5|*.sha1|*.sha256|*.sha512) continue ;;
esac
[ -f "${f}.md5" ] || md5sum "$f" | awk '{print $1}' > "${f}.md5"
[ -f "${f}.sha1" ] || sha1sum "$f" | awk '{print $1}' > "${f}.sha1"
if [ -n "${GPG_PRIVATE_KEY:-}" ] && [ ! -f "${f}.asc" ]; then
echo "Missing signature for ${f}" >&2
exit 1
fi
done

BUNDLE_ZIP="android-aar/build/freesched-android-${FREESCHED_VERSION}-bundle.zip"
(cd android-aar/build/staging-repo && zip -r "../freesched-android-${FREESCHED_VERSION}-bundle.zip" "${STAGE_REL}")

if [ -n "${MAVEN_CENTRAL_USERNAME:-}" ] && [ -n "${MAVEN_CENTRAL_PASSWORD:-}" ]; then
gradle -p android-aar publishReleasePublicationToMavenCentralRepository --no-daemon
CENTRAL_AUTH="$(printf '%s:%s' "${MAVEN_CENTRAL_USERNAME}" "${MAVEN_CENTRAL_PASSWORD}" | base64 | tr -d '\n')"
curl --fail-with-body -sS -X POST \
"https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC&name=freesched-android-${FREESCHED_VERSION}" \
-H "Authorization: Bearer ${CENTRAL_AUTH}" \
-F "bundle=@${BUNDLE_ZIP}"
echo ""
else
echo "Maven Central secrets not configured; skipping publish."
echo "Maven Central secrets not configured; skipping Central Portal upload."
fi

- name: Collect release artifacts
Expand Down
70 changes: 40 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ option(FREESCHED_BUILD_TOOLS "Build freesched CLI tools" ON)
option(FS_GOV_EXPERIMENTAL "Enable experimental ADPF/ARR/LMKD/SVE2 governor modules" OFF)
option(FS_MTE_OPT_IN_UNSAFE_THREAD_DISABLE
"Compile in opt-in unsafe prctl(PR_SET_TAGGED_ADDR_CTRL, 0) helper" OFF)
set(FREESCHED_OPENBUENOS_DIR "" CACHE PATH "Optional libopenbuenos root for direct EdgeTPU/FreeTile linkage")
if (NOT FREESCHED_OPENBUENOS_DIR AND DEFINED OPENBUENOS_DIR AND NOT "${OPENBUENOS_DIR}" STREQUAL "")
set(FREESCHED_OPENBUENOS_DIR "${OPENBUENOS_DIR}")
set(FREESCHED_FREETPU_DIR "" CACHE PATH "Optional libfreetpu root (freesilicon/freetpu) for direct EdgeTPU/FreeTile linkage")
set(_FREESCHED_TPU_DIR "${FREESCHED_FREETPU_DIR}")
if (NOT _FREESCHED_TPU_DIR AND DEFINED FREETPU_ROOT AND NOT "${FREETPU_ROOT}" STREQUAL "")
set(_FREESCHED_TPU_DIR "${FREETPU_ROOT}")
elseif (NOT _FREESCHED_TPU_DIR AND DEFINED FREETPU_DIR AND NOT "${FREETPU_DIR}" STREQUAL "")
set(_FREESCHED_TPU_DIR "${FREETPU_DIR}")
endif()

add_library(freesched STATIC
src/fs_topology.cpp
src/fs_dmabuf.cpp
src/fs_router.cpp
src/fs_executor.cpp
src/fs_backend_openbuenos.cpp
src/fs_backend_freetpu.cpp
src/fs_backend_vulkan_dmabuf.cpp
src/fs_vk_adreno_caps.c
src/fs_vk_adreno_spirv_embed.c
Expand Down Expand Up @@ -87,32 +90,39 @@ elseif (APPLE)
target_link_libraries(freesched PUBLIC m)
endif()

if (FREESCHED_OPENBUENOS_DIR)
find_path(_FREESCHED_OB_INCLUDE openbuenos.h
PATHS "${FREESCHED_OPENBUENOS_DIR}/include"
if (_FREESCHED_TPU_DIR)
find_path(_FREESCHED_FREETPU_INCLUDE
NAMES freetpu.h
PATHS
"${_FREESCHED_TPU_DIR}/include"
"${_FREESCHED_TPU_DIR}/libfreetpu/include"
"${_FREESCHED_TPU_DIR}"
NO_DEFAULT_PATH)
if (APPLE)
set(_FREESCHED_OB_LIB_PATHS
"${FREESCHED_OPENBUENOS_DIR}/build/host"
"${FREESCHED_OPENBUENOS_DIR}/build"
"${FREESCHED_OPENBUENOS_DIR}")
set(_FREESCHED_FREETPU_LIB_PATHS
"${_FREESCHED_TPU_DIR}/lib"
"${_FREESCHED_TPU_DIR}/build/host"
"${_FREESCHED_TPU_DIR}/build"
"${_FREESCHED_TPU_DIR}")
else()
set(_FREESCHED_OB_LIB_PATHS
"${FREESCHED_OPENBUENOS_DIR}/build/linux-arm64"
"${FREESCHED_OPENBUENOS_DIR}/build/host"
"${FREESCHED_OPENBUENOS_DIR}/build"
"${FREESCHED_OPENBUENOS_DIR}")
set(_FREESCHED_FREETPU_LIB_PATHS
"${_FREESCHED_TPU_DIR}/lib"
"${_FREESCHED_TPU_DIR}/build/linux-arm64"
"${_FREESCHED_TPU_DIR}/build/host"
"${_FREESCHED_TPU_DIR}/build"
"${_FREESCHED_TPU_DIR}")
endif()
find_library(_FREESCHED_OB_LIB openbuenos
PATHS ${_FREESCHED_OB_LIB_PATHS}
find_library(_FREESCHED_FREETPU_LIB
NAMES freetpu
PATHS ${_FREESCHED_FREETPU_LIB_PATHS}
NO_DEFAULT_PATH)
if (_FREESCHED_OB_INCLUDE AND _FREESCHED_OB_LIB)
message(STATUS "freesched: linking static libopenbuenos (${_FREESCHED_OB_LIB})")
target_compile_definitions(freesched PRIVATE FREESCHED_HAVE_LIBOPENBUENOS=1)
target_include_directories(freesched PRIVATE "${_FREESCHED_OB_INCLUDE}")
target_link_libraries(freesched PUBLIC "${_FREESCHED_OB_LIB}")
if (_FREESCHED_FREETPU_INCLUDE AND _FREESCHED_FREETPU_LIB)
message(STATUS "freesched: linking static libfreetpu (${_FREESCHED_FREETPU_LIB})")
target_compile_definitions(freesched PRIVATE FREESCHED_HAVE_LIBFREETPU=1)
target_include_directories(freesched PRIVATE "${_FREESCHED_FREETPU_INCLUDE}")
target_link_libraries(freesched PUBLIC "${_FREESCHED_FREETPU_LIB}")
else()
message(FATAL_ERROR "FREESCHED_OPENBUENOS_DIR='${FREESCHED_OPENBUENOS_DIR}' missing openbuenos.h or libopenbuenos")
message(FATAL_ERROR "FREESCHED_FREETPU_DIR='${_FREESCHED_TPU_DIR}' missing freetpu.h or libfreetpu")
endif()
endif()

Expand All @@ -126,19 +136,19 @@ add_executable(volcanic_tpu_dmabuf_bench tools/volcanic_tpu_dmabuf_bench.cpp)
target_link_libraries(volcanic_tpu_dmabuf_bench PRIVATE freesched)
target_compile_features(volcanic_tpu_dmabuf_bench PRIVATE cxx_std_17)
target_compile_options(volcanic_tpu_dmabuf_bench PRIVATE -Wall -Wextra -Werror -fno-exceptions -fno-rtti)
if (_FREESCHED_OB_INCLUDE AND _FREESCHED_OB_LIB)
target_compile_definitions(volcanic_tpu_dmabuf_bench PRIVATE FREESCHED_HAVE_LIBOPENBUENOS=1)
target_include_directories(volcanic_tpu_dmabuf_bench PRIVATE "${_FREESCHED_OB_INCLUDE}")
if (_FREESCHED_FREETPU_INCLUDE AND _FREESCHED_FREETPU_LIB)
target_compile_definitions(volcanic_tpu_dmabuf_bench PRIVATE FREESCHED_HAVE_LIBFREETPU=1)
target_include_directories(volcanic_tpu_dmabuf_bench PRIVATE "${_FREESCHED_FREETPU_INCLUDE}")
endif()

add_executable(volcanic_tpu_token_loop_bench tools/volcanic_tpu_token_loop_bench.cpp)
target_link_libraries(volcanic_tpu_token_loop_bench PRIVATE freesched)
target_include_directories(volcanic_tpu_token_loop_bench PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tools)
target_compile_features(volcanic_tpu_token_loop_bench PRIVATE cxx_std_17)
target_compile_options(volcanic_tpu_token_loop_bench PRIVATE -Wall -Wextra -Werror -fno-exceptions -fno-rtti)
if (_FREESCHED_OB_INCLUDE AND _FREESCHED_OB_LIB)
target_compile_definitions(volcanic_tpu_token_loop_bench PRIVATE FREESCHED_HAVE_LIBOPENBUENOS=1)
target_include_directories(volcanic_tpu_token_loop_bench PRIVATE "${_FREESCHED_OB_INCLUDE}")
if (_FREESCHED_FREETPU_INCLUDE AND _FREESCHED_FREETPU_LIB)
target_compile_definitions(volcanic_tpu_token_loop_bench PRIVATE FREESCHED_HAVE_LIBFREETPU=1)
target_include_directories(volcanic_tpu_token_loop_bench PRIVATE "${_FREESCHED_FREETPU_INCLUDE}")
endif()
if (ANDROID)
target_link_options(volcanic_tpu_token_loop_bench PRIVATE -static-libstdc++ -Wl,-z,max-page-size=16384)
Expand Down
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ LDFLAGS += -ldl
STB_POSIX_FLAGS := -D_POSIX_C_SOURCE=200809L
endif

OPENBUENOS_DIR ?=
ifneq ($(OPENBUENOS_DIR),)
OB_LIB := $(firstword $(wildcard $(OPENBUENOS_DIR)/build/host/libopenbuenos.a $(OPENBUENOS_DIR)/build/linux-arm64/libopenbuenos.a $(OPENBUENOS_DIR)/build/libopenbuenos.a))
ifeq ($(OB_LIB),)
$(error OPENBUENOS_DIR=$(OPENBUENOS_DIR) specified but libopenbuenos.a not found)
FREETPU_ROOT ?=
FREETPU_DIR ?=
TPU_DIR := $(or $(FREETPU_ROOT),$(FREETPU_DIR))
ifneq ($(TPU_DIR),)
FREETPU_LIB := $(firstword $(wildcard $(TPU_DIR)/lib/libfreetpu.a $(TPU_DIR)/build/host/libfreetpu.a $(TPU_DIR)/build/linux-arm64/libfreetpu.a $(TPU_DIR)/build/libfreetpu.a $(TPU_DIR)/libfreetpu.a))
ifeq ($(FREETPU_LIB),)
$(error FREETPU_ROOT=$(TPU_DIR) specified but libfreetpu.a not found)
endif
CXXFLAGS += -DFREESCHED_HAVE_LIBOPENBUENOS=1 -I$(OPENBUENOS_DIR)/include
LDFLAGS := $(OB_LIB) $(LDFLAGS)
CXXFLAGS += -DFREESCHED_HAVE_LIBFREETPU=1 -I$(TPU_DIR)/include $(if $(wildcard $(TPU_DIR)/libfreetpu/include),-I$(TPU_DIR)/libfreetpu/include)
LDFLAGS := $(FREETPU_LIB) $(LDFLAGS)
endif

SRCS := \
$(THIS_DIR)/src/fs_topology.cpp \
$(THIS_DIR)/src/fs_dmabuf.cpp \
$(THIS_DIR)/src/fs_router.cpp \
$(THIS_DIR)/src/fs_executor.cpp \
$(THIS_DIR)/src/fs_backend_openbuenos.cpp \
$(THIS_DIR)/src/fs_backend_freetpu.cpp \
$(THIS_DIR)/src/fs_backend_vulkan_dmabuf.cpp \
$(THIS_DIR)/src/ggml_freesilicon.cpp \
$(THIS_DIR)/src/pc_gguf.cpp \
Expand Down
18 changes: 4 additions & 14 deletions android-aar/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ val freeschedVersion = (System.getenv("FREESCHED_VERSION") ?: "0.2.0").removePre
android {
namespace = "io.github.freesilicon.freesched"
compileSdk = 35
ndkVersion = "27.0.12077973"

defaultConfig {
minSdk = 31
Expand Down Expand Up @@ -94,29 +95,18 @@ afterEvaluate {

repositories {
maven {
name = "MavenCentral"
val centralUrl = System.getenv("MAVEN_CENTRAL_URL")
?: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
url = uri(centralUrl)
credentials {
username = System.getenv("MAVEN_CENTRAL_USERNAME") ?: ""
password = System.getenv("MAVEN_CENTRAL_PASSWORD") ?: ""
}
name = "LocalStaging"
url = uri(layout.buildDirectory.dir("staging-repo"))
}
}
}

signing {
val keyId = System.getenv("GPG_KEY_ID")
val signingKey = System.getenv("GPG_PRIVATE_KEY")
val signingPassword = System.getenv("GPG_PASSPHRASE")
isRequired = !signingKey.isNullOrBlank()
if (!signingKey.isNullOrBlank() && !signingPassword.isNullOrBlank()) {
if (!keyId.isNullOrBlank()) {
useInMemoryPgpKeys(keyId, signingKey, signingPassword)
} else {
useInMemoryPgpKeys(signingKey, signingPassword)
}
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications["release"])
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ add_library(freesched SHARED
${FS_ROOT}/src/fs_governor.cpp
${FS_ROOT}/src/fs_router.cpp
${FS_ROOT}/src/fs_executor.cpp
${FS_ROOT}/src/fs_backend_openbuenos.cpp
${FS_ROOT}/src/fs_backend_freetpu.cpp
${FS_ROOT}/src/fs_backend_vulkan_dmabuf.cpp
${FS_ROOT}/src/fs_vk_adreno_caps.c
${FS_ROOT}/src/fs_vk_adreno_spirv_embed.c
Expand Down
2 changes: 1 addition & 1 deletion docs/ANDROID_PLAYBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Still stock Android userspace (Termux/root shell) — root only opens the two de

### 3.1 Direct EdgeTPU (`/dev/edgetpu-soc`)

The clean-room backend is `freesilicon/freetpu` (`libopenbuenos` + FreeTile), bound in `src/fs_backend_openbuenos.cpp`: it probes `/dev/edgetpu-soc` (default `device_path`), maps DMA-BUFs with `EDGETPU_MAP_DMABUF` (36-bit IOVA), registers immutable weight regions with upfront quantized prepacking (zero runtime repack loop; weight-cache hits/evictions are counted, never silently repacked), enforces `fs_dmabuf_reconcile()` upfront, fails closed on tiled layouts, and falls back to exact host reference with `allow_mock_fallback == 1`. Link it statically on the host build with `OPENBUENOS_DIR=<path> make verify` (expects `libopenbuenos.a` under that tree, defines `FREESCHED_HAVE_LIBOPENBUENOS=1`), or let it resolve dynamically via `dlopen`/`dlsym`. DSpark speculative decoding reuses the same cache discipline: `fs_moe_plan_dspark_union` (hit-first exact union, miss tiles of at most 8 experts), then `fs_moe_streamer_begin_speculative` / `commit_speculative` / `rollback_speculative` so rejected drafts never pollute committed LFU counts and accepted tokens reuse prepacked weights with no repack.
The clean-room backend is `freesilicon/freetpu` (`libfreetpu` + FreeTile), bound in `src/fs_backend_freetpu.cpp`: it probes `/dev/edgetpu-soc` (default `device_path`), maps DMA-BUFs with `EDGETPU_MAP_DMABUF` (36-bit IOVA), registers immutable weight regions with upfront quantized prepacking (zero runtime repack loop; weight-cache hits/evictions are counted, never silently repacked), enforces `fs_dmabuf_reconcile()` upfront, fails closed on tiled layouts, and falls back to exact host reference with `allow_mock_fallback == 1`. Link it statically on the host build with `FREETPU_ROOT=<path> make verify` (expects `libfreetpu.a` under that tree, defines `FREESCHED_HAVE_LIBFREETPU=1`), or let it resolve dynamically via `dlopen`/`dlsym` (`libfreetpu.so`). DSpark speculative decoding reuses the same cache discipline: `fs_moe_plan_dspark_union` (hit-first exact union, miss tiles of at most 8 experts), then `fs_moe_streamer_begin_speculative` / `commit_speculative` / `rollback_speculative` so rejected drafts never pollute committed LFU counts and accepted tokens reuse prepacked weights with no repack.

### 3.2 Zero-copy EdgeTPU <-> Vulkan hybrid (`/dev/dma_heap/system`)

Expand Down
Loading
Loading