diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-20 20:10:56 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-21 05:57:19 +0200 |
| commit | 6b969d25ce136eaf695222bd1a10bff1ecac0220 (patch) | |
| tree | c23afb50c28b9deaddae5c6526a74ee11cf2d865 /libffwd/Makefile | |
| parent | d4bdb8dae753462f621507d5fc3582e0e53da35c (diff) | |
| download | ffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.tar.gz ffwd-6b969d25ce136eaf695222bd1a10bff1ecac0220.zip | |
all: split Makefile and reorg library/tools
Diffstat (limited to 'libffwd/Makefile')
| -rw-r--r-- | libffwd/Makefile | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libffwd/Makefile b/libffwd/Makefile new file mode 100644 index 0000000..0c831a6 --- /dev/null +++ b/libffwd/Makefile @@ -0,0 +1,61 @@ +ROOT := .. +COMPONENT := libffwd +include ../build.mk + +LIB := ffwd +STATIC := $(OUTDIR)/lib$(LIB).a +SHARED := $(OUTDIR)/lib$(LIB).$(SHARED_EXT) + +CFLAGS += -std=c11 -pthread $(BACKEND_CFLAGS) +CPPFLAGS += -I. +SHARED_FLAGS += -pthread +# Restrict the shared library's exported symbols to the public ABI. +SHARED_LDFLAGS += $(EXPORT_FLAGS) + +# Tokenizer, config, safetensors reader, and L2/cosine helpers: every backend. +COMMON_SRCS := config.c vec.c tokenize.c bpe.c sentencepiece.c wordpiece.c safetensors.c + +# CPU math kernels and SIMD dispatch. generic.c is always built; avx.c and +# neon.c each guard their entire body by arch (__AVX2__ / __ARM_NEON), so the +# off-target file compiles to an empty translation unit. +KERNEL_SRCS := act.c gemm.c norm.c rope.c attn.c threadpool.c generic.c avx.c neon.c + +BLAS_SRCS := backend_blas.c model.c model_blas.c forward.c late.c late_blas.c alloc.c \ + $(COMMON_SRCS) $(KERNEL_SRCS) +MLX_SRCS := backend_mlx.c mlx.c $(COMMON_SRCS) +CUDA_SRCS := backend_cuda.c model.c late.c alloc.c $(COMMON_SRCS) $(KERNEL_SRCS) + +ifeq ($(BACKEND),mlx) + SRCS := $(MLX_SRCS) + CU_SRCS := +else ifeq ($(BACKEND),cuda) + SRCS := $(CUDA_SRCS) + CU_SRCS := cuda.cu +else + SRCS := $(BLAS_SRCS) + CU_SRCS := +endif + +OBJS := $(call objs,$(SRCS) $(CU_SRCS)) +DEPS := $(call deps,$(OBJS)) + +.PHONY: all clean + +all: $(STATIC) $(SHARED) + +$(eval $(call static_archive,$(STATIC),$(OBJS))) +$(eval $(call shared_library,$(SHARED),$(OBJS),,$(BACKEND_LDFLAGS) -lm)) +# The export map is generated from the public ABI (the FFWD_API declarations in +# ffwd.h) instead of being committed, so it cannot drift from the header. It is +# regenerated when the header or the generator changes, and the shared library +# relinks when it does. +$(EXPORT_FILE): ffwd.h $(ROOT)/devtools/gen_exports.py + python3 $(ROOT)/devtools/gen_exports.py --outdir $(ROOT) +$(SHARED): $(EXPORT_FILE) + +# Removes only this MODE/BACKEND's objects and artifacts; the root `make clean` +# removes the whole build/ tree. +clean: + $(RM) -r $(OBJDIR) $(STATIC) $(SHARED) $(SHARED).dSYM + +-include $(DEPS) |
