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

Add SLATE for Distributed Memory Linear Algebra #407

Draft
wants to merge 51 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7301417
Added SLATE to FetchOrFind Dependencies + config, added dummy test case
Jun 1, 2023
fb76f52
[skip ci] [slate] Add dummy SLATE conversion example driver
Jun 1, 2023
2833cc9
[skip ci] Prototype for converting between TA PMap and SLATE functors
Jun 2, 2023
e8608e1
[skip ci] Copy from TA -> SLATE works
Jun 3, 2023
fa0076b
[skip ci] Wrapped up TA -> SLATE into a stand alone function
Jun 5, 2023
39b5983
Fixed bug in UserPmap::begin/end inconsistency, added slate_to_array
Jun 6, 2023
6207b68
[skip ci] minor dox
Jun 6, 2023
e87d2c3
Add conversions/slate.h move SLATE conversions
Jun 9, 2023
9023b1b
[skip ci] Cleanup of SLATE example code
Jun 9, 2023
61fbe42
[skip ci] Cleanup++
Jun 9, 2023
7950fa0
Added unit test for TA -> SLATE conversion
Jul 24, 2023
eda1009
Added SlateFunctors to wrap-up TA -> SLATE metadata
Jul 24, 2023
cc109c2
Minor cleanup + factor SLATE -> Pmap generation into separate function
Jul 24, 2023
aa5834d
Cleanup
Jul 24, 2023
46f556e
[skip ci] Added test for TA -> SLATE conversion
Jul 24, 2023
24e082b
SLATE Cholesky Interface + UT, added zero_triangle utilitiy
Jul 25, 2023
12627e7
SLATE Cholesky Linv + UT
Jul 25, 2023
6d1ec1f
Added SLATE impls for cholesky_{l,}solve, need UTs for both SLATE and…
Jul 25, 2023
2300b64
[skip ci] SLATE LU_SOLVE API added, test fails but standalone works
Jul 25, 2023
5bcd73f
Added SLATE HEIG implementation + UT
Aug 1, 2023
e8f8569
Merge branch 'master' into feature/slate_linear_algebra
Aug 1, 2023
a4d825c
Fix ScaLAPACK unit test build, add HEIG test for ScaLAPACK
Aug 1, 2023
8423308
Fix MPI + distributed HEIG unit test
Aug 2, 2023
3808609
Merge branch 'master' into feature/slate_linear_algebra
Aug 2, 2023
8bb9cf5
[skip ci] Add stubs for SLATE QR
Aug 2, 2023
ddad01e
Add ScaLAPACK SVD-values check in UTs
Aug 2, 2023
f041af7
Minor refactor of linalg testing starategy for SLATE/ScaLAPACK, add S…
Aug 22, 2023
7c21800
Flesh out ScaLAPACK unit tests
Aug 22, 2023
cad781d
Add additional SLATE conversion tests with random tiling
Aug 22, 2023
65b3529
Refactor linalg tests
Aug 23, 2023
4e2d34e
Refactor reference/identity generation in linalg UTs
Aug 23, 2023
b1087f6
Linalg tests are now OO to allow for easier extensibility
Aug 23, 2023
316ee14
Moved ScaLAPACK + SLATE tests over to new OO UT framework, disable an…
Aug 23, 2023
29086c3
Move QR tests over to new OO infrastructure
Aug 23, 2023
2afee0b
Enable SLATE tests that were held up by https://github.com/icl-utk-ed…
Aug 23, 2023
f12535c
Added slate::lu_inv + UT
Aug 23, 2023
a44a2ca
Fleshed out SLATE SVD API + enabled all SVD UTs
Aug 23, 2023
1bb4113
Added utilitiy function to generate SLATE matrix from functors, propa…
Aug 23, 2023
62d6fda
Added SLATE QR + UTs, fixed bug in QR UTs
Aug 24, 2023
7a6e4a4
Move TA <-> ScaLAPACK unit tests to scalapack.cpp
Aug 24, 2023
9c227e5
Cleanup of linalg.cpp
Aug 24, 2023
6ad69f1
Move all SLATE conversion tests to slate.cpp, fix slate_to_array for …
Aug 24, 2023
0a9dcc9
Major cleanup of linalg unit tests
Aug 24, 2023
3e317ee
Merge remote-tracking branch 'origin/master' into feature/slate_linea…
Aug 25, 2023
12de97a
Add ColMajor option for CyclicPmap + UTs, temporarily (?) disable "sm…
Aug 25, 2023
abad056
Added SLATE {SY,HE}GV driver + UT
Aug 26, 2023
ab999b0
Added eivenvector retiling path in SLATE heig + UT
Aug 26, 2023
4550e1e
Make linalg test optionally MPI safe, guard SLATE HEIG, validated rem…
Aug 26, 2023
61e0330
Enable SLATE in Gitlab CI
Aug 26, 2023
29572cc
Bump pinned SLATE tag
Aug 26, 2023
6accd5e
[CI] Ensure OMP_NUM_THREADS=1 in gitlab CI to avoid LIBOMP bug in SLATE
Aug 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ default:

