Skip to content

Commit

Permalink
Venado optimizations (#755)
Browse files Browse the repository at this point in the history
* Add build script for venado hackathon

* Add preliminary method to set matrix size

* Add build scripts for hackathon

* Add bml_transpose_inplace Fortran subroutine

* Modify Fortran bml_transpose API to match the C interface

* Modify tests to use new transpose API

* Venado build modifications

* Move build scripts to scripts/ dir

* Expose dense matrix pointer using bml_get_ptr_dense

* New introspection methods

o Back out bml_get_ptr_dense() from bml_getters
o Write fortran wrapper for existing bml_get_data_ptr_dense() method
o Write new bml_get_ld_dense() to enable magma matrix pointer use

* Remove LANL-specific build scripts

* Remove an additional LANL specific build script

* Add N_allocated and check in bml_set_N_dense

* Reallocate if bml_set_N_dense fails test

* Remove LANL-specific build script

* Fix linter issues

* Fix syntax error in workflow (#758)

Signed-off-by: Nicolas Bock <[email protected]>

* Update GitHub checkout action (#757)

Signed-off-by: Nicolas Bock <[email protected]>

* Add yaml extension to dev container (#756)

Helpful when editing workflow files.

Signed-off-by: Nicolas Bock <[email protected]>

* Add another VSCode extension to container (#759)

Signed-off-by: Nicolas Bock <[email protected]>

* Update version of artifact action (#761)

Signed-off-by: Nicolas Bock <[email protected]>

* Update compiler for OS X runner (#762)

Signed-off-by: Nicolas Bock <[email protected]>

* Linter fix

---------

Signed-off-by: Nicolas Bock <[email protected]>
Co-authored-by: Nicolas Bock <[email protected]>
  • Loading branch information
mewall and nicolasbock authored Feb 5, 2025
1 parent bda9a9a commit f386348
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/C-interface/dense/bml_allocate_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ bml_matrix_dense_t *TYPED_FUNC(
A->matrix_type = dense;
A->matrix_precision = MATRIX_PRECISION;
A->N = matrix_dimension.N_rows;
A->N_allocated = A->N;
A->distribution_mode = distrib_mode;
#ifdef BML_USE_MAGMA
A->ld = magma_roundup(matrix_dimension.N_rows, 32);
Expand Down Expand Up @@ -154,6 +155,7 @@ bml_matrix_dense_t *TYPED_FUNC(
A->matrix_type = dense;
A->matrix_precision = MATRIX_PRECISION;
A->N = matrix_dimension.N_rows;
A->N_allocated = A->N;
A->distribution_mode = distrib_mode;
#ifdef BML_USE_MAGMA
A->ld = magma_roundup(matrix_dimension.N_rows, 32);
Expand Down
19 changes: 19 additions & 0 deletions src/C-interface/dense/bml_introspection_dense.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,22 @@ bml_get_data_ptr_dense(
{
return A->matrix;
}

/** Return the dense matrix ld parameter.
*
* \param A The dense matrix.
* \return The matrix ld parameter.
*/
int
bml_get_ld_dense(
bml_matrix_dense_t * A)
{
if (A != NULL)
{
return A->ld;
}
else
{
return -1;
}
}
31 changes: 31 additions & 0 deletions src/C-interface/dense/bml_setters_dense.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@
#include "../bml_logger.h"
#include "bml_setters_dense.h"
#include "bml_types_dense.h"
#include "bml_allocate_dense.h"

#ifdef BML_USE_MAGMA
#include "magma_v2.h"
#endif

void
bml_set_N_dense(
bml_matrix_dense_t * A,
int N)
{
if (A->N <= A->N_allocated)
{
A->N = N;
#ifdef BML_USE_MAGMA
A->ld = magma_roundup(A->N, 32);
#else
A->ld = A->N;
#endif
}
else
{
bml_matrix_dense_t *B;
bml_matrix_dimension_t matrix_dimension = { A->N, A->N, A->N };

B = bml_noinit_matrix_dense(A->matrix_precision, matrix_dimension,
A->distribution_mode);
bml_deallocate_dense(A);
A = B;
}
}

void
bml_set_element_dense(
Expand Down
4 changes: 4 additions & 0 deletions src/C-interface/dense/bml_setters_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

#include <complex.h>

void bml_set_N_dense(
bml_matrix_dense_t * A,
int N);

void bml_set_element_dense(
bml_matrix_dense_t * A,
int i,
Expand Down
2 changes: 2 additions & 0 deletions src/C-interface/dense/bml_types_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct bml_matrix_dense_t
bml_distribution_mode_t distribution_mode;
/** The number of rows/columns. */
int N;
/** The number of rows/columns originally allocated. */
int N_allocated;
/** The dense matrix. */
void *matrix;
/** The leading dimension of the array matrix. */
Expand Down
23 changes: 23 additions & 0 deletions src/Fortran-interface/bml_c_interface_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,18 @@ function bml_get_bandwidth_C(a) bind(C, name="bml_get_bandwidth")
integer(C_INT) :: bml_get_bandwidth_C
end function bml_get_bandwidth_C

function bml_get_data_ptr_dense_C(a) bind(C, name="bml_get_data_ptr_dense")
import :: C_PTR
type(C_PTR), value, intent(in) :: a
type(C_PTR) :: bml_get_data_ptr_dense_C
end function bml_get_data_ptr_dense_C

function bml_get_ld_dense_C(a) bind(C, name="bml_get_ld_dense")
import :: C_PTR, C_INT
type(C_PTR), value, intent(in) :: a
integer(C_INT) :: bml_get_ld_dense_C
end function bml_get_ld_dense_C

function bml_get_sparsity_C(a, threshold) bind(C, name="bml_get_sparsity")
import :: C_PTR, C_DOUBLE, C_INT
type(C_PTR), value, intent(in) :: a
Expand Down Expand Up @@ -448,6 +460,12 @@ subroutine bml_scale_inplace_C(alpha, a) bind(C, name="bml_scale_inplace")
type(C_PTR), value :: a
end subroutine bml_scale_inplace_C

subroutine bml_set_N_dense_C(a,n) bind(C, name="bml_set_N_dense")
import :: C_PTR, C_INT
type(C_PTR), value, intent(in) :: a
integer(C_INT), value, intent(in) :: n
end subroutine bml_set_N_dense_C

subroutine bml_set_row_C(a, i, row, threshold) bind(C, name="bml_set_row")
import :: C_PTR, C_INT, C_DOUBLE
type(C_PTR), value, intent(in) :: a
Expand Down Expand Up @@ -616,6 +634,11 @@ function bml_transpose_new_C(a) bind(C, name="bml_transpose_new")
type(C_PTR) :: bml_transpose_new_C
end function bml_transpose_new_C

subroutine bml_transpose_C(a) bind(C, name="bml_transpose")
import :: C_PTR
type(C_PTR), value, intent(in) :: a
end subroutine bml_transpose_C

subroutine bml_write_bml_matrix_C(a, filename) &
& bind(C, name="bml_write_bml_matrix")
import :: C_PTR, C_CHAR
Expand Down
23 changes: 23 additions & 0 deletions src/Fortran-interface/bml_introspection_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module bml_introspection_m
public :: bml_get_bandwidth
public :: bml_get_distribution_mode
public :: bml_get_sparsity
public :: bml_get_data_ptr_dense
public :: bml_get_ld_dense

contains

Expand Down Expand Up @@ -247,4 +249,25 @@ function bml_get_sparsity(a, threshold) result(sparsity)

end function bml_get_sparsity

function bml_get_data_ptr_dense(a)
type(bml_matrix_t), intent(inout) :: a
type(C_PTR) :: bml_get_data_ptr_dense

bml_get_data_ptr_dense = bml_get_data_ptr_dense_C(a%ptr)

end function bml_get_data_ptr_dense

!> Return the dense matrix ld parameter.
!!
!!\param a The matrix.
!!\return The matrix ld parameter.
function bml_get_ld_dense(a)

type(bml_matrix_t), intent(in) :: a
integer :: bml_get_ld_dense

bml_get_ld_dense = bml_get_ld_dense_C(a%ptr)

end function bml_get_ld_dense

end module bml_introspection_m
9 changes: 9 additions & 0 deletions src/Fortran-interface/bml_setters_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ module bml_setters_m
public :: bml_set_diagonal
public :: bml_set_element
public :: bml_set_element_new
public :: bml_set_N_dense

contains

subroutine bml_set_N_dense(a,n)
type(bml_matrix_t), intent(inout) :: a
integer(C_INT), intent(in) :: n

call bml_set_N_dense_C(a%ptr,n)

end subroutine bml_set_N_dense

!Setters for element new
subroutine bml_set_element_new_single_real(a,i,j,element)

Expand Down
12 changes: 10 additions & 2 deletions src/Fortran-interface/bml_transpose_m.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ module bml_transpose_m
implicit none
private

public :: bml_transpose
public :: bml_transpose_new, bml_transpose

contains

!> Return the transpose of a matrix.
!!
!! @param a The matrix.
!! @param a_t The transpose.
subroutine bml_transpose(a, a_t)
subroutine bml_transpose_new(a, a_t)

type(bml_matrix_t), intent(in) :: a
type(bml_matrix_t), intent(inout) :: a_t

call bml_deallocate(a_t)
a_t%ptr = bml_transpose_new_C(a%ptr)

end subroutine bml_transpose_new

subroutine bml_transpose(a)

type(bml_matrix_t), intent(in) :: a

call bml_transpose_C(a%ptr)

end subroutine bml_transpose

end module bml_transpose_m
4 changes: 2 additions & 2 deletions tests/Fortran-tests/diagonalize_matrix_typed.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function test_diagonalize_matrix_typed(matrix_type, element_kind, element_precis
call bml_random_matrix(matrix_type, element_kind, element_precision, n, m, &
& a)
call bml_print_matrix("A", a, 1, n, 1, n)
call bml_transpose(a, a_t)
call bml_transpose_new(a, a_t)
call bml_print_matrix("A_t", a_t, 1, n, 1, n)
call bml_add(a, a_t, 0.5d0, 0.5d0, threshold)
call bml_print_matrix("A", a, 1, n, 1, n)
Expand All @@ -44,7 +44,7 @@ function test_diagonalize_matrix_typed(matrix_type, element_kind, element_precis
& eigenvectors)
!! \todo Fixme: diagonalization routine is not respecting precision
call bml_diagonalize(a, eigenvalues, eigenvectors)
call bml_transpose(eigenvectors, eigenvectors_t)
call bml_transpose_new(eigenvectors, eigenvectors_t)
call bml_zero_matrix(matrix_type, element_kind, element_precision, n, m, b)
call bml_zero_matrix(matrix_type, element_kind, element_precision, n, m, c)
call bml_multiply(eigenvectors_t, eigenvectors, b)
Expand Down
2 changes: 1 addition & 1 deletion tests/Fortran-tests/io_matrix_typed.F90
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module io_matrix_typed

public :: test_io_matrix_typed

#ifdef CRAY_SDK
#if defined(CRAY_SDK) || defined(NVHPC_SDK)
interface
integer(c_int) function getpid() bind(c,name="getpid")
use iso_c_binding
Expand Down
2 changes: 1 addition & 1 deletion tests/Fortran-tests/transpose_matrix_typed.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function test_transpose_matrix_typed(matrix_type, element_kind, element_precisio

call bml_random_matrix(matrix_type, element_kind, element_precision, n, m, &
& a)
call bml_transpose(a, b)
call bml_transpose_new(a, b)
call bml_copy_new(a, c)

call bml_export_to_dense(a, a_dense)
Expand Down

0 comments on commit f386348

Please sign in to comment.