Skip to content

Commit

Permalink
2025 cleanup (#94)
Browse files Browse the repository at this point in the history
Updates in this PR:
1. Resolves several old issues/errors (switch c to c++ style
allocations, fix HQRRP input format, add license, fix CMake regexp
error, etc).
2.  Adds sparse and general linear operator support.
3. Augments RBKI input format to accept dense and sparse matrices.

---------

Co-authored-by: Riley Murray <[email protected]>
  • Loading branch information
TeachRaccooon and Riley Murray authored Feb 13, 2025
1 parent 4f1a3b8 commit 8ea1196
Show file tree
Hide file tree
Showing 34 changed files with 1,524 additions and 792 deletions.
2 changes: 1 addition & 1 deletion CMake/rl_build_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (OpenMP_CXX_FOUND)
set(tmp TRUE)
endif()

set(RandLAPACK_HAS_OpenMP ${tmp} CACHE BOOL "Set if we have a working OpenMP")
set(RandBLAS_HAS_OpenMP ${tmp} CACHE BOOL "Set if we have a working OpenMP")
message(STATUS "Checking for OpenMP ... ${RandBLAS_HAS_OpenMP}")

include(GNUInstallDirs)
Expand Down
50 changes: 38 additions & 12 deletions CMake/rl_version.cmake
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
set(tmp)

# Find Git executable
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE}
--git-dir=${CMAKE_SOURCE_DIR}/.git describe
--tags --match "[0-9]*.[0-9]*.[0-9]*"
OUTPUT_VARIABLE tmp OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
message(STATUS "Git found: ${GIT_EXECUTABLE}")
execute_process(
COMMAND ${GIT_EXECUTABLE} --git-dir=${CMAKE_SOURCE_DIR}/.git describe --tags --match "[0-9]*.[0-9]*.[0-9]*"
OUTPUT_VARIABLE tmp
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE git_error
RESULT_VARIABLE git_result
)

# Print the result of the Git command
message(STATUS "Git command result: ${git_result}")
message(STATUS "Git command output: ${tmp}")
if(NOT git_result EQUAL 0)
message(WARNING "Git command failed with error: ${git_error}")
set(tmp "0.0.0")
endif()
else()
message(WARNING "Git not found, using fallback version 0.0.0")
set(tmp "0.0.0")
endif()

# Check if tmp is empty and set a fallback version if necessary
if(NOT tmp)
message(WARNING "Git describe output is empty, using fallback version 0.0.0")
set(tmp "0.0.0")
endif()

set(RandLAPACK_VERSION ${tmp} CACHE STRING "RandLAPACK version" FORCE)
# Debugging: Print tmp before setting RandLAPACK_VERSION
message(STATUS "tmp before setting RandLAPACK_VERSION: ${tmp}")

string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*$)"
"\\1" RandLAPACK_VERSION_MAJOR ${RandLAPACK_VERSION})
# Set RandLAPACK_VERSION without CACHE option
set(RandLAPACK_VERSION "${tmp}")
message(STATUS "RandLAPACK_VERSION after setting: ${RandLAPACK_VERSION}")

string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*$)"
"\\2" RandLAPACK_VERSION_MINOR ${RandLAPACK_VERSION})
# Ensure RandLAPACK_VERSION is not empty
if(NOT RandLAPACK_VERSION)
message(FATAL_ERROR "RandLAPACK_VERSION is empty")
endif()

string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*$)"
"\\3" RandLAPACK_VERSION_PATCH ${RandLAPACK_VERSION})
# Extract major, minor, and patch versions
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)$" "\\1" RandLAPACK_VERSION_MAJOR "${RandLAPACK_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)$" "\\2" RandLAPACK_VERSION_MINOR "${RandLAPACK_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)$" "\\3" RandLAPACK_VERSION_PATCH "${RandLAPACK_VERSION}")

