fixed segfault on write_raw

This commit is contained in:
Nicholas Young 2024-10-15 19:48:19 -07:00
parent 94305918c1
commit 6f95699d19

View file

@ -11,7 +11,7 @@ const hef_file = "yolov7.hef";
const max_edge_layers = 32; const max_edge_layers = 32;
pub fn main() void { pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit(); defer arena.deinit();
@ -89,29 +89,47 @@ pub fn main() void {
var input_frame_size: usize = 0; var input_frame_size: usize = 0;
status = hlo.hailo_get_input_vstream_frame_size(&input_vstreams, &input_frame_size); status = hlo.hailo_get_input_vstream_frame_size(input_vstreams[0], &input_frame_size);
assert(status == hlo.HAILO_SUCCESS); assert(status == hlo.HAILO_SUCCESS);
const frame_count = input_frame_size / @sizeOf(u8); const frame_count = input_frame_size / @sizeOf(u8);
std.debug.print("Trying to create {d} u8s\n", .{ frame_count }); std.debug.print("Trying to create {d} u8s\n", .{ frame_count });
var input_data = try alloc.create(u8, frame_count); var input_data: [:0]u8 = try alloc.allocSentinel(u8, frame_count, 0);
var rnd = std.Random.init(0);
var prng = std.Random.DefaultPrng.init(blk: {
var seed: u64 = undefined;
try std.posix.getrandom(std.mem.asBytes(&seed));
break :blk seed;
});
const rand = prng.random();
for (0..frame_count) |i| { for (0..frame_count) |i| {
input_data[i] = rnd.random().int(u8); input_data[i] = rand.int(u8);
} }
std.debug.print("Random numbers filled!\n", .{});
std.debug.print("Getting vstream info\n", .{});
var stream_info: hlo.hailo_vstream_info_t = undefined;
status = hlo.hailo_get_input_vstream_info(input_vstreams[0], &stream_info);
assert(status == hlo.HAILO_SUCCESS);
std.debug.print("Writing vstream data\n", .{});
// Here we simulate taking our data and chunking it into frame_size, then uploading each frame until we have uploaded // Here we simulate taking our data and chunking it into frame_size, then uploading each frame until we have uploaded
// all of our data // all of our data
for (0..frame_count) |_| { for (0..frame_count) |_| {
status = hlo.hailo_vstream_write_raw_buffer(&input_vstreams, input_data, input_frame_size); status = hlo.hailo_vstream_write_raw_buffer(input_vstreams[0], @ptrCast(input_data.ptr), input_frame_size);
assert(status == hlo.HAILO_SUCCESS); assert(status == hlo.HAILO_SUCCESS);
} }
status = hlo.hailo_flush_input_vstream(&input_vstreams); std.debug.print("Input written\n", .{});
status = hlo.hailo_flush_input_vstream(input_vstreams[0]);
assert(status == hlo.HAILO_SUCCESS); assert(status == hlo.HAILO_SUCCESS);
std.debug.print("input flushed!\n", .{});
_ = hlo.hailo_release_output_vstreams(&output_vstreams, output_vstream_size); _ = hlo.hailo_release_output_vstreams(&output_vstreams, output_vstream_size);
_ = hlo.hailo_release_input_vstreams(&input_vstreams, input_vstream_size); _ = hlo.hailo_release_input_vstreams(&input_vstreams, input_vstream_size);
@ -119,15 +137,3 @@ pub fn main() void {
_ = hlo.hailo_release_vdevice(vdevice); _ = hlo.hailo_release_vdevice(vdevice);
} }
fn write_to_hlo(input_stream: hlo.hailo_input_vstream, alloc: Allocator) bool {
var device_status: hlo.hailo_status = undefined;
var input_frame_size: usize = 0;
var src_data: *[]u8 = undefined;
device_status = hlo.hailo_get_input_vstream_frame_size(input_stream, &input_frame_size);
src_data = alloc.alloc(u8, input_frame_size);
}