Skip to content

Optimise openjph build - #410

Merged
t20100 merged 4 commits into
silx-kit:mainfrom
t20100:optimise-openjph-build
Sep 1, 2026
Merged

t20100 merged 4 commits into
silx-kit:mainfrom
t20100:optimise-openjph-build

Conversation

@t20100

@t20100 t20100 commented Aug 31, 2026

Copy link
Copy Markdown
Member

This PR use SIMD source code to build openjh.

This expects the compilers to support SIMD up to avx512, which is available since >8 years old in gcc, clang and msvc, so fine for me.

@t20100 t20100 added this to the Next release milestone Aug 31, 2026
Comment thread setup.py Outdated
Comment on lines +1002 to +1008
"-msse",
"-msse2",
"-mssse3",
"-mavx",
"-mavx2",
"-mavx512f",
"-mavx512cd",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just expects the compiler to support those, which sounds fine for me as of today.

@t20100
t20100 requested a review from payno August 31, 2026 14:18
@t20100
t20100 force-pushed the optimise-openjph-build branch from 91aae07 to d2ec22a Compare August 31, 2026 14:35
@t20100
t20100 marked this pull request as draft August 31, 2026 14:35
@t20100
t20100 force-pushed the optimise-openjph-build branch from 11c0535 to 5f80275 Compare September 1, 2026 10:08
@t20100
t20100 force-pushed the optimise-openjph-build branch from 5f80275 to cc7b8cd Compare September 1, 2026 11:39

@t20100 t20100 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This again adds some complexity to the setup.py but for a good gain of performance

Comment thread setup.py
Comment on lines +1062 to +1069
simd_cflags = {
"sse": ["-msse"],
"sse2": ["-msse2"],
"ssse3": ["-mssse3"],
"avx": ["-mavx", "/arch:AVX"],
"avx2": ["-mavx2", "/arch:AVX2"],
"avx512": ["-mavx512f", "-mavx512cd", "/arch:AVX512"],
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIMD flags must be passed only to the relevant files

Comment thread setup.py
"avx2": ["-mavx2", "/arch:AVX2"],
"avx512": ["-mavx512f", "-mavx512cd", "/arch:AVX512"],
}
simd_macros = []

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no SIMD related macros so all are enabled: there is a runtime probe to get the host capabilities

Comment thread setup.py
def portable_sources(pattern):
macros = [("_FILE_OFFSET_BITS", 64)] + simd_macros

source_cflags = [

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a custom construct to allow passing specific flags to only some source files: setuptools clib support is limited: we'd better use cmake, but this is out of the scope of this PR IMO

Comment thread setup.py
include_dir = pkgconfig.variables(libname).get("includedir", None)
extra_link_args = pkgconfig.libs(libname).split(" ")
for arg in extra_link_args:
for arg in extra_link_args[:]:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small fix: copy list before loop since it is modified in the loop

Comment thread setup.py


PLUGIN_LIB_DEPENDENCIES["htj2k"] = ("openjph",)
PLUGIN_LIB_DEPENDENCIES["zfp"] = ("zfp",)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-order the code to match the filter defined in previous function

@t20100
t20100 marked this pull request as ready for review September 1, 2026 11:44
@t20100

t20100 commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Ready for review

Comment thread setup.py
Comment on lines +563 to +565
build_info["cflags"] = self._update_cflags(
cflags + list(config.compile_args)
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have flags existing in both cflags and and config.compile_args. Which mean should we take care of this ? (using set instead of list).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, but it shouldn't happen.

Comment thread setup.py


PLUGIN_LIB_DEPENDENCIES["zfp"] = ("zfp",)
PLUGIN_LIB_DEPENDENCIES["htj2k"] = ("openjph",)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

miss those one during the first review sorry :(

@t20100
t20100 merged commit c297b8d into silx-kit:main Sep 1, 2026
4 checks passed
@t20100
t20100 deleted the optimise-openjph-build branch September 1, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants