Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions cm_generate_makefile.bash
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ get_kernels_tpls_list() {
KOKKOSKERNELS_USER_TPL_PATH_CMD=
KOKKOSKERNELS_USER_TPL_LIBNAME_CMD=
CUBLAS_DEFAULT=OFF
CUSOLVER_DEFAULT=OFF
CUSPARSE_DEFAULT=OFF
PARSE_TPLS_LIST=$(echo $KOKKOSKERNELS_TPLS | tr "," "\n")
for TPLS_ in $PARSE_TPLS_LIST
Expand All @@ -178,6 +179,9 @@ get_kernels_tpls_list() {
if [ "$UC_TPLS" == "CUSPARSE" ]; then
CUSPARSE_DEFAULT=ON
fi
if [ "$UC_TPLS" == "CUSOLVER" ]; then
CUSOLVER_DEFAULT=ON
fi
if [ "$UC_TPLS" == "BLAS" ]; then
if [ "$BLAS_PATH" != "" ]; then
echo User BLAS_PATH=$BLAS_PATH
Expand All @@ -202,6 +206,9 @@ get_kernels_tpls_list() {
if [ "$CUBLAS_DEFAULT" == "OFF" ]; then
KOKKOSKERNELS_TPLS_CMD="-DKokkosKernels_ENABLE_TPL_CUBLAS=OFF ${KOKKOSKERNELS_TPLS_CMD}"
fi
if [ "$CUSOLVER_DEFAULT" == "OFF" ]; then
KOKKOSKERNELS_TPLS_CMD="-DKokkosKernels_ENABLE_TPL_CUSOLVER=OFF ${KOKKOSKERNELS_TPLS_CMD}"
fi
if [ "$CUSPARSE_DEFAULT" == "OFF" ]; then
KOKKOSKERNELS_TPLS_CMD="-DKokkosKernels_ENABLE_TPL_CUSPARSE=OFF ${KOKKOSKERNELS_TPLS_CMD}"
fi
Expand Down
2 changes: 2 additions & 0 deletions cmake/KokkosKernels_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
#cmakedefine KOKKOSKERNELS_ENABLE_TPL_CUSPARSE
/* CUBLAS */
#cmakedefine KOKKOSKERNELS_ENABLE_TPL_CUBLAS
/* CUSOLVER */
#cmakedefine KOKKOSKERNELS_ENABLE_TPL_CUSOLVER
/* MAGMA */
#cmakedefine KOKKOSKERNELS_ENABLE_TPL_MAGMA
/* SuperLU */
Expand Down
18 changes: 18 additions & 0 deletions cmake/Modules/FindTPLCUSOLVER.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FIND_PACKAGE(CUDA)

INCLUDE(FindPackageHandleStandardArgs)
IF (NOT CUDA_FOUND)
#Important note here: this find Module is named TPLCUSOLVER
#The eventual target is named CUSOLVER. To avoid naming conflicts
#the find module is called TPLCUSOLVER. This call will cause
#the find_package call to fail in a "standard" CMake way
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TPLCUSOLVER REQUIRED_VARS CUDA_FOUND)
ELSE()
#The libraries might be empty - OR they might explicitly be not found
IF("${CUDA_CUSOLVER_LIBRARIES}" MATCHES "NOTFOUND")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TPLCUSOLVER REQUIRED_VARS CUDA_cusolver_LIBRARY)
ELSE()
KOKKOSKERNELS_CREATE_IMPORTED_TPL(CUSOLVER INTERFACE
LINK_LIBRARIES "${CUDA_cusolver_LIBRARY}")
ENDIF()
ENDIF()
4 changes: 4 additions & 0 deletions cmake/kokkoskernels_tpls.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,14 @@ SET(CUSPARSE_DEFAULT ${KOKKOS_ENABLE_CUDA})
IF(KOKKOSKERNELS_NO_DEFAULT_CUDA_TPLS)
SET(CUBLAS_DEFAULT OFF)
SET(CUSPARSE_DEFAULT OFF)
SET(CUSOLVER_DEFAULT OFF)
ENDIF()
KOKKOSKERNELS_ADD_TPL_OPTION(CUBLAS ${CUBLAS_DEFAULT} "Whether to enable CUBLAS"
DEFAULT_DOCSTRING "ON if CUDA-enabled Kokkos, otherwise OFF")
KOKKOSKERNELS_ADD_TPL_OPTION(CUSPARSE ${CUSPARSE_DEFAULT} "Whether to enable CUSPARSE"
DEFAULT_DOCSTRING "ON if CUDA-enabled Kokkos, otherwise OFF")
KOKKOSKERNELS_ADD_TPL_OPTION(CUSOLVER ${CUSOLVER_DEFAULT} "Whether to enable CUSOLVER"
DEFAULT_DOCSTRING "ON if CUDA-enabled Kokkos, otherwise OFF")

KOKKOSKERNELS_ADD_OPTION(NO_DEFAULT_ROCM_TPLS OFF BOOL "Whether ROCM TPLs should be enabled by default. Default: OFF")
# Unlike CUDA, ROCm does not automatically install these TPLs
Expand Down Expand Up @@ -508,6 +511,7 @@ IF (NOT KOKKOSKERNELS_HAS_TRILINOS)
KOKKOSKERNELS_IMPORT_TPL(MKL)
KOKKOSKERNELS_IMPORT_TPL(CUBLAS)
KOKKOSKERNELS_IMPORT_TPL(CUSPARSE)
KOKKOSKERNELS_IMPORT_TPL(CUSOLVER)
KOKKOSKERNELS_IMPORT_TPL(CBLAS)
KOKKOSKERNELS_IMPORT_TPL(LAPACKE)
KOKKOSKERNELS_IMPORT_TPL(CHOLMOD)
Expand Down
36 changes: 36 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ IF (KOKKOSKERNELS_ENABLE_TPL_BLAS OR KOKKOSKERNELS_ENABLE_TPL_MKL)
APPEND_GLOB(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/impl/tpls/KokkosBlas_Host_tpl.cpp)
ENDIF()

#Include LAPACKE host wrapper
IF (KOKKOSKERNELS_ENABLE_TPL_LAPACKE)
#Do NOT add this to include path
APPEND_GLOB(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/impl/tpls/KokkosLapack_Host_tpl.cpp)
ENDIF()

include(kokkoskernels_eti.cmake)
SET(ETI_HEADERS)

Expand Down Expand Up @@ -283,6 +289,34 @@ KOKKOSKERNELS_GENERATE_ETI(Blas_trtri trtri
TYPE_LISTS FLOATS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Blas_geqrf geqrf
COMPONENTS blas
HEADER_LIST ETI_HEADERS
SOURCE_LIST SOURCES
TYPE_LISTS FLOATS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Blas_geqrf_workspace geqrf
COMPONENTS blas
HEADER_LIST ETI_HEADERS
SOURCE_LIST SOURCES
TYPE_LISTS FLOATS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Blas_unmqr unmqr
COMPONENTS blas
HEADER_LIST ETI_HEADERS
SOURCE_LIST SOURCES
TYPE_LISTS FLOATS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Blas_unmqr_workspace unmqr
COMPONENTS blas
HEADER_LIST ETI_HEADERS
SOURCE_LIST SOURCES
TYPE_LISTS FLOATS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Sparse_sptrsv_solve sptrsv_solve
COMPONENTS sparse
HEADER_LIST ETI_HEADERS
Expand Down Expand Up @@ -394,6 +428,7 @@ LIST(APPEND HEADERS ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}_config.h)
LIST(APPEND SOURCES
batched/KokkosBatched_Util.cpp
impl/tpls/KokkosBlas_Host_tpl.cpp
impl/tpls/KokkosLapack_Host_tpl.cpp
impl/tpls/KokkosBlas_Cuda_tpl.cpp
impl/tpls/KokkosBlas_Rocm_tpl.cpp
impl/tpls/KokkosKernels_tpl_handles.cpp
Expand Down Expand Up @@ -440,6 +475,7 @@ KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC SUPERLU)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CHOLMOD)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC MKL)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CUBLAS)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CUSOLVER)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC CUSPARSE)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC ROCBLAS)
KOKKOSKERNELS_LINK_TPL(kokkoskernels PUBLIC ROCSPARSE)
Expand Down
199 changes: 199 additions & 0 deletions src/blas/KokkosBlas_geqrf.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 3.0
// Copyright (2020) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// 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 Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY NTESS "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 NTESS OR THE
// 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.
//
// Questions? Contact Siva Rajamanickam (srajama@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#ifndef KOKKOSBLAS_GEQRF_HPP_
#define KOKKOSBLAS_GEQRF_HPP_

