Skip to content

Commit 75fa13a

Browse files
author
Daniele Briggi
committed
feat(windows-cuda): make CUDA for Windows
1 parent 82e79e9 commit 75fa13a

File tree

2 files changed

+61
-52
lines changed

2 files changed

+61
-52
lines changed

.github/workflows/main.yml

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,34 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
include:
18-
- name: linux-vulkan
19-
os: ubuntu-latest
20-
arch: x86_64
21-
make: LLAMA="-DGGML_BACKEND_DL=ON -DGGML_NATIVE=OFF -DGGML_CPU_ALL_VARIANTS=ON -DGGML_VULKAN=ON"
22-
- name: macos
23-
os: macos-latest
24-
- name: windows
18+
# - name: linux-vulkan
19+
# os: ubuntu-latest
20+
# arch: x86_64
21+
# make: LLAMA="-DGGML_BACKEND_DL=ON -DGGML_NATIVE=OFF -DGGML_CPU_ALL_VARIANTS=ON -DGGML_VULKAN=ON"
22+
# - name: macos
23+
# os: macos-latest
24+
# - name: windows
25+
# os: windows-latest
26+
# arch: x86_64
27+
- name: windows-cuda
2528
os: windows-latest
2629
arch: x86_64
27-
- name: android
28-
os: ubuntu-latest
29-
arch: arm64-v8a
30-
make: PLATFORM=android ARCH=arm64-v8a
31-
- name: android
32-
os: ubuntu-latest
33-
arch: x86_64
34-
make: PLATFORM=android ARCH=x86_64
35-
sqlite-amalgamation-zip: https://sqlite.org/2025/sqlite-amalgamation-3490100.zip
36-
- name: ios
37-
os: macos-latest
38-
make: PLATFORM=ios
39-
- name: isim
40-
os: macos-latest
41-
make: PLATFORM=isim
30+
make: LLAMA="-DGGML_BACKEND_DL=ON -DGGML_NATIVE=OFF -DGGML_CPU=OFF -DGGML_CUDA=ON"
31+
# - name: android
32+
# os: ubuntu-latest
33+
# arch: arm64-v8a
34+
# make: PLATFORM=android ARCH=arm64-v8a
35+
# - name: android
36+
# os: ubuntu-latest
37+
# arch: x86_64
38+
# make: PLATFORM=android ARCH=x86_64
39+
# sqlite-amalgamation-zip: https://sqlite.org/2025/sqlite-amalgamation-3490100.zip
40+
# - name: ios
41+
# os: macos-latest
42+
# make: PLATFORM=ios
43+
# - name: isim
44+
# os: macos-latest
45+
# make: PLATFORM=isim
4246

4347
defaults:
4448
run:
@@ -50,15 +54,6 @@ jobs:
5054
with:
5155
submodules: true
5256

53-
- uses: msys2/[email protected]
54-
if: matrix.os == 'windows-latest'
55-
with:
56-
msystem: mingw64
57-
install: >-
58-
mingw-w64-x86_64-cc
59-
mingw-w64-x86_64-cmake
60-
make
61-
6257
- name: linux install dependencies
6358
if: matrix.name == 'linux-vulkan'
6459
run: |
@@ -82,17 +77,20 @@ jobs:
8277
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $GITHUB_ENV
8378
echo "VK_ADD_LAYER_PATH=$VK_ADD_LAYER_PATH" >> $GITHUB_ENV
8479
85-
- name: windows install dependencies
86-
if: matrix.os == 'windows-latest'
80+
81+
- name: Install CUDA Toolkit
82+
if: matrix.name == 'windows-cuda'
8783
run: |
88-
pacman -S --noconfirm git sqlite3
89-
shell: msys2 {0}
84+
choco install cuda -y
85+
shell: powershell
9086

91-
- name: windows build sqlite-ai
92-
if: matrix.name == 'windows'
93-
run: make extension ${{ matrix.make && matrix.make || ''}}
94-
shell: msys2 {0}
95-
87+
- name: Windows build sqlite-ai
88+
if: matrix.os == 'windows-latest' || matrix.name == 'windows-cuda'
89+
run: |
90+
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
91+
nmake /f Makefile PLATFORM=windows ${{ matrix.make && matrix.make || ''}}
92+
shell: cmd
93+
9694
- name: build sqlite-ai
9795
if: matrix.name != 'windows'
9896
run: make extension ${{ matrix.make && matrix.make || ''}}
@@ -143,10 +141,13 @@ jobs:
143141
adb push ${{ github.workspace }}/. /data/local/tmp/
144142
adb shell "sh /data/local/tmp/commands.sh"
145143
144+
146145
- name: windows test sqlite-ai
147-
if: matrix.name == 'windows'
148-
run: make test
149-
shell: msys2 {0}
146+
if: matrix.os == 'windows-latest'
147+
run: |
148+
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
149+
nmake /f Makefile test PLATFORM=windows
150+
shell: cmd
150151

151152
- name: test sqlite-ai
152153
if: matrix.name == 'linux' || matrix.name == 'macos'

Makefile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ BUILD_LLAMA = $(BUILD_DIR)/llama.cpp
3636
BUILD_WHISPER = $(BUILD_DIR)/whisper.cpp
3737
BUILD_MINIAUDIO = $(BUILD_DIR)/miniaudio
3838

39+
OBJ_EXT = o
3940
# Compiler and flags
4041
CC = gcc
4142
CXX = g++
@@ -53,18 +54,21 @@ LDFLAGS = $(LLAMA_LDFLAGS) $(WHISPER_LDFLAGS) $(MINIAUDIO_LDFLAGS)
5354

