build.zig 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. }