|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ludovic Henry <git@ludovic.dev> |
| 3 | +Date: Mon, 21 Sep 2026 20:00:00 +0000 |
| 4 | +Subject: [PATCH] use schedule(static) for the dynamic and guided OpenMP loops |
| 5 | + |
| 6 | +Upstream-Status: Inappropriate [works around a libgomp defect on the riscv64 runners, riseproject-dev/python-wheels#617] |
| 7 | + |
| 8 | +libgomp's dynamic and guided work-share schedules fault on the riscv64 |
| 9 | +machines these wheels are built and tested on (see CLAUDE.md gotcha 166). |
| 10 | +copy_fuji_uncropped/copy_bayer in raw2image.cpp run schedule(dynamic) on |
| 11 | +every single postprocess() call regardless of camera or demosaic |
| 12 | +algorithm, and ahd_demosaic.cpp (the default demosaic algorithm) and |
| 13 | +dht_demosaic.cpp (the optional DHT algorithm) run schedule(dynamic)/ |
| 14 | +schedule(guided) too, so this is reachable by ordinary decoding, not an |
| 15 | +edge case. |
| 16 | + |
| 17 | +Moving all 16 affected loops in the vendored LibRaw copy to |
| 18 | +schedule(static) costs only load balancing on rows/columns whose |
| 19 | +iterations differ in cost, and buys a wheel that does not crash. Revert |
| 20 | +once the runners' toolchain is fixed. |
| 21 | +--- |
| 22 | + external/LibRaw/src/demosaic/ahd_demosaic.cpp | 2 +- |
| 23 | + external/LibRaw/src/demosaic/dht_demosaic.cpp | 26 +++++++++++++------------- |
| 24 | + external/LibRaw/src/preprocessing/raw2image.cpp | 4 ++-- |
| 25 | + 3 files changed, 16 insertions(+), 16 deletions(-) |
| 26 | + |
| 27 | +diff --git a/external/LibRaw/src/demosaic/ahd_demosaic.cpp b/external/LibRaw/src/demosaic/ahd_demosaic.cpp |
| 28 | +index ae87b28..ae6ad6d 100644 |
| 29 | +--- a/external/LibRaw/src/demosaic/ahd_demosaic.cpp |
| 30 | ++++ b/external/LibRaw/src/demosaic/ahd_demosaic.cpp |
| 31 | +@@ -306,7 +306,7 @@ void LibRaw::ahd_interpolate() |
| 32 | + char** buffers = malloc_omp_buffers(buffer_count, buffer_size); |
| 33 | + |
| 34 | + #ifdef LIBRAW_USE_OPENMP |
| 35 | +-#pragma omp parallel for schedule(dynamic) default(none) shared(terminate_flag) firstprivate(buffers) |
| 36 | ++#pragma omp parallel for schedule(static) default(none) shared(terminate_flag) firstprivate(buffers) |
| 37 | + #endif |
| 38 | + for (int top = 2; top < height - 5; top += LIBRAW_AHD_TILE - 6) |
| 39 | + { |
| 40 | +diff --git a/external/LibRaw/src/demosaic/dht_demosaic.cpp b/external/LibRaw/src/demosaic/dht_demosaic.cpp |
| 41 | +index 9fa603f..b23dc61 100644 |
| 42 | +--- a/external/LibRaw/src/demosaic/dht_demosaic.cpp |
| 43 | ++++ b/external/LibRaw/src/demosaic/dht_demosaic.cpp |
| 44 | +@@ -259,7 +259,7 @@ void DHT::hide_hots() |
| 45 | + { |
| 46 | + int iwidth = libraw.imgdata.sizes.iwidth; |
| 47 | + #if defined(LIBRAW_USE_OPENMP) |
| 48 | +-#pragma omp parallel for schedule(guided) firstprivate(iwidth) |
| 49 | ++#pragma omp parallel for schedule(static) firstprivate(iwidth) |
| 50 | + #endif |
| 51 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 52 | + { |
| 53 | +@@ -401,7 +401,7 @@ void DHT::restore_hots() |
| 54 | + #ifdef _MSC_VER |
| 55 | + #pragma omp parallel for firstprivate(iwidth) |
| 56 | + #else |
| 57 | +-#pragma omp parallel for schedule(guided) firstprivate(iwidth) collapse(2) |
| 58 | ++#pragma omp parallel for schedule(static) firstprivate(iwidth) collapse(2) |
| 59 | + #endif |
| 60 | + #endif |
| 61 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 62 | +@@ -423,7 +423,7 @@ void DHT::restore_hots() |
| 63 | + void DHT::make_diag_dirs() |
| 64 | + { |
| 65 | + #if defined(LIBRAW_USE_OPENMP) |
| 66 | +-#pragma omp parallel for schedule(guided) |
| 67 | ++#pragma omp parallel for schedule(static) |
| 68 | + #endif |
| 69 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 70 | + { |
| 71 | +@@ -442,7 +442,7 @@ void DHT::make_diag_dirs() |
| 72 | + // refine_diag_dirs(i, (i & 1) ^ 1); |
| 73 | + // } |
| 74 | + #if defined(LIBRAW_USE_OPENMP) |
| 75 | +-#pragma omp parallel for schedule(guided) |
| 76 | ++#pragma omp parallel for schedule(static) |
| 77 | + #endif |
| 78 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 79 | + { |
| 80 | +@@ -453,28 +453,28 @@ void DHT::make_diag_dirs() |
| 81 | + void DHT::make_hv_dirs() |
| 82 | + { |
| 83 | + #if defined(LIBRAW_USE_OPENMP) |
| 84 | +-#pragma omp parallel for schedule(guided) |
| 85 | ++#pragma omp parallel for schedule(static) |
| 86 | + #endif |
| 87 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 88 | + { |
| 89 | + make_hv_dline(i); |
| 90 | + } |
| 91 | + #if defined(LIBRAW_USE_OPENMP) |
| 92 | +-#pragma omp parallel for schedule(guided) |
| 93 | ++#pragma omp parallel for schedule(static) |
| 94 | + #endif |
| 95 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 96 | + { |
| 97 | + refine_hv_dirs(i, i & 1); |
| 98 | + } |
| 99 | + #if defined(LIBRAW_USE_OPENMP) |
| 100 | +-#pragma omp parallel for schedule(guided) |
| 101 | ++#pragma omp parallel for schedule(static) |
| 102 | + #endif |
| 103 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 104 | + { |
| 105 | + refine_hv_dirs(i, (i & 1) ^ 1); |
| 106 | + } |
| 107 | + #if defined(LIBRAW_USE_OPENMP) |
| 108 | +-#pragma omp parallel for schedule(guided) |
| 109 | ++#pragma omp parallel for schedule(static) |
| 110 | + #endif |
| 111 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 112 | + { |
| 113 | +@@ -689,7 +689,7 @@ void DHT::refine_idiag_dirs(int i) |
| 114 | + void DHT::make_greens() |
| 115 | + { |
| 116 | + #if defined(LIBRAW_USE_OPENMP) |
| 117 | +-#pragma omp parallel for schedule(guided) |
| 118 | ++#pragma omp parallel for schedule(static) |
| 119 | + #endif |
| 120 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 121 | + { |
| 122 | +@@ -765,7 +765,7 @@ void DHT::make_gline(int i) |
| 123 | + void DHT::illustrate_dirs() |
| 124 | + { |
| 125 | + #if defined(LIBRAW_USE_OPENMP) |
| 126 | +-#pragma omp parallel for schedule(guided) |
| 127 | ++#pragma omp parallel for schedule(static) |
| 128 | + #endif |
| 129 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 130 | + { |
| 131 | +@@ -956,7 +956,7 @@ void DHT::make_rb() |
| 132 | + { |
| 133 | + #if defined(LIBRAW_USE_OPENMP) |
| 134 | + #pragma omp barrier |
| 135 | +-#pragma omp parallel for schedule(guided) |
| 136 | ++#pragma omp parallel for schedule(static) |
| 137 | + #endif |
| 138 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 139 | + { |
| 140 | +@@ -964,7 +964,7 @@ void DHT::make_rb() |
| 141 | + } |
| 142 | + #if defined(LIBRAW_USE_OPENMP) |
| 143 | + #pragma omp barrier |
| 144 | +-#pragma omp parallel for schedule(guided) |
| 145 | ++#pragma omp parallel for schedule(static) |
| 146 | + #endif |
| 147 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 148 | + { |
| 149 | +@@ -982,7 +982,7 @@ void DHT::copy_to_image() |
| 150 | + #ifdef _MSC_VER |
| 151 | + #pragma omp parallel for |
| 152 | + #else |
| 153 | +-#pragma omp parallel for schedule(guided) collapse(2) |
| 154 | ++#pragma omp parallel for schedule(static) collapse(2) |
| 155 | + #endif |
| 156 | + #endif |
| 157 | + for (int i = 0; i < libraw.imgdata.sizes.iheight; ++i) |
| 158 | +diff --git a/external/LibRaw/src/preprocessing/raw2image.cpp b/external/LibRaw/src/preprocessing/raw2image.cpp |
| 159 | +index e343762..9fd2f1e 100644 |
| 160 | +--- a/external/LibRaw/src/preprocessing/raw2image.cpp |
| 161 | ++++ b/external/LibRaw/src/preprocessing/raw2image.cpp |
| 162 | +@@ -221,7 +221,7 @@ void LibRaw::copy_fuji_uncropped(unsigned short cblack[4], |
| 163 | + unsigned short *dmaxp) |
| 164 | + { |
| 165 | + #if defined(LIBRAW_USE_OPENMP) |
| 166 | +-#pragma omp parallel for schedule(dynamic) default(none) firstprivate(cblack) shared(dmaxp) |
| 167 | ++#pragma omp parallel for schedule(static) default(none) firstprivate(cblack) shared(dmaxp) |
| 168 | + #endif |
| 169 | + for (int row = 0; row < int(S.raw_height) - int(S.top_margin) * 2; row++) |
| 170 | + { |
| 171 | +@@ -276,7 +276,7 @@ void LibRaw::copy_bayer(unsigned short cblack[4], unsigned short *dmaxp) |
| 172 | + // Both cropped and uncropped |
| 173 | + int maxHeight = MIN(int(S.height),int(S.raw_height)-int(S.top_margin)); |
| 174 | + #if defined(LIBRAW_USE_OPENMP) |
| 175 | +-#pragma omp parallel for schedule(dynamic) default(none) shared(dmaxp) firstprivate(cblack, maxHeight) |
| 176 | ++#pragma omp parallel for schedule(static) default(none) shared(dmaxp) firstprivate(cblack, maxHeight) |
| 177 | + #endif |
| 178 | + for (int row = 0; row < maxHeight ; row++) |
| 179 | + { |
| 180 | +-- |
| 181 | +2.43.0 |
0 commit comments