Port to Visual C++.
- Combined nmake/Unix Makefile. - _alloca instead of variable size array. - Cast void* to char* for math. - C++20 for designated initializers. It builds. I haven't run it yet.
This commit is contained in:
parent
da1a4ff01f
commit
636d56818a
4 changed files with 81 additions and 25 deletions
69
Makefile
69
Makefile
|
@ -1,3 +1,47 @@
|
||||||
|
# This one Makefile works with Microsoft nmake and Unix make.
|
||||||
|
# They use different conditional syntax, but each can be nested and inverted within the other.
|
||||||
|
|
||||||
|
all: default
|
||||||
|
|
||||||
|
ifdef MAKEDIR:
|
||||||
|
!ifdef MAKEDIR
|
||||||
|
|
||||||
|
# Windows code.
|
||||||
|
|
||||||
|
CXX = cl
|
||||||
|
# C++20 for designated initializers
|
||||||
|
# TODO: Detect AVX.
|
||||||
|
CXXFLAGS = /MD /Gy /Z7 /EHsc /O2 /arch:AVX2 /std:c++20
|
||||||
|
CC = $(CXX)
|
||||||
|
CFLAGS = $(CXXFLAGS)
|
||||||
|
LDFLAGS=/incremental:no
|
||||||
|
LINK_OUT = /out:
|
||||||
|
CC_OUT = /Fo
|
||||||
|
O = obj
|
||||||
|
EXE = .exe
|
||||||
|
RM_F = del 2>nul /f
|
||||||
|
UNIX_SPACE =
|
||||||
|
START_LINK_FLAGS = /link
|
||||||
|
|
||||||
|
# The need for this is surprising but otherwise there is an access violation
|
||||||
|
# running main -h.
|
||||||
|
SLASH=^\
|
||||||
|
|
||||||
|
!else
|
||||||
|
else
|
||||||
|
|
||||||
|
# Unix code.
|
||||||
|
|
||||||
|
O = o
|
||||||
|
EXE=
|
||||||
|
UNIX_SPACE = " "
|
||||||
|
UNIX_SPACE := $(UNIX_SPACE:"=)
|
||||||
|
LINK_OUT = -o$(UNIX_SPACE)
|
||||||
|
CC_OUT=-o$(UNIX_SPACE)
|
||||||
|
RM_F = rm -f
|
||||||
|
START_LINK_FLAGS=
|
||||||
|
SLASH=/
|
||||||
|
|
||||||
ifndef UNAME_S
|
ifndef UNAME_S
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
endif
|
endif
|
||||||
|
@ -172,27 +216,30 @@ $(info I CC: $(CCV))
|
||||||
$(info I CXX: $(CXXV))
|
$(info I CXX: $(CXXV))
|
||||||
$(info )
|
$(info )
|
||||||
|
|
||||||
default: main quantize
|
endif
|
||||||
|
!endif :
|
||||||
|
|
||||||
|
default: main$(EXE) quantize$(EXE)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Build library
|
# Build library
|
||||||
#
|
#
|
||||||
|
|
||||||
ggml.o: ggml.c ggml.h
|
ggml.$O: ggml.c ggml.h
|
||||||
$(CC) $(CFLAGS) -c ggml.c -o ggml.o
|
$(CC) $(CFLAGS) -c ggml.c $(CC_OUT)ggml.$O
|
||||||
|
|
||||||
utils.o: utils.cpp utils.h
|
utils.$O: utils.cpp utils.h
|
||||||
$(CXX) $(CXXFLAGS) -c utils.cpp -o utils.o
|
$(CXX) $(CXXFLAGS) -c utils.cpp $(CC_OUT)utils.$O
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o main quantize
|
$(RM_F) *.$O main$(EXE) quantize$(EXE)
|
||||||
|
|
||||||
main: main.cpp ggml.o utils.o
|
main$(EXE): main.cpp ggml.$O utils.$O
|
||||||
$(CXX) $(CXXFLAGS) main.cpp ggml.o utils.o -o main $(LDFLAGS)
|
$(CXX) $(CXXFLAGS) main.cpp $(START_LINK_FLAGS) ggml.$O utils.$O $(LINK_OUT)main$(EXE) $(LDFLAGS)
|
||||||
./main -h
|
.$(SLASH)main.exe -h
|
||||||
|
|
||||||
quantize: quantize.cpp ggml.o utils.o
|
quantize$(EXE): quantize.cpp ggml.$O utils.$O
|
||||||
$(CXX) $(CXXFLAGS) quantize.cpp ggml.o utils.o -o quantize $(LDFLAGS)
|
$(CXX) $(CXXFLAGS) quantize.cpp $(START_LINK_FLAGS) ggml.$O utils.$O $(LINK_OUT)quantize$(EXE) $(LDFLAGS)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Tests
|
# Tests
|
||||||
|
|
20
ggml.c
20
ggml.c
|
@ -407,8 +407,8 @@ void quantize_row_q4_0(const float * restrict x, void * restrict y, int k) {
|
||||||
const int nb = k / QK;
|
const int nb = k / QK;
|
||||||
const size_t bs = sizeof(float) + QK/2;
|
const size_t bs = sizeof(float) + QK/2;
|
||||||
|
|
||||||
uint8_t * restrict pd = (uint8_t *) (y + 0*bs);
|
uint8_t * restrict pd = (uint8_t *) ((char*)y + 0*bs);
|
||||||
uint8_t * restrict pb = (uint8_t *) (y + 0*bs + sizeof(float));
|
uint8_t * restrict pb = (uint8_t *) ((char*)y + 0*bs + sizeof(float));
|
||||||
|
|
||||||
uint8_t pp[QK/2];
|
uint8_t pp[QK/2];
|
||||||
|
|
||||||
|
@ -654,8 +654,8 @@ void dequantize_row_q4_0(const void * restrict x, float * restrict y, int k) {
|
||||||
const int nb = k / QK;
|
const int nb = k / QK;
|
||||||
const size_t bs = sizeof(float) + QK/2;
|
const size_t bs = sizeof(float) + QK/2;
|
||||||
|
|
||||||
const uint8_t * restrict pd = (const uint8_t *) (x + 0*bs);
|
const uint8_t * restrict pd = (const uint8_t *) ((char*)x + 0*bs);
|
||||||
const uint8_t * restrict pb = (const uint8_t *) (x + 0*bs + sizeof(float));
|
const uint8_t * restrict pb = (const uint8_t *) ((char*)x + 0*bs + sizeof(float));
|
||||||
|
|
||||||
// scalar
|
// scalar
|
||||||
for (int i = 0; i < nb; i++) {
|
for (int i = 0; i < nb; i++) {
|
||||||
|
@ -1301,11 +1301,11 @@ inline static void ggml_vec_dot_q4_0(const int n, float * restrict s, const void
|
||||||
|
|
||||||
const size_t bs = sizeof(float) + QK/2;
|
const size_t bs = sizeof(float) + QK/2;
|
||||||
|
|
||||||
const uint8_t * restrict pd0 = (const uint8_t *) (x + 0*bs);
|
const uint8_t * restrict pd0 = (const uint8_t *) ((char*)x + 0*bs);
|
||||||
const uint8_t * restrict pd1 = (const uint8_t *) (y + 0*bs);
|
const uint8_t * restrict pd1 = (const uint8_t *) ((char*)y + 0*bs);
|
||||||
|
|
||||||
const uint8_t * restrict pb0 = (const uint8_t *) (x + 0*bs + sizeof(float));
|
const uint8_t * restrict pb0 = (const uint8_t *) ((char*)x + 0*bs + sizeof(float));
|
||||||
const uint8_t * restrict pb1 = (const uint8_t *) (y + 0*bs + sizeof(float));
|
const uint8_t * restrict pb1 = (const uint8_t *) ((char*)y + 0*bs + sizeof(float));
|
||||||
|
|
||||||
float sumf = 0.0;
|
float sumf = 0.0;
|
||||||
|
|
||||||
|
@ -1731,8 +1731,8 @@ inline static void ggml_vec_mad_q4_0(const int n, float * restrict y, void * res
|
||||||
const int nb = n / QK;
|
const int nb = n / QK;
|
||||||
const size_t bs = sizeof(float) + QK/2;
|
const size_t bs = sizeof(float) + QK/2;
|
||||||
|
|
||||||
const uint8_t * restrict pd = (const uint8_t *) (x + 0*bs);
|
const uint8_t * restrict pd = (const uint8_t *) ((char*)x + 0*bs);
|
||||||
const uint8_t * restrict pb = (const uint8_t *) (x + 0*bs + sizeof(float));
|
const uint8_t * restrict pb = (const uint8_t *) ((char*)x + 0*bs + sizeof(float));
|
||||||
|
|
||||||
#if __ARM_NEON
|
#if __ARM_NEON
|
||||||
#if QK == 32
|
#if QK == 32
|
||||||
|
|
1
main.cpp
1
main.cpp
|
@ -733,6 +733,7 @@ bool llama_eval(
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
|
ggml_time_init();
|
||||||
const int64_t t_main_start_us = ggml_time_us();
|
const int64_t t_main_start_us = ggml_time_us();
|
||||||
|
|
||||||
gpt_params params;
|
gpt_params params;
|
||||||
|
|
|
@ -453,7 +453,11 @@ size_t ggml_quantize_q4_0(float * src, void * dst, int n, int k, int qk, int64_t
|
||||||
|
|
||||||
assert(k % qk == 0);
|
assert(k % qk == 0);
|
||||||
|
|
||||||
|
#if _MSC_VER
|
||||||
|
uint8_t* pp = (uint8_t*)_alloca(qk / 2);
|
||||||
|
#else
|
||||||
uint8_t pp[qk/2];
|
uint8_t pp[qk/2];
|
||||||
|
#endif
|
||||||
|
|
||||||
char * pdst = (char *) dst;
|
char * pdst = (char *) dst;
|
||||||
|
|
||||||
|
@ -507,7 +511,11 @@ size_t ggml_quantize_q4_1(float * src, void * dst, int n, int k, int qk, int64_t
|
||||||
|
|
||||||
assert(k % qk == 0);
|
assert(k % qk == 0);
|
||||||
|
|
||||||
|
#if _MSC_VER
|
||||||
|
uint8_t* pp = (uint8_t*)_alloca(qk / 2);
|
||||||
|
#else
|
||||||
uint8_t pp[qk/2];
|
uint8_t pp[qk/2];
|
||||||
|
#endif
|
||||||
|
|
||||||
char * pdst = (char *) dst;
|
char * pdst = (char *) dst;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue