diffstruc__operations_linalg_sub Submodule

Submodule containing implementations of linear algebra operations


Uses


Interfaces

interface

  • subroutine sgemm(transa, transb, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc)

    Arguments

    Type IntentOptional Attributes Name
    character(len=1), intent(in) :: transa
    character(len=1), intent(in) :: transb
    integer, intent(in) :: m
    integer, intent(in) :: n
    integer, intent(in) :: k
    real(kind=real32), intent(in) :: alpha
    real(kind=real32), intent(in) :: A(lda,*)
    integer, intent(in) :: lda
    real(kind=real32), intent(in) :: B(ldb,*)
    integer, intent(in) :: ldb
    real(kind=real32), intent(in) :: beta
    real(kind=real32), intent(inout) :: C(ldc,*)
    integer, intent(in) :: ldc

interface

  • subroutine sgemv(trans, m, n, alpha, A, lda, x, incx, beta, y, incy)

    Arguments

    Type IntentOptional Attributes Name
    character(len=1), intent(in) :: trans
    integer, intent(in) :: m
    integer, intent(in) :: n
    real(kind=real32), intent(in) :: alpha
    real(kind=real32), intent(in) :: A(lda,*)
    integer, intent(in) :: lda
    real(kind=real32), intent(in) :: x(*)
    integer, intent(in) :: incx
    real(kind=real32), intent(in) :: beta
    real(kind=real32), intent(inout) :: y(*)
    integer, intent(in) :: incy

Functions

function get_partial_dot_product_left(this, upstream_grad) result(output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)

function get_partial_dot_product_right(this, upstream_grad) result(output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)

function get_partial_matmul_left(this, upstream_grad) result(output)

Get partial derivative with respect to left operand of matmul

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)

function get_partial_matmul_right(this, upstream_grad) result(output)

Get partial derivative with respect to right operand of matmul

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)

function get_partial_outer_product_left(this, upstream_grad) result(output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)

function get_partial_outer_product_right(this, upstream_grad) result(output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)

function get_partial_transpose_left(this, upstream_grad) result(output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this
type(array_type), intent(in) :: upstream_grad

Return Value type(array_type)


Subroutines

pure subroutine get_partial_dot_product_left_val(this, upstream_grad, output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in) :: this
real(kind=real32), intent(in), dimension(:,:) :: upstream_grad
real(kind=real32), intent(out), dimension(:,:) :: output

pure subroutine get_partial_dot_product_right_val(this, upstream_grad, output)

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in) :: this
real(kind=real32), intent(in), dimension(:,:) :: upstream_grad
real(kind=real32), intent(out), dimension(:,:) :: output

subroutine get_partial_matmul_left_val(this, upstream_grad, output)

Compute gradient w.r.t. left operand for matmul in reverse mode.

Read more…

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in) :: this
real(kind=real32), intent(in), dimension(:,:) :: upstream_grad
real(kind=real32), intent(out), dimension(:,:) :: output

subroutine get_partial_matmul_left_val_sum(this, upstream_grad, output)

Sum-reduced gradient w.r.t. left operand for matmul. For the outer product case (rank-1 right operand), this computes: output = sum_s(upstream(:,s) (x) right(:,s)) = upstream * right^T using a single SGEMM call instead of computing the full (n_elem, S) array.

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in) :: this
real(kind=real32), intent(in), dimension(:,:) :: upstream_grad
real(kind=real32), intent(out), dimension(:) :: output

subroutine get_partial_matmul_right_val(this, upstream_grad, output)

Compute gradient w.r.t. right operand for matmul in reverse mode.

Read more…

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in) :: this
real(kind=real32), intent(in), dimension(:,:) :: upstream_grad
real(kind=real32), intent(out), dimension(:,:) :: output

subroutine get_partial_matmul_right_val_sum(this, upstream_grad, output)

Sum-reduced gradient w.r.t. right operand for matmul. For the outer product case (rank-1 left operand), this computes: output = sum_s(left(:,s) (x) upstream(:,s)) = left * upstream^T using a single SGEMM call.

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in) :: this
real(kind=real32), intent(in), dimension(:,:) :: upstream_grad
real(kind=real32), intent(out), dimension(:) :: output

Module Functions

module function dot_product_arrays(a, b) result(c)

Dot product of two autodiff arrays

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in), target :: a
class(array_type), intent(in), target :: b

Return Value type(array_type), pointer

module function matmul_arrays(a, b) result(c)

Matrix multiplication of two autodiff arrays

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in), target :: a
class(array_type), intent(in), target :: b

Return Value type(array_type), pointer

module function matmul_real2d(a, b) result(c)

Matrix multiplication of a real array and an autodiff array Computes C = a * b where a is autodiff (vector per sample) and b is a real 2D matrix. Equivalent to C(:,s) = b^T * a(:,s) for each sample s.

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in), target :: a
real(kind=real32), intent(in), dimension(:,:) :: b

Return Value type(array_type), pointer

module function outer_product_arrays(a, b) result(c)

Outer product of two autodiff arrays

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in), target :: a
class(array_type), intent(in), target :: b

Return Value type(array_type), pointer

module function real2d_matmul(a, b) result(c)

Matrix multiplication of a real 2D matrix and an autodiff array Computes C = a * b where a is a real matrix and b is autodiff

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in), dimension(:,:) :: a
class(array_type), intent(in), target :: b

Return Value type(array_type), pointer

module function transpose_array(a) result(c)

Transpose an autodiff array

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(in), target :: a

Return Value type(array_type), pointer