Skip to content

Windows support: build with MinGW-w64 and OpenBLAS - #52

Open
dareus66 wants to merge 3 commits into
antirez:mainfrom
dareus66:windows-port-pr
Open

Windows support: build with MinGW-w64 and OpenBLAS#52
dareus66 wants to merge 3 commits into
antirez:mainfrom
dareus66:windows-port-pr

Conversation

@dareus66

Copy link
Copy Markdown

Adds a Windows build of the BLAS backend, so make blas works 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.cCreateFileMapping/MapViewOfFile instead of mmap. A mapped view keeps its own references, so both handles are closed right after mapping, mirroring the POSIX code that closes the fd after mmap; the struct is unchanged. Release goes through a small iris_unmap() helper.
  • iris_transformer_flux.cGetSystemInfo instead of sysconf 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 sit in 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 never detected on Windows, so implementing one would be dead code.
  • Binary-mode fopen — config, tokenizer and index files. Windows text mode translates CRLF and corrupts the sized reads that follow ftell(). On POSIX "rb" is identical to "r".

Not built on Windows

The interactive REPL (iris_cli.c, linenoise.c, embcache.c need termios); main.c prints 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 fopen mode strings and three munmap calls that now go through iris_unmap(), which on POSIX calls munmap — 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:

Test mean_diff expected
64x64, 2 steps, seed 42 1.14 ~3.4
512x512, 4 steps, seed 123 2.12 ~1.7
img2img 256x256, seed 456 8.29 6-17

run_test.py --quick passes 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 pngtest was broken on every platformiris_image.c calls jpeg_load_mem()/jpeg_free(), whose implementation lives in jpeg.c, but the target only compiled png_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) against woman_with_sunglasses_compressed2.png (256x256). I left that alone since it is not clear which image was intended. The cat_* pair is correctly matched and passes.

🤖 Generated with Claude Code

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).
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.

1 participant