Skip to content

Fix Metal preamble generation for paths with spaces#2

Open
aramdov wants to merge 1 commit intoPrismML-Eng:prismfrom
aramdov:fix/metal-preamble-space-paths
Open

Fix Metal preamble generation for paths with spaces#2
aramdov wants to merge 1 commit intoPrismML-Eng:prismfrom
aramdov:fix/metal-preamble-space-paths

Conversation

@aramdov
Copy link
Copy Markdown

@aramdov aramdov commented Apr 1, 2026

Summary

mlx/backend/metal/make_compiled_preamble.sh parsed xcrun metal -H output using shell word splitting.

That breaks when header paths contain spaces, for example a checkout located under a path like Software Projects.

The generated preamble then omits real dependencies and produces truncated fake header paths. At runtime this shows up as Metal JIT compilation failures with errors such as:

  • unknown type name 'bfloat16_t'
  • unknown type name 'complex64_t'
  • use of undeclared identifier 'offset_neg_idx'

Root cause

The script previously expanded the compiler output with shell word splitting, which does not preserve one dependency record per line.

Fix

  • keep only dependency lines reported by -H
  • read them line-by-line into the bash array
  • parse each record as depth + path while preserving embedded spaces

Validation

I reproduced this with a local checkout under a path containing spaces. Before the fix, the generated preamble contained broken path fragments instead of real headers. After the fix, the generated preamble correctly includes dependencies such as:

  • mlx/backend/metal/kernels/bf16.h
  • mlx/backend/metal/kernels/bf16_math.h
  • mlx/backend/metal/kernels/complex.h

and the downstream MLX inference path succeeds again.

@kyr0
Copy link
Copy Markdown

kyr0 commented Apr 1, 2026

thx man

@khosravipasha
Copy link
Copy Markdown
Collaborator

Thanks for the fix, is the more of mlx issue or issue with demo?
Might want to send the PR to MLX directly

Or in https://github.com/PrismML-Eng/Bonsai-demo.

Can keep the PR open here too if its helping others. Our plan is to merge our changes to the main MLX so this fork won't be needed long term.

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.

3 participants