Skip to content

Commit a3c0bf0

Browse files
committed
Release v1.0
1 parent 2dfa208 commit a3c0bf0

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

build.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ pub fn build(b: *std.Build) void {
439439
.root_source_file = b.path(model_options_path),
440440
});
441441
model_opts_mod.addImport("zant", zant_mod);
442+
model_opts_mod.addImport("codegen", codegen_mod);
442443
model_opts_mod.addImport("IR_zant", IR_zant_mod);
443444
main_executable.root_module.addImport("model_opts", model_opts_mod);
444445
const install_main_exe_step = b.addInstallArtifact(main_executable, .{}); // Installa l'eseguibile

docs/ZANT_CLI.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ The workflows above use the `zant` wrapper script for ONNX model preparation. He
307307
./zant user_tests_gen --model model.onnx --iterations 10
308308
```
309309

310+
311+
### Model Profiling
312+
```bash
313+
zig build build-main -Dmodel="my_model"
314+
315+
valgrind --tool=massif --heap=yes --stacks=yes ./zig-out/bin/main_profiling_target
316+
317+
ms_print massif.out.* > out_profiling.txt
318+
```
319+
310320
### Zant Script Locations
311321
- **onnx_gen**: `tests/CodeGen/Python-ONNX/onnx_gen.py`
312322
- **user_tests_gen**: `tests/CodeGen/user_tests_gen.py`

src/main.zig

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ extern fn predict(
1111
result: *[*]f32, // Pointer to receive the output slice pointer
1212
) i32;
1313

14-
fn prepareInputData(allocator: std.mem.Allocator) ![]model_opts.data_type {
14+
fn prepareInputData(allocator: std.mem.Allocator) ![]model_opts.input_data_type {
1515
const shape = model_opts.input_shape;
1616
var total_size: usize = 1;
1717
for (shape) |dim| {
1818
total_size *= dim;
1919
}
2020

21-
const data = try allocator.alloc(model_opts.data_type, total_size);
21+
const data = try allocator.alloc(model_opts.input_data_type, total_size);
2222
errdefer allocator.free(data);
2323

2424
for (data, 0..) |*val, i| {
25-
val.* = @as(model_opts.data_type, @floatFromInt(i));
25+
val.* = @as(model_opts.input_data_type, @floatFromInt(i));
2626
}
2727

2828
return data;
2929
}
3030

3131
fn getPredictOutputSize() usize {
32-
return 1 * 84 * 1344;
32+
return 1 * 4;
3333
}
3434

3535
pub fn main() !void {
@@ -41,17 +41,20 @@ pub fn main() !void {
4141
const input_data = try prepareInputData(allocator);
4242
const input_shape = model_opts.input_shape;
4343

44-
var output_ptr: [*]model_opts.data_type = undefined;
44+
var output_ptr: [*]model_opts.output_data_type = undefined;
4545

4646
main_log.info("Calling predict (via model_opts.lib)...\\n", .{});
4747

48-
model_opts.lib.predict(
48+
const res = model_opts.lib.predict(
4949
input_data.ptr,
5050
@constCast(@ptrCast(&input_shape)),
5151
@intCast(input_shape.len),
5252
&output_ptr,
5353
);
5454

55+
if (res == 0) {
56+
main_log.info("\n !!!! ERRORR!!! \n\n something went wrong", .{});
57+
}
5558
main_log.info("Predict call finished.\n", .{});
5659

5760
const output_size = getPredictOutputSize();
@@ -64,7 +67,7 @@ pub fn main() !void {
6467
return;
6568
}
6669

67-
const output_slice = @as([*]model_opts.data_type, @ptrCast(output_ptr))[0..output_size];
70+
const output_slice = @as([*]model_opts.output_data_type, @ptrCast(output_ptr))[0..output_size];
6871

6972
//print the output
7073
main_log.info("Output (first 10 elements):\n", .{});

0 commit comments

Comments
 (0)