Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transposed operations segfault #82

Open
RylanYancey opened this issue Oct 30, 2023 · 1 comment
Open

Transposed operations segfault #82

RylanYancey opened this issue Oct 30, 2023 · 1 comment

Comments

@RylanYancey
Copy link

I'm using matrixmultiply for machine learning, and I'm trying to perform the operation:

GB = A^T * GC

where:
GB = (6272, 100)
A = (100, 6272)
GC = (100, 100)

After transposition of A, we end up with a valid matrix multiplication.

However, when I run the following function, I get SIGSEGV: Invalid Memory Reference. I'm not sure if I'm doing something wrong or if its an internal error, so I thought I'd post here. I was under the impression that for transposition, all you did was swap the rsa and csa, but again I could be wrong.

#[inline]
pub unsafe fn matmul_wrt_b(
    a: *const f32,
    gc: *const f32,
    gb: *mut f32,
    a_dim: [usize; 2],
    b_dim: [usize; 2],
    beta: f32,
) {
    // Check that the dimensions are compatible for multiplication
    assert_eq!(a_dim[1], b_dim[0]);

   // Dimensions of GC are (a_dim[0], b_dim[1])
   // Dimensions of GB are the same as B. 
  
    // Compute the gradient of the matrix product
    sgemm(
        a_dim[0],                    
        a_dim[1],                    
        b_dim[1],                    
        1.0,                         
        a,                                              
        1,         
        a_dim[1] as isize, 
        gc,                           
        a_dim[1] as isize,           
        1,                           
        beta,                        
        gb,                          
        b_dim[1] as isize,           
        1,                           
    );
}
@bluss
Copy link
Owner

bluss commented Oct 30, 2023

swapping rsa, csa sounds right, but effective matrix sizes also need to be input. I can't check your values, but you need to input the effective size - i.e. the relevant side of the matrix after it is transposed. There is no 'transpose' in the API, so this is the only way you can submit the information. Sizes, strides. Hope it works out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants