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
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ weights/
stage/
.cache/

apple/
android/build/
android/libs/
android/arm64-v8a/
*.so

apple/build/
apple/build-static/
apple/*.xcframework
apple/libcactus.a
apple/libcactus*.a
*.a
!libs/curl/**/*.a
!cactus-engine/libs/curl/**/*.a
!android/mbedtls/**/*.a
venv

__pycache__
Expand Down
202 changes: 202 additions & 0 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
cmake_minimum_required(VERSION 3.10)
project(Cactus LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CACTUS_REPO_ROOT "${CMAKE_SOURCE_DIR}/..")
set(CACTUS_ENGINE_DIR "${CACTUS_REPO_ROOT}/cactus-engine")
set(CACTUS_GRAPH_DIR "${CACTUS_REPO_ROOT}/cactus-graph")
set(CACTUS_KERNEL_DIR "${CACTUS_REPO_ROOT}/cactus-kernels")
set(CACTUS_CURL_ROOT "${CACTUS_ENGINE_DIR}/libs/curl" CACHE PATH "Path to vendored libcurl artifacts")

set(_CACTUS_VERSION_FILE "${CACTUS_REPO_ROOT}/CACTUS_VERSION")
if(EXISTS "${_CACTUS_VERSION_FILE}")
file(READ "${_CACTUS_VERSION_FILE}" _CACTUS_VERSION_CONTENT)
string(STRIP "${_CACTUS_VERSION_CONTENT}" CACTUS_VERSION_STR)
message(STATUS "Cactus version: ${CACTUS_VERSION_STR}")
else()
set(CACTUS_VERSION_STR "")
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
message(STATUS "CMAKE_BUILD_TYPE was not set, defaulting to Release.")
endif()

file(GLOB KERNEL_SOURCES "${CACTUS_KERNEL_DIR}/src/*.cpp")
file(GLOB GRAPH_SOURCES "${CACTUS_GRAPH_DIR}/src/*.cpp")

set(ENGINE_SOURCES
${CACTUS_ENGINE_DIR}/src/bpe.cpp
${CACTUS_ENGINE_DIR}/src/sp.cpp
${CACTUS_ENGINE_DIR}/src/constraints.cpp
${CACTUS_ENGINE_DIR}/src/model.cpp
${CACTUS_ENGINE_DIR}/src/engine_image.cpp
${CACTUS_ENGINE_DIR}/src/index.cpp
${CACTUS_ENGINE_DIR}/src/index_ffi.cpp
${CACTUS_ENGINE_DIR}/src/log.cpp
${CACTUS_ENGINE_DIR}/src/graph_ffi.cpp
${CACTUS_ENGINE_DIR}/src/rag.cpp
${CACTUS_ENGINE_DIR}/src/telemetry.cpp
${CACTUS_ENGINE_DIR}/src/telemetry_impl.cpp
${CACTUS_ENGINE_DIR}/src/cloud.cpp
${CACTUS_ENGINE_DIR}/src/init.cpp
${CACTUS_ENGINE_DIR}/src/embed.cpp
${CACTUS_ENGINE_DIR}/src/complete.cpp
${CACTUS_ENGINE_DIR}/src/transcribe.cpp
${CACTUS_ENGINE_DIR}/src/tokenizer.cpp
${CACTUS_ENGINE_DIR}/src/npu.cpp
)

set(HEADER_FILES
${CACTUS_REPO_ROOT}/cactus/cactus.h
${CACTUS_ENGINE_DIR}/cactus_engine.h
${CACTUS_GRAPH_DIR}/cactus_graph.h
${CACTUS_KERNEL_DIR}/cactus_kernels.h
)

set(COMMON_SOURCES
${KERNEL_SOURCES}
${GRAPH_SOURCES}
${ENGINE_SOURCES}
)

if(NOT COMMON_SOURCES)
message(FATAL_ERROR "No source files found! Check repo layout under ${CACTUS_REPO_ROOT}")
endif()

