Skip to content

Commit 4ea3d11

Browse files
committed
update
1 parent 0d418ec commit 4ea3d11

File tree

4 files changed

+551
-173
lines changed

4 files changed

+551
-173
lines changed

build.zig

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,57 @@
11
const std = @import("std");
22

3-
// Zig Version: 0.11.0-dev.3798+a5e15eced
4-
// Zig Build Command: zig build
5-
// Zig Run Command: zig build -h
6-
// zig build run_test0_zig
7-
// zig build run_test1_zig
3+
// // Zig Version: 0.11.0-dev.3798+a5e15eced
4+
// // Zig Build Command: zig build
5+
// // Zig Run Command: zig build -h
6+
// // zig build run_zig_test0
7+
// // zig build run_zig_test1
88
pub fn build(b: *std.Build) void {
9+
// // Standard target options allows the person running `zig build` to choose
10+
// // what target to build for. Here we do not override the defaults, which
11+
// // means any target is allowed, and the default is native. Other options
12+
// // for restricting supported target set are available.
913
const target = b.standardTargetOptions(.{});
14+
15+
// // Standard optimization options allow the person running `zig build` to select
16+
// // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
17+
// // set a preferred release mode, allowing the user to decide how to optimize.
1018
const optimize = b.standardOptimizeOption(.{});
19+
// const optimize = .ReleaseFast;
20+
// const optimize = .ReleaseSmall;
21+
22+
// zig_examples
23+
const zig_examples = .{
24+
25+
};
26+
inline for (zig_examples) |name| {
27+
const exe = b.addExecutable(.{
28+
.name = name,
29+
.root_source_file = .{ .path = std.fmt.comptimePrint("examples/{s}/main.zig", .{name}) },
30+
.target = target,
31+
.optimize = optimize,
32+
});
33+
exe.addIncludePath("./thirdparty/ggml/include");
34+
exe.addIncludePath("./thirdparty/ggml/include/ggml");
35+
exe.addCSourceFiles(&.{
36+
"./thirdparty/ggml/src/ggml.c",
37+
}, &.{"-std=c11"});
38+
exe.linkLibC();
39+
b.installArtifact(exe);
40+
const run_cmd = b.addRunArtifact(exe);
41+
// // This allows the user to pass arguments to the application in the build
42+
// // command itself, like this: `zig build run -- arg1 arg2 etc`
43+
run_cmd.step.dependOn(b.getInstallStep());
44+
if (b.args) |args| run_cmd.addArgs(args);
45+
const run_step = b.step("run_zig_" ++ name, "Run zig_examples");
46+
run_step.dependOn(&run_cmd.step);
47+
}
1148

12-
// tests_zig
13-
const tests_zig = .{
49+
// zig_tests
50+
const zig_tests = .{
1451
"test0",
1552
"test1",
1653
};
17-
inline for (tests_zig) |name| {
54+
inline for (zig_tests) |name| {
1855
const exe = b.addExecutable(.{
1956
.name = name,
2057
.root_source_file = .{ .path = std.fmt.comptimePrint("tests/{s}.zig", .{name}) },
@@ -29,9 +66,11 @@ pub fn build(b: *std.Build) void {
2966
exe.linkLibC();
3067
b.installArtifact(exe);
3168
const run_cmd = b.addRunArtifact(exe);
69+
// // This allows the user to pass arguments to the application in the build
70+
// // command itself, like this: `zig build run -- arg1 arg2 etc`
3271
run_cmd.step.dependOn(b.getInstallStep());
3372
if (b.args) |args| run_cmd.addArgs(args);
34-
const run_step = b.step("run_" ++ name ++ "_zig", "Run tests_zig");
73+
const run_step = b.step("run_zig_" ++ name, "Run zig_tests");
3574
run_step.dependOn(&run_cmd.step);
3675
}
3776
}

tests/test0.zig

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
const std = @import("std");
2-
const c = @cImport({
3-
@cInclude("ggml/ggml.h");
4-
@cInclude("stdio.h");
5-
@cInclude("stdlib.h");
6-
});
7-
8-
pub fn main() !void {
9-
const params: c.ggml_init_params = .{
10-
.mem_size = 128*1024*1024,
11-
.mem_buffer = null,
12-
.no_alloc = false,
13-
};
14-
15-
const ctx0 = c.ggml_init(params);
16-
defer c.ggml_free(ctx0);
17-
18-
const t1 = c.ggml_new_tensor_1d(ctx0, c.GGML_TYPE_F32, 10);
19-
const t2 = c.ggml_new_tensor_2d(ctx0, c.GGML_TYPE_I16, 10, 20);
20-
const t3 = c.ggml_new_tensor_3d(ctx0, c.GGML_TYPE_I32, 10, 20, 30);
21-
22-
try std.testing.expect(t1.*.n_dims == 1);
23-
try std.testing.expect(t1.*.ne[0] == 10);
24-
try std.testing.expect(t1.*.nb[1] == 10*@sizeOf(f32));
25-
26-
try std.testing.expect(t2.*.n_dims == 2);
27-
try std.testing.expect(t2.*.ne[0] == 10);
28-
try std.testing.expect(t2.*.ne[1] == 20);
29-
try std.testing.expect(t2.*.nb[1] == 10*@sizeOf(i16));
30-
try std.testing.expect(t2.*.nb[2] == 10*20*@sizeOf(i16));
31-
32-
try std.testing.expect(t3.*.n_dims == 3);
33-
try std.testing.expect(t3.*.ne[0] == 10);
34-
try std.testing.expect(t3.*.ne[1] == 20);
35-
try std.testing.expect(t3.*.ne[2] == 30);
36-
try std.testing.expect(t3.*.nb[1] == 10*@sizeOf(i32));
37-
try std.testing.expect(t3.*.nb[2] == 10*20*@sizeOf(i32));
38-
try std.testing.expect(t3.*.nb[3] == 10*20*30*@sizeOf(i32));
39-
40-
c.ggml_print_objects(ctx0);
41-
42-
_ = try std.io.getStdIn().reader().readByte();
43-
}
1+
const std = @import("std");
2+
const c = @cImport({
3+
@cInclude("stdio.h");
4+
@cInclude("stdlib.h");
5+
@cInclude("ggml/ggml.h");
6+
});
7+
8+
pub fn main() !void {
9+
const params = .{
10+
.mem_size = 128*1024*1024,
11+
.mem_buffer = null,
12+
.no_alloc = false,
13+
};
14+
15+
const ctx0 = c.ggml_init(params);
16+
defer c.ggml_free(ctx0);
17+
18+
const t1 = c.ggml_new_tensor_1d(ctx0, c.GGML_TYPE_F32, 10);
19+
const t2 = c.ggml_new_tensor_2d(ctx0, c.GGML_TYPE_I16, 10, 20);
20+
const t3 = c.ggml_new_tensor_3d(ctx0, c.GGML_TYPE_I32, 10, 20, 30);
21+
22+
try std.testing.expect(t1.*.n_dims == 1);
23+
try std.testing.expect(t1.*.ne[0] == 10);
24+
try std.testing.expect(t1.*.nb[1] == 10*@sizeOf(f32));
25+
26+
try std.testing.expect(t2.*.n_dims == 2);
27+
try std.testing.expect(t2.*.ne[0] == 10);
28+
try std.testing.expect(t2.*.ne[1] == 20);
29+
try std.testing.expect(t2.*.nb[1] == 10*@sizeOf(i16));
30+
try std.testing.expect(t2.*.nb[2] == 10*20*@sizeOf(i16));
31+
32+
try std.testing.expect(t3.*.n_dims == 3);
33+
try std.testing.expect(t3.*.ne[0] == 10);
34+
try std.testing.expect(t3.*.ne[1] == 20);
35+
try std.testing.expect(t3.*.ne[2] == 30);
36+
try std.testing.expect(t3.*.nb[1] == 10*@sizeOf(i32));
37+
try std.testing.expect(t3.*.nb[2] == 10*20*@sizeOf(i32));
38+
try std.testing.expect(t3.*.nb[3] == 10*20*30*@sizeOf(i32));
39+
40+
c.ggml_print_objects(ctx0);
41+
42+
_ = try std.io.getStdIn().reader().readByte();
43+
}

0 commit comments

Comments
 (0)