-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.win
144 lines (123 loc) · 3.91 KB
/
Makefile.win
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
INCLUDE_PATH := $(abspath ./)
LIBRARY_PATH := $(abspath ./)
ifndef UNAME_S
UNAME_S := $(shell ver)
endif
ifndef UNAME_P
UNAME_P := $(shell wmic cpu get caption)
endif
ifndef UNAME_M
UNAME_M := $(PROCESSOR_ARCHITECTURE)
endif
CCV := $(shell $(CC) --version | head -n 1)
CXXV := $(shell $(CXX) --version | head -n 1)
#
# Compile flags
#
BUILD_TYPE?=
# keep standard at C17 and C++17
CXXFLAGS = -I. -O3 -DNDEBUG -std=c++17 -fPIC -pthread
# GPGPU specific
GGML_CUDA_OBJ_PATH=third_party/ggml/src/CMakeFiles/ggml.dir/ggml-cuda.cu.o
# Architecture specific
# feel free to update the Makefile for your architecture and send a pull request or issue
ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686))
# Use all CPU extensions that are available:
CXXFLAGS += -march=native -mtune=native
endif
ifneq ($(filter ppc64%,$(UNAME_M)),)
POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
ifneq (,$(findstring POWER9,$(POWER9_M)))
CXXFLAGS += -mcpu=power9
endif
# Require c++23's std::byteswap for big-endian support.
ifeq ($(UNAME_M),ppc64)
CXXFLAGS += -std=c++23 -DGGML_BIG_ENDIAN
endif
endif
ifdef CHATGLM_GPROF
CXXFLAGS += -pg
endif
ifneq ($(filter aarch64%,$(UNAME_M)),)
CXXFLAGS += -mcpu=native
endif
ifneq ($(filter armv6%,$(UNAME_M)),)
# Raspberry Pi 1, 2, 3
CXXFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access
endif
ifneq ($(filter armv7%,$(UNAME_M)),)
# Raspberry Pi 4
CXXFLAGS += -mfpu=neon-fp-armv8 -mfp16-format=ieee -mno-unaligned-access -funsafe-math-optimizations
endif
ifneq ($(filter armv8%,$(UNAME_M)),)
# Raspberry Pi 4
CXXFLAGS += -mfp16-format=ieee -mno-unaligned-access
endif
ifeq ($(BUILD_TYPE),cublas)
CMAKE_ARGS+=-DGGML_CUBLAS=ON
endif
ifeq ($(BUILD_TYPE),openblas)
CMAKE_ARGS+=-DGGML_OPENBLAS=ON
CXXFLAGS += -I/usr/local/include/openblas -lopenblas
CGO_TAGS=-tags openblas
endif
ifeq ($(BUILD_TYPE),hipblas)
ROCM_HOME ?= "/opt/rocm"
CXX="$(ROCM_HOME)"/llvm/bin/clang++
CC="$(ROCM_HOME)"/llvm/bin/clang
GPU_TARGETS ?= gfx900,gfx90a,gfx1030,gfx1031,gfx1100
AMDGPU_TARGETS ?= "$(GPU_TARGETS)"
CMAKE_ARGS+=-DGGML_HIPBLAS=ON -DAMDGPU_TARGETS="$(AMDGPU_TARGETS)" -DGPU_TARGETS="$(GPU_TARGETS)"
GGML_CUDA_OBJ_PATH=CMakeFiles/ggml-rocm.dir/ggml-cuda.cu.o
endif
ifeq ($(BUILD_TYPE),clblas)
CMAKE_ARGS+=-DGGML_CLBLAST=ON
CGO_TAGS=-tags cublas
endif
ifdef CLBLAST_DIR
CMAKE_ARGS+=-DCLBlast_dir=$(CLBLAST_DIR)
endif
#
# Print build information
#
$(info I chatglm.cpp build info: )
$(info I UNAME_S: $(UNAME_S))
$(info I UNAME_P: $(UNAME_P))
$(info I UNAME_M: $(UNAME_M))
$(info I CXXFLAGS: $(CXXFLAGS))
$(info I BUILD_TYPE: $(BUILD_TYPE))
$(info I CMAKE_ARGS: $(CMAKE_ARGS))
$(info I EXTRA_TARGETS: $(EXTRA_TARGETS))
$(info I CC: $(CCV))
$(info I CXX: $(CXXV))
$(info I CGO_TAGS: $(CGO_TAGS))
$(info )
# Use this if you want to set the default behavior
prepare:
mkdir -p build && mkdir -p out
# build chatglm.cpp
build/chatglm.cpp: prepare
cd build && CC="$(CC)" CXX="$(CXX)" cmake $(CMAKE_ARGS) ../chatglm.cpp && VERBOSE=1 cmake --build . -j --config Release
chatglm.dir: build/chatglm.cpp
xcopy build\\lib\\Release\\*.lib out\\
# binding
binding.o: prepare build/chatglm.cpp chatglm.dir ggml.dir sentencepiece.dir protobuf-lite.dir absl.dir
$(CXX) $(CXXFLAGS) \
-I./chatglm.cpp \
-I./chatglm.cpp/third_party/ggml/include/ggml \
-I./chatglm.cpp/third_party/sentencepiece/src \
binding.cpp -MD -MT binding.lib -MF binding.d -o binding.lib -c
libbinding.a: prepare binding.o $(EXTRA_TARGETS)
lib.exe /OUT:libbinding.lib out/*.lib binding.lib
clean:
rm -rf *.o
rm -rf *.d
rm -rf *.a
rm -rf out
rm -rf build
ggllm-test-model.bin:
powershell -Command "Invoke-WebRequest -Uri 'https://huggingface.co/Xorbits/chatglm3-6B-GGML/resolve/main/chatglm3-ggml-q4_0.bin' -OutFile 'ggllm-test-model.bin'"
test: ggllm-test-model.bin libbinding.a
go test ${CGO_TAGS} -timeout 1800s -o go-chatglm.cpp.test -c -cover
TEST_MODEL=ggllm-test-model.bin ./go-chatglm.cpp.test
# build\lib\Release\chatglm.lib