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

Fix/separate gendc bin file #268

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
66 changes: 23 additions & 43 deletions src/bb/image-io/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ template<typename T, int D>
class BinarySaver : public ion::BuildingBlock<BinarySaver<T, D>> {
public:
BuildingBlockParam<std::string> output_directory_ptr{ "output_directory", "." };
BuildingBlockParam<int32_t> num_devices{"num_devices", 2};
BuildingBlockParam<std::string> prefix_ptr{"prefix", "raw-"};

Input<Halide::Func> input_images{"input", Halide::type_of<T>(), D};
Expand All @@ -1125,8 +1124,6 @@ class BinarySaver : public ion::BuildingBlock<BinarySaver<T, D>> {
void generate() {
using namespace Halide;

int32_t num_gendc = static_cast<int32_t>(num_devices);

const std::string output_directory(output_directory_ptr);
Halide::Buffer<uint8_t> output_directory_buf(static_cast<int>(output_directory.size() + 1));
output_directory_buf.fill(0);
Expand Down Expand Up @@ -1173,10 +1170,10 @@ class BinaryGenDCSaver : public ion::BuildingBlock<BinaryGenDCSaver> {
public:
BuildingBlockParam<std::string> output_directory_ptr{ "output_directory", "." };

BuildingBlockParam<int32_t> num_devices{"num_devices", 2};
BuildingBlockParam<std::string> prefix_ptr{"prefix", "raw-"};

Input<Halide::Func[]> input_gendc{ "input_gendc", Halide::type_of<uint8_t>(), 1 };
Input<Halide::Func[]> input_deviceinfo{ "input_deviceinfo", Halide::type_of<uint8_t>(), 1 };
Input<Halide::Func> input_gendc{ "input_gendc", Halide::type_of<uint8_t>(), 1 };
Input<Halide::Func> input_deviceinfo{ "input_deviceinfo", Halide::type_of<uint8_t>(), 1 };


Input<int32_t> payloadsize{ "payloadsize" };
Expand All @@ -1185,49 +1182,32 @@ class BinaryGenDCSaver : public ion::BuildingBlock<BinaryGenDCSaver> {

void generate() {
using namespace Halide;
int32_t num_gendc = static_cast<int32_t>(num_devices);

const std::string prefix(prefix_ptr);
Halide::Buffer<uint8_t> prefix_buf(static_cast<int>(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<uint8_t> output_directory_buf(static_cast<int>(output_directory.size() + 1));
output_directory_buf.fill(0);
std::memcpy(output_directory_buf.data(), output_directory.c_str(), output_directory.size());
Buffer<uint8_t> 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<ExternFuncArgument> 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<ExternFuncArgument> 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<ExternFuncArgument> 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");
}
};
Expand Down
66 changes: 5 additions & 61 deletions src/bb/image-io/rt_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(id_buf->host));
const ::std::string output_directory(reinterpret_cast<const char*>(output_directory_buf->host));
std::vector<int32_t>payloadsize_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<ion::bb::image_io::rawHeader> header_infos{header_info0, header_info1};

std::vector<void *> obufs{in0->host, in1->host};
std::vector<size_t> 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<const char *>(id_buf->host));
const ::std::string output_directory(reinterpret_cast<const char*>(output_directory_buf->host));
std::vector<int32_t>payloadsize_list{payloadsize};
auto& w(Writer::get_instance(id,payloadsize_list, output_directory, false));
const ::std::string prefix(reinterpret_cast<const char*>(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;
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 14 additions & 2 deletions src/bb/image-io/rt_u3v.h
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,20 @@ class U3VGenDC: public U3V{

int32_t num_device = devices_.size();
std::vector<ArvBuffer *> bufs(num_device);

if (operation_mode_ == OperationMode::Came2USB2 || operation_mode_ == OperationMode::Came1USB1){
if (sim_mode_){
std::vector<ArvBuffer *> 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);
Expand Down
Loading