Skip to content

[R][C++][Packaging] Illegal opcode error on aggregate Array/ChunkedArray of integer #28343

Closed as not planned

Description

@asfimport

I see this error with the 4.0.0 version of the R package with the C++ library from Homebrew:

sum(Array$create(c(1L, 2L))) 

## *** caught illegal operation ***
## address 0x109f1b45c, cause 'illegal opcode'

This is on an Intel Mac running Big Sur 11.3 with AVX2 support but no AVX512 support.

This happens regardless of whether I build the Homebrew formula locally or install the pre-built bottle.

Reporter: Ian Cook / @ianmcook

Related issues:

Original Issue Attachments:

Note: This issue was originally created as ARROW-12587. Please see the migration documentation for further details.

Activity

  1. asfimport commented on Apr 29, 2021

    @asfimport
    Author

    David Li / @lidavidm:
    According to a disassembler, it's crashing on an AVX512 instruction, so maybe Arrow is picking the wrong SIMD level, or was built with the wrong flags:

    
    Raw Hex (zero bytes in bold):
    
    62F1FF087BC0BF3800   
    
    String Literal:
    
    "\x62\xF1\xFF\x08\x7B\xC0\xBF\x38\x00"
    
    Array Literal:
    
    { 0x62, 0xF1, 0xFF, 0x08, 0x7B, 0xC0, 0xBF, 0x38, 0x00 }
    Disassembly:
    
    0:  62 f1 ff 08 7b c0       vcvtusi2sd xmm0,xmm0,rax
    6:  bf                      .byte 0xbf
    7:  38 00                   cmp    BYTE PTR [rax],al
    

    The backtrace ends at arrow::compute::aggregate::MeanImpl<arrow::Int32Type, (arrow::compute::SimdLevel::type)4>::Finalize and SimdLevel = 4 corresponds to AVX512.

  2. asfimport commented on Apr 30, 2021

    @asfimport
    Author

    Ian Cook / @ianmcook:
    Setting -DARROW_RUNTIME_SIMD_LEVEL=AVX2 in the Homebrew formula (apache-arrow.rb) stops this error

    As a band-aid fix, I can add this to the formula:

    args << "-DARROW_RUNTIME_SIMD_LEVEL=AVX2" if MacOS.version == :big_sur 

    or to ensure it will work with older Macs that don't support AVX2 but can still run Big Sur (e.g. older Mac Pros) maybe we should set it to SSE4_2.

  3. asfimport commented on Apr 30, 2021

    @asfimport
    Author

    Neal Richardson / @nealrichardson:
    Is arrow picking the wrong runtime SIMD level? This should be available from R in arrow_info().

    Or do we have runtime-dispatched AVX512 code that is flagged as AVX2?

    Or something else?

  4. asfimport commented on Apr 30, 2021

    @asfimport
    Author

    Ian Cook / @ianmcook:
    When I build libarrow with

     HOMEBREW_NO_AUTO_UPDATE=1 brew install --build-from-source ./apache-arrow.rb

    using apache-arrow.rb downloaded from https://github.com/Homebrew/homebrew-core/blob/master/Formula/apache-arrow.rb, arrow_info() reports:

    Runtime:
                            
    SIMD Level          avx2
    Detected SIMD Level avx2

    The same happens if I modify apache-arrow.rb to and add -DARROW_RUNTIME_SIMD_LEVEL=MAX or -DARROW_RUNTIME_SIMD_LEVEL=AVX2.

    So it seems like there is an AVX512 instruction being executed when it shouldn't.

  5. asfimport commented on Apr 30, 2021

    @asfimport
    Author
  6. asfimport commented on Apr 30, 2021

    @asfimport
    Author

    Ian Cook / @ianmcook:
    [~frank.du] we are seeing false positives for AVX512 support on Intel Macs running Big Sur. Do you know what might be causing this? Thank you.

  7. asfimport commented on Apr 30, 2021

    @asfimport
    Author

    Jonathan Keane / @jonkeane:

    or to ensure it will work with older Macs that don't support AVX2 but can still run Big Sur (e.g. older Mac Pros) maybe we should set it to SSE4_2.

    On my macpro (late 2013) I have AVX1.0 (though it's not in machdep.cpu.leaf7_features it is in machdep.cpu.features. I'm not sure if there are any big sur compatible machines that don't have avx 1

    jkeane@het arrow % sysctl -a | grep machdep.cpu.features      
    machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX SMX EST TM2 SSSE3 CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC POPCNT AES PCID XSAVE OSXSAVE TSCTMR AVX1.0 RDRAND F16C

    And arrow_info() seems to catch that:

    ...
    Runtime:
                           
    SIMD Level          avx
    Detected SIMD Level avx
  8. asfimport commented on May 3, 2021

    @asfimport
    Author

    Jeroen / @jeroen:
    I am also seeing a crash in the R, when we build the R package on big sur using the big-sur autobrew bottles. OTOH binaries for MacOS 10.11-10.15 seem fine. Running the unit tests dies like this (attached the Console stack trace from macos: big-sur-crash.txt).

    This seems a lot like https://issues.apache.org/jira/browse/ARROW-11217 which also involved arrow::compute::aggregate::SumImpl()

    ✔ |   3       | arrow-info
    ✔ |  10       | General checks [0.3 s]
    ✔ |  12       | backwards-compatibility
    ✔ |  12       | BufferReader
    ✔ |  24       | Buffer
    ✔ | 281       | ChunkedArray [0.4 s]
    ✔ |  12       | Compressed.*Stream
    ⠏ |   0       | compute: aggregation
     *** caught illegal operation ***
    address 0x1089cc6dc, cause 'illegal opcode'
    
    Traceback:
     1: compute__CallFunction(function_name, args, options)
     2: call_function(FUN, a, options = list(na.rm = na.rm))
     3: scalar_aggregate("sum", ..., na.rm = na.rm)
     4: sum.ArrowDatum(<environment>, na.rm = FALSE)
     5: eval_bare(expr, quo_get_env(quo))
     6: quasi_label(enquo(object), arg = "object")
     7: expect_s3_class(object, class)
     8: expect_r6_class(sum(a), "Scalar")
     9: eval(code, test_env)
  9. asfimport commented on May 3, 2021

    @asfimport
    Author

    Neal Richardson / @nealrichardson:
    @jeroen thanks. This is on an Intel mac, to be clear? (IIRC we thought the other issue was about Rosetta emulation.)

  10. asfimport commented on May 3, 2021

    @asfimport
    Author

    Jeroen / @jeroen:
    @nealrichardson  Yes indeed, ARROW-11217 would crash under the intel emulator but now we get the crash on native intel hardware.

    The crash does not happen on M1. It also does not happen if we use binaries compiled on macos 10.13 (which is the CRAN default). It only happens when using arrow built under big sur.

  11. asfimport commented on May 4, 2021

    @asfimport
    Author

    Ian Cook / @ianmcook:
    Discussion about this also at Homebrew/homebrew-core#76537

  12. asfimport commented on May 16, 2021

    @asfimport
    Author

    Webb Phillips:
    Same problem occurs after updating the MacPorts apache-arrow Portfile to apache-arrow-4.0.0.

  13. asfimport commented on May 16, 2021

    @asfimport
    Author

    Neal Richardson / @nealrichardson:
    For what it's worth, we don't maintain or test the MacPorts formula (I honestly didn't know macports was still a thing). I see https://github.com/macports/macports-ports/blob/master/devel/apache-arrow/Portfile exists but it still says 3.0.0.

  14. asfimport commented on Jul 5, 2021

    @asfimport
    Author

    Carlo Cabrera:
    I've merged a fix that disables the filtering of -march flags in the Arrow build in Homebrew/core. This should hopefully fix this issue with the Homebrew formula.

    I hope you have your runtime detection working correctly for everything that Arrow builds – otherwise we might have to just disable AVX512 on the formula entirely.

    I'm particularly concerned about vendored dependencies being tuned for the build-time CPU. (If they're not, they're probably being built for Penryn, which I'll note is a step down from what the Homebrew formula used to build them for.)

  15. asfimport commented on Jul 12, 2022

    @asfimport
    Author

    Todd Farmer / @toddfarmer:
    This issue was last updated over 90 days ago, which may be an indication it is no longer being actively worked. To better reflect the current state, the issue is being unassigned. Please feel free to re-take assignment of the issue if it is being actively worked, or if you plan to start that work soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions