From c9362927026f2f398550a146a39b9d5472035a07 Mon Sep 17 00:00:00 2001 From: Takuro IIZUKA Date: Fri, 5 Apr 2024 14:41:17 -0700 Subject: [PATCH 1/8] Merge pull request #263 from fixstars/fix/port-access Fix port index access in capi --- src/c_ion.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/c_ion.cc b/src/c_ion.cc index 35798690..45c69e78 100644 --- a/src/c_ion.cc +++ b/src/c_ion.cc @@ -46,7 +46,6 @@ int ion_port_create_with_index(ion_port_t *ptr, ion_port_t obj, int index) auto p = new Port(*reinterpret_cast(obj)); p->set_index(index); *ptr = reinterpret_cast(p); - reinterpret_cast(obj)->set_index(index); } catch (const Halide::Error& e) { log::error(e.what()); return 1; From cf268c6166d6ccc1ba4fe504607a1529427f8623 Mon Sep 17 00:00:00 2001 From: Takuro IIZUKA Date: Tue, 9 Apr 2024 11:33:29 -0700 Subject: [PATCH 2/8] Merge pull request #265 from fixstars/fix/image-save-bin Fix/save single bin --- src/bb/image-io/bb.h | 58 +++++++-------------- src/bb/image-io/rt_file.h | 106 ++++++-------------------------------- 2 files changed, 36 insertions(+), 128 deletions(-) diff --git a/src/bb/image-io/bb.h b/src/bb/image-io/bb.h index eeb6a34a..a7986e7d 100644 --- a/src/bb/image-io/bb.h +++ b/src/bb/image-io/bb.h @@ -1112,13 +1112,11 @@ 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_images", Halide::type_of(), D }; - - Input input_deviceinfo{ "input_deviceinfo", Halide::type_of(), 1 }; + Input input_images{"input", Halide::type_of(), D}; + Input input_deviceinfo{ "input_deviceinfo", Halide::type_of(), 1 }; Input frame_count{ "frame_count", Halide::type_of(), 1 }; - - Input width{ "width" }; Input height{ "height" }; @@ -1134,6 +1132,11 @@ class BinarySaver : public ion::BuildingBlock> { output_directory_buf.fill(0); std::memcpy(output_directory_buf.data(), output_directory.c_str(), output_directory.size()); + 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()); + Func fc; fc(_) = frame_count(_); fc.compute_root(); @@ -1141,42 +1144,21 @@ class BinarySaver : public ion::BuildingBlock> { int32_t dim = D; int32_t byte_depth = sizeof(T); - Buffer id_buf = this->get_id(); - if (num_devices==1){ - Func image; - image(_) = input_images(_); - image.compute_root(); - - Func deviceinfo; - deviceinfo(_) = input_deviceinfo(_); - deviceinfo.compute_root(); + Buffer id_buf = this->get_id(); - std::vector params = {id_buf, image, deviceinfo, fc, width, height, dim, byte_depth, output_directory_buf }; - Func ion_bb_image_io_binary_image_saver; - ion_bb_image_io_binary_image_saver.define_extern("ion_bb_image_io_binary_1image_saver", params, Int(32), 0); - ion_bb_image_io_binary_image_saver.compute_root(); - output() = ion_bb_image_io_binary_image_saver(); - }else if (num_devices==2){ - Func image0, image1; - image0(_) = input_images[0](_); - image1(_) = input_images[1](_); - image0.compute_root(); - image1.compute_root(); + Func image; + image(_) = input_images(_); + image.compute_root(); - Func deviceinfo0, deviceinfo1; - deviceinfo0(_) = input_deviceinfo[0](_); - deviceinfo1(_) = input_deviceinfo[1](_); - deviceinfo0.compute_root(); - deviceinfo1.compute_root(); + Func deviceinfo; + deviceinfo(_) = input_deviceinfo(_); + deviceinfo.compute_root(); - std::vector params = {id_buf, image0, image1, deviceinfo0, deviceinfo1, fc, width, height, dim, byte_depth, output_directory_buf }; - Func ion_bb_image_io_binary_image_saver; - ion_bb_image_io_binary_image_saver.define_extern("ion_bb_image_io_binary_2image_saver", params, Int(32), 0); - ion_bb_image_io_binary_image_saver.compute_root(); - output() = ion_bb_image_io_binary_image_saver(); - }else{ - std::runtime_error("device number > 2 is not supported"); - } + std::vector params = {id_buf, image, deviceinfo, fc, width, height, dim, byte_depth, output_directory_buf, prefix_buf }; + Func ion_bb_image_io_binary_image_saver; + ion_bb_image_io_binary_image_saver.define_extern("ion_bb_image_io_binary_image_saver", params, Int(32), 0); + ion_bb_image_io_binary_image_saver.compute_root(); + output(_) = ion_bb_image_io_binary_image_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 88d0160a..a20b4729 100644 --- a/src/bb/image-io/rt_file.h +++ b/src/bb/image-io/rt_file.h @@ -120,11 +120,11 @@ namespace { class Writer { public: - static Writer& get_instance(const std::string& id, std::vector& payload_size, const ::std::string& output_directory, bool write_framecount) + static Writer& get_instance(const std::string& id, std::vector& payload_size, const ::std::string& output_directory, bool write_framecount, const std::string& prefix = "raw-") { if (instances.count(id) == 0) { - instances[id] = std::unique_ptr(new Writer(payload_size, output_directory, write_framecount)); + instances[id] = std::unique_ptr(new Writer(payload_size, output_directory, write_framecount, prefix )); } return *instances[id]; } @@ -137,7 +137,7 @@ class Writer { } - void post_images(std::vector& outs, std::vector& size, + void post_image(std::vector& outs, std::vector& size, std::vector& header_infos, void* framecounts) { if (with_header_){ @@ -229,8 +229,8 @@ class Writer { } private: - Writer(std::vector& payload_size, const ::std::string& output_directory, bool write_framecount) - : keep_running_(true), output_directory_(output_directory), with_header_(true), disposed_(false) + Writer(std::vector& payload_size, const std::string& output_directory, bool write_framecount, const std::string& prefix) + : keep_running_(true), output_directory_(output_directory), with_header_(true), disposed_(false), prefix_(prefix) { int total_payload_size = 0; for (auto s : payload_size){ @@ -246,7 +246,8 @@ class Writer { buf_queue_.push(buffers_[i].data()); } thread_ = ::std::make_shared<::std::thread>(entry_point, this); - ofs_ = ::std::ofstream(output_directory_ / "raw-0.bin", ::std::ios::binary); + auto filename = prefix_ + std::to_string(0) + ".bin"; + ofs_ = ::std::ofstream(output_directory_ / filename, ::std::ios::binary); } int get_buffer_num(int width, int height, int num_sensor = 2, int data_in_byte = 2) { @@ -294,7 +295,7 @@ class Writer { if (i == rotate_limit) { i = 0; - ofs_ = ::std::ofstream(output_directory_ / ("raw-" + ::std::to_string(file_idx++) + ".bin"), ::std::ios::binary); + ofs_ = ::std::ofstream(output_directory_ / (prefix_ + ::std::to_string(file_idx++) + ".bin"), ::std::ios::binary); } ofs_.write(reinterpret_cast(buffer), size); @@ -321,7 +322,7 @@ class Writer { if (i == rotate_limit) { i = 0; - ofs_ = ::std::ofstream(output_directory_ / ("raw-" + ::std::to_string(file_idx++) + ".bin"), ::std::ios::binary); + ofs_ = ::std::ofstream(output_directory_ / (prefix_ + ::std::to_string(file_idx++) + ".bin"), ::std::ios::binary); } @@ -353,6 +354,7 @@ class Writer { uint32_t width_; uint32_t height_; std::filesystem::path output_directory_; + std::string prefix_; bool disposed_; bool with_header_; @@ -474,10 +476,11 @@ 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); extern "C" ION_EXPORT -int ion_bb_image_io_binary_1image_saver( +int ion_bb_image_io_binary_image_saver( halide_buffer_t * id_buf, halide_buffer_t * image, halide_buffer_t * deviceinfo, halide_buffer_t * frame_count, int width, int height, int dim, int byte_depth, halide_buffer_t* output_directory_buf, + halide_buffer_t* prefix_buf, halide_buffer_t * out) { try { @@ -486,7 +489,8 @@ int ion_bb_image_io_binary_1image_saver( int32_t frame_size = dim == 2 ? width * height * byte_depth : width * height * 3 * byte_depth; std::vectorframe_size_list{frame_size}; const ::std::string output_directory(reinterpret_cast(output_directory_buf->host)); - auto& w(Writer::get_instance(id, frame_size_list, output_directory, true)); + const ::std::string prefix(reinterpret_cast(prefix_buf->host)); + auto& w(Writer::get_instance(id, frame_size_list, output_directory, true, prefix)); if (image->is_bounds_query() || deviceinfo->is_bounds_query() || frame_count->is_bounds_query()) { if (image->is_bounds_query()) { @@ -518,7 +522,7 @@ int ion_bb_image_io_binary_1image_saver( std::vector obufs{image->host}; std::vector size_in_bytes{image->size_in_bytes()}; - w.post_images(obufs, size_in_bytes, header_infos, frame_count->host); + w.post_image(obufs, size_in_bytes, header_infos, frame_count->host); } return 0; @@ -533,85 +537,7 @@ int ion_bb_image_io_binary_1image_saver( } } -ION_REGISTER_EXTERN(ion_bb_image_io_binary_1image_saver); - -extern "C" ION_EXPORT -int ion_bb_image_io_binary_2image_saver( - halide_buffer_t * id_buf, - halide_buffer_t * image0, halide_buffer_t * image1, - halide_buffer_t * deviceinfo0, halide_buffer_t * deviceinfo1, halide_buffer_t * frame_count, - int32_t width, int32_t height, int32_t dim, int byte_depth, halide_buffer_t* output_directory_buf, - halide_buffer_t * out) - { - try { - int num_output = 2; - const std::string id(reinterpret_cast(id_buf->host)); - int32_t frame_size = dim == 2 ? width * height * byte_depth : width * height * 3 * byte_depth; - std::vectorframe_size_list{frame_size, frame_size}; - const ::std::string output_directory(reinterpret_cast(output_directory_buf->host)); - auto& w(Writer::get_instance(id, frame_size_list, output_directory, true)); - - if (image0->is_bounds_query() || deviceinfo0->is_bounds_query() || - image1->is_bounds_query() || deviceinfo1->is_bounds_query() || frame_count->is_bounds_query()) { - if (image0->is_bounds_query()) { - image0->dim[0].min = 0; - image0->dim[0].extent = width; - image0->dim[1].min = 0; - image0->dim[1].extent = height; - if (dim == 3){ - image0->dim[2].min = 0; - image0->dim[2].extent = 3; - } - } - if (deviceinfo0->is_bounds_query()) { - deviceinfo0->dim[0].min = 0; - deviceinfo0->dim[0].extent = sizeof(ion::bb::image_io::rawHeader); - } - if (image1->is_bounds_query()) { - image1->dim[0].min = 0; - image1->dim[0].extent = width; - image1->dim[1].min = 0; - image1->dim[1].extent = height; - if (dim == 3){ - image1->dim[2].min = 0; - image1->dim[2].extent = 3; - } - } - if (deviceinfo1->is_bounds_query()) { - deviceinfo1->dim[0].min = 0; - deviceinfo1->dim[0].extent = sizeof(ion::bb::image_io::rawHeader); - } - if (frame_count->is_bounds_query()) { - frame_count->dim[0].min = 0; - frame_count->dim[0].extent = num_output; - } - return 0; - } - else { - - ion::bb::image_io::rawHeader header_info0, header_info1; - ::memcpy(&header_info0, deviceinfo0->host, sizeof(ion::bb::image_io::rawHeader)); - ::memcpy(&header_info1, deviceinfo1->host, sizeof(ion::bb::image_io::rawHeader)); - std::vector header_infos{header_info0, header_info1}; - - std::vector obufs{image0->host, image1->host}; - std::vector size_in_bytes{image0->size_in_bytes(), image1->size_in_bytes()}; - w.post_images(obufs, size_in_bytes, header_infos, frame_count->host); - } - - 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_2image_saver); +ION_REGISTER_EXTERN(ion_bb_image_io_binary_image_saver); namespace { From cd65f8144f9697d90fee1abeef37701d1bf4d31d Mon Sep 17 00:00:00 2001 From: Takuro IIZUKA Date: Thu, 11 Apr 2024 11:40:24 -0700 Subject: [PATCH 3/8] Merge pull request #268 from fixstars/fix/gendc-save-single-bin Fix/separate gendc bin file --- 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); From 51a1b0a6f87de74fe80a50436ec962fc3e2914a5 Mon Sep 17 00:00:00 2001 From: Fixstars-momoko Date: Tue, 7 May 2024 11:37:42 -0700 Subject: [PATCH 4/8] update the output type of frame_count for U3VCameraN --- src/bb/image-io/bb.h | 17 ++++++++++++++--- src/bb/image-io/rt_u3v.h | 25 +++++++++++++------------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/bb/image-io/bb.h b/src/bb/image-io/bb.h index 9566da05..0547b20f 100644 --- a/src/bb/image-io/bb.h +++ b/src/bb/image-io/bb.h @@ -839,7 +839,7 @@ class U3VCameraN : public ion::BuildingBlock> { Output output{ "output", Halide::type_of(), D}; Output device_info{ "device_info", Halide::type_of(), 1}; - Output frame_count{ "frame_count", Halide::type_of(), 1 }; + Output frame_count{ "frame_count", Halide::type_of(), 1 }; std::vector *> gain; std::vector *> exposure; @@ -964,9 +964,20 @@ class U3VCameraN : public ion::BuildingBlock> { pixel_format_buf }; - cameraN_fc.define_extern("ion_bb_image_io_u3v_multiple_camera_frame_count" + std::to_string(output.size()), params, type_of(), 1); + frame_count.resize(num_devices); + std::vector output_type; + for (int i = 0; i < frame_count.size(); i++) { + output_type.push_back(Halide::type_of()); + } + cameraN_fc.define_extern("ion_bb_image_io_u3v_multiple_camera_frame_count" + std::to_string(output.size()), params, output_type, 1); cameraN_fc.compute_root(); - frame_count(_) = cameraN_fc(_); + if (frame_count.size() == 1){ + frame_count[0](_) = cameraN_fc(_); + }else{ + for (int i = 0; i < device_info.size(); i++) { + frame_count[i](_) = cameraN_fc(_)[i]; + } + } } this->register_disposer("u3v_dispose"); } diff --git a/src/bb/image-io/rt_u3v.h b/src/bb/image-io/rt_u3v.h index 29dd78c0..1019f792 100644 --- a/src/bb/image-io/rt_u3v.h +++ b/src/bb/image-io/rt_u3v.h @@ -296,12 +296,12 @@ class U3V { virtual void get(std::vector>& outs){}; virtual void get(std::vector& outs){}; - void get_frame_count(uint32_t * out){ + void get_frame_count(std::vector& outs){ if (num_sensor_ != devices_.size()){ - ::memcpy(out, &frame_cnt_, sizeof(uint32_t)); + ::memcpy(outs[0], &frame_cnt_, sizeof(uint32_t)); }else{ for (int nd = 0; nd < num_sensor_; nd++){ - ::memcpy(out + nd, &devices_[nd].frame_count_, sizeof(uint32_t)); + ::memcpy(outs[nd], &devices_[nd].frame_count_, sizeof(uint32_t)); } } } @@ -1652,13 +1652,14 @@ int u3v_camera_frame_count( { try { auto &u3v(ion::bb::image_io::U3VRealCam::get_instance(id, num_sensor, frame_sync, realtime_display_mode)); + std::vector obufs{out->host}; if (out->is_bounds_query()) { out->dim[0].min = 0; out->dim[0].extent = num_sensor; return 0; } else { - u3v.get_frame_count(reinterpret_cast(out->host)); + u3v.get_frame_count(obufs); } return 0; @@ -1967,6 +1968,7 @@ int ION_EXPORT ion_bb_image_io_u3v_multiple_camera_frame_count1( try { const std::string id(reinterpret_cast(id_buf->host)); const std::string pixel_format(reinterpret_cast(pixel_format_buf->host)); + std::vector obufs{out->host}; if (out->is_bounds_query()) { out->dim[0].min = 0; out->dim[0].extent = num_sensor; @@ -1974,10 +1976,10 @@ int ION_EXPORT ion_bb_image_io_u3v_multiple_camera_frame_count1( } if(force_sim_mode){ auto &u3v(ion::bb::image_io::U3VFakeCam::get_instance(id, 1, width, height, fps, pixel_format)); - u3v.get_frame_count(reinterpret_cast(out->host)); + u3v.get_frame_count(obufs); }else{ auto &u3v(ion::bb::image_io::U3VRealCam::get_instance(id, 1, frame_sync, realtime_display_mode, force_sim_mode, width, height, fps, pixel_format)); - u3v.get_frame_count(reinterpret_cast(out->host)); + u3v.get_frame_count(obufs); } return 0; @@ -2000,22 +2002,21 @@ int ION_EXPORT ion_bb_image_io_u3v_multiple_camera_frame_count2( int32_t width, int32_t height, float_t fps, bool frame_sync, bool realtime_display_mode, halide_buffer_t * pixel_format_buf, - halide_buffer_t* out) + halide_buffer_t * out0, halide_buffer_t * out1) { try { const std::string id(reinterpret_cast(id_buf->host)); const std::string pixel_format(reinterpret_cast(pixel_format_buf->host)); - if (out->is_bounds_query()) { - out->dim[0].min = 0; - out->dim[0].extent = num_sensor; + std::vector obufs{out0->host, out1->host}; + if (out0->is_bounds_query() || out1->is_bounds_query()) { return 0; } if(force_sim_mode){ auto &u3v(ion::bb::image_io::U3VFakeCam::get_instance(id, 2, width, height, fps, pixel_format)); - u3v.get_frame_count(reinterpret_cast(out->host)); + u3v.get_frame_count(obufs); }else{ auto &u3v(ion::bb::image_io::U3VRealCam::get_instance(id, 2, frame_sync, realtime_display_mode, force_sim_mode, width, height, fps, pixel_format)); - u3v.get_frame_count(reinterpret_cast(out->host)); + u3v.get_frame_count(obufs); } return 0; } catch (const std::exception &e) { From dd94c0af0e6bb2815bd77ed43d94bed2636e293b Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Thu, 9 May 2024 11:17:02 -0700 Subject: [PATCH 5/8] fix config json --- src/bb/image-io/rt_file.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bb/image-io/rt_file.h b/src/bb/image-io/rt_file.h index cc5fb769..2b798bf9 100644 --- a/src/bb/image-io/rt_file.h +++ b/src/bb/image-io/rt_file.h @@ -220,8 +220,8 @@ class Writer { j_ith_sensor["pfnc_pixelformat"] = header_infos[i].pfnc_pixelformat; j["sensor" + std::to_string(i+1)] = j_ith_sensor; } - - ::std::ofstream config(output_directory_ / "config.json"); + auto filename = prefix_ + "config.json"; + std::ofstream config(output_directory_ / filename); config << std::setw(4) << j << std::endl; config.close(); From ee4c158876b010715c75e2f7db91f05e5076f1b3 Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Thu, 9 May 2024 14:15:38 -0700 Subject: [PATCH 6/8] fix headerinfo --- src/bb/image-io/rt_file.h | 42 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/bb/image-io/rt_file.h b/src/bb/image-io/rt_file.h index 2b798bf9..4a8bc37c 100644 --- a/src/bb/image-io/rt_file.h +++ b/src/bb/image-io/rt_file.h @@ -138,10 +138,10 @@ class Writer { } void post_image(std::vector& outs, std::vector& size, - std::vector& header_infos, void* framecounts) + ion::bb::image_io::rawHeader& header_info, void* framecounts) { if (with_header_){ - write_config_file(header_infos); + write_config_file(header_info); } ::std::unique_lock<::std::mutex> lock(mutex_); buf_cv_.wait(lock, [&] { return !buf_queue_.empty() || ep_; }); @@ -161,10 +161,10 @@ class Writer { task_cv_.notify_one(); } - void post_gendc(std::vector& outs, std::vector& size, std::vector& header_infos) + void post_gendc(std::vector& outs, std::vector& size, ion::bb::image_io::rawHeader& header_info) { if (with_header_){ - write_config_file(header_infos); + write_config_file(header_info); } ::std::unique_lock<::std::mutex> lock(mutex_); buf_cv_.wait(lock, [&] { return !buf_queue_.empty() || ep_; }); @@ -209,22 +209,19 @@ class Writer { } - void write_config_file(std::vector& header_infos){ + void write_config_file(ion::bb::image_io::rawHeader& header_info){ nlohmann::json j; - j["num_device"] = header_infos.size(); - for (int i = 0; i < header_infos.size(); ++i){ - nlohmann::json j_ith_sensor; - j_ith_sensor["framerate"] = header_infos[i].fps_; - j_ith_sensor["width"] = header_infos[i].width_; - j_ith_sensor["height"] = header_infos[i].height_; - j_ith_sensor["pfnc_pixelformat"] = header_infos[i].pfnc_pixelformat; - j["sensor" + std::to_string(i+1)] = j_ith_sensor; - } + nlohmann::json j_sensor; + j_sensor["framerate"] = header_info.fps_; + j_sensor["width"] = header_info.width_; + j_sensor["height"] = header_info.height_; + j_sensor["pfnc_pixelformat"] = header_info.pfnc_pixelformat; + j["sensor"] = j_sensor; + auto filename = prefix_ + "config.json"; std::ofstream config(output_directory_ / filename); config << std::setw(4) << j << std::endl; config.close(); - with_header_ = false; } @@ -394,13 +391,12 @@ int ion_bb_image_io_binary_gendc_saver( halide_buffer_t * id_buf, halide_buffer_ return 0; } else { - ion::bb::image_io::rawHeader header_info0; - ::memcpy(&header_info0, deviceinfo->host, sizeof(ion::bb::image_io::rawHeader)); - std::vector header_infos{header_info0}; + ion::bb::image_io::rawHeader header_info; + ::memcpy(&header_info, deviceinfo->host, sizeof(ion::bb::image_io::rawHeader)); std::vector obufs{gendc->host}; std::vector size_in_bytes{gendc->size_in_bytes()}; - w.post_gendc(obufs, size_in_bytes, header_infos); + w.post_gendc(obufs, size_in_bytes, header_info); } @@ -460,13 +456,13 @@ int ion_bb_image_io_binary_image_saver( else { - ion::bb::image_io::rawHeader header_info0; - ::memcpy(&header_info0, deviceinfo->host, sizeof(ion::bb::image_io::rawHeader)); - std::vector header_infos{header_info0}; + ion::bb::image_io::rawHeader header_info; + memcpy(&header_info, deviceinfo->host, sizeof(ion::bb::image_io::rawHeader)); + std::vector header_infos{header_info}; std::vector obufs{image->host}; std::vector size_in_bytes{image->size_in_bytes()}; - w.post_image(obufs, size_in_bytes, header_infos, frame_count->host); + w.post_image(obufs, size_in_bytes, header_info, frame_count->host); } return 0; From c0104684b13477310f623c21dae52e41b23629f6 Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Thu, 9 May 2024 14:21:52 -0700 Subject: [PATCH 7/8] add prefix --- src/bb/image-io/rt_file.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bb/image-io/rt_file.h b/src/bb/image-io/rt_file.h index 4a8bc37c..b7b8803c 100644 --- a/src/bb/image-io/rt_file.h +++ b/src/bb/image-io/rt_file.h @@ -212,6 +212,7 @@ class Writer { void write_config_file(ion::bb::image_io::rawHeader& header_info){ nlohmann::json j; nlohmann::json j_sensor; + j_sensor["prefix"] = prefix_; j_sensor["framerate"] = header_info.fps_; j_sensor["width"] = header_info.width_; j_sensor["height"] = header_info.height_; From d6776667ead5fb72f7aa3d13dcddea60a81cfffd Mon Sep 17 00:00:00 2001 From: Xinyu Li Date: Thu, 9 May 2024 15:14:16 -0700 Subject: [PATCH 8/8] remove sensor --- src/bb/image-io/rt_file.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bb/image-io/rt_file.h b/src/bb/image-io/rt_file.h index b7b8803c..839a5ed2 100644 --- a/src/bb/image-io/rt_file.h +++ b/src/bb/image-io/rt_file.h @@ -210,18 +210,16 @@ class Writer { } void write_config_file(ion::bb::image_io::rawHeader& header_info){ - nlohmann::json j; nlohmann::json j_sensor; j_sensor["prefix"] = prefix_; j_sensor["framerate"] = header_info.fps_; j_sensor["width"] = header_info.width_; j_sensor["height"] = header_info.height_; j_sensor["pfnc_pixelformat"] = header_info.pfnc_pixelformat; - j["sensor"] = j_sensor; auto filename = prefix_ + "config.json"; std::ofstream config(output_directory_ / filename); - config << std::setw(4) << j << std::endl; + config << std::setw(4) << j_sensor << std::endl; config.close(); with_header_ = false; }