Segfault for Accelerate cblas_sgemv with 4-byte floats not aligned to 32 byte boundary

Originator:matthew.brett
Number:rdar://17250307 Date Originated:06/10/2014
Status:Open Resolved:
Product:OS X SDK Product Version:5.1.0.0.1.1396320587
Classification: Reproducible:Always
 
Summary:
The attached file demonstrates the problem.

Calling cblas_sgemv for matrix data that is not aligned at 8 byte boundaries causes a segfault.   This may be due to unprotected use of AVX instructions because running the code on a machine that does not have AVX does not produce the segfault.

See: https://github.com/numpy/numpy/issues/4007 for discussion

Steps to Reproduce:
Compile and run attached c code:

    cc accelerate_aligned.c -lblas
    ./a.outOutput on my 6,2 MBA:

    0 16 0
    Segmentation fault: 11

Expected Results:
No segmentation fault. 

Actual Results:
Output on my 6,2 MBA:

    0 16 0
    Segmentation fault: 11

Version:
XCode version : 5.1.0.0.1.1396320587
OSX version : 10.9.3 (13D65)

Notes:


Configuration:
Does not segfault on two OSX machines without AVX.  However, these are running 10.6 and 10.7.


accelerate_aligned.c

// cc file.c -lblas
#include <stdlib.h>
#include <stdio.h>
#include "Accelerate/Accelerate.h"

int main(int argc, const char *argv[])
{
    long m = 10000;
    long n = 200;
    float * A = calloc(m*n + 4, sizeof(float));
    float * X = calloc(m*n + 4, sizeof(float));
    float * R = calloc(m*n + 4, sizeof(float));
    X +=4;
    printf("%ld %ld %ld", (long)A % 32, (long)X % 32, (long)R % 32);
    puts("");
    cblas_sgemv(CblasRowMajor, CblasNoTrans, m, n, 1.f, A, n, X, 1,
                 0.f, R, 1);
    return 0;
}

Comments

Response from Apple to corresponding bug report on https://bugreport.apple.com

Apple replied to my bug report containing the same text as here.

They said the bug is fixed in OS X Yosemite GM (Build 14A389), and that appears to be right.

They said they had no plan to backport the fix to 10.9.

By matthew.brett at Oct. 28, 2014, 11:41 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!