Skip to content

Detect NEON when py-cpuinfo reports no CPU flags - #8765

Draft
vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix/simd-width-missing-cpuinfo-flags
Draft

vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix/simd-width-missing-cpuinfo-flags

Conversation

@vineethsaivs

Copy link
Copy Markdown
Contributor

On Apple Silicon, building CPU ops such as cpu_adam fails with KeyError: 'flags' before the compiler runs.

simd_width() indexes cpu_info['flags'], but py-cpuinfo returns no flags key on M-series Macs (it gives only arch, brand, bits and count). The SVE check added in #8365 sits ahead of the NEON branch from #8453, so these CPUs never reach NEON.

Fix: read the flags once with cpu_info.get('flags', []). Apple Silicon now gets -D__NEON__; CPUs that report flags are unchanged.

Test: new parametrized test in tests/unit/ops/test_op_builder.py covers a cpu_info without flags (fails on master with KeyError, passes here) and one with sve. On an M2 Pro with real py-cpuinfo, simd_width() goes from KeyError to -D__NEON__. The test file: 18 passed, 1 skipped; yapf and flake8 clean.

On Apple Silicon py-cpuinfo returns no 'flags' key, so simd_width()
raised KeyError on the SVE check and CPU ops such as cpu_adam could not
build. Read the flags with a default so these CPUs fall through to the
NEON path.

Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>

This branch has not been deployed

No deployments
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