Add examples demonstrating Buffer.from options, non‑blocking loading, and memory copy behavior.
This commit is contained in:
parent
bb2b77d7de
commit
da1fd2d9dc
@ -123,5 +123,5 @@ fn createRandomBuffer(allocator: std.mem.Allocator, platform: zml.Platform, shap
|
|||||||
|
|
||||||
var host_buffer = zml.HostBuffer.fromBytes(shape, data);
|
var host_buffer = zml.HostBuffer.fromBytes(shape, data);
|
||||||
errdefer host_buffer.deinit(allocator);
|
errdefer host_buffer.deinit(allocator);
|
||||||
return zml.Buffer.from(platform, host_buffer);
|
return zml.Buffer.from(platform, host_buffer, .{});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,7 +54,7 @@ pub fn asyncMain() !void {
|
|||||||
const host_buffer = entry.value_ptr.*;
|
const host_buffer = entry.value_ptr.*;
|
||||||
total_bytes += host_buffer.shape().byteSize();
|
total_bytes += host_buffer.shape().byteSize();
|
||||||
std.debug.print("Buffer: {s} ({any} / {any})\n", .{ entry.key_ptr.*, i + 1, buffer_store.buffers.count() });
|
std.debug.print("Buffer: {s} ({any} / {any})\n", .{ entry.key_ptr.*, i + 1, buffer_store.buffers.count() });
|
||||||
buffers[i] = try zml.Buffer.from(platform, host_buffer);
|
buffers[i] = try zml.Buffer.from(platform, host_buffer, .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
const stop = timer.read();
|
const stop = timer.read();
|
||||||
|
|||||||
@ -101,7 +101,7 @@ pub fn asyncMain() !void {
|
|||||||
const idx = rng.random().intRangeAtMost(u64, 0, 10000 - 1);
|
const idx = rng.random().intRangeAtMost(u64, 0, 10000 - 1);
|
||||||
var sample: [28 * 28]u8 align(16) = undefined;
|
var sample: [28 * 28]u8 align(16) = undefined;
|
||||||
_ = try dataset.pread(&sample, 16 + (idx * 28 * 28));
|
_ = try dataset.pread(&sample, 16 + (idx * 28 * 28));
|
||||||
var input = try zml.Buffer.from(platform, zml.HostBuffer.fromBytes(zml.Shape.init(.{ 28, 28 }, .u8), &sample));
|
var input = try zml.Buffer.from(platform, zml.HostBuffer.fromBytes(zml.Shape.init(.{ 28, 28 }, .u8), &sample), .{});
|
||||||
defer input.deinit();
|
defer input.deinit();
|
||||||
|
|
||||||
printDigit(sample);
|
printDigit(sample);
|
||||||
|
|||||||
@ -82,7 +82,7 @@ pub fn asyncMain() !void {
|
|||||||
// with a specific shape from an array.
|
// with a specific shape from an array.
|
||||||
// For situations where e.g. you have an [4]f16 array but need a .{2, 2} input shape.
|
// For situations where e.g. you have an [4]f16 array but need a .{2, 2} input shape.
|
||||||
var input = [4]f16{ 5.0, 5.0, 5.0, 5.0 };
|
var input = [4]f16{ 5.0, 5.0, 5.0, 5.0 };
|
||||||
var input_buffer = try zml.Buffer.from(platform, zml.HostBuffer.fromSlice(input_shape, &input));
|
var input_buffer = try zml.Buffer.from(platform, zml.HostBuffer.fromSlice(input_shape, &input), .{});
|
||||||
defer input_buffer.deinit();
|
defer input_buffer.deinit();
|
||||||
|
|
||||||
// call our executable module
|
// call our executable module
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user