find_library(LOG_LIB log)

add_library(
cactus
SHARED
${COMMON_SOURCES}
${CMAKE_SOURCE_DIR}/cactus_jni.cpp
)

add_library(
cactus_static
STATIC
${COMMON_SOURCES}
)

set(COMMON_INCLUDE_DIRS
${CACTUS_REPO_ROOT}
${CACTUS_REPO_ROOT}/cactus
${CACTUS_ENGINE_DIR}
${CACTUS_ENGINE_DIR}/src
${CACTUS_ENGINE_DIR}/libs
${CACTUS_GRAPH_DIR}
${CACTUS_GRAPH_DIR}/src
${CACTUS_KERNEL_DIR}
${CACTUS_KERNEL_DIR}/src
${CACTUS_KERNEL_DIR}/libs
)

target_include_directories(cactus PRIVATE ${COMMON_INCLUDE_DIRS})
target_include_directories(cactus_static PRIVATE ${COMMON_INCLUDE_DIRS})

target_link_libraries(cactus ${LOG_LIB} android)

set(CACTUS_CURL_INCLUDE_DIR "${CACTUS_CURL_ROOT}/include")
set(CACTUS_CURL_LIBRARY_ANDROID "${CACTUS_CURL_ROOT}/android/${ANDROID_ABI}/libcurl.a")
set(CACTUS_MBEDTLS_ROOT "${CMAKE_SOURCE_DIR}/mbedtls/${ANDROID_ABI}")
if(NOT EXISTS "${CACTUS_MBEDTLS_ROOT}")
set(CACTUS_MBEDTLS_ROOT "${CACTUS_REPO_ROOT}/libs/mbedtls/android/${ANDROID_ABI}")
endif()
set(CACTUS_MBEDTLS_INCLUDE_DIR "${CACTUS_MBEDTLS_ROOT}/include")
set(CACTUS_MBEDTLS_LIBRARY "${CACTUS_MBEDTLS_ROOT}/lib/libmbedtls.a")
set(CACTUS_MBEDX509_LIBRARY "${CACTUS_MBEDTLS_ROOT}/lib/libmbedx509.a")
set(CACTUS_MBEDCRYPTO_LIBRARY "${CACTUS_MBEDTLS_ROOT}/lib/libmbedcrypto.a")
if(EXISTS "${CACTUS_CURL_INCLUDE_DIR}/curl/curl.h" AND EXISTS "${CACTUS_CURL_LIBRARY_ANDROID}")
message(STATUS "Using vendored libcurl for Android: ${CACTUS_CURL_LIBRARY_ANDROID}")

if(NOT (EXISTS "${CACTUS_MBEDTLS_LIBRARY}" AND EXISTS "${CACTUS_MBEDX509_LIBRARY}" AND EXISTS "${CACTUS_MBEDCRYPTO_LIBRARY}"))
message(FATAL_ERROR "Vendored mbedTLS libraries not found. Expected: ${CACTUS_MBEDTLS_LIBRARY}, ${CACTUS_MBEDX509_LIBRARY}, ${CACTUS_MBEDCRYPTO_LIBRARY}")
endif()

target_include_directories(cactus PRIVATE "${CACTUS_CURL_INCLUDE_DIR}")
target_include_directories(cactus_static PRIVATE "${CACTUS_CURL_INCLUDE_DIR}")
target_include_directories(cactus PRIVATE "${CACTUS_MBEDTLS_INCLUDE_DIR}")
target_include_directories(cactus_static PRIVATE "${CACTUS_MBEDTLS_INCLUDE_DIR}")
target_compile_definitions(cactus PRIVATE CACTUS_USE_CURL=1)
target_compile_definitions(cactus_static PRIVATE CACTUS_USE_CURL=1)

target_link_libraries(cactus "${CACTUS_CURL_LIBRARY_ANDROID}")
target_link_libraries(cactus_static "${CACTUS_CURL_LIBRARY_ANDROID}")
target_link_libraries(cactus "${CACTUS_MBEDTLS_LIBRARY}" "${CACTUS_MBEDX509_LIBRARY}" "${CACTUS_MBEDCRYPTO_LIBRARY}")
target_link_libraries(cactus_static "${CACTUS_MBEDTLS_LIBRARY}" "${CACTUS_MBEDX509_LIBRARY}" "${CACTUS_MBEDCRYPTO_LIBRARY}")
else()
message(FATAL_ERROR "Vendored Android libcurl not found. Expected: ${CACTUS_CURL_INCLUDE_DIR}/curl/curl.h and ${CACTUS_CURL_LIBRARY_ANDROID}")
endif()

set(COMMON_COMPILE_DEFINITIONS
PLATFORM_CPU_ONLY=1
)
if(NOT "${CACTUS_VERSION_STR}" STREQUAL "")
list(APPEND COMMON_COMPILE_DEFINITIONS "CACTUS_COMPILE_TIME_VERSION=\"${CACTUS_VERSION_STR}\"")
endif()

target_compile_definitions(cactus PRIVATE ${COMMON_COMPILE_DEFINITIONS})
target_compile_definitions(cactus_static PRIVATE ${COMMON_COMPILE_DEFINITIONS})

set(COMMON_COMPILE_OPTIONS
-pthread
-Wall
-Wextra
-pedantic
-Wno-c++20-designator
-Wno-missing-field-initializers
-fomit-frame-pointer
-funroll-loops
-ftree-vectorize
)

target_compile_options(cactus PRIVATE ${COMMON_COMPILE_OPTIONS})
target_compile_options(cactus_static PRIVATE ${COMMON_COMPILE_OPTIONS})

if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
target_compile_options(cactus PRIVATE -DCACTUS_ANDROID_ENABLE_LOGGING)
target_compile_options(cactus_static PRIVATE -DCACTUS_ANDROID_ENABLE_LOGGING)
endif ()

set(OPTIMIZATION_OPTIONS
-O3
-DNDEBUG
-ffunction-sections
-fdata-sections
)

target_compile_options(cactus PRIVATE ${OPTIMIZATION_OPTIONS})
target_compile_options(cactus_static PRIVATE ${OPTIMIZATION_OPTIONS})

target_compile_options(cactus PRIVATE -fvisibility=hidden -fvisibility-inlines-hidden)

if (${ANDROID_ABI} STREQUAL "arm64-v8a")
set(ARM_OPTIONS
-march=armv8.2-a+fp16+simd+dotprod
)
set(ARM_DEFINITIONS
__ARM_NEON=1
__ARM_FEATURE_FP16_VECTOR_ARITHMETIC=1
__ARM_FEATURE_DOTPROD=1
)

target_compile_options(cactus PRIVATE ${ARM_OPTIONS})
target_compile_options(cactus_static PRIVATE ${ARM_OPTIONS})

target_compile_definitions(cactus PRIVATE ${ARM_DEFINITIONS})
target_compile_definitions(cactus_static PRIVATE ${ARM_DEFINITIONS})
else()
message(FATAL_ERROR "Unsupported Android ABI: ${ANDROID_ABI}. Cactus only supports arm64-v8a due to ARM NEON requirements.")
endif()

target_link_options(cactus PRIVATE -Wl,--gc-sections)
target_link_options(cactus PRIVATE -Wl,--exclude-libs,ALL)
target_link_options(cactus PRIVATE -flto)
target_link_options(cactus PRIVATE -Wl,-z,max-page-size=16384)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
115 changes: 115 additions & 0 deletions android/Cactus.android.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
@file:JvmName("Cactus")
package com.cactus

private object CactusJNI {
init {
System.loadLibrary("cactus")
nativeSetFramework()
}

@JvmStatic external fun nativeSetFramework()
@JvmStatic external fun nativeGetLastError(): String
@JvmStatic external fun nativeSetCacheDir(cacheDir: String)
@JvmStatic external fun nativeSetAppId(appId: String)
@JvmStatic external fun nativeTelemetryFlush()
@JvmStatic external fun nativeTelemetryShutdown()
@JvmStatic external fun nativeInit(modelPath: String, corpusDir: String?, cacheIndex: Boolean): Long
@JvmStatic external fun nativeDestroy(handle: Long)
@JvmStatic external fun nativeReset(handle: Long)
@JvmStatic external fun nativeStop(handle: Long)
@JvmStatic external fun nativeComplete(handle: Long, messagesJson: String, optionsJson: String?, toolsJson: String?, callback: CactusTokenCallback?, pcmData: ByteArray?): String
@JvmStatic external fun nativePrefill(handle: Long, messagesJson: String, optionsJson: String?, toolsJson: String?, pcmData: ByteArray?): String
@JvmStatic external fun nativeDetectLanguage(handle: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String
@JvmStatic external fun nativeLogSetLevel(level: Int)
@JvmStatic external fun nativeLogSetCallback(callback: CactusLogCallback?)
@JvmStatic external fun nativeTranscribe(handle: Long, audioPath: String?, prompt: String?, optionsJson: String?, callback: CactusTokenCallback?, pcmData: ByteArray?): String
@JvmStatic external fun nativeEmbed(handle: Long, text: String, normalize: Boolean): FloatArray
@JvmStatic external fun nativeRagQuery(handle: Long, query: String, topK: Int): String
@JvmStatic external fun nativeTokenize(handle: Long, text: String): IntArray
@JvmStatic external fun nativeScoreWindow(handle: Long, tokens: IntArray, start: Int, end: Int, context: Int): String
@JvmStatic external fun nativeImageEmbed(handle: Long, imagePath: String): FloatArray
@JvmStatic external fun nativeAudioEmbed(handle: Long, audioPath: String): FloatArray
@JvmStatic external fun nativeVad(handle: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String
@JvmStatic external fun nativeDiarize(handle: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String
@JvmStatic external fun nativeEmbedSpeaker(handle: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?, maskWeights: FloatArray?): String
@JvmStatic external fun nativeStreamTranscribeInit(handle: Long, optionsJson: String?): Long
@JvmStatic external fun nativeStreamTranscribeProcess(handle: Long, pcmData: ByteArray): String
@JvmStatic external fun nativeStreamTranscribeStop(handle: Long): String
@JvmStatic external fun nativeIndexInit(indexDir: String, embeddingDim: Int): Long
@JvmStatic external fun nativeIndexAdd(handle: Long, ids: IntArray, documents: Array<String>, metadatas: Array<String>?, embeddings: Array<FloatArray>, embeddingDim: Long): Int
@JvmStatic external fun nativeIndexDelete(handle: Long, ids: IntArray): Int
@JvmStatic external fun nativeIndexGet(handle: Long, ids: IntArray): String
@JvmStatic external fun nativeIndexQuery(handle: Long, embedding: FloatArray, topK: Long, optionsJson: String?): String
@JvmStatic external fun nativeIndexCompact(handle: Long): Int
@JvmStatic external fun nativeIndexDestroy(handle: Long)
}

actual fun cactusInit(modelPath: String, corpusDir: String?, cacheIndex: Boolean): Long {
val h = CactusJNI.nativeInit(modelPath, corpusDir, cacheIndex)
if (h == 0L) throw RuntimeException(CactusJNI.nativeGetLastError().ifEmpty { "Failed to initialize model" })
return h
}
actual fun cactusDestroy(model: Long) = CactusJNI.nativeDestroy(model)
actual fun cactusReset(model: Long) = CactusJNI.nativeReset(model)
actual fun cactusStop(model: Long) = CactusJNI.nativeStop(model)
actual fun cactusGetLastError(): String = CactusJNI.nativeGetLastError()
actual fun cactusSetTelemetryEnvironment(cacheDir: String) = CactusJNI.nativeSetCacheDir(cacheDir)
actual fun cactusSetAppId(appId: String) = CactusJNI.nativeSetAppId(appId)
actual fun cactusTelemetryFlush() = CactusJNI.nativeTelemetryFlush()
actual fun cactusTelemetryShutdown() = CactusJNI.nativeTelemetryShutdown()
actual fun cactusComplete(model: Long, messagesJson: String, optionsJson: String?, toolsJson: String?, callback: CactusTokenCallback?, pcmData: ByteArray?): String =
CactusJNI.nativeComplete(model, messagesJson, optionsJson, toolsJson, callback, pcmData)
actual fun cactusPrefill(model: Long, messagesJson: String, optionsJson: String?, toolsJson: String?, pcmData: ByteArray?): String =
CactusJNI.nativePrefill(model, messagesJson, optionsJson, toolsJson, pcmData)
actual fun cactusTranscribe(model: Long, audioPath: String?, prompt: String?, optionsJson: String?, callback: CactusTokenCallback?, pcmData: ByteArray?): String =
CactusJNI.nativeTranscribe(model, audioPath, prompt, optionsJson, callback, pcmData)
actual fun cactusEmbed(model: Long, text: String, normalize: Boolean): FloatArray =
CactusJNI.nativeEmbed(model, text, normalize)
actual fun cactusImageEmbed(model: Long, imagePath: String): FloatArray =
CactusJNI.nativeImageEmbed(model, imagePath)
actual fun cactusAudioEmbed(model: Long, audioPath: String): FloatArray =
CactusJNI.nativeAudioEmbed(model, audioPath)
actual fun cactusVad(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String =
CactusJNI.nativeVad(model, audioPath, optionsJson, pcmData)
actual fun cactusDiarize(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String =
CactusJNI.nativeDiarize(model, audioPath, optionsJson, pcmData)
actual fun cactusEmbedSpeaker(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?, maskWeights: FloatArray?): String =
CactusJNI.nativeEmbedSpeaker(model, audioPath, optionsJson, pcmData, maskWeights)
actual fun cactusRagQuery(model: Long, query: String, topK: Int): String =
CactusJNI.nativeRagQuery(model, query, topK)
actual fun cactusTokenize(model: Long, text: String): IntArray =
CactusJNI.nativeTokenize(model, text)
actual fun cactusScoreWindow(model: Long, tokens: IntArray, start: Int, end: Int, context: Int): String =
CactusJNI.nativeScoreWindow(model, tokens, start, end, context)
actual fun cactusStreamTranscribeStart(model: Long, optionsJson: String?): Long {
val h = CactusJNI.nativeStreamTranscribeInit(model, optionsJson)
if (h == 0L) throw RuntimeException(CactusJNI.nativeGetLastError().ifEmpty { "Failed to create stream transcriber" })
return h
}
actual fun cactusStreamTranscribeProcess(stream: Long, pcmData: ByteArray): String =
CactusJNI.nativeStreamTranscribeProcess(stream, pcmData)
actual fun cactusStreamTranscribeStop(stream: Long): String =
CactusJNI.nativeStreamTranscribeStop(stream)
actual fun cactusIndexInit(indexDir: String, embeddingDim: Int): Long {
val h = CactusJNI.nativeIndexInit(indexDir, embeddingDim)
if (h == 0L) throw RuntimeException("Failed to initialize index")
return h
}
actual fun cactusIndexAdd(index: Long, ids: IntArray, documents: Array<String>, embeddings: Array<FloatArray>, metadatas: Array<String>?): Int =
CactusJNI.nativeIndexAdd(index, ids, documents, metadatas, embeddings, embeddings[0].size.toLong())
actual fun cactusIndexDelete(index: Long, ids: IntArray): Int =
CactusJNI.nativeIndexDelete(index, ids)
actual fun cactusIndexGet(index: Long, ids: IntArray): String =
CactusJNI.nativeIndexGet(index, ids)
actual fun cactusIndexQuery(index: Long, embedding: FloatArray, optionsJson: String?): String =
CactusJNI.nativeIndexQuery(index, embedding, 1000L, optionsJson)
actual fun cactusIndexCompact(index: Long): Int =
CactusJNI.nativeIndexCompact(index)
actual fun cactusIndexDestroy(index: Long) =
CactusJNI.nativeIndexDestroy(index)
actual fun cactusDetectLanguage(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String =
CactusJNI.nativeDetectLanguage(model, audioPath, optionsJson, pcmData)
actual fun cactusLogSetLevel(level: Int) =
CactusJNI.nativeLogSetLevel(level)
actual fun cactusLogSetCallback(callback: CactusLogCallback?) =
CactusJNI.nativeLogSetCallback(callback)
44 changes: 44 additions & 0 deletions android/Cactus.common.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.cactus

fun interface CactusTokenCallback {
fun onToken(token: String, tokenId: Int)
}

fun interface CactusLogCallback {
fun onLog(level: Int, component: String, message: String)
}

expect fun cactusInit(modelPath: String, corpusDir: String?, cacheIndex: Boolean): Long
expect fun cactusDestroy(model: Long)
expect fun cactusReset(model: Long)
expect fun cactusStop(model: Long)
expect fun cactusGetLastError(): String
expect fun cactusSetTelemetryEnvironment(cacheDir: String)
expect fun cactusSetAppId(appId: String)
expect fun cactusTelemetryFlush()
expect fun cactusTelemetryShutdown()
expect fun cactusComplete(model: Long, messagesJson: String, optionsJson: String?, toolsJson: String?, callback: CactusTokenCallback?, pcmData: ByteArray? = null): String
expect fun cactusPrefill(model: Long, messagesJson: String, optionsJson: String?, toolsJson: String?, pcmData: ByteArray? = null): String
expect fun cactusTranscribe(model: Long, audioPath: String?, prompt: String?, optionsJson: String?, callback: CactusTokenCallback?, pcmData: ByteArray?): String
expect fun cactusEmbed(model: Long, text: String, normalize: Boolean): FloatArray
expect fun cactusImageEmbed(model: Long, imagePath: String): FloatArray
expect fun cactusAudioEmbed(model: Long, audioPath: String): FloatArray
expect fun cactusVad(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String
expect fun cactusRagQuery(model: Long, query: String, topK: Int): String
expect fun cactusTokenize(model: Long, text: String): IntArray
expect fun cactusScoreWindow(model: Long, tokens: IntArray, start: Int, end: Int, context: Int): String
expect fun cactusStreamTranscribeStart(model: Long, optionsJson: String?): Long
expect fun cactusStreamTranscribeProcess(stream: Long, pcmData: ByteArray): String
expect fun cactusStreamTranscribeStop(stream: Long): String
expect fun cactusIndexInit(indexDir: String, embeddingDim: Int): Long
expect fun cactusIndexAdd(index: Long, ids: IntArray, documents: Array<String>, embeddings: Array<FloatArray>, metadatas: Array<String>?): Int
expect fun cactusIndexDelete(index: Long, ids: IntArray): Int
expect fun cactusIndexGet(index: Long, ids: IntArray): String
expect fun cactusIndexQuery(index: Long, embedding: FloatArray, optionsJson: String?): String
expect fun cactusIndexCompact(index: Long): Int
expect fun cactusIndexDestroy(index: Long)
expect fun cactusDetectLanguage(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String
expect fun cactusDiarize(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?): String
expect fun cactusEmbedSpeaker(model: Long, audioPath: String?, optionsJson: String?, pcmData: ByteArray?, maskWeights: FloatArray? = null): String
expect fun cactusLogSetLevel(level: Int)
expect fun cactusLogSetCallback(callback: CactusLogCallback?)
Loading
Loading