Skip to content

Commit 2a86019

Browse files
committed
testing: hwy testing strategies
1. Some tests are repeated, run once with hwy off and once with hwy on. The "on" version append ".hwy" to the test name and set the OPENIMAGEIO_ENABLE_HWY=1 environment variable to force it on while running the test. The advantage to this approach is that the test itself doesn't need to change at all, we just run it separately in each mode. In this PR, I do this with oiiotool, oiiotool-xform, and docs-examples-cpp. For now, while hwy is not enabled by default, it's doing these extra things to enable hwy. Eventually, if/when hwy is enabled by default, we'll flip the sense and use the env variable to turn it off. 2. Some tests do certain operations both ways when hwy support was enabled at build time. This is more convenient for certain unit test executables, where perhaps we want to benchmark both ways and have those show up right next to each other within the run. In this PR, I do this with the imagebufalgo_test unit test. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 70c6fc1 commit 2a86019

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ else ()
112112
endif ()
113113
option (${PROJ_NAME}_BUILD_TOOLS "Build the command-line tools" ON)
114114
option (${PROJ_NAME}_BUILD_TESTS "Build the unit tests" ON)
115-
set_option (OIIO_USE_HWY "Enable experimental Google Highway SIMD optimizations (if Highway is available)" OFF)
115+
set_option (OIIO_USE_HWY "Enable experimental Google Highway SIMD optimizations (if Highway is available)" OFF VERBOSE)
116116
set (OIIO_LIBNAME_SUFFIX "" CACHE STRING
117117
"Optional name appended to ${PROJECT_NAME} libraries that are built")
118118
option (BUILD_OIIOUTIL_ONLY "If ON, will build *only* libOpenImageIO_Util" OFF)