variables:
MAD_NUM_THREADS : 2
OMP_NUM_THREADS : 1
TA_TARGETS : "tiledarray examples-tiledarray ta_test check-tiledarray"
# Debug builds with ScaLAPACK=ON need increased TA_UT_CTEST_TIMEOUT
TA_CONFIG : >
Expand All @@ -18,6 +19,7 @@ variables:
${BLA_VENDOR}
${BLA_THREADS}
${ENABLE_SCALAPACK}
${ENABLE_SLATE}

before_script:
# NB: if CMAKE_BUILD_PARALLEL_LEVEL is not set (i.e. using shared runner), use 1 to ensure we have enough memory
Expand All @@ -35,6 +37,7 @@ ubuntu:
variables:
TA_PYTHON : "TA_PYTHON=ON"
ENABLE_SCALAPACK : "ENABLE_SCALAPACK=OFF"
ENABLE_SLATE : "ENABLE_SLATE=OFF"
script:
- ./ci/.build-project
--build ./build
Expand Down Expand Up @@ -69,6 +72,7 @@ ubuntu:
CXX: [ g++, clang++-13 ]
BUILD_TYPE : [ "Release", "Debug" ]
ENABLE_SCALAPACK : [ "ENABLE_SCALAPACK=ON", "ENABLE_SCALAPACK=OFF" ]
ENABLE_SLATE : [ "ENABLE_SLATE=ON", "ENABLE_SLATE=OFF" ]
RUNNER_TAGS: [ linux ]
- IMAGE : [ "ubuntu:22.04", "ubuntu:20.04" ]
CXX: [ g++ ]
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ add_feature_info(MPI ENABLE_MPI "Message-Passing Interface supports distributed-
option(ENABLE_SCALAPACK "Enable ScaLAPACK Bindings in TiledArray" OFF)
add_feature_info(ScaLAPACK ENABLE_SCALAPACK "ScaLAPACK provides distributed linear algebra")

option(ENABLE_SLATE "Enable SLATE Bindings in TiledArray" OFF)
add_feature_info(SLATE ENABLE_SLATE "SLATE provides distributed linear algebra on GPU architectures")

option(ENABLE_WFN91_LINALG_DISCOVERY_KIT "Use linear algebra discovery kit from github.com/wavefunction91 [recommended]" ON)
add_feature_info(WFN91LinearAlgebraDiscoveryKit ENABLE_WFN91_LINALG_DISCOVERY_KIT "Linear algebra discovery kit from github.com/wavefunction91 supports many more corner cases than the default CMake modules and/or ICL's BLAS++/LAPACK++ modules")

Expand Down Expand Up @@ -338,6 +341,9 @@ include(${PROJECT_SOURCE_DIR}/cmake/modules/FindOrFetchBoost.cmake)
if(ENABLE_SCALAPACK)
include(external/scalapackpp.cmake)
endif()
if(ENABLE_SLATE)
include(external/slate.cmake)
endif()

# optional deps:
# 1. ccache
Expand Down
32 changes: 32 additions & 0 deletions cmake/modules/FindOrFetchSLATE.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Try find_package
if (NOT TARGET slate)
find_package(slate QUIET CONFIG)
if (TARGET slate)
message(STATUS "Found SLATE CONFIG at ${slate_CONFIG}")
endif (TARGET slate)
endif (NOT TARGET slate)

# If not found, build via FetchContent
if (NOT TARGET slate)

# Make sure BLAS++/LAPACK++ are already in place
# (will typically be loaded from BTAS)
include(${vg_cmake_kit_SOURCE_DIR}/modules/FindOrFetchLinalgPP.cmake)

if (NOT TILEDARRAY_HAS_CUDA)
set(gpu_backend none CACHE STRING "Device Backend for ICL Linalg++/SLATE")
endif (NOT TILEDARRAY_HAS_CUDA)

include(FetchContent)
FetchContent_Declare(
slate
GIT_REPOSITORY https://github.com/icl-utk-edu/slate.git
GIT_TAG ${TA_TRACKED_SLATE_TAG}
)
FetchContent_MakeAvailable(slate)

endif (NOT TARGET slate)

if (NOT TARGET slate)
message( FATAL_ERROR "FindOrFetchSLATE could not make slate target available")
endif (NOT TARGET slate)
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_subdirectory (cuda)
add_subdirectory (dgemm)
add_subdirectory (demo)
add_subdirectory (scalapack)
add_subdirectory (slate)
add_subdirectory (fock)
add_subdirectory (mpi_tests)
add_subdirectory (pmap_test)
Expand Down
38 changes: 38 additions & 0 deletions examples/slate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# This file is a part of TiledArray.
# Copyright (C) 2016 Virginia Tech
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Drew Lewis
# Department of Chemistry, Virginia Tech
#
# CMakeLists.txt
# Dec 6th, 2016
#

# Create example executable

if(ENABLE_SLATE)

foreach(_exec conversion)

# Add executable
add_executable(slate-${_exec} EXCLUDE_FROM_ALL ${_exec}.cpp)
target_link_libraries(slate-${_exec} PRIVATE tiledarray)
add_dependencies(examples-tiledarray slate-${_exec})

endforeach()

endif(ENABLE_SLATE)
140 changes: 140 additions & 0 deletions examples/slate/conversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* This file is a part of TiledArray.
* Copyright (C) 2020 Virginia Tech
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* David Williams-Young
* Computational Research Division, Lawrence Berkeley National Laboratory
*
* conversion.cpp
* Created: 7 Feb, 2020
* Edited: 13 May, 2020
*
*/

#include <TiledArray/conversions/slate.h>

#include <tiledarray.h>
#include <random>
#include <slate/slate.hh>
#include <TiledArray/pmap/user_pmap.h>


template <typename Integral1, typename Integral2>
int64_t div_ceil(Integral1 x, Integral2 y) {
int64_t x_ll = x;
int64_t y_ll = y;

auto d = std::div(x_ll, y_ll);
return d.quot + !!d.rem;
}

TA::TiledRange gen_trange(size_t N, const std::vector<size_t>& TA_NBs) {
assert(TA_NBs.size() > 0);

std::default_random_engine gen(0);
std::uniform_int_distribution<> dist(0, TA_NBs.size() - 1);
auto rand_indx = [&]() { return dist(gen); };
auto rand_nb = [&]() { return TA_NBs[rand_indx()]; };

std::vector<size_t> t_boundaries = {0};
auto TA_NB = rand_nb();
while (t_boundaries.back() + TA_NB < N) {
t_boundaries.emplace_back(t_boundaries.back() + TA_NB);
TA_NB = rand_nb();
}
t_boundaries.emplace_back(N);

std::vector<TA::TiledRange1> ranges(
2, TA::TiledRange1(t_boundaries.begin(), t_boundaries.end()));

return TA::TiledRange(ranges.begin(), ranges.end());
};



auto make_square_proc_grid(MPI_Comm comm) {
int mpi_size; MPI_Comm_size(comm, &mpi_size);
int p,q;
for(p = int( sqrt( mpi_size ) ); p > 0; --p) {
q = int( mpi_size / p );
if(p*q == mpi_size) break;
}
return std::make_pair(p,q);
}









int main(int argc, char** argv) {
auto& world = TA::initialize(argc, argv);
{
int64_t N = argc > 1 ? std::stoi(argv[1]) : 1000;
size_t NB = argc > 2 ? std::stoi(argv[2]) : 128;

auto make_ta_reference =
[&](TA::Tensor<double>& t, TA::Range const& range) {

t = TA::Tensor<double>(range, 0.0);
auto lo = range.lobound_data();
auto up = range.upbound_data();
for (int m = lo[0]; m < up[0]; ++m) {
for (int n = lo[1]; n < up[1]; ++n) {
t(m, n) = m - n;
}
}

return t.norm();
};

// Generate Reference TA tensor.
auto trange = gen_trange(N, {NB});
auto ref_ta =
TA::make_array<TA::TArray<double> >(world, trange, make_ta_reference);

// Do Conversion
auto A = TA::array_to_slate( ref_ta );
auto A_ta = TA::slate_to_array<TA::TArray<double>>(A, world);
world.gop.fence();

// Slate matrix to eigen
Eigen::MatrixXd slate_eigen = Eigen::MatrixXd::Zero(N,N);
for (int64_t j = 0; j < A.nt(); ++j)
for (int64_t i = 0; i < A.mt(); ++i) {
A.tileBcast(i,j, A, slate::Layout::ColMajor);
auto T = A(i,j);
Eigen::Map<Eigen::MatrixXd> T_map( T.data(), T.mb(), T.nb() );
slate_eigen.block(i*NB,j*NB,T.mb(), T.nb()) = T_map;
}
//if(!world.rank()) {
//std::cout << "SLATE\n" << slate_eigen << std::endl;
//}

A_ta.make_replicated();
world.gop.fence();
auto A_eigen = TA::array_to_eigen(A_ta);
//if(!world.rank()) std::cout << "TA\n" << A_eigen << std::endl;
std::cout << (A_eigen - slate_eigen).norm() << std::endl;


}

TA::finalize();
}
21 changes: 21 additions & 0 deletions external/slate.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if (NOT TARGET slate)
set(VGCMAKEKIT_TRACKED_SLATE_TAG ${TA_TRACKED_SLATE_TAG} CACHE STRING "slate tag")
include(FindOrFetchSLATE)
endif()

# built {blacs,scalapack}pp as a subproject? install as part of tiledarray export as well
# to be able to use TiledArray_SLATE from the build tree
if (TARGET slate)
install( TARGETS slate EXPORT tiledarray COMPONENT tiledarray )
# Add these dependencies to External
add_dependencies(External-tiledarray slate )
endif()

if (TARGET slate)
add_library( TiledArray_SLATE INTERFACE )
target_link_libraries( TiledArray_SLATE INTERFACE slate )

install( TARGETS TiledArray_SLATE EXPORT tiledarray COMPONENT tiledarray )

set( TILEDARRAY_HAS_SLATE 1 )
endif()
3 changes: 3 additions & 0 deletions external/versions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ set(TA_TRACKED_UMPIRE_PREVIOUS_TAG v6.0.0)
set(TA_TRACKED_SCALAPACKPP_TAG 6397f52cf11c0dfd82a79698ee198a2fce515d81)
set(TA_TRACKED_SCALAPACKPP_PREVIOUS_TAG 711ef363479a90c88788036f9c6c8adb70736cbf )

set(TA_TRACKED_SLATE_TAG 04d552f12e0d181c27652ecd3ebedb265b7eec07)
set(TA_TRACKED_SLATE_PREVIOUS_TAG 8651441aa87cd69b560d4dac8c5ceb0e7f8c32a4)

set(TA_TRACKED_RANGEV3_TAG 2e0591c57fce2aca6073ad6e4fdc50d841827864)
set(TA_TRACKED_RANGEV3_PREVIOUS_TAG dbdaa247a25a0daa24c68f1286a5693c72ea0006)

Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ endif(CUDA_FOUND)
if( TARGET TiledArray_SCALAPACK )
list(APPEND _TILEDARRAY_DEPENDENCIES TiledArray_SCALAPACK)
endif()
if( TARGET TiledArray_SLATE )
list(APPEND _TILEDARRAY_DEPENDENCIES TiledArray_SLATE)
endif()
list(APPEND _TILEDARRAY_DEPENDENCIES "${LAPACK_LIBRARIES}")

if( TARGET ttg-parsec )
Expand Down
3 changes: 3 additions & 0 deletions src/TiledArray/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
/* Define if TA has enabled ScaLAPACK Bindings */
#cmakedefine TILEDARRAY_HAS_SCALAPACK 1

/* Define if TA has enabled SLATE Bindings */
#cmakedefine TILEDARRAY_HAS_SLATE 1

/* Define if TiledArray configured with CUDA support */
#cmakedefine TILEDARRAY_HAS_CUDA @TILEDARRAY_HAS_CUDA@
#cmakedefine TILEDARRAY_CHECK_CUDA_ERROR @TILEDARRAY_CHECK_CUDA_ERROR@
Expand Down
Loading