Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

build.zig 4.6 KB

You have to be logged in to leave a comment. Sign In
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
  1. const std = @import("std");
  2. const builtin = @import("builtin");
  3. // Zig Version: 0.11.0
  4. // Zig Build Command: zig build
  5. // Zig Run Command: zig build -h
  6. // zig build run_dolly-v2
  7. // zig build run_gpt-2
  8. // zig build run_gpt-j
  9. // zig build run_gpt-neox
  10. // zig build run_mnist
  11. // zig build run_mpt
  12. // zig build run_replit
  13. // zig build run_starcoder
  14. // zig build run_test-grad0
  15. // zig build run_test-mul-mat0
  16. // zig build run_test-mul-mat2
  17. // zig build run_test-opt
  18. // zig build run_test-vec1
  19. // zig build run_test0
  20. // zig build run_test1
  21. // zig build run_test2
  22. // zig build run_test3
  23. // zig build run_zig_test0
  24. // zig build run_zig_test1
  25. // zig build run_zig_test2
  26. // zig build run_zig_test3
  27. pub fn build(b: *std.build.Builder) void {
  28. const target = b.standardTargetOptions(.{});
  29. const optimize = b.standardOptimizeOption(.{});
  30. const lib = b.addStaticLibrary(.{
  31. .name = "ggml",
  32. .target = target,
  33. .optimize = optimize,
  34. });
  35. lib.addIncludePath(.{ .path = "./include" });
  36. lib.addIncludePath(.{ .path = "./include/ggml" });
  37. lib.addCSourceFiles(&.{
  38. "src/ggml.c",
  39. }, &.{"-std=c11"});
  40. lib.linkLibC();
  41. lib.linkLibCpp();
  42. b.installArtifact(lib);
  43. // examples
  44. const examples = .{
  45. "dolly-v2",
  46. "gpt-2",
  47. "gpt-j",
  48. "gpt-neox",
  49. "mnist",
  50. "mpt",
  51. "replit",
  52. "starcoder",
  53. // "whisper",
  54. };
  55. inline for (examples) |name| {
  56. const exe = b.addExecutable(.{
  57. .name = name,
  58. .target = target,
  59. .optimize = optimize,
  60. });
  61. exe.addIncludePath(.{ .path = "./include" });
  62. exe.addIncludePath(.{ .path = "./include/ggml" });
  63. exe.addIncludePath(.{ .path = "./examples" });
  64. // exe.addIncludePath("./examples/whisper");
  65. exe.addCSourceFiles(&.{
  66. std.fmt.comptimePrint("examples/{s}/main.cpp", .{name}),
  67. "examples/common.cpp",
  68. "examples/common-ggml.cpp",
  69. // "examples/whisper/whisper.cpp",
  70. }, &.{"-std=c++11"});
  71. exe.linkLibrary(lib);
  72. b.installArtifact(exe);
  73. const run_cmd = b.addRunArtifact(exe);
  74. run_cmd.step.dependOn(b.getInstallStep());
  75. if (b.args) |args| run_cmd.addArgs(args);
  76. const run_step = b.step("run_" ++ name, "Run examples");
  77. run_step.dependOn(&run_cmd.step);
  78. }
  79. // tests
  80. const tests = if (builtin.target.cpu.arch == .x86_64) .{
  81. // "test-blas0",
  82. // "test-grad0",
  83. "test-mul-mat0",
  84. // "test-mul-mat1",
  85. "test-mul-mat2",
  86. // "test-opt",
  87. // "test-svd0",
  88. // "test-vec0",
  89. "test-vec1",
  90. // "test-vec2",
  91. "test0",
  92. "test1",
  93. "test2",
  94. "test3",
  95. } else .{
  96. // "test-blas0",
  97. // "test-grad0",
  98. "test-mul-mat0",
  99. // "test-mul-mat1",
  100. "test-mul-mat2",
  101. // "test-opt",
  102. // "test-svd0",
  103. // "test-vec0",
  104. // "test-vec1",
  105. // "test-vec2",
  106. "test0",
  107. "test1",
  108. "test2",
  109. "test3",
  110. };
  111. inline for (tests) |name| {
  112. const exe = b.addExecutable(.{
  113. .name = name,
  114. .target = target,
  115. .optimize = optimize,
  116. });
  117. exe.addIncludePath(.{ .path = "./include" });
  118. exe.addIncludePath(.{ .path = "./include/ggml" });
  119. exe.addCSourceFiles(&.{
  120. std.fmt.comptimePrint("tests/{s}.c", .{name}),
  121. }, &.{"-std=c11"});
  122. exe.linkLibrary(lib);
  123. b.installArtifact(exe);
  124. const run_cmd = b.addRunArtifact(exe);
  125. run_cmd.step.dependOn(b.getInstallStep());
  126. if (b.args) |args| run_cmd.addArgs(args);
  127. const run_step = b.step("run_" ++ name, "Run tests");
  128. run_step.dependOn(&run_cmd.step);
  129. }
  130. // zig_tests
  131. const zig_tests = .{
  132. "test0",
  133. "test1",
  134. "test2",
  135. "test3",
  136. };
  137. inline for (zig_tests) |name| {
  138. const exe = b.addExecutable(.{
  139. .name = name,
  140. .root_source_file = .{ .path = std.fmt.comptimePrint("tests/{s}.zig", .{name}) },
  141. .target = target,
  142. .optimize = optimize,
  143. });
  144. exe.addIncludePath(.{ .path = "./include" });
  145. exe.addIncludePath(.{ .path = "./include/ggml" });
  146. exe.linkLibrary(lib);
  147. b.installArtifact(exe);
  148. const run_cmd = b.addRunArtifact(exe);
  149. run_cmd.step.dependOn(b.getInstallStep());
  150. if (b.args) |args| run_cmd.addArgs(args);
  151. const run_step = b.step("run_zig_" ++ name, "Run zig_tests");
  152. run_step.dependOn(&run_cmd.step);
  153. }
  154. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...