src/cmake/testing.cmake

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set(OIIO_TESTSUITE_IMAGEDIR "${PROJECT_BINARY_DIR}/testsuite" CACHE PATH
3030
# [ URL http://find.reference.cases.here.com ]
3131
# [ FOUNDVAR variable_name ... ]
3232
# [ ENABLEVAR variable_name ... ]
33+
# [ DISABLEVAR variable_name ... ]
3334
# [ SUFFIX suffix ]
3435
# [ ENVIRONMENT "VAR=value" ... ]
3536
# )
@@ -43,35 +44,48 @@ set(OIIO_TESTSUITE_IMAGEDIR "${PROJECT_BINARY_DIR}/testsuite" CACHE PATH
4344
# not existing and true, will skip the test.
4445
#
4546
# The optional ENABLEVAR introduces variables (typically ENABLE_Foo) that
46-
# if existing and yet false, will skip the test.
47+
# if existing and yet false/off/zero, will skip the test. (Not existing
48+
# does NOT disable the test.)
49+
#
50+
# The optional DISABLEVAR introduces variables that, if existing and
51+
# true/on/nonzero, will skip the test.
4752
#
4853
# The optional SUFFIX is appended to the test name.
4954
#
5055
# The optional ENVIRONMENT is a list of environment variables to set for the
5156
# test.
5257
#
5358
macro (oiio_add_tests)
54-
cmake_parse_arguments (_ats "" "SUFFIX;TESTNAME" "URL;IMAGEDIR;LABEL;FOUNDVAR;ENABLEVAR;ENVIRONMENT" ${ARGN})
59+
cmake_parse_arguments (_ats "" "SUFFIX;TESTNAME" "URL;IMAGEDIR;LABEL;FOUNDVAR;ENABLEVAR;DISABLEVAR;ENVIRONMENT" ${ARGN})
5560
# Arguments: <prefix> <options> <one_value_keywords> <multi_value_keywords> args...
5661
set (_ats_testdir "${OIIO_TESTSUITE_IMAGEDIR}/${_ats_IMAGEDIR}")
5762
# If there was a FOUNDVAR param specified and that variable name is
5863
# not defined, mark the test as broken.
5964
set (_test_disabled FALSE)
6065
set (_test_notfound FALSE)
6166
foreach (_var ${_ats_FOUNDVAR})
67+
# FOUNDVAR entires had better exist and be true
6268
if (NOT ${_var})
6369
set (_ats_LABEL "broken")
6470
set (_test_notfound TRUE)
6571
endif ()
6672
endforeach ()
6773
set (_test_disabled 0)
6874
foreach (_var ${_ats_ENABLEVAR})
75+
# ENABLEVAR, *if* it exists, must be true. But not existing is fine.
6976
if ((NOT "${${_var}}" STREQUAL "" AND NOT "${${_var}}") OR
7077
(NOT "$ENV{${_var}}" STREQUAL "" AND NOT "$ENV{${_var}}"))
7178
set (_ats_LABEL "broken")
7279
set (_test_disabled TRUE)
7380
endif ()
7481
endforeach ()
82+
foreach (_var ${_ats_DISABLEVAR})
83+
# DISABLEVAR, if true, disable the test. Not existing is fine.
84+
if (${_var})
85+
set (_ats_LABEL "broken")
86+
set (_test_disabled TRUE)
87+
endif ()
88+
endforeach ()
7589
# For OCIO 2.2+, have the testsuite use the default built-in config
7690
list (APPEND _ats_ENVIRONMENT "OCIO=ocio://default"
7791
"OIIO_TESTSUITE_OCIOCONFIG=ocio://default")
@@ -238,6 +252,27 @@ macro (oiio_add_all_tests)
238252
oiio_add_tests (oiiotool-color
239253
FOUNDVAR OpenColorIO_FOUND)
240254

255+
# Tests to run with HWY enabled.
256+
# Remember to add tests here as hwy enabled IBA functions are added
257+
oiio_add_tests ( oiiotool
258+
oiiotool-composite
259+
oiiotool-xform
260+
docs-examples-cpp
261+
FOUNDVAR hwy_FOUND
262+
ENABLEVAR OIIO_USE_HWY
263+
SUFFIX ".hwy"
264+
ENVIRONMENT "OPENIMAGEIO_ENABLE_HWY=1"
265+
)
266+
267+
oiio_add_tests ( python-imagebufalgo
268+
FOUNDVAR hwy_FOUND
269+
ENABLEVAR OIIO_USE_HWY USE_PYTHON
270+
DISABLEVAR BUILD_OIIOUTIL_ONLY SANITIZE
271+
SUFFIX ".hwy"
272+
ENVIRONMENT "OPENIMAGEIO_ENABLE_HWY=1"
273+
IMAGEDIR oiio-images
274+
)
275+
241276
# List testsuites for specific formats or features which might be not found
242277
# or be intentionally disabled, or which need special external reference
243278
# images from the web that if not found, should skip the tests:

src/libOpenImageIO/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ if (OIIO_BUILD_TESTS AND BUILD_TESTING)
282282
${OpenCV_LIBRARIES}
283283
${OPENIMAGEIO_IMATH_TARGETS}
284284
FOLDER "Unit Tests" NO_INSTALL)
285+
target_compile_definitions (imagebufalgo_test PRIVATE OIIO_USE_HWY=${_oiio_use_hwy})
285286
add_test (unit_imagebufalgo ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/imagebufalgo_test)
286287

287288
fancy_add_executable (NAME imagespec_test SRC imagespec_test.cpp

src/libOpenImageIO/imagebufalgo_test.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ static bool wedge = false;
4343
static int threadcounts[] = { 1, 2, 4, 8, 12, 16, 20,
4444
24, 28, 32, 64, 128, 1024, 1 << 30 };
4545

46+
static const int hwy_build = OIIO_USE_HWY;
47+
static int hwy_on = hwy_build;
48+
49+
4650

4751
static void
4852
getargs(int argc, char* argv[])
@@ -403,7 +407,7 @@ test_channel_append()
403407
void
404408
test_add()
405409
{
406-
std::cout << "test add\n";
410+
print("test add{}\n", hwy_on ? " (HWY)" : "");
407411

408412
// Create buffers
409413
const float Aval[] = { 0.1f, 0.2f, 0.3f, 0.4f };
@@ -429,7 +433,7 @@ test_add()
429433
void
430434
test_sub()
431435
{
432-
std::cout << "test sub\n";
436+
print("test sub{}\n", hwy_on ? " (HWY)" : "");
433437

434438
// Create buffers
435439
const float Aval[] = { 0.1f, 0.2f, 0.3f, 0.4f };
@@ -455,7 +459,7 @@ test_sub()
455459
void
456460
test_mul()
457461
{
458-
std::cout << "test mul\n";
462+
print("test mul{}\n", hwy_on ? " (HWY)" : "");
459463

460464
// Create buffers
461465
// Create buffers
@@ -482,7 +486,7 @@ test_mul()
482486
void
483487
test_mad()
484488
{
485-
std::cout << "test mad\n";
489+
print("test mad{}\n", hwy_on ? " (HWY)" : "");
486490
const int WIDTH = 4, HEIGHT = 4, CHANNELS = 4;
487491
ImageSpec spec(WIDTH, HEIGHT, CHANNELS, TypeDesc::FLOAT);
488492

@@ -1678,6 +1682,17 @@ test_demosaic()
16781682
}
16791683

16801684

1685+
1686+
// clang-format off
1687+
// Neat trick macro to prefix in front of the calls where we want to
1688+
// run it in both hwy and non-hwy modes. It will loop over both settings.
1689+
#define HWY_TEST \
1690+
for (hwy_on = 0; hwy_on <= hwy_build; ++hwy_on) \
1691+
OIIO::attribute("enable_hwy", hwy_on), /* next command */
1692+
// clang-format on
1693+
1694+
1695+
16811696
int
16821697
main(int argc, char** argv)
16831698
{
@@ -1702,10 +1717,10 @@ main(int argc, char** argv)
17021717
test_crop();
17031718
test_paste();
17041719
test_channel_append();
1705-
test_add();
1706-
test_sub();
1707-
test_mul();
1708-
test_mad();
1720+
HWY_TEST test_add();
1721+
HWY_TEST test_sub();
1722+
HWY_TEST test_mul();
1723+
HWY_TEST test_mad();
17091724
test_hwy_strided_roi_fallback();
17101725
test_min();
17111726
test_max();

0 commit comments

Comments
 (0)