diff --git a/examples/mnist/build.zig b/examples/mnist/build.zig new file mode 100644 index 00000000..f53c8c08 --- /dev/null +++ b/examples/mnist/build.zig @@ -0,0 +1,45 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + // Note: setting -Dcuda on CLI fails cause zml_sandbox doesn't yet contains all CUDA deps. + const cuda = b.option(bool, "cuda", "Enable cuda (broken)") orelse false; + const zml_pkg = b.dependency("zml", .{ + .@"runtimes:cuda" = cuda, + .@"runtimes:cpu" = !cuda, + }); + const zml_sandbox = zml_pkg.namedWriteFiles("zml_sandbox"); + + const mnist = b.createModule(.{ + .root_source_file = b.path("mnist.zig"), + .target = target, + .optimize = optimize, + .imports = &.{ + .{ .name = "async", .module = zml_pkg.module("async") }, + .{ .name = "zml", .module = zml_pkg.module("zml") }, + }, + }); + + const exe = b.addExecutable(.{ .name = "mnist", .root_module = mnist }); + exe.addRPath(zml_sandbox.getDirectory()); + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); + { + const ggml = b.dependency("ggml", .{}); + const mnist_model = ggml.path("examples/mnist/models/mnist/mnist_model.state_dict"); + const mnist_data = ggml.path("examples/mnist/models/mnist/t10k-images.idx3-ubyte"); + + run_cmd.addFileArg(mnist_model); + run_cmd.addFileArg(mnist_data); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/examples/mnist/build.zig.zon b/examples/mnist/build.zig.zon new file mode 100644 index 00000000..a2dd4cc5 --- /dev/null +++ b/examples/mnist/build.zig.zon @@ -0,0 +1,25 @@ +.{ + .name = .mnist, + .version = "0.0.0", + + .fingerprint = 0x6805ab6e16b3f141, // Changing this has security and trust implications. + + .minimum_zig_version = "0.14.0", + .dependencies = .{ + .zml = .{ + .url = "git+https://github.com/zml/zml#e6ec751e6e478c64113169c28aaed278d6ce13e9", + .hash = "zml-0.0.0-N9uPKHO8IgABeyC0QM0tqVA4wyL4lVr8vwCvGEQgrDqU", + }, + // Get MNIST model and data from GGML repo. + .ggml = .{ + .url = "git+https://github.com/ggerganov/ggml#18703ad600cc68dbdb04d57434c876989a841d12", + .hash = "N-V-__8AAGUBBAESVQ00NaQbKKLu9KDR54aQyFBxUmYvJLF4", + }, + }, + + .paths = .{ + "build.zig", + "build.zig.zon", + "mnist.zig", + }, +}