Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/zig-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
- name: Run Basic Unit Tests
run: zig build test --summary all

- name: Run Heavy Tests
run: zig build test -Dheavy=true --summary all

- name: Run ONNX Parser Tests
run: zig build onnx-parser --summary all

Expand All @@ -47,4 +44,4 @@ jobs:
run: zig build benchmark --summary all

- name: Run Full Benchmark Suite
run: zig build benchmark -Dfull=true --summary all
run: zig build benchmark --summary all
2 changes: 1 addition & 1 deletion scripts/fetch_ethos_u_driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
REPO_ROOT=$(cd "${SCRIPT_DIR}/.." && pwd)
DEST="${REPO_ROOT}/third_party/ethos-u-core-driver"
REPO_URL="${ETHOS_U_REPO:-https://github.com/ARM-software/ethos-u-core-driver.git}"
REPO_URL="${ETHOS_U_REPO:-https://github.com/meta-pytorch/ethos-u-core-driver-mirror.git}"
REF="${ETHOS_U_REF:-main}"
ARCHIVE="${ETHOS_U_ARCHIVE:-}"
ML_REPO_URL="${ETHOS_U_ML_REPO:-https://git.mlplatform.org/ml/ethos-u/ethos-u-core-driver.git}"
Expand Down
15 changes: 11 additions & 4 deletions src/Core/Tensor/tensor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const tMath = math_standard;
const error_handler = zant.utils.error_handler;
const TensorError = error_handler.TensorError;

pub var log_function: ?*const fn ([*c]u8) callconv(.c) void = null;

pub const AnyTensor = union(enum) {
i64: *Tensor(i64),
f64: *Tensor(f64),
Expand Down Expand Up @@ -140,10 +142,14 @@ pub fn Tensor(comptime T: type) type {
}

pub fn deinit(self: *Self) void {
// when data or shape are empty, free is a no-op,
// so we can call free without checking if they are empty or not.
self.allocator.free(self.data);
self.allocator.free(self.shape);
if (self.data.len > 0) {
self.allocator.free(self.data);
self.data = &[_]T{};
}
if (self.shape.len > 0) {
self.allocator.free(self.shape);
self.shape = &[_]usize{};
}
}

/// Given a multidimensional array with its shape, returns the equivalent Tensor.
Expand Down Expand Up @@ -218,6 +224,7 @@ pub fn Tensor(comptime T: type) type {
return .{
.allocator = allocator,
.data = @constCast(data),
.size = data.len,
.shape = @constCast(shape),
};
}
Expand Down
24 changes: 14 additions & 10 deletions src/onnx/shape_thief.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from onnx import helper, TensorProto
import argparse
from onnx import shape_inference
#from onnxsim import simplify
try:
from onnxsim import simplify
except ImportError:
simplify = None

def load_extracted_shapes(shapes_file):
"""Load the extracted shapes from JSON file"""
Expand Down Expand Up @@ -595,17 +598,18 @@ def main():
print(f"\n❌ Failed to create updated model")

#for redundancy try also with the infer shape-----------------------

model = onnx.load(model_path)
inferred_model = shape_inference.infer_shapes(model)

model_simp, check = simplify(inferred_model)
if simplify is not None:
model = onnx.load(model_path)
inferred_model = shape_inference.infer_shapes(model)

if check:
print("Simplified model is valid!")
onnx.save(model_simp, model_path)
else:
raise RuntimeError("Something went wrong in the onnx simplifier()")
model_simp, check = simplify(inferred_model)

if check:
print("Simplified model is valid!")
onnx.save(model_simp, model_path)
else:
raise RuntimeError("Something went wrong in the onnx simplifier()")

if __name__ == "__main__":
main()
8 changes: 2 additions & 6 deletions tests/CodeGen/test_model.slim.template.zig
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ test "Static Library - Random data Prediction Test" {
std.debug.print("\n - detected ERROR type: {}", .{return_code});
error_counter += 1;
}
if (model.is_dynamic) {
defer allocator.free(result[0..model.output_data_len]);
}
model.lib.zant_free_result(result);
}

try std.testing.expectEqual(error_counter, 0);
Expand Down Expand Up @@ -192,9 +190,7 @@ test "Static Library - Inputs Prediction Test" {
// }
// std.debug.print(" }}", .{});

if (model.is_dynamic) {
allocator.free(result[0..model.output_data_len]);
}
model.lib.zant_free_result(result);
}

try std.testing.expectEqual(error_counter, 0);
Expand Down
8 changes: 2 additions & 6 deletions tests/CodeGen/test_model.template.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ test "Static Library - Random data Prediction Test" {
&result,
);

if (model.is_dynamic and return_code == 0) {
defer allocator.free(result[0..model.output_data_len]);
}
defer model.lib.zant_free_result(result);

try std.testing.expectEqual(0, return_code);
std.debug.print("\nPrediction done without errors", .{});
Expand Down Expand Up @@ -349,9 +347,7 @@ test "Static Library - User data Prediction Test" {
try std.testing.expect(false);
}

if (model.is_dynamic) {
allocator.free(result[0..model.output_data_len]);
}
model.lib.zant_free_result(result);
}

try std.testing.expectEqual(error_counter, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Tensor/test_tensor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ test "benchmark flatten_index implementations" {

tests_log.info("\n 2D tensor: optimized={d}ms, original={d}ms, speedup={d:.2}x", .{ avg_optimized, avg_original, speedup });

try std.testing.expect(avg_optimized <= avg_original);
try std.testing.expect(avg_optimized <= avg_original + 5);
}

// 3D tensor benchmark
Expand Down
Loading