# Print extracted version components
message(STATUS "RandLAPACK_VERSION_MAJOR=${RandLAPACK_VERSION_MAJOR}")
message(STATUS "RandLAPACK_VERSION_MINOR=${RandLAPACK_VERSION_MINOR}")
message(STATUS "RandLAPACK_VERSION_PATCH=${RandLAPACK_VERSION_PATCH}")
4 changes: 4 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ cmake -DCMAKE_BUILD_TYPE=Release \
make -j2 install
```

If you wish for BLAS++ tester to be built, make sure that the CPATH is set properly,
i.e. pointing at the BLAS vendor library's /include/ folder.
This will ensure that CBLAS is properly encountered by CMake.

One can compile and install LAPACK++ from
[source](https://bitbucket.org/icl/lapackpp/src/master/) using CMake by running
```shell
Expand Down
103 changes: 103 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
RandLAPACK Copyright Notices and License Agreement
================================================
RandLAPACK is an open source software project. Contributors to RandLAPACK can act
as individuals or as corporate entities. All contributions are licensed for
use under the BSD 3-Clause License. The terms of the license appear below.

Some contributors to RandLAPACK have chosen to make explicit statements concerning
authorship, copyright, or other aspects of intellectual property. Those statements
appear later in this file, after the license agreement. Future modifications of
RandLAPACK code may result in ammendments to these statements.

******************************************************************************
*** License Agreement ***
******************************************************************************

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

(1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

(2) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

(3) Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

******************************************************************************
*** Copyright Notice 1. ***
******************************************************************************

Copyright (c) 2022, The Regents of the University of California, through
Lawrence Berkeley National Laboratory (subject to receipt of any
required approvals from the U.S. Dept. of Energy). All rights reserved.

If you have questions about your rights to use or distribute this software,
please contact Berkeley Lab's Intellectual Property Office at
[email protected].

NOTICE. This Software was developed under funding from the U.S. Department
of Energy and the U.S. Government consequently retains certain rights. As
such, the U.S. Government has been granted for itself and others acting on
its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
Software to reproduce, distribute copies to the public, prepare derivative
works, and perform publicly and display publicly, and to permit others to do so.

******************************************************************************
*** Copyright Notice 2. ***
******************************************************************************

Copyright (c) 2022, University of Tennessee. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University of Tennessee nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

******************************************************************************
*** Copyright Notice 3. ***
******************************************************************************

Copyright (2023) National Technology & Engineering Solutions of Sandia, LLC (NTESS).
Under the terms of Contract DE-NA0003525, there is a non-exclusive license for use
of this work by or on behalf of the U.S. Government. Export of this program
may require a license from the United States Government.

NEITHER THE UNITED STATES GOVERNMENT, NOR THE UNITED STATES DEPARTMENT
OF ENERGY, NOR NTESS, NOR ANY OF THEIR EMPLOYEES, MAKES
ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR
RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY
INFORMATION, APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS
THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
2 changes: 1 addition & 1 deletion RandLAPACK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ target_link_libraries(RandLAPACK INTERFACE
Random123
)

if (RandLAPACK_HAS_OpenMP)
if (RandBLAS_HAS_OpenMP)
target_link_libraries(RandLAPACK INTERFACE OpenMP::OpenMP_CXX)
endif()

Expand Down
20 changes: 10 additions & 10 deletions RandLAPACK/comps/rl_orth.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int CholQRQ<T>::call(
T* A
){

T* A_gram = ( T * ) calloc( k * k, sizeof( T ) );
T* A_gram = new T[k * k]();

// Find normal equation Q'Q - Just the upper triangular portion
blas::syrk(Layout::ColMajor, Uplo::Upper, Op::Trans, k, m, 1.0, A, m, 0.0, A_gram, k);
Expand All @@ -83,20 +83,20 @@ int CholQRQ<T>::call(
printf("CHOLESKY QR FAILED\n");
}
this->chol_fail = true; // scheme failure
free(A_gram);
delete[] A_gram;
return 1;
}

// Scheme may succeed, but output garbage
if(this->cond_check) {
if(util::cond_num_check(k, k, A_gram, this->verbose) > (1 / std::sqrt(std::numeric_limits<T>::epsilon()))){
free(A_gram);
delete[] A_gram;
return 1;
}
}

blas::trsm(Layout::ColMajor, Side::Right, Uplo::Upper, Op::NoTrans, Diag::NonUnit, m, k, 1.0, A_gram, k, A, m);
free(A_gram);
delete[] A_gram;
return 0;
}

