[Bug]: Wrong CPU Softmax results when built with libc++ 22 (Xcode 27)
OpenVINO Version
master fc46784a9a, built from source
Operating System
macOS Systems for Apple Silicon
Device used for inference
CPU
Framework
None
Model used
Any model with Softmax. A single Softmax op is enough.
Issue description
When OpenVINO is built with libc++ 22 (Xcode 27), CPU Softmax gives wrong results on Apple Silicon. softmax([-1, 0, 1]) returns [0.0795, 0.2999, 0.6207] instead of [0.0900, 0.2447, 0.6652]. 19 tests in ov_onnx_frontend_tests fail because of this. The official 2026.4.0 wheel and the nightly wheel are correct on the same machine.
Cause. The oneDNN eltwise injector stores its constants in a std::multimap. Some keys have several entries, for example the 5 coefficients of exp_pol. table_off() and table_val() use entry_map_.find(key) and expect the first entry. The C++ standard does not promise that for a multimap. libc++ 22 changed find() to return any matching entry (llvm/llvm-project#152370). Its release notes say code that relies on this will break and should use lower_bound. Now exp() reads the wrong coefficients, so Softmax is wrong.
I confirmed this with ONEDNN_JIT_DUMP=1. My build and the nightly build generate the same Softmax kernel except for 7 bytes. Those bytes are the addresses of the 5 exp coefficients, and in my build they point 2 entries too far.
Where. The same code is in 4 places. It is in the OpenVINO oneDNN fork and in upstream oneDNN main:
src/cpu/aarch64/injectors/jit_uni_eltwise_injector.hpp:table_off()andtable_val()src/cpu/x64/injectors/jit_uni_eltwise_injector.hpp:table_off()src/cpu/x64/injectors/jit_uni_eltwise_injector.cpp: thelog_predefined_valslookup
Other multi-entry keys like log_pol and tanh_pol_table can be affected too. I only tested exp on aarch64. Linux CI does not see it because libstdc++ still returns the first entry.
Fix. Using entry_map_.lower_bound(key) fixes it. With this change Softmax is correct, the generated kernel is identical to the nightly one, and the ONNX tests go from 25 failures to 6. The other 6 also fail on an older build and are not related.
I have the patch ready. Should I send it to upstream oneDNN first, or to openvinotoolkit/oneDNN?
Step-by-step reproduction
- Build OpenVINO master on an Apple Silicon Mac with Xcode 27.
- Run:
import numpy as np, openvino as ov, openvino.opset13 as ops
p = ops.parameter([3], np.float32)
model = ov.Model([ops.softmax(p, 0)], [p])
compiled = ov.Core().compile_model(model, "CPU", {"INFERENCE_PRECISION_HINT": "f32"})
print(compiled({0: np.array([-1, 0, 1], np.float32)})[0])
# expected: [0.09003056 0.24472848 0.66524094]This small program shows the libc++ change. It prints find -> p1 with libc++ 19 and find -> p2 with libc++ 22:
#include <cstdio>
#include <map>
int main() {
enum key_t { a, b, exp_pol, c, d };
std::multimap<key_t, int> m;
m.insert({a, 100}); m.insert({b, 101});
for (int i = 1; i <= 5; ++i) m.insert({exp_pol, i});
m.insert({c, 102}); m.insert({d, 103});
std::printf("find -> p%d, lower_bound -> p%d\n", m.find(exp_pol)->second, m.lower_bound(exp_pol)->second);
}Relevant log output
$ ONEDNN_VERBOSE=1 python repro.py
onednn_verbose,v1,primitive,exec,cpu,softmax,jit:asimd,forward_inference,src:f32::blocked:a::f0 dst:f32::blocked:a::f0,attr-scratchpad:user,alg:softmax_accurate axis:0,3,0.220947
[0.0795 0.2999 0.6207]
# Generated kernel, nightly (left) vs this build (right). x1 is the constant table.
add x28, x1, #336 | add x28, x1, #368
add x28, x1, #352 | add x28, x1, #384
add x28, x1, #368 | add x28, x1, #400
add x28, x1, #384 | add x28, x1, #416
add x28, x1, #400 | add x28, x1, #432Issue submission checklist
- I'm reporting an issue. It's not a question.
- I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
- There is reproducer code and related data files such as images, videos, models, etc.
Source: openvinotoolkit/openvino