Quantcast
Channel: Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 2652

dgemv - Invalid memory access for small dynamically allocated arrays

$
0
0

Hello,

I do a blas matrix/vector product with this simple code in VS2013:

#include "mkl.h"
#include <stdio.h>
int main(){
const int M = 2;
const int N = 3;
double *x = new double[N];
double *A = new double[M*N];
double *b = new double[M];
for (int i = 0; i < M; i++){
    b[i] = 0.0; //Not necessary but anyway...
    for (int j = 0; j < N; j++){
        A[j * M + i] = i + j * 2;
    }
}
for (int j = 0; j < N; j++)
    x[j] = j*j;
const int incr = 1;
const double alpha = 1.0;
const double beta = 0.0;
const char no = 'N';
dgemv(&no, &M, &N, &alpha, A, &M, x, &incr, &beta, b, &incr );
printf("b = [%e %e]'\n",b[0],b[1]);

delete[] x;
delete[] A;
delete[] b;

}

While the displayed result is as expected ([18, 23]), Intel Inspector finds one invalid memory accessand 2 invalid partial memory access when calling dgemv. The invalid memory access and one invalid partial memory access are related to memory allocated corresponding to the vector b. The second invalid partial memory access is related with the memory allocated for A. I do not get any error if I use a static array.

It also happens with other MKL functions, such as dgesv or with cblas_dgemv. The error appears only on small-size arrays, probably because MKL is trying to access memory in large chunks for efficiency. After more testing, I concluded that M needs to be at least 20 in order to not get an error. N can be any positive number.

I use Intel Inspector XE 2016 and intel C++ Compiler 16.0 with MKL 11.3 update 4, run sequential.

Is it safe anyway to use MKL on small matrices?

 

This is a question I originally posted on stackoverflow, but it looks like it may be a bug:

http://stackoverflow.com/questions/40303672/mkl-dgemv-invalid-memory-acc...

Thread Topic: 

Bug Report

Viewing all articles
Browse latest Browse all 2652

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>