Page MenuHome

Cycles AVX kernel detection leads to crash when CPU does support AVX but OS does NOT
Closed, ResolvedPublic

Description

System Information
Any OS without AVX support (windows 7 pre SP1 and Vista 64 are most common with this)

Blender Version
Broken: Any build after AVX kernel was introduced

Short description of error
http://insufficientlycomplicated.wordpress.com/2011/11/07/detecting-intel-advanced-vector-extensions-avx-in-visual-studio/

Exact steps for others to reproduce the error
Open Blender try to render

Revisions and Commits

rB Blender
Audited
rBAC Blender Add-ons Contrib

Event Timeline

Tested on OS 10.9.1/macbook pro 2013.

With patch still detects AVX successful

The final check need to be (xcr_feature_mask & 0x6) == 0x6.

Tested also on linux x64 and windows x64 and for the true positive case the check still works on all platforms it seems

llvm does this:

  static bool OSHasAVXSupport() {
  #if defined(__GNUC__)
    // Check xgetbv; this uses a .byte sequence instead of the instruction
    // directly because older assemblers do not include support for xgetbv and
    // there is no easy way to conditionally compile based on the assembler used.
    int rEAX, rEDX;
    __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a" (rEAX), "=d" (rEDX) : "c" (0));
  #elif defined(_MSC_FULL_VER) && defined(_XCR_XFEATURE_ENABLED_MASK)
    unsigned long long rEAX = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
  #else
    int rEAX = 0; // Ensures we return false
  #endif
    return (rEAX & 6) == 6;
  }

// If CPUID indicates support for XSAVE, XRESTORE and AVX, and XGETBV 
// indicates that the AVX registers will be saved and restored on context
// switch, then we have full AVX support.
const unsigned AVXBits = (1 << 27) | (1 << 28);
bool HasAVX = ((ECX & AVXBits) == AVXBits) && OSHasAVXSupport();

The latest patch looks good to me.

Only thing I would change is to replace || false by != 0 for consistency with the lines above it.

Martijn Berger (juicyfruit) changed the task status from Unknown Status to Resolved.Feb 25 2014, 6:01 PM

Closed by commit rBef73d547cc7c.