Skip to content
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

feat : support CoreML #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,47 @@ if (EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -O3")
endif()

if (APPLE)
option(BARK_COREML "bark: enable CoreML framework" OFF)
endif()

# coreml

if (BARK_COREML)
find_library(FOUNDATION_FRAMEWORK Foundation)
find_library(COREML_FRAMEWORK CoreML)

if (COREML_FRAMEWORK)
message(STATUS "CoreML framework found")

set(BARK_EXTRA_FLAGS ${BARK_EXTRA_FLAGS} -DBARK_USE_COREML)
else()
message(FATAL_ERROR "CoreML framework not found")
endif()

set(TARGET bark.coreml)

add_library(${TARGET}
coreml/bark.h
coreml/bark.mm
coreml/bark-impl.h
coreml/bark-impl.m
)

include(DefaultTargetOptions)

target_include_directories(${TARGET} PUBLIC .)

target_link_libraries(${TARGET} PRIVATE ${FOUNDATION_FRAMEWORK} ${COREML_FRAMEWORK})

set_target_properties(${TARGET} PROPERTIES COMPILE_FLAGS "-fobjc-arc")
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
endif()

#
# bark_lib (main lib)
#

set(BARK_LIB bark)

add_subdirectory(encodec.cpp)
Expand All @@ -34,6 +75,10 @@ if (EMSCRIPTEN)
set_target_properties(${BARK_LIB} PROPERTIES COMPILE_FLAGS "-msimd128")
endif()

if (BARK_COREML)
target_link_libraries(${BARK_LIB} PRIVATE bark.coreml)
endif()

if (GGML_CUBLAS)
add_compile_definitions(GGML_USE_CUBLAS)
endif()
Expand Down
4 changes: 4 additions & 0 deletions bark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "ggml-backend.h"
#include "ggml.h"

#ifdef BARK_USE_COREML
#include "coreml/bark.h"
#endif

#ifdef GGML_USE_CUBLAS
#include "ggml-cuda.h"
#endif
Expand Down
8 changes: 8 additions & 0 deletions bark.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include "ggml-backend.h"
#include "ggml.h"

#ifdef BARK_USE_COREML
#include "coreml/bark.h"
#endif

enum class bark_verbosity_level {
LOW = 0,
MEDIUM = 1,
Expand Down Expand Up @@ -201,6 +205,10 @@ struct bark_context {

// encodec parameters
std::string encodec_model_path;

#ifdef BARK_USE_COREML
bark_coreml_context * ctx_coreml = nullptr;
#endif
};

/**
Expand Down
Loading
Loading