From bdb0742dcad625ba9384410416e831e13da85385 Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Wed, 10 Apr 2024 13:14:50 -0700 Subject: [PATCH] splt gendc bin --- src/bb/image-io/bb.h | 66 ++++++++++++++------------------------- src/bb/image-io/rt_file.h | 66 +++------------------------------------ src/bb/image-io/rt_u3v.h | 16 ++++++++-- 3 files changed, 42 insertions(+), 106 deletions(-) diff --git a/src/bb/image-io/bb.h b/src/bb/image-io/bb.h index a7986e7d..9566da05 100644 --- a/src/bb/image-io/bb.h +++ b/src/bb/image-io/bb.h @@ -1111,7 +1111,6 @@ template class BinarySaver : public ion::BuildingBlock> { public: BuildingBlockParam output_directory_ptr{ "output_directory", "." }; - BuildingBlockParam num_devices{"num_devices", 2}; BuildingBlockParam prefix_ptr{"prefix", "raw-"}; Input input_images{"input", Halide::type_of(), D}; @@ -1125,8 +1124,6 @@ class BinarySaver : public ion::BuildingBlock> { void generate() { using namespace Halide; - int32_t num_gendc = static_cast(num_devices); - const std::string output_directory(output_directory_ptr); Halide::Buffer output_directory_buf(static_cast(output_directory.size() + 1)); output_directory_buf.fill(0); @@ -1173,10 +1170,10 @@ class BinaryGenDCSaver : public ion::BuildingBlock { public: BuildingBlockParam output_directory_ptr{ "output_directory", "." }; - BuildingBlockParam num_devices{"num_devices", 2}; + BuildingBlockParam prefix_ptr{"prefix", "raw-"}; - Input input_gendc{ "input_gendc", Halide::type_of(), 1 }; - Input input_deviceinfo{ "input_deviceinfo", Halide::type_of(), 1 }; + Input input_gendc{ "input_gendc", Halide::type_of(), 1 }; + Input input_deviceinfo{ "input_deviceinfo", Halide::type_of(), 1 }; Input payloadsize{ "payloadsize" }; @@ -1185,49 +1182,32 @@ class BinaryGenDCSaver : public ion::BuildingBlock { void generate() { using namespace Halide; - int32_t num_gendc = static_cast(num_devices); + const std::string prefix(prefix_ptr); + Halide::Buffer prefix_buf(static_cast(prefix.size() + 1)); + prefix_buf.fill(0); + + std::memcpy(prefix_buf.data(), prefix.c_str(), prefix.size()); const std::string output_directory(output_directory_ptr); Halide::Buffer output_directory_buf(static_cast(output_directory.size() + 1)); output_directory_buf.fill(0); std::memcpy(output_directory_buf.data(), output_directory.c_str(), output_directory.size()); Buffer id_buf = this->get_id(); - if (num_gendc==1){ - Func gendc; - gendc(_) = input_gendc(_); - gendc.compute_root(); - - Func deviceinfo; - deviceinfo(_) = input_deviceinfo(_); - deviceinfo.compute_root(); - - std::vector params = { id_buf, gendc, deviceinfo, payloadsize, output_directory_buf }; - Func image_io_binary_gendc_saver; - image_io_binary_gendc_saver.define_extern("ion_bb_image_io_binary_1gendc_saver", params, Int(32), 0); - image_io_binary_gendc_saver.compute_root(); - output() = image_io_binary_gendc_saver(); - }else if (num_gendc ==2){ - Func gendc0, gendc1; - Var x, y; - gendc0(_) = input_gendc[0](_); - gendc1(_) = input_gendc[1](_); - gendc0.compute_root(); - gendc1.compute_root(); - - Func deviceinfo0, deviceinfo1; - deviceinfo0(_) = input_deviceinfo[0](_); - deviceinfo1(_) = input_deviceinfo[1](_); - deviceinfo0.compute_root(); - deviceinfo1.compute_root(); - - std::vector params = { id_buf, gendc0, gendc1, deviceinfo0, deviceinfo1, payloadsize, output_directory_buf }; - Func image_io_binary_gendc_saver; - image_io_binary_gendc_saver.define_extern("ion_bb_image_io_binary_2gendc_saver", params, Int(32), 0); - image_io_binary_gendc_saver.compute_root(); - output() = image_io_binary_gendc_saver(); - }else{ - std::runtime_error("device number > 2 is not supported"); - } + + Func gendc; + gendc(_) = input_gendc(_); + gendc.compute_root(); + + Func deviceinfo; + deviceinfo(_) = input_deviceinfo(_); + deviceinfo.compute_root(); + + std::vector params = { id_buf, gendc, deviceinfo, payloadsize, output_directory_buf, prefix_buf }; + Func image_io_binary_gendc_saver; + image_io_binary_gendc_saver.define_extern("ion_bb_image_io_binary_gendc_saver", params, Int(32), 0); + image_io_binary_gendc_saver.compute_root(); + output() = image_io_binary_gendc_saver(); + this->register_disposer("writer_dispose"); } }; diff --git a/src/bb/image-io/rt_file.h b/src/bb/image-io/rt_file.h index a20b4729..cc5fb769 100644 --- a/src/bb/image-io/rt_file.h +++ b/src/bb/image-io/rt_file.h @@ -372,72 +372,16 @@ int ION_EXPORT writer_dispose(const char *id) { extern "C" ION_EXPORT -int ion_bb_image_io_binary_2gendc_saver( halide_buffer_t * id_buf, halide_buffer_t * in0, halide_buffer_t * in1, halide_buffer_t * in2, halide_buffer_t * in3, - int payloadsize, halide_buffer_t* output_directory_buf, - halide_buffer_t * out) - { - try { - const std::string id(reinterpret_cast(id_buf->host)); - const ::std::string output_directory(reinterpret_cast(output_directory_buf->host)); - std::vectorpayloadsize_list{payloadsize, payloadsize}; - auto& w(Writer::get_instance(id, payloadsize_list, output_directory, false)); - if (in0->is_bounds_query() || in1->is_bounds_query() || in2->is_bounds_query() || in3->is_bounds_query()) { - int i = 1; - if (in0->is_bounds_query()) { - in0->dim[0].min = 0; - in0->dim[0].extent = payloadsize; - } - if (in1->is_bounds_query()) { - in1->dim[0].min = 0; - in1->dim[0].extent = payloadsize; - } - if (in2->is_bounds_query()) { - in2->dim[0].min = 0; - in2->dim[0].extent = sizeof(ion::bb::image_io::rawHeader); - } - if (in3->is_bounds_query()) { - in3->dim[0].min = 0; - in3->dim[0].extent = sizeof(ion::bb::image_io::rawHeader); - } - return 0; - } - else { - ion::bb::image_io::rawHeader header_info0, header_info1; - ::memcpy(&header_info0, in2->host, sizeof(ion::bb::image_io::rawHeader)); - ::memcpy(&header_info1, in3->host, sizeof(ion::bb::image_io::rawHeader)); - std::vector header_infos{header_info0, header_info1}; - - std::vector obufs{in0->host, in1->host}; - std::vector size_in_bytes{in0->size_in_bytes(), in1->size_in_bytes()}; - w.post_gendc(obufs, size_in_bytes, header_infos); - - - } - - return 0; - } - catch (const ::std::exception& e) { - ::std::cerr << e.what() << ::std::endl; - return -1; - } - catch (...) { - ::std::cerr << "Unknown error" << ::std::endl; - return -1; - } -} - -ION_REGISTER_EXTERN(ion_bb_image_io_binary_2gendc_saver); - -extern "C" ION_EXPORT -int ion_bb_image_io_binary_1gendc_saver( halide_buffer_t * id_buf, halide_buffer_t * gendc, halide_buffer_t * deviceinfo, - int payloadsize, halide_buffer_t* output_directory_buf, +int ion_bb_image_io_binary_gendc_saver( halide_buffer_t * id_buf, halide_buffer_t * gendc, halide_buffer_t * deviceinfo, + int payloadsize, halide_buffer_t* output_directory_buf, halide_buffer_t* prefix_buf, halide_buffer_t * out) { try { const std::string id(reinterpret_cast(id_buf->host)); const ::std::string output_directory(reinterpret_cast(output_directory_buf->host)); std::vectorpayloadsize_list{payloadsize}; - auto& w(Writer::get_instance(id,payloadsize_list, output_directory, false)); + const ::std::string prefix(reinterpret_cast(prefix_buf->host)); + auto& w(Writer::get_instance(id,payloadsize_list, output_directory, false, prefix)); if (gendc->is_bounds_query() || deviceinfo->is_bounds_query()) { if (gendc->is_bounds_query()) { gendc->dim[0].min = 0; @@ -473,7 +417,7 @@ int ion_bb_image_io_binary_1gendc_saver( halide_buffer_t * id_buf, halide_buffer } } -ION_REGISTER_EXTERN(ion_bb_image_io_binary_1gendc_saver); +ION_REGISTER_EXTERN(ion_bb_image_io_binary_gendc_saver); extern "C" ION_EXPORT int ion_bb_image_io_binary_image_saver( diff --git a/src/bb/image-io/rt_u3v.h b/src/bb/image-io/rt_u3v.h index 6d0ddf5c..29dd78c0 100644 --- a/src/bb/image-io/rt_u3v.h +++ b/src/bb/image-io/rt_u3v.h @@ -1182,8 +1182,20 @@ class U3VGenDC: public U3V{ int32_t num_device = devices_.size(); std::vector bufs(num_device); - - if (operation_mode_ == OperationMode::Came2USB2 || operation_mode_ == OperationMode::Came1USB1){ + if (sim_mode_){ + std::vector bufs(num_sensor_); + for (int i = 0;i< num_sensor_;i++){ + auto size = devices_[i].u3v_payload_size_; + arv_stream_push_buffer (devices_[i].stream_, arv_buffer_new_allocate (size)); + bufs[i] = arv_stream_timeout_pop_buffer (devices_[i].stream_, timeout_us); + if (bufs[i] == nullptr){ + log::error("pop_buffer(L1) failed due to timeout ({}s)", timeout_us*1e-6f); + throw ::std::runtime_error("Buffer is null"); + } + devices_[i].frame_count_ += 1; + memcpy(outs[i], arv_buffer_get_part_data(bufs[i], 0, nullptr), size);} + } + else if (operation_mode_ == OperationMode::Came2USB2 || operation_mode_ == OperationMode::Came1USB1){ if (realtime_display_mode_){ consume_old_buffer(bufs,timeout_us);