From 11171c936466dfd90bcfc9048de84ebca2962276 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Thu, 4 Apr 2024 15:17:12 -0400 Subject: [PATCH 1/5] gather some data --- .../workflows/delivered-height-vs-height.yml | 61 +++++ sandbox/CMakeLists.txt | 37 +++ sandbox/delivered-height-vs-height.cpp | 218 ++++++++++++++++++ 3 files changed, 316 insertions(+) create mode 100644 .github/workflows/delivered-height-vs-height.yml create mode 100644 sandbox/delivered-height-vs-height.cpp diff --git a/.github/workflows/delivered-height-vs-height.yml b/.github/workflows/delivered-height-vs-height.yml new file mode 100644 index 0000000..87b4cfd --- /dev/null +++ b/.github/workflows/delivered-height-vs-height.yml @@ -0,0 +1,61 @@ +name: Gather delivered height vs. height dataset + +on: workflow_call + +env: + BUILD_TYPE: Release + +jobs: + run-program: + name: "Build on Windows with eGrabber SDK" + runs-on: + - self-hosted + - egrabber + - VC-151MX-M6H00 + - windows + + permissions: + actions: write + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.10.0 + with: + access_token: ${{ github.token }} + + - name: Enable long paths + run: | + git config --global core.longpaths true + shell: pwsh + + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: true + + - name: Get CMake 3.24 + uses: lukka/get-cmake@latest + with: + useCloudCache: false + useLocalCache: true + cmakeVersion: 3.24.3 + + - name: Install MSVC + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: amd64_x86 + + - name: Build + run: | + cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DWITH_SANDBOX=ON + cmake --build ${{github.workspace}}/build --config Release + + - name: Run + working-directory: ${{github.workspace}} + run: | + ${{github.workspace}}/build/sandbox/Release/acquire-driver-egrabber-delivered-height-vs-height.exe + + - uses: actions/upload-artifact@v3 + with: + name: Dataset + path: ${{github.workspace}}/*.zip diff --git a/sandbox/CMakeLists.txt b/sandbox/CMakeLists.txt index 3475344..1049da8 100644 --- a/sandbox/CMakeLists.txt +++ b/sandbox/CMakeLists.txt @@ -6,6 +6,7 @@ if (${WITH_SANDBOX}) # set(project acquire-driver-egrabber) # CMAKE_PROJECT_NAME gets overridden if this is a subtree of another project + ### Playground set(tgt ${project}-playground) add_executable(${tgt} playground.cpp) set_target_properties(${tgt} PROPERTIES @@ -16,4 +17,40 @@ if (${WITH_SANDBOX}) egrabber acquire-core-logger acquire-core-platform) + + ### Delivered height vs. height + set(tgt ${project}-delivered-height-vs-height) + + set(NO_TEST ${NOTEST}) + set(NOTEST "FALSE") + add_subdirectory(../acquire-common/acquire-driver-common ${CMAKE_CURRENT_BINARY_DIR}/acquire-driver-common) + add_subdirectory(../acquire-common/acquire-video-runtime ${CMAKE_CURRENT_BINARY_DIR}/acquire-video-runtime) + set(NOTEST ${NO_TEST}) + add_subdirectory(../tests/acquire-driver-zarr ${CMAKE_CURRENT_BINARY_DIR}/acquire-driver-zarr) + + add_executable(${tgt} delivered-height-vs-height.cpp) + set_target_properties(${tgt} PROPERTIES + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" + ) + target_include_directories(${tgt} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/../") + target_link_libraries(${tgt} PRIVATE + egrabber + acquire-core-logger + acquire-core-platform + acquire-video-runtime) + + foreach(driver + acquire-driver-egrabber + acquire-driver-zarr) + add_custom_target(${project}-copy-${driver}-for-delivered-height-vs-height + COMMAND ${CMAKE_COMMAND} -E copy + $ + $ + DEPENDS ${driver} + COMMENT "Copying ${driver} to $") + + foreach(name ${tests}) + add_dependencies(${tgt} ${project}-copy-${driver}-for-delivered-height-vs-height) + endforeach() + endforeach() endif () diff --git a/sandbox/delivered-height-vs-height.cpp b/sandbox/delivered-height-vs-height.cpp new file mode 100644 index 0000000..09e5857 --- /dev/null +++ b/sandbox/delivered-height-vs-height.cpp @@ -0,0 +1,218 @@ +#include "acquire.h" +#include "device/hal/device.manager.h" +#include "platform.h" +#include "logger.h" + +#include +#include +#include + +static class IntrospectiveLogger +{ + public: + explicit IntrospectiveLogger() + : different_heights_(false){}; + + // inspect for "[stream 0] Dropped", otherwise pass the mesage through + void report_and_inspect(int is_error, + const char* file, + int line, + const char* function, + const char* msg) + { + std::string m(msg); + if (m.find("Delivered height and height are different:")) { + different_heights_ = true; + } + + printf("%s%s(%d) - %s: %s\n", + is_error ? "ERROR " : "", + file, + line, + function, + msg); + } + + [[nodiscard]] bool different_heights() const { return different_heights_; } + + private: + bool different_heights_; +} introspective_logger; + +static void +reporter(int is_error, + const char* file, + int line, + const char* function, + const char* msg) +{ + introspective_logger.report_and_inspect( + is_error, file, line, function, msg); +} + +/// Helper for passing size static strings as function args. +/// For a function: `f(char*,size_t)` use `f(SIZED("hello"))`. +/// Expands to `f("hello",5)`. +#define SIZED(str) str, sizeof(str) + +#define L (aq_logger) +#define LOG(...) L(0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) +#define ERR(...) L(1, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) +#define EXPECT(e, ...) \ + do { \ + if (!(e)) { \ + char buf[1 << 8] = { 0 }; \ + ERR(__VA_ARGS__); \ + snprintf(buf, sizeof(buf) - 1, __VA_ARGS__); \ + throw std::runtime_error(buf); \ + } \ + } while (0) +#define CHECK(e) EXPECT(e, "Expression evaluated as false: %s", #e) +#define DEVOK(e) CHECK(Device_Ok == (e)) +#define OK(e) CHECK(AcquireStatus_Ok == (e)) + +int +main() +{ + auto runtime = acquire_init(reporter); + + try { + CHECK(runtime); + auto dm = acquire_device_manager(runtime); + CHECK(dm); + + AcquireProperties props = {}; + OK(acquire_get_configuration(runtime, &props)); + + DEVOK(device_manager_select(dm, + DeviceKind_Camera, + SIZED("VIEWORKS.*") - 1, + &props.video[0].camera.identifier)); + DEVOK(device_manager_select(dm, + DeviceKind_Storage, + SIZED("tiff") - 1, + &props.video[0].storage.identifier)); + + storage_properties_init(&props.video[0].storage.settings, + 0, + SIZED("vieworks.zarr"), + 0, + 0, + { 0 }, + 0); + + // avoid initing w zero shape + props.video[0].camera.settings.shape = { + .x = 14192, + .y = 10640, + }; + + OK(acquire_configure(runtime, &props)); + + AcquirePropertyMetadata metadata = { 0 }; + OK(acquire_get_configuration_metadata(runtime, &metadata)); + + props.video[0].camera.settings.binning = 1; + props.video[0].camera.settings.pixel_type = SampleType_u12; + props.video[0].camera.settings.shape = { + .x = (uint32_t)metadata.video[0].camera.shape.x.high, + .y = (uint32_t)metadata.video[0].camera.shape.y.high, + }; + props.video[0].camera.settings.exposure_time_us = 1e4; + props.video[0].max_frame_count = 1000; + + OK(acquire_configure(runtime, &props)); + + const auto next = [](VideoFrame* cur) -> VideoFrame* { + return (VideoFrame*)(((uint8_t*)cur) + cur->bytes_of_frame); + }; + + const auto consumed_bytes = [](const VideoFrame* const cur, + const VideoFrame* const end) -> size_t { + return (uint8_t*)end - (uint8_t*)cur; + }; + + struct clock clock; + static double time_limit_ms = + (double)props.video[0].max_frame_count * + props.video[0].camera.settings.exposure_time_us / 1000.0; + clock_init(&clock); + clock_shift_ms(&clock, time_limit_ms); + OK(acquire_start(runtime)); + { + uint64_t nframes = 0; + VideoFrame *beg, *end, *cur; + + while (DeviceState_Running == acquire_get_state(runtime) && + nframes < props.video[0].max_frame_count && + !introspective_logger.different_heights()) { + struct clock throttle = { 0 }; + clock_init(&throttle); + EXPECT(clock_cmp_now(&clock) < 0, + "Timeout at %f ms", + clock_toc_ms(&clock) + time_limit_ms); + OK(acquire_map_read(runtime, 0, &beg, &end)); + for (cur = beg; cur < end; cur = next(cur)) { + LOG("stream %d counting frame w id %d (nframes = %d)", + 0, + cur->frame_id, + nframes); + CHECK(cur->shape.dims.width == + props.video[0].camera.settings.shape.x); + CHECK(cur->shape.dims.height == + props.video[0].camera.settings.shape.y); + ++nframes; + } + + { + uint32_t n = (uint32_t)consumed_bytes(beg, end); + OK(acquire_unmap_read(runtime, 0, n)); + if (n) + LOG("stream %d consumed bytes %d", 0, n); + } + clock_sleep_ms(&throttle, 100.0f); + + LOG("stream %d nframes %d. remaining time %f s", + 0, + nframes, + -1e-3 * clock_toc_ms(&clock)); + } + + do { + OK(acquire_map_read(runtime, 0, &beg, &end)); + for (cur = beg; cur < end; cur = next(cur)) { + LOG("[Flush] stream %d counting frame w id %d", + 0, + cur->frame_id); + CHECK(cur->shape.dims.width == + props.video[0].camera.settings.shape.x); + CHECK(cur->shape.dims.height == + props.video[0].camera.settings.shape.y); + ++nframes; + } + + { + uint32_t n = (uint32_t)consumed_bytes(beg, end); + OK(acquire_unmap_read(runtime, 0, n)); + if (n) + LOG("[Flush] stream %d consumed bytes %d", 0, n); + } + } while (beg != end); + + CHECK(nframes == props.video[0].max_frame_count); + } + + OK(acquire_abort(runtime)); + + CHECK(introspective_logger.different_heights()); + OK(acquire_shutdown(runtime)); + return 0; + } catch (const std::runtime_error& e) { + ERR("Runtime error: %s", e.what()); + + } catch (...) { + ERR("Uncaught exception"); + } + acquire_shutdown(runtime); + return 1; +} From 16ab183fe20c23cec651a1687a1677479c92534d Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Thu, 4 Apr 2024 15:19:05 -0400 Subject: [PATCH 2/5] Change workflow to pull_request target. --- .github/workflows/delivered-height-vs-height.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/delivered-height-vs-height.yml b/.github/workflows/delivered-height-vs-height.yml index 87b4cfd..163c4f7 100644 --- a/.github/workflows/delivered-height-vs-height.yml +++ b/.github/workflows/delivered-height-vs-height.yml @@ -1,6 +1,9 @@ name: Gather delivered height vs. height dataset -on: workflow_call +on: + pull_request: + branches: + - main env: BUILD_TYPE: Release From 1b48f920b731ab6c38f9f7337867112fa01cf312 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Thu, 4 Apr 2024 15:38:46 -0400 Subject: [PATCH 3/5] Set NOTEST=TRUE in delivered-height-vs-height workflow. --- .github/workflows/delivered-height-vs-height.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/delivered-height-vs-height.yml b/.github/workflows/delivered-height-vs-height.yml index 163c4f7..20688db 100644 --- a/.github/workflows/delivered-height-vs-height.yml +++ b/.github/workflows/delivered-height-vs-height.yml @@ -10,7 +10,7 @@ env: jobs: run-program: - name: "Build on Windows with eGrabber SDK" + name: "Gather some data" runs-on: - self-hosted - egrabber @@ -50,7 +50,7 @@ jobs: - name: Build run: | - cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DWITH_SANDBOX=ON + cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DNOTEST="TRUE" -DWITH_SANDBOX=ON cmake --build ${{github.workspace}}/build --config Release - name: Run From 3bb5f9d3d546f3d570dc891481b943faf0acb6b5 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Thu, 4 Apr 2024 15:50:43 -0400 Subject: [PATCH 4/5] wip --- .../workflows/delivered-height-vs-height.yml | 28 +++++++-------- sandbox/CMakeLists.txt | 36 ------------------- tests/CMakeLists.txt | 1 + .../delivered-height-vs-height.cpp | 1 - 4 files changed, 15 insertions(+), 51 deletions(-) rename {sandbox => tests}/delivered-height-vs-height.cpp (99%) diff --git a/.github/workflows/delivered-height-vs-height.yml b/.github/workflows/delivered-height-vs-height.yml index 20688db..c9f9ece 100644 --- a/.github/workflows/delivered-height-vs-height.yml +++ b/.github/workflows/delivered-height-vs-height.yml @@ -1,4 +1,4 @@ -name: Gather delivered height vs. height dataset +name: Tests on: pull_request: @@ -9,13 +9,11 @@ env: BUILD_TYPE: Release jobs: - run-program: - name: "Gather some data" + test: runs-on: - self-hosted - egrabber - VC-151MX-M6H00 - - windows permissions: actions: write @@ -35,6 +33,7 @@ jobs: uses: actions/checkout@v3 with: submodules: true + ref: ${{ github.event.pull_request.head.sha }} - name: Get CMake 3.24 uses: lukka/get-cmake@latest @@ -48,17 +47,18 @@ jobs: with: arch: amd64_x86 + - name: Configure + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Build - run: | - cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DNOTEST="TRUE" -DWITH_SANDBOX=ON - cmake --build ${{github.workspace}}/build --config Release + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - name: Run - working-directory: ${{github.workspace}} - run: | - ${{github.workspace}}/build/sandbox/Release/acquire-driver-egrabber-delivered-height-vs-height.exe + - name: Test + working-directory: ${{github.workspace}}/build + run: ctest -C ${{env.BUILD_TYPE}} -L acquire-driver-egrabber --output-on-failure - - uses: actions/upload-artifact@v3 + - name: Upload + uses: actions/upload-artifact@v3 with: - name: Dataset - path: ${{github.workspace}}/*.zip + name: Zarr dataset + path: ${{github.workspace}}/*.zarr diff --git a/sandbox/CMakeLists.txt b/sandbox/CMakeLists.txt index 1049da8..39afaf5 100644 --- a/sandbox/CMakeLists.txt +++ b/sandbox/CMakeLists.txt @@ -17,40 +17,4 @@ if (${WITH_SANDBOX}) egrabber acquire-core-logger acquire-core-platform) - - ### Delivered height vs. height - set(tgt ${project}-delivered-height-vs-height) - - set(NO_TEST ${NOTEST}) - set(NOTEST "FALSE") - add_subdirectory(../acquire-common/acquire-driver-common ${CMAKE_CURRENT_BINARY_DIR}/acquire-driver-common) - add_subdirectory(../acquire-common/acquire-video-runtime ${CMAKE_CURRENT_BINARY_DIR}/acquire-video-runtime) - set(NOTEST ${NO_TEST}) - add_subdirectory(../tests/acquire-driver-zarr ${CMAKE_CURRENT_BINARY_DIR}/acquire-driver-zarr) - - add_executable(${tgt} delivered-height-vs-height.cpp) - set_target_properties(${tgt} PROPERTIES - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" - ) - target_include_directories(${tgt} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/../") - target_link_libraries(${tgt} PRIVATE - egrabber - acquire-core-logger - acquire-core-platform - acquire-video-runtime) - - foreach(driver - acquire-driver-egrabber - acquire-driver-zarr) - add_custom_target(${project}-copy-${driver}-for-delivered-height-vs-height - COMMAND ${CMAKE_COMMAND} -E copy - $ - $ - DEPENDS ${driver} - COMMENT "Copying ${driver} to $") - - foreach(name ${tests}) - add_dependencies(${tgt} ${project}-copy-${driver}-for-delivered-height-vs-height) - endforeach() - endforeach() endif () diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9e3384a..6324ca6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,6 +22,7 @@ else() one-video-stream repeat-start repeat-start-no-stop + delivered-height-vs-height ) foreach(name ${tests}) diff --git a/sandbox/delivered-height-vs-height.cpp b/tests/delivered-height-vs-height.cpp similarity index 99% rename from sandbox/delivered-height-vs-height.cpp rename to tests/delivered-height-vs-height.cpp index 09e5857..74ec224 100644 --- a/sandbox/delivered-height-vs-height.cpp +++ b/tests/delivered-height-vs-height.cpp @@ -13,7 +13,6 @@ static class IntrospectiveLogger explicit IntrospectiveLogger() : different_heights_(false){}; - // inspect for "[stream 0] Dropped", otherwise pass the mesage through void report_and_inspect(int is_error, const char* file, int line, From b80a02d4ea6f424acb26ad4561ccd47cf51e5327 Mon Sep 17 00:00:00 2001 From: Alan Liddell Date: Thu, 4 Apr 2024 16:00:20 -0400 Subject: [PATCH 5/5] wip --- .github/workflows/delivered-height-vs-height.yml | 4 ++-- tests/CMakeLists.txt | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/delivered-height-vs-height.yml b/.github/workflows/delivered-height-vs-height.yml index c9f9ece..d51d8ac 100644 --- a/.github/workflows/delivered-height-vs-height.yml +++ b/.github/workflows/delivered-height-vs-height.yml @@ -1,4 +1,4 @@ -name: Tests +name: Collect dataset on: pull_request: @@ -55,7 +55,7 @@ jobs: - name: Test working-directory: ${{github.workspace}}/build - run: ctest -C ${{env.BUILD_TYPE}} -L acquire-driver-egrabber --output-on-failure + run: ctest -C ${{env.BUILD_TYPE}} -L collect-dataset --output-on-failure - name: Upload uses: actions/upload-artifact@v3 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6324ca6..41584ef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -40,7 +40,11 @@ else() ) add_test(NAME test-${tgt} COMMAND ${tgt}) - set_tests_properties(test-${tgt} PROPERTIES LABELS acquire-driver-egrabber) + if (name MATCHES "delivered-height-vs-height$") + set_tests_properties(test-${tgt} PROPERTIES LABELS collect-dataset) + else() + set_tests_properties(test-${tgt} PROPERTIES LABELS acquire-driver-egrabber) + endif() endforeach() #