Skip to content

cblas_dgemv error during matrix multiplication #1085

Closed

Description

@YuhanLiin

I've been sometimes getting the error message Intel MKL ERROR: Parameter 9 was incorrect on entry to cblas_dgemv. when running A.dot(b), where A is 2-D and b is 1-D. This happens when I link with the Intel MKL library. This doesn't crash the program but leads to the wrong result. Does anyone know what the error message means?

Activity

  1. jturner314 commented on Oct 22, 2021

    @jturner314
    Member

    Can you provide an example? In particular, it would be helpful to print the following for each array:

    println!("ptr: {:?}, shape: {:?}, strides: {:?}", array.as_ptr(), array.shape(), array.strides());

    These are the docs for Intel's cblas_dgemv implementation. I'm guessing that parameter 9 is the incx parameter, which the docs say must not be zero. If the 1-D array is the result of broadcasting, its stride may be zero, and I'm not sure if ndarray checks for that before calling cblas_dgemv. I'm also not sure what happens if the stride is negative.

  2. YuhanLiin commented on Oct 23, 2021

    @YuhanLiin
    ContributorAuthor

    This is the code:

            let A = array![[0.], [1.], [2.]];
            let mut x = array![1., 4.];
            x.remove_index(Axis(0), x.len() - 1);
            println!(
                "A: {:?}, shape: {:?}, strides: {:?}",
                A.as_ptr(),
                A.shape(),
                A.strides()
            );
            println!(
                "x: {:?}, shape: {:?}, strides: {:?}",
                x.as_ptr(),
                x.shape(),
                x.strides()
            );
            println!("{}", A.dot(&x));

    This is the printout:

    A: 0x7f72b4000c00, shape: [3, 1], strides: [1, 1]
    x: 0x7f72b4000c20, shape: [1], strides: [0]
    
    Intel MKL ERROR: Parameter 9 was incorrect on entry to cblas_dgemv.
    [0, 0, 0]
    

    Looks like remove_index is setting the stride to 0. Things work fine with 1-D arrays when I don't use it.

  3. jturner314 commented on Oct 23, 2021

    @jturner314
    Member

    #1088 should fix this issue. Will you please confirm? A simple way to test would be to add the following to your Cargo.toml:

    [patch.crates-io]
    ndarray = { git = 'https://github.com/jturner314/ndarray.git', branch = 'fix-blas_compat_1d-stride0' }
  4. YuhanLiin commented on Oct 23, 2021

    @YuhanLiin
    ContributorAuthor

    I get this printout instead:

    A: 0x7fac64000c00, shape: [3, 1], strides: [1, 1]
    x: 0x7fac64000c20, shape: [1], strides: [0]
    [0, 1, 2]
    

    The error is no longer present and the result is correct. The stride of the 2nd array is still 0 but I don't know if that's a bug.

  5. jturner314 commented on Oct 23, 2021

    @jturner314
    Member

    Okay, great. Thanks for confirming that the PR fixes the issue. The stride of 0 is not a bug – for a 1-D array with length 1, the stride is arbitrary.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions