From 726a2d0691d3c70d4601ce8224ffce5ab7fd0413 Mon Sep 17 00:00:00 2001 From: Foke Singh Date: Thu, 3 Aug 2023 11:35:24 +0000 Subject: [PATCH] =?UTF-8?q?Update=20docs=20and=20examples=20to=20showcase?= =?UTF-8?q?=20the=20new=20async=20runtime=20with=20coroutines=20and=20cros?= =?UTF-8?q?s=E2=80=91thread=20signaling.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tutorials/write_first_model.md | 10 +++++----- examples/benchmark/main.zig | 2 +- examples/llama/main.zig | 4 ++-- examples/mnist/mnist.zig | 12 ++++++------ examples/simple_layer/main.zig | 2 +- examples/zls.build.json | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/tutorials/write_first_model.md b/docs/tutorials/write_first_model.md index ba3998d..39cecc2 100644 --- a/docs/tutorials/write_first_model.md +++ b/docs/tutorials/write_first_model.md @@ -101,7 +101,7 @@ const std = @import("std"); const zml = @import("zml"); const asynk = @import("async"); -// shortcut to the async_ function in the asynk module +// shortcut to the asyncc function in the asynk module const asyncc = asynk.asyncc; ``` @@ -263,11 +263,11 @@ var model_weights = try zml.aio.loadBuffers(Layer, .{}, bs, arena, platform); defer zml.aio.unloadBuffers(&model_weights); // for good practice // Wait for compilation to finish -const compiled = try compilation.await_(); +const compiled = try compilation.awaitt(); ``` -Compiling is happening in the background via the `async_` function. We call -`async_` with the `zml.compileModel` function and its arguments +Compiling is happening in the background via the `asyncc` function. We call +`asyncc` with the `zml.compileModel` function and its arguments separately. The arguments themselves are basically the shapes of the weights in the BufferStore, the `.forward` function name in order to compile `Layer.forward`, the shape of the input tensor(s), and the platform for which to @@ -494,7 +494,7 @@ pub fn asyncMain() !void { defer zml.aio.unloadBuffers(&model_weights); // for good practice // Wait for compilation to finish - const compiled = try compilation.await_(); + const compiled = try compilation.awaitt(); // pass the model weights to the compiled module to create an executable // module diff --git a/examples/benchmark/main.zig b/examples/benchmark/main.zig index 011c604..ee032fc 100644 --- a/examples/benchmark/main.zig +++ b/examples/benchmark/main.zig @@ -63,7 +63,7 @@ pub fn asyncMain() !void { var compilation = try asynk.asyncc(zml.module.compileModel, .{ allocator, Benchmark.forward, Benchmark{}, .{ a_shape, b_shape }, platform }); // Wait for compilation to finish - const compiled = try compilation.await_(); + const compiled = try compilation.awaitt(); const compilation_elapsed = timer.lap() / std.time.ns_per_ms; std.debug.print("-" ** 160 ++ "\n\n", .{}); std.debug.print("✅ Compiled Benchmark model in {d} milliseconds! \n", .{compilation_elapsed}); diff --git a/examples/llama/main.zig b/examples/llama/main.zig index c3ffa0d..1eda838 100644 --- a/examples/llama/main.zig +++ b/examples/llama/main.zig @@ -217,9 +217,9 @@ pub fn asyncMain() !void { defer zml.aio.unloadBuffers(&llama_weights); log.info("✅\tLoaded weights in {d}ms", .{start.read() / std.time.ns_per_ms}); - var llama_module_prefill = try (try fut_mod_prefill.await_()).prepare(allocator, llama_weights); + var llama_module_prefill = try (try fut_mod_prefill.awaitt()).prepare(allocator, llama_weights); defer llama_module_prefill.deinit(); - var llama_module = try (try fut_mod.await_()).prepare(allocator, llama_weights); + var llama_module = try (try fut_mod.awaitt()).prepare(allocator, llama_weights); defer llama_module.deinit(); log.info("✅\tCompiled model in {d}ms", .{start.read() / std.time.ns_per_ms}); diff --git a/examples/mnist/mnist.zig b/examples/mnist/mnist.zig index 5b7b9b2..f15a86e 100644 --- a/examples/mnist/mnist.zig +++ b/examples/mnist/mnist.zig @@ -6,6 +6,11 @@ const show_mlir = true; const log = std.log.scoped(.mnist); +pub const std_options: std.Options = .{ + .logFn = asynk.logFn, + .log_level = .info, +}; + /// Model definition const Mnist = struct { fc1: Layer, @@ -78,7 +83,7 @@ pub fn asyncMain() !void { defer zml.aio.unloadBuffers(&model_weights); // Wait for end of compilation and end of weights loading. - const compiled_mnist = try compilation.wait(); + const compiled_mnist = try compilation.awaitt(); log.info("✅ Compiled model in {d}ms", .{start_time.read() / std.time.ns_per_ms}); var mnist = try compiled_mnist.prepare(allocator, model_weights); @@ -222,8 +227,3 @@ const digits = [_][]const u8{ \\ | ##### | , }; - -pub const std_options = .{ - .logFn = asynk.logFn, - .log_level = .info, -}; diff --git a/examples/simple_layer/main.zig b/examples/simple_layer/main.zig index 4cc3b97..ec88aaf 100644 --- a/examples/simple_layer/main.zig +++ b/examples/simple_layer/main.zig @@ -71,7 +71,7 @@ pub fn asyncMain() !void { defer zml.aio.unloadBuffers(&model_weights); // for good practice // Wait for compilation to finish - const compiled = try compilation.await_(); + const compiled = try compilation.awaitt(); // pass the model weights to the compiled module to create an executable module var executable = try compiled.prepare(arena, model_weights); diff --git a/examples/zls.build.json b/examples/zls.build.json index a426832..796644a 100644 --- a/examples/zls.build.json +++ b/examples/zls.build.json @@ -2,7 +2,7 @@ "build_options": [ { "name": "cmd", - "value": "bazel run @zml//zml:completion" + "value": "bazel run @zml//:completion" } ] }