Commit a5862bd
committed
fix(where): gate x86-specific SIMD path on Sse41/Avx2 for ARM64 compatibility
CI failure on macos-latest (ARM64/Apple Silicon) reported 31 np.where tests
throwing PlatformNotSupportedException at runtime:
PlatformNotSupportedException: Operation is not supported on this platform.
at System.Runtime.Intrinsics.X86.Sse41.ConvertToVector128Int64(Vector128`1 value)
at IL_Where_Int64(...)
Root cause: the SIMD-emit path was gated only on `VectorBits >= 128`. On ARM64,
`Vector128.IsHardwareAccelerated` is true (maps to Neon), so VectorBits is 128,
and the kernel emits calls to Sse41/Avx2 byte-lane expansion intrinsics which
are x86-only.
Breakdown of the byte-mask expansion path by element size:
- 1-byte (byte): portable Vector*.Load/GreaterThan — safe on any SIMD platform
- 2-byte: Sse41.ConvertToVector128Int16 / Avx2.ConvertToVector256Int16
- 4-byte: Sse41.ConvertToVector128Int32 / Avx2.ConvertToVector256Int32
- 8-byte: Sse41.ConvertToVector128Int64 / Avx2.ConvertToVector256Int64
Fix: in GenerateWhereKernelIL, compute `useV256`/`useV128` with an additional
Sse41.IsSupported / Avx2.IsSupported guard — but only when elementSize > 1,
since the 1-byte path is portable. If neither x86 intrinsic set is available
for the required lane size, skip SIMD emission entirely; the scalar IL loop
that follows handles correctness.
Also passes the useV256 decision to EmitWhereSIMDLoop explicitly instead of
recomputing it from VectorBits inside the loop, which was both duplicative and
ignored the IsSupported guard.
Result: on ARM64, byte-typed arrays still use Neon-backed SIMD; int/long/float/
double/short fall back to the scalar IL kernel. On x86 nothing changes.
Verified: 180 np.where + np.asanyarray tests pass on Windows x64 (net8.0 +
net10.0). ARM path awaits CI verification.1 parent 21d7eec commit a5862bd
1 file changed
Lines changed: 15 additions & 8 deletions
Lines changed: 15 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
120 | 129 | | |
121 | 130 | | |
122 | 131 | | |
| |||
139 | 148 | | |
140 | 149 | | |
141 | 150 | | |
142 | | - | |
| 151 | + | |
143 | 152 | | |
144 | | - | |
145 | | - | |
| 153 | + | |
146 | 154 | | |
147 | 155 | | |
148 | 156 | | |
| |||
170 | 178 | | |
171 | 179 | | |
172 | 180 | | |
173 | | - | |
| 181 | + | |
174 | 182 | | |
175 | 183 | | |
176 | | - | |
| 184 | + | |
177 | 185 | | |
178 | 186 | | |
179 | | - | |
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
| |||
0 commit comments