-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (52 loc) · 1.34 KB
/
Copy pathMakefile
File metadata and controls
65 lines (52 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
CC ?= cc
CFLAGS ?= -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Werror
LDFLAGS ?=
BUILD_DIR := build
SRC := \
src/tensor.c \
src/graph.c \
src/runtime.c \
src/allocator.c \
src/planner.c \
src/ops.c \
src/onnx.c \
src/ops/matmul.c \
src/ops/add.c \
src/ops/relu.c \
src/ops/softmax.c \
src/ops/reshape.c \
src/ops/transpose.c
OBJ := $(SRC:%.c=$(BUILD_DIR)/%.o)
# Metal support on macOS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
METAL_SRC := src/metal/metal_context.m src/metal/metal_ops.m
METAL_OBJ := $(METAL_SRC:%.m=$(BUILD_DIR)/%.o)
OBJCFLAGS := -fobjc-arc -O2 -g -Wall
OBJ += $(METAL_OBJ)
LDFLAGS += -framework Metal -framework Foundation
endif
LIB := $(BUILD_DIR)/libmir.a
.PHONY: all clean test test_metal
all: $(LIB)
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -MMD -MP -Iinclude -Isrc -c $< -o $@
ifeq ($(UNAME_S),Darwin)
$(BUILD_DIR)/%.o: %.m
@mkdir -p $(@D)
$(CC) $(OBJCFLAGS) -MMD -MP -Iinclude -Isrc -c $< -o $@
endif
$(LIB): $(OBJ)
ar rcs $@ $(OBJ)
$(BUILD_DIR)/test_%: tests/test_%.c tests/test_common.h $(LIB)
@mkdir -p $(@D)
$(CC) $(CFLAGS) -Iinclude $< -o $@ $(LIB) $(LDFLAGS) -lm
test: $(BUILD_DIR)/test_ops $(BUILD_DIR)/test_onnx
./$(BUILD_DIR)/test_ops
./$(BUILD_DIR)/test_onnx
test_metal: $(BUILD_DIR)/test_metal
./$(BUILD_DIR)/test_metal
clean:
rm -rf $(BUILD_DIR)
-include $(OBJ:.o=.d)