forked from ggerganov/ggml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
158 lines (154 loc) · 4.65 KB
/
build.zig
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const std = @import("std");
const builtin = @import("builtin");
// Zig Version: 0.11.0
// Zig Build Command: zig build
// Zig Run Command: zig build -h
// zig build run_dolly-v2
// zig build run_gpt-2
// zig build run_gpt-j
// zig build run_gpt-neox
// zig build run_mnist
// zig build run_mpt
// zig build run_replit
// zig build run_starcoder
// zig build run_test-grad0
// zig build run_test-mul-mat0
// zig build run_test-mul-mat2
// zig build run_test-opt
// zig build run_test-vec1
// zig build run_test0
// zig build run_test1
// zig build run_test2
// zig build run_test3
// zig build run_zig_test0
// zig build run_zig_test1
// zig build run_zig_test2
// zig build run_zig_test3
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "ggml",
.target = target,
.optimize = optimize,
});
lib.addIncludePath(.{ .path = "./include" });
lib.addIncludePath(.{ .path = "./include/ggml" });
lib.addCSourceFiles(&.{
"src/ggml.c",
}, &.{"-std=c11"});
lib.linkLibC();
lib.linkLibCpp();
b.installArtifact(lib);
// examples
const examples = .{
"dolly-v2",
"gpt-2",
"gpt-j",
"gpt-neox",
"mnist",
"mpt",
"replit",
"starcoder",
// "whisper",
};
inline for (examples) |name| {
const exe = b.addExecutable(.{
.name = name,
.target = target,
.optimize = optimize,
});
exe.addIncludePath(.{ .path = "./include" });
exe.addIncludePath(.{ .path = "./include/ggml" });
exe.addIncludePath(.{ .path = "./examples" });
// exe.addIncludePath("./examples/whisper");
exe.addCSourceFiles(&.{
std.fmt.comptimePrint("examples/{s}/main.cpp", .{name}),
"examples/common.cpp",
"examples/common-ggml.cpp",
// "examples/whisper/whisper.cpp",
}, &.{"-std=c++11"});
exe.linkLibrary(lib);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run_" ++ name, "Run examples");
run_step.dependOn(&run_cmd.step);
}
// tests
const tests = if (builtin.target.cpu.arch == .x86_64) .{
// "test-blas0",
// "test-grad0",
"test-mul-mat0",
// "test-mul-mat1",
"test-mul-mat2",
// "test-opt",
// "test-svd0",
// "test-vec0",
"test-vec1",
// "test-vec2",
"test0",
"test1",
"test2",
"test3",
} else .{
// "test-blas0",
// "test-grad0",
"test-mul-mat0",
// "test-mul-mat1",
"test-mul-mat2",
// "test-opt",
// "test-svd0",
// "test-vec0",
// "test-vec1",
// "test-vec2",
"test0",
"test1",
"test2",
"test3",
};
inline for (tests) |name| {
const exe = b.addExecutable(.{
.name = name,
.target = target,
.optimize = optimize,
});
exe.addIncludePath(.{ .path = "./include" });
exe.addIncludePath(.{ .path = "./include/ggml" });
exe.addCSourceFiles(&.{
std.fmt.comptimePrint("tests/{s}.c", .{name}),
}, &.{"-std=c11"});
exe.linkLibrary(lib);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run_" ++ name, "Run tests");
run_step.dependOn(&run_cmd.step);
}
// zig_tests
const zig_tests = .{
"test0",
"test1",
"test2",
"test3",
};
inline for (zig_tests) |name| {
const exe = b.addExecutable(.{
.name = name,
.root_source_file = .{ .path = std.fmt.comptimePrint("tests/{s}.zig", .{name}) },
.target = target,
.optimize = optimize,
});
exe.addIncludePath(.{ .path = "./include" });
exe.addIncludePath(.{ .path = "./include/ggml" });
exe.linkLibrary(lib);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run_zig_" ++ name, "Run zig_tests");
run_step.dependOn(&run_cmd.step);
}
}