/// \file KokkosBlas_qeqrf.hpp

#include "KokkosKernels_Macros.hpp"
#include "KokkosBlas_geqrf_spec.hpp"
#include "KokkosKernels_helpers.hpp"
#include <sstream>
#include <type_traits>

namespace KokkosBlas {

/// \brief Compute the QR factorization of M x N matrix A. (geqrf)

/// \tparam AViewType Input(A) / Output (Solution) M x N matrix , as a 2-D
/// Kokkos::View \tparam TauViewType Input k vector , as a 1-D Kokkos::View
/// \tparam WViewType Input Workspace, as a 1-D Kokkos::View
///
/// \param A [in, out] Input matrix, as a 2-D Kokkos::View
/// On entry, M-by-N matrix
/// On exit, overwritten with the solution.
/// \param tau [in] Input vector, as a 1-D Kokkos::View. Scalar factors of
/// reflectors.
/// \param workspace [in] Input vector, as a 1-D Kokkos::View.
/// Scratchspace for calculations.

template <class AViewType, class TauViewType, class WViewType>
void geqrf(AViewType& A, TauViewType& tau, WViewType& workspace) {
#if (KOKKOSKERNELS_DEBUG_LEVEL > 0)
static_assert(Kokkos::Impl::is_view<AViewType>::value,
"KokkosBlas::geqrf: A must be a Kokkos::View");
static_assert(Kokkos::Impl::is_view<TauViewType>::value,
"KokkosBlas::geqrf: tau must be a Kokkos::View");
static_assert(Kokkos::Impl::is_view<WViewType>::value,
"KokkosBlas::geqrf: workspace must be a Kokkos::View");

static_assert(static_cast<int>(AViewType::rank) == 2,
"KokkosBlas::geqrf: A must have rank 2");
static_assert(static_cast<int>(TauViewType::rank) == 1,
"KokkosBlas::geqrf: Tau must have rank 1");
static_assert(static_cast<int>(WViewType::rank) == 1,
"KokkosBlas::geqrf: Workspace must have rank 1");

int64_t A0 = A.extent(0); // M
int64_t A1 = A.extent(1); // N
int64_t minmn = (A0 < A1) ? A0 : A1;

int64_t tau0 = tau.extent(0);
int64_t lwork = workspace.extent(0);

// Check validity of Tau
if (tau0 < minmn) {
std::ostringstream os;
os << "KokkosBlas::geqrf: Dimensions of tau and MIN(M, N) do not match "
"(require len(tau) >= min(M, N) ): "
<< "min(M, N): " << minmn << "Tau: " << tau0;
Kokkos::Impl::throw_runtime_exception(os.str());
}

#endif // KOKKOSKERNELS_DEBUG_LEVEL > 0

// return if degenerate matrix provided
if ((A.extent(0) == 0) || (A.extent(1) == 0)) return;

// standardize particular View specializations
typedef Kokkos::View<typename AViewType::non_const_value_type**,
typename AViewType::array_layout,
typename AViewType::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> >
AVT;

typedef Kokkos::View<typename TauViewType::non_const_value_type*,
typename TauViewType::array_layout,
typename TauViewType::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> >
TVT;

typedef Kokkos::View<typename WViewType::non_const_value_type*,
typename TauViewType::array_layout,
typename TauViewType::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> >
WVT;

AVT A_i = A;
TVT tau_i = tau;
WVT W_i = workspace;

typedef KokkosBlas::Impl::GEQRF<AVT, TVT, WVT> impl_type;
impl_type::geqrf(A_i, tau_i, W_i);

} // function geqrf

/// \brief Returns the required workspace of geqrf. ( Compute the QR
/// factorization of M x N matrix A. (geqrf) )
///
/// \return int64_t length of the required workspace
/// \tparam AViewType Input(A) / Output (Solution) M x N matrix , as a 2-D
/// Kokkos::View \tparam TauViewType Input k vector , as a 1-D Kokkos::View
/// \tparam WViewType Input Workspace, as a 1-D Kokkos::View
///
/// \param A [in] Input matrix, as a 2-D Kokkos::View. Can be
/// uninitialized for workspace queries just needs to be the correct size.
/// \param tau [in] Input vector, as a 1-D Kokkos::View. Scalar factors of
/// reflectors. Can be empty for workspace queries.

template <class AViewType, class TauViewType>
int64_t geqrf_workspace(AViewType& A, TauViewType& tau) {
Comment thread
wlruys marked this conversation as resolved.
// return if degenerate matrix provided
if ((A.extent(0) == 0) || (A.extent(1) == 0)) return 0;

// standardize particular View specializations
typedef Kokkos::View<typename AViewType::non_const_value_type**,
typename AViewType::array_layout,
typename AViewType::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> >
AVT;

typedef Kokkos::View<typename TauViewType::non_const_value_type*,
typename TauViewType::array_layout,
typename TauViewType::device_type,
Kokkos::MemoryTraits<Kokkos::Unmanaged> >
TVT;

AVT A_i = A;
TVT tau_i = tau;

typedef KokkosBlas::Impl::GEQRF_WORKSPACE<AVT, TVT> impl_type;
return impl_type::geqrf_workspace(A_i, tau_i);

} // function geqrf_workspace

/// \brief Compute the QR factorization of M x N matrix A. (geqrf). Allocates an
/// internal workspace.

/// \tparam AViewType Input(A) / Output (Solution) M x N matrix , as a 2-D
/// Kokkos::View \tparam TauViewType Input k vector , as a 1-D Kokkos::View
///
/// \param A [in, out] Input matrix, as a 2-D Kokkos::View
/// On entry, M-by-N matrix
/// On exit, overwritten with the solution.
/// \param tau [in] Input vector, as a 1-D Kokkos::View. Scalar factors of
/// reflectors.

template <class AViewType, class TauViewType>
void geqrf(AViewType& A, TauViewType& tau) {
Comment thread
wlruys marked this conversation as resolved.
int64_t lwork = geqrf_workspace(A, tau);
TauViewType workspace("KokkosBlas::temporary_geqrf_workspace", lwork);
geqrf(A, tau, workspace);

} // function geqrf with temp workspace

} // namespace KokkosBlas

#endif // KOKKOSBLAS_GEQRF_HPP_
Loading