diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index fd251e02..ebf1281e 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -19,7 +19,7 @@ endif() if(WITH_CUDA) ion_run(producerx3_gpu producerx3_compile SRCS producerx3_run.cc TARGET_STRING "host-cuda-cuda_capability_50-profile") - if(UNIX) + if(UNIX AND NOT APPLE) ion_run(sgm_gpu sgm_compile SRCS sgm_run.cc TARGET_STRING "host-cuda-cuda_capability_50-profile") ion_run(dnn_gpu dnn_compile SRCS dnn_run.cc TARGET_STRING "host-cuda-cuda_capability_50-profile") ion_run(demo_gpu demo_compile SRCS demo_run.cc TARGET_STRING "host-cuda-cuda_capability_50-profile") @@ -38,18 +38,22 @@ endif() ion_jit(isp_jit SRCS isp.cc) ion_jit(isp_and_sgm_jit SRCS isp_and_sgm.cc) ion_jit(dnn_jit SRCS dnn.cc) -ion_jit(v4l2_jit SRCS v4l2.cc) -ion_jit(realsense_jit SRCS realsense.cc) ion_jit(demo_jit SRCS demo.cc) ion_jit(imx219_isp_display_jit SRCS imx219_isp_display.cc) ion_jit(gender_count SRCS gender_count.cc) ion_jit(io SRCS io.cc) # ion_jit(u3v_jit SRCS u3v.cc) +if (UNIX AND NOT APPLE) + ion_jit(v4l2_jit SRCS v4l2.cc) + ion_jit(realsense_jit SRCS realsense.cc) + + ion_register_test(v4l2 v4l2_jit TARGET_STRING "host-profile") + ion_register_test(realsense realsense_jit TARGET_STRING "host-profile") +endif() + ion_register_test(isp isp_jit TARGET_STRING "host-profile") ion_register_test(isp_and_sgm isp_and_sgm_jit TARGET_STRING "host-profile") -ion_register_test(v4l2 v4l2_jit TARGET_STRING "host-profile") -ion_register_test(realsense realsense_jit TARGET_STRING "host-profile") if(WITH_CUDA) ion_register_test(isp_gpu isp_jit TARGET_STRING "host-cuda-cuda_capability_50-profile") # Temporaly disabled diff --git a/src/bb/dnn/config.cmake b/src/bb/dnn/config.cmake index c7f2b795..31884734 100644 --- a/src/bb/dnn/config.cmake +++ b/src/bb/dnn/config.cmake @@ -11,22 +11,22 @@ set(LINK_DIRS ${OpenCV_DIR}/lib) if (UNIX) -if (APPLE) - set(LIBRARIES - dl - pthread - m - z - ${OpenCV_LIBRARIES}) -else() - set(LIBRARIES - rt - dl - pthread - m - z - ${OpenCV_LIBRARIES}) -endif() + if (APPLE) + set(LIBRARIES + dl + pthread + m + z + ${OpenCV_LIBRARIES}) + else() + set(LIBRARIES + rt + dl + pthread + m + z + ${OpenCV_LIBRARIES}) + endif() else() set(LIBRARIES ${OpenCV_LIBRARIES}) endif() diff --git a/src/bb/image-io/bb.h b/src/bb/image-io/bb.h index 2f68a0b9..fe2a4389 100644 --- a/src/bb/image-io/bb.h +++ b/src/bb/image-io/bb.h @@ -110,191 +110,6 @@ uint32_t make_pixel_format(BayerMap::Pattern bayer_pattern, int32_t bit_width) int instance_id = 0; -class IMX219 : public ion::BuildingBlock { -public: - GeneratorParam gc_title{"gc_title", "IMX219"}; - GeneratorParam gc_description{"gc_description", "This captures IMX219 image."}; - GeneratorParam gc_tags{"gc_tags", "input,sensor"}; - GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; - GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; - GeneratorParam gc_strategy{"gc_strategy", "self"}; - GeneratorParam gc_prefix{"gc_prefix", ""}; - - GeneratorParam fps{"fps", 24}; - GeneratorParam width{"width", 3264}; - GeneratorParam height{"height", 2464}; - GeneratorParam index{"index", 0}; - GeneratorParam url{"url", ""}; - GeneratorParam force_sim_mode{"force_sim_mode", false}; - - GeneratorOutput output{"output", Halide::type_of(), 2}; - - void generate() { - using namespace Halide; - std::string url_str = url; - Halide::Buffer url_buf(url_str.size() + 1); - url_buf.fill(0); - std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); - - std::vector params = { - instance_id++, - cast(index), - cast(fps), - cast(width), - cast(height), - cast(Expr(V4L2_PIX_FMT_SRGGB10)), - cast(force_sim_mode), - url_buf, - 0.4f, 0.5f, 0.3125f, - 0.0625f, - 10, 6 - }; - Func v4l2_imx219(static_cast(gc_prefix) + "output"); - v4l2_imx219.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); - v4l2_imx219.compute_root(); - - output = v4l2_imx219; - } -}; - -class D435 : public ion::BuildingBlock { -public: - GeneratorParam gc_title{"gc_title", "D435"}; - GeneratorParam gc_description{"gc_description", "This captures D435 stereo image and depth."}; - GeneratorParam gc_tags{"gc_tags", "input,sensor"}; - GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output_l: [1280, 720], output_r: [1280, 720], output_d: [1280, 720] }}))"}; - GeneratorParam gc_mandatory{"gc_mandatory", ""}; - GeneratorParam gc_strategy{"gc_strategy", "self"}; - GeneratorParam gc_prefix{"gc_prefix", ""}; - - GeneratorOutput output_l{"output_l", Halide::type_of(), 2}; - GeneratorOutput output_r{"output_r", Halide::type_of(), 2}; - GeneratorOutput output_d{"output_d", Halide::type_of(), 2}; - - void generate() { - using namespace Halide; - Func realsense_d435_frameset(static_cast(gc_prefix) + "frameset"); - realsense_d435_frameset.define_extern("ion_bb_image_io_realsense_d435_frameset", {}, type_of(), 0); - realsense_d435_frameset.compute_root(); - - // TODO: Seperate channel - Func realsense_d435_infrared(static_cast(gc_prefix) + "output_lr"); - realsense_d435_infrared.define_extern("ion_bb_image_io_realsense_d435_infrared", {realsense_d435_frameset}, {type_of(), type_of()}, 2); - realsense_d435_infrared.compute_root(); - - Func realsense_d435_depth(static_cast(gc_prefix) + "output_d"); - realsense_d435_depth.define_extern("ion_bb_image_io_realsense_d435_depth", {realsense_d435_frameset}, type_of(), 2); - realsense_d435_depth.compute_root(); - - output_l(_) = realsense_d435_infrared(_)[0]; - output_r(_) = realsense_d435_infrared(_)[1]; - output_d = realsense_d435_depth; - } -}; - - -class GenericV4L2Bayer : public ion::BuildingBlock { -public: - GeneratorParam gc_title{"gc_title", "GenericV4L2Bayer"}; - GeneratorParam gc_description{"gc_description", "This captures Bayer image from V4L2."}; - GeneratorParam gc_tags{"gc_tags", "input,sensor"}; - GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; - GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; - GeneratorParam gc_strategy{"gc_strategy", "self"}; - GeneratorParam gc_prefix{"gc_prefix", ""}; - - GeneratorParam index{"index", 0}; - GeneratorParam url{"url", ""}; - GeneratorParam fps{"fps", 20}; - GeneratorParam width{"width", 0}; - GeneratorParam height{"height", 0}; - GeneratorParam bit_width{"bit_width", 10}; - GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; - GeneratorOutput output{"output", Halide::type_of(), 2}; - - void generate() { - using namespace Halide; - - std::string url_str = url; - Halide::Buffer url_buf(url_str.size() + 1); - url_buf.fill(0); - std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); - - std::vector params = { - instance_id++, - cast(index), - cast(fps), - cast(width), - cast(height), - Expr(make_pixel_format(bayer_pattern, bit_width)), - cast(0), - url_buf, - 1.f, 1.f, 1.f, - 0.f, - cast(bit_width), 16 - bit_width - }; - Func v4l2(static_cast(gc_prefix) + "output"); - v4l2.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); - v4l2.compute_root(); - - output = v4l2; - } -}; - -class CameraSimulation : public ion::BuildingBlock { -public: - GeneratorParam gc_title{"gc_title", "CameraSimulation"}; - GeneratorParam gc_description{"gc_description", "This simulates Bayer image."}; - GeneratorParam gc_tags{"gc_tags", "input,sensor"}; - GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; - GeneratorParam gc_mandatory{"gc_mandatory", "width,height,url"}; - GeneratorParam gc_strategy{"gc_strategy", "self"}; - GeneratorParam gc_prefix{"gc_prefix", ""}; - - GeneratorParam fps{"fps", 30}; - GeneratorParam width{"width", 0}; - GeneratorParam height{"height", 0}; - GeneratorParam url{"url", ""}; - GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; - GeneratorParam bit_width{"bit_width", 10}; - GeneratorParam bit_shift{"bit_shift", 0}; - GeneratorParam gain_r{"gain_r", 1.f}; - GeneratorParam gain_g{"gain_g", 1.f}; - GeneratorParam gain_b{"gain_b", 1.f}; - GeneratorParam offset{"offset", 0.f}; - - GeneratorOutput output{"output", Halide::type_of(), 2}; - - void generate() { - using namespace Halide; - std::string url_str = url; - Halide::Buffer url_buf(url_str.size() + 1); - url_buf.fill(0); - std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); - - std::vector params = { - instance_id++, - 0, - cast(fps), - cast(width), - cast(height), - Expr(make_pixel_format(bayer_pattern, bit_width)), - cast(1), - url_buf, - cast(gain_r), cast(gain_g), cast(gain_b), - cast(offset), - cast(bit_width), cast(bit_shift) - }; - Func camera(static_cast(gc_prefix) + "output"); - camera.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); - camera.compute_root(); - - output = camera; - } -}; -#endif - -int instance_id = 0; class Camera : public ion::BuildingBlock { public: @@ -502,6 +317,190 @@ class CameraN : public ion::BuildingBlock { } }; +class IMX219 : public ion::BuildingBlock { +public: + GeneratorParam gc_title{"gc_title", "IMX219"}; + GeneratorParam gc_description{"gc_description", "This captures IMX219 image."}; + GeneratorParam gc_tags{"gc_tags", "input,sensor"}; + GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; + GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; + GeneratorParam gc_strategy{"gc_strategy", "self"}; + GeneratorParam gc_prefix{"gc_prefix", ""}; + + GeneratorParam fps{"fps", 24}; + GeneratorParam width{"width", 3264}; + GeneratorParam height{"height", 2464}; + GeneratorParam index{"index", 0}; + GeneratorParam url{"url", ""}; + GeneratorParam force_sim_mode{"force_sim_mode", false}; + + GeneratorOutput output{"output", Halide::type_of(), 2}; + + void generate() { + using namespace Halide; + std::string url_str = url; + Halide::Buffer url_buf(url_str.size() + 1); + url_buf.fill(0); + std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); + + std::vector params = { + instance_id++, + cast(index), + cast(fps), + cast(width), + cast(height), + cast(Expr(V4L2_PIX_FMT_SRGGB10)), + cast(force_sim_mode), + url_buf, + 0.4f, 0.5f, 0.3125f, + 0.0625f, + 10, 6 + }; + Func v4l2_imx219(static_cast(gc_prefix) + "output"); + v4l2_imx219.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); + v4l2_imx219.compute_root(); + + output = v4l2_imx219; + } +}; + +class D435 : public ion::BuildingBlock { +public: + GeneratorParam gc_title{"gc_title", "D435"}; + GeneratorParam gc_description{"gc_description", "This captures D435 stereo image and depth."}; + GeneratorParam gc_tags{"gc_tags", "input,sensor"}; + GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output_l: [1280, 720], output_r: [1280, 720], output_d: [1280, 720] }}))"}; + GeneratorParam gc_mandatory{"gc_mandatory", ""}; + GeneratorParam gc_strategy{"gc_strategy", "self"}; + GeneratorParam gc_prefix{"gc_prefix", ""}; + + GeneratorOutput output_l{"output_l", Halide::type_of(), 2}; + GeneratorOutput output_r{"output_r", Halide::type_of(), 2}; + GeneratorOutput output_d{"output_d", Halide::type_of(), 2}; + + void generate() { + using namespace Halide; + Func realsense_d435_frameset(static_cast(gc_prefix) + "frameset"); + realsense_d435_frameset.define_extern("ion_bb_image_io_realsense_d435_frameset", {}, type_of(), 0); + realsense_d435_frameset.compute_root(); + + // TODO: Seperate channel + Func realsense_d435_infrared(static_cast(gc_prefix) + "output_lr"); + realsense_d435_infrared.define_extern("ion_bb_image_io_realsense_d435_infrared", {realsense_d435_frameset}, {type_of(), type_of()}, 2); + realsense_d435_infrared.compute_root(); + + Func realsense_d435_depth(static_cast(gc_prefix) + "output_d"); + realsense_d435_depth.define_extern("ion_bb_image_io_realsense_d435_depth", {realsense_d435_frameset}, type_of(), 2); + realsense_d435_depth.compute_root(); + + output_l(_) = realsense_d435_infrared(_)[0]; + output_r(_) = realsense_d435_infrared(_)[1]; + output_d = realsense_d435_depth; + } +}; + + +class GenericV4L2Bayer : public ion::BuildingBlock { +public: + GeneratorParam gc_title{"gc_title", "GenericV4L2Bayer"}; + GeneratorParam gc_description{"gc_description", "This captures Bayer image from V4L2."}; + GeneratorParam gc_tags{"gc_tags", "input,sensor"}; + GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; + GeneratorParam gc_mandatory{"gc_mandatory", "width,height"}; + GeneratorParam gc_strategy{"gc_strategy", "self"}; + GeneratorParam gc_prefix{"gc_prefix", ""}; + + GeneratorParam index{"index", 0}; + GeneratorParam url{"url", ""}; + GeneratorParam fps{"fps", 20}; + GeneratorParam width{"width", 0}; + GeneratorParam height{"height", 0}; + GeneratorParam bit_width{"bit_width", 10}; + GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; + GeneratorOutput output{"output", Halide::type_of(), 2}; + + void generate() { + using namespace Halide; + + std::string url_str = url; + Halide::Buffer url_buf(url_str.size() + 1); + url_buf.fill(0); + std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); + + std::vector params = { + instance_id++, + cast(index), + cast(fps), + cast(width), + cast(height), + Expr(make_pixel_format(bayer_pattern, bit_width)), + cast(0), + url_buf, + 1.f, 1.f, 1.f, + 0.f, + cast(bit_width), 16 - bit_width + }; + Func v4l2(static_cast(gc_prefix) + "output"); + v4l2.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); + v4l2.compute_root(); + + output = v4l2; + } +}; + +class CameraSimulation : public ion::BuildingBlock { +public: + GeneratorParam gc_title{"gc_title", "CameraSimulation"}; + GeneratorParam gc_description{"gc_description", "This simulates Bayer image."}; + GeneratorParam gc_tags{"gc_tags", "input,sensor"}; + GeneratorParam gc_inference{"gc_inference", R"((function(v){ return { output: [parseInt(v.width), parseInt(v.height)] }}))"}; + GeneratorParam gc_mandatory{"gc_mandatory", "width,height,url"}; + GeneratorParam gc_strategy{"gc_strategy", "self"}; + GeneratorParam gc_prefix{"gc_prefix", ""}; + + GeneratorParam fps{"fps", 30}; + GeneratorParam width{"width", 0}; + GeneratorParam height{"height", 0}; + GeneratorParam url{"url", ""}; + GeneratorParam bayer_pattern{"bayer_pattern", BayerMap::Pattern::RGGB, BayerMap::enum_map}; + GeneratorParam bit_width{"bit_width", 10}; + GeneratorParam bit_shift{"bit_shift", 0}; + GeneratorParam gain_r{"gain_r", 1.f}; + GeneratorParam gain_g{"gain_g", 1.f}; + GeneratorParam gain_b{"gain_b", 1.f}; + GeneratorParam offset{"offset", 0.f}; + + GeneratorOutput output{"output", Halide::type_of(), 2}; + + void generate() { + using namespace Halide; + std::string url_str = url; + Halide::Buffer url_buf(url_str.size() + 1); + url_buf.fill(0); + std::memcpy(url_buf.data(), url_str.c_str(), url_str.size()); + + std::vector params = { + instance_id++, + 0, + cast(fps), + cast(width), + cast(height), + Expr(make_pixel_format(bayer_pattern, bit_width)), + cast(1), + url_buf, + cast(gain_r), cast(gain_g), cast(gain_b), + cast(offset), + cast(bit_width), cast(bit_shift) + }; + Func camera(static_cast(gc_prefix) + "output"); + camera.define_extern("ion_bb_image_io_v4l2", params, type_of(), 2); + camera.compute_root(); + + output = camera; + } +}; +#endif + class GUIDisplay : public ion::BuildingBlock { public: @@ -1204,11 +1203,13 @@ ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::D435, image_io_d435); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::GenericV4L2Bayer, image_io_generic_v4l2_bayer); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::CameraSimulation, image_io_camera_simulation); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::FBDisplay, image_io_fb_display); -#endif ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::Camera, image_io_camera); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::Camera2, image_io_camera2); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::CameraN, image_io_cameraN); +#endif + + ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::ColorDataLoader, image_io_color_data_loader); ION_REGISTER_BUILDING_BLOCK(ion::bb::image_io::GrayscaleDataLoader, image_io_grayscale_data_loader); diff --git a/src/bb/image-io/rt.h b/src/bb/image-io/rt.h index 26f28e15..98f2fbb5 100644 --- a/src/bb/image-io/rt.h +++ b/src/bb/image-io/rt.h @@ -29,9 +29,9 @@ class RegisterExtern { #include "rt_u3v.h" #include "rt_file.h" +#include "rt_display.h" #ifdef __linux__ -#include "rt_display.h" #include "rt_realsense.h" #include "rt_v4l2.h" #endif diff --git a/src/bb/image-io/rt_common.h b/src/bb/image-io/rt_common.h index ec58e2eb..a92c5f20 100644 --- a/src/bb/image-io/rt_common.h +++ b/src/bb/image-io/rt_common.h @@ -154,7 +154,7 @@ std::tuple parse_url(const std::string &url) { return std::tuple(host_name, path_name); } -#ifdef __linux__ + cv::Mat get_image(const std::string &url) { if (url.empty()) { return {}; @@ -291,7 +291,7 @@ class ImageSequence { int32_t idx_; std::vector paths_; }; -#endif // _WIN32 + struct rawHeader { diff --git a/src/bb/image-io/rt_file.h b/src/bb/image-io/rt_file.h index ef05591c..6d18ed0e 100644 --- a/src/bb/image-io/rt_file.h +++ b/src/bb/image-io/rt_file.h @@ -17,12 +17,10 @@ #include "rt_common.h" #include "httplib.h" -#ifdef __linux__ #include #include -#endif -#ifdef __linux__ + extern "C" int ION_EXPORT ion_bb_image_io_color_data_loader(halide_buffer_t *session_id_buf, halide_buffer_t *url_buf, int32_t width, int32_t height, halide_buffer_t *out) { using namespace ion::bb::image_io; @@ -128,7 +126,7 @@ extern "C" int ION_EXPORT ion_bb_image_io_saver(halide_buffer_t *in, int32_t in_ return 0; } ION_REGISTER_EXTERN(ion_bb_image_io_saver); -#endif + namespace { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 77858d27..622a562e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -64,6 +64,7 @@ ion_jit(port-binding SRCS port-binding.cc) add_dependencies(port-binding ion-bb-test) ion_register_test(port-binding_test port-binding) +if(UNIX AND NOT APPLE) # Port index access ion_jit(port-access SRCS port-access.cc) add_dependencies(port-access ion-bb-test) @@ -73,6 +74,7 @@ ion_register_test(port-access_test port-access) ion_jit(portmap-access SRCS portmap-access.cc) add_dependencies(portmap-access ion-bb-test) ion_register_test(portmap-access_test portmap-access) +endif() ion_jit(direct-extern SRCS direct-extern.cc) add_dependencies(direct-extern ion-bb-test)