Windows support: build with MinGW-w64 and OpenBLAS - #52
Open
dareus66 wants to merge 3 commits into
Open
Conversation
iris_image.c calls jpeg_load_mem() and jpeg_free(), whose implementation lives in jpeg.c (it defines JPEG_IMPLEMENTATION before including jpeg.h), but the pngtest target only compiled png_compare.c and iris_image.c, so the link failed with undefined references on every platform. Also remove the .exe variant of the helper on cleanup, since MinGW adds that extension automatically. Note: the target still fails afterwards on its first image pair, which compares woman_with_sunglasses.png (512x512) against woman_with_sunglasses_compressed2.png (256x256). That mismatch is left untouched here, since it is not clear which image was intended. The cat_* pair is correctly matched and passes.
Adds a Windows build of the BLAS backend, compiled from an MSYS2 UCRT64 shell with "make blas". The delta is Linux to Windows rather than macOS to Windows, since the OpenBLAS path already exists and every Accelerate include is behind __APPLE__. Four platform shims, all inside #ifdef _WIN32, with the POSIX branches left untouched: - iris_safetensors.c: CreateFileMapping/MapViewOfFile instead of mmap. A mapped view keeps its own references, so the file and mapping handles are closed right after mapping, mirroring the POSIX code that closes the fd after mmap. Release goes through a small iris_unmap() helper, so the struct is unchanged. - iris_transformer_flux.c: GetSystemInfo instead of sysconf for the CPU count in get_attn_num_threads(). MinGW ships unistd.h but not sysconf, so this is a hard compile error otherwise. The other two sysconf calls are inside USE_METAL / __APPLE__ branches and never reach this build. - terminals.c: the iTerm2 temp-file path returns -1. MinGW has no mkstemps(), and iTerm2 is a macOS terminal that is never detected on Windows, so a shim there would be dead code. - Config, tokenizer and index files are opened in binary mode. Windows text mode translates CRLF and would corrupt the sized reads that follow ftell(); on POSIX "rb" is identical to "r". The interactive REPL is not built on Windows: iris_cli.c, linenoise.c and embcache.c need termios. main.c prints an error and exits when interactive mode is requested. The only symbol main.c needs from that module is iris_cli_run(), so excluding the three files is enough. Verified on a Xeon W-2125 with flux-klein-4b against the repository's own reference images, all well inside the threshold of 20: 64x64, 2 steps, seed 42 mean_diff 1.14 512x512, 4 steps, seed 123 mean_diff 2.12 img2img 256x256, seed 456 mean_diff 8.29 Note that run_test.py cannot run unchanged on hardware this slow: it kills each test after 300s and the 512x512 case needs more, so those three were run by hand. "run_test.py --quick" passes as is. Also ignores the built binary, which .gitignore still referred to by its pre-rename name (flux).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Windows build of the BLAS backend, so
make blasworks from an MSYS2 UCRT64 shell.The delta turned out to be Linux to Windows rather than macOS to Windows: the OpenBLAS path already exists and every Accelerate include sits behind
__APPLE__, so nothing had to be de-macified. The whole port is 118 lines of code across 9 files, all inside#ifdef _WIN32.Platform shims
iris_safetensors.c—CreateFileMapping/MapViewOfFileinstead ofmmap. A mapped view keeps its own references, so both handles are closed right after mapping, mirroring the POSIX code that closes the fd aftermmap; the struct is unchanged. Release goes through a smalliris_unmap()helper.iris_transformer_flux.c—GetSystemInfoinstead ofsysconfinget_attn_num_threads(). MinGW shipsunistd.hbut notsysconf, so this is a hard compile error otherwise. The other twosysconfcalls sit inUSE_METAL/__APPLE__branches and never reach this build.terminals.c— the iTerm2 temp-file path returns -1. MinGW has nomkstemps(), and iTerm2 is never detected on Windows, so implementing one would be dead code.fopen— config, tokenizer and index files. Windows text mode translates CRLF and corrupts the sized reads that followftell(). On POSIX"rb"is identical to"r".Not built on Windows
The interactive REPL (
iris_cli.c,linenoise.c,embcache.cneed termios);main.cprints an error and exits when interactive mode is requested. Terminal image previews compile but do not render.Other backends
Unchanged. The only lines removed anywhere are the eight
fopenmode strings and threemunmapcalls that now go throughiris_unmap(), which on POSIX callsmunmap— so macOS and Linux behaviour is identical.Verification
Built on a Xeon W-2125 (4 cores) with OpenBLAS 0.3.34 and gcc 16.2, checked against this repository's own reference images — all well inside the threshold of 20:
run_test.py --quickpasses as is. The full suite cannot run unchanged on hardware this slow: it kills each test after 300s and the 512x512 case needs about 220s of denoising plus loading, so those three cases were run by hand.One unrelated fix, kept in its own commit
make pngtestwas broken on every platform —iris_image.ccallsjpeg_load_mem()/jpeg_free(), whose implementation lives injpeg.c, but the target only compiledpng_compare.c iris_image.c, so the link failed with undefined references. It is the first commit here so it can be taken independently of the Windows work.It still fails afterwards on its first image pair, which compares
woman_with_sunglasses.png(512x512) againstwoman_with_sunglasses_compressed2.png(256x256). I left that alone since it is not clear which image was intended. Thecat_*pair is correctly matched and passes.🤖 Generated with Claude Code