Skip to content

Commit b56d00d

Browse files
authored
int: Some minor cleanup of the hwy related code (#5137)
* imageio.h: Document 'enable_hwy' global option. * imagebufalgo_hwy_pvt.h: Remove RoiNChannels -- it's the same as roi.nchannels() * Macros: we can simply test OIIO_USE_HWY, since it's always defined; there is no need to also test defined(OIIO_USE_HWY). Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 4f40fcf commit b56d00d

7 files changed

Lines changed: 37 additions & 34 deletions

File tree

src/include/OpenImageIO/imageio.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3776,6 +3776,15 @@ OIIO_API std::string geterror(bool clear = true);
37763776
/// If zero, they will try to use OIIO's native thread pool even if TBB
37773777
/// is available.
37783778
///
3779+
/// - `int enable_hwy' (0)
3780+
///
3781+
/// If nonzero and Google Highway was found and support configured when
3782+
/// OIIO was built, SIMD accelertion using Highway will be used to
3783+
/// accelerate certain ImageBufAlgo functionality. If this attribute is
3784+
/// set to zero, that Highway-based SIMD acceleration will be disabled
3785+
/// at runtime, even if support was enabled when OIIO was built.
3786+
/// (Added in OIIO 3.2.)
3787+
///
37793788
/// - `string plugin_searchpath`
37803789
///
37813790
/// Colon-separated (or semicolon-separated) list of directories to search

src/libOpenImageIO/imagebufalgo_addsub.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <OpenImageIO/imagebufalgo.h>
1919
#include <OpenImageIO/imagebufalgo_util.h>
2020

21-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
21+
#if OIIO_USE_HWY
2222
# include "imagebufalgo_hwy_pvt.h"
2323
#endif
2424

@@ -131,7 +131,7 @@ add_impl_hwy(ImageBuf& R, const ImageBuf& A, cspan<float> b, ROI roi,
131131
});
132132
return true;
133133
}
134-
#endif // defined(OIIO_USE_HWY) && OIIO_USE_HWY
134+
#endif // OIIO_USE_HWY
135135

136136
template<class Rtype, class Atype, class Btype>
137137
static bool
@@ -144,7 +144,7 @@ add_impl(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
144144
auto Rv = HwyPixels(R);
145145
auto Av = HwyPixels(A);
146146
auto Bv = HwyPixels(B);
147-
const int nchannels = RoiNChannels(roi);
147+
const int nchannels = roi.nchannels();
148148
const bool contig = ChannelsContiguous<Rtype>(Rv, nchannels)
149149
&& ChannelsContiguous<Atype>(Av, nchannels)
150150
&& ChannelsContiguous<Btype>(Bv, nchannels);
@@ -180,14 +180,14 @@ template<class Rtype, class Atype>
180180
static bool
181181
add_impl(ImageBuf& R, const ImageBuf& A, cspan<float> b, ROI roi, int nthreads)
182182
{
183-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
183+
#if OIIO_USE_HWY
184184
if (OIIO::pvt::enable_hwy && R.localpixels() && A.localpixels())
185185
return add_impl_hwy<Rtype, Atype>(R, A, b, roi, nthreads);
186186
#endif
187187
return add_impl_scalar<Rtype, Atype>(R, A, b, roi, nthreads);
188188
}
189189

190-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
190+
#if OIIO_USE_HWY
191191
// Native integer sub using SaturatedSub (scale-invariant, no float conversion)
192192
template<class T>
193193
static bool
@@ -226,7 +226,7 @@ sub_impl_hwy(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
226226
return hwy_binary_perpixel_op<Rtype, Atype, Btype>(R, A, B, roi, nthreads,
227227
op);
228228
}
229-
#endif // defined(OIIO_USE_HWY) && OIIO_USE_HWY
229+
#endif // OIIO_USE_HWY
230230

231231
template<class Rtype, class Atype, class Btype>
232232
static bool
@@ -244,7 +244,7 @@ sub_impl(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
244244
auto Rv = HwyPixels(R);
245245
auto Av = HwyPixels(A);
246246
auto Bv = HwyPixels(B);
247-
const int nchannels = RoiNChannels(roi);
247+
const int nchannels = roi.nchannels();
248248
const bool contig = ChannelsContiguous<Rtype>(Rv, nchannels)
249249
&& ChannelsContiguous<Atype>(Av, nchannels)
250250
&& ChannelsContiguous<Btype>(Bv, nchannels);

src/libOpenImageIO/imagebufalgo_hwy_pvt.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ HwyPixels(const ImageBuf& img)
5757
spec.nchannels };
5858
}
5959

60-
inline int
61-
RoiNChannels(const ROI& roi) noexcept
62-
{
63-
return roi.chend - roi.chbegin;
64-
}
65-
6660
template<class T, class ByteT>
6761
inline bool
6862
ChannelsContiguous(const HwyLocalPixelsView<ByteT>& v, int nchannels) noexcept
@@ -938,7 +932,7 @@ hwy_binary_perpixel_op(ImageBuf& R, const ImageBuf& A, const ImageBuf& B,
938932
auto Av = HwyPixels(A);
939933
auto Bv = HwyPixels(B);
940934
ImageBufAlgo::parallel_image(roi, nthreads, [&, op](ROI roi) {
941-
const int nchannels = RoiNChannels(roi);
935+
const int nchannels = roi.nchannels();
942936
const size_t n = static_cast<size_t>(roi.width())
943937
* static_cast<size_t>(nchannels);
944938
for (int y = roi.ybegin; y < roi.yend; ++y) {
@@ -965,7 +959,7 @@ hwy_ternary_perpixel_op(ImageBuf& R, const ImageBuf& A, const ImageBuf& B,
965959
auto Bv = HwyPixels(B);
966960
auto Cv = HwyPixels(C);
967961
ImageBufAlgo::parallel_image(roi, nthreads, [&, op](ROI roi) {
968-
const int nchannels = RoiNChannels(roi);
962+
const int nchannels = roi.nchannels();
969963
const size_t n = static_cast<size_t>(roi.width())
970964
* static_cast<size_t>(nchannels);
971965
for (int y = roi.ybegin; y < roi.yend; ++y) {
@@ -992,7 +986,7 @@ hwy_binary_native_int_perpixel_op(ImageBuf& R, const ImageBuf& A,
992986
auto Av = HwyPixels(A);
993987
auto Bv = HwyPixels(B);
994988
ImageBufAlgo::parallel_image(roi, nthreads, [&, op](ROI roi) {
995-
const int nchannels = RoiNChannels(roi);
989+
const int nchannels = roi.nchannels();
996990
const size_t n = static_cast<size_t>(roi.width())
997991
* static_cast<size_t>(nchannels);
998992
for (int y = roi.ybegin; y < roi.yend; ++y) {

src/libOpenImageIO/imagebufalgo_mad.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <OpenImageIO/imagebufalgo.h>
1717
#include <OpenImageIO/imagebufalgo_util.h>
1818

19-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
19+
#if OIIO_USE_HWY
2020
# include "imagebufalgo_hwy_pvt.h"
2121
#endif
2222
#include "imageio_pvt.h"
@@ -46,7 +46,7 @@ mad_impl_scalar(ImageBuf& R, const ImageBuf& A, const ImageBuf& B,
4646

4747

4848

49-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
49+
#if OIIO_USE_HWY
5050
template<class Rtype, class ABCtype>
5151
static bool
5252
mad_impl_hwy(ImageBuf& R, const ImageBuf& A, const ImageBuf& B,
@@ -63,21 +63,21 @@ mad_impl_hwy(ImageBuf& R, const ImageBuf& A, const ImageBuf& B,
6363
return hwy_ternary_perpixel_op<Rtype, ABCtype>(R, A, B, C, roi, nthreads,
6464
op);
6565
}
66-
#endif // defined(OIIO_USE_HWY) && OIIO_USE_HWY
66+
#endif // OIIO_USE_HWY
6767

6868
template<class Rtype, class ABCtype>
6969
static bool
7070
mad_impl(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, const ImageBuf& C,
7171
ROI roi, int nthreads)
7272
{
73-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
73+
#if OIIO_USE_HWY
7474
if (OIIO::pvt::enable_hwy && R.localpixels() && A.localpixels()
7575
&& B.localpixels() && C.localpixels()) {
7676
auto Rv = HwyPixels(R);
7777
auto Av = HwyPixels(A);
7878
auto Bv = HwyPixels(B);
7979
auto Cv = HwyPixels(C);
80-
const int nchannels = RoiNChannels(roi);
80+
const int nchannels = roi.nchannels();
8181
const bool contig = ChannelsContiguous<Rtype>(Rv, nchannels)
8282
&& ChannelsContiguous<ABCtype>(Av, nchannels)
8383
&& ChannelsContiguous<ABCtype>(Bv, nchannels)

src/libOpenImageIO/imagebufalgo_muldiv.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <OpenImageIO/half.h>
1818

19-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
19+
#if OIIO_USE_HWY
2020
# include "imagebufalgo_hwy_pvt.h"
2121
#endif
2222
#include <OpenImageIO/dassert.h>
@@ -125,7 +125,7 @@ mul_impl_scalar(ImageBuf& R, const ImageBuf& A, cspan<float> b, ROI roi,
125125

126126

127127

128-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
128+
#if OIIO_USE_HWY
129129
template<class Rtype, class Atype, class Btype>
130130
static bool
131131
mul_impl_hwy(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
@@ -168,7 +168,7 @@ mul_impl_hwy(ImageBuf& R, const ImageBuf& A, cspan<float> b, ROI roi,
168168
});
169169
return true;
170170
}
171-
#endif // defined(OIIO_USE_HWY) && OIIO_USE_HWY
171+
#endif // OIIO_USE_HWY
172172

173173
template<class Rtype, class Atype, class Btype>
174174
static bool
@@ -181,7 +181,7 @@ mul_impl(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
181181
auto Rv = HwyPixels(R);
182182
auto Av = HwyPixels(A);
183183
auto Bv = HwyPixels(B);
184-
const int nchannels = RoiNChannels(roi);
184+
const int nchannels = roi.nchannels();
185185
const bool contig = ChannelsContiguous<Rtype>(Rv, nchannels)
186186
&& ChannelsContiguous<Atype>(Av, nchannels)
187187
&& ChannelsContiguous<Btype>(Bv, nchannels);
@@ -208,7 +208,7 @@ template<class Rtype, class Atype>
208208
static bool
209209
mul_impl(ImageBuf& R, const ImageBuf& A, cspan<float> b, ROI roi, int nthreads)
210210
{
211-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
211+
#if OIIO_USE_HWY
212212
if (OIIO::pvt::enable_hwy && R.localpixels() && A.localpixels())
213213
return mul_impl_hwy<Rtype, Atype>(R, A, b, roi, nthreads);
214214
#endif
@@ -314,7 +314,7 @@ div_impl_scalar(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
314314

315315

316316

317-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
317+
#if OIIO_USE_HWY
318318
template<class Rtype, class Atype, class Btype>
319319
static bool
320320
div_impl_hwy(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
@@ -336,7 +336,7 @@ div_impl_hwy(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
336336
return hwy_binary_perpixel_op<Rtype, Atype, Btype>(R, A, B, roi, nthreads,
337337
op);
338338
}
339-
#endif // defined(OIIO_USE_HWY) && OIIO_USE_HWY
339+
#endif // OIIO_USE_HWY
340340

341341
template<class Rtype, class Atype, class Btype>
342342
static bool
@@ -349,7 +349,7 @@ div_impl(ImageBuf& R, const ImageBuf& A, const ImageBuf& B, ROI roi,
349349
auto Rv = HwyPixels(R);
350350
auto Av = HwyPixels(A);
351351
auto Bv = HwyPixels(B);
352-
const int nchannels = RoiNChannels(roi);
352+
const int nchannels = roi.nchannels();
353353
const bool contig = ChannelsContiguous<Rtype>(Rv, nchannels)
354354
&& ChannelsContiguous<Atype>(Av, nchannels)
355355
&& ChannelsContiguous<Btype>(Bv, nchannels);

src/libOpenImageIO/imagebufalgo_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ test_mad()
522522
void
523523
test_hwy_strided_roi_fallback()
524524
{
525-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
525+
#if OIIO_USE_HWY
526526
std::cout << "test hwy strided roi fallback\n";
527527

528528
int prev_enable_hwy = 0;

src/libOpenImageIO/imagebufalgo_xform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <Imath/ImathBox.h>
2323

24-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
24+
#if OIIO_USE_HWY
2525
# include "imagebufalgo_hwy_pvt.h"
2626
#endif
2727

@@ -1266,7 +1266,7 @@ resample_deep(ImageBuf& dst, const ImageBuf& src, bool interpolate, ROI roi,
12661266

12671267

12681268

1269-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
1269+
#if OIIO_USE_HWY
12701270
template<typename DSTTYPE, typename SRCTYPE>
12711271
static bool
12721272
resample_hwy(ImageBuf& dst, const ImageBuf& src, bool interpolate, ROI roi,
@@ -1427,14 +1427,14 @@ resample_hwy(ImageBuf& dst, const ImageBuf& src, bool interpolate, ROI roi,
14271427
});
14281428
return true;
14291429
}
1430-
#endif // defined(OIIO_USE_HWY) && OIIO_USE_HWY
1430+
#endif // OIIO_USE_HWY
14311431

14321432
template<typename DSTTYPE, typename SRCTYPE>
14331433
static bool
14341434
resample_(ImageBuf& dst, const ImageBuf& src, bool interpolate, ROI roi,
14351435
int nthreads)
14361436
{
1437-
#if defined(OIIO_USE_HWY) && OIIO_USE_HWY
1437+
#if OIIO_USE_HWY
14381438
if (OIIO::pvt::enable_hwy && dst.localpixels() && src.localpixels())
14391439
return resample_hwy<DSTTYPE, SRCTYPE>(dst, src, interpolate, roi,
14401440
nthreads);

0 commit comments

Comments
 (0)