Skip to content

Commit 206cf07

Browse files
author
Awni Hannun
authored
Fix non simd f16 build (ml-explore#3097)
1 parent f47729c commit 206cf07

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

mlx/backend/cpu/simd/base_simd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ struct Simd<T, 1> {
2929
Simd(Simd<U, 1> v) : value(v.value) {}
3030
template <typename U>
3131
Simd(U v) : value(v) {}
32+
33+
T operator[](int) const {
34+
return value;
35+
}
36+
37+
T& operator[](int) {
38+
return value;
39+
}
3240
};
3341

3442
template <typename T, int N>

mlx/backend/cpu/unary_ops.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,18 @@ struct FromFP8 {
155155
template <int N>
156156
Simd<float, N> operator()(Simd<uint8_t, N> x) {
157157
auto v = Simd<uint16_t, N>(x & 127) << 7;
158-
auto converted = *(Simd<float16_t, N>*)(&v);
159-
converted = converted * 256.0;
158+
Simd<float, N> out;
159+
if constexpr (simd::max_size<float16_t> >= N) {
160+
auto converted = *(Simd<float16_t, N>*)(&v);
161+
out = converted * 256.0;
162+
} else {
163+
for (int i = 0; i < N; ++i) {
164+
auto converted = *(float16_t*)(&v[i]);
165+
out[i] = converted * 256.0;
166+
}
167+
}
160168
auto sign = Simd<bool, N>(x & 128);
161-
Simd<float, N> out = select(sign, -converted, converted);
162-
return out;
169+
return select(sign, -out, out);
163170
}
164171
float operator()(uint8_t x) {
165172
return (*this)(Simd<uint8_t, 1>(x)).value;

0 commit comments

Comments
 (0)