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
66 changes: 59 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ project("CLIP.cpp" C CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

#
Expand All @@ -11,6 +16,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# general
option(CLIP_STATIC "CLIP: static link libraries" OFF)
option(CLIP_NO_EXAMPLES "CLIP: do not build examples" OFF)
option(CLIP_NO_TESTS "CLIP: do not build tests" OFF)
option(CLIP_NATIVE "CLIP: enable -march=native flag" ON)
option(CLIP_LTO "CLIP: enable link time optimization" OFF)

Expand All @@ -28,6 +35,14 @@ option(CLIP_SANITIZE_UNDEFINED "CLIP: enable undefined sanitizer"
option(CLIP_AVX "CLIP: enable AVX" ON)
option(CLIP_AVX2 "CLIP: enable AVX2" ON)
option(CLIP_FMA "CLIP: enable FMA" ON)
option(CLIP_AVX512 "clip: enable AVX512" OFF)
option(CLIP_AVX512_VBMI "clip: enable AVX512-VBMI" OFF)
option(CLIP_AVX512_VNNI "clip: enable AVX512-VNNI" OFF)
# in MSVC F16C is implied with AVX2/AVX512
if (NOT MSVC)
option(CLIP_F16C "clip: enable F16C" ON)
endif()


# 3rd party libs
option(CLIP_ACCELERATE "CLIP: enable Accelerate framework" ON)
Expand Down Expand Up @@ -130,6 +145,8 @@ if (CLIP_LTO)
endif()
endif()



# Architecture specific
# TODO: probably these flags need to be tweaked on some architectures
# feel free to update the Makefile for your architecture and send a pull request or issue
Expand Down Expand Up @@ -162,13 +179,32 @@ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$")
message(STATUS "x86 detected")
if (MSVC)
if (CLIP_AVX2)
add_compile_options(/arch:AVX2)
if (CLIP_AVX512)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX512>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX512>)
# MSVC has no compile-time flags enabling specific
# AVX512 extensions, neither it defines the
# macros corresponding to the extensions.
# Do it manually.
if (CLIP_AVX512_VBMI)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:__AVX512VBMI__>)
add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:__AVX512VBMI__>)
endif()
if (CLIP_AVX512_VNNI)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:__AVX512VNNI__>)
add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:__AVX512VNNI__>)
endif()
elseif (CLIP_AVX2)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX2>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX2>)
elseif (CLIP_AVX)
add_compile_options(/arch:AVX)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/arch:AVX>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/arch:AVX>)
endif()
else()
add_compile_options(-mf16c)
if (CLIP_F16C)
add_compile_options(-mf16c)
endif()
if (CLIP_FMA)
add_compile_options(-mfma)
endif()
Expand All @@ -178,12 +214,24 @@ elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(x86_64|i686|AMD64)$")
if (CLIP_AVX2)
add_compile_options(-mavx2)
endif()
if (CLIP_AVX512)
add_compile_options(-mavx512f)
add_compile_options(-mavx512bw)
endif()
if (CLIP_AVX512_VBMI)
add_compile_options(-mavx512vbmi)
endif()
if (CLIP_AVX512_VNNI)
add_compile_options(-mavx512vnni)
endif()
endif()
else()
# TODO: support PowerPC
message(STATUS "Unknown architecture")
endif()



#
# Build libraries
#
Expand Down Expand Up @@ -213,6 +261,10 @@ endif()

add_subdirectory(models)

# TODO: build examples and tests conditionally
add_subdirectory(examples)
add_subdirectory(tests)
if (NOT CLIP_NO_EXAMPLES)
add_subdirectory(examples)
endif()

if (NOT CLIP_NO_TESTS)
add_subdirectory(tests)
endif()
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ make

And the binaries are in the `./bin` directory.

TODO: Detail other build optimizations.
**Note**: Some Mac devices report `x86_64` instead of `arm64` architecture. If this is the case see [here](https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment) for a discussion.
I couldn't reproduce it on my Macbook M2 pro so cannot help further. If you know a solution that I can include in `CMakeLists.txt` please ping me [here](https://github.com/monatis/clip.cpp/issues/24).

## Quantization
`clip.cpp` currently supports q4_0 and q4_1 quantization types.
Expand Down