Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging release/v1 #279

Merged
merged 11 commits into from
May 23, 2024
17 changes: 14 additions & 3 deletions src/bb/image-io/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ class U3VCameraN : public ion::BuildingBlock<U3VCameraN<T, D>> {

Output<Halide::Func[]> output{ "output", Halide::type_of<T>(), D};
Output<Halide::Func[]> device_info{ "device_info", Halide::type_of<uint8_t>(), 1};
Output<Halide::Func> frame_count{ "frame_count", Halide::type_of<uint32_t>(), 1 };
Output<Halide::Func[]> frame_count{ "frame_count", Halide::type_of<uint32_t>(), 1 };

std::vector<Input<double> *> gain;
std::vector<Input<double> *> exposure;
Expand Down Expand Up @@ -964,9 +964,20 @@ class U3VCameraN : public ion::BuildingBlock<U3VCameraN<T, D>> {
pixel_format_buf
};

cameraN_fc.define_extern("ion_bb_image_io_u3v_multiple_camera_frame_count" + std::to_string(output.size()), params, type_of<uint32_t>(), 1);
frame_count.resize(num_devices);
std::vector<Halide::Type> output_type;
for (int i = 0; i < frame_count.size(); i++) {
output_type.push_back(Halide::type_of<uint32_t>());
}
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");
}
Expand Down
53 changes: 23 additions & 30 deletions src/bb/image-io/rt_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ class Writer {
}

void post_image(std::vector<void *>& outs, std::vector<size_t>& size,
std::vector<ion::bb::image_io::rawHeader>& 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_; });
Expand All @@ -161,10 +161,10 @@ class Writer {
task_cv_.notify_one();
}

void post_gendc(std::vector<void *>& outs, std::vector<size_t>& size, std::vector<ion::bb::image_io::rawHeader>& header_infos)
void post_gendc(std::vector<void *>& outs, std::vector<size_t>& 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_; });
Expand Down Expand Up @@ -209,22 +209,18 @@ class Writer {

}

void write_config_file(std::vector<ion::bb::image_io::rawHeader>& header_infos){
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;
}

::std::ofstream config(output_directory_ / "config.json");
config << std::setw(4) << j << std::endl;
void write_config_file(ion::bb::image_io::rawHeader& header_info){
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;

auto filename = prefix_ + "config.json";
std::ofstream config(output_directory_ / filename);
config << std::setw(4) << j_sensor << std::endl;
config.close();

with_header_ = false;
}

Expand Down Expand Up @@ -394,13 +390,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<ion::bb::image_io::rawHeader> header_infos{header_info0};
ion::bb::image_io::rawHeader header_info;
::memcpy(&header_info, deviceinfo->host, sizeof(ion::bb::image_io::rawHeader));

std::vector<void *> obufs{gendc->host};
std::vector<size_t> 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);


}
Expand Down Expand Up @@ -458,15 +453,13 @@ int ion_bb_image_io_binary_image_saver(
return 0;
}
else {


ion::bb::image_io::rawHeader header_info0;
::memcpy(&header_info0, deviceinfo->host, sizeof(ion::bb::image_io::rawHeader));
std::vector<ion::bb::image_io::rawHeader> header_infos{header_info0};
ion::bb::image_io::rawHeader header_info;
memcpy(&header_info, deviceinfo->host, sizeof(ion::bb::image_io::rawHeader));
std::vector<ion::bb::image_io::rawHeader> header_infos{header_info};

std::vector<void *> obufs{image->host};
std::vector<size_t> 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;
Expand Down Expand Up @@ -716,4 +709,4 @@ int binaryloader_finished(halide_buffer_t* in0, halide_buffer_t* in1, halide_buf
}
ION_REGISTER_EXTERN(binaryloader_finished);

#endif
#endif
25 changes: 13 additions & 12 deletions src/bb/image-io/rt_u3v.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ class U3V {
virtual void get(std::vector<Halide::Buffer<>>& outs){};
virtual void get(std::vector<void *>& outs){};

void get_frame_count(uint32_t * out){
void get_frame_count(std::vector<void *>& 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));
}
}
}
Expand Down Expand Up @@ -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<void *> 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<uint32_t*>(out->host));
u3v.get_frame_count(obufs);
}

return 0;
Expand Down Expand Up @@ -1967,17 +1968,18 @@ int ION_EXPORT ion_bb_image_io_u3v_multiple_camera_frame_count1(
try {
const std::string id(reinterpret_cast<const char *>(id_buf->host));
const std::string pixel_format(reinterpret_cast<const char *>(pixel_format_buf->host));
std::vector<void *> obufs{out->host};
if (out->is_bounds_query()) {
out->dim[0].min = 0;
out->dim[0].extent = num_sensor;
return 0;
}
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<uint32_t*>(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<uint32_t*>(out->host));
u3v.get_frame_count(obufs);
}

return 0;
Expand All @@ -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<const char *>(id_buf->host));
const std::string pixel_format(reinterpret_cast<const char *>(pixel_format_buf->host));
if (out->is_bounds_query()) {
out->dim[0].min = 0;
out->dim[0].extent = num_sensor;
std::vector<void *> 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<uint32_t*>(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<uint32_t*>(out->host));
u3v.get_frame_count(obufs);
}
return 0;
} catch (const std::exception &e) {
Expand Down
Loading