Expand Down Expand Up @@ -154,15 +154,15 @@ int HQRQ<T>::call(
// tau The vector tau of length min(m,n). The scalar factors of the elementary reflectors (see Further Details).
// tau needs to be a vector of all 2's by default

T* tau = ( T * ) calloc( n, sizeof( T ) );
T* tau = new T[n]();

if(lapack::geqrf(m, n, A, m, tau)) {
free(tau);
delete[] tau;
return 1; // Failure condition
}

lapack::ungqr(m, n, n, A, m, tau);
free(tau);
delete[] tau;
return 0;
}

Expand Down Expand Up @@ -217,17 +217,17 @@ int PLUL<T>::call(
int64_t n,
T* A
){
int64_t* ipiv = ( int64_t * ) calloc( n, sizeof( int64_t ) );
int64_t* ipiv = new int64_t[n]();

if(lapack::getrf(m, n, A, m, ipiv)) {
free(ipiv);
delete[] ipiv;
return 1; // failure condition
}

util::get_L(m, n, A, 1);
lapack::laswp(n, A, m, 1, n, ipiv, 1);

free(ipiv);
delete[] ipiv;
return 0;
}

Expand Down
9 changes: 5 additions & 4 deletions RandLAPACK/comps/rl_rf.hh
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ int RF<T, RNG>::call(
RandBLAS::RNGState<RNG> &state
){

T* Omega = ( T * ) calloc( n * k, sizeof( T ) );
T* Omega = new T[n * k]();

if(this->rs.call(m, n, A, k, Omega, state)) {
free(Omega);
return 1;
}

Expand All @@ -127,11 +126,13 @@ int RF<T, RNG>::call(
// Writes into this->cond_nums
this->cond_nums.push_back(util::cond_num_check(m, k, Q, this->verbose));

if(this->orth.call(m, k, Q))
if(this->orth.call(m, k, Q)) {
delete[] Omega;
return 2; // Orthogonalization failed
}

// Normal termination
free(Omega);
delete[] Omega;
return 0;
}

Expand Down
14 changes: 9 additions & 5 deletions RandLAPACK/comps/rl_rs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int RS<T, RNG>::call(
int64_t q = this->passes_per_stab;
int64_t p_done= 0;

T* Omega_1 = ( T * ) calloc( m * k, sizeof( T ) );
T* Omega_1 = new T[m * k]();

if (p % 2 == 0) {
// Fill n by k Omega
Expand All @@ -142,8 +142,10 @@ int RS<T, RNG>::call(
blas::gemm(Layout::ColMajor, Op::Trans, Op::NoTrans, n, k, m, 1.0, A, m, Omega_1, m, 0.0, Omega, n);

++ p_done;
if ((p_done % q == 0) && (this->Stab_Obj.call(n, k, Omega)))
return 1; // Scheme failure
if ((p_done % q == 0) && (this->Stab_Obj.call(n, k, Omega))) {
delete[] Omega_1;
return 1;
}
}

while (p - p_done > 0) {
Expand All @@ -154,8 +156,10 @@ int RS<T, RNG>::call(
if(this->cond_check)
this->cond_nums.push_back(util::cond_num_check(m, k, Omega_1, this->verbose));

if ((p_done % q == 0) && (this->Stab_Obj.call(m, k, Omega_1)))
if ((p_done % q == 0) && (this->Stab_Obj.call(m, k, Omega_1))) {
delete[] Omega_1;
return 1;
}

// Omega = A' * Omega
blas::gemm(Layout::ColMajor, Op::Trans, Op::NoTrans, n, k, m, 1.0, A, m, Omega_1, m, 0.0, Omega, n);
Expand All @@ -168,7 +172,7 @@ int RS<T, RNG>::call(
return 1;
}

free(Omega_1);
delete[] Omega_1;
//successful termination
return 0;
}
Expand Down
Loading

0 comments on commit 8ea1196

Please sign in to comment.