5455
# Files
5556
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
56-
OBJ_FILES = $(patsubst %.c, $(BUILD_DIR)/%.o, $(notdir $(SRC_FILES)))
57+
OBJ_FILES = $(patsubst %.c, $(BUILD_DIR)/%.$(OBJ_EXT), $(notdir $(SRC_FILES)))
5758
LLAMA_LIBS = $(BUILD_LLAMA)/common/libcommon.a $(BUILD_LLAMA)/ggml/src/libggml.a $(BUILD_LLAMA)/ggml/src/libggml-base.a $(BUILD_LLAMA)/ggml/src/libggml-cpu.a $(BUILD_LLAMA)/src/libllama.a
5859
WHISPER_LIBS = $(BUILD_WHISPER)/src/libwhisper.a
5960
MINIAUDIO_LIBS = $(BUILD_MINIAUDIO)/libminiaudio.a
6061

6162
# Platform-specific settings
6263
ifeq ($(PLATFORM),windows)
64+
OBJ_EXT = obj
65+
CC = cl
66+
CXX = cl
6367
TARGET := $(DIST_DIR)/ai.dll
64-
LDFLAGS = -L./$(BUILD_LLAMA)/common -L./$(BUILD_LLAMA)/ggml/src -L./$(BUILD_LLAMA)/src -L./$(BUILD_WHISPER)/src -L./$(BUILD_MINIAUDIO) -l:libllama.a -l:libwhisper.a -l:libminiaudio.a -l:libcommon.a -l:ggml.a -l:ggml-cpu.a -l:ggml-base.a -fopenmp -static-libgcc -static-libstdc++ -shared -lbcrypt
65-
# Create .def file for Windows
68+
CFLAGS = /nologo /W3 /EHsc /I$(SRC_DIR) /I$(LLAMA_DIR)/ggml/include /I$(LLAMA_DIR)/include /I$(WHISPER_DIR)/include /I$(MINIAUDIO_DIR) /MD
69+
LDFLAGS = /DLL /OUT:$(TARGET) /LIBPATH:$(BUILD_LLAMA)/common /LIBPATH:$(BUILD_LLAMA)/ggml/src /LIBPATH:$(BUILD_LLAMA)/src /LIBPATH:$(BUILD_WHISPER)/src /LIBPATH:$(BUILD_MINIAUDIO) common.lib ggml.lib ggml-cpu.lib ggml-base.lib llama.lib whisper.lib miniaudio.lib bcrypt.lib
6670
DEF_FILE := $(BUILD_DIR)/ai.def
67-
STRIP = strip --strip-unneeded $@
71+
STRIP = echo "No strip needed for MSVC"
6872
else ifeq ($(PLATFORM),macos)
6973
TARGET := $(DIST_DIR)/ai.dylib
7074
LLAMA_LIBS += $(BUILD_LLAMA)/ggml/src/ggml-metal/libggml-metal.a $(BUILD_LLAMA)/ggml/src/ggml-blas/libggml-blas.a
@@ -128,7 +132,7 @@ else ifeq ($(PLATFORM),isim)
128132
WHISPER_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DWHISPER_COREML=ON
129133
else # linux
130134
TARGET := $(DIST_DIR)/ai.so
131-
# using -DGGML_CPU_ALL_VARIANTS=ON
135+
# Using -DGGML_CPU_ALL_VARIANTS=ON, `-lggml-cpu` is not needed
132136
LDFLAGS := $(filter-out -lggml-cpu,$(LDFLAGS))
133137
LDFLAGS += -shared -L./$(BUILD_LLAMA)/bin -Wl,-rpath,./$(BUILD_LLAMA)/bin -Wl,-rpath,./$(BUILD_LLAMA)/common -Wl,-rpath,./$(BUILD_LLAMA)/ggml/src -Wl,-rpath,./$(BUILD_LLAMA)/src -Wl,-rpath,./$(BUILD_WHISPER)/src
134138
# Add miniaudio Linux-specific flags (as per miniaudio docs)
@@ -158,17 +162,21 @@ compile: $(OBJ_FILES)
158162

159163
# Loadable library
160164
$(TARGET): $(DEF_FILE) $(LLAMA_LIBS) $(WHISPER_LIBS) $(MINIAUDIO_LIBS)
161-
$(CXX) $(OBJ_FILES) $(DEF_FILE) -o $@ $(LDFLAGS)
162165
ifeq ($(PLATFORM),windows)
163-
# Generate import library for Windows
164-
dlltool -D $@ -d $(DEF_FILE) -l $(DIST_DIR)/ai.lib
166+
$(CXX) $(OBJ_FILES) /link $(LDFLAGS)
167+
else
168+
$(CXX) $(OBJ_FILES) $(DEF_FILE) -o $@ $(LDFLAGS)
165169
endif
166-
# Strip debug symbols
167170
$(STRIP)
168171

169172
# Object files
173+
ifeq ($(PLATFORM),windows)
174+
$(BUILD_DIR)/%.obj: %.c
175+
$(CC) $(CFLAGS) /c $< /Fo$@
176+
else
170177
$(BUILD_DIR)/%.o: %.c
171178
$(CC) $(CFLAGS) -O3 -fPIC -c $< -o $@
179+
endif
172180

173181
test: $(TARGET)
174182
$(SQLITE3) ":memory:" -cmd ".bail on" ".load ./dist/ai" "SELECT ai_version();"

0 commit comments

Comments
 (0)