./0000775000175100017510000000000015176134511011107 5ustar jenkinsjenkins./library/0000775000175100017510000000000015176134511012553 5ustar jenkinsjenkins./library/CMakeLists.txt0000664000175100017510000002332615176134511015321 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # This option only works for make/nmake and the ninja generators, but no reason it shouldn't be on all the time # This tells cmake to create a compile_commands.json file that can be used with clang tooling or vim set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Print verbose compiler flags if(BUILD_VERBOSE) include(../cmake/Verbose.cmake) endif() # Configure a header file to pass the hipSPARSE version configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/hipsparse-version.h.in" "${PROJECT_BINARY_DIR}/include/hipsparse/hipsparse-version.h") # Copy Header files to build directory configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/hipsparse.h" "${PROJECT_BINARY_DIR}/include/hipsparse/hipsparse.h" COPYONLY) set(HEADER_FILES # Level1 internal/level1/hipsparse_axpyi.h internal/level1/hipsparse_dotci.h internal/level1/hipsparse_doti.h internal/level1/hipsparse_gthr.h internal/level1/hipsparse_gthrz.h internal/level1/hipsparse_roti.h internal/level1/hipsparse_sctr.h # Level2 internal/level2/hipsparse_bsrmv.h internal/level2/hipsparse_bsrsv.h internal/level2/hipsparse_bsrxmv.h internal/level2/hipsparse_csrmv.h internal/level2/hipsparse_csrsv.h internal/level2/hipsparse_gemvi.h internal/level2/hipsparse_hybmv.h # Level3 internal/level3/hipsparse_bsrmm.h internal/level3/hipsparse_bsrsm.h internal/level3/hipsparse_csrmm.h internal/level3/hipsparse_csrsm.h internal/level3/hipsparse_gemmi.h # Extra internal/extra/hipsparse_csrgeam.h internal/extra/hipsparse_csrgemm.h # Precond internal/precond/hipsparse_bsric0.h internal/precond/hipsparse_bsrilu0.h internal/precond/hipsparse_csric0.h internal/precond/hipsparse_csrilu0.h internal/precond/hipsparse_gpsv_interleaved_batch.h internal/precond/hipsparse_gtsv_interleaved_batch.h internal/precond/hipsparse_gtsv_nopivot.h internal/precond/hipsparse_gtsv_strided_batch.h internal/precond/hipsparse_gtsv.h # Reorder internal/reorder/hipsparse_csrcolor.h # Conversion internal/conversion/hipsparse_bsr2csr.h internal/conversion/hipsparse_coo2csr.h internal/conversion/hipsparse_coosort.h internal/conversion/hipsparse_create_identity_permutation.h internal/conversion/hipsparse_csc2dense.h internal/conversion/hipsparse_cscsort.h internal/conversion/hipsparse_csr2bsr.h internal/conversion/hipsparse_csr2coo.h internal/conversion/hipsparse_csr2csc.h internal/conversion/hipsparse_csr2csr_compress.h internal/conversion/hipsparse_csr2csru.h internal/conversion/hipsparse_csr2dense.h internal/conversion/hipsparse_csr2gebsr.h internal/conversion/hipsparse_csr2hyb.h internal/conversion/hipsparse_csrsort.h internal/conversion/hipsparse_csru2csr.h internal/conversion/hipsparse_dense2csc.h internal/conversion/hipsparse_dense2csr.h internal/conversion/hipsparse_gebsr2csr.h internal/conversion/hipsparse_gebsr2gebsc.h internal/conversion/hipsparse_gebsr2gebsr.h internal/conversion/hipsparse_hyb2csr.h internal/conversion/hipsparse_nnz_compress.h internal/conversion/hipsparse_nnz.h internal/conversion/hipsparse_prune_csr2csr_by_percentage.h internal/conversion/hipsparse_prune_csr2csr.h internal/conversion/hipsparse_prune_dense2csr_by_percentage.h internal/conversion/hipsparse_prune_dense2csr.h # Generic internal/generic/hipsparse_axpby.h internal/generic/hipsparse_dense2sparse.h internal/generic/hipsparse_gather.h internal/generic/hipsparse_rot.h internal/generic/hipsparse_scatter.h internal/generic/hipsparse_sddmm.h internal/generic/hipsparse_sparse2dense.h internal/generic/hipsparse_spgemm_reuse.h internal/generic/hipsparse_spgemm.h internal/generic/hipsparse_spmm.h internal/generic/hipsparse_spmv.h internal/generic/hipsparse_spsm.h internal/generic/hipsparse_spsv.h internal/generic/hipsparse_spvv.h # Auxiliary hipsparse-bfloat16.h hipsparse-types.h hipsparse-auxiliary.h hipsparse-generic-types.h hipsparse-generic-auxiliary.h) foreach( file_i ${HEADER_FILES}) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/${file_i}" "${PROJECT_BINARY_DIR}/include/hipsparse/${file_i}" COPYONLY) endforeach() # Public hipSPARSE headers set(hipsparse_headers_public include/hipsparse.h ${PROJECT_BINARY_DIR}/include/hipsparse/hipsparse-version.h) source_group("Header Files\\Public" FILES ${hipsparse_headers_public}) # Include sources include(src/CMakeLists.txt) if (NOT WIN32) # Set Fortran module output directory set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include/hipsparse) # Create hipSPARSE Fortran module add_library(hipsparse_fortran OBJECT ${hipsparse_fortran_source}) # Target compile options target_compile_options(hipsparse_fortran PRIVATE -ffree-form -cpp) endif() # Create hipSPARSE library add_library(hipsparse ${hipsparse_source} ${hipsparse_headers_public}) add_library(roc::hipsparse ALIAS hipsparse) # Target compile options target_compile_options(hipsparse PRIVATE -Wno-unused-command-line-argument -Wall) # External header includes included as system files target_include_directories( hipsparse SYSTEM PRIVATE $ ) # Target include directories target_include_directories(hipsparse PRIVATE $ PUBLIC $ $ $ $) if(NOT USE_CUDA) target_link_libraries(hipsparse PUBLIC hip::host) target_link_libraries(hipsparse PRIVATE roc::rocsparse) else() target_compile_definitions(hipsparse PUBLIC __HIP_PLATFORM_NVIDIA__) target_include_directories(hipsparse PUBLIC $ $) SET(SEARCH_SYMBOL "cusparseCreateSpVec") SET(SEARCH_RESULTS "") if(WIN32) EXECUTE_PROCESS( COMMAND dumpbin /EXPORTS ${CUDA_cusparse_LIBRARY} COMMAND findstr ${SEARCH_SYMBOL} OUTPUT_VARIABLE SEARCH_RESULTS ERROR_VARIABLE ERR) else() EXECUTE_PROCESS( COMMAND objdump -T ${CUDA_cusparse_LIBRARY} COMMAND grep ${SEARCH_SYMBOL} OUTPUT_VARIABLE SEARCH_RESULTS ERROR_VARIABLE ERR) endif() if(SEARCH_RESULTS STREQUAL "") # symbol not found target_compile_definitions(hipsparse PRIVATE CUDART_10_1_UPDATE_VERSION=0) else() # symbol found target_compile_definitions(hipsparse PRIVATE CUDART_10_1_UPDATE_VERSION=1) endif() target_link_libraries(hipsparse PRIVATE ${CUDA_cusparse_LIBRARY}) endif() # Target properties rocm_set_soversion(hipsparse ${hipsparse_SOVERSION}) set_target_properties(hipsparse PROPERTIES CXX_EXTENSIONS NO) set_target_properties(hipsparse PROPERTIES CXX_VISIBILITY_PRESET "hidden" VISIBILITY_INLINES_HIDDEN ON) set_target_properties(hipsparse PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") set_target_propertieS(hipsparse PROPERTIES DEBUG_POSTFIX "-d") if (WIN32 AND BUILD_SHARED_LIBS) add_custom_command( TARGET hipsparse POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/staging/$ ${PROJECT_BINARY_DIR}/clients/staging/$ ) if( ${CMAKE_BUILD_TYPE} MATCHES "Debug") add_custom_command( TARGET hipsparse POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/staging/hipsparse.pdb ${PROJECT_BINARY_DIR}/clients/staging/hipsparse.pdb ) endif() endif() # Following boost conventions of prefixing 'lib' on static built libraries if(NOT BUILD_SHARED_LIBS) set_target_properties(hipsparse PROPERTIES PREFIX "lib") endif() # Generate export header include(GenerateExportHeader) generate_export_header(hipsparse EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/hipsparse/hipsparse-export.h) # Install targets rocm_install_targets(TARGETS hipsparse INCLUDE ${CMAKE_BINARY_DIR}/include ) # Export targets if(NOT USE_CUDA) rocm_export_targets(TARGETS roc::hipsparse DEPENDS PACKAGE hip STATIC_DEPENDS PACKAGE rocsparse NAMESPACE roc::) else() rocm_export_targets(TARGETS roc::hipsparse NAMESPACE roc::) endif() ./library/include/0000775000175100017510000000000015176134511014176 5ustar jenkinsjenkins./library/include/hipsparse-generic-types.h0000664000175100017510000005035115176134511021125 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GENERIC_TYPES_H #define HIPSPARSE_GENERIC_TYPES_H /*! \ingroup types_module * \brief Generic API opaque structure holding information for a sparse vector * * \details * The hipSPARSE descriptor is an opaque structure holding information for a sparse vector. It must * be initialized using hipsparseCreateSpVec() and the returned descriptor * is used in hipSPARSE generic API's involving sparse vectors. It should be destroyed at the end using * hipsparseDestroySpVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) typedef void* hipsparseSpVecDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a dense vector * * \details * The hipSPARSE descriptor is an opaque structure holding information for a dense vector. It must * be initialized using hipsparseCreateDnVec() and the returned descriptor * is used in hipSPARSE generic API's involving dense vectors. It should be destroyed at the end using * hipsparseDestroyDnVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) typedef void* hipsparseDnVecDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a sparse matrix * * \details * The hipSPARSE descriptor is an opaque structure holding information for a sparse matrix. It must * be initialized using either hipsparseCreateCoo() (for COO format), hipsparseCreateCooAoS() (for COO AOS format). * hipsparseCreateCsr() (for CSR format), hipsparseCreateCsc() (for CSC format) or hipsparseCreateBlockedEll() * (for Blocked ELL format). The returned descriptor is used in hipSPARSE generic API's involving sparse matrices. * It should be destroyed at the end using hipsparseDestroySpMat(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) typedef struct hipsparseSpMatDescr_st* hipsparseSpMatDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a dense matrix * * \details * The hipSPARSE descriptor is an opaque structure holding information for a dense matrix. It must * be initialized using hipsparseCreateDnMat() and the returned descriptor * is used in hipSPARSE generic API's involving dense matrices. It should be destroyed at the end using * hipsparseDestroyDnMat(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) typedef void* hipsparseDnMatDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a sparse vector * * \details * The hipSPARSE (const) descriptor is an opaque structure holding information for a sparse vector. It must * be initialized using hipsparseCreateConstSpVec() and the returned descriptor * is used in hipSPARSE generic API's involving sparse vectors. It should be destroyed at the end using * hipsparseDestroySpVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) typedef void const* hipsparseConstSpVecDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a dense vector * * \details * The hipSPARSE (const) descriptor is an opaque structure holding information for a dense vector. It must * be initialized using hipsparseCreateConstDnVec() and the returned descriptor * is used in hipSPARSE generic API's involving dense vectors. It should be destroyed at the end using * hipsparseDestroyDnVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) typedef void const* hipsparseConstDnVecDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a sparse matrix * * \details * The hipSPARSE (const) descriptor is an opaque structure holding information for a sparse matrix. It must * be initialized using hipsparseCreateConstSpMat() and the returned descriptor * is used in hipSPARSE generic API's involving sparse matrices. It should be destroyed at the end using * hipsparseDestroySpMat(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) typedef struct hipsparseSpMatDescr_st const* hipsparseConstSpMatDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a dense matrix * * \details * The hipSPARSE (const) descriptor is an opaque structure holding information for a dense matrix. It must * be initialized using hipsparseCreateConstDnMat() and the returned descriptor * is used in hipSPARSE generic API's involving dense matrices. It should be destroyed at the end using * hipsparseDestroyDnMat(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) typedef void const* hipsparseConstDnMatDescr_t; #endif /// \cond DO_NOT_DOCUMENT // Forward declarations struct hipsparseSpGEMMDescr; struct hipsparseSpSVDescr; struct hipsparseSpSMDescr; /// \endcond /*! \ingroup types_module * \brief Generic API opaque structure holding information for a SpGEMM calculations * * \details * The hipSPARSE descriptor is an opaque structure holding information that is used in hipsparseSpGEMM_workEstimation(), * hipsparseSpGEMMreuse_workEstimation(), hipsparseSpGEMMreuse_nnz(), hipsparseSpGEMM_compute(), * hipsparseSpGEMMreuse_compute(), hipsparseSpGEMM_copy(), and hipsparseSpGEMMreuse_copy(). It must * be initialized using hipsparseSpGEMM_createDescr(). It should be destroyed at the end using * hipsparseSpGEMM_destroyDescr(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) typedef struct hipsparseSpGEMMDescr* hipsparseSpGEMMDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a SpSV calculations * * \details * The hipSPARSE descriptor is an opaque structure holding information that is used in hipsparseSpSV_bufferSize(), * hipsparseSpSV_analysis(), and hipsparseSpSV_solve(). It must be initialized using hipsparseSpSV_createDescr(). * It should be destroyed at the end using hipsparseSpSV_destroyDescr(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) typedef struct hipsparseSpSVDescr* hipsparseSpSVDescr_t; #endif /*! \ingroup types_module * \brief Generic API opaque structure holding information for a SpSM calculations * * \details * The hipSPARSE descriptor is an opaque structure holding information that is used in hipsparseSpSM_bufferSize(), * hipsparseSpSM_analysis(), and hipsparseSpSM_solve(). It must be initialized using hipsparseSpSM_createDescr(). * It should be destroyed at the end using hipsparseSpSM_destroyDescr(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) typedef struct hipsparseSpSMDescr* hipsparseSpSMDescr_t; #endif /* Generic API types */ /*! \ingroup generic_module * \brief List of hipsparse sparse matrix formats. * * \details * This is a list of the \ref hipsparseFormat_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION)) typedef enum { HIPSPARSE_FORMAT_CSR = 1, /**< Compressed Sparse Row */ HIPSPARSE_FORMAT_CSC = 2, /**< Compressed Sparse Column */ HIPSPARSE_FORMAT_COO = 3, /**< Coordinate - Structure of Arrays */ HIPSPARSE_FORMAT_COO_AOS = 4, /**< Coordinate - Array of Structures */ HIPSPARSE_FORMAT_BLOCKED_ELL = 5 /**< Blocked ELL */ } hipsparseFormat_t; #else #if(CUDART_VERSION >= 12000) typedef enum { HIPSPARSE_FORMAT_CSR = 1, /**< Compressed Sparse Row */ HIPSPARSE_FORMAT_CSC = 2, /**< Compressed Sparse Column */ HIPSPARSE_FORMAT_COO = 3, /**< Coordinate - Structure of Arrays */ HIPSPARSE_FORMAT_BLOCKED_ELL = 5 /**< Blocked ELL */ } hipsparseFormat_t; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) typedef enum { HIPSPARSE_FORMAT_CSR = 1, /**< Compressed Sparse Row */ HIPSPARSE_FORMAT_CSC = 2, /**< Compressed Sparse Column */ HIPSPARSE_FORMAT_COO = 3, /**< Coordinate - Structure of Arrays */ HIPSPARSE_FORMAT_COO_AOS = 4, /**< Coordinate - Array of Structures */ HIPSPARSE_FORMAT_BLOCKED_ELL = 5 /**< Blocked ELL */ } hipsparseFormat_t; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) typedef enum { HIPSPARSE_FORMAT_CSR = 1, /**< Compressed Sparse Row */ HIPSPARSE_FORMAT_COO = 3, /**< Coordinate - Structure of Arrays */ HIPSPARSE_FORMAT_COO_AOS = 4, /**< Coordinate - Array of Structures */ } hipsparseFormat_t; #endif #endif /*! \ingroup generic_module * \brief List of hipsparse dense matrix memory layout ordering. * * \details * This is a list of the \ref hipsparseOrder_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION)) typedef enum { HIPSPARSE_ORDER_COLUMN HIPSPARSE_DEPRECATED_MSG("Please use HIPSPARSE_ORDER_COL instead") = 1, /**< Column major */ HIPSPARSE_ORDER_COL = 1, /**< Column major */ HIPSPARSE_ORDER_ROW = 2 /**< Row major */ } hipsparseOrder_t; #else #if(CUDART_VERSION >= 11000) typedef enum { HIPSPARSE_ORDER_COLUMN HIPSPARSE_DEPRECATED_MSG("Please use HIPSPARSE_ORDER_COL instead") = 1, /**< Column major */ HIPSPARSE_ORDER_COL = 1, /**< Column major */ HIPSPARSE_ORDER_ROW = 2 /**< Row major */ } hipsparseOrder_t; #elif(CUDART_VERSION >= 10010) typedef enum { HIPSPARSE_ORDER_COLUMN HIPSPARSE_DEPRECATED_MSG("Please use HIPSPARSE_ORDER_COL instead") = 1, /**< Column major */ HIPSPARSE_ORDER_COL = 1 /**< Column major */ } hipsparseOrder_t; #endif #endif /*! \ingroup generic_module * \brief List of hipsparse index type used by sparse matrix indices. * * \details * This is a list of the \ref hipsparseIndexType_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) typedef enum { HIPSPARSE_INDEX_16U = 1, /**< 16 bit unsigned integer indices */ HIPSPARSE_INDEX_32I = 2, /**< 32 bit signed integer indices */ HIPSPARSE_INDEX_64I = 3 /**< 64 bit signed integer indices */ } hipsparseIndexType_t; #endif /*! \ingroup generic_module * \brief List of hipsparse SpMV algorithms. * * \details * This is a list of the \ref hipsparseSpMVAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION)) typedef enum { HIPSPARSE_MV_ALG_DEFAULT = 0, HIPSPARSE_COOMV_ALG = 1, HIPSPARSE_CSRMV_ALG1 = 2, HIPSPARSE_CSRMV_ALG2 = 3, HIPSPARSE_SPMV_ALG_DEFAULT = 0, HIPSPARSE_SPMV_COO_ALG1 = 1, HIPSPARSE_SPMV_CSR_ALG1 = 2, HIPSPARSE_SPMV_CSR_ALG2 = 3, HIPSPARSE_SPMV_COO_ALG2 = 4 } hipsparseSpMVAlg_t; #else #if(CUDART_VERSION >= 12000) typedef enum { HIPSPARSE_SPMV_ALG_DEFAULT = 0, HIPSPARSE_SPMV_COO_ALG1 = 1, HIPSPARSE_SPMV_CSR_ALG1 = 2, HIPSPARSE_SPMV_CSR_ALG2 = 3, HIPSPARSE_SPMV_COO_ALG2 = 4 } hipsparseSpMVAlg_t; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) typedef enum { HIPSPARSE_MV_ALG_DEFAULT = 0, HIPSPARSE_COOMV_ALG = 1, HIPSPARSE_CSRMV_ALG1 = 2, HIPSPARSE_CSRMV_ALG2 = 3, HIPSPARSE_SPMV_ALG_DEFAULT = 0, HIPSPARSE_SPMV_COO_ALG1 = 1, HIPSPARSE_SPMV_CSR_ALG1 = 2, HIPSPARSE_SPMV_CSR_ALG2 = 3, HIPSPARSE_SPMV_COO_ALG2 = 4 } hipsparseSpMVAlg_t; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) typedef enum { HIPSPARSE_MV_ALG_DEFAULT = 0, HIPSPARSE_COOMV_ALG = 1, HIPSPARSE_CSRMV_ALG1 = 2, HIPSPARSE_CSRMV_ALG2 = 3 } hipsparseSpMVAlg_t; #endif #endif /*! \ingroup generic_module * \brief List of hipsparse SpMM algorithms. * * \details * This is a list of the \ref hipsparseSpMMAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION)) typedef enum { HIPSPARSE_MM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_COOMM_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_COOMM_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_COOMM_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_CSRMM_ALG1 = 4, /**< CSR algorithm 1 */ HIPSPARSE_SPMM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_SPMM_COO_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_SPMM_COO_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_SPMM_COO_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_SPMM_COO_ALG4 = 5, /**< COO algorithm 4 */ HIPSPARSE_SPMM_CSR_ALG1 = 4, /**< CSR algorithm 1 */ HIPSPARSE_SPMM_CSR_ALG2 = 6, /**< CSR algorithm 2 */ HIPSPARSE_SPMM_CSR_ALG3 = 12, /**< CSR algorithm 3 */ HIPSPARSE_SPMM_BLOCKED_ELL_ALG1 = 13 /**< Blocked ELL algorithm 1 */ } hipsparseSpMMAlg_t; #else #if(CUDART_VERSION >= 12000) typedef enum { HIPSPARSE_SPMM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_SPMM_COO_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_SPMM_COO_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_SPMM_COO_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_SPMM_COO_ALG4 = 5, /**< COO algorithm 4 */ HIPSPARSE_SPMM_CSR_ALG1 = 4, /**< CSR algorithm 1 */ HIPSPARSE_SPMM_CSR_ALG2 = 6, /**< CSR algorithm 2 */ HIPSPARSE_SPMM_CSR_ALG3 = 12, /**< CSR algorithm 3 */ HIPSPARSE_SPMM_BLOCKED_ELL_ALG1 = 13 /**< Blocked ELL algorithm 1 */ } hipsparseSpMMAlg_t; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) typedef enum { HIPSPARSE_MM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_COOMM_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_COOMM_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_COOMM_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_CSRMM_ALG1 = 4, /**< CSR algorithm 1 */ HIPSPARSE_SPMM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_SPMM_COO_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_SPMM_COO_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_SPMM_COO_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_SPMM_COO_ALG4 = 5, /**< COO algorithm 4 */ HIPSPARSE_SPMM_CSR_ALG1 = 4, /**< CSR algorithm 1 */ HIPSPARSE_SPMM_CSR_ALG2 = 6, /**< CSR algorithm 2 */ HIPSPARSE_SPMM_CSR_ALG3 = 12, /**< CSR algorithm 3 */ HIPSPARSE_SPMM_BLOCKED_ELL_ALG1 = 13 /**< Blocked ELL algorithm 1 */ } hipsparseSpMMAlg_t; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) typedef enum { HIPSPARSE_MM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_COOMM_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_COOMM_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_COOMM_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_CSRMM_ALG1 = 4, /**< CSR algorithm 1 */ HIPSPARSE_SPMM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_SPMM_COO_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_SPMM_COO_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_SPMM_COO_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_SPMM_COO_ALG4 = 5, /**< COO algorithm 4 */ HIPSPARSE_SPMM_CSR_ALG1 = 4, /**< CSR algorithm 1 */ HIPSPARSE_SPMM_CSR_ALG2 = 6, /**< CSR algorithm 2 */ HIPSPARSE_SPMM_BLOCKED_ELL_ALG1 = 13 /**< Blocked ELL algorithm 1 */ } hipsparseSpMMAlg_t; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) typedef enum { HIPSPARSE_MM_ALG_DEFAULT = 0, /**< Default algorithm */ HIPSPARSE_COOMM_ALG1 = 1, /**< COO algorithm 1 */ HIPSPARSE_COOMM_ALG2 = 2, /**< COO algorithm 2 */ HIPSPARSE_COOMM_ALG3 = 3, /**< COO algorithm 3 */ HIPSPARSE_CSRMM_ALG1 = 4 /**< CSR algorithm 1 */ } hipsparseSpMMAlg_t; #endif #endif /*! \ingroup generic_module * \brief List of hipsparse SparseToDense algorithms. * * \details * This is a list of the \ref hipsparseSparseToDenseAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) typedef enum { HIPSPARSE_SPARSETODENSE_ALG_DEFAULT = 0, } hipsparseSparseToDenseAlg_t; #endif /*! \ingroup generic_module * \brief List of hipsparse DenseToSparse algorithms. * * \details * This is a list of the \ref hipsparseDenseToSparseAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) typedef enum { HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT = 0, } hipsparseDenseToSparseAlg_t; #endif /*! \ingroup generic_module * \brief List of hipsparse SDDMM algorithms. * * \details * This is a list of the \ref hipsparseSDDMMAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) typedef enum { HIPSPARSE_SDDMM_ALG_DEFAULT = 0 } hipsparseSDDMMAlg_t; #endif /*! \ingroup generic_module * \brief List of hipsparse SpSV algorithms. * * \details * This is a list of the \ref hipsparseSpSVAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) typedef enum { HIPSPARSE_SPSV_ALG_DEFAULT = 0 } hipsparseSpSVAlg_t; #endif /*! \ingroup generic_module * \brief List of hipsparse SpSM algorithms. * * \details * This is a list of the \ref hipsparseSpSMAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) typedef enum { HIPSPARSE_SPSM_ALG_DEFAULT = 0 } hipsparseSpSMAlg_t; #endif /*! \ingroup generic_module * \brief List of hipsparse attributes. * * \details * This is a list of the \ref hipsparseSpMatAttribute_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) typedef enum { HIPSPARSE_SPMAT_FILL_MODE = 0, /**< Fill mode attribute */ HIPSPARSE_SPMAT_DIAG_TYPE = 1 /**< Diag type attribute */ } hipsparseSpMatAttribute_t; #endif /*! \ingroup generic_module * \brief List of hipsparse SpGEMM algorithms. * * \details * This is a list of the \ref hipsparseSpGEMMAlg_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION)) typedef enum { HIPSPARSE_SPGEMM_DEFAULT = 0, HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC = 1, HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC = 2, HIPSPARSE_SPGEMM_ALG1 = 3, HIPSPARSE_SPGEMM_ALG2 = 4, HIPSPARSE_SPGEMM_ALG3 = 5 } hipsparseSpGEMMAlg_t; #else #if(CUDART_VERSION >= 12000) typedef enum { HIPSPARSE_SPGEMM_DEFAULT = 0, HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC = 1, HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC = 2, HIPSPARSE_SPGEMM_ALG1 = 3, HIPSPARSE_SPGEMM_ALG2 = 4, HIPSPARSE_SPGEMM_ALG3 = 5 } hipsparseSpGEMMAlg_t; #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) typedef enum { HIPSPARSE_SPGEMM_DEFAULT = 0, HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC = 1, HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC = 2, } hipsparseSpGEMMAlg_t; #elif(CUDART_VERSION >= 11000) typedef enum { HIPSPARSE_SPGEMM_DEFAULT = 0 } hipsparseSpGEMMAlg_t; #endif #endif #endif /* HIPSPARSE_GENERIC_TYPES_H */ ./library/include/hipsparse.h0000664000175100017510000002070515176134511016351 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief hipsparse.h provides Sparse Linear Algebra Subprograms * of Level 1, 2 and 3, using HIP optimized for AMD GPU hardware. */ // HIP = Heterogeneous-compute Interface for Portability // // Define a extremely thin runtime layer that allows source code to be compiled // unmodified through either AMD HCC or NVCC. Key features tend to be in the spirit // and terminology of CUDA, but with a portable path to other accelerators as well. // // This is the master include file for hipSPARSE, wrapping around rocSPARSE and // cuSPARSE "version 2". #ifndef HIPSPARSE_H #define HIPSPARSE_H #include "hipsparse-export.h" #include "hipsparse-version.h" #include #include /// \cond DO_NOT_DOCUMENT #define DEPRECATED_CUDA_12000(warning) #define DEPRECATED_CUDA_11000(warning) #define DEPRECATED_CUDA_10000(warning) #define DEPRECATED_CUDA_9000(warning) #ifdef __cplusplus #ifndef __has_cpp_attribute #define __has_cpp_attribute(X) 0 #endif #define HIPSPARSE_HAS_DEPRECATED_MSG __has_cpp_attribute(deprecated) >= 201309L #else #ifndef __has_c_attribute #define __has_c_attribute(X) 0 #endif #define HIPSPARSE_HAS_DEPRECATED_MSG __has_c_attribute(deprecated) >= 201904L #endif #if HIPSPARSE_HAS_DEPRECATED_MSG #define HIPSPARSE_DEPRECATED_MSG(MSG) [[deprecated(MSG)]] #else #define HIPSPARSE_DEPRECATED_MSG(MSG) HIPSPARSE_DEPRECATED // defined in hipsparse-export.h #endif /// \endcond #if defined(CUDART_VERSION) #if CUDART_VERSION < 10000 #undef DEPRECATED_CUDA_9000 #define DEPRECATED_CUDA_9000(warning) HIPSPARSE_DEPRECATED_MSG(warning) #elif CUDART_VERSION < 11000 #undef DEPRECATED_CUDA_10000 #define DEPRECATED_CUDA_10000(warning) HIPSPARSE_DEPRECATED_MSG(warning) #elif CUDART_VERSION < 12000 #undef DEPRECATED_CUDA_11000 #define DEPRECATED_CUDA_11000(warning) HIPSPARSE_DEPRECATED_MSG(warning) #elif CUDART_VERSION < 13000 #undef DEPRECATED_CUDA_12000 #define DEPRECATED_CUDA_12000(warning) HIPSPARSE_DEPRECATED_MSG(warning) #endif #endif #include "hipsparse-bfloat16.h" #include "hipsparse-types.h" #include "hipsparse-auxiliary.h" /* * =========================================================================== * level 1 SPARSE * =========================================================================== */ #include "internal/level1/hipsparse_axpyi.h" #include "internal/level1/hipsparse_dotci.h" #include "internal/level1/hipsparse_doti.h" #include "internal/level1/hipsparse_gthr.h" #include "internal/level1/hipsparse_gthrz.h" #include "internal/level1/hipsparse_roti.h" #include "internal/level1/hipsparse_sctr.h" /* * =========================================================================== * level 2 SPARSE * =========================================================================== */ #include "internal/level2/hipsparse_bsrmv.h" #include "internal/level2/hipsparse_bsrsv.h" #include "internal/level2/hipsparse_bsrxmv.h" #include "internal/level2/hipsparse_csrmv.h" #include "internal/level2/hipsparse_csrsv.h" #include "internal/level2/hipsparse_gemvi.h" #include "internal/level2/hipsparse_hybmv.h" /* * =========================================================================== * level 3 SPARSE * =========================================================================== */ #include "internal/level3/hipsparse_bsrmm.h" #include "internal/level3/hipsparse_bsrsm.h" #include "internal/level3/hipsparse_csrmm.h" #include "internal/level3/hipsparse_csrsm.h" #include "internal/level3/hipsparse_gemmi.h" /* * =========================================================================== * extra SPARSE * =========================================================================== */ #include "internal/extra/hipsparse_csrgeam.h" #include "internal/extra/hipsparse_csrgemm.h" /* * =========================================================================== * preconditioner SPARSE * =========================================================================== */ #include "internal/precond/hipsparse_bsric0.h" #include "internal/precond/hipsparse_bsrilu0.h" #include "internal/precond/hipsparse_csric0.h" #include "internal/precond/hipsparse_csrilu0.h" #include "internal/precond/hipsparse_gpsv_interleaved_batch.h" #include "internal/precond/hipsparse_gtsv.h" #include "internal/precond/hipsparse_gtsv_interleaved_batch.h" #include "internal/precond/hipsparse_gtsv_nopivot.h" #include "internal/precond/hipsparse_gtsv_strided_batch.h" /* * =========================================================================== * format conversions SPARSE * =========================================================================== */ #include "internal/conversion/hipsparse_bsr2csr.h" #include "internal/conversion/hipsparse_coo2csr.h" #include "internal/conversion/hipsparse_coosort.h" #include "internal/conversion/hipsparse_create_identity_permutation.h" #include "internal/conversion/hipsparse_csc2dense.h" #include "internal/conversion/hipsparse_cscsort.h" #include "internal/conversion/hipsparse_csr2bsr.h" #include "internal/conversion/hipsparse_csr2coo.h" #include "internal/conversion/hipsparse_csr2csc.h" #include "internal/conversion/hipsparse_csr2csr_compress.h" #include "internal/conversion/hipsparse_csr2csru.h" #include "internal/conversion/hipsparse_csr2dense.h" #include "internal/conversion/hipsparse_csr2gebsr.h" #include "internal/conversion/hipsparse_csr2hyb.h" #include "internal/conversion/hipsparse_csrsort.h" #include "internal/conversion/hipsparse_csru2csr.h" #include "internal/conversion/hipsparse_dense2csc.h" #include "internal/conversion/hipsparse_dense2csr.h" #include "internal/conversion/hipsparse_gebsr2csr.h" #include "internal/conversion/hipsparse_gebsr2gebsc.h" #include "internal/conversion/hipsparse_gebsr2gebsr.h" #include "internal/conversion/hipsparse_hyb2csr.h" #include "internal/conversion/hipsparse_nnz.h" #include "internal/conversion/hipsparse_nnz_compress.h" #include "internal/conversion/hipsparse_prune_csr2csr.h" #include "internal/conversion/hipsparse_prune_csr2csr_by_percentage.h" #include "internal/conversion/hipsparse_prune_dense2csr.h" #include "internal/conversion/hipsparse_prune_dense2csr_by_percentage.h" /* * =========================================================================== * reordering SPARSE * =========================================================================== */ #include "internal/reorder/hipsparse_csrcolor.h" /* * =========================================================================== * generic SPARSE * =========================================================================== */ #include "hipsparse-generic-types.h" #include "hipsparse-generic-auxiliary.h" #include "internal/generic/hipsparse_axpby.h" #include "internal/generic/hipsparse_dense2sparse.h" #include "internal/generic/hipsparse_gather.h" #include "internal/generic/hipsparse_rot.h" #include "internal/generic/hipsparse_scatter.h" #include "internal/generic/hipsparse_sddmm.h" #include "internal/generic/hipsparse_sparse2dense.h" #include "internal/generic/hipsparse_spgemm.h" #include "internal/generic/hipsparse_spgemm_reuse.h" #include "internal/generic/hipsparse_spmm.h" #include "internal/generic/hipsparse_spmv.h" #include "internal/generic/hipsparse_spsm.h" #include "internal/generic/hipsparse_spsv.h" #include "internal/generic/hipsparse_spvv.h" #endif // HIPSPARSE_H ./library/include/hipsparse-bfloat16.h0000664000175100017510000001172315176134511017765 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BFLOAT16_H #define HIPSPARSE_BFLOAT16_H #if __cplusplus < 201103L // If this is a C or C++ compiler below C++11, // we only include a minimal definition of hipsparseBfloat16 typedef struct hipsparseBfloat16 { uint16_t data; } hipsparseBfloat16; #else #include #include class hipsparseBfloat16 { public: uint16_t data; // zero extend lower 16 bits of bfloat16 to convert to IEEE float static float bfloat16_to_float(hipsparseBfloat16 val) { union { uint32_t int32; float fp32; } u = {uint32_t(val.data) << 16}; return u.fp32; } static uint16_t float_to_bfloat16(float f) { union { float fp32; uint32_t int32; } u = {f}; if(~u.int32 & 0x7f800000) { u.int32 += 0x7fff + ((u.int32 >> 16) & 1); // Round to nearest, round to even } else if(u.int32 & 0xffff) { u.int32 |= 0x10000; // Preserve signaling NaN } return uint16_t(u.int32 >> 16); } hipsparseBfloat16() = default; // round upper 16 bits of IEEE float to convert to bfloat16 explicit hipsparseBfloat16(float f) : data(float_to_bfloat16(f)) { } hipsparseBfloat16 operator=(float a) { return hipsparseBfloat16(a); } // zero extend lower 16 bits of bfloat16 to convert to IEEE float operator float() const { union { uint32_t int32; float fp32; } u = {uint32_t(data) << 16}; return u.fp32; } explicit operator bool() const { return data & 0x7fff; } }; inline std::ostream& operator<<(std::ostream& os, const hipsparseBfloat16& bf16) { return os << float(bf16); } typedef struct { uint16_t data; } hipsparseBfloat16_public; static_assert(std::is_standard_layout{}, "hipsparseBfloat16 is not a standard layout type, and thus is " "incompatible with C."); static_assert(std::is_trivial{}, "hipsparseBfloat16 is not a trivial type, and thus is " "incompatible with C."); static_assert(sizeof(hipsparseBfloat16) == sizeof(hipsparseBfloat16_public) && offsetof(hipsparseBfloat16, data) == offsetof(hipsparseBfloat16_public, data), "internal hipsparseBfloat16 does not match public hipsparseBfloat16_public"); inline hipsparseBfloat16 operator+=(hipsparseBfloat16 a, hipsparseBfloat16 b) { return a = a + b; } inline hipsparseBfloat16 operator+=(hipsparseBfloat16 a, float b) { return a = hipsparseBfloat16(float(a) + b); } inline float operator+=(float a, hipsparseBfloat16 b) { return a = a + float(b); } inline hipsparseBfloat16 operator-=(hipsparseBfloat16 a, hipsparseBfloat16 b) { return a = a - b; } inline hipsparseBfloat16 operator-=(hipsparseBfloat16 a, float b) { return a = hipsparseBfloat16(float(a) - b); } inline float operator-=(float a, hipsparseBfloat16 b) { return a = a - float(b); } inline hipsparseBfloat16 operator*=(hipsparseBfloat16 a, hipsparseBfloat16 b) { return a = a * b; } inline float operator*=(hipsparseBfloat16 a, float b) { return a = float(a) * b; } inline float operator*=(float a, hipsparseBfloat16 b) { return a = a * float(b); } inline hipsparseBfloat16 operator/=(hipsparseBfloat16 a, hipsparseBfloat16 b) { return a = a / b; } inline hipsparseBfloat16 operator/=(hipsparseBfloat16 a, float b) { return a = hipsparseBfloat16(float(a) / b); } inline float operator/=(float a, hipsparseBfloat16 b) { return a = a / float(b); } #endif #endif // HIPSPARSE_BFLOAT16_H ./library/include/internal/0000775000175100017510000000000015176134305016013 5ustar jenkinsjenkins./library/include/internal/level1/0000775000175100017510000000000015176134511017202 5ustar jenkinsjenkins./library/include/internal/level1/hipsparse_roti.h0000664000175100017510000001042515176134511022410 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_ROTI_H #define HIPSPARSE_ROTI_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level1_module * \brief Apply Givens rotation to a dense and a sparse vector. * * \details * \p hipsparseXroti applies the Givens rotation matrix \f$G\f$ to the sparse vector * \f$x\f$ and the dense vector \f$y\f$, where * \f[ * G = \begin{pmatrix} c & s \\ -s & c \end{pmatrix} * \f] * * \code{.c} * for(i = 0; i < nnz; ++i) * { * x_tmp = xVal[i]; * y_tmp = y[xInd[i]]; * * xVal[i] = c * x_tmp + s * y_tmp; * y[xInd[i]] = c * y_tmp - s * x_tmp; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * nnz number of non-zero entries of \f$x\f$. * @param[inout] * xVal array of \p nnz elements containing the non-zero values of \f$x\f$. * @param[in] * xInd array of \p nnz elements containing the indices of the non-zero * values of \f$x\f$. * @param[inout] * y array of values in dense format. * @param[in] * c pointer to the cosine element of \f$G\f$, can be on host or device. * @param[in] * s pointer to the sine element of \f$G\f$, can be on host or device. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p idxBase, \p nnz, \p c, \p s, \p xVal, \p xInd * or \p y is invalid. * * \par Example * \snippet example_hipsparse_roti.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSroti(hipsparseHandle_t handle, int nnz, float* xVal, const int* xInd, float* y, const float* c, const float* s, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDroti(hipsparseHandle_t handle, int nnz, double* xVal, const int* xInd, double* y, const double* c, const double* s, hipsparseIndexBase_t idxBase); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_ROTI_H */ ./library/include/internal/level1/hipsparse_sctr.h0000664000175100017510000001116615176134511022411 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SCTR_H #define HIPSPARSE_SCTR_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level1_module * \brief Scatter elements from a dense vector across a sparse vector. * * \details * \p hipsparseXsctr scatters the elements that are listed in \p xInd from the sparse * vector \f$x\f$ into the dense vector \f$y\f$. Indices of \f$y\f$ that are not listed * in \p xInd remain unchanged. * * \code{.c} * for(i = 0; i < nnz; ++i) * { * y[xInd[i]] = xVal[i]; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * nnz number of non-zero entries of \f$x\f$. * @param[in] * xVal array of \p nnz elements containing the non-zero values of \f$x\f$. * @param[in] * xInd array of \p nnz elements containing the indices of the non-zero * values of x. * @param[inout] * y array of values in dense format. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p idxBase, \p nnz, \p xVal, \p xInd * or \p y is invalid. * * \par Example * \snippet example_hipsparse_sctr.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSsctr(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDsctr(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCsctr(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZsctr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SCTR_H */ ./library/include/internal/level1/hipsparse_gthrz.h0000664000175100017510000001117415176134511022573 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GTHRZ_H #define HIPSPARSE_GTHRZ_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level1_module * \brief Gather and zero out elements from a dense vector and store them into a sparse * vector. * * \details * \p hipsparseXgthrz gathers the elements that are listed in \p xInd from the dense * vector \f$y\f$ and stores them in the sparse vector \f$x\f$. The gathered elements * in \f$y\f$ are replaced by zero. * * \code{.c} * for(i = 0; i < nnz; ++i) * { * xVal[i] = y[xInd[i]]; * y[xInd[i]] = 0; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * nnz number of non-zero entries of \f$x\f$. * @param[inout] * y array of values in dense format. * @param[out] * xVal array of \p nnz elements containing the non-zero values of \f$x\f$. * @param[in] * xInd array of \p nnz elements containing the indices of the non-zero * values of \f$x\f$. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p idxBase, \p nnz, \p y, \p xVal * or \p xInd is invalid. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgthrz(hipsparseHandle_t handle, int nnz, float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgthrz(hipsparseHandle_t handle, int nnz, double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgthrz(hipsparseHandle_t handle, int nnz, hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgthrz(hipsparseHandle_t handle, int nnz, hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GTHRZ_H */ ./library/include/internal/level1/hipsparse_gthr.h0000664000175100017510000001110315176134511022371 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GTHR_H #define HIPSPARSE_GTHR_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level1_module * \brief Gather elements from a dense vector and store them into a sparse vector. * * \details * \p hipsparseXgthr gathers the elements that are listed in \p xInd from the dense * vector \f$y\f$ and stores them in the sparse vector \f$x\f$. * * \code{.c} * for(i = 0; i < nnz; ++i) * { * xVal[i] = y[xInd[i]]; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * nnz number of non-zero entries of \f$x\f$. * @param[in] * y array of values in dense format. * @param[out] * xVal array of \p nnz elements containing the values of \f$x\f$. * @param[in] * xInd array of \p nnz elements containing the indices of the non-zero * values of \f$x\f$. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p idxBase, \p nnz, \p y, \p xVal or \p xInd is * invalid. * * \par Example * \snippet example_hipsparse_gthr.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgthr(hipsparseHandle_t handle, int nnz, const float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgthr(hipsparseHandle_t handle, int nnz, const double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgthr(hipsparseHandle_t handle, int nnz, const hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgthr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GTHR_H */ ./library/include/internal/level1/hipsparse_dotci.h0000664000175100017510000001012515176134511022532 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_DOTCI_H #define HIPSPARSE_DOTCI_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup level1_module * \brief Compute the dot product of a complex conjugate sparse vector with a dense * vector. * * \details * \p hipsparseXdotci computes the dot product of the complex conjugate sparse vector * \f$x\f$ with the dense vector \f$y\f$, such that * \f[ * result := \bar{x}^H y * \f] * * \code{.c} * result = 0 * for(i = 0; i < nnz; ++i) * { * result += conj(xVal[i]) * y[xInd[i]]; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * nnz number of non-zero entries of vector \f$x\f$. * @param[in] * xVal array of \p nnz values. * @param[in] * xInd array of \p nnz elements containing the indices of the non-zero * values of \f$x\f$. * @param[in] * y array of values in dense format. * @param[out] * result pointer to the result, can be host or device memory * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p idxBase, \p nnz, \p xVal, * \p xInd, \p y or \p result is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED the buffer for the dot product reduction * could not be allocated. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCdotci(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZdotci(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_DOTCI_H */ ./library/include/internal/level1/hipsparse_axpyi.h0000664000175100017510000001166615176134511022575 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_AXPYI_H #define HIPSPARSE_AXPYI_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level1_module * \brief Scale a sparse vector and add it to a dense vector. * * \details * \p hipsparseXaxpyi multiplies the sparse vector \f$x\f$ with scalar \f$\alpha\f$ and * adds the result to the dense vector \f$y\f$, such that * * \f[ * y := y + \alpha \cdot x * \f] * * \code{.c} * for(i = 0; i < nnz; ++i) * { * y[xInd[i]] = y[xInd[i]] + alpha * xVal[i]; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * nnz number of non-zero entries of vector \f$x\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * xVal array of \p nnz elements containing the values of \f$x\f$. * @param[in] * xInd array of \p nnz elements containing the indices of the non-zero * values of \f$x\f$. * @param[inout] * y array of values in dense format. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p idxBase, \p nnz, \p alpha, \p xVal, \p xInd or \p y is invalid. * * \par Example * \snippet example_hipsparse_axpyi.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSaxpyi(hipsparseHandle_t handle, int nnz, const float* alpha, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDaxpyi(hipsparseHandle_t handle, int nnz, const double* alpha, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCaxpyi(hipsparseHandle_t handle, int nnz, const hipComplex* alpha, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZaxpyi(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_AXPYI_H */ ./library/include/internal/level1/hipsparse_doti.h0000664000175100017510000001210715176134511022371 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_DOTI_H #define HIPSPARSE_DOTI_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup level1_module * \brief Compute the dot product of a sparse vector with a dense vector. * * \details * \p hipsparseXdoti computes the dot product of the sparse vector \f$x\f$ with the * dense vector \f$y\f$, such that * \f[ * result := y^T x * \f] * * \code{.c} * result = 0 * for(i = 0; i < nnz; ++i) * { * result += xVal[i] * y[xInd[i]]; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * nnz number of non-zero entries of vector \f$x\f$. * @param[in] * xVal array of \p nnz values. * @param[in] * xInd array of \p nnz elements containing the indices of the non-zero * values of \f$x\f$. * @param[in] * y array of values in dense format. * @param[out] * result pointer to the result, can be host or device memory * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p idxBase, \p nnz, \p xVal, * \p xInd, \p y or \p result is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED the buffer for the dot product reduction * could not be allocated. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_doti.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSdoti(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, const float* y, float* result, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDdoti(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, const double* y, double* result, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCdoti(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZdoti(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_DOTI_H */ ./library/include/internal/level3/0000775000175100017510000000000015176134511017204 5ustar jenkinsjenkins./library/include/internal/level3/hipsparse_csrmm.h0000664000175100017510000004433315176134511022563 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRMM_H #define HIPSPARSE_CSRMM_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup level3_module * \brief Sparse matrix dense matrix multiplication using CSR storage format * * \details * \p hipsparseXcsrmm multiplies the scalar \f$\alpha\f$ with a sparse \f$m \times k\f$ * matrix \f$A\f$, defined in CSR storage format, and the column-oriented dense \f$k \times n\f$ * matrix \f$B\f$ and adds the result to the column-oriented dense \f$m \times n\f$ matrix \f$C\f$ that * is multiplied by the scalar \f$\beta\f$, such that * \f[ * C := \alpha \cdot op(A) \cdot B + \beta \cdot C, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if transA == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * \code{.c} * for(i = 0; i < ldc; ++i) * { * for(j = 0; j < n; ++j) * { * C[i][j] = beta * C[i][j]; * * for(k = csrRowPtr[i]; k < csrRowPtr[i + 1]; ++k) * { * C[i][j] += alpha * csrVal[k] * B[csrColInd[k]][j]; * } * } * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$. * @param[in] * n number of columns of the dense matrix \f$op(B)\f$ and \f$C\f$. * @param[in] * k number of columns of the sparse CSR matrix \f$A\f$. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix \f$A\f$. * @param[in] * B array of dimension \p ldb*n (\f$op(B) == B\f$), * \p ldb*k otherwise. * @param[in] * ldb leading dimension of \f$B\f$, must be at least \f$\max{(1, k)}\f$ * (\f$op(B) == B\f$), \f$\max{(1, n)}\f$ otherwise. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * C array of dimension \p ldc*n. * @param[in] * ldc leading dimension of \f$C\f$, must be at least \f$\max{(1, m)}\f$ * (\f$op(A) == A\f$), \f$\max{(1, k)}\f$ otherwise. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnz, \p ldb, \p ldc * \p descrA, \p alpha, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, * \p B, \p beta or \p C is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrmm.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, const float* beta, float* C, int ldc); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, const double* beta, double* C, int ldc); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup level3_module * \brief Sparse matrix dense matrix multiplication using CSR storage format * * \details * \p hipsparseXcsrmm2 multiplies the scalar \f$\alpha\f$ with a sparse \f$m \times k\f$ * matrix \f$A\f$, defined in CSR storage format, and the column-oriented dense \f$k \times n\f$ * matrix \f$B\f$ and adds the result to the column-oriented dense \f$m \times n\f$ matrix \f$C\f$ that * is multiplied by the scalar \f$\beta\f$, such that * \f[ * C := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if transA == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * and * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if transB == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if transB == HIPSPARSE_OPERATION_TRANSPOSE} \\ * B^H, & \text{if transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * \code{.c} * for(i = 0; i < ldc; ++i) * { * for(j = 0; j < n; ++j) * { * C[i][j] = beta * C[i][j]; * * for(k = csrRowPtr[i]; k < csrRowPtr[i + 1]; ++k) * { * C[i][j] += alpha * csrVal[k] * B[csrColInd[k]][j]; * } * } * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transB matrix \f$B\f$ operation type. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$. * @param[in] * n number of columns of the dense matrix \f$op(B)\f$ and \f$C\f$. * @param[in] * k number of columns of the sparse CSR matrix \f$A\f$. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix \f$A\f$. * @param[in] * B array of dimension \p ldb*n (\f$op(B) == B\f$), * \p ldb*k otherwise. * @param[in] * ldb leading dimension of \f$B\f$, must be at least \f$\max{(1, k)}\f$ * (\f$op(B) == B\f$), \f$\max{(1, n)}\f$ otherwise. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * C array of dimension \p ldc*n. * @param[in] * ldc leading dimension of \f$C\f$, must be at least \f$\max{(1, m)}\f$ * (\f$op(A) == A\f$), \f$\max{(1, k)}\f$ otherwise. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnz, \p ldb, \p ldc * \p descrA, \p alpha, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, * \p B, \p beta or \p C is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, const float* beta, float* C, int ldc); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, const double* beta, double* C, int ldc); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRMM_H */ ./library/include/internal/level3/hipsparse_bsrmm.h0000664000175100017510000002520515176134511022557 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSRMM_H #define HIPSPARSE_BSRMM_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup level3_module * \brief Sparse matrix dense matrix multiplication using BSR storage format * * \details * \p hipsparseXbsrmm multiplies the scalar \f$\alpha\f$ with a sparse \f$m \times k\f$ * matrix \f$A\f$, defined in BSR storage format, and the column-oriented dense \f$k \times n\f$ * matrix \f$B\f$ and adds the result to the column-oriented dense \f$m \times n\f$ matrix \f$C\f$ that * is multiplied by the scalar \f$\beta\f$, such that * \f[ * C := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * \end{array} * \right. * \f] * and * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if transB == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if transB == HIPSPARSE_OPERATION_TRANSPOSE} \\ * \end{array} * \right. * \f] * and where \f$k = blockDim \times kb\f$ and \f$m = blockDim \times mb\f$. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA the storage format of the blocks. Can be \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * transA matrix \f$A\f$ operation type. Currently, only \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * @param[in] * transB matrix \f$B\f$ operation type. Currently, only \ref HIPSPARSE_OPERATION_NON_TRANSPOSE and \ref HIPSPARSE_OPERATION_TRANSPOSE * are supported. * @param[in] * mb number of block rows of the sparse BSR matrix \f$A\f$. * @param[in] * n number of columns of the dense matrix \f$op(B)\f$ and \f$C\f$. * @param[in] * kb number of block columns of the sparse BSR matrix \f$A\f$. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix \f$A\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse BSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * bsrValA array of \p nnzb*blockDim*blockDim elements of the sparse BSR matrix \f$A\f$. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix \f$A\f$. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse * BSR matrix \f$A\f$. * @param[in] * blockDim size of the blocks in the sparse BSR matrix. * @param[in] * B array of dimension \p ldb*n (\f$op(B) == B\f$), * \p ldb*k otherwise. * @param[in] * ldb leading dimension of \f$B\f$, must be at least \f$\max{(1, k)}\f$ (\f$ op(B) == B\f$) where \p k=blockDim*kb, * \f$\max{(1, n)}\f$ otherwise. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * C array of dimension \p ldc*n. * @param[in] * ldc leading dimension of \f$C\f$, must be at least \f$\max{(1, m)}\f$ (\f$ op(A) == A\f$) where \p m=blockDim*mb, * \f$\max{(1, k)}\f$ where \p k=blockDim*kb otherwise. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p n, \p kb, \p nnzb, \p ldb, * \p ldc, \p descr, \p alpha, \p bsrValA, \p bsrRowPtrA, \p bsrColIndA, * \p B, \p beta or \p C is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p transB == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_bsrmm.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const float* B, int ldb, const float* beta, float* C, int ldc); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const double* B, int ldb, const double* beta, double* C, int ldc); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSRMM_H */ ./library/include/internal/level3/hipsparse_bsrsm.h0000664000175100017510000010310215176134511022556 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSRSM_H #define HIPSPARSE_BSRSM_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level3_module * \details * \p hipsparseXbsrsm2_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during \ref hipsparseSbsrsm2_analysis "hipsparseXbsrsm2_analysis()" * or \ref hipsparseSbsrsm2_solve "hipsparseXbsrsm2_solve()" computation. The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ * is stored in \p position, using same index base as the BSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note \p hipsparseXbsrsm2_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info or \p position is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXbsrsm2_zeroPivot(hipsparseHandle_t handle, bsrsm2Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level3_module * \details * \p hipsparseXbsrsm2_buffer_size returns the size of the temporary storage buffer in bytes * that is required by \ref hipsparseSbsrsm2_analysis "hipsparseXbsrsm2_analysis()" and * \ref hipsparseSbsrsm2_solve "hipsparseXbsrsm2_solve()". The temporary storage buffer must * be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transX matrix \f$X\f$ operation type. * @param[in] * mb number of block rows of the sparse BSR matrix \f$A\f$. * @param[in] * nrhs number of columns of the dense matrix \f$op(X)\f$. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix \f$A\f$. * @param[in] * descrA descriptor of the sparse BSR matrix \f$A\f$. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnzb containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[in] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseSbsrsm2_analysis "hipsparseXbsrsm2_analysis()" and * \ref hipsparseSbsrsm2_solve "hipsparseXbsrsm2_solve()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nrhs, \p nnzb, \p blockDim, * \p descrA, \p bsrSortedValA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, \p info or * \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, * \p transX == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level3_module * \brief Sparse triangular system solve using BSR storage format * * \details * \p hipsparseXbsrsm2_analysis performs the analysis step for \ref hipsparseSbsrsm2_solve * "hipsparseXbsrsm2_solve()". It is expected that this function will be executed only once * for a given matrix and particular operation type. * * \note * If the matrix sparsity pattern changes, the gathered information will become invalid. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transX matrix \f$X\f$ operation type. * @param[in] * mb number of block rows of the sparse BSR matrix \f$A\f$. * @param[in] * nrhs number of columns of the dense matrix \f$op(X)\f$. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix \f$A\f$. * @param[in] * descrA descriptor of the sparse BSR matrix \f$A\f$. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix \f$A\f$. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix \f$A\f$. * @param[in] * bsrSortedColIndA array of \p nnzb containing the block column indices of the sparse * BSR matrix \f$A\f$. * @param[in] * blockDim block dimension of the sparse BSR matrix \f$A\f$. * @param[out] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nrhs, \p nnzb or * \p blockDim, \p descrA, \p bsrSortedValA, \p bsrSortedRowPtrA, * \p bsrSortedColIndA, \p info or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, * \p transX == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level3_module * \brief Sparse triangular system solve using BSR storage format * * \details * \p hipsparseXbsrsm2_solve solves a sparse triangular linear system of a sparse * \f$m \times m\f$ matrix, defined in BSR storage format, a column-oriented dense solution matrix * \f$X\f$ and the column-oriented dense right-hand side matrix \f$B\f$ that is multiplied by \f$\alpha\f$, * such that * \f[ * op(A) \cdot op(X) = \alpha \cdot op(B), * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if transA == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * , * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if transX == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if transX == HIPSPARSE_OPERATION_TRANSPOSE} \\ * B^H, & \text{if transX == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * and * \f[ * op(X) = \left\{ * \begin{array}{ll} * X, & \text{if transX == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * X^T, & \text{if transX == HIPSPARSE_OPERATION_TRANSPOSE} \\ * X^H, & \text{if transX == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * and where \f$m = blockDim \times mb\f$. * * Note that as indicated above, the operation type of both \f$op(B)\f$ and \f$op(X)\f$ is specified by the * \p transX parameter and that the operation type of \f$B\f$ and \f$X\f$ must match. For example, if \f$op(B)=B\f$ then * \f$op(X)=X\f$. Likewise, if \f$op(B)=B^T\f$ then \f$op(X)=X^T\f$. * * Given that the sparse matrix \f$A\f$ is a square matrix, its size is \f$m \times m\f$ regardless of * whether \f$A\f$ is transposed or not. The size of the column-oriented dense matrices \f$B\f$ and \f$X\f$ have * size that depends on the value of \p transX: * * \f[ * op(B) = \left\{ * \begin{array}{ll} * ldb \times nrhs, \text{ } ldb \ge m, & \text{if transX == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * ldb \times m, \text{ } ldb \ge nrhs, & \text{if transX == HIPSPARSE_OPERATION_TRANSPOSE} \\ * ldb \times m, \text{ } ldb \ge nrhs, & \text{if transX == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * and * \f[ * op(X) = \left\{ * \begin{array}{ll} * ldb \times nrhs, \text{ } ldb \ge m, & \text{if transX == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * ldb \times m, \text{ } ldb \ge nrhs, & \text{if transX == HIPSPARSE_OPERATION_TRANSPOSE} \\ * ldb \times m, \text{ } ldb \ge nrhs, & \text{if transX == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * \p hipsparseXbsrsm2_solve requires a user allocated temporary buffer. Its size is returned by * \ref hipsparseSbsrsm2_bufferSize "hipsparseXbsrsm2_bufferSize()". The size of the required buffer is larger * when \p transA equals \ref HIPSPARSE_OPERATION_TRANSPOSE or \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE and * when \p transX is \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. The subsequent solve will also be faster when \f$A\f$ is * non-transposed and \f$B\f$ is transposed (or conjugate transposed). For example, instead of solving: * * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c} * a_{00} & a_{01} \\ * a_{10} & a_{11} * \end{array} & * \begin{array}{c c} * 0 & 0 \\ * 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c} * a_{20} & a_{21} \\ * a_{30} & a_{31} * \end{array} & * \begin{array}{c c} * a_{22} & a_{23} \\ * a_{32} & a_{33} * \end{array} \\ * \end{array} * \right] * \cdot * \begin{bmatrix} * x_{00} & x_{01} \\ * x_{10} & x_{11} \\ * x_{20} & x_{21} \\ * x_{30} & x_{31} \\ * \end{bmatrix} * = * \begin{bmatrix} * b_{00} & b_{01} \\ * b_{10} & b_{11} \\ * b_{20} & b_{21} \\ * b_{30} & b_{31} \\ * \end{bmatrix} * \f] * * Consider solving: * * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c} * a_{00} & a_{01} \\ * a_{10} & a_{11} * \end{array} & * \begin{array}{c c} * 0 & 0 \\ * 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c} * a_{20} & a_{21} \\ * a_{30} & a_{31} * \end{array} & * \begin{array}{c c} * a_{22} & a_{23} \\ * a_{32} & a_{33} * \end{array} \\ * \end{array} * \right] * \cdot * \begin{bmatrix} * x_{00} & x_{10} & x_{20} & x_{30} \\ * x_{01} & x_{11} & x_{21} & x_{31} * \end{bmatrix}^{T} * = * \begin{bmatrix} * b_{00} & b_{10} & b_{20} & b_{30} \\ * b_{01} & b_{11} & b_{21} & b_{31} * \end{bmatrix}^{T} * \f] * * Once the temporary storage buffer has been allocated, analysis meta data is required. It can be obtained * by hipsparseSbsrsm2_analysis "hipsparseXbsrsm2_analysis()". The triangular solve is completed by calling * \p hipsparseXbsrsm2_solve and once all solves are performed, the temporary storage buffer allocated by the * user can be freed. * * Solving a triangular system involves inverting the diagonal blocks. This means that if the sparse matrix is * missing the diagonal block (referred to as a structural zero) or the diagonal block is not invertible (referred * to as a numerical zero) then a solution is not possible. \p hipsparseXbsrsm2_solve tracks the location of the first * zero pivot (either numerical or structural zero). The zero pivot status can be checked calling \ref hipsparseXbsrsm2_zeroPivot(). * If \ref hipsparseXbsrsm2_zeroPivot() returns \ref HIPSPARSE_STATUS_SUCCESS, then no zero pivot was found and therefore * the matrix does not have a structural or numerical zero. * * The user can specify that the sparse matrix should be interpreted as having identity blocks on the diagonal by setting the diagonal * type on the descriptor \p descrA to \ref HIPSPARSE_DIAG_TYPE_UNIT using \ref hipsparseSetMatDiagType. If * \ref hipsparseDiagType_t == \ref HIPSPARSE_DIAG_TYPE_UNIT, no zero pivot will be reported, even if the diagonal block \f$A_{j,j}\f$ * for some \f$j\f$ is not invertible. * * The sparse CSR matrix passed to \p hipsparseXbsrsm2_solve does not actually have to be a triangular matrix. Instead the * triangular upper or lower part of the sparse matrix is solved based on \ref hipsparseFillMode_t set on the descriptor * \p descrA. If the fill mode is set to \ref HIPSPARSE_FILL_MODE_LOWER, then the lower triangular matrix is solved. If the * fill mode is set to \ref HIPSPARSE_FILL_MODE_UPPER then the upper triangular matrix is solved. * * \note * The sparse BSR matrix has to be sorted. * * \note * Operation type of B and X must match, if \f$op(B)=B, op(X)=X\f$. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA != \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE and * \p transX != \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transX matrix \f$X\f$ operation type. * @param[in] * mb number of block rows of the sparse BSR matrix \f$A\f$. * @param[in] * nrhs number of columns of the dense matrix \f$op(X)\f$. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix \f$A\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse BSR matrix \f$A\f$. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnzb containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * B rhs matrix B with leading dimension \p ldb. * @param[in] * ldb leading dimension of rhs matrix \f$B\f$. * @param[out] * X solution matrix X with leading dimension \p ldx. * @param[in] * ldx leading dimension of solution matrix \f$X\f$. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nrhs, \p nnzb, \p blockDim, * \p alpha, \p descrA, \p bsrSortedValA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, * \p B, \p X \p info or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, * \p transX == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_bsrsm.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const float* B, int ldb, float* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const double* B, int ldb, double* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipComplex* B, int ldb, hipComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipDoubleComplex* B, int ldb, hipDoubleComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSRSM_H */ ./library/include/internal/level3/hipsparse_gemmi.h0000664000175100017510000001700215176134511022531 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GEMMI_H #define HIPSPARSE_GEMMI_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level3_module * \brief Dense matrix sparse matrix multiplication using CSC storage format * * \details * \p hipsparseXgemmi multiplies the scalar \f$\alpha\f$ with a dense column-oriented \f$m \times k\f$ * matrix \f$A\f$ and the sparse \f$k \times n\f$ matrix \f$B\f$, defined in CSC * storage format and adds the result to the dense column-oriented \f$m \times n\f$ matrix \f$C\f$ that * is multiplied by the scalar \f$\beta\f$, such that * \f[ * C := \alpha \cdot A \cdot B + \beta \cdot C * \f] * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \f$A\f$. * @param[in] * n number of columns of the sparse CSC matrix \f$op(B)\f$ and \f$C\f$. * @param[in] * k number of columns of the dense matrix \f$A\f$. * @param[in] * nnz number of non-zero entries of the sparse CSC matrix \f$B\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * A array of dimension \f$lda \times k\f$ (\f$op(A) == A\f$) or * \f$lda \times m\f$ (\f$op(A) == A^T\f$ or \f$op(A) == A^H\f$). * @param[in] * lda leading dimension of \f$A\f$, must be at least \f$m\f$ * (\f$op(A) == A\f$) or \f$k\f$ (\f$op(A) == A^T\f$ or * \f$op(A) == A^H\f$). * @param[in] * cscValB array of \p nnz elements of the sparse CSC matrix \f$B\f$. * @param[in] * cscColPtrB array of \p n+1 elements that point to the start of every column of the * sparse CSC matrix \f$B\f$. * @param[in] * cscRowIndB array of \p nnz elements containing the column indices of the sparse CSC * matrix \f$B\f$. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * C array of dimension \f$ldc \times n\f$ that holds the values of \f$C\f$. * @param[in] * ldc leading dimension of \f$C\f$, must be at least \f$m\f$. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnz, * \p lda, \p ldc, \p alpha, \p A, \p cscValB, \p cscColPtrB, \p cscRowIndB, * \p beta or \p C is invalid. * * \par Example * \snippet example_hipsparse_gemmi.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const float* alpha, const float* A, int lda, const float* cscValB, const int* cscColPtrB, const int* cscRowIndB, const float* beta, float* C, int ldc); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const double* alpha, const double* A, int lda, const double* cscValB, const int* cscColPtrB, const int* cscRowIndB, const double* beta, double* C, int ldc); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipComplex* alpha, const hipComplex* A, int lda, const hipComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipComplex* beta, hipComplex* C, int ldc); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, const hipDoubleComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GEMMI_H */ ./library/include/internal/level3/hipsparse_csrsm.h0000664000175100017510000010211415176134511022561 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRSM_H #define HIPSPARSE_CSRSM_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level3_module * \details * \p hipsparseXcsrsm2_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during \ref hipsparseScsrsm2_analysis * "hipsparseXcsrsm2_analysis()" or \ref hipsparseScsrsm2_solve "hipsparseXcsrsm2_solve()" * computation. The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ is stored in \p position, * using same index base as the CSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note \p hipsparseXcsrsm2_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info or \p position is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrsm2_zeroPivot(hipsparseHandle_t handle, csrsm2Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level3_module * \details * \p hipsparseXcsrsm2_bufferSizeExt returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseScsrsm2_analysis "hipsparseXcsrsm2_analysis()" * and \ref hipsparseScsrsm2_solve "hipsparseXcsrsm2_solve()". The temporary storage buffer * must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * algo algorithm to use. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transB matrix \f$B\f$ operation type. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$. * @param[in] * nrhs number of columns of the dense matrix \f$op(B)\f$. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix \f$A\f$. * @param[in] * B array of \p m \f$\times\f$ \p nrhs elements of the rhs matrix \f$B\f$. * @param[in] * ldb leading dimension of rhs matrix \f$B\f$. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseScsrsm2_analysis "hipsparseXcsrsm2_analysis()" and * \ref hipsparseScsrsm2_solve "hipsparseXcsrsm2_solve()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nrhs, \p nnz, \p alpha, * \p descrA, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, \p B, * \p info or \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, * \p transB == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level3_module * \details * \p hipsparseXcsrsm2_analysis performs the analysis step for \ref hipsparseScsrsm2_solve * "hipsparseXcsrsm2_solve()". It is expected that this function will be executed only once * for a given matrix and particular operation type. * * \note * If the matrix sparsity pattern changes, the gathered information will become invalid. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * algo algorithm to use. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transB matrix \f$B\f$ operation type. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$. * @param[in] * nrhs number of columns of the dense matrix \f$op(B)\f$. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix \f$A\f$. * @param[in] * B array of \p m \f$\times\f$ \p nrhs elements of the rhs matrix \f$B\f$. * @param[in] * ldb leading dimension of rhs matrix \f$B\f$. * @param[out] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nrhs, \p nnz, \p alpha, * \p descrA, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, \p B, * \p info or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, * \p transB == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level3_module * \brief Sparse triangular system solve using CSR storage format * * \details * \p hipsparseXcsrsm2_solve solves a sparse triangular linear system of a sparse * \f$m \times m\f$ matrix, defined in CSR storage format, a column-oriented dense solution matrix * \f$X\f$ and the column-oriented dense right-hand side matrix \f$B\f$ that is multiplied by \f$\alpha\f$, such that * \f[ * op(A) \cdot op(X) = \alpha \cdot op(B), * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if transA == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * , * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if transB == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if transB == HIPSPARSE_OPERATION_TRANSPOSE} \\ * B^H, & \text{if transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * and * \f[ * op(X) = \left\{ * \begin{array}{ll} * X, & \text{if transB == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * X^T, & \text{if transB == HIPSPARSE_OPERATION_TRANSPOSE} \\ * X^H, & \text{if transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * The solution is performed inplace meaning that the matrix \f$B\f$ is overwritten with the solution * \f$X\f$ after calling \p hipsparseXcsrsm2_solve. Given that the sparse matrix \f$A\f$ is a square matrix, its * size is \f$m \times m\f$ regardless of whether \f$A\f$ is transposed or not. The size of the column-oriented dense * matrices \f$B\f$ and \f$X\f$ have size that depends on the value of \p transB: * * \f[ * op(B)/op(X) = \left\{ * \begin{array}{ll} * ldb \times nrhs, \text{ } ldb \ge m, & \text{if transB == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * ldb \times m, \text{ } ldb \ge nrhs, & \text{if transB == HIPSPARSE_OPERATION_TRANSPOSE} \\ * ldb \times m, \text{ } ldb \ge nrhs, & \text{if transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * \p hipsparseXcsrsm2_solve requires a user allocated temporary buffer. Its size is returned by * \ref hipsparseScsrsm2_bufferSizeExt "hipsparseXcsrsm2_bufferSizeExt()". The size of the required buffer is * larger when \p transA equals \ref HIPSPARSE_OPERATION_TRANSPOSE or \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE * and when \p transB is \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. The subsequent solve will also be faster when \f$A\f$ * is non-transposed and \f$B\f$ is transposed (or conjugate transposed). For example, instead of solving: * * \f[ * \begin{bmatrix} * a_{00} & 0 & 0 \\ * a_{10} & a_{11} & 0 \\ * a_{20} & a_{21} & a_{22} \\ * \end{bmatrix} * \cdot * \begin{bmatrix} * x_{00} & x_{01} \\ * x_{10} & x_{11} \\ * x_{20} & x_{21} \\ * \end{bmatrix} * = * \begin{bmatrix} * b_{00} & b_{01} \\ * b_{10} & b_{11} \\ * b_{20} & b_{21} \\ * \end{bmatrix} * \f] * * Consider solving: * * \f[ * \begin{bmatrix} * a_{00} & 0 & 0 \\ * a_{10} & a_{11} & 0 \\ * a_{20} & a_{21} & a_{22} * \end{bmatrix} * \cdot * \begin{bmatrix} * x_{00} & x_{10} & x_{20} \\ * x_{01} & x_{11} & x_{21} * \end{bmatrix}^{T} * = * \begin{bmatrix} * b_{00} & b_{10} & b_{20} \\ * b_{01} & b_{11} & b_{21} * \end{bmatrix}^{T} * \f] * * Once the temporary storage buffer has been allocated, analysis meta data is required. It can be obtained by * \ref hipsparseScsrsm2_analysis "hipsparseXcsrsm2_analysis()". The triangular solve is completed by calling * \p hipsparseXcsrsm2_solve and once all solves are performed, the temporary storage buffer allocated by the * user can be freed. * * Solving a triangular system involves division by the diagonal elements. This means that if the sparse matrix is * missing the diagonal entry (referred to as a structural zero) or the diagonal entry is zero (referred to as a numerical zero) * then a division by zero would occur. \p hipsparseXcsrsm2_solve tracks the location of the first zero pivot (either numerical * or structural zero). The zero pivot status can be checked calling \ref hipsparseXcsrsm2_zeroPivot(). If * \ref hipsparseXcsrsm2_zeroPivot() returns \ref HIPSPARSE_STATUS_SUCCESS, then no zero pivot was found and therefore * the matrix does not have a structural or numerical zero. * * The user can specify that the sparse matrix should be interpreted as having ones on the diagonal by setting the diagonal type * on the descriptor \p descrA to \ref HIPSPARSE_DIAG_TYPE_UNIT using \ref hipsparseSetMatDiagType. If * \ref hipsparseDiagType_t == \ref HIPSPARSE_DIAG_TYPE_UNIT, no zero pivot will be reported, even if \f$A_{j,j} = 0\f$ for * some \f$j\f$. * * The sparse CSR matrix passed to \p hipsparseXcsrsm2_solve does not actually have to be a triangular matrix. Instead the * triangular upper or lower part of the sparse matrix is solved based on \ref hipsparseFillMode_t set on the descriptor * \p descrA. If the fill mode is set to \ref HIPSPARSE_FILL_MODE_LOWER, then the lower triangular matrix is solved. If the * fill mode is set to \ref HIPSPARSE_FILL_MODE_UPPER then the upper triangular matrix is solved. * * \note * The sparse CSR matrix has to be sorted. This can be achieved by calling * hipsparseXcsrsort(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA != \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE and * \p transB != \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * algo algorithm to use. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transB matrix \f$B\f$ operation type. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$. * @param[in] * nrhs number of columns of the dense matrix \f$op(B)\f$. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix \f$A\f$. * @param[inout] * B array of \p m \f$\times\f$ \p nrhs elements of the rhs matrix \f$B\f$. * @param[in] * ldb leading dimension of rhs matrix \f$B\f$. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nrhs, \p nnz, \p alpha, * \p descrA, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, \p B, * \p info or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, * \p transB == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrsm2.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRSM_H */ ./library/include/internal/conversion/0000775000175100017510000000000015176134511020177 5ustar jenkinsjenkins./library/include/internal/conversion/hipsparse_csr2bsr.h0000664000175100017510000003425715176134511024021 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2BSR_H #define HIPSPARSE_CSR2BSR_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief * This function computes the number of nonzero block columns per row and the total number of nonzero blocks in a sparse * BSR matrix given a sparse CSR matrix as input. * * \details * Consider the matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 \\ * 1 & 2 & 3 & 4 * \end{bmatrix} * \f] * * stored as a sparse CSR matrix. This function computes both the BSR row pointer array as well as the total number * of non-zero blocks that results when converting the CSR matrix to the BSR format. Assuming a block dimension of 2, * the above matrix once converted to BSR format looks like: * * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c} * 1 & 0 \\ * 3 & 4 * \end{array} & * \begin{array}{c c} * 0 & 2 \\ * 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c} * 5 & 0 \\ * 1 & 2 * \end{array} & * \begin{array}{c c} * 6 & 7 \\ * 3 & 4 * \end{array} \\ * \end{array} * \right] * \f] * * and the resulting BSR row pointer array and total non-zero blocks once \p hipsparseXcsr2bsrNnz has been called: * * \f[ * \begin{align} * \text{bsrRowPtrC} &= \begin{bmatrix} 0 & 2 & 4 \end{bmatrix} \\ * \text{bsrNnzb} &= 4 * \end{align} * \f] * * In general, when converting a CSR matrix of size \p m x \p n to a BSR matrix, the resulting BSR matrix will have size * \p mb x \p nb where \p mb and \p nb equal: * * \f[ * \begin{align} * \text{mb} &= \text{(m - 1) / blockDim + 1} \\ * \text{nb} &= \text{(n - 1) / blockDim + 1} * \end{align} * \f] * * In particular, it may be the case that \p blockDim does not divide evenly into \p m and/or \p n. In these cases, the * CSR matrix is expanded in size in order to fit full BSR blocks. For example, using the original CSR matrix and block * dimension 3 instead of 2, the function \p hipsparseXcsr2bsrNnz computes the BSR row pointer array and total number of * non-zero blocks for the BSR matrix: * * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c c} * 1 & 0 & 0 \\ * 3 & 4 & 0 \\ * 5 & 0 & 6 * \end{array} & * \begin{array}{c c c} * 2 & 0 & 0 \\ * 0 & 0 & 0 \\ * 7 & 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c c} * 1 & 2 & 3 \\ * 0 & 0 & 0 \\ * 0 & 0 & 0 * \end{array} & * \begin{array}{c c c} * 4 & 0 & 0 \\ * 0 & 0 & 0 \\ * 0 & 0 & 0 * \end{array} \\ * \end{array} * \right] * \f] * * See hipsparseScsr2bsr() for full code example. * * \note * The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA direction that specified whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW or by * \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrRowPtrA integer array containing \p m+1 elements that point to the start of each row of the CSR matrix * @param[in] * csrColIndA integer array of the column indices for each non-zero element in the CSR matrix * @param[in] * blockDim the block dimension of the BSR matrix. Between \f$1\f$ and \f$\min(m, n)\f$ * @param[in] * descrC descriptor of the sparse BSR matrix. Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * bsrRowPtrC integer array containing \p mb+1 elements that point to the start of each block row of the BSR matrix * @param[out] * bsrNnzb total number of nonzero elements in device or host memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p blockDim, \p csrRowPtrA, \p csrColIndA, * \p bsrRowPtrC or \p bsrNnzb pointer is invalid. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, int* bsrRowPtrC, int* bsrNnzb); /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a sparse BSR matrix * * \details * \p hipsparseXcsr2bsr completes the conversion of a CSR matrix into a BSR matrix. * It is assumed, that \p bsrValC, \p bsrColIndC and \p bsrRowPtrC are allocated. The * allocation size for \p bsrRowPtr is computed as \p mb+1 where \p mb is the number of * block rows in the BSR matrix defined as: * * \f[ * \begin{align} * \text{mb} &= \text{(m - 1) / blockDim + 1} * \end{align} * \f] * * The allocation size for \p bsrColIndC, i.e. \p bsrNnzb, is computed using * \ref hipsparseXcsr2bsrNnz() which also fills the \p bsrRowPtrC array. The allocation size * for \p bsrValC is then equal to: * * \f[ * \text{bsrNnzb * blockDim * blockDim} * \f] * * For example, given the CSR matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 \\ * 1 & 2 & 3 & 4 * \end{bmatrix} * \f] * * The resulting BSR matrix using block dimension 2 would look like: * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c} * 1 & 0 \\ * 3 & 4 * \end{array} & * \begin{array}{c c} * 0 & 2 \\ * 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c} * 5 & 0 \\ * 1 & 2 * \end{array} & * \begin{array}{c c} * 6 & 7 \\ * 3 & 4 * \end{array} \\ * \end{array} * \right] * \f] * * The call to \ref hipsparseXcsr2bsrNnz results in the BSR row pointer array: * \f[ * \begin{align} * \text{bsrRowPtrC} &= \begin{bmatrix} 0 & 2 & 4 \end{bmatrix} \\ * \end{align} * \f] * * and the call to \p hipsparseXcsr2bsr completes the conversion resulting in the BSR column indices and values arrays: * \f[ * \begin{align} * \text{bsrColIndC} &= \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} \\ * \text{bsrValC} &= \begin{bmatrix} 1 & 0 & 3 & 4 & 0 & 2 & 0 & 0 & 5 & 0 & 1 & 2 & 6 & 7 & 3 & 4 \end{bmatrix} \\ * \end{align} * \f] * * The \p dirA parameter determines the order of the BSR block values. The example above uses row order. Using column ordering * would result instead in the BSR values array: * * \f[ * \text{bsrValC} &= \begin{bmatrix} 1 & 3 & 0 & 4 & 0 & 0 & 2 & 0 & 5 & 1 & 0 & 2 & 6 & 3 & 7 & 4 \end{bmatrix} \\ * \f] * * \note * \p hipsparseXcsr2bsr requires extra temporary storage that is allocated internally if * \p blockDim>16 * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA the storage format of the blocks, \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnz elements containing the values of the sparse CSR matrix. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrColIndA array of \p nnz elements containing the column indices of the sparse CSR matrix. * @param[in] * blockDim size of the blocks in the sparse BSR matrix. * @param[in] * descrC descriptor of the sparse BSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * bsrValC array of \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[out] * bsrRowPtrC array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[out] * bsrColIndC array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p blockDim, \p bsrValC, \p bsrRowPtrC, * \p bsrColIndC, \p csrValA, \p csrRowPtrA or \p csrColIndA pointer is invalid. * * \par Example * \snippet example_hipsparse_csr2bsr.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2BSR_H */ ./library/include/internal/conversion/hipsparse_csru2csr.h0000664000175100017510000002005515176134511024176 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRU2CSR_H #define HIPSPARSE_CSRU2CSR_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * This function calculates the amount of temporary storage in bytes required for * hipsparseXcsru2csr() and hipsparseXcsr2csru(). */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * This function converts unsorted CSR format to sorted CSR format. The required * temporary storage has to be allocated by the user. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRU2CSR_H */ ./library/include/internal/conversion/hipsparse_gebsr2gebsr.h0000664000175100017510000005773515176134511024656 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GEBSR2GEBSR_H #define HIPSPARSE_GEBSR2GEBSR_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief * This function computes the the size of the user allocated temporary storage buffer used when converting a sparse * GEBSR matrix to another sparse GEBSR matrix. * * \details * \p hipsparseXgebsr2gebsr_bufferSize returns the size of the temporary storage buffer that is required by * \ref hipsparseXgebsr2gebsrNnz() and \ref hipsparseSgebsr2gebsr "hipsparseXgebsr2gebsr()". The temporary storage * buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA the storage format of the blocks, \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN * @param[in] * mb number of block rows of the general BSR sparse matrix \f$A\f$. * @param[in] * nb number of block columns of the general BSR sparse matrix \f$A\f$. * @param[in] * nnzb number of blocks in the general BSR sparse matrix \f$A\f$. * @param[in] * descrA the descriptor of the general BSR sparse matrix \f$A\f$, the supported matrix type is * \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also any valid value of the \ref hipsparseIndexBase_t. * @param[in] * bsrValA array of \p nnzb*rowBlockDimA*colBlockDimA containing the values of the sparse general BSR matrix \f$A\f$. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse general BSR matrix \f$A\f$. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse general BSR matrix \f$A\f$. * @param[in] * rowBlockDimA row size of the blocks in the sparse general BSR matrix \f$A\f$. * @param[in] * colBlockDimA column size of the blocks in the sparse general BSR matrix \f$A\f$. * @param[in] * rowBlockDimC row size of the blocks in the sparse general BSR matrix \f$C\f$. * @param[in] * colBlockDimC column size of the blocks in the sparse general BSR matrix \f$C\f$. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by hipsparseXgebsr2gebsrNnz(), * hipsparseSgebsr2gebsr(), hipsparseDgebsr2gebsr(), hipsparseCgebsr2gebsr(), and * hipsparseZgebsr2gebsr(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p nnzb, \p rowBlockDimA, \p colBlockDimA, * \p rowBlockDimC, \p colBlockDimC, \p bsrRowPtrA, \p bsrColIndA, \p descrA or \p pBufferSizeInBytes pointer * is invalid. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes); /**@}*/ /*! \ingroup conv_module * \brief This function is used when converting a GEBSR sparse matrix \f$A\f$ to another GEBSR sparse matrix \f$C\f$. * Specifically, this function determines the number of non-zero blocks that will exist in \f$C\f$ (stored using either a host * or device pointer), and computes the row pointer array for \f$C\f$. * * \details * The routine does support asynchronous execution. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA the storage format of the blocks, \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN * @param[in] * mb number of block rows of the general BSR sparse matrix \f$A\f$. * @param[in] * nb number of block columns of the general BSR sparse matrix \f$A\f$. * @param[in] * nnzb number of blocks in the general BSR sparse matrix \f$A\f$. * @param[in] * descrA the descriptor of the general BSR sparse matrix \f$A\f$, the supported matrix type is * \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also any valid value of the \ref hipsparseIndexBase_t. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse general BSR matrix \f$A\f$. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse general BSR matrix \p A. * @param[in] * rowBlockDimA row size of the blocks in the sparse general BSR matrix \f$A\f$. * @param[in] * colBlockDimA column size of the blocks in the sparse general BSR matrix \f$A\f$. * @param[in] * descrC the descriptor of the general BSR sparse matrix \f$C\f$, the supported matrix type is * \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also any valid value of the \ref hipsparseIndexBase_t. * @param[in] * bsrRowPtrC array of \p mbC+1 elements that point to the start of every block row of the * sparse general BSR matrix \f$C\f$ where \p mbC = ( \p m+rowBlockDimC-1 ) / \p rowBlockDimC. * @param[in] * rowBlockDimC row size of the blocks in the sparse general BSR matrix \f$C\f$. * @param[in] * colBlockDimC column size of the blocks in the sparse general BSR matrix \f$C\f$. * @param[out] * nnzTotalDevHostPtr total number of nonzero blocks in general BSR sparse matrix \f$C\f$ stored using device or host memory. * @param[out] * buffer buffer allocated by the user whose size is determined by calling \ref hipsparseSgebsr2gebsr_bufferSize * "hipsparseXgebsr2gebsr_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p nnzb, \p rowBlockDimA, \p colBlockDimA, \p rowBlockDimC, * \p colBlockDimC, \p bsrRowPtrA, \p bsrColIndA, \p bsrRowPtrC, \p descrA, \p descrC, \p buffer pointer is invalid. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXgebsr2gebsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, int* bsrRowPtrC, int rowBlockDimC, int colBlockDimC, int* nnzTotalDevHostPtr, void* buffer); /*! \ingroup conv_module * \brief * This function converts the GEBSR sparse matrix \f$A\f$ to another GEBSR sparse matrix \f$C\f$. * * \details * The conversion uses three steps. First, the user calls \ref hipsparseSgebsr2gebsr_bufferSize * "hipsparseXgebsr2gebsr_bufferSize()" to determine the size of the required temporary storage buffer. * The user then allocates this buffer. Secondly, the user then allocates \p mbC+1 integers for the row * pointer array for \f$C\f$ where: * \f[ * \begin{align} * \text{mbC} &= \text{(m - 1) / rowBlockDimC + 1} \\ * \text{nbC} &= \text{(n - 1) / colBlockDimC + 1} * \end{align} * \f] * The user then calls hipsparseXgebsr2gebsrNnz() to fill in the row pointer array for \f$C\f$ ( \p bsrRowPtrC ) and * determine the number of non-zero blocks that will exist in \f$C\f$. Finally, the user allocates space for the column * indices array of \f$C\f$ to have \p nnzbC elements and space for the values array of \f$C\f$ to have * \p nnzbC*rowBlockDimC*colBlockDimC and then calls \p hipsparseXgebsr2gebsr to complete the conversion. * * It may be the case that \p rowBlockDimC does not divide evenly into \p m and/or \p colBlockDim does not divide evenly * into \p n. In these cases, the GEBSR matrix is expanded in size in order to fit full GEBSR blocks. For example, if * the original GEBSR matrix A (using \p rowBlockDimA=2, \p colBlockDimA=3) looks like: * * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c c} * 1 & 0 & 0 \\ * 3 & 4 & 0 * \end{array} & * \begin{array}{c c c} * 2 & 0 & 0 \\ * 4 & 5 & 6 * \end{array} \\ * \hline * \begin{array}{c c c} * 1 & 2 & 3 \\ * 1 & 2 & 0 * \end{array} & * \begin{array}{c c c} * 4 & 0 & 0 \\ * 3 & 0 & 1 * \end{array} \\ * \end{array} * \right] * \f] * * then if we specify \p rowBlockDimC=3 and \p colBlockDimC=2, our output GEBSR matrix C would be: * * \f[ * \left[ * \begin{array}{c | c | c} * \begin{array}{c c} * 1 & 0 \\ * 3 & 4 \\ * 1 & 2 * \end{array} & * \begin{array}{c c} * 0 & 2 \\ * 0 & 4 \\ * 3 & 4 * \end{array} & * \begin{array}{c c} * 0 & 0 \\ * 5 & 6 \\ * 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c} * 1 & 2 \\ * 0 & 0 \\ * 0 & 0 * \end{array} & * \begin{array}{c c} * 0 & 3 \\ * 0 & 0 \\ * 0 & 0 * \end{array} & * \begin{array}{c c} * 0 & 1 \\ * 0 & 0 \\ * 0 & 0 * \end{array} \\ * \end{array} * \right] * \f] * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA the storage format of the blocks, \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN * @param[in] * mb number of block rows of the general BSR sparse matrix \f$A\f$. * @param[in] * nb number of block columns of the general BSR sparse matrix \f$A\f$. * @param[in] * nnzb number of blocks in the general BSR sparse matrix \f$A\f$. * @param[in] * descrA the descriptor of the general BSR sparse matrix \f$A\f$, the supported matrix type is * \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also any valid value of the \ref hipsparseIndexBase_t. * @param[in] * bsrValA array of \p nnzb*rowBlockDimA*colBlockDimA containing the values of the sparse general BSR matrix \f$A\f$. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse general BSR matrix \f$A\f$. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse general BSR matrix \f$A\f$. * @param[in] * rowBlockDimA row size of the blocks in the sparse general BSR matrix \f$A\f$. * @param[in] * colBlockDimA column size of the blocks in the sparse general BSR matrix \f$A\f$. * @param[in] * descrC the descriptor of the general BSR sparse matrix \f$C\f$, the supported matrix type is * \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also any valid value of the \ref hipsparseIndexBase_t. * @param[in] * bsrValC array of \p nnzbC*rowBlockDimC*colBlockDimC containing the values of the sparse general BSR matrix \f$C\f$. * @param[in] * bsrRowPtrC array of \p mbC+1 elements that point to the start of every block row of the * sparse general BSR matrix \f$C\f$. * @param[in] * bsrColIndC array of \p nnzbC elements containing the block column indices of the sparse general BSR matrix \f$C\f$. * @param[in] * rowBlockDimC row size of the blocks in the sparse general BSR matrix \f$C\f$. * @param[in] * colBlockDimC column size of the blocks in the sparse general BSR matrix \f$C\f$. * @param[out] * buffer buffer allocated by the user whose size is determined by calling \ref hipsparseSgebsr2gebsr_bufferSize * "hipsparseXgebsr2gebsr_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p nnzb, \p rowBlockDimA, \p colBlockDimA, * \p rowBlockDimC, \p colBlockDimC, \p bsrRowPtrA, \p bsrColIndA, \p bsrValA, \p bsrRowPtrC, \p bsrColIndC, * \p bsrValC, \p descrA, \p descrC or \p buffer pointer is invalid. * * \par Example * \snippet example_hipsparse_gebsr2gebsr.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GEBSR2GEBSR_H */ ./library/include/internal/conversion/hipsparse_csr2coo.h0000664000175100017510000000727715176134511024015 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2COO_H #define HIPSPARSE_CSR2COO_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a sparse COO matrix * * \details * \p hipsparseXcsr2coo converts the CSR array containing the row offsets, that point * to the start of every row, into a COO array of row indices. All arrays are assumed * to be allocated by the user prior to calling \p hipsparseXcsr2coo. * * For example, given the CSR row pointer array (assuming zero index base): * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 1 & 3 & 4 \end{bmatrix} * \end{align} * \f] * * Calling \p hipsparseXcsr2coo() results in the COO row indices array: * \f[ * \begin{align} * \text{cooRowInd} &= \begin{bmatrix} 0 & 1 & 1 & 2 \end{bmatrix} * \end{align} * \f] * * \note * It can also be used to convert a CSC array containing the column offsets into a COO * array of column indices. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * csrRowPtr array of \p m+1 elements that point to the start of every row * of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * m number of rows of the sparse CSR matrix. * @param[out] * cooRowInd array of \p nnz elements containing the row indices of the sparse COO * matrix. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p csrRowPtr or \p cooRowInd * pointer is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsr2coo(hipsparseHandle_t handle, const int* csrRowPtr, int nnz, int m, int* cooRowInd, hipsparseIndexBase_t idxBase); #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2COO_H */ ./library/include/internal/conversion/hipsparse_create_identity_permutation.h0000664000175100017510000000517015176134511030234 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CREATE_IDENTITY_PERMUTATION_H #define HIPSPARSE_CREATE_IDENTITY_PERMUTATION_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Create the identity map * * \details * \p hipsparseCreateIdentityPermutation stores the identity map in \p p, such that * \f$p = 0:1:(n-1)\f$. * * \code{.c} * for(i = 0; i < n; ++i) * { * p[i] = i; * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * n size of the map \p p. * @param[out] * p array of \p n integers containing the map. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p n or \p p pointer is invalid. * * \par Example * \snippet example_hipsparse_create_identity_permutation.cpp doc example */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateIdentityPermutation(hipsparseHandle_t handle, int n, int* p); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CREATE_IDENTITY_PERMUTATION_H */ ./library/include/internal/conversion/hipsparse_dense2csr.h0000664000175100017510000001610615176134511024322 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_DENSE2CSR_H #define HIPSPARSE_DENSE2CSR_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup conv_module * \brief * \p hipsparseXdense2csr converts the matrix A in dense format into a sparse matrix in CSR format. * * \details * Given a dense, column ordered, matrix \p A with leading dimension \p ld where \p ld>=m, * \p hipsparseXdense2csr converts the matrix to a sparse CSR format matrix. All the parameters * are assumed to have been pre-allocated by the user and the arrays are filled in based on number * of nonzeros per row, which can be pre-computed with \ref hipsparseSnnz "hipsparseXnnz()". The * desired index base in the output CSR matrix is set in the \ref hipsparseMatDescr_t. See * \ref hipsparseSetMatIndexBase(). * * As an example, if using index base zero (i.e. the default) and the dense * matrix: * * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 * \end{bmatrix} * \f] * * The conversion results in the CSR arrays: * * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 2 & 4 & 7 \end{bmatrix} \\ * \text{csrColInd} &= \begin{bmatrix} 0 & 3 & 0 & 1 & 0 & 2 & 3 \end{bmatrix} \\ * \text{csrVal} &= \begin{bmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 \end{bmatrix} \\ * \end{align} * \f] * * \note * It is executed asynchronously with respect to the host and may return control to the * application on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also * any valid value of the \ref hipsparseIndexBase_t. * @param[in] * A array of dimensions (\p ld, \p n) * @param[in] * ld leading dimension of dense array \p A. * @param[in] * nnzPerRow array of size \p n containing the number of non-zero elements per row. * @param[out] * csrVal array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) nonzero elements of matrix \p A. * @param[out] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[out] * csrColInd integer array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) column indices of the non-zero elements of matrix \p A. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ld, \p A, \p nnzPerRow, \p csrVal \p csrRowPtr or \p csrColInd * pointer is invalid. * * \par Example * \snippet example_hipsparse_dense2csr.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerRow, float* csrVal, int* csrRowPtr, int* csrColInd); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerRow, double* csrVal, int* csrRowPtr, int* csrColInd); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerRow, hipComplex* csrVal, int* csrRowPtr, int* csrColInd); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerRow, hipDoubleComplex* csrVal, int* csrRowPtr, int* csrColInd); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_DENSE2CSR_H */ ./library/include/internal/conversion/hipsparse_prune_dense2csr.h0000664000175100017510000004646615176134511025547 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_PRUNE_DENSE2CSR_H #define HIPSPARSE_PRUNE_DENSE2CSR_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * \p hipsparseXpruneDense2csr_bufferSize computes the the size of the user allocated temporary storage buffer * used when converting a dense matrix to a pruned CSR matrix. * * \details * Specifically given an input dense column ordered matrix A, with leading dimension \p lda where \p lda>=m, * the resulting pruned sparse CSR matrix C is computed using: * \f[ * |C(i,j)| = A(i, j) \text{ if |A(i, j)| > threshold} * \f] * * The first step in this conversion is to determine the required user allocated buffer size * using \p hipsparseXpruneDense2csr_bufferSize() that will be passed to the subsequent steps of the conversion. * Once the buffer size has been determined the user must allocate it. This user allocated buffer is then passed * to \ref hipsparseSpruneDense2csrNnz "hipsparseXpruneDense2csrNnz()" and \ref hipsparseSpruneDense2csr * "hipsparseXpruneDense2csr()" to complete the conversion. The user is responsible to then free the buffer once * the conversion has been completed. * * See hipsparseSpruneDense2csr() for a full code example. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[in] * threshold pointer to the pruning non-negative threshold which can exist in either host or device memory. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL * and also any valid value of the \ref hipsparseIndexBase_t. * @param[in] * csrVal array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) nonzero elements of matrix \p A. * @param[in] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[in] * csrColInd integer array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) column indices of the non-zero elements of matrix \p A. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSpruneDense2csrNnz(), hipsparseDpruneDense2csrNnz(), * hipsparseSpruneDense2csr() and hipsparseDpruneDense2csr(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * \p hipsparseXpruneDense2csrNnz function computes the number of nonzero elements per row and the total * number of nonzero elements in a dense matrix once the elements less than the (non-negative) threshold are * pruned from the matrix. * * \details * Specifically given an input dense column ordered matrix A, with leading dimension \p lda where \p lda>=m, * the resulting pruned sparse CSR matrix C is computed using: * \f[ * |C(i,j)| = A(i, j) \text{ if |A(i, j)| > threshold} * \f] * * First the user must determine the size of the required temporary buffer using the routine * \ref hipsparseSpruneDense2csr_bufferSize "hipsparseXpruneDense2csr_bufferSize()" and then allocate it. Next * the user allocates \p csrRowPtr with size \p m+1. Then the passes both the temporary storage buffer as well * as \p csrRowPtr to \p hipsparseXpruneDense2csrNnz in order to determine the total number of non-zeros that * will exist in the sparse CSR matrix C (after pruning has been performed on A) as well as fill the output CSR * row pointer array \p csrRowPtr. * * For example, given the dense matrix: * * \f[ * \begin{bmatrix} * 6 & 2 & 3 & 7 \\ * 5 & 6 & 7 & 8 \\ * 5 & 4 & 8 & 1 * \end{bmatrix} * \f] * * and the \p threshold value 5, the resulting matrix after pruning is: * * \f[ * \begin{bmatrix} * 6 & 0 & 0 & 7 \\ * 0 & 6 & 7 & 8 \\ * 0 & 0 & 8 & 0 * \end{bmatrix} * \f] * * and corresponding row pointer array and non-zero count: * * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 2 & 5 & 6 \end{bmatrix} \\ * \text{nnzTotalDevHostPtr} &= 6 * \end{align} * \f] * * The above example assumes a zero index base for the output CSR matrix. We can set the desired index base * in the output CSR matrix by setting it in the \ref hipsparseMatDescr_t. See \ref hipsparseSetMatIndexBase(). * * For a full code example on how to use this routine, see hipsparseSpruneDense2csr(). * * \note * The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[in] * threshold pointer to the pruning non-negative threshold which can exist in either host or device memory. * @param[in] * descr the descriptor of the dense matrix \p A. * @param[out] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[out] * nnzTotalDevHostPtr total number of nonzero elements in device or host memory. * @param[out] * buffer buffer allocated by the user whose size is determined by calling * \ref hipsparseSpruneDense2csr_bufferSize "hipsparseXpruneDense2csr_bufferSize()" or * \ref hipsparseSpruneDense2csr_bufferSizeExt "hipsparseXpruneDense2csr_bufferSizeExt()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p lda, \p A, \p threshold, \p descr, \p csrRowPtr * \p nnzTotalDevHostPtr or \p buffer pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * \p hipsparseXpruneDense2csr converts the matrix A in dense format into a sparse matrix in CSR format * while pruning values that are less than the (non-negative) threshold. All the parameters are assumed * to have been pre-allocated by the user. * * \details * Specifically given an input dense column ordered matrix A, with leading dimension \p lda where \p lda>=m, * the resulting pruned sparse CSR matrix C is computed using: * \f[ * |C(i,j)| = A(i, j) \text{ if |A(i, j)| > threshold} * \f] * * The user first calls \ref hipsparseSpruneDense2csr_bufferSize "hipsparseXpruneDense2csr_bufferSize()" to * determine the size of the required user allocate temporary storage buffer. The user then allocates this * buffer. Next, the user allocates \p csrRowPtr to have \p m+1 elements and then calls * \ref hipsparseSpruneDense2csrNnz "hipsparseXpruneDense2csrNnz()" which fills in the \p csrRowPtr array * and stores the number of elements that are larger than the pruning \p threshold in \p nnzTotalDevHostPtr. * The user then allocates \p csrColInd and \p csrVal to have size \p nnzTotalDevHostPtr and completes the * conversion by calling \p hipsparseXpruneDense2csr(). * * For example, performing these steps with the dense input matrix A: * \f[ * \begin{bmatrix} * 6 & 2 & 3 & 7 \\ * 5 & 6 & 7 & 8 \\ * 5 & 4 & 8 & 1 * \end{bmatrix} * \f] * * and the \p threshold value 5, results in the pruned matrix C: * * \f[ * \begin{bmatrix} * 6 & 0 & 0 & 7 \\ * 0 & 6 & 7 & 8 \\ * 0 & 0 & 8 & 0 * \end{bmatrix} * \f] * * and corresponding CSR row, column, and values arrays: * * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 2 & 5 & 6 \end{bmatrix} \\ * \text{csrColInd} &= \begin{bmatrix} 0 & 3 & 1 & 2 & 3 & 2 \end{bmatrix} \\ * \text{csrVal} &= \begin{bmatrix} 6 & 7 & 6 & 7 & 8 & 8 \end{bmatrix} \\ * \end{align} * \f] * * \note * The routine \p hipsparseXpruneDense2csr() is executed asynchronously with respect to the host and may * return control to the application on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[in] * threshold pointer to the non-negative pruning threshold which can exist in either host or device memory. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL * and also any valid value of the \ref hipsparseIndexBase_t. * @param[out] * csrVal array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) nonzero elements of matrix \p A. * @param[in] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[out] * csrColInd integer array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) column indices of the non-zero elements of matrix \p A. * * @param[in] * buffer temporary storage buffer allocated by the user, size is returned by * \ref hipsparseSpruneDense2csr_bufferSize "hipsparseXpruneDense2csr_bufferSize()" or * \ref hipsparseSpruneDense2csr_bufferSizeExt "hipsparseXpruneDense2csr_bufferSizeExt()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p lda, \p A, \p descr, \p threshold, \p csrVal * \p csrRowPtr, \p csrColInd, \p buffer pointer is invalid. * * \par Example * \snippet example_hipsparse_prune_dense2csr.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csr(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csr(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_PRUNE_DENSE2CSR_H */ ./library/include/internal/conversion/hipsparse_coosort.h0000664000175100017510000002130715176134511024121 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_COOSORT_H #define HIPSPARSE_COOSORT_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Sort a sparse COO matrix * * \details * \p hipsparseXcoosort_bufferSizeExt returns the size of the temporary storage buffer * in bytes required by \ref hipsparseXcoosortByRow() and \ref hipsparseXcoosortByColumn(). * The temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse COO matrix. * @param[in] * n number of columns of the sparse COO matrix. * @param[in] * nnz number of non-zero entries of the sparse COO matrix. * @param[in] * cooRows array of \p nnz elements containing the row indices of the sparse * COO matrix. * @param[in] * cooCols array of \p nnz elements containing the column indices of the sparse * COO matrix. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseXcoosortByRow() and hipsparseXcoosortByColumn(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p cooRows, * \p cooCols or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcoosort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* cooRows, const int* cooCols, size_t* pBufferSizeInBytes); /*! \ingroup conv_module * \brief Sort a sparse COO matrix by row * * \details * \p hipsparseXcoosortByRow sorts a matrix in COO format by row. The sorted * permutation vector \p P can be used to obtain sorted \p cooVal array. In this * case, \p P must be initialized as the identity permutation, see * \ref hipsparseCreateIdentityPermutation(). To apply the permutation vector to the COO * values, see hipsparse \ref hipsparseSgthr "hipsparseXgthr()". * * \p hipsparseXcoosortByRow requires extra temporary storage buffer that has to be * allocated by the user. Storage buffer size can be determined by * \ref hipsparseXcoosort_bufferSizeExt(). * * \note * \p P can be \p NULL if a sorted permutation vector is not required. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse COO matrix. * @param[in] * n number of columns of the sparse COO matrix. * @param[in] * nnz number of non-zero entries of the sparse COO matrix. * @param[inout] * cooRows array of \p nnz elements containing the row indices of the sparse * COO matrix. * @param[inout] * cooCols array of \p nnz elements containing the column indices of the sparse * COO matrix. * @param[inout] * P array of \p nnz integers containing the unsorted map indices, can be * \p NULL. * @param[in] * pBuffer temporary storage buffer allocated by the user, size is returned by * \ref hipsparseXcoosort_bufferSizeExt(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p cooRows, * \p cooCols or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_coosort_by_row.cpp doc example */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcoosortByRow(hipsparseHandle_t handle, int m, int n, int nnz, int* cooRows, int* cooCols, int* P, void* pBuffer); /*! \ingroup conv_module * \brief Sort a sparse COO matrix by column * * \details * \p hipsparseXcoosortByColumn sorts a matrix in COO format by column. The sorted * permutation vector \p P can be used to obtain sorted \p cooVal array. In this * case, \p P must be initialized as the identity permutation, see * \ref hipsparseCreateIdentityPermutation(). To apply the permutation vector to the COO * values, see hipsparse \ref hipsparseSgthr "hipsparseXgthr()". * * \p hipsparseXcoosortByColumn requires extra temporary storage buffer that has to be * allocated by the user. Storage buffer size can be determined by * \ref hipsparseXcoosort_bufferSizeExt(). * * \note * \p P can be \p NULL if a sorted permutation vector is not required. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse COO matrix. * @param[in] * n number of columns of the sparse COO matrix. * @param[in] * nnz number of non-zero entries of the sparse COO matrix. * @param[inout] * cooRows array of \p nnz elements containing the row indices of the sparse * COO matrix. * @param[inout] * cooCols array of \p nnz elements containing the column indices of the sparse * COO matrix. * @param[inout] * P array of \p nnz integers containing the unsorted map indices, can be * \p NULL. * @param[in] * pBuffer temporary storage buffer allocated by the user, size is returned by * \ref hipsparseXcoosort_bufferSizeExt(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p cooRows, * \p cooCols or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_coosort_by_column.cpp doc example */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcoosortByColumn(hipsparseHandle_t handle, int m, int n, int nnz, int* cooRows, int* cooCols, int* P, void* pBuffer); #ifdef __cplusplus } #endif #endif /* HIPSPARSE_COOSORT_H */ ./library/include/internal/conversion/hipsparse_csr2hyb.h0000664000175100017510000001602115176134511024002 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2HYB_H #define HIPSPARSE_CSR2HYB_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a sparse HYB matrix * * \details * \p hipsparseXcsr2hyb converts a CSR matrix into a HYB matrix. It is assumed * that \p hyb has been initialized with \ref hipsparseCreateHybMat(). * * \note * This function requires a significant amount of storage for the HYB matrix, * depending on the matrix structure. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrSortedValA array containing the values of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array containing the column indices of the sparse CSR matrix. * @param[out] * hybA sparse matrix in HYB format. * @param[in] * userEllWidth width of the ELL part of the HYB matrix (only required if * \p partitionType == \ref HIPSPARSE_HYB_PARTITION_USER). * @param[in] * partitionType \ref HIPSPARSE_HYB_PARTITION_AUTO (recommended), * \ref HIPSPARSE_HYB_PARTITION_USER or * \ref HIPSPARSE_HYB_PARTITION_MAX. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p userEllWidth, \p partitionType, * \p descrA, \p hybA, \p csrSortedValA, \p csrSortedRowPtrA or \p csrSortedColIndA pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED the buffer for the HYB matrix could not be * allocated. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csr2hyb.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2HYB_H */ ./library/include/internal/conversion/hipsparse_csr2csru.h0000664000175100017510000001141015176134511024171 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2CSRU_H #define HIPSPARSE_CSR2CSRU_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * This function converts sorted CSR format to unsorted CSR format. The required * temporary storage has to be allocated by the user. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2CSRU_H */ ./library/include/internal/conversion/hipsparse_bsr2csr.h0000664000175100017510000002100015176134511023777 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSR2CSR_H #define HIPSPARSE_BSR2CSR_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert a sparse BSR matrix into a sparse CSR matrix * * \details * \p hipsparseXbsr2csr converts a BSR matrix into a CSR matrix. It is assumed, * that \p csrValC, \p csrColIndC and \p csrRowPtrC are allocated. Allocation size * for \p csrRowPtrC is computed by the number of block rows multiplied by the block * dimension plus one. Allocation for \p csrValC and \p csrColInd is computed by the * the number of blocks in the BSR matrix multiplied by the block dimension squared. * * For example, given the BSR matrix using block dimension 2: * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c} * 1 & 0 \\ * 3 & 4 * \end{array} & * \begin{array}{c c} * 0 & 2 \\ * 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c} * 5 & 0 \\ * 1 & 2 * \end{array} & * \begin{array}{c c} * 6 & 7 \\ * 3 & 4 * \end{array} \\ * \end{array} * \right] * \f] * * The resulting CSR matrix row pointer, column indices, and values arrays are: * \f[ * \begin{align} * \text{csrRowPtrC} &= \begin{bmatrix} 0 & 4 & 8 & 12 & 16 \end{bmatrix} \\ * \text{csrColIndC} &= \begin{bmatrix} 0 & 1 & 2 & 3 & 0 & 1 & 2 & 3 & 0 & 1 & 2 & 3 & 0 & 1 & 2 & 3 \end{bmatrix} \\ * \text{csrValC} &= \begin{bmatrix} 1 & 0 & 0 & 2 & 3 & 4 & 0 & 0 & 5 & 0 & 6 & 7 & 1 & 2 & 3 & 4 \end{bmatrix} \\ * \end{align} * \f] * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA the storage format of the blocks, \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN * @param[in] * mb number of block rows in the sparse BSR matrix. * @param[in] * nb number of block columns in the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * bsrValA array of \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * blockDim size of the blocks in the sparse BSR matrix. * @param[in] * descrC descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrValC array of \p nnzb*blockDim*blockDim elements containing the values of the sparse CSR matrix. * @param[out] * csrRowPtrC array of \p m+1 where \p m=mb*blockDim elements that point to the start of every row of the * sparse CSR matrix. * @param[out] * csrColIndC array of \p nnzb*blockDim*blockDim elements containing the column indices of the sparse CSR matrix. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p blockDim, \p bsrValA, * \p bsrRowPtrA, \p bsrColIndA, \p csrValC, \p csrRowPtrC or \p csrColIndC pointer is invalid. * * \par Example * \snippet example_hipsparse_bsr2csr.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSR2CSR_H */ ./library/include/internal/conversion/hipsparse_gebsr2gebsc.h0000664000175100017510000003700715176134511024625 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GEBSR2GEBSC_H #define HIPSPARSE_GEBSR2GEBSC_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert a sparse GEBSR matrix into a sparse GEBSC matrix * * \details * \p hipsparseXgebsr2gebsc_bufferSize returns the size of the temporary storage buffer * required by \ref hipsparseSgebsr2gebsc "hipsparseXgebsr2gebsc()" and is the first step * in converting a sparse matrix in GEBSR format to a sparse matrix in GEBSC format. Once * the size of the temporary storage buffer has been determined, it must be allocated by the user. * * See hipsparseSgebsr2gebsc() for a complete code example. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * mb number of rows of the sparse GEneral BSR matrix. * @param[in] * nb number of columns of the sparse GEneral BSR matrix. * @param[in] * nnzb number of non-zero entries of the sparse GEneral BSR matrix. * @param[in] * bsrVal array of \p nnzb*rowBlockDim*colBlockDim containing the values of the sparse GEneral * BSR matrix. * @param[in] * bsrRowPtr array of \p mb+1 elements that point to the start of every row of the * sparse GEneral BSR matrix. * @param[in] * bsrColInd array of \p nnzb elements containing the column indices of the sparse * GEneral BSR matrix. * @param[in] * rowBlockDim row size of the blocks in the sparse general BSR matrix. * @param[in] * colBlockDim col size of the blocks in the sparse general BSR matrix. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSgebsr2gebsc(), hipsparseDgebsr2gebsc(), hipsparseCgebsr2gebsc() and * hipsparseZgebsr2gebsc(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p nnzb, \p bsrRowPtr, \p bsrColInd * or \p pBufferSizeInBytes pointer is invalid. * \retval rocsparse_status_internal_error an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup conv_module * \brief Convert a sparse GEBSR matrix into a sparse GEBSC matrix * * \details * \p hipsparseXgebsr2gebsc converts a GEBSR matrix into a GEBSC matrix. \p hipsparseXgebsr2gebsc * can also be used to convert a GEBSC matrix into a GEBSR matrix. \p copyValues decides * whether \p bscVal is being filled during conversion (\ref HIPSPARSE_ACTION_NUMERIC) * or not (\ref HIPSPARSE_ACTION_SYMBOLIC). * * \p hipsparseXgebsr2gebsc requires extra temporary storage buffer that has to be allocated * by the user. Storage buffer size can be determined by \ref hipsparseSgebsr2gebsc_bufferSize * "hipsparseXgebsr2gebsc_bufferSize()". * * For example, given the GEBSR matrix: * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c} * 1 & 2 \\ * 3 & 4 \\ * 6 & 0 * \end{array} & * \begin{array}{c c} * 0 & 2 \\ * 0 & 0 \\ * 3 & 4 * \end{array} \\ * \hline * \begin{array}{c c} * 5 & 0 \\ * 1 & 2 \\ * 3 & 4 * \end{array} & * \begin{array}{c c} * 6 & 7 \\ * 3 & 4 \\ * 3 & 4 * \end{array} \\ * \end{array} * \right] * \f] * * represented with the arrays: * \f[ * \begin{align} * \text{bsrRowPtr} &= \begin{bmatrix} 0 & 2 & 4 \end{bmatrix} \\ * \text{bsrColInd} &= \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} \\ * \text{bsrVal} &= \begin{bmatrix} 1 & 2 & 3 & 4 & 6 & 0 & 0 & 2 & 0 & 0 & 3 & 4 & 5 & 0 & 1 & 2 & 3 & 4 & 6 & 7 & 3 & 4 & 3 & 4 \end{bmatrix} * \end{align} * \f] * * this function converts the matrix to GEBSC format: * \f[ * \begin{align} * \text{bscRowInd} &= \begin{bmatrix} 0 & 1 & 0 & 1 \end{bmatrix} \\ * \text{bscColPtr} &= \begin{bmatrix} 0 & 2 & 4 \end{bmatrix} \\ * \text{bscVal} &= \begin{bmatrix} 1 & 2 & 3 & 4 & 6 & 0 & 5 & 0 & 1 & 2 & 3 & 4 & 0 & 2 & 0 & 0 & 3 & 4 & 6 & 7 & 3 & 4 & 3 & 4 \end{bmatrix} * \end{align} * \f] * * The GEBSC arrays, \p bscRowInd, \p bscColPtr, and \p bscVal must be allocated by the user prior * to calling \p hipsparseXgebsr2gebsc(). The \p bscRowInd array has size \p nnzb, the \p bscColPtr * array has size \p nb+1, and the \p bscVal array has size \p nnzb*rowBlockDim*colBlockDim. * * \note * The resulting matrix can also be seen as the transpose of the input matrix. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * mb number of rows of the sparse GEneral BSR matrix. * @param[in] * nb number of columns of the sparse GEneral BSR matrix. * @param[in] * nnzb number of non-zero entries of the sparse GEneral BSR matrix. * @param[in] * bsrVal array of \p nnzb * \p rowBlockDim * \p colBlockDim elements of the sparse GEneral BSR matrix. * @param[in] * bsrRowPtr array of \p m+1 elements that point to the start of every row of the * sparse GEneral BSR matrix. * @param[in] * bsrColInd array of \p nnz elements containing the column indices of the sparse * GEneral BSR matrix. * @param[in] * rowBlockDim row size of the blocks in the sparse general BSR matrix. * @param[in] * colBlockDim col size of the blocks in the sparse general BSR matrix. * @param[out] * bscVal array of \p nnz elements of the sparse BSC matrix. * @param[out] * bscRowInd array of \p nnz elements containing the row indices of the sparse BSC * matrix. * @param[out] * bscColPtr array of \p n+1 elements that point to the start of every column of the * sparse BSC matrix. * @param[in] * copyValues \ref HIPSPARSE_ACTION_SYMBOLIC or \ref HIPSPARSE_ACTION_NUMERIC. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * @param[in] * temp_buffer temporary storage buffer allocated by the user, size is returned by * \ref hipsparseSgebsr2gebsc_bufferSize "hipsparseXgebsr2gebsc_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p nnzb, \p bsrVal, * \p bsrRowPtr, \p bsrColInd, \p bscVal, \p bscRowInd, \p bscColPtr or * \p temp_buffer pointer is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_gebsr2gebsc.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, float* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, double* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipDoubleComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GEBSR2GEBSC_H */ ./library/include/internal/conversion/hipsparse_csr2csc.h0000664000175100017510000004024315176134511023773 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2CSC_H #define HIPSPARSE_CSR2CSC_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a sparse CSC matrix * * \details * \p hipsparseXcsr2csc converts a CSR matrix into a CSC matrix. \p hipsparseXcsr2csc * can also be used to convert a CSC matrix into a CSR matrix. \p copyValues decides * whether \p cscSortedVal is being filled during conversion (\ref HIPSPARSE_ACTION_NUMERIC) * or not (\ref HIPSPARSE_ACTION_SYMBOLIC). * * For example given the matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 * \end{bmatrix} * \f] * * Represented using the sparse CSR format as: * \f[ * \begin{align} * \text{csrSortedRowPtr} &= \begin{bmatrix} 0 & 2 & 4 & 7 \end{bmatrix} \\ * \text{csrSortedColInd} &= \begin{bmatrix} 0 & 3 & 0 & 1 & 0 & 2 & 3 \end{bmatrix} \\ * \text{csrSortedVal} &= \begin{bmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 \end{bmatrix} * \end{align} * \f] * * this function converts to sparse CSC format: * \f[ * \begin{align} * \text{cscSortedRowInd} &= \begin{bmatrix} 0 & 1 & 2 & 1 & 2 & 0 & 2 \end{bmatrix} \\ * \text{cscSortedColPtr} &= \begin{bmatrix} 0 & 3 & 4 & 5 & 7 \end{bmatrix} \\ * \text{cscSortedVal} &= \begin{bmatrix} 1 & 3 & 5 & 4 & 6 & 2 & 7 \end{bmatrix} * \end{align} * \f] * * The CSC arrays, \p cscSortedRowInd, \p cscSortedColPtr, and \p cscSortedVal must be allocated by the * user prior to calling \p hipsparseXcsr2csc(). * * \note * The resulting matrix can also be seen as the transpose of the input matrix. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * csrSortedVal array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtr array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColInd array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * cscSortedVal array of \p nnz elements of the sparse CSC matrix. * @param[out] * cscSortedRowInd array of \p nnz elements containing the row indices of the sparse CSC * matrix. * @param[out] * cscSortedColPtr array of \p n+1 elements that point to the start of every column of the * sparse CSC matrix. * @param[in] * copyValues \ref HIPSPARSE_ACTION_SYMBOLIC or \ref HIPSPARSE_ACTION_NUMERIC. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p csrSortedVal, \p csrSortedRowPtr, * \p csrSortedColInd, \p cscSortedVal, \p cscSortedRowInd or \p cscSortedColPtr pointer is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_csr2csc.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const float* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, float* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const double* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, double* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipComplex* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, hipComplex* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipDoubleComplex* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, hipDoubleComplex* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) /*! \ingroup conv_module * \brief This function computes the size of the user allocated temporary storage buffer used * when converting a sparse CSR matrix into a sparse CSC matrix. * * \details * \p hipsparseCsr2cscEx2_bufferSize calculates the required user allocated temporary buffer needed * by \ref hipsparseCsr2cscEx2 to convert a CSR matrix into a CSC matrix. \ref hipsparseCsr2cscEx2 * can also be used to convert a CSC matrix into a CSR matrix. \p copyValues decides * whether \p cscVal is being filled during conversion (\ref HIPSPARSE_ACTION_NUMERIC) * or not (\ref HIPSPARSE_ACTION_SYMBOLIC). * * \note * The resulting matrix can also be seen as the transpose of the input matrix. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * csrVal array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrRowPtr array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrColInd array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[in] * cscVal array of \p nnz elements of the sparse CSC matrix. * @param[in] * cscColPtr array of \p n+1 elements that point to the start of every column of the * sparse CSC matrix. * @param[in] * cscRowInd array of \p nnz elements containing the row indices of the sparse * CSC matrix. * @param[in] * valType The data type of the values arrays \p csrVal and \p cscVal. Can be HIP_R_32F, * HIP_R_64F, HIP_C_32F or HIP_C_64F * @param[in] * copyValues \ref HIPSPARSE_ACTION_SYMBOLIC or \ref HIPSPARSE_ACTION_NUMERIC. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * @param[in] * alg HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1 or HIPSPARSE_CSR2CSC_ALG2. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseCsr2cscEx2(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p csrRowPtr, \p csrColInd or * \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCsr2cscEx2_bufferSize(hipsparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, hipDataType valType, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, hipsparseCsr2CscAlg_t alg, size_t* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a sparse CSC matrix * * \details * \p hipsparseCsr2cscEx2 converts a CSR matrix into a CSC matrix. \p hipsparseCsr2cscEx2 * can also be used to convert a CSC matrix into a CSR matrix. \p copyValues decides * whether \p cscVal is being filled during conversion (\ref HIPSPARSE_ACTION_NUMERIC) * or not (\ref HIPSPARSE_ACTION_SYMBOLIC). * * \note * The resulting matrix can also be seen as the transpose of the input matrix. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * csrVal array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrRowPtr array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrColInd array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[in] * cscVal array of \p nnz elements of the sparse CSC matrix. * @param[in] * cscColPtr array of \p n+1 elements that point to the start of every column of the * sparse CSC matrix. * @param[in] * cscRowInd array of \p nnz elements containing the row indices of the sparse * CSC matrix. * @param[in] * valType The data type of the values arrays \p csrVal and \p cscVal. Can be HIP_R_32F, * HIP_R_64F, HIP_C_32F or HIP_C_64F * @param[in] * copyValues \ref HIPSPARSE_ACTION_SYMBOLIC or \ref HIPSPARSE_ACTION_NUMERIC. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * @param[in] * alg HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1 or HIPSPARSE_CSR2CSC_ALG2. * @param[in] * buffer temporary storage buffer allocated by the user, size is returned by * hipsparseCsr2cscEx2_bufferSize(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p csrRowPtr, \p csrColInd or * \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_csr2csc_ex2.cpp doc example */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCsr2cscEx2(hipsparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, hipDataType valType, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, hipsparseCsr2CscAlg_t alg, void* buffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2CSC_H */ ./library/include/internal/conversion/hipsparse_nnz.h0000664000175100017510000001453115176134511023237 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_NNZ_H #define HIPSPARSE_NNZ_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief * \p hipsparseXnnz computes the number of nonzero elements per row or column and the total * number of nonzero elements in a dense matrix. * * \details * For example, given the dense matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 * \end{bmatrix} * \f] * * then using \p dirA == \ref HIPSPARSE_DIRECTION_ROW results in: * \f[ * \begin{align} * \text{nnzPerRowColumn} &= \begin{bmatrix} 2 & 2 & 3 \end{bmatrix} \\ * \text{nnzTotalDevHostPtr} &= 7 * \end{align} * \f] * * while using \p dirA == \ref HIPSPARSE_DIRECTION_COLUMN results in: * \f[ * \begin{align} * \text{nnzPerRowColumn} &= \begin{bmatrix} 3 & 1 & 1 & 2 \end{bmatrix} \\ * \text{nnzTotalDevHostPtr} &= 7 * \end{align} * \f] * * The array \p nnzPerRowColumn must be allocated by the user before calling \p hipsparseXnnz and * has length equal to \p m if \p dirA == \ref HIPSPARSE_DIRECTION_ROW or \p n if * \p dirA == \ref HIPSPARSE_DIRECTION_COLUMN. * * For a complete code example on its usage, see the example found with hipsparseSdense2csr(). * * \note * As indicated, \p nnzTotalDevHostPtr can point either to host or device memory. This is controlled * by setting the pointer mode. See \ref hipsparseSetPointerMode(). * * \note * The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the rocsparse library context queue. * @param[in] * dirA direction that specified whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW * or by \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * descrA the descriptor of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[out] * nnzPerRowColumn array of size \p m or \p n containing the number of nonzero elements per row or column, respectively. * @param[out] * nnzTotalDevHostPtr total number of nonzero elements in device or host memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p lda, \p A or \p nnzPerRowColumn or * \p nnzTotalDevHostPtr pointer is invalid. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_NNZ_H */ ./library/include/internal/conversion/hipsparse_dense2csc.h0000664000175100017510000001716315176134511024307 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_DENSE2CSC_H #define HIPSPARSE_DENSE2CSC_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup conv_module * \brief * \p hipsparseXdense2csc converts the matrix A in dense format into a sparse matrix in CSC format. * * \details * Given a dense, column ordered, matrix \p A with leading dimension \p ld where \p ld>=m, * \p hipsparseXdense2csc converts the matrix to a sparse CSC format matrix. * All the parameters are assumed to have been pre-allocated by the user and the arrays * are filled in based on number of nonzeros per row, which can be pre-computed with * \ref hipsparseSnnz "hipsparseXnnz()". We can set the desired index base in the output CSC * matrix by setting it in the \ref hipsparseMatDescr_t. See \ref hipsparseSetMatIndexBase(). * * As an example, if using index base zero (i.e. the default) and the dense * matrix: * * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 * \end{bmatrix} * \f] * * where the \p A values have column ordering with leading dimension \p ld=m: * \f[ * \text{A} &= \begin{bmatrix} 1 & 3 & 5 & 0 & 4 & 0 & 0 & 0 & 6 & 2 & 0 & 7 \end{bmatrix} \\ * \f] * * the conversion results in the CSC arrays: * * \f[ * \begin{align} * \text{cscRowInd} &= \begin{bmatrix} 0 & 1 & 2 & 1 & 2 & 0 & 2 \end{bmatrix} \\ * \text{cscColPtr} &= \begin{bmatrix} 0 & 3 & 4 & 5 & 7 \end{bmatrix} \\ * \text{cscVal} &= \begin{bmatrix} 1 & 3 & 5 & 4 & 6 & 2 & 7 \end{bmatrix} \\ * \end{align} * \f] * * This function works very similar to \ref hipsparseSdense2csr "hipsparseXdense2csr()". & See hipsparseSdense2csr() for a code example. * * \note * It is executed asynchronously with respect to the host and may return control to the * application on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also * any valid value of the \ref hipsparseIndexBase_t. * @param[in] * A array of dimensions (\p ld, \p n) * @param[in] * ld leading dimension of dense array \p A. * @param[in] * nnzPerColumn array of size \p n containing the number of non-zero elements per column. * @param[out] * cscVal array of nnz ( = \p cscColPtr[n] - \p cscColPtr[0] ) nonzero elements of matrix \p A. * @param[out] * cscRowInd integer array of nnz ( = \p cscColPtr[n] - \p cscColPtr[0] ) column indices of the non-zero elements of matrix \p A. * @param[out] * cscColPtr integer array of \p n+1 elements that contains the start of every column and the end of the last column plus one. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ld, \p A, \p nnzPerColumn or \p cscVal \p cscColPtr * or \p cscRowInd pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerColumn, float* cscVal, int* cscRowInd, int* cscColPtr); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerColumn, double* cscVal, int* cscRowInd, int* cscColPtr); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerColumn, hipComplex* cscVal, int* cscRowInd, int* cscColPtr); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerColumn, hipDoubleComplex* cscVal, int* cscRowInd, int* cscColPtr); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_DENSE2CSC_H */ ./library/include/internal/conversion/hipsparse_prune_dense2csr_by_percentage.h0000664000175100017510000005653315176134511030432 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_PRUNE_DENSE2CSR_BY_PRECENTAGE_H #define HIPSPARSE_PRUNE_DENSE2CSR_BY_PRECENTAGE_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * \p hipsparseXpruneDense2csrByPercentage_bufferSize computes the size of the user allocated temporary * storage buffer used when converting a dense matrix to a pruned CSR matrix where the pruning is done * based on a percantage. * * \details * When converting and pruning a dense matrix A to a CSR matrix by percentage the * following steps are performed. First the user calls * \p hipsparseXpruneDense2csrByPercentage_bufferSize which determines the size of the * temporary storage buffer. Once determined, this buffer must be allocated by the user. * Next the user allocates the \p csrRowPtr array to have \p m+1 elements and calls * \ref hipsparseSpruneDense2csrNnzByPercentage "hipsparseXpruneDense2csrNnzByPercentage()". * Finally the user finishes the conversion by allocating the \p csrColInd and \p csrVal arrays * (whose size is determined by the value at \p nnzTotalDevHostPtr) and calling * \ref hipsparseSpruneDense2csrByPercentage "hipsparseXpruneDense2csrByPercentage()". * * The pruning by percentage works by first sorting the absolute values of the dense * matrix \p A. We then determine a position in this sorted array by * \f[ * pos = ceil(m \cdot n \cdot (percentage/100)) - 1 \\ * pos = \min(pos, m \cdot n-1) \\ * pos = \max(pos, 0) \\ * threshold = sorted_A[pos] * \f] * * Once we have this threshold we prune values in the dense matrix \p A as in * \ref hipsparseSpruneDense2csr "hipsparseXpruneDense2csr()". * * \note * It is executed asynchronously with respect to the host and may return control to the * application on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also * any valid value of the \ref hipsparseIndexBase_t. * @param[in] * csrVal array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) nonzero elements of matrix \p A. * @param[in] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[in] * csrColInd integer array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) column indices of the non-zero elements of matrix \p A. * @param[in] * info prune information structure * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSpruneDense2csrNnzByPercentage(), hipsparseDpruneDense2csrNnzByPercentage(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE the \p handle or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * This function computes the size of the user allocated temporary storage buffer used * when converting and pruning by percentage a dense matrix to a CSR matrix. * * \details * When converting and pruning a dense matrix A to a CSR matrix by percentage the * following steps are performed. First the user calls * \p hipsparseXpruneDense2csrByPercentage_bufferSizeExt which determines the size of the * temporary storage buffer. Once determined, this buffer must be allocated by the user. * Next the user allocates the \p csrRowPtr array to have \p m+1 elements and calls * \ref hipsparseSpruneDense2csrNnzByPercentage "hipsparseXpruneDense2csrNnzByPercentage()". * Finally the user finishes the conversion by allocating the \p csrColInd and \p csrVal arrays * (whos size is determined by the value at \p nnzTotalDevHostPtr) and calling * \ref hipsparseSpruneDense2csrByPercentage "hipsparseXpruneDense2csrByPercentage()". * * The pruning by percentage works by first sorting the absolute values of the dense * matrix \p A. We then determine a position in this sorted array by * \f[ * pos = ceil(m \cdot n \cdot (percentage/100)) - 1 \\ * pos = \min(pos, m \cdot n-1) \\ * pos = \max(pos, 0) \\ * threshold = sorted_A[pos] * \f] * * Once we have this threshold we prune values in the dense matrix \p A as in * \ref hipsparseSpruneDense2csr "hipsparseXpruneDense2csr()". * * \note * It is executed asynchronously with respect to the host and may return control to the * application on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also * any valid value of the \ref hipsparseIndexBase_t. * @param[in] * csrVal array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) nonzero elements of matrix \p A. * @param[in] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[in] * csrColInd integer array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) column indices of the non-zero elements of matrix \p A. * @param[in] * info prune information structure * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSpruneDense2csrNnzByPercentage(), hipsparseDpruneDense2csrNnzByPercentage(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE the \p handle or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * This function computes the number of nonzero elements per row and the total number of * nonzero elements in a dense matrix when converting and pruning by percentage a dense * matrix to a CSR matrix. * * \details * When converting and pruning a dense matrix A to a CSR matrix by percentage the * following steps are performed. First the user calls * \ref hipsparseSpruneDense2csrByPercentage_bufferSize "hipsparseXpruneDense2csrByPercentage_bufferSize()" * which determines the size of the temporary storage buffer. Once determined, this buffer must be allocated * by the user. Next the user allocates the \p csrRowPtr array to have \p m+1 elements and calls * \p hipsparseXpruneDense2csrNnzByPercentage. Finally the user finishes the conversion * by allocating the \p csrColInd and \p csrVal arrays (whos size is determined by the value * at \p nnzTotalDevHostPtr) and calling \ref hipsparseSpruneDense2csrByPercentage * "hipsparseXpruneDense2csrByPercentage()". * * The pruning by percentage works by first sorting the absolute values of the dense * matrix \p A. We then determine a position in this sorted array by * \f[ * pos = ceil(m \cdot n \cdot (percentage/100)) - 1 \\ * pos = \min(pos, m \cdot n-1) \\ * pos = \max(pos, 0) \\ * threshold = sorted_A[pos] * \f] * * Once we have this threshold we prune values in the dense matrix \p A as in * \ref hipsparseSpruneDense2csr "hipsparseXpruneDense2csr()". * * \note * The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descr the descriptor of the dense matrix \p A. * @param[out] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[out] * nnzTotalDevHostPtr total number of nonzero elements in device or host memory. * @param[in] * info prune information structure * @param[out] * buffer buffer allocated by the user whose size is determined by calling * \ref hipsparseSpruneDense2csrByPercentage_bufferSize "hipsparseXpruneDense2csrByPercentage_bufferSize()" * or \ref hipsparseSpruneDense2csrByPercentage_bufferSizeExt "hipsparseXpruneDense2csrByPercentage_bufferSizeExt()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p lda, \p percentage, \p A, \p descr, \p info, \p csrRowPtr * \p nnzTotalDevHostPtr or \p buffer pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief * This function computes the number of nonzero elements per row and the total number of * nonzero elements in a dense matrix when converting and pruning by percentage a dense * matrix to a CSR matrix. * * \details * When converting and pruning a dense matrix A to a CSR matrix by percentage the * following steps are performed. First the user calls \ref hipsparseSpruneDense2csrByPercentage_bufferSize * "hipsparseXpruneDense2csrByPercentage_bufferSize()" which determines the size of the * temporary storage buffer. Once determined, this buffer must be allocated by the user. * Next the user allocates the \p csrRowPtr array to have \p m+1 elements and calls * \ref hipsparseSpruneDense2csrNnzByPercentage "hipsparseXpruneDense2csrNnzByPercentage()". Finally the * user finishes the conversion by allocating the \p csrColInd and \p csrVal arrays (whos size is * determined by the value at \p nnzTotalDevHostPtr) and calling \p hipsparseXpruneDense2csrByPercentage. * * The pruning by percentage works by first sorting the absolute values of the dense * matrix \p A. We then determine a position in this sorted array by * \f[ * pos = ceil(m \ cdot n \cdot (percentage/100)) - 1 \\ * pos = \min(pos, m \cdot n-1) \\ * pos = \max(pos, 0) \\ * threshold = sorted_A[pos] * \f] * * Once we have this threshold we prune values in the dense matrix \p A as in * \ref hipsparseSpruneDense2csr "hipsparseXpruneDense2csr()". * * \note * The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * A array of dimensions (\p lda, \p n) * @param[in] * lda leading dimension of dense array \p A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL and * also any valid value of the \ref hipsparseIndexBase_t. * @param[out] * csrVal array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) nonzero elements of matrix \p A. * @param[in] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[out] * csrColInd integer array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) column indices of the non-zero elements of matrix \p A. * @param[in] * info prune information structure * @param[in] * buffer temporary storage buffer allocated by the user, size is returned by * \ref hipsparseSpruneDense2csrByPercentage_bufferSize "hipsparseXpruneDense2csrByPercentage_bufferSize()" or * \ref hipsparseSpruneDense2csrByPercentage_bufferSizeExt "hipsparseXpruneDense2csrByPercentage_bufferSizeExt()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p lda, \p percentage, \p A, \p descr, \p info, \p csrVal * \p csrRowPtr, \p csrColInd or \p buffer pointer is invalid. * * \par Example * \snippet example_hipsparse_prune_dense2csr_by_percentage.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_PRUNE_DENSE2CSR_BY_PRECENTAGE_H */ ./library/include/internal/conversion/hipsparse_prune_csr2csr.h0000664000175100017510000005247415176134511025234 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_PRUNE_CSR2CSR_H #define HIPSPARSE_PRUNE_CSR2CSR_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert and prune sparse CSR matrix into a sparse CSR matrix * * \details * \p hipsparseXpruneCsr2csr_bufferSize returns the size of the temporary buffer that * is required by \p hipsparseXpruneCsr2csrNnz and hipsparseXpruneCsr2csr. The * temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * threshold pointer to the non-negative pruning threshold which can exist in either host or device memory. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValC array of \p nnzC elements containing the values of the sparse CSR matrix C. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[in] * csrColIndC array of \p nnzC elements containing the column indices of the sparse CSR matrix C. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by hipsparseSpruneCsr2csrNnz(), * hipsparseDpruneCsr2csrNnz(), hipsparseSpruneCsr2csr(), and hipsparseDpruneCsr2csr(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes); /**@}*/ #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Convert and prune sparse CSR matrix into a sparse CSR matrix * * \details * \p hipsparseXpruneCsr2csr_bufferSizeExt returns the size of the temporary buffer that * is required by \ref hipsparseSpruneCsr2csrNnz "hipsparseXpruneCsr2csrNnz()" and * \ref hipsparseSpruneCsr2csr "hipsparseXpruneCsr2csr()". The temporary storage buffer * must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * threshold pointer to the non-negative pruning threshold which can exist in either host or device memory. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValC array of \p nnzC elements containing the values of the sparse CSR matrix C. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[in] * csrColIndC array of \p nnzC elements containing the column indices of the sparse CSR matrix C. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by hipsparseSpruneCsr2csrNnz(), * hipsparseDpruneCsr2csrNnz(), hipsparseSpruneCsr2csr(), and hipsparseDpruneCsr2csr(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Convert and prune sparse CSR matrix into a sparse CSR matrix * * \details * \p hipsparseXpruneCsr2csrNnz computes the number of nonzero elements per row and the total * number of nonzero elements in a sparse CSR matrix once elements less than the threshold are * pruned from the matrix. * * \note The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * threshold pointer to the non-negative pruning threshold which can exist in either host or device memory. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[out] * nnzTotalDevHostPtr total number of nonzero elements in device or host memory. * @param[out] * buffer buffer allocated by the user whose size is determined by calling \ref hipsparseSpruneCsr2csr_bufferSize * "hipsparseXpruneCsr2csr_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p threshold, \p descrA, * \p descrC, \p csrValA, \p csrRowPtrA, \p csrColIndA, \p csrRowPtrC, \p nnzTotalDevHostPtr * or \p buffer pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Convert and prune sparse CSR matrix into a sparse CSR matrix * * \details * This function converts the sparse CSR matrix A into a sparse CSR matrix C by pruning values in A * that are less than the threshold. All the parameters are assumed to have been pre-allocated by the user. * The user first calls \ref hipsparseSpruneCsr2csr_bufferSize "hipsparseXpruneCsr2csr_bufferSize()" to * determine the size of the buffer used by \ref hipsparseSpruneCsr2csrNnz "hipsparseXpruneCsr2csrNnz()" * and \p hipsparseXpruneCsr2csr() which the user then allocates. The user then allocates \p csrRowPtrC to * have \p m+1 elements and then calls hipsparseXpruneCsr2csrNnz() which fills in the \p csrRowPtrC array * stores then number of elements that are larger than the pruning \p threshold in \p nnzTotalDevHostPtr. * The user then calls \p hipsparseXpruneCsr2csr() to complete the conversion. It is executed asynchronously * with respect to the host and may return control to the application on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * threshold pointer to the non-negative pruning threshold which can exist in either host or device memory. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrValC array of \p nnzC elements containing the values of the sparse CSR matrix C. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[out] * csrColIndC array of \p nnzC elements containing the column indices of the sparse CSR matrix C. * @param[in] * buffer buffer allocated by the user whose size is determined by calling \ref hipsparseSpruneCsr2csr_bufferSize * "hipsparseXpruneCsr2csr_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p threshold, \p descrA, \p descrC, \p csrValA, * \p csrRowPtrA, \p csrcolindA, \p csrvalC, \p csrrowptrC, \p csrcolIndC or \p buffer pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_PRUNE_CSR2CSR_H */ ./library/include/internal/conversion/hipsparse_gebsr2csr.h0000664000175100017510000002206715176134511024331 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GEBSR2CSR_H #define HIPSPARSE_GEBSR2CSR_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert a sparse GEBSR matrix into a sparse CSR matrix * * \details * \p hipsparseXgebsr2csr converts a GEBSR matrix into a CSR matrix. It is assumed, * that \p csrValC, \p csrColIndC and \p csrRowPtrC are already allocated prior to * calling \p hipsparseXgebsr2csr. Allocation size for \p csrRowPtrC equals * \p m+1 where: * * \f[ * \begin{align} * \text{m} &= \text{mb * rowBlockDim} \\ * \text{n} &= \text{nb * colBlockDim} * \end{align} * \f] * * Allocation size for \p csrValC and \p csrColIndC is computed by the the number of blocks in the GEBSR * matrix, \p nnzb, multiplied by the product of the block dimensions, i.e. \p nnz=nnzb*rocBlockDim*colBlockDim. * * For example, given the GEBSR matrix: * \f[ * \left[ * \begin{array}{c | c | c} * \begin{array}{c c} * 6 & 2 \\ * 1 & 4 \\ * 5 & 4 * \end{array} & * \begin{array}{c c} * 0 & 3 \\ * 5 & 0 \\ * 0 & 7 * \end{array} & * \begin{array}{c c} * 0 & 0 \\ * 0 & 0 \\ * 0 & 0 * \end{array} \\ * \hline * \begin{array}{c c} * 0 & 0 \\ * 0 & 0 \\ * 0 & 0 * \end{array} & * \begin{array}{c c} * 3 & 0 \\ * 0 & 0 \\ * 0 & 7 * \end{array} & * \begin{array}{c c} * 2 & 2 \\ * 4 & 3 \\ * 1 & 4 * \end{array} \\ * \end{array} * \right] * \f] * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA the storage format of the blocks, \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN * @param[in] * mb number of block rows in the sparse general BSR matrix. * @param[in] * nb number of block columns in the sparse general BSR matrix. * @param[in] * descrA descriptor of the sparse general BSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * bsrValA array of \p nnzb*rowBlockDim*colBlockDim containing the values of the sparse BSR matrix. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * rowBlockDim row size of the blocks in the sparse general BSR matrix. * @param[in] * colBlockDim column size of the blocks in the sparse general BSR matrix. * @param[in] * descrC descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrValC array of \p nnzb*rowBlockDim*colBlockDim elements containing the values of the sparse CSR matrix. * @param[out] * csrRowPtrC array of \p m+1 where \p m=mb*rowBlockDim elements that point to the start of every row of the * sparse CSR matrix. * @param[out] * csrColIndC array of \p nnzb*block_dim*block_dim elements containing the column indices of the sparse CSR matrix. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p block_dim, \p bsrValA, * \p bsrRowPtrA, \p bsrColIndA, \p csrValC, \p csrRowPtrC or \p csrColIndC pointer is invalid. * * \par Example * \snippet example_hipsparse_gebsr2csr.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GEBSR2CSR_H */ ./library/include/internal/conversion/hipsparse_hyb2csr.h0000664000175100017510000001174015176134511024005 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_HYB2CSR_H #define HIPSPARSE_HYB2CSR_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup conv_module * \brief Convert a sparse HYB matrix into a sparse CSR matrix * * \details * \p hipsparseXhyb2csr converts a HYB matrix into a CSR matrix. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * descrA descriptor of the sparse HYB matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * hybA sparse matrix in HYB format. * @param[out] * csrSortedValA array containing the values of the sparse CSR matrix. * @param[out] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[out] * csrSortedColIndA array containing the column indices of the sparse CSR matrix. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p descrA, \p hybA, \p csrSortedValA, * \p csrSortedRowPtrA or \p csrSortedColIndA pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseShyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, float* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, double* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseChyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipComplex* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipDoubleComplex* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_HYB2CSR_H */ ./library/include/internal/conversion/hipsparse_nnz_compress.h0000664000175100017510000001505015176134511025147 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_NNZ_COMPRESS_H #define HIPSPARSE_NNZ_COMPRESS_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * This function is used as the first step in converting a CSR matrix to a compressed CSR matrix. * * \details * Given a sparse CSR matrix and a non-negative tolerance, this function computes how many entries would be left * in each row of the matrix if elements less than the tolerance were removed. It also computes the total number * of remaining elements in the matrix. * * Specifically given an input sparse matrix A in CSR format, the resulting compressed sparse CSR matrix C is * computed using: * \f[ * C(i,j) = A(i, j) \text{ if |A(i, j)| > tol} * \f] * * The user first allocates \p nnzPerRow with size \p m elements. Then calling \p hipsparseXnnz_compress, * the function fills in the \p nnzPerRow array and sets the total number of nonzeros found in \p nnzC. * * See hipsparseScsr2csr_compress() for full code example. * * \note * In the case of complex matrices only the magnitude of the real part of \p tol is used. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * descrA the descriptor of the sparse CSR matrix. * @param[in] * csrValA array of \p nnzA elements of the sparse CSR matrix. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * uncompressed sparse CSR matrix. * @param[out] * nnzPerRow array of length \p m containing the number of entries that will be kept per row in * the final compressed CSR matrix. * @param[out] * nnzC number of elements in the column indices and values arrays of the compressed * sparse CSR matrix. Can be either host or device pointer. * @param[in] * tol the non-negative tolerance used for compression. If \p tol is complex then only the magnitude * of the real part is used. Entries in the input uncompressed CSR array that are below the tolerance * are removed in output compressed CSR matrix. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p tol, \p csrValA, \p csrRowPtrA, \p nnzPerRow or \p nnzC * pointer is invalid. * * \par Example * \snippet example_hipsparse_nnz_compress.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, float tol); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, double tol); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipComplex tol); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipDoubleComplex tol); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_NNZ_COMPRESS_H */ ./library/include/internal/conversion/hipsparse_csc2dense.h0000664000175100017510000001570615176134511024310 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSC2DENSE_H #define HIPSPARSE_CSC2DENSE_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup conv_module * \brief * \p hipsparseXcsc2dense function converts the sparse matrix in CSC format into a dense matrix. * * \details * Given the input CSC matrix of size \p mxn, the routine writes the matrix to the dense array \p A such * that \p A has leading dimension \p ld and is column ordered. This means that \p A has size \p ldxn where * \p ld>=m. All the parameters are assumed to have been pre-allocated by the user. If the input CSC matrix * has index base of one, it must be set in the \ref hipsparseMatDescr_t. See \ref hipsparseSetMatIndexBase() * prior to calling \p hipsparseXcsc2dense. * * For example, consider the sparse CSC matrix: * \f[ * \begin{align} * \text{cscRowInd} &= \begin{bmatrix} 0 & 1 & 2 & 1 & 2 & 0 & 2 \end{bmatrix} \\ * \text{cscColPtr} &= \begin{bmatrix} 0 & 3 & 4 & 5 & 7 \end{bmatrix} \\ * \text{cscVal} &= \begin{bmatrix} 1 & 3 & 5 & 4 & 6 & 2 & 7 \end{bmatrix} \\ * \end{align} * \f] * * \p hipsparseXcsc2dense is used to convert to the dense matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 * \end{bmatrix} * \f] * * where the values in the \p A array are column ordered: * \f[ * \text{A} &= \begin{bmatrix} 1 & 3 & 5 & 0 & 4 & 0 & 0 & 0 & 6 & 2 & 0 & 7 \end{bmatrix} \\ * \f] * * \note * It is executed asynchronously with respect to the host and may return control to the application * on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL and also * any valid value of the \ref hipsparseIndexBase_t. * @param[in] * cscVal array of nnz ( = \p cscColPtr[n] - \p cscColPtr[0] ) nonzero elements of matrix \p A. * @param[in] * cscRowInd integer array of nnz ( = \p cscColPtr[n] - \p cscColPtr[0] ) column indices of the non-zero elements of matrix \p A. * @param[in] * cscColPtr integer array of \p n+1 elements that contains the start of every column and the end of the last column plus one. * @param[out] * A array of dimensions (\p ld, \p n) * @param[out] * ld leading dimension of dense array \p A. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ld, \p A, \p cscVal \p cscColPtr * or \p cscRowInd pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* cscVal, const int* cscRowInd, const int* cscColPtr, float* A, int ld); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* cscVal, const int* cscRowInd, const int* cscColPtr, double* A, int ld); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipComplex* A, int ld); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipDoubleComplex* A, int ld); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSC2DENSE_H */ ./library/include/internal/conversion/hipsparse_csr2csr_compress.h0000664000175100017510000002072715176134511025732 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2CSR_COMPRESS_H #define HIPSPARSE_CSR2CSR_COMPRESS_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a compressed sparse CSR matrix * * \details * \p hipsparseXcsr2csr_compress converts a CSR matrix into a compressed CSR matrix by * removing entries in the input CSR matrix that are below a non-negative threshold \p tol: * * \f[ * C(i,j) = A(i, j) \text{ if |A(i, j)| > tol} * \f] * * The user must first call \ref hipsparseSnnz_compress "hipsparseXnnz_compress()" to determine the number * of nonzeros per row as well as the total number of nonzeros that will exist in resulting compressed CSR * matrix. The user then uses this information to allocate the column indices array \p csrColIndC and the * values array \p csrValC. The user then calls \p hipsparseXcsr2csr_compress to complete the conversion. * * \note * In the case of complex matrices only the magnitude of the real part of \p tol is used. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * descrA matrix descriptor for the CSR matrix * @param[in] * csrValA array of \p nnzA elements of the sparse CSR matrix. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * uncompressed sparse CSR matrix. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the uncompressed * sparse CSR matrix. * @param[in] * nnzA number of elements in the column indices and values arrays of the uncompressed * sparse CSR matrix. * @param[in] * nnzPerRow array of length \p m containing the number of entries that will be kept per row in * the final compressed CSR matrix. * @param[out] * csrValC array of \p nnzC elements of the compressed sparse CSC matrix. * @param[out] * csrRowPtrC array of \p m+1 elements that point to the start of every column of the compressed * sparse CSR matrix. * @param[out] * csrColIndC array of \p nnzC elements containing the row indices of the compressed * sparse CSR matrix. * @param[in] * tol the non-negative tolerance used for compression. If \p tol is complex then only the magnitude * of the real part is used. Entries in the input uncompressed CSR array that are below the tolerance * are removed in output compressed CSR matrix. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p tol, \p csrValA, \p csrRowPtrA, * \p csrColIndA, \p csrValC, \p csrRowPtrC, \p csrColIndC or \p nnzPerRow pointer is invalid. * * \par Example * \snippet example_hipsparse_csr2csr_compress.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, float* csrValC, int* csrColIndC, int* csrRowPtrC, float tol); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, double* csrValC, int* csrColIndC, int* csrRowPtrC, double tol); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipComplex tol); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipDoubleComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipDoubleComplex tol); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2CSR_COMPRESS_H */ ./library/include/internal/conversion/hipsparse_csr2dense.h0000664000175100017510000001600715176134511024322 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2DENSE_H #define HIPSPARSE_CSR2DENSE_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup conv_module * \brief * \p hipsparseXcsr2dense function converts the sparse matrix in CSR format into a dense matrix. * * \details * Given the input CSR matrix of size \p mxn, the routine writes the matrix to the dense array \p A such * that \p A has leading dimension \p ld and is column ordered. This means that \p A has size \p ldxn where * \p ld>=m. All the parameters are assumed to have been pre-allocated by the user. If the input CSR matrix * has index base of one, it must be set in the \ref hipsparseMatDescr_t. See \ref hipsparseSetMatIndexBase() * prior to calling \p hipsparseXcsr2dense. * * For example, consider the sparse CSR matrix: * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 2 & 4 & 7 \end{bmatrix} \\ * \text{csrColInd} &= \begin{bmatrix} 0 & 3 & 0 & 1 & 0 & 2 & 3 \end{bmatrix} \\ * \text{csrVal} &= \begin{bmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 \end{bmatrix} \\ * \end{align} * \f] * * \p hipsparseXcsr2dense is used to convert to the dense matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 \\ * 3 & 4 & 0 & 0 \\ * 5 & 0 & 6 & 7 * \end{bmatrix} * \f] * * where the values in the \p A array are column ordered: * \f[ * \text{A} &= \begin{bmatrix} 1 & 3 & 5 & 0 & 4 & 0 & 0 & 0 & 6 & 2 & 0 & 7 \end{bmatrix} \\ * \f] * * \note * It is executed asynchronously with respect to the host and may return control to the application * on the host before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the dense matrix \p A. * @param[in] * n number of columns of the dense matrix \p A. * @param[in] * descr the descriptor of the dense matrix \p A, the supported matrix type is \ref HIPSPARSE_MATRIX_TYPE_GENERAL and * also any valid value of the \ref hipsparseIndexBase_t. * @param[in] * csrVal array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) nonzero elements of matrix \p A. * @param[in] * csrRowPtr integer array of \p m+1 elements that contains the start of every row and the end of the last row plus one. * @param[in] * csrColInd integer array of nnz ( = \p csrRowPtr[m] - \p csrRowPtr[0] ) column indices of the non-zero elements of matrix \p A. * @param[out] * A array of dimensions (\p ld, \p n) * @param[out] * ld leading dimension of dense array \p A. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ld, \p A, \p csrVal, \p csrRowPtr or \p csrColInd * pointer is invalid. * * \par Example * \snippet example_hipsparse_csr2dense.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, float* A, int ld); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, double* A, int ld); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipComplex* A, int ld); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipDoubleComplex* A, int ld); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2DENSE_H */ ./library/include/internal/conversion/hipsparse_prune_csr2csr_by_percentage.h0000664000175100017510000005676415176134511030131 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_PRUNE_CSR2CSR_BY_PRECENTAGE_H #define HIPSPARSE_PRUNE_CSR2CSR_BY_PRECENTAGE_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Convert and prune by percentage a sparse CSR matrix into a sparse CSR matrix * * \details * \p hipsparseXpruneCsr2csrByPercentage_bufferSize returns the size of the temporary buffer that * is required by \ref hipsparseSpruneCsr2csrNnzByPercentage "hipsparseXpruneCsr2csrNnzByPercentage()". * The temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValC array of \p nnzC elements containing the values of the sparse CSR matrix C. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[in] * csrColIndC array of \p nnzC elements containing the column indices of the sparse CSR matrix C. * @param[in] * info prune info structure. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by hipsparseSpruneCsr2csrNnzByPercentage(), * hipsparseDpruneCsr2csrNnzByPercentage(), hipsparseSpruneCsr2csrByPercentage(), * and hipsparseDpruneCsr2csrByPercentage(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Convert and prune by percentage a sparse CSR matrix into a sparse CSR matrix * * \details * \p hipsparseXpruneCsr2csrByPercentage_bufferSizeExt returns the size of the temporary buffer that * is required by \ref hipsparseSpruneCsr2csrNnzByPercentage "hipsparseXpruneCsr2csrNnzByPercentage()". * The temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValC array of \p nnzC elements containing the values of the sparse CSR matrix C. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[in] * csrColIndC array of \p nnzC elements containing the column indices of the sparse CSR matrix C. * @param[in] * info prune info structure. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by hipsparseSpruneCsr2csrNnzByPercentage(), * hipsparseDpruneCsr2csrNnzByPercentage(), hipsparseSpruneCsr2csrByPercentage(), * and hipsparseDpruneCsr2csrByPercentage(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Convert and prune by percentage a sparse CSR matrix into a sparse CSR matrix * * \details * \p hipsparseXpruneCsr2csrNnzByPercentage computes the number of nonzero elements per row and the total * number of nonzero elements in a sparse CSR matrix once elements less than the threshold are * pruned from the matrix. * * \note The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[out] * nnzTotalDevHostPtr total number of nonzero elements in device or host memory. * @param[in] * info prune info structure. * @param[out] * buffer buffer allocated by the user whose size is determined by calling * \ref hipsparseSpruneCsr2csrByPercentage_bufferSize "hipsparseXpruneCsr2csrByPercentage_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p percentage, \p descrA, \p descrC, * \p info, \p csrValA, \p csrRowPtrA, \p csrColIndA, \p csrRowPtrC, \p nnzTotalDevHostPtr or \p buffer * pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup conv_module * \brief Convert and prune by percentage a sparse CSR matrix into a sparse CSR matrix * * \details * This function converts the sparse CSR matrix A into a sparse CSR matrix C by pruning values in A * that are less than the threshold. All the parameters are assumed to have been pre-allocated by the user. * The user first calls \ref hipsparseSpruneCsr2csr_bufferSize "hipsparseXpruneCsr2csr_bufferSize()" to * determine the size of the buffer used by \ref hipsparseSpruneCsr2csrNnz "hipsparseXpruneCsr2csrNnz()" and * \p hipsparseXpruneCsr2csr() which the user then allocates. The user then allocates \p csrRowPtrC to have * \p m+1 elements and then calls \ref hipsparseSpruneCsr2csrNnz "hipsparseXpruneCsr2csrNnz()" which fills * in the \p csrRowPtrC array stores then number of elements that are larger than the pruning \p threshold * in \p nnzTotalDevHostPtr. The user then calls \p hipsparseXpruneCsr2csr() to complete the conversion. It * is executed asynchronously with respect to the host and may return control to the application on the host * before the entire result is ready. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * nnzA number of non-zeros in the sparse CSR matrix A. * @param[in] * descrA descriptor of the sparse CSR matrix A. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrValA array of \p nnzA elements containing the values of the sparse CSR matrix A. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix A. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the sparse CSR matrix A. * @param[in] * percentage \p percentage>=0 and \p percentage<=100. * @param[in] * descrC descriptor of the sparse CSR matrix C. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrValC array of \p nnz_C elements containing the values of the sparse CSR matrix C. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix C. * @param[out] * csrColIndC array of \p nnz_C elements containing the column indices of the sparse CSR matrix C. * @param[in] * info prune info structure. * @param[in] * buffer buffer allocated by the user whose size is determined by calling * \ref hipsparseSpruneCsr2csrByPercentage_bufferSize "hipsparseXpruneCsr2csrByPercentage_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p percentage, \p descrA, \p descrC, \p info, * \p csrValA, \p csrRowPtrA, \p csrColIndA, \p csrValC, \p csrRowPtrC, \p csrColIndC or \p buffer pointer is * invalid. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_PRUNE_CSR2CSR_BY_PRECENTAGE_H */ ./library/include/internal/conversion/hipsparse_csrsort.h0000664000175100017510000001436215176134511024133 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRSORT_H #define HIPSPARSE_CSRSORT_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Sort a sparse CSR matrix * * \details * \p hipsparseXcsrsort_bufferSizeExt returns the size of the temporary storage buffer * in bytes required by hipsparseXcsrsort(). The temporary storage buffer must be allocated by * the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * csrRowPtr array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrColInd array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseXcsrsort(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p csrRowPtr, \p csrColInd or * \p pBufferSizeInBytes pointer is invalid. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrsort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes); /*! \ingroup conv_module * \brief Sort a sparse CSR matrix * * \details * \p hipsparseXcsrsort sorts a matrix in CSR format. The sorted permutation vector * \p P can be used to obtain sorted \p csrVal array. In this case, \p P must be * initialized as the identity permutation, see \ref hipsparseCreateIdentityPermutation(). To * apply the permutation vector to the CSR values, see hipsparse \ref hipsparseSgthr * "hipsparseXgthr()". * * \p hipsparseXcsrsort requires extra temporary storage buffer that has to be allocated by * the user. Storage buffer size can be determined by hipsparseXcsrsort_bufferSizeExt(). * * \note * \p P can be \p NULL if a sorted permutation vector is not required. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrRowPtr array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[inout] * csrColInd array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[inout] * P array of \p nnz integers containing the unsorted map indices, can be * \p NULL. * @param[in] * pBuffer temporary storage buffer allocated by the user, size is returned by * \ref hipsparseXcsrsort_bufferSizeExt(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p descrA, \p csrRowPtr, * \p csrColInd or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrsort.cpp doc example */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrsort(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, const int* csrRowPtr, int* csrColInd, int* P, void* pBuffer); #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRSORT_H */ ./library/include/internal/conversion/hipsparse_cscsort.h0000664000175100017510000001436715176134511024121 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSCSORT_H #define HIPSPARSE_CSCSORT_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Sort a sparse CSC matrix * * \details * \p hipsparseXcscsort_bufferSizeExt returns the size of the temporary storage buffer * in bytes required by hipsparseXcscsort(). The temporary storage buffer must be * allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSC matrix. * @param[in] * n number of columns of the sparse CSC matrix. * @param[in] * nnz number of non-zero entries of the sparse CSC matrix. * @param[in] * cscColPtr array of \p n+1 elements that point to the start of every column of * the sparse CSC matrix. * @param[in] * cscRowInd array of \p nnz elements containing the row indices of the sparse * CSC matrix. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseXcscsort(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p cscColPtr, \p cscRowInd or * \p pBufferSizeInBytes pointer is invalid. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcscsort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* cscColPtr, const int* cscRowInd, size_t* pBufferSizeInBytes); /*! \ingroup conv_module * \brief Sort a sparse CSC matrix * * \details * \p hipsparseXcscsort sorts a matrix in CSC format. The sorted permutation vector * \p P can be used to obtain sorted \p cscVal array. In this case, \p P must be * initialized as the identity permutation, see \ref hipsparseCreateIdentityPermutation(). To * apply the permutation vector to the CSC values, see hipsparse \ref hipsparseSgthr * "hipsparseXgthr()". * * \p hipsparseXcscsort requires extra temporary storage buffer that has to be allocated by * the user. Storage buffer size can be determined by \ref hipsparseXcscsort_bufferSizeExt(). * * \note * \p P can be \p NULL if a sorted permutation vector is not required. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSC matrix. * @param[in] * n number of columns of the sparse CSC matrix. * @param[in] * nnz number of non-zero entries of the sparse CSC matrix. * @param[in] * descrA descriptor of the sparse CSC matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * cscColPtr array of \p n+1 elements that point to the start of every column of * the sparse CSC matrix. * @param[inout] * cscRowInd array of \p nnz elements containing the row indices of the sparse * CSC matrix. * @param[inout] * P array of \p nnz integers containing the unsorted map indices, can be * \p NULL. * @param[in] * pBuffer temporary storage buffer allocated by the user, size is returned by * \ref hipsparseXcscsort_bufferSizeExt(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz, \p descrA, \p cscColPtr, * \p cscRowInd or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_cscsort.cpp doc example */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcscsort(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, const int* cscColPtr, int* cscRowInd, int* P, void* pBuffer); #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSCSORT_H */ ./library/include/internal/conversion/hipsparse_coo2csr.h0000664000175100017510000000752615176134511024012 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_COO2CSR_H #define HIPSPARSE_COO2CSR_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert a sparse COO matrix into a sparse CSR matrix * * \details * \p hipsparseXcoo2csr converts the COO array containing the row indices into a * CSR array of row offsets, that point to the start of every row. * It is assumed that the COO row index array is sorted and that all arrays have been allocated * prior to calling hipsparseXcoo2csr. * * For example, given the COO row indices array: * \f[ * \begin{align} * \text{cooRowInd} &= \begin{bmatrix} 0 & 0 & 1 & 2 & 2 & 4 & 4 & 4 \end{bmatrix} * \end{align} * \f] * * the resulting CSR row pointer array after calling \p hipsparseXcoo2csr is: * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 2 & 3 & 5 & 8 \end{bmatrix} * \end{align} * \f] * * \note It can also be used, to convert a COO array containing the column indices into * a CSC array of column offsets, that point to the start of every column. Then, it is * assumed that the COO column index array is sorted, instead. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * cooRowInd array of \p nnz elements containing the row indices of the sparse COO * matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * m number of rows of the sparse CSR matrix. * @param[out] * csrRowPtr array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p cooRowInd or \p csrRowPtr * pointer is invalid. * * \par Example * \snippet example_hipsparse_coo2csr.cpp doc example */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcoo2csr(hipsparseHandle_t handle, const int* cooRowInd, int nnz, int m, int* csrRowPtr, hipsparseIndexBase_t idxBase); #ifdef __cplusplus } #endif #endif /* HIPSPARSE_COO2CSR_H */ ./library/include/internal/conversion/hipsparse_csr2gebsr.h0000664000175100017510000005754115176134511024336 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSR2GEBSR_H #define HIPSPARSE_CSR2GEBSR_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a sparse GEBSR matrix * * \details * \p hipsparseXcsr2gebsr_bufferSize returns the size of the temporary buffer that * is required by \ref hipsparseXcsr2gebsrNnz and \ref hipsparseScsr2gebsr "hipsparseXcsr2gebsr()". * Once the temporary buffer size has been determined, it must be allocated by the user prior * to calling \ref hipsparseXcsr2gebsrNnz and \ref hipsparseScsr2gebsr "hipsparseXcsr2gebsr()". * * See hipsparseScsr2gebsr() for complete code example. * * \note * The routine does support asynchronous execution if the pointer mode is set to device. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dir direction that specified whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW * or by \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * csr_descr descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrVal array of \p nnz elements containing the values of the sparse CSR matrix. * @param[in] * csrRowPtr integer array containing \p m+1 elements that point to the start of each row of the CSR matrix * @param[in] * csrColInd integer array of the column indices for each non-zero element in the CSR matrix * @param[in] * rowBlockDim the row block dimension of the GEneral BSR matrix. Between 1 and \p m * @param[in] * colBlockDim the col block dimension of the GEneral BSR matrix. Between 1 and \p n * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by \ref hipsparseXcsr2gebsrNnz() * and \ref hipsparseScsr2gebsr "hipsparseXcsr2gebsr()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p rowBlockDim, \p colBlockDim, \p csrVal, * \p csrRowPtr, \p csrColInd or \p pBufferSizeInBytes pointer is invalid. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup conv_module * \brief * This function computes the number of nonzero block columns per row and the total number of nonzero blocks in a sparse * GEBSR matrix given a sparse CSR matrix as input. * * \details * This is the second step in conveting a CSR matrix to a GEBSR matrix. The user must first call * \ref hipsparseScsr2gebsr_bufferSize "hipsparseXcsr2gebsr_bufferSize()" to determine the size of * the required temporary storage buffer. The user then allocates this buffer as well as the * \p bsrRowPtr array ( size \p mb+1 ) and passes both to \p hipsparseXcsr2gebsrNnz(). This second * step then computes the number of nonzero block columns per row and the total number of nonzero blocks. * * In general, when converting a CSR matrix of size \p m x \p n to a GEBSR matrix, the resulting GEBSR matrix will have size * \p mb x \p nb where \p mb and \p nb equal: * \f[ * \begin{align} * \text{mb} &= \text{(m - 1) / rowBlockDim + 1} \\ * \text{nb} &= \text{(n - 1) / colBlockDim + 1} * \end{align} * \f] * * For example given a matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 & 4 & 0 \\ * 3 & 4 & 0 & 0 & 5 & 1 \\ * 5 & 0 & 6 & 7 & 6 & 2 * \end{bmatrix} * \f] * * represented in CSR format with the arrays: * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 3 & 7 & 12 \end{bmatrix} \\ * \text{csrColInd} &= \begin{bmatrix} 0 & 3 & 4 & 0 & 1 & 4 & 5 & 0 & 2 & 3 & 4 & 5 \end{bmatrix} \\ * \text{csrVal} &= \begin{bmatrix} 1 & 2 & 4 & 3 & 4 & 5 & 1 & 5 & 6 & 7 & 6 & 2 \end{bmatrix} * \end{align} * \f] * * the \p bsrRowPtr array and total nonzero block count will be filled with: * \f[ * \begin{align} * \text{bsrRowPtr} &= \begin{bmatrix} 0 & 3 \end{bmatrix} \\ * \text{*bsrNnzDevhost} &= 3 * \end{align} * \f] * * after calling \p hipsparseXcsr2gebsrNnz with \p rowBlockDim=3 and \p colBlockDim=2. * * \note * As indicated, \p bsrNnzDevhost can point either to host or device memory. This is controlled * by setting the pointer mode. See \ref hipsparseSetPointerMode(). * * It may be the case that \p rowBlockDim does not divide evenly into \p m and/or that \p colBlockDim does not divide * evenly into \p n. In these cases, the CSR matrix is expanded in size in order to fit full GEBSR blocks. For example, * using the original CSR matrix but this time with \p rowBlockDim=2 and \p colBlockDim=3, the function * \p hipsparseXcsr2gebsrNnz computes the GEBSR row pointer array and total number of non-zero blocks for the GEBSR matrix: * * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c c} * 1 & 0 & 0 \\ * 3 & 4 & 0 * \end{array} & * \begin{array}{c c c} * 2 & 4 & 0 \\ * 0 & 5 & 1 * \end{array} \\ * \hline * \begin{array}{c c c} * 5 & 0 & 6 \\ * 0 & 0 & 0 * \end{array} & * \begin{array}{c c c} * 7 & 6 & 2 \\ * 0 & 0 & 0 * \end{array} * \end{array} * \right] * \f] * * See hipsparseScsr2gebsr() for full code example. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dir direction that specified whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW or by * \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * csr_descr descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrRowPtr integer array containing \p m+1 elements that point to the start of each row of the CSR matrix * @param[in] * csrColInd integer array of the column indices for each non-zero element in the CSR matrix * @param[in] * bsr_descr descriptor of the sparse GEneral BSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * bsrRowPtr integer array containing \p mb+1 elements that point to the start of each block row of the General BSR matrix * * @param[in] * rowBlockDim the row block dimension of the GEneral BSR matrix. Between \f$1\f$ and \f$\min(m, n)\f$ * * @param[in] * colBlockDim the col block dimension of the GEneral BSR matrix. Between \f$1\f$ and \f$\min(m, n)\f$ * * @param[out] * bsrNnzDevhost total number of nonzero elements in device or host memory. * * @param[in] * pbuffer buffer allocated by the user whose size is determined by calling \ref hipsparseScsr2gebsr_bufferSize * "hipsparseXcsr2gebsr_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p rowBlockDim, \p colBlockDim, \p csrRowPtr, * \p csrColInd, \p bsrRowPtr or \p bsrNnzDevhost pointer is invalid. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsr2gebsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, int* bsrRowPtr, int rowBlockDim, int colBlockDim, int* bsrNnzDevhost, void* pbuffer); /*! \ingroup conv_module * \brief Convert a sparse CSR matrix into a sparse GEBSR matrix * * \details * \p hipsparseXcsr2gebsr converts a CSR matrix into a GEBSR matrix. It is assumed, * that \p bsrVal, \p bsrColInd and \p bsrRowPtr are allocated. Allocation size * for \p bsrRowPtr is computed as \p mb+1 where \p mb is the number of block rows in * the GEBSR matrix. The number of nonzero blocks in the resulting GEBSR matrix * is computed using \ref hipsparseXcsr2gebsrNnz which also fills in \p bsrRowPtr. * * In more detail, \p hipsparseXcsr2gebsr is the third and final step on the conversion from CSR to GEBSR. * The user first determines the size of the required user allocated temporary storage buffer using * \ref hipsparseScsr2gebsr_bufferSize "hipsparseXcsr2gebsr_bufferSize()". The user then allocates this buffer * as well as the row pointer array \p bsrRowPtr with size \p mb+1, where \p mb is the number of block rows * in the GEBSR matrix and \p nb is the number of block columns in GEBSR matrix: * * \f[ * \begin{align} * \text{mb} &= \text{(m - 1) / rowBlockDim + 1} \\ * \text{nb} &= \text{(n - 1) / colBlockDim + 1} * \end{align} * \f] * * Both the temporary storage buffer and the GEBSR row pointer array are then passed to \ref hipsparseXcsr2gebsrNnz * which fills the GEBSR row pointer array \p bsrRowPtr and also computes the number of nonzero blocks, * \p bsrNnzDevhost, that will exist in the GEBSR matrix. The user then allocates both the GEBSR column indices array * \p bsrColInd with size \p bsrNnzDevhost as well as the GEBSR values array \p bsrVal with size * \p bsrNnzDevhost*rowBlockDim*colBlockDim. Finally, with all arrays allocated, the conversion is completed by calling * \p hipsparseXcsr2gebsr. * * For example, assuming the matrix: * \f[ * \begin{bmatrix} * 1 & 0 & 0 & 2 & 4 & 0 \\ * 3 & 4 & 0 & 0 & 5 & 1 \\ * 5 & 0 & 6 & 7 & 6 & 2 * \end{bmatrix} * \f] * * represented in CSR format with the arrays: * \f[ * \begin{align} * \text{csrRowPtr} &= \begin{bmatrix} 0 & 3 & 7 & 12 \end{bmatrix} \\ * \text{csrColInd} &= \begin{bmatrix} 0 & 3 & 4 & 0 & 1 & 4 & 5 & 0 & 2 & 3 & 4 & 5 \end{bmatrix} \\ * \text{csrVal} &= \begin{bmatrix} 1 & 2 & 4 & 3 & 4 & 5 & 1 & 5 & 6 & 7 & 6 & 2 \end{bmatrix} * \end{align} * \f] * * then using \p rowBlockDim=3 and \p colBlockDim=2, the final GEBSR matrix is: * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c} * 1 & 0 \\ * 3 & 4 \\ * 3 & 0 * \end{array} & * \begin{array}{c c} * 0 & 2 \\ * 0 & 0 \\ * 6 & 7 * \end{array} & * \begin{array}{c c} * 4 & 0 \\ * 5 & 1 \\ * 6 & 2 * \end{array} * \end{array} * \right] * \f] * * and is represented with the arrays: * \f[ * \begin{align} * \text{bsrRowPtr} &= \begin{bmatrix} 0 & 3 \end{bmatrix} \\ * \text{bsrColInd} &= \begin{bmatrix} 0 & 1 & 2 \end{bmatrix} \\ * \text{bsrVal} &= \begin{bmatrix} 1 & 0 & 3 & 4 & 3 & 0 & 0 & 2 & 0 & 0 & 6 & 7 & 4 & 0 & 5 & 1 & 6 & 2 \end{bmatrix} * \end{align} * \f] * * The above example assumes that the blocks are row ordered. If instead the blocks are column ordered, the \p bsrVal arrays * becomes: * \f[ * \begin{align} * \text{bsrVal} &= \begin{bmatrix} 1 & 3 & 3 & 0 & 4 & 0 & 0 & 0 & 6 & 2 & 0 & 7 & 4 & 5 & 6 & 0 & 1 & 2 \end{bmatrix} * \end{align} * \f] * * The block order direction is determined by \p dir. * * It may be the case that \p rowBlockDim does not divide evenly into \p m and/or that \p colBlockDim does not divide * evenly into \p n. In these cases, the CSR matrix is expanded in size in order to fit full GEBSR blocks. For example, * using the original CSR matrix but this time with \p rowBlockDim=2 and \p colBlockDim=3, the resulting GEBSR matrix * would looks like: * * \f[ * \left[ * \begin{array}{c | c} * \begin{array}{c c c} * 1 & 0 & 0 \\ * 3 & 4 & 0 * \end{array} & * \begin{array}{c c c} * 2 & 4 & 0 \\ * 0 & 5 & 1 * \end{array} \\ * \hline * \begin{array}{c c c} * 5 & 0 & 6 \\ * 0 & 0 & 0 * \end{array} & * \begin{array}{c c c} * 7 & 6 & 2 \\ * 0 & 0 & 0 * \end{array} * \end{array} * \right] * \f] * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dir the storage format of the blocks, \ref HIPSPARSE_DIRECTION_ROW or \ref HIPSPARSE_DIRECTION_COLUMN * @param[in] * m number of rows in the sparse CSR matrix. * @param[in] * n number of columns in the sparse CSR matrix. * @param[in] * csr_descr descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrVal array of \p nnz elements containing the values of the sparse CSR matrix. * @param[in] * csrRowPtr array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrColInd array of \p nnz elements containing the column indices of the sparse CSR matrix. * @param[in] * bsr_descr descriptor of the sparse BSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * bsrVal array of \p nnzb* \p rowBlockDim* \p colBlockDim containing the values of the sparse BSR matrix. * @param[out] * bsrRowPtr array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[out] * bsrColInd array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * rowBlockDim row size of the blocks in the sparse GEneral BSR matrix. * @param[in] * colBlockDim col size of the blocks in the sparse GEneral BSR matrix. * @param[in] * pbuffer buffer allocated by the user whose size is determined by calling \ref hipsparseScsr2gebsr_bufferSize * "hipsparseXcsr2gebsr_bufferSize()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p rowBlockDim, \p colBlockDim, \p bsrVal, * \p bsrRowPtr, \p bsrColInd, \p csrVal, \p csrRowPtr or \p csrColInd pointer is invalid. * * \par Example * \snippet example_hipsparse_csr2gebsr.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, float* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, double* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipDoubleComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSR2GEBSR_H */ ./library/include/internal/precond/0000775000175100017510000000000015176134511017444 5ustar jenkinsjenkins./library/include/internal/precond/hipsparse_csrilu0.h0000664000175100017510000007644015176134511023267 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRILU0_H #define HIPSPARSE_CSRILU0_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXcsrilu02_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during \ref hipsparseScsrilu02 "hipsparseXcsrilu02()" * computation. The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ is stored in \p position, using same * index base as the CSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note \p hipsparseXcsrilu02_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info or \p position pointer is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrilu02_zeroPivot(hipsparseHandle_t handle, csrilu02Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXcsrilu02_numericBoost enables the user to replace a numerical value in * an incomplete LU factorization. \p tol is used to determine whether a numerical value * is replaced by \p boost_val, such that \f$A_{j,j} = \text{boost_val}\f$ if * \f$\text{tol} \ge \left|A_{j,j}\right|\f$. * * \note The boost value is enabled by setting \p enable_boost to 1 or disabled by * setting \p enable_boost to 0. * * \note \p tol and \p boost_val can be in host or device memory. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * enable_boost enable/disable numeric boost. * @param[in] * tol tolerance to determine whether a numerical value is replaced or not. * @param[in] * boost_val boost value to replace a numerical value. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info, \p tol or \p boost_val pointer * is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, float* boost_val); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, double* boost_val); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXcsrilu02_bufferSize returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseScsrilu02_analysis "hipsparseXcsrilu02_analysis()" * and \ref hipsparseScsrilu02 "hipsparseXcsrilu02()". The temporary storage buffer * must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseScsrilu02_analysis "hipsparseXcsrilu02_analysis()" and * \ref hipsparseScsrilu02 "hipsparseXcsrilu02()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBufferSizeInBytes pointer * is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes); /**@}*/ #endif /*! \ingroup precond_module * \details * \p hipsparseXcsrilu02_bufferSizeExt returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseScsrilu02_analysis "hipsparseXcsrilu02_analysis()" * and \ref hipsparseScsrilu02 "hipsparseXcsrilu02()". The temporary storage buffer * must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseScsrilu02_analysis "hipsparseXcsrilu02_analysis()" and * \ref hipsparseScsrilu02 "hipsparseXcsrilu02()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBufferSizeInBytes pointer * is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes); /**@}*/ #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXcsrilu02_analysis performs the analysis step for \ref hipsparseScsrilu02 * "hipsparseXcsrilu02()". It is expected that this function will be executed only once for * a given matrix and particular operation type. * * \note * If the matrix sparsity pattern changes, the gathered information will become invalid. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during * the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \brief Incomplete LU factorization with 0 fill-ins and no pivoting using CSR * storage format * * \details * \p hipsparseXcsrilu02 computes the incomplete LU factorization with 0 fill-ins and no * pivoting of a sparse \f$m \times m\f$ CSR matrix \f$A\f$, such that * \f[ * A \approx LU * \f] * where the lower triangular matrix \f$L\f$ and the upper triangular matrix \f$U\f$ are computed using: * \f[ * \begin{array}{ll} * L_{ij} = \frac{1}{U_{jj}}(A_{ij} - \sum_{k=0}^{j-1}L_{ik} \times U_{kj}), & \text{if i > j} \\ * U_{ij} = (A_{ij} - \sum_{k=0}^{j-1}L_{ik} \times U_{kj}), & \text{if i <= j} * \end{array} * \f] * for each entry found in the CSR matrix \f$A\f$. * * Computing the above incomplete \f$LU\f$ factorization requires three steps to complete. First, * the user determines the size of the required temporary storage buffer by calling * \ref hipsparseScsrilu02_bufferSize "hipsparseXcsrilu02_bufferSize()". Once this buffer size has been determined, * the user allocates the buffer and passes it to \ref hipsparseScsrilu02_analysis "hipsparseXcsrilu02_analysis()". * This will perform analysis on the sparsity pattern of the matrix. Finally, the user calls \p hipsparseScsrilu02, * \p hipsparseDcsrilu02, \p hipsparseCcsrilu02, or \p hipsparseZcsrilu02 to perform the actual factorization. The calculation * of the buffer size and the analysis of the sparse matrix only need to be performed once for a given sparsity pattern * while the factorization can be repeatedly applied to multiple matrices having the same sparsity pattern. Once all calls * to \ref hipsparseScsrilu02 "hipsparseXcsrilu02()" are complete, the temporary buffer can be deallocated. * * When computing the \f$LU\f$ factorization, it is possible that \f$U_{jj} == 0\f$ which would result in a division by zero. * This could occur from either \f$A_{jj}\f$ not existing in the sparse CSR matrix (referred to as a structural zero) or because * \f$A_{ij} - \sum_{k=0}^{j-1}L_{ik} \times U_{kj} == 0\f$ (referred to as a numerical zero). For example, running the * \f$LU\f$ factorization on the following matrix: * \f[ * \begin{bmatrix} * 2 & 1 & 0 \\ * 1 & 2 & 1 \\ * 0 & 1 & 2 * \end{bmatrix} * \f] * results in a successful \f$LU\f$ factorization, however running with the matrix: * \f[ * \begin{bmatrix} * 2 & 1 & 0 \\ * 1 & 1/2 & 1 \\ * 0 & 1 & 2 * \end{bmatrix} * \f] * results in a numerical zero because: * \f[ * \begin{array}{ll} * U_{00} &= 2 \\ * U_{01} &= 1 \\ * L_{10} &= \frac{1}{2} \\ * U_{11} &= \frac{1}{2} - \frac{1}{2} * &= 0 * \end{array} * \f] * The user can detect the presence of a structural zero by calling \ref hipsparseXcsrilu02_zeroPivot() after * \ref hipsparseScsrilu02_analysis "hipsparseXcsrilu02_analysis()" and/or the presence of a structural or * numerical zero by calling \ref hipsparseXcsrilu02_zeroPivot() after \ref hipsparseScsrilu02 "hipsparseXcsrilu02()". * In both cases, \ref hipsparseXcsrilu02_zeroPivot() will report the first zero pivot (either numerical or structural) * found. See example below. The user can also set the diagonal type to be \f$1\f$ using \ref hipsparseSetMatDiagType() * which will interpret the matrix \f$A\f$ as having ones on its diagonal (even if no nonzero exists in the sparsity pattern). * * \p hipsparseXcsrilu02 computes the \f$LU\f$ factorization inplace meaning that the values array \p csrSortedValA_valM of the \f$A\f$ * matrix is overwritten with the \f$L\f$ matrix stored in the strictly lower triangular part of \f$A\f$ and the \f$U\f$ matrix * stored in the upper part of \f$A\f$: * * \f[ * \begin{align} * \begin{bmatrix} * a_{00} & a_{01} & a_{02} \\ * a_{10} & a_{11} & a_{12} \\ * a_{20} & a_{21} & a_{22} * \end{bmatrix} * \rightarrow * \begin{bmatrix} * u_{00} & u_{01} & u_{02} \\ * l_{10} & u_{11} & u_{12} \\ * l_{20} & l_{21} & u_{22} * \end{bmatrix} * \end{align} * \f] * The row pointer array \p csrSortedRowPtrA and the column indices array \p csrSortedColIndA remain the same for \f$A\f$ and \f$LU\f$ as * the incomplete factorization does not generate new nonzeros in \f$LU\f$ which do not already exist in \f$A\f$. * * The performance of computing \f$LU\f$ factorization with hipSPARSE greatly depends on the sparisty pattern * the the matrix \f$A\f$ as this is what determines the amount of parallelism available. * * \note * The sparse CSR matrix has to be sorted. This can be achieved by calling * \ref hipsparseXcsrsort(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[inout] * csrSortedValA_valM array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start * of every row of the sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA_valM, * \p csrSortedRowPtrA or \p csrSortedColIndA pointer is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_csrilu02.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRILU0_H */ ./library/include/internal/precond/hipsparse_gtsv.h0000664000175100017510000002431715176134511022665 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GTSV_H #define HIPSPARSE_GTSV_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup precond_module * \details * \p hipsparseSgtsv2_bufferSizeExt returns the size of the temporary storage buffer * that is required by \ref hipsparseSgtsv2 "hipsparseXgtsv2()". The temporary * storage buffer must be allocated by the user. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * This routine supports execution in a hipGraph context. * * @param[in] * handle handle to the hipSPARSE library context queue. * @param[in] * m size of the tri-diagonal linear system (must be >= 2). * @param[in] * n number of columns in the dense matrix B. * @param[in] * dl lower diagonal of tri-diagonal system. First entry must be zero. * @param[in] * d main diagonal of tri-diagonal system. * @param[in] * du upper diagonal of tri-diagonal system. Last entry must be zero. * @param[in] * B Dense matrix of size ( \p ldb, \p n ). * @param[in] * ldb Leading dimension of B. Must satisfy \p ldb >= max(1, m). * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseSgtsv2 "hipsparseXgtsv2()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ldb, \p dl, \p d, \p du, * \p B or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup precond_module * \brief Tridiagonal solver with pivoting * * \details * \p hipsparseXgtsv2 solves a tridiagonal system for multiple right hand sides using pivoting * \f[ * T*B = B * \f] * where \f$T\f$ is a sparse tridiagonal matrix and \f$B\f$ is a dense \f$ldb \times n\f$ matrix storing the * right-hand side vectors in column order. The tridiagonal matrix \f$T\f$ is defined by three vectors: \p dl * for the lower diagonal, \p d for the main diagonal and \p du for the upper diagonal. * * Solving the tridiagonal system involves two steps. First, the user calls * \ref hipsparseSgtsv2_bufferSizeExt "hipsparseXgtsv2_bufferSizeExt()" in order to determine the size of the required * temporary storage buffer. Once determined, the user allocates this buffer and passes it to * \ref hipsparseSgtsv2 "hipsparseXgtsv2()" to perform the actual solve. The \f$B\f$ dense matrix, which initially * stores the \p n right-hand side vectors, is overwritten with the \p n solution vectors after the call to * \ref hipsparseSgtsv2 "hipsparseXgtsv2()". * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * This routine supports execution in a hipGraph context. * * @param[in] * handle handle to the hipSPARSE library context queue. * @param[in] * m size of the tri-diagonal linear system (must be >= 2). * @param[in] * n number of columns in the dense matrix B. * @param[in] * dl lower diagonal of tri-diagonal system. First entry must be zero. * @param[in] * d main diagonal of tri-diagonal system. * @param[in] * du upper diagonal of tri-diagonal system. Last entry must be zero. * @param[inout] * B Dense matrix of size ( \p ldb, \p n ). * @param[in] * ldb Leading dimension of B. Must satisfy \p ldb >= max(1, m). * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ldb, \p dl, \p d, * \p du, \p B or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_gtsv.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsv2(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsv2(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsv2(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsv2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GTSV_H */ ./library/include/internal/precond/hipsparse_gpsv_interleaved_batch.h0000664000175100017510000003562615176134511026411 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GPSV_INTERLEAVED_BATCH_H #define HIPSPARSE_GPSV_INTERLEAVED_BATCH_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup precond_module * \details * \p hipsparseXgpsvInterleavedBatch_bufferSizeExt returns the size of the temporary storage * buffer in bytes that is required by \ref hipsparseSgpsvInterleavedBatch "hipsparseXgpsvInterleavedBatch()". * The temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * algo algorithm to solve the linear system. * @param[in] * m size of the pentadiagonal linear system. * @param[in] * ds lower diagonal (distance 2) of pentadiagonal system. First two entries * must be zero. * @param[in] * dl lower diagonal of pentadiagonal system. First entry must be zero. * @param[in] * d main diagonal of pentadiagonal system. * @param[in] * du upper diagonal of pentadiagonal system. Last entry must be zero. * @param[in] * dw upper diagonal (distance 2) of pentadiagonal system. Last two entries * must be zero. * @param[in] * x Dense array of right-hand-sides with dimension \p batchCount by \p m. * @param[in] * batchCount The number of systems to solve. * @param[out] * pBufferSizeInBytes Number of bytes of the temporary storage buffer required. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p alg, \p batchCount, \p ds, \p dl, * \p d, \p du, \p dw, \p x or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* ds, const float* dl, const float* d, const float* du, const float* dw, const float* x, int batchCount, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* ds, const double* dl, const double* d, const double* du, const double* dw, const double* x, int batchCount, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* ds, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* dw, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* ds, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* dw, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup precond_module * \brief Interleaved Batch pentadiagonal solver * * \details * \p hipsparseXgpsvInterleavedBatch solves a batch of pentadiagonal linear systems * \f[ * P^{i}*x^{i} = x^{i} * \f] * where for each batch \f$i=0\ldots\f$ \p batchCount, \f$P^{i}\f$ is a sparse pentadiagonal matrix and * \f$x^{i}\f$ is a dense right-hand side vector. All of the pentadiagonal matrices, \f$P^{i}\f$, are * packed in an interleaved fashion into five vectors: \p ds for the lowest diagonals, \p dl for the lower * diagonals, \p d for the main diagonals, \p du for the upper diagonals, and \p dw for the highest digaonals. * See below for a description of what this interleaved memory pattern looks like. * * Solving the batched pentadiagonal system involves two steps. First, the user calls * \ref hipsparseSgpsvInterleavedBatch_bufferSizeExt "hipsparseSgpsvInterleavedBatch_bufferSizeExt()" * in order to determine the size of the required temporary storage buffer. Once determined, the user allocates * this buffer and passes it to \ref hipsparseSgpsvInterleavedBatch "hipsparseXgpsvInterleavedBatch()" * to perform the actual solve. The \f$x^{i}\f$ vectors, which initially stores the right-hand side values, are * overwritten with the solution after the call to * \ref hipsparseSgpsvInterleavedBatch "hipsparseXgpsvInterleavedBatch()". * * Unlike the strided batch routines which write each batch matrix one after the other in memory, the interleaved * routines write the batch matrices such that each element from each matrix is written consecutively one after * the other. For example, consider the following batch matrices: * * \f[ * \begin{bmatrix} * t^{0}_{00} & t^{0}_{01} & t^{0}_{02} \\ * t^{0}_{10} & t^{0}_{11} & t^{0}_{12} \\ * t^{0}_{20} & t^{0}_{21} & t^{0}_{22} * \end{bmatrix} * \begin{bmatrix} * t^{1}_{00} & t^{1}_{01} & t^{1}_{02} \\ * t^{1}_{10} & t^{1}_{11} & t^{1}_{12} \\ * t^{1}_{20} & t^{1}_{21} & t^{1}_{22} * \end{bmatrix} * \begin{bmatrix} * t^{2}_{00} & t^{2}_{01} & t^{2}_{02} \\ * t^{2}_{10} & t^{2}_{11} & t^{2}_{12} \\ * t^{2}_{20} & t^{2}_{21} & t^{2}_{22} * \end{bmatrix} * \f] * * In interleaved format, the highest, higher, lowest, lower, and diagonal arrays would look like: * \f[ * \begin{align} * \text{lowest} &= \begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & t^{0}_{20} & t^{1}_{20} & t^{2}_{20} \end{bmatrix} \\ * \text{lower} &= \begin{bmatrix} 0 & 0 & 0 & t^{0}_{10} & t^{1}_{10} & t^{1}_{10} & t^{0}_{21} & t^{1}_{21} & t^{2}_{21} \end{bmatrix} \\ * \text{diagonal} &= \begin{bmatrix} t^{0}_{00} & t^{1}_{00} & t^{2}_{00} & t^{0}_{11} & t^{1}_{11} & t^{2}_{11} & t^{0}_{22} & t^{1}_{22} & t^{2}_{22} \end{bmatrix} \\ * \text{higher} &= \begin{bmatrix} t^{0}_{01} & t^{1}_{01} & t^{2}_{01} & t^{0}_{12} & t^{1}_{12} & t^{2}_{12} & 0 & 0 & 0 \end{bmatrix} \\ * \text{highest} &= \begin{bmatrix} t^{0}_{02} & t^{1}_{02} & t^{2}_{02} & 0 & 0 & 0 & 0 & 0 & 0 \end{bmatrix} \\ * \end{align} * \f] * For the lowest array, the first \p 2*batchCount entries are zero, for the lower array, the first \p batchCount entries are zero, * for the upper array the last \p batchCount entries are zero, and for the highest array, the last \p 2*batchCount entries are zero. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * algo algorithm to solve the linear system. * @param[in] * m size of the pentadiagonal linear system. * @param[inout] * ds lower diagonal (distance 2) of pentadiagonal system. First two entries * must be zero. * @param[inout] * dl lower diagonal of pentadiagonal system. First entry must be zero. * @param[inout] * d main diagonal of pentadiagonal system. * @param[inout] * du upper diagonal of pentadiagonal system. Last entry must be zero. * @param[inout] * dw upper diagonal (distance 2) of pentadiagonal system. Last two entries * must be zero. * @param[inout] * x Dense array of right-hand-sides with dimension \p batchCount by \p m. * @param[in] * batchCount The number of systems to solve. * @param[in] * pBuffer Temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p alg, \p batchCount, \p ds, * \p dl, \p d, \p du, \p dw, \p x or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* ds, float* dl, float* d, float* du, float* dw, float* x, int batchCount, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* ds, double* dl, double* d, double* du, double* dw, double* x, int batchCount, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* ds, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* dw, hipComplex* x, int batchCount, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* ds, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* dw, hipDoubleComplex* x, int batchCount, void* pBuffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GPSV_INTERLEAVED_BATCH_H */ ./library/include/internal/precond/hipsparse_csric0.h0000664000175100017510000007214515176134511023067 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRIC0_H #define HIPSPARSE_CSRIC0_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXcsric02_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during \ref hipsparseScsric02_analysis * "hipsparseXcsric02_analysis()" or \ref hipsparseScsric02 "hipsparseXcsric02()" * computation. The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ is stored in \p position, * using same index base as the CSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note \p hipsparseXcsric02_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info or \p position pointer is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsric02_zeroPivot(hipsparseHandle_t handle, csric02Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXcsric02_bufferSize returns the size of the temporary storage buffer in bytes * that is required by \ref hipsparseScsric02_analysis "hipsparseXcsric02_analysis()" and * \ref hipsparseScsric02 "hipsparseXcsric02()". The temporary storage buffer must be allocated * by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseScsric02_analysis "hipsparseXcsric02_analysis()" and * \ref hipsparseScsric02 "hipsparseXcsric02()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBufferSizeInBytes pointer is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes); /**@}*/ #endif /*! \ingroup precond_module * \details * \p hipsparseXcsric02_bufferSizeExt returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseScsric02_analysis "hipsparseXcsric02_analysis()" * and \ref hipsparseScsric02 "hipsparseXcsric02()". The temporary storage buffer must be * allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseScsric02_analysis "hipsparseXcsric02_analysis()" and * \ref hipsparseScsric02 "hipsparseXcsric02()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBufferSizeInBytes pointer is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes); /**@}*/ #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXcsric02_analysis performs the analysis step for \ref hipsparseScsric02 * "hipsparseXcsric02()". * * \note * If the matrix sparsity pattern changes, the gathered information will become invalid. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during * the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \brief Incomplete Cholesky factorization with 0 fill-ins and no pivoting using CSR * storage format * * \details * \p hipsparseXcsric02 computes the incomplete Cholesky factorization with 0 fill-ins * and no pivoting of a sparse \f$m \times m\f$ CSR matrix \f$A\f$, such that * \f[ * A \approx LL^T * \f] * where the lower triangular matrix \f$L\f$ is computed using: * \f[ * L_{ij} = \left\{ * \begin{array}{ll} * \sqrt{A_{jj} - \sum_{k=0}^{j-1}(L_{jk})^{2}}, & \text{if i == j} \\ * \frac{1}{L_{jj}}(A_{jj} - \sum_{k=0}^{j-1}L_{ik} \times L_{jk}), & \text{if i > j} * \end{array} * \right. * \f] * for each entry found in the CSR matrix \f$A\f$. * * Computing the above incomplete Cholesky factorization requires three steps to complete. First, * the user determines the size of the required temporary storage buffer by calling * \ref hipsparseScsric02_bufferSize "hipsparseXcsric02_bufferSize()". Once this buffer size has been determined, * the user allocates the buffer and passes it to \ref hipsparseScsric02_analysis "hipsparseXcsric02_analysis()". * This will perform analysis on the sparsity pattern of the matrix. Finally, the user calls \p hipsparseScsric02, * \p hipsparseDcsric02, \p hipsparseCcsric02, or \p hipsparseZcsric02 to perform the actual factorization. The calculation * of the buffer size and the analysis of the sparse matrix only need to be performed once for a given sparsity pattern * while the factorization can be repeatedly applied to multiple matrices having the same sparsity pattern. Once all calls * to \ref hipsparseScsric02 "hipsparseXcsric02()" are complete, the temporary buffer can be deallocated. * * When computing the Cholesky factorization, it is possible that \f$L_{jj} == 0\f$ which would result in a division by zero. * This could occur from either \f$A_{jj}\f$ not existing in the sparse CSR matrix (referred to as a structural zero) or because * \f$A_{jj} - \sum_{k=0}^{j-1}(L_{jk})^{2} == 0\f$ (referred to as a numerical zero). For example, running the Cholesky * factorization on the following matrix: * \f[ * \begin{bmatrix} * 2 & 1 & 0 \\ * 1 & 2 & 1 \\ * 0 & 1 & 2 * \end{bmatrix} * \f] * results in a successful Cholesky factorization, however running with the matrix: * \f[ * \begin{bmatrix} * 2 & 1 & 0 \\ * 1 & 1/2 & 1 \\ * 0 & 1 & 2 * \end{bmatrix} * \f] * results in a numerical zero because: * \f[ * \begin{array}{ll} * L_{00} &= \sqrt{2} \\ * L_{10} &= \frac{1}{\sqrt{2}} \\ * L_{11} &= \sqrt{\frac{1}{2} - (\frac{1}{\sqrt{2}})^2} * &= 0 * \end{array} * \f] * The user can detect the presence of a structural zero by calling \ref hipsparseXcsric02_zeroPivot() after * \ref hipsparseScsric02_analysis "hipsparseXcsric02_analysis()" and/or the presence of a structural or * numerical zero by calling \ref hipsparseXcsric02_zeroPivot() after \ref hipsparseScsric02 "hipsparseXcsric02()": * \code{.c} * hipsparseDcsric02(handle, * m, * nnz, * descrM, * csrVal, * csrRowPtr, * csrColInd, * info, * HIPSPARSE_SOLVE_POLICY_USE_LEVEL, * buffer); * * // Check for zero pivot * if(CUSPARSE_STATUS_ZERO_PIVOT == hipsparseXcsric02_zeroPivot(handle, info, &position)) * { * printf("L has structural and/or numerical zero at L(%d,%d)\n", position, position); * } * \endcode * In both cases, \ref hipsparseXcsric02_zeroPivot() will report the first zero pivot (either numerical or structural) * found. See full example below. The user can also set the diagonal type to be \f$1\f$ using \ref hipsparseSetMatDiagType() * which will interpret the matrix \f$A\f$ as having ones on its diagonal (even if no nonzero exists in the sparsity pattern). * * \p hipsparseXcsric02 computes the Cholesky factorization inplace meaning that the values array \p csrSortedValA_valM of the \f$A\f$ * matrix is overwritten with the \f$L\f$ matrix stored in the lower triangular part of \f$A\f$: * * \f[ * \begin{align} * \begin{bmatrix} * a_{00} & a_{01} & a_{02} \\ * a_{10} & a_{11} & a_{12} \\ * a_{20} & a_{21} & a_{22} * \end{bmatrix} * \rightarrow * \begin{bmatrix} * l_{00} & a_{01} & a_{02} \\ * l_{10} & l_{11} & a_{12} \\ * l_{20} & l_{21} & l_{22} * \end{bmatrix} * \end{align} * \f] * The row pointer array \p csrSortedRowPtrA and the column indices array \p csrSortedColIndA remain the same for \f$A\f$ and the * output as the incomplete factorization does not generate new nonzeros in the output which do not already exist in \f$A\f$. * * The performance of computing Cholesky factorization with hipSPARSE greatly depends on the sparisty pattern * the the matrix \f$A\f$ as this is what determines the amount of parallelism available. * * \note * The sparse CSR matrix has to be sorted. This can be achieved by calling * \ref hipsparseXcsrsort(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[inout] * csrSortedValA_valM array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start * of every row of the sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA_valM, * \p csrSortedRowPtrA or \p csrSortedColIndA pointer is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csric02.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRIC0_H */ ./library/include/internal/precond/hipsparse_gtsv_nopivot.h0000664000175100017510000002524415176134511024443 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GTSV_NOPIVOT_H #define HIPSPARSE_GTSV_NOPIVOT_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup precond_module * \details * \p hipsparseXgtsv2_nopivot_bufferSizeExt returns the size of the temporary storage * buffer in bytes that is required by \ref hipsparseSgtsv2_nopivot "hipsparseXgtsv2_nopivot()". * The temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m size of the tri-diagonal linear system (must be >= 2). * @param[in] * n number of columns in the dense matrix B. * @param[in] * dl lower diagonal of tri-diagonal system. First entry must be zero. * @param[in] * d main diagonal of tri-diagonal system. * @param[in] * du upper diagonal of tri-diagonal system. Last entry must be zero. * @param[in] * B Dense matrix of size ( \p ldb, \p n ). * @param[in] * ldb Leading dimension of B. Must satisfy \p ldb >= max(1, m). * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSgtsv2_nopivot "hipsparseXgtsv2_nopivot()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ldb, \p dl, \p d, \p du, * \p B or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup precond_module * \brief Tridiagonal solver (no pivoting) * * \details * \p hipsparseXgtsv2_nopivot solves a tridiagonal linear system for multiple right-hand sides without pivoting * \f[ * T*B = B * \f] * where \f$T\f$ is a sparse tridiagonal matrix and \f$B\f$ is a dense \f$ldb \times n\f$ matrix storing the * right-hand side vectors in column order. The tridiagonal matrix \f$T\f$ is defined by three vectors: \p dl * for the lower diagonal, \p d for the main diagonal and \p du for the upper diagonal. * * Solving the tridiagonal system with multiple right-hand sides without pivoting involves two steps. First, * the user calls \ref hipsparseSgtsv2_nopivot_bufferSizeExt "hipsparseXgtsv2_nopivot_bufferSizeExt()" in order * to determine the size of the required temporary storage buffer. Once determined, the user allocates this * buffer and passes it to \ref hipsparseSgtsv2_nopivot "hipsparseXgtsv2_nopivot()" to perform the actual * solve. The \f$B\f$ dense matrix, which initially stores the \p n right-hand side vectors, is overwritten * with the \p n solution vectors after the call to \ref hipsparseSgtsv2_nopivot "hipsparseXgtsv2_nopivot()". * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m size of the tri-diagonal linear system (must be >= 2). * @param[in] * n number of columns in the dense matrix B. * @param[in] * dl lower diagonal of tri-diagonal system. First entry must be zero. * @param[in] * d main diagonal of tri-diagonal system. * @param[in] * du upper diagonal of tri-diagonal system. Last entry must be zero. * @param[inout] * B Dense matrix of size ( \p ldb, \p n ). * @param[in] * ldb Leading dimension of B. Must satisfy \p ldb >= max(1, m). * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p ldb, \p dl, \p d, * \p du, \p B or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_gtsv_no_pivot.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GTSV_NOPIVOT_H */ ./library/include/internal/precond/hipsparse_gtsv_interleaved_batch.h0000664000175100017510000003272015176134511026405 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GTSV_INTERLEAVED_BATCH_H #define HIPSPARSE_GTSV_INTERLEAVED_BATCH_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup precond_module * \details * \p hipsparseXgtsvInterleavedBatch_bufferSizeExt returns the size of the temporary storage * buffer in bytes that is required by \ref hipsparseSgtsvInterleavedBatch "hipsparseXgtsvInterleavedBatch()". * The temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * algo Algorithm to use when solving tridiagonal systems. Options are thomas ( \p algo=0 ), * LU ( \p algo=1 ), or QR ( \p algo=2 ). Thomas algorithm is the fastest but is not * stable while LU and QR are slower but are stable. * @param[in] * m size of the tri-diagonal linear system. * @param[in] * dl lower diagonal of tri-diagonal system. The first element of the lower diagonal must be zero. * @param[in] * d main diagonal of tri-diagonal system. * @param[in] * du upper diagonal of tri-diagonal system. The last element of the upper diagonal must be zero. * @param[inout] * x Dense array of righthand-sides with dimension \p batchCount by \p m. * @param[in] * batchCount The number of systems to solve. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseSgtsvInterleavedBatch "hipsparseSgtsvInterleavedBatch()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p batchCount, \p dl, \p d, \p du, * \p x or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup precond_module * \brief Interleaved Batch tridiagonal solver * * \details * \p hipsparseXgtsvInterleavedBatch solves a batched tridiagonal linear system * \f[ * T^{i}*x^{i} = x^{i} * \f] * where for each batch \f$i=0\ldots\f$ \p batchCount, \f$T^{i}\f$ is a sparse tridiagonal matrix and * \f$x^{i}\f$ is a dense right-hand side vector. All of the tridiagonal matrices, \f$T^{i}\f$, are * packed in an interleaved fashion into three vectors: \p dl for the lower diagonals, \p d for the main * diagonals and \p du for the upper diagonals. See below for a description of what this interleaved * memory pattern looks like. * * Solving the batched tridiagonal system involves two steps. First, the user calls * \ref hipsparseSgtsvInterleavedBatch_bufferSizeExt "hipsparseXgtsvInterleavedBatch_bufferSizeExt()" * in order to determine the size of the required temporary storage buffer. Once determined, the user allocates * this buffer and passes it to \ref hipsparseSgtsvInterleavedBatch "hipsparseXgtsvInterleavedBatch()" * to perform the actual solve. The \f$x^{i}\f$ vectors, which initially stores the right-hand side values, are * overwritten with the solution after the call to * \ref hipsparseSgtsvInterleavedBatch "hipsparseXgtsvInterleavedBatch()". * * The user can specify different algorithms for \p hipsparseXgtsvInterleavedBatch * to use. Options are thomas ( \p algo=0 ), * LU ( \p algo=1 ), or QR ( \p algo=2 ). * * Unlike the strided batch routines which write each batch matrix one after the other in memory, the interleaved * routines write the batch matrices such that each element from each matrix is written consecutively one after * the other. For example, consider the following batch matrices: * * \f[ * \begin{bmatrix} * t^{0}_{00} & t^{0}_{01} & 0 \\ * t^{0}_{10} & t^{0}_{11} & t^{0}_{12} \\ * 0 & t^{0}_{21} & t^{0}_{22} * \end{bmatrix} * \begin{bmatrix} * t^{1}_{00} & t^{1}_{01} & 0 \\ * t^{1}_{10} & t^{1}_{11} & t^{1}_{12} \\ * 0 & t^{1}_{21} & t^{1}_{22} * \end{bmatrix} * \begin{bmatrix} * t^{2}_{00} & t^{2}_{01} & 0 \\ * t^{2}_{10} & t^{2}_{11} & t^{2}_{12} \\ * 0 & t^{2}_{21} & t^{2}_{22} * \end{bmatrix} * \f] * * In interleaved format, the upper, lower, and diagonal arrays would look like: * \f[ * \begin{align} * \text{lower} &= \begin{bmatrix} 0 & 0 & 0 & t^{0}_{10} & t^{1}_{10} & t^{1}_{10} & t^{0}_{21} & t^{1}_{21} & t^{2}_{21} \end{bmatrix} \\ * \text{diagonal} &= \begin{bmatrix} t^{0}_{00} & t^{1}_{00} & t^{2}_{00} & t^{0}_{11} & t^{1}_{11} & t^{2}_{11} & t^{0}_{22} & t^{1}_{22} & t^{2}_{22} \end{bmatrix} \\ * \text{upper} &= \begin{bmatrix} t^{0}_{01} & t^{1}_{01} & t^{2}_{01} & t^{0}_{12} & t^{1}_{12} & t^{2}_{12} & 0 & 0 & 0 \end{bmatrix} \\ * \end{align} * \f] * For the lower array, the first \p batchCount entries are zero and for the upper array the last \p batchCount * entries are zero. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * algo Algorithm to use when solving tridiagonal systems. Options are thomas ( \p algo=0 ), * LU ( \p algo=1 ), or QR ( \p algo=2 ). Thomas algorithm is the fastest but is not * stable while LU and QR are slower but are stable. * @param[in] * m size of the tri-diagonal linear system. * @param[inout] * dl lower diagonal of tri-diagonal system. The first element of the lower diagonal must be zero. * @param[inout] * d main diagonal of tri-diagonal system. * @param[inout] * du upper diagonal of tri-diagonal system. The last element of the upper diagonal must be zero. * @param[inout] * x Dense array of righthand-sides with dimension \p batchCount by \p m. * @param[in] * batchCount The number of systems to solve. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p batchCount, \p dl, \p d, * \p du, \p x or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * * \par Example * \snippet example_hipsparse_gtsv_interleaved_batch.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* dl, float* d, float* du, float* x, int batchCount, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* dl, double* d, double* du, double* x, int batchCount, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* x, int batchCount, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, void* pBuffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GTSV_INTERLEAVED_BATCH_H */ ./library/include/internal/precond/hipsparse_bsrilu0.h0000664000175100017510000006610015176134511023256 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSRILU0_H #define HIPSPARSE_BSRILU0_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXbsrilu02_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during \ref hipsparseSbsrilu02_analysis * "hipsparseXbsrilu02_analysis()" or \ref hipsparseSbsrilu02 "hipsparseXbsrilu02()" * computation. The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ is stored in \p position, * using same index base as the BSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note * If a zero pivot is found, \p position \f$=j\f$ means that either the diagonal block * \f$A_{j,j}\f$ is missing (structural zero) or the diagonal block \f$A_{j,j}\f$ is not * invertible (numerical zero). * * \note \p hipsparseXbsrilu02_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info or \p position pointer is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXbsrilu02_zeroPivot(hipsparseHandle_t handle, bsrilu02Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXbsrilu02_numericBoost enables the user to replace a numerical value in * an incomplete LU factorization. \p tol is used to determine whether a numerical value * is replaced by \p boost_val, such that \f$A_{j,j} = \text{boost_val}\f$ if * \f$\text{tol} \ge \left|A_{j,j}\right|\f$. * * \note The boost value is enabled by setting \p enable_boost to 1 or disabled by * setting \p enable_boost to 0. * * \note \p tol and \p boost_val can be in host or device memory. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * enable_boost enable/disable numeric boost. * @param[in] * tol tolerance to determine whether a numerical value is replaced or not. * @param[in] * boost_val boost value to replace a numerical value. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info, \p tol or \p boost_val pointer * is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, float* boost_val); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, double* boost_val); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXbsrilu02_bufferSize returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseSbsrilu02_analysis "hipsparseXbsrilu02_analysis()" * and \ref hipsparseSbsrilu02 "hipsparseXbsrilu02()". The temporary storage buffer must be * allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA direction that specifies whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW * or by \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * mb number of block rows in the sparse BSR matrix. * @param[in] * nnzb number of non-zero block entries of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrSortedValA array of length \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * blockDim the block dimension of the BSR matrix. Between 1 and m where \p m=mb*blockDim. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSbsrilu02_analysis(), hipsparseDbsrilu02_analysis(), * hipsparseCbsrilu02_analysis(), hipsparseZbsrilu02_analysis(), * hipsparseSbsrilu02(), hipsparseDbsrilu02(), hipsparseCbsrilu02() * and hipsparseZbsrilu02(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, \p descrA, * \p bsrSortedValA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, \p info or * \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXbsrilu02_analysis performs the analysis step for \ref hipsparseSbsrilu02 * "hipsparseXbsrilu02()". It is expected that this function will be executed only once * for a given matrix. * * \note * If the matrix sparsity pattern changes, the gathered information will become invalid. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA direction that specified whether to count nonzero elements by * \ref HIPSPARSE_DIRECTION_ROW or by \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * mb number of block rows in the sparse BSR matrix. * @param[in] * nnzb number of non-zero block entries of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrSortedValA array of length \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * blockDim the block dimension of the BSR matrix. Between 1 and m where \p m=mb*blockDim. * @param[out] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, \p descrA, * \p bsrSortedValA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, \p info or \p pBuffer pointer * is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \brief Incomplete LU factorization with 0 fill-ins and no pivoting using BSR storage * format * * \details * \p hipsparseXbsrilu02 computes the incomplete LU factorization with 0 fill-ins and no * pivoting of a sparse \f$mb \times mb\f$ BSR matrix \f$A\f$, such that * \f[ * A \approx LU * \f] * * Computing the above incomplete LU factorization requires three steps to complete. First, * the user determines the size of the required temporary storage buffer by calling * \ref hipsparseSbsrilu02_bufferSize "hipsparseXbsrilu02_bufferSize()". Once this buffer size * has been determined, the user allocates the buffer and passes it to * \ref hipsparseSbsrilu02_analysis "hipsparseXbsrilu02_analysis()". This will perform analysis on * the sparsity pattern of the matrix. Finally, the user calls \p hipsparseXbsrilu02 to perform the * actual factorization. The calculation of the buffer size and the analysis of the sparse matrix * only need to be performed once for a given sparsity pattern while the factorization can be * repeatedly applied to multiple matrices having the same sparsity pattern. Once all calls to * \ref hipsparseSbsrilu02 "hipsparseXbsrilu02()" are complete, the temporary buffer can be deallocated. * * \p hipsparseXbsrilu02 reports the first zero pivot (either numerical or structural zero). * The zero pivot status can be obtained by calling \ref hipsparseXbsrilu02_zeroPivot(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA direction that specified whether to count nonzero elements by * \ref HIPSPARSE_DIRECTION_ROW or by \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * mb number of block rows in the sparse BSR matrix. * @param[in] * nnzb number of non-zero block entries of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[inout] * bsrSortedValA_valM array of length \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * blockDim the block dimension of the BSR matrix. Between 1 and m where \p m=mb*blockDim. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, \p descrA, * \p bsrSortedValA_valM, \p bsrSortedRowPtrA or \p bsrSortedColIndA pointer is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_bsrilu02.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSRILU0_H */ ./library/include/internal/precond/hipsparse_gtsv_strided_batch.h0000664000175100017510000003145015176134511025540 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GTSV_STRIDED_BATCH_H #define HIPSPARSE_GTSV_STRIDED_BATCH_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup precond_module * \details * \p hipsparseXgtsv2StridedBatch_bufferSizeExt returns the size of the temporary storage * buffer in bytes that is required by \ref hipsparseSgtsv2StridedBatch "hipsparseXgtsv2StridedBatch()". * The temporary storage buffer must be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m size of the tri-diagonal linear system. * @param[in] * dl lower diagonal of tri-diagonal system where the ith system lower diagonal starts at * \p dl+batchStride*i. * @param[in] * d main diagonal of tri-diagonal system where the ith system diagonal starts at * \p d+batchStride*i. * @param[in] * du upper diagonal of tri-diagonal system where the ith system upper diagonal starts at * \p du+batchStride*i. * @param[inout] * x Dense array of righthand-sides where the ith righthand-side starts at \p x+batchStride*i. * @param[in] * batchCount The number of systems to solve. * @param[in] * batchStride The number of elements that separate each system. Must satisfy \p batchStride >= m. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSgtsv2StridedBatch "hipsparseXgtsv2StridedBatch()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p batchCount, \p batchStride, \p dl, * \p d, \p du, \p x or \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup precond_module * \brief Strided Batch tridiagonal solver (no pivoting) * * \details * \p hipsparseXgtsv2StridedBatch solves a batched tridiagonal linear system * \f[ * T^{i}*x^{i} = x^{i} * \f] * where for each batch \f$i=0\ldots\f$ \p batchCount, \f$T^{i}\f$ is a sparse tridiagonal matrix and * \f$x^{i}\f$ is a dense right-hand side vector. All of the tridiagonal matrices, \f$T^{i}\f$, are * packed one after the other into three vectors: \p dl for the lower diagonals, \p d for the main * diagonals and \p du for the upper diagonals. See below for a description of what this strided * memory pattern looks like. * * Solving the batched tridiagonal system involves two steps. First, the user calls * \ref hipsparseSgtsv2StridedBatch_bufferSizeExt "hipsparseXgtsv2StridedBatch_bufferSizeExt()" * in order to determine the size of the required temporary storage buffer. Once determined, the user allocates * this buffer and passes it to \ref hipsparseSgtsv2StridedBatch "hipsparseXgtsv2StridedBatch()" * to perform the actual solve. The \f$x^{i}\f$ vectors, which initially stores the right-hand side values, are * overwritten with the solution after the call to * \ref hipsparseSgtsv2StridedBatch "hipsparseXgtsv2StridedBatch()". * * The strided batch routines write each batch matrix one after the other in memory. For example, consider * the following batch matrices: * * \f[ * \begin{bmatrix} * t^{0}_{00} & t^{0}_{01} & 0 \\ * t^{0}_{10} & t^{0}_{11} & t^{0}_{12} \\ * 0 & t^{0}_{21} & t^{0}_{22} * \end{bmatrix} * \begin{bmatrix} * t^{1}_{00} & t^{1}_{01} & 0 \\ * t^{1}_{10} & t^{1}_{11} & t^{1}_{12} \\ * 0 & t^{1}_{21} & t^{1}_{22} * \end{bmatrix} * \begin{bmatrix} * t^{2}_{00} & t^{2}_{01} & 0 \\ * t^{2}_{10} & t^{2}_{11} & t^{2}_{12} \\ * 0 & t^{2}_{21} & t^{2}_{22} * \end{bmatrix} * \f] * * In strided format, the upper, lower, and diagonal arrays would look like: * \f[ * \begin{align} * \text{lower} &= \begin{bmatrix} 0 & t^{0}_{10} & t^{0}_{21} & 0 & t^{1}_{10} & t^{1}_{21} & 0 & t^{2}_{10} & t^{2}_{21} \end{bmatrix} \\ * \text{diagonal} &= \begin{bmatrix} t^{0}_{00} & t^{0}_{11} & t^{0}_{22} & t^{1}_{00} & t^{1}_{11} & t^{1}_{22} & t^{2}_{00} & t^{2}_{11} & t^{2}_{22} \end{bmatrix} \\ * \text{upper} &= \begin{bmatrix} t^{0}_{01} & t^{0}_{12} & 0 & t^{1}_{01} & t^{1}_{12} & 0 & t^{2}_{01} & t^{2}_{12} & 0 \end{bmatrix} \\ * \end{align} * \f] * For the lower array, for each batch \p i, the \p i*batchStride entries are zero and for the upper array the * \p i*batchStride+batchStride-1 entries are zero. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m size of the tri-diagonal linear system (must be >= 2). * @param[in] * dl lower diagonal of tri-diagonal system. First entry must be zero. * @param[in] * d main diagonal of tri-diagonal system. * @param[in] * du upper diagonal of tri-diagonal system. Last entry must be zero. * @param[inout] * x Dense array of righthand-sides where the ith righthand-side starts at \p x+batchStride*i. * @param[in] * batchCount The number of systems to solve. * @param[in] * batchStride The number of elements that separate each system. Must satisfy \p batchStride >= m. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p batchCount, \p batchStride, \p dl, \p d, * \p du, \p x or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgtsv2StridedBatch(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, float* x, int batchCount, int batchStride, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgtsv2StridedBatch(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, double* x, int batchCount, int batchStride, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* x, int batchCount, int batchStride, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, int batchStride, void* pBuffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GTSV_STRIDED_BATCH_H */ ./library/include/internal/precond/hipsparse_bsric0.h0000664000175100017510000005676615176134511023101 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSRIC0_H #define HIPSPARSE_BSRIC0_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXbsric02_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during \ref hipsparseSbsric02_analysis * "hipsparseXbsric02_analysis()" or \ref hipsparseSbsric02 "hipsparseXbsric02()" computation. * The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ is stored in \p position, using same index * base as the BSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note * If a zero pivot is found, \p position=j means that either the diagonal block \p A(j,j) * is missing (structural zero) or the diagonal block \p A(j,j) is not positive definite * (numerical zero). * * \note \p hipsparseXbsric02_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info or \p position pointer is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXbsric02_zeroPivot(hipsparseHandle_t handle, bsric02Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXbsric02_bufferSize returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseSbsric02_analysis "hipsparseXbsric02_analysis()" * and \ref hipsparseSbsric02 "hipsparseXbsric02()". The temporary storage buffer must be * allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA direction that specifies whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW * or by \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * mb number of block rows in the sparse BSR matrix. * @param[in] * nnzb number of non-zero block entries of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrValA array of length \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * blockDim the block dimension of the BSR matrix. Between 1 and m where \p m=mb*blockDim. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseSbsric02_analysis(), hipsparseDbsric02_analysis(), * hipsparseCbsric02_analysis(), hipsparseZbsric02_analysis(), * hipsparseSbsric02(), hipsparseDbsric02(), hipsparseCbsric02() * and hipsparseZbsric02(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, \p descrA, * \p bsrValA, \p bsrRowPtrA, \p bsrColIndA, \p info or \p pBufferSizeInBytes pointer * is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \details * \p hipsparseXbsric02_analysis performs the analysis step for \ref hipsparseSbsric02 * "hipsparseXbsric02()". It is expected that this function will be executed only once * for a given matrix and particular operation type. * * \note * If the matrix sparsity pattern changes, the gathered information will become invalid. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA direction that specified whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW or by * \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * mb number of block rows in the sparse BSR matrix. * @param[in] * nnzb number of non-zero block entries of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrValA array of length \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * blockDim the block dimension of the BSR matrix. Between 1 and m where \p m=mb*blockDim. * @param[out] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, \p descrA, * \p bsrValA, \p bsrRowPtrA, \p bsrColIndA, \p info or \p pBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup precond_module * \brief Incomplete Cholesky factorization with 0 fill-ins and no pivoting using BSR * storage format * * \details * \p hipsparseXbsric02 computes the incomplete Cholesky factorization with 0 fill-ins * and no pivoting of a sparse \f$mb \times mb\f$ BSR matrix \f$A\f$, such that * \f[ * A \approx LL^T * \f] * * Computing the above incomplete Cholesky factorization requires three steps to complete. First, * the user determines the size of the required temporary storage buffer by calling * \ref hipsparseSbsric02_bufferSize "hipsparseXbsric02_bufferSize()". Once this buffer size has been determined, * the user allocates the buffer and passes it to \ref hipsparseSbsric02_analysis "hipsparseXbsric02_analysis()". * This will perform analysis on the sparsity pattern of the matrix. Finally, the user calls \p hipsparseXbsric02 * to perform the actual factorization. The calculation of the buffer size and the analysis of the sparse matrix * only need to be performed once for a given sparsity pattern while the factorization can be repeatedly applied * to multiple matrices having the same sparsity pattern. Once all calls to \p hipsparseXbsric02 are complete, * the temporary buffer can be deallocated. * * \p hipsparseXbsric02 requires a user allocated temporary buffer. Its size is returned * by \ref hipsparseSbsric02_bufferSize "hipsparseXbsric02_bufferSize()". Furthermore, * analysis meta data is required. It can be obtained by \ref hipsparseSbsric02_analysis * "hipsparseXbsric02_analysis()". \p hipsparseXbsric02 reports the first zero pivot * (either numerical or structural zero). The zero pivot status can be obtained by calling * \ref hipsparseXbsric02_zeroPivot(). * * \p hipsparseXbsric02 reports the first zero pivot (either numerical or structural zero). * The zero pivot status can be obtained by calling \ref hipsparseXbsric02_zeroPivot(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA direction that specified whether to count nonzero elements by \ref HIPSPARSE_DIRECTION_ROW or by * \ref HIPSPARSE_DIRECTION_COLUMN. * @param[in] * mb number of block rows in the sparse BSR matrix. * @param[in] * nnzb number of non-zero block entries of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[inout] * bsrValA array of length \p nnzb*blockDim*blockDim containing the values of the sparse BSR matrix. * @param[in] * bsrRowPtrA array of \p mb+1 elements that point to the start of every block row of the * sparse BSR matrix. * @param[in] * bsrColIndA array of \p nnzb elements containing the block column indices of the sparse BSR matrix. * @param[in] * blockDim the block dimension of the BSR matrix. Between 1 and m where \p m=mb*blockDim. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, \p descrA, * \p bsrValA, \p bsrRowPtrA, or \p bsrColIndA pointer is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_bsric02.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSRIC0_H */ ./library/include/internal/level2/0000775000175100017510000000000015176134511017203 5ustar jenkinsjenkins./library/include/internal/level2/hipsparse_gemvi.h0000664000175100017510000002533615176134511022552 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GEMVI_H #define HIPSPARSE_GEMVI_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level2_module * \details * \p hipsparseXgemvi_bufferSize returns the size of the temporary storage buffer in bytes * required by \ref hipsparseSgemvi "hipsparseXgemvi()". The temporary storage buffer must * be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * m number of rows of the dense matrix. * @param[in] * n number of columns of the dense matrix. * @param[in] * nnz number of non-zero entries in the sparse vector. * @param[out] * pBufferSizeInBytes temporary storage buffer size. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnz or * \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level2_module * \brief Dense matrix sparse vector multiplication * * \details * \p hipsparseXgemvi multiplies the scalar \f$\alpha\f$ with a dense \f$m \times n\f$ * matrix \f$A\f$ and the sparse vector \f$x\f$ and adds the result to the dense vector * \f$y\f$ that is multiplied by the scalar \f$\beta\f$, such that * \f[ * y := \alpha \cdot op(A) \cdot x + \beta \cdot y, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} * \end{array} * \right. * \f] * * Performing the above operation involves two steps. First, the user calls * \ref hipsparseSgemvi_bufferSize "hipsparseXgemvi_bufferSize()" in order to determine the size of * the temporary storage buffer. Next, the user allocates this temporary buffer and passes it to * \p hipsparseXgemvi to complete the computation. Once all calls to \p hipsparseXgemvi are complete the * temporary storage buffer can be freed. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * m number of rows of the dense matrix. * @param[in] * n number of columns of the dense matrix. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * A pointer to the dense matrix. * @param[in] * lda leading dimension of the dense matrix * @param[in] * nnz number of non-zero entries in the sparse vector * @param[in] * x array of \p nnz elements containing the values of the sparse vector * @param[in] * xInd array of \p nnz elements containing the indices of the sparse vector * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * y array of \p m elements (\f$op(A) == A\f$) or \p n elements * (\f$op(A) == A^T\f$ or \f$op(A) == A^H\f$). * @param[in] * idxBase \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. * @param[in] * pBuffer temporary storage buffer * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p lda, \p nnz, \p alpha, * \p A, \p x, \p xInd, \p beta, \p y or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_gemvi.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const float* alpha, const float* A, int lda, int nnz, const float* x, const int* xInd, const float* beta, float* y, hipsparseIndexBase_t idxBase, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const double* alpha, const double* A, int lda, int nnz, const double* x, const int* xInd, const double* beta, double* y, hipsparseIndexBase_t idxBase, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipComplex* alpha, const hipComplex* A, int lda, int nnz, const hipComplex* x, const int* xInd, const hipComplex* beta, hipComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, int nnz, const hipDoubleComplex* x, const int* xInd, const hipDoubleComplex* beta, hipDoubleComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GEMVI_H */ ./library/include/internal/level2/hipsparse_bsrmv.h0000664000175100017510000002076515176134511022575 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSRMV_H #define HIPSPARSE_BSRMV_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup level2_module * \brief Sparse matrix vector multiplication using BSR storage format * * \details * \p hipsparseXbsrmv multiplies the scalar \f$\alpha\f$ with a sparse * \f$m \times n\f$ matrix, defined in BSR storage format, and the dense vector \f$x\f$ and adds the * result to the dense vector \f$y\f$ that is multiplied by the scalar \f$\beta\f$, such that * \f[ * y := \alpha \cdot op(A) \cdot x + \beta \cdot y, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if trans == HIPSPARSE_OPERATION_NON_TRANSPOSE} * \end{array} * \right. * \f] * and where \f$m = mb \times blockDim\f$ and \f$n= nb \times blockDim\f$. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix operation type. * @param[in] * mb number of block rows of the sparse BSR matrix. * @param[in] * nb number of block columns of the sparse BSR matrix. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse BSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnzb elements containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[in] * x array of \p nb*blockDim elements (\f$op(A) = A\f$) or \p mb*blockDim * elements (\f$op(A) = A^T\f$ or \f$op(A) = A^H\f$). * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * y array of \p mb*blockDim elements (\f$op(A) = A\f$) or \p nb*blockDim * elements (\f$op(A) = A^T\f$ or \f$op(A) = A^H\f$). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p nnzb, * \p blockDim, \p descr, \p alpha, \p bsrSortedValA, \p bsrSortedRowPtrA, * \p bsrSortedColIndA, \p x, \p beta or \p y is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p trans != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_bsrmv.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const float* x, const float* beta, float* y); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const double* x, const double* beta, double* y); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSRMV_H */ ./library/include/internal/level2/hipsparse_bsrxmv.h0000664000175100017510000002476615176134511022772 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSRXMV_H #define HIPSPARSE_BSRXMV_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level2_module * \brief Sparse matrix vector multiplication with mask operation using BSR storage format * * \details * \p hipsparseXbsrxmv multiplies the scalar \f$\alpha\f$ with a sparse * \f$(mb \times \text{blockDim}) \times (nb \times \text{blockDim})\f$ * modified matrix, defined in BSR storage format, and the dense vector \f$x\f$ and adds the * result to the dense vector \f$y\f$ that is multiplied by the scalar \f$\beta\f$, * such that * \f[ * y := \left( \alpha \cdot op(A) \cdot x + \beta \cdot y \right)\left( \text{mask} \right), * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if trans == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if trans == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * The \f$\text{mask}\f$ is defined as an array of block row indices. * The input sparse matrix is defined with a modified BSR storage format where the beginning and the end of each row * is defined with two arrays, \p bsrRowPtr and \p bsr_end_ptr (both of size \p mb), rather the usual \p bsrRowPtr of size \p mb+1. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p trans == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * Currently, \p blockDim == 1 is not supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dir matrix storage of BSR blocks. * @param[in] * trans matrix operation type. * @param[in] * sizeOfMask number of updated block rows of the array \p y. * @param[in] * mb number of block rows of the sparse BSR matrix. * @param[in] * nb number of block columns of the sparse BSR matrix. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descr descriptor of the sparse BSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * bsrVal array of \p nnzb blocks of the sparse BSR matrix. * * @param[in] * bsrMaskPtr array of \p sizeOfMask elements that give the indices of the updated block rows. * * @param[in] * bsrRowPtr array of \p mb elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrEndPtr array of \p mb elements that point to the end of every block row of * the sparse BSR matrix. * @param[in] * bsrColInd array of \p nnzb elements containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[in] * x array of \p nb*blockDim elements (\f$op(A) = A\f$) or \p mb*blockDim * elements (\f$op(A) = A^T\f$ or \f$op(A) = A^H\f$). * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * y array of \p mb*blockDim elements (\f$op(A) = A\f$) or \p nb*blockDim * elements (\f$op(A) = A^T\f$ or \f$op(A) = A^H\f$). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nb, \p nnzb, \p blockDim, * \p sizeOfMask, \p descr, \p alpha, \p bsrVal, \p bsrRowPtr, \p bsrEndPtr, * \p bsrColInd, \p x, \p beta or \p y is invalid or if \p sizeOfMask is greater * than \p mb. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p blockDim==1, \p trans != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descr, const float* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const float* x, const float* beta, float* y); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descr, const double* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const double* x, const double* beta, double* y); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSRXMV_H */ ./library/include/internal/level2/hipsparse_hybmv.h0000664000175100017510000001425015176134511022561 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_HYBMV_H #define HIPSPARSE_HYBMV_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup level2_module * \brief Sparse matrix vector multiplication using HYB storage format * * \details * \p hipsparseXhybmv multiplies the scalar \f$\alpha\f$ with a sparse \f$m \times n\f$ * matrix, defined in HYB storage format, and the dense vector \f$x\f$ and adds the * result to the dense vector \f$y\f$ that is multiplied by the scalar \f$\beta\f$, * such that * \f[ * y := \alpha \cdot op(A) \cdot x + \beta \cdot y, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} * \end{array} * \right. * \f] * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse HYB matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * hybA matrix in HYB storage format. * @param[in] * x array of \p n elements (\f$op(A) == A\f$) or \p m elements * (\f$op(A) == A^T\f$ or \f$op(A) == A^H\f$). * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * y array of \p m elements (\f$op(A) == A\f$) or \p n elements * (\f$op(A) == A^T\f$ or \f$op(A) == A^H\f$). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p descrA, \p alpha, * \p hybA, \p x, \p beta or \p y is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_ALLOC_FAILED the buffer could not be allocated. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_hybmv.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseShybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const float* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const float* x, const float* beta, float* y); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDhybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const double* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const double* x, const double* beta, double* y); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseChybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const hipComplex* x, const hipComplex* beta, hipComplex* y); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZhybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_HYBMV_H */ ./library/include/internal/level2/hipsparse_csrsv.h0000664000175100017510000007316115176134511022602 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRSV_H #define HIPSPARSE_CSRSV_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level2_module * \details * \p hipsparseXcsrsv2_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during hipsparseScsrsv2_solve(), * hipsparseDcsrsv2_solve(), hipsparseCcsrsv2_solve() or hipsparseZcsrsv2_solve() * computation. The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ is stored in \p position, * using same index base as the CSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note \p hipsparseXcsrsv2_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle \p info or \p position is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrsv2_zeroPivot(hipsparseHandle_t handle, csrsv2Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level2_module * \details * \p hipsparseXcsrsv2_bufferSize returns the size of the temporary storage buffer in bytes * that is required by \ref hipsparseScsrsv2_analysis "hipsparseScsrsv2_analysis()" and * \ref hipsparseScsrsv2_solve "hipsparseXcsrsv2_solve()". The temporary storage buffer must * be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseScsrsv2_analysis "hipsparseXcsrsv2_analysis()" and * \ref hipsparseScsrsv2_solve "hipsparseXcsrsv2_solve()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes); /**@}*/ #endif /*! \ingroup level2_module * \details * \p hipsparseXcsrsv2_bufferSizeExt returns the size of the temporary storage buffer in bytes * that is required by \ref hipsparseScsrsv2_analysis "hipsparseXcsrsv2_analysis()" and * \ref hipsparseScsrsv2_solve "hipsparseScsrsv2_solve()". The temporary storage buffer must be * allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseScsrsv2_analysis "hipsparseXcsrsv2_analysis()" and * \ref hipsparseScsrsv2_solve "hipsparseXcsrsv2_solve()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrSortedValA, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes); /**@}*/ #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level2_module * \details * \p hipsparseXcsrsv2_analysis performs the analysis step for * \ref hipsparseScsrsv2_solve "hipsparseXcsrsv2_solve()". It is expected that this * function will be executed only once for a given matrix and particular operation * type. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[out] * info structure that holds the information collected during * the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descr, * \p csrSortedRowPtrA, \p csrSortedColIndA, \p info or \p pBuffer is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup level2_module * \brief Sparse triangular solve using CSR storage format * * \details * \p hipsparseXcsrsv2_solve solves a sparse triangular linear system of a sparse * \f$m \times m\f$ matrix, defined in CSR storage format, a dense solution vector * \f$y\f$ and the right-hand side \f$x\f$ that is multiplied by \f$\alpha\f$, such that * \f[ * op(A) \cdot y = \alpha \cdot x, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if trans == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if trans == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * Performing the above operation requires three steps. First, the user calls * \ref hipsparseScsrsv2_bufferSize "hipsparseXcsrsv2_bufferSize()" (or * \ref hipsparseScsrsv2_bufferSizeExt "hipsparseXcsrsv2_bufferSizeExt()") which will determine the size of the * required temporary storage buffer. The user then allocates this buffer and calls * \ref hipsparseScsrsv2_analysis "hipsparseXcsrsv2_analysis()" which will perform analysis on the sparse matrix * \f$op(A)\f$. Finally, the user completes the computation by calling \p hipsparseXcsrsv2_solve. The buffer size, * buffer allocation, and analysis only need to be called once for a given sparse matrix \f$op(A)\f$ while the * computation stage can be repeatedly used with different \f$x\f$ and \f$y\f$ vectors. Once all calls to * \p hipsparseXcsrsv2_solve are complete, the temporary buffer can be deallocated. * * Solving a triangular system involves division by the diagonal elements. This means that if the sparse matrix is * missing the diagonal entry (referred to as a structural zero) or the diagonal entry is zero (referred to as a numerical zero) * then a division by zero would occur. \p hipsparseXcsrsv2_solve tracks the location of the first zero pivot (either numerical * or structural zero). The zero pivot status can be checked calling \ref hipsparseXcsrsv2_zeroPivot(). If * \ref hipsparseXcsrsv2_zeroPivot() returns \ref HIPSPARSE_STATUS_SUCCESS, then no zero pivot was found and therefore * the matrix does not have a structural or numerical zero. * * The user can specify that the sparse matrix should be interpreted as having ones on the diagonal by setting the diagonal type * on the descriptor \p descrA to \ref HIPSPARSE_DIAG_TYPE_UNIT using \ref hipsparseSetMatDiagType. If * \ref hipsparseDiagType_t == \ref HIPSPARSE_DIAG_TYPE_UNIT, no zero pivot will be reported, even if \f$A_{j,j} = 0\f$ for * some \f$j\f$. * * The sparse CSR matrix passed to \p hipsparseXcsrsv2_solve does not actually have to be a triangular matrix. Instead the * triangular upper or lower part of the sparse matrix is solved based on \ref hipsparseFillMode_t set on the descriptor * \p descrA. If the fill mode is set to \ref HIPSPARSE_FILL_MODE_LOWER, then the lower triangular matrix is solved. If the * fill mode is set to \ref HIPSPARSE_FILL_MODE_UPPER then the upper triangular matrix is solved. * * \note * The sparse CSR matrix has to be sorted. This can be achieved by calling * hipsparseXcsrsort(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE and * \p transA == \ref HIPSPARSE_OPERATION_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start * of every row of the sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * f array of \p m elements, holding the right-hand side. * @param[out] * x array of \p m elements, holding the solution. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, * \p alpha, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, * \p f or \p x is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrsv2.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRSV_H */ ./library/include/internal/level2/hipsparse_csrmv.h0000664000175100017510000002051115176134511022563 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRMV_H #define HIPSPARSE_CSRMV_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup level2_module * \brief Sparse matrix vector multiplication using CSR storage format * * \details * \p hipsparseXcsrmv multiplies the scalar \f$\alpha\f$ with a sparse \f$m \times n\f$ * matrix, defined in CSR storage format, and the dense vector \f$x\f$ and adds the * result to the dense vector \f$y\f$ that is multiplied by the scalar \f$\beta\f$, * such that * \f[ * y := \alpha \cdot op(A) \cdot x + \beta \cdot y, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if transA == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * \code{.c} * for(i = 0; i < m; ++i) * { * y[i] = beta * y[i]; * * for(j = csrRowPtr[i]; j < csrRowPtr[i + 1]; ++j) * { * y[i] = y[i] + alpha * csrVal[j] * x[csrColInd[j]]; * } * } * \endcode * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix operation type. * @param[in] * m number of rows of the sparse CSR matrix. * @param[in] * n number of columns of the sparse CSR matrix. * @param[in] * nnz number of non-zero entries of the sparse CSR matrix. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrSortedValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start * of every row of the sparse CSR matrix. * @param[in] * csrSortedColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[in] * x array of \p n elements (\f$op(A) == A\f$) or \p m elements * (\f$op(A) == A^T\f$ or \f$op(A) == A^H\f$). * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * y array of \p m elements (\f$op(A) == A\f$) or \p n elements * (\f$op(A) == A^T\f$ or \f$op(A) == A^H\f$). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n or \p nnz, \p descr, * \p alpha, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, \p x, * \p beta or \p y is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrmv.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* x, const float* beta, float* y); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* x, const double* beta, double* y); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* x, const hipComplex* beta, hipComplex* y); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRMV_H */ ./library/include/internal/level2/hipsparse_bsrsv.h0000664000175100017510000010105415176134511022572 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_BSRSV_H #define HIPSPARSE_BSRSV_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level2_module * \details * \p hipsparseXbsrsv2_zeroPivot returns \ref HIPSPARSE_STATUS_ZERO_PIVOT, if either a * structural or numerical zero has been found during \ref hipsparseSbsrsv2_analysis * "hipsparseXbsrsv2_analysis()" or \ref hipsparseSbsrsv2_solve "hipsparseXbsrsv2_solve()" * computation. The first zero pivot \f$j\f$ at \f$A_{j,j}\f$ is stored in \p position, * using same index base as the BSR matrix. * * \p position can be in host or device memory. If no zero pivot has been found, * \p position is set to -1 and \ref HIPSPARSE_STATUS_SUCCESS is returned instead. * * \note \p hipsparseXbsrsv2_zeroPivot is a blocking function. It might influence * performance negatively. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * info structure that holds the information collected during the analysis step. * @param[inout] * position pointer to zero pivot \f$j\f$, can be in host or device memory. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p info or \p position is * invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_ZERO_PIVOT zero pivot has been found. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXbsrsv2_zeroPivot(hipsparseHandle_t handle, bsrsv2Info_t info, int* position); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level2_module * \details * \p hipsparseXbsrsv2_bufferSize returns the size of the temporary storage buffer in bytes * that is required by \ref hipsparseSbsrsv2_analysis "hipsparseXbsrsv2_analysis()" and * \ref hipsparseSbsrsv2_solve "hipsparseXbsrsv2_solve()". The temporary storage buffer must * be allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix operation type. * @param[in] * mb number of block rows of the sparse BSR matrix. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnz containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseSbsrsv2_analysis "hipsparseXbsrsv2_analysis()" and * \ref hipsparseSbsrsv2_solve "hipsparseXbsrsv2_solve()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb or \p blockDim, * \p descr, \p bsrSortedValA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, * \p info or \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes); /**@}*/ #endif /*! \ingroup level2_module * \details * \p hipsparseXbsrsv2_bufferSizeExt returns the size of the temporary storage buffer in bytes * that is required by \ref hipsparseSbsrsv2_analysis "hipsparseXbsrsv2_analysis()" and * \ref hipsparseSbsrsv2_solve "hipsparseXbsrsv2_solve()". The temporary storage buffer must be * allocated by the user. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix operation type. * @param[in] * mb number of block rows of the sparse BSR matrix. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnz containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[out] * info structure that holds the information collected during the analysis step. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * \ref hipsparseSbsrsv2_analysis "hipsparseXbsrsv2_analysis()" and * \ref hipsparseSbsrsv2_solve "hipsparseXbsrsv2_solve()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb or \p blockDim, * \p descr, \p bsrSortedValA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, * \p info or \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes); /**@}*/ #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level2_module * \details * \p hipsparseXbsrsv2_analysis performs the analysis step for \ref hipsparseSbsrsv2_solve * "hipsparseXbsrsv2_solve()". It is expected that this function will be executed only once * for a given matrix and particular operation type. * * \note * If the matrix sparsity pattern changes, the gathered information will become invalid. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix operation type. * @param[in] * mb number of block rows of the sparse BSR matrix. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnz containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[out] * info structure that holds the information collected during * the analysis step. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, * \p descrA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, \p info or * \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup level2_module * \brief Sparse triangular solve using BSR storage format * * \details * \p hipsparseXbsrsv2_solve solves a sparse triangular linear system of a sparse * \f$m \times m\f$ matrix, defined in BSR storage format, a dense solution vector * \f$y\f$ and the right-hand side \f$x\f$ that is multiplied by \f$\alpha\f$, such that * \f[ * op(A) \cdot y = \alpha \cdot x, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if trans == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if trans == HIPSPARSE_OPERATION_TRANSPOSE} * \end{array} * \right. * \f] * * Performing the above operation requires three steps. First, the user calls * \ref hipsparseSbsrsv2_bufferSize "hipsparseXbsrsv2_bufferSize()" which will determine the size of the required * temporary storage buffer. The user then allocates this buffer and calls * \ref hipsparseSbsrsv2_analysis "hipsparseXbsrsv2_analysis()" which will perform analysis on the sparse matrix * \f$op(A)\f$. Finally, the user completes the computation by calling \p hipsparseXbsrsv2_solve. The buffer size, * buffer allocation, and analysis only need to be called once for a given sparse matrix \f$op(A)\f$ while the * computation stage can be repeatedly used with different \f$x\f$ and \f$y\f$ vectors. Once all calls to * \p hipsparseXbsrsv2_solve are complete, the temporary buffer can be deallocated. * * Solving a triangular system involves inverting the diagonal blocks. This means that if the sparse matrix is * missing the diagonal block (referred to as a structural zero) or the diagonal block is not invertible (referred * to as a numerical zero) then a solution is not possible. \p hipsparseXbsrsv2_solve tracks the location of the first * zero pivot (either numerical or structural zero). The zero pivot status can be checked calling \ref hipsparseXbsrsv2_zeroPivot(). * If \ref hipsparseXbsrsv2_zeroPivot() returns \ref HIPSPARSE_STATUS_SUCCESS, then no zero pivot was found and therefore * the matrix does not have a structural or numerical zero. * * The user can specify that the sparse matrix should be interpreted as having identity blocks on the diagonal by setting the diagonal * type on the descriptor \p descrA to \ref HIPSPARSE_DIAG_TYPE_UNIT using \ref hipsparseSetMatDiagType. If * \ref hipsparseDiagType_t == \ref HIPSPARSE_DIAG_TYPE_UNIT, no zero pivot will be reported, even if the diagonal block \f$A_{j,j}\f$ * for some \f$j\f$ is not invertible. * * The sparse CSR matrix passed to \p hipsparseXbsrsv2_solve does not actually have to be a triangular matrix. Instead the * triangular upper or lower part of the sparse matrix is solved based on \ref hipsparseFillMode_t set on the descriptor * \p descrA. If the fill mode is set to \ref HIPSPARSE_FILL_MODE_LOWER, then the lower triangular matrix is solved. If the * fill mode is set to \ref HIPSPARSE_FILL_MODE_UPPER then the upper triangular matrix is solved. * * \note * The sparse BSR matrix has to be sorted. * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE and * \p transA == \ref HIPSPARSE_OPERATION_TRANSPOSE is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * dirA matrix storage of BSR blocks. * @param[in] * transA matrix operation type. * @param[in] * mb number of block rows of the sparse BSR matrix. * @param[in] * nnzb number of non-zero blocks of the sparse BSR matrix. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse BSR matrix. * @param[in] * bsrSortedValA array of \p nnzb blocks of the sparse BSR matrix. * @param[in] * bsrSortedRowPtrA array of \p mb+1 elements that point to the start of every block row of * the sparse BSR matrix. * @param[in] * bsrSortedColIndA array of \p nnz containing the block column indices of the sparse * BSR matrix. * @param[in] * blockDim block dimension of the sparse BSR matrix. * @param[in] * info structure that holds the information collected during the analysis step. * @param[in] * f array of \p m elements, holding the right-hand side. * @param[out] * x array of \p m elements, holding the solution. * @param[in] * policy \ref HIPSPARSE_SOLVE_POLICY_NO_LEVEL or * \ref HIPSPARSE_SOLVE_POLICY_USE_LEVEL. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p mb, \p nnzb, \p blockDim, * \p descrA, \p alpha, \p bsrSortedValA, \p bsrSortedRowPtrA, \p bsrSortedColIndA, * \p f or \p x is invalid. * \retval HIPSPARSE_STATUS_ARCH_MISMATCH the device is not supported. * \retval HIPSPARSE_STATUS_INTERNAL_ERROR an internal error occurred. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_bsrsv2.cpp doc example */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_BSRSV_H */ ./library/include/internal/reorder/0000775000175100017510000000000015176134511017454 5ustar jenkinsjenkins./library/include/internal/reorder/hipsparse_csrcolor.h0000664000175100017510000001717715176134511023546 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRCOLOR_H #define HIPSPARSE_CSRCOLOR_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup reordering_module * \brief Coloring of the adjacency graph of the matrix \f$A\f$ stored in the CSR format. * * \details * \p hipsparseXcsrcolor performs the coloring of the undirected graph represented by the (symmetric) sparsity * pattern of the matrix \f$A\f$ stored in CSR format. Graph coloring is a way of coloring the nodes of a graph * such that no two adjacent nodes are of the same color. The \p fractionToColor is a parameter to only color * a given percentage of the graph nodes, the remaining uncolored nodes receive distinct new colors. The optional * \p reordering array is a permutation array such that unknowns of the same color are grouped. The matrix \f$A\f$ * must be stored as a general matrix with a symmetric sparsity pattern, and if the matrix \f$A\f$ is non-symmetric * then the user is responsible to provide the symmetric part \f$\frac{A+A^T}{2}\f$. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of sparse matrix \f$A\f$. * @param[in] * nnz number of non-zero entries of sparse matrix \f$A\f$. * @param[in] * descrA sparse matrix descriptor. * @param[in] * csrValA array of \p nnz elements of the sparse CSR matrix. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix. * @param[in] * csrColIndA array of \p nnz elements containing the column indices of the sparse * CSR matrix. * @param[in] * fractionToColor fraction of nodes to be colored, which should be in the interval \f$[0.0,1.0]\f$, for example \f$0.8\f$ implies that * \f$80\f$ percent of nodes will be colored. * @param[out] * ncolors resulting number of distinct colors. * @param[out] * coloring resulting mapping of colors. * @param[out] * reordering optional resulting reordering permutation if \p reordering is a non-null pointer. * @param[inout] * info structure that holds the information collected during the coloring algorithm. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p nnz, \p descrA, \p csrValA, \p csrRowPtrA, \p csrColIndA, * \p fractionToColor, \p ncolors, \p coloring or \p info pointer is invalid. */ /**@{*/ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info); DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRCOLOR_H */ ./library/include/internal/extra/0000775000175100017510000000000015176134511017135 5ustar jenkinsjenkins./library/include/internal/extra/hipsparse_csrgeam.h0000664000175100017510000012160215176134511023007 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRGEAM_H #define HIPSPARSE_CSRGEAM_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup extra_module * \details * \p hipsparseXcsrgeamNnz computes the total CSR non-zero elements and the CSR row * offsets, that point to the start of every row of the sparse CSR matrix, of the * resulting matrix \f$C\f$. It is assumed that \p csrRowPtrC has been allocated with * size \p m+1. The desired index base in the output CSR matrix is set in the * \ref hipsparseMatDescr_t. See \ref hipsparseSetMatIndexBase(). * * For full code example, see \ref hipsparseScsrgeam(). * * \note * As indicated, \p nnzTotalDevHostPtr can point either to host or device memory. This is controlled * by setting the pointer mode. See \ref hipsparseSetPointerMode(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrRowPtrB array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$B\f$. * @param[in] * csrColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * nnzTotalDevHostPtr pointer to the number of non-zero entries of the sparse CSR * matrix \f$C\f$. \p nnzTotalDevHostPtr can be a host or device pointer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p nnzB, \p descrA, * \p csrRowPtrA, \p csrColIndA, \p descrB, \p csrRowPtrB, \p csrColIndB, \p descrC, * \p csrRowPtrC or \p nnzTotalDevHostPtr is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrgeamNnz(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr); /*! \ingroup extra_module * \brief Sparse matrix sparse matrix addition using CSR storage format * * \details * \p hipsparseXcsrgeam multiplies the scalar \f$\alpha\f$ with the sparse * \f$m \times n\f$ matrix \f$A\f$, defined in CSR storage format, multiplies the * scalar \f$\beta\f$ with the sparse \f$m \times n\f$ matrix \f$B\f$, defined in CSR * storage format, and adds both resulting matrices to obtain the sparse * \f$m \times n\f$ matrix \f$C\f$, defined in CSR storage format, such that * \f[ * C := \alpha \cdot A + \beta \cdot B. * \f] * * This computation involves a multi step process. First the user must allocate \p csrRowPtrC * to have size \p m+1. The user then calls \ref hipsparseXcsrgeamNnz which fills in the \p csrRowPtrC * array as well as computes the total number of nonzeros in \f$C\f$, \p nnzC. The user then allocates both * arrays \p csrColIndC and \p csrValC to have size \p nnzC and calls \p hipsparseXcsrgeam to complete * the computation. The desired index base in the output CSR matrix \f$C\f$ is set in the * \ref hipsparseMatDescr_t \p descrC. See \ref hipsparseSetMatIndexBase(). * * \note Both scalars \f$\alpha\f$ and \f$beta\f$ have to be valid. * \note Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * \note This function is non blocking and executed asynchronously with respect to the * host. It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrValA array of \p nnzA elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrValB array of \p nnzB elements of the sparse CSR matrix \f$B\f$. * @param[in] * csrRowPtrB array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$B\f$. * @param[in] * csrColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrValC array of elements of the sparse CSR matrix \f$C\f$. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * csrColIndC array of elements containing the column indices of the * sparse CSR matrix \f$C\f$. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p nnzB, * \p alpha, \p descrA, \p csrValA, \p csrRowPtrA, \p csrColIndA, \p beta, * \p descrB, \p csrValB, \p csrRowPtrB, \p csrColIndB, \p descrC, \p csrValC, * \p csrRowPtrC or \p csrColIndC is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrgeam.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrgeam(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrgeam(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrgeam(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrgeam(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC); /**@}*/ #endif /*! \ingroup extra_module * \details * \p hipsparseXcsrgeam2_bufferSizeExt returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseXcsrgeam2Nnz() and \ref hipsparseScsrgeam2 * "hipsparseXcsrgeam2()". The temporary storage buffer must be allocated by the user. * * \note * Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedValA array of \p nnzA elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrSortedValB array of \p nnzB elements of the sparse CSR matrix \f$B\f$. * @param[in] * csrSortedRowPtrB array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$B\f$. * @param[in] * csrSortedColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrSortedValC array of elements of the sparse CSR matrix \f$C\f$. * @param[in] * csrSortedRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * csrSortedColIndC array of elements containing the column indices of the * sparse CSR matrix \f$C\f$. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseXcsrgeam2Nnz() and \ref hipsparseScsrgeam2 "hipsparseXcsrgeam2()". * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p nnzB, * \p alpha, \p descrA, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, * \p beta, \p descrB, \p csrSortedValB, \p csrSortedRowPtrB, \p csrSortedColIndB, * \p descrC, \p csrSortedValC, \p csrSortedRowPtrC, \p csrSortedColIndC, or * \p pBufferSizeInBytes is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const float* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const double* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipDoubleComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes); /**@}*/ /*! \ingroup extra_module * \details * \p hipsparseXcsrgeam2Nnz computes the total CSR non-zero elements and the CSR row * offsets, that point to the start of every row of the sparse CSR matrix, of the * resulting matrix \f$C\f$. It is assumed that \p csrRowPtrC has been allocated with * size \p m+1. The required buffer size can be obtained by * \ref hipsparseScsrgeam2_bufferSizeExt "hipsparseXcsrgeam2_bufferSizeExt()". The * desired index base in the output CSR matrix \f$C\f$ is set in the \ref hipsparseMatDescr_t * \p descrC. See \ref hipsparseSetMatIndexBase(). * * \note * As indicated, \p nnzTotalDevHostPtr can point either to host or device memory. This is controlled * by setting the pointer mode. See \ref hipsparseSetPointerMode(). * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * \note * Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrSortedRowPtrB array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$B\f$. * @param[in] * csrSortedColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrSortedRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * nnzTotalDevHostPtr pointer to the number of non-zero entries of the sparse CSR * matrix \f$C\f$. \p nnzTotalDevHostPtr can be a host or device pointer. * @param[in] * workspace temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p nnzB, * \p descrA, \p csrSortedRowPtrA, \p csrSortedColIndA, \p descrB, \p csrSortedRowPtrB, * \p csrSortedColIndB, \p descrC, \p csrSortedRowPtrC or \p nnzTotalDevHostPtr is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrgeam2Nnz(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, int nnzA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, int* csrSortedRowPtrC, int* nnzTotalDevHostPtr, void* workspace); /*! \ingroup extra_module * \brief Sparse matrix sparse matrix addition using CSR storage format * * \details * \p hipsparseXcsrgeam2 multiplies the scalar \f$\alpha\f$ with the sparse * \f$m \times n\f$ matrix \f$A\f$, defined in CSR storage format, multiplies the * scalar \f$\beta\f$ with the sparse \f$m \times n\f$ matrix \f$B\f$, defined in CSR * storage format, and adds both resulting matrices to obtain the sparse * \f$m \times n\f$ matrix \f$C\f$, defined in CSR storage format, such that * \f[ * C := \alpha \cdot A + \beta \cdot B. * \f] * * This computation involves a multi step process. First the user must call * \ref hipsparseScsrgeam2_bufferSizeExt "hipsparseXcsrgeam2_bufferSizeExt()" in order to determine the * required user allocated temporary buffer size. The user then allocates this buffer and also allocates * \p csrRowPtrC to have size \p m+1. Both the temporary storage buffer and \p csrRowPtrC array are then * passed to \ref hipsparseXcsrgeam2Nnz which fills in the \p csrRowPtrC array as well as computes the total * number of nonzeros in C, \p nnzC. The user then allocates both arrays \p csrColIndC and \p csrValC to have * size \p nnzC and calls \p hipsparseXcsrgeam2 to complete the computation. The desired index base in * the output CSR matrix C is set in the \ref hipsparseMatDescr_t \p descrC. See \ref hipsparseSetMatIndexBase(). * * \note Both scalars \f$\alpha\f$ and \f$beta\f$ have to be valid. * \note Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * \note This function is non blocking and executed asynchronously with respect to the * host. It may return before the actual computation has finished. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$A\f$, \f$B\f$ and \f$C\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedValA array of \p nnzA elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrSortedRowPtrA array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$A\f$. * @param[in] * csrSortedColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrSortedValB array of \p nnzB elements of the sparse CSR matrix \f$B\f$. * @param[in] * csrSortedRowPtrB array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$B\f$. * @param[in] * csrSortedColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrSortedValC array of elements of the sparse CSR matrix \f$C\f$. * @param[in] * csrSortedRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * csrSortedColIndC array of elements containing the column indices of the * sparse CSR matrix \f$C\f$. * @param[in] * pBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p nnzA, \p nnzB, * \p alpha, \p descrA, \p csrSortedValA, \p csrSortedRowPtrA, \p csrSortedColIndA, \p beta, * \p descrB, \p csrSortedValB, \p csrSortedRowPtrB, \p csrSortedColIndB, \p descrC, \p csrSortedValC, * \p csrSortedRowPtrC, \p csrSortedColIndC or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrgeam2.cpp doc example */ /**@{*/ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrgeam2(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, float* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrgeam2(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, double* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer); HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer); /**@}*/ #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRGEAM_H */ ./library/include/internal/extra/hipsparse_csrgemm.h0000664000175100017510000014325115176134511023027 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_CSRGEMM_H #define HIPSPARSE_CSRGEMM_H #ifdef __cplusplus extern "C" { #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup extra_module * \details * \p hipsparseXcsrgemmNnz computes the total CSR non-zero elements and the CSR row * offsets, that point to the start of every row of the sparse CSR matrix, of the * resulting multiplied matrix \f$C\f$. It is assumed that \p csrRowPtrC has been allocated * with size \p m+1. The desired index base in the output CSR matrix \f$C\f$ is set in the * \ref hipsparseMatDescr_t \p descrC. See \ref hipsparseSetMatIndexBase(). * * \note * As indicated, \p nnzTotalDevHostPtr can point either to host or device memory. This is controlled * by setting the pointer mode. See \ref hipsparseSetPointerMode(). * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Please note, that for matrix products with more than 8192 intermediate products per * row, additional temporary storage buffer is allocated by the algorithm. * * \note * Currently, only \p transA == \p transB == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is * supported. * * \note * Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transB matrix \f$B\f$ operation type. * @param[in] * m number of rows of the sparse CSR matrix \f$op(A)\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$op(B)\f$ and * \f$C\f$. * @param[in] * k number of columns of the sparse CSR matrix \f$op(A)\f$ and number of * rows of the sparse CSR matrix \f$op(B)\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrRowPtrA array of \p m+1 elements (\f$op(A) == A\f$, \p k+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(A)\f$. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrRowPtrB array of \p k+1 elements (\f$op(B) == B\f$, \p m+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(B)\f$. * @param[in] * csrColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[inout] * nnzTotalDevHostPtr pointer to the number of non-zero entries of the sparse CSR * matrix \f$C\f$. \p nnzTotalDevHostPtr can be a host or device pointer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnzA, \p nnzB, \p nnzC, * \p descrA, \p csrRowPtrA, \p csrColIndA, \p descrB, \p csrRowPtrB, \p csrColIndB, * \p descrC, \p csrRowPtrC or \p nnzTotalDevHostPtr is invalid. * \retval HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED * \p transA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE, * \p transB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE, or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrgemmNnz(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup extra_module * \brief Sparse matrix sparse matrix multiplication using CSR storage format * * \details * \p hipsparseXcsrgemm multiplies the sparse \f$m \times k\f$ matrix \f$op(A)\f$, defined in * CSR storage format with the sparse \f$k \times n\f$ matrix \f$op(B)\f$, defined in CSR * storage format, and stores the result in the sparse \f$m \times n\f$ matrix \f$C\f$, * defined in CSR storage format, such that * \f[ * C := op(A) \cdot op(B), * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if transA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if transA == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * and * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if transB == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if transB == HIPSPARSE_OPERATION_TRANSPOSE} \\ * B^H, & \text{if transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * This computation involves a multi step process. First the user must allocate \p csrRowPtrC * to have size \p m+1. The user then calls \ref hipsparseXcsrgemmNnz which fills in the \p csrRowPtrC * array as well as computes the total number of nonzeros in C, \p nnzC. The user then allocates both * arrays \p csrColIndC and \p csrValC to have size \p nnzC and calls \p hipsparseXcsrgemm to complete * the computation. The desired index base in the output CSR matrix C is set in the * \ref hipsparseMatDescr_t \p descrC. See \ref hipsparseSetMatIndexBase(). * * \note Currently, only \p transA == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * \note Currently, only \p transB == \ref HIPSPARSE_OPERATION_NON_TRANSPOSE is supported. * \note Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * \note This function is non blocking and executed asynchronously with respect to the * host. It may return before the actual computation has finished. * \note Please note, that for matrix products with more than 4096 non-zero entries per * row, additional temporary storage buffer is allocated by the algorithm. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * transA matrix \f$A\f$ operation type. * @param[in] * transB matrix \f$B\f$ operation type. * @param[in] * m number of rows of the sparse CSR matrix \f$op(A)\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$op(B)\f$ and * \f$C\f$. * @param[in] * k number of columns of the sparse CSR matrix \f$op(A)\f$ and number of * rows of the sparse CSR matrix \f$op(B)\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrValA array of \p nnzA elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrRowPtrA array of \p m+1 elements (\f$op(A) == A\f$, \p k+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(A)\f$. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrValB array of \p nnzB elements of the sparse CSR matrix \f$B\f$. * @param[in] * csrRowPtrB array of \p k+1 elements (\f$op(B) == B\f$, \p m+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(B)\f$. * @param[in] * csrColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrValC array of \p nnzC elements of the sparse CSR matrix \f$C\f$. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * csrColIndC array of \p nnzC elements containing the column indices of the * sparse CSR matrix \f$C\f$. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnzA, \p nnzB, * \p descrA, \p csrValA, \p csrRowPtrA, \p csrColIndA, \p descrB, \p csrValB, * \p csrRowPtrB, \p csrColIndB, \p descrC, \p csrValC, \p csrRowPtrC, \p csrColIndC * is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p transA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE, * \p transB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE, or * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrgemm.cpp doc example */ /**@{*/ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC); DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup extra_module * \details * \p hipsparseXcsrgemm2_bufferSizeExt returns the size of the temporary storage buffer * in bytes that is required by \ref hipsparseXcsrgemm2Nnz() and \ref hipsparseScsrgemm2 * "hipsparseXcsrgemm2()". The temporary storage buffer must be allocated by the user. * * \note * Please note, that for matrix products with more than 4096 non-zero entries per row, * additional temporary storage buffer is allocated by the algorithm. * * \note * Please note, that for matrix products with more than 8192 intermediate products per * row, additional temporary storage buffer is allocated by the algorithm. * * \note * Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$op(A)\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$op(B)\f$ and * \f$C\f$. * @param[in] * k number of columns of the sparse CSR matrix \f$op(A)\f$ and number of * rows of the sparse CSR matrix \f$op(B)\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrRowPtrA array of \p m+1 elements (\f$op(A) == A\f$, \p k+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(A)\f$. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrRowPtrB array of \p k+1 elements (\f$op(B) == B\f$, \p m+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(B)\f$. * @param[in] * csrColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * descrD descriptor of the sparse CSR matrix \f$D\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzD number of non-zero entries of the sparse CSR matrix \f$D\f$. * @param[in] * csrRowPtrD array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$D\f$. * @param[in] * csrColIndD array of \p nnzD elements containing the column indices of the sparse * CSR matrix \f$D\f$. * @param[inout] * info structure that holds meta data for the sparse CSR matrix \f$C\f$. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer required by * hipsparseXcsrgemm2Nnz(), hipsparseScsrgemm2(), hipsparseDcsrgemm2(), * hipsparseCcsrgemm2() and hipsparseZcsrgemm2(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnzA, \p nnzB, \p nnz_D, * \p alpha, \p beta, \p descrA, \p csrRowPtrA, \p csrColIndA, \p descrB, \p csrRowPtrB, * \p csrColIndB, \p descrD, \p csrRowPtrD, \p csrColIndD, \p info or \p pBufferSizeInBytes * is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes); /**@}*/ #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup extra_module * \details * \p hipsparseXcsrgemm2Nnz computes the total CSR non-zero elements and the CSR row * offsets, that point to the start of every row of the sparse CSR matrix, of the * resulting multiplied matrix \f$C\f$. It is assumed that \p csrRowPtrC has been allocated * with size \p m+1. The required buffer size can be obtained by * \ref hipsparseScsrgemm2_bufferSizeExt "hipsparseXcsrgemm2_bufferSizeExt()". The desired * index base in the output CSR matrix \f$C\f$ is set in the \ref hipsparseMatDescr_t \p descrC. * See \ref hipsparseSetMatIndexBase(). * * \note * As indicated, \p nnzTotalDevHostPtr can point either to host or device memory. This is controlled * by setting the pointer mode. See \ref hipsparseSetPointerMode(). * * \note * This function is non blocking and executed asynchronously with respect to the host. * It may return before the actual computation has finished. * * \note * Please note, that for matrix products with more than 8192 intermediate products per * row, additional temporary storage buffer is allocated by the algorithm. * * \note * Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$op(A)\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$op(B)\f$ and * \f$C\f$. * @param[in] * k number of columns of the sparse CSR matrix \f$op(A)\f$ and number of * rows of the sparse CSR matrix \f$op(B)\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrRowPtrA array of \p m+1 elements (\f$op(A) == A\f$, \p k+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(A)\f$. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrRowPtrB array of \p k+1 elements (\f$op(B) == B\f$, \p m+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(B)\f$. * @param[in] * csrColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * descrD descriptor of the sparse CSR matrix \f$D\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzD number of non-zero entries of the sparse CSR matrix \f$D\f$. * @param[in] * csrRowPtrD array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$D\f$. * @param[in] * csrColIndD array of \p nnzD elements containing the column indices of the sparse * CSR matrix \f$D\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * nnzTotalDevHostPtr pointer to the number of non-zero entries of the sparse CSR * matrix \f$C\f$. * @param[in] * info structure that holds meta data for the sparse CSR matrix \f$C\f$. * @param[in] * pBuffer temporary storage buffer allocated by the user, size is returned * by hipsparseScsrgemm2_bufferSizeExt(), hipsparseDcsrgemm2_bufferSizeExt(), * hipsparseZcsrgemm2_bufferSizeExt() or hipsparseZcsrgemm2_bufferSizeExt(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnzA, \p nnzB, \p nnzD, * \p descrA, \p csrRowPtrA, \p csrColIndA, \p descrB, \p csrRowPtrB, \p csrColIndB, * \p descrD, \p csrRowPtrD, \p csrColIndD, \p descrC, \p csrRowPtrC, \p nnzTotalDevHostPtr, * \p info or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseXcsrgemm2Nnz(hipsparseHandle_t handle, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, const csrgemm2Info_t info, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /*! \ingroup extra_module * \brief Sparse matrix sparse matrix multiplication using CSR storage format * * \details * \p hipsparseXcsrgemm2 multiplies the scalar \f$\alpha\f$ with the sparse * \f$m \times k\f$ matrix \f$A\f$, defined in CSR storage format, and the sparse * \f$k \times n\f$ matrix \f$B\f$, defined in CSR storage format, and adds the result * to the sparse \f$m \times n\f$ matrix \f$D\f$ that is multiplied by \f$\beta\f$. The * final result is stored in the sparse \f$m \times n\f$ matrix \f$C\f$, defined in CSR * storage format, such * that * \f[ * C := \alpha \cdot A \cdot B + \beta \cdot D * \f] * * This computation involves a multi step process. First the user must call * \ref hipsparseScsrgemm2_bufferSizeExt "hipsparseXcsrgemm2_bufferSizeExt()" in order to * determine the required user allocated temporary buffer size. The user then allocates this * buffer and also allocates \p csrRowPtrC to have size \p m+1. Both the temporary storage * buffer and \p csrRowPtrC array are then passed to \ref hipsparseXcsrgemm2Nnz which fills * in the \p csrRowPtrC array as well as computes the total number of nonzeros in C, \p nnzC. * The user then allocates both arrays \p csrColIndC and \p csrValC to have size \p nnzC and * calls \p hipsparseXcsrgemm2 to complete the computation. The desired index base in the output * CSR matrix C is set in the \ref hipsparseMatDescr_t \p descrC. See \ref hipsparseSetMatIndexBase(). * * \note If \f$\alpha == 0\f$, then \f$C = \beta \cdot D\f$ will be computed. * \note If \f$\beta == 0\f$, then \f$C = \alpha \cdot A \cdot B\f$ will be computed. * \note \f$\alpha == beta == 0\f$ is invalid. * \note Currently, only \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * \note This function is non blocking and executed asynchronously with respect to the * host. It may return before the actual computation has finished. * \note Please note, that for matrix products with more than 4096 non-zero entries per * row, additional temporary storage buffer is allocated by the algorithm. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * m number of rows of the sparse CSR matrix \f$op(A)\f$ and \f$C\f$. * @param[in] * n number of columns of the sparse CSR matrix \f$op(B)\f$ and * \f$C\f$. * @param[in] * k number of columns of the sparse CSR matrix \f$op(A)\f$ and number of * rows of the sparse CSR matrix \f$op(B)\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * descrA descriptor of the sparse CSR matrix \f$A\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzA number of non-zero entries of the sparse CSR matrix \f$A\f$. * @param[in] * csrValA array of \p nnzA elements of the sparse CSR matrix \f$A\f$. * @param[in] * csrRowPtrA array of \p m+1 elements (\f$op(A) == A\f$, \p k+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(A)\f$. * @param[in] * csrColIndA array of \p nnzA elements containing the column indices of the * sparse CSR matrix \f$A\f$. * @param[in] * descrB descriptor of the sparse CSR matrix \f$B\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzB number of non-zero entries of the sparse CSR matrix \f$B\f$. * @param[in] * csrValB array of \p nnzB elements of the sparse CSR matrix \f$B\f$. * @param[in] * csrRowPtrB array of \p k+1 elements (\f$op(B) == B\f$, \p m+1 otherwise) * that point to the start of every row of the sparse CSR matrix * \f$op(B)\f$. * @param[in] * csrColIndB array of \p nnzB elements containing the column indices of the * sparse CSR matrix \f$B\f$. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * descrD descriptor of the sparse CSR matrix \f$D\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[in] * nnzD number of non-zero entries of the sparse CSR matrix \f$D\f$. * @param[in] * csrValD array of \p nnzD elements of the sparse CSR matrix \f$D\f$. * @param[in] * csrRowPtrD array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$D\f$. * @param[in] * csrColIndD array of \p nnzD elements containing the column indices of the * sparse CSR matrix \f$D\f$. * @param[in] * descrC descriptor of the sparse CSR matrix \f$C\f$. Currently, only * \ref HIPSPARSE_MATRIX_TYPE_GENERAL is supported. * @param[out] * csrValC array of \p nnzC elements of the sparse CSR matrix \f$C\f$. * @param[in] * csrRowPtrC array of \p m+1 elements that point to the start of every row of the * sparse CSR matrix \f$C\f$. * @param[out] * csrColIndC array of \p nnzC elements containing the column indices of the * sparse CSR matrix \f$C\f$. * @param[in] * info structure that holds meta data for the sparse CSR matrix \f$C\f$. * @param[in] * pBuffer temporary storage buffer allocated by the user, size is returned * by hipsparseScsrgemm2_bufferSizeExt(), hipsparseDcsrgemm2_bufferSizeExt(), * hipsparseCcsrgemm2_bufferSizeExt() or hipsparseZcsrgemm2_bufferSizeExt(). * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p m, \p n, \p k, \p nnzA, \p nnzB, * \p nnzD, \p alpha, \p beta, \p descrA, \p csrValA, \p csrRowPtrA, \p csrColIndA, * \p descrB, \p csrValB, \p csrRowPtrB, \p csrColIndB, \p descrD, \p csrValD, * \p csrRowPtrD, \p csrColIndD, \p csrValC, \p csrRowPtrC, \p csrColIndC, \p info * or \p pBuffer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \ref hipsparseMatrixType_t != \ref HIPSPARSE_MATRIX_TYPE_GENERAL. * * \par Example * \snippet example_hipsparse_csrgemm2.cpp doc example */ /**@{*/ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const float* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const double* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer); DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseZcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipDoubleComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer); /**@}*/ #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_CSRGEMM_H */ ./library/include/internal/generic/0000775000175100017510000000000015176134511017426 5ustar jenkinsjenkins./library/include/internal/generic/hipsparse_spmv.h0000664000175100017510000003716615176134511022657 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPMV_H #define HIPSPARSE_SPMV_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSpMV_bufferSize computes the required user allocated buffer size needed when computing the * sparse matrix multiplication with a dense vector: * \f[ * y := \alpha \cdot op(A) \cdot x + \beta \cdot y, * \f] * where \f$op(A)\f$ is a sparse \f$m \times n\f$ matrix in CSR, CSC, COO, or COO (AoS) format, \f$x\f$ is * a dense vector of length \f$n\f$ and \f$y\f$ is a dense vector of length \f$m\f$. * * \p hipsparseSpMV_bufferSize supports multiple combinations of data types and compute types. See \ref hipsparseSpMV for a complete * listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * vecX vector descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * vecY vector descriptor. * @param[in] * computeType floating point precision for the SpMV computation. * @param[in] * alg SpMV algorithm for the SpMV computation. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p x, \p beta, \p y or * \p pBufferSizeInBytes pointer is invalid or if \p opA, \p computeType, \p alg is incorrect. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \details * \p hipsparseSpMV_preprocess performs analysis on the sparse matrix \f$op(A)\f$ when computing the * sparse matrix multiplication with a dense vector: * \f[ * y := \alpha \cdot op(A) \cdot x + \beta \cdot y, * \f] * where \f$op(A)\f$ is a sparse \f$m \times n\f$ matrix in CSR, CSC, COO, or COO (AoS) format, \f$x\f$ * is a dense vector of length \f$n\f$ and \f$y\f$ is a dense vector of length \f$m\f$. This step is * optional but if used may results in better performance. * * \p hipsparseSpMV_preprocess supports multiple combinations of data types and compute types. See \ref hipsparseSpMV for * a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * vecX vector descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * vecY vector descriptor. * @param[in] * computeType floating point precision for the SpMV computation. * @param[in] * alg SpMV algorithm for the SpMV computation. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p x, \p beta, \p y or * \p externalBuffer pointer is invalid or if \p opA, \p computeType, \p alg is incorrect. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMV_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMV_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer); #endif /*! \ingroup generic_module * \brief Compute the sparse matrix multiplication with a dense vector * * \details * \p hipsparseSpMV multiplies the scalar \f$\alpha\f$ with a sparse \f$m \times n\f$ matrix \f$op(A)\f$, defined in CSR, * CSC, COO, or COO (AoS) format, with the dense vector \f$x\f$ and adds the result to the dense vector \f$y\f$ * that is multiplied by the scalar \f$\beta\f$, such that * \f[ * y := \alpha \cdot op(A) \cdot x + \beta \cdot y, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if trans == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if trans == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * * Performing the above operation involves multiple steps. First the user calls \ref hipsparseSpMV_bufferSize to determine the * size of the required temporary storage buffer. The user then allocates this buffer and calls \ref hipsparseSpMV_preprocess. * Depending on the algorithm and sparse matrix format, this will perform analysis on the sparsity pattern of \f$op(A)\f$. Finally * the user completes the operation by calling \p hipsparseSpMV. The buffer size and preprecess routines only need to be called * once for a given sparse matrix \f$op(A)\f$ while the computation can be repeatedly used with different \f$x\f$ and \f$y\f$ * vectors. Once all calls to \p hipsparseSpMV are complete, the temporary buffer can be deallocated. * * \p hipsparseSpMV supports multiple different algorithms. These algorithms have different trade offs depending on the sparsity * pattern of the matrix, whether or not the results need to be deterministic, and how many times the sparse-vector product will * be performed. * * * * * *
CSR/CSC Algorithms
CSR Algorithms *
HIPSPARSE_SPMV_CSR_ALG1
HIPSPARSE_SPMV_CSR_ALG2
* * * * * *
COO Algorithms
COO Algorithms *
HIPSPARSE_SPMV_COO_ALG1
HIPSPARSE_SPMV_COO_ALG2
* * \p hipsparseSpMV supports multiple combinations of data types and compute types. The tables below indicate the currently * supported data types that can be used for the sparse matrix \f$op(A)\f$ and the dense vectors \f$x\f$ and \f$y\f$ and the * compute type for \f$\alpha\f$ and \f$\beta\f$. The advantage of using different data types is to save on memory bandwidth * and storage when a user application allows while performing the actual computation in a higher precision. * * \par Uniform Precisions: * * *
Uniform Precisions
A / X / Y / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \par Mixed precisions: * * *
Mixed Precisions
A / X Y compute_type *
HIP_R_8I HIP_R_32I HIP_R_32I *
HIP_R_8I HIP_R_32F HIP_R_32F *
HIP_R_16F HIP_R_32F HIP_R_32F *
HIP_R_16BF HIP_R_32F HIP_R_32F *
* * \par Mixed-regular real precisions * * *
Mixed-regular real precisions
A X / Y / compute_type *
HIP_R_32F HIP_R_64F *
HIP_C_32F HIP_C_64F *
* * \par Mixed-regular Complex precisions * * *
Mixed-regular Complex precisions
A X / Y / compute_type *
HIP_R_32F HIP_C_32F *
HIP_R_64F HIP_C_64F *
* * \p hipsparseSpMV supports \ref HIPSPARSE_INDEX_32I and \ref HIPSPARSE_INDEX_64I index precisions * for storing the row pointer and row/column indices arrays of the sparse matrices. * * \note * None of the algorithms above are deterministic when \f$A\f$ is transposed. * * \note * The sparse matrix formats currently supported are: \ref HIPSPARSE_FORMAT_COO, \ref HIPSPARSE_FORMAT_COO_AOS, * \ref HIPSPARSE_FORMAT_CSR, and \ref HIPSPARSE_FORMAT_CSC. * * \note * Only the \ref hipsparseSpMV_bufferSize and \ref hipsparseSpMV routines are non blocking and executed asynchronously * with respect to the host. They may return before the actual computation has finished. The \ref hipsparseSpMV_preprocess * routine is blocking with respect to the host. * * \note * Only the \ref hipsparseSpMV_bufferSize and the \ref hipsparseSpMV routines support execution in a hipGraph context. * The \ref hipsparseSpMV_preprocess stage does not support hipGraph. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * vecX vector descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * vecY vector descriptor. * @param[in] * computeType floating point precision for the SpMV computation. * @param[in] * alg SpMV algorithm for the SpMV computation. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p x, \p beta, \p y or * \p externalBuffer pointer is invalid or if \p opA, \p computeType, \p alg is incorrect. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p computeType or \p alg is * currently not supported. * * \par Example * \snippet example_hipsparse_spmv.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMV(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMV(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPMV_H */ ./library/include/internal/generic/hipsparse_axpby.h0000664000175100017510000000763615176134511023014 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_AXPBY_H #define HIPSPARSE_AXPBY_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \brief Scale a sparse vector and add it to a scaled dense vector. * * \details * \p hipsparseAxpby multiplies the sparse vector \f$x\f$ with scalar \f$\alpha\f$ and * adds the result to the dense vector \f$y\f$ that is multiplied with scalar * \f$\beta\f$, such that * * \f[ * y := \alpha \cdot x + \beta \cdot y * \f] * * \code{.c} * for(i = 0; i < size; ++i) * { * y[i] = beta * y[i] * } * for(i = 0; i < nnz; ++i) * { * y[xInd[i]] += alpha * xVal[i] * } * \endcode * * \p hipsparseAxpby supports the following precision data types for the sparse and dense vectors \f$x\f$ and * \f$y\f$ and compute types for the scalars \f$\alpha\f$ and \f$\beta\f$. * * \par Uniform Precisions: * * *
Uniform Precisions
X / Y / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \par Mixed precisions: * * *
Mixed Precisions
X / Y compute_type *
HIP_R_16F HIP_R_32F *
HIP_R_16BF HIP_R_32F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * vecX sparse matrix descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * vecY dense matrix descriptor. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p vecX, \p beta or \p vecY pointer is * invalid. * * \par Example * \snippet example_hipsparse_axpby.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseAxpby(hipsparseHandle_t handle, const void* alpha, hipsparseConstSpVecDescr_t vecX, const void* beta, hipsparseDnVecDescr_t vecY); #elif(CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseAxpby(hipsparseHandle_t handle, const void* alpha, hipsparseSpVecDescr_t vecX, const void* beta, hipsparseDnVecDescr_t vecY); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_AXPBY_H */ ./library/include/internal/generic/hipsparse_spvv.h0000664000175100017510000001734015176134511022660 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPVV_H #define HIPSPARSE_SPVV_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSpVV_bufferSize computes the required user allocated buffer size needed when computing the * inner dot product of a sparse vector with a dense vector: * \f[ * \text{result} := op(x) \cdot y, * \f] * * \p hipsparseSpVV_bufferSize supports multiple combinations of data types and compute types. See \ref hipsparseSpVV for a complete * listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opX sparse vector operation type. * @param[in] * vecX sparse vector descriptor. * @param[in] * vecY dense vector descriptor. * @param[out] * result pointer to the result, can be host or device memory * @param[in] * computeType floating point precision for the SpVV computation. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p vecX, \p vecY, \p result or \p pBufferSizeInBytes * pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p computeType is currently not * supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseConstSpVecDescr_t vecX, hipsparseConstDnVecDescr_t vecY, void* result, hipDataType computeType, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY, void* result, hipDataType computeType, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \brief Compute the inner dot product of a sparse vector with a dense vector * * \details * \details * \p hipsparseSpVV computes the inner dot product of the sparse vector \f$x\f$ with the * dense vector \f$y\f$, such that * \f[ * \text{result} := op(x) \cdot y, * \f] * with * \f[ * op(x) = \left\{ * \begin{array}{ll} * x, & \text{if trans == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * \bar{x}, & \text{if trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} \\ * \end{array} * \right. * \f] * * \code{.c} * result = 0; * for(i = 0; i < nnz; ++i) * { * result += x_val[i] * y[x_ind[i]]; * } * \endcode * * Performing the above operation involves two steps. First, the user calls \p hipsparseSpVV_bufferSize which will return the * required temporary buffer size. The user then allocates this buffer. Finally, the user then completes the computation by * calling \p hipsparseSpVV with the newly allocated buffer. Once the computation is complete, the user is free to deallocate * the buffer. * * \p hipsparseSpVV supports the following uniform and mixed precision data types for the sparse and dense vectors \f$x\f$ and * \f$y\f$ and compute types for the scalar \f$result\f$. * * \par Uniform Precisions: * * *
Uniform Precisions
X / Y / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \par Mixed precisions: * * *
Mixed Precisions
X / Y compute_type *
HIP_R_8I HIP_R_32I *
HIP_R_8I HIP_R_32F *
HIP_R_16F HIP_R_32F *
HIP_R_16BF HIP_R_32F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opX sparse vector operation type. * @param[in] * vecX sparse vector descriptor. * @param[in] * vecY dense vector descriptor. * @param[out] * result pointer to the result, can be host or device memory * @param[in] * computeType floating point precision for the SpVV computation. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p vecX, \p vecY, \p result or \p externalBuffer * pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p computeType is currently not * supported. * * \par Example * \snippet example_hipsparse_spvv.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVV(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseConstSpVecDescr_t vecX, hipsparseConstDnVecDescr_t vecY, void* result, hipDataType computeType, void* externalBuffer); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVV(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY, void* result, hipDataType computeType, void* externalBuffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPVV_H */ ./library/include/internal/generic/hipsparse_sddmm.h0000664000175100017510000003502315176134511022764 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SDDMM_H #define HIPSPARSE_SDDMM_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSDDMM_bufferSize returns the size of the required buffer needed when computing the sampled * dense-dense matrix multiplication: * \f[ * C := \alpha (op(A) \cdot op(B)) \circ spy(C) + \beta \cdot C, * \f] * where \f$C\f$ is a sparse matrix and \f$A\f$ and \f$B\f$ are dense matrices. This routine is used in * conjunction with \ref hipsparseSDDMM_preprocess() and \ref hipsparseSDDMM(). * * \p hipsparseSDDMM_bufferSize supports multiple combinations of data types and compute types. See \ref hipsparseSDDMM * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA dense matrix \f$A\f$ operation type. * @param[in] * opB dense matrix \f$B\f$ operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * A dense matrix \f$A\f$ descriptor. * @param[in] * B dense matrix \f$B\f$ descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * C sparse matrix \f$C\f$ descriptor. * @param[in] * computeType floating point precision for the SDDMM computation. * @param[in] * alg specification of the algorithm to use. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p beta, \p A, \p B, \p D, \p C or * \p pBufferSizeInBytes pointer is invalid or the value of \p opA or \p opB is incorrect * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \p opB == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSDDMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t A, hipsparseConstDnMatDescr_t B, const void* beta, hipsparseSpMatDescr_t C, hipDataType computeType, hipsparseSDDMMAlg_t alg, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION >= 11022) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSDDMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseDnMatDescr_t A, const hipsparseDnMatDescr_t B, const void* beta, hipsparseSpMatDescr_t C, hipDataType computeType, hipsparseSDDMMAlg_t alg, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \details * \p hipsparseSDDMM_preprocess performs the required preprocessing used when computing the * sampled dense dense matrix multiplication: * \f[ * C := \alpha (op(A) \cdot op(B)) \circ spy(C) + \beta \cdot C, * \f] * where \f$C\f$ is a sparse matrix and \f$A\f$ and \f$B\f$ are dense matrices. This routine is * used in conjunction with \ref hipsparseSDDMM(). * * \p hipsparseSDDMM_preprocess supports multiple combinations of data types and compute types. See \ref hipsparseSDDMM * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA dense matrix \f$A\f$ operation type. * @param[in] * opB dense matrix \f$B\f$ operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * A dense matrix \f$A\f$ descriptor. * @param[in] * B dense matrix \f$B\f$ descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * C sparse matrix \f$C\f$ descriptor. * @param[in] * computeType floating point precision for the SDDMM computation. * @param[in] * alg specification of the algorithm to use. * @param[in] * tempBuffer temporary storage buffer allocated by the user. The size must be greater or equal to * the size obtained with \ref hipsparseSDDMM_bufferSize. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p beta, \p A, \p B, \p C or * \p tempBuffer pointer is invalid or the value of \p opA or \p opB is incorrect. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \p opB == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSDDMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t A, hipsparseConstDnMatDescr_t B, const void* beta, hipsparseSpMatDescr_t C, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer); #elif(CUDART_VERSION >= 11022) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSDDMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseDnMatDescr_t A, const hipsparseDnMatDescr_t B, const void* beta, hipsparseSpMatDescr_t C, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer); #endif /*! \ingroup generic_module * \brief Sampled Dense-Dense Matrix Multiplication. * * \details * \p hipsparseSDDMM multiplies the scalar \f$\alpha\f$ with the dense * \f$m \times k\f$ matrix \f$op(A)\f$, the dense \f$k \times n\f$ matrix \f$op(B)\f$, filtered by the sparsity pattern * of the \f$m \times n\f$ sparse matrix \f$C\f$ and adds the result to \f$C\f$ scaled by * \f$\beta\f$. The final result is stored in the sparse \f$m \times n\f$ matrix \f$C\f$, * such that * \f[ * C := \alpha ( op(A) \cdot op(B) ) \circ spy(C) + \beta C, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if op(A) == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if op(A) == HIPSPARSE_OPERATION_TRANSPOSE} \\ * \end{array} * \right. * \f], * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if op(B) == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if op(B) == HIPSPARSE_OPERATION_TRANSPOSE} \\ * \end{array} * \right. * \f] * and * \f[ * spy(C)_{ij} = \left\{ * \begin{array}{ll} * 1, & \text{ if C_{ij} != 0} \\ * 0, & \text{ otherwise} \\ * \end{array} * \right. * \f] * * Computing the above sampled dense-dense multiplication requires three steps to complete. First, the user calls * \ref hipsparseSDDMM_bufferSize to determine the size of the required temporary storage buffer. Next, the user * allocates this buffer and calls \ref hipsparseSDDMM_preprocess which performs any analysis of the input matrices * that may be required. Finally, the user calls \p hipsparseSDDMM to complete the computation. Once all calls to * \p hipsparseSDDMM are complete, the temporary buffer can be deallocated. * * \p hipsparseSDDMM supports different algorithms which can provide better performance for different matrices. * * * * *
Algorithms
CSR/CSC Algorithms *
HIPSPARSE_SDDMM_ALG_DEFAULT
* * Currently, \p hipsparseSDDMM only supports the uniform precisions indicated in the table below. For the sparse matrix * \f$C\f$, \p hipsparseSDDMM supports the index types \ref HIPSPARSE_INDEX_32I and \ref HIPSPARSE_INDEX_64I. * * \par Uniform Precisions: * * *
Uniform Precisions
A / B / C / compute_type *
HIP_R_16F *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \par Mixed precisions: * * *
Mixed Precisions
A / B C compute_type *
HIP_R_16F HIP_R_32F HIP_R_32F *
HIP_R_16F HIP_R_16F HIP_R_32F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA dense matrix \f$A\f$ operation type. * @param[in] * opB dense matrix \f$B\f$ operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * A dense matrix \f$A\f$ descriptor. * @param[in] * B dense matrix \f$B\f$ descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[inout] * C sparse matrix \f$C\f$ descriptor. * @param[in] * computeType floating point precision for the SDDMM computation. * @param[in] * alg specification of the algorithm to use. * @param[in] * tempBuffer temporary storage buffer allocated by the user. The size must be greater or equal to * the size obtained with \ref hipsparseSDDMM_bufferSize. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p beta, \p A, \p B, \p C or * \p tempBuffer pointer is invalid or the value of \p opA or \p opB is incorrect. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE or * \p opB == \ref HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE. * * \par Example * This example performs sampled dense-dense matrix product, \f$C := \alpha ( A \cdot B ) \circ spy(C) + \beta C\f$ * where \f$\circ\f$ is the hadamard product * \snippet example_hipsparse_sddmm.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSDDMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t A, hipsparseConstDnMatDescr_t B, const void* beta, hipsparseSpMatDescr_t C, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer); #elif(CUDART_VERSION >= 11022) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSDDMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseDnMatDescr_t A, const hipsparseDnMatDescr_t B, const void* beta, hipsparseSpMatDescr_t C, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SDDMM_H */ ./library/include/internal/generic/hipsparse_spsv.h0000664000175100017510000003131415176134511022652 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPSV_H #define HIPSPARSE_SPSV_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSpSV_createDescr creates a sparse matrix triangular solve descriptor. It should be * destroyed at the end using \ref hipsparseSpSV_destroyDescr(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_createDescr(hipsparseSpSVDescr_t* descr); #endif /*! \ingroup generic_module * \details * \p hipsparseSpSV_destroyDescr destroys a sparse matrix triangular solve descriptor and releases all * resources used by the descriptor. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_destroyDescr(hipsparseSpSVDescr_t descr); #endif /*! \ingroup generic_module * \details * \p hipsparseSpSV_bufferSize computes the size of the required user allocated buffer needed when solving the * triangular linear system: * \f[ * op(A) \cdot y := \alpha \cdot x, * \f] * where \f$op(A)\f$ is a sparse matrix in CSR or COO storage format, \f$x\f$ and \f$y\f$ are dense vectors. * * \p hipsparseSpSV_bufferSize supports multiple combinations of data types and compute types. See \ref hipsparseSpSV_solve * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * x vector descriptor. * @param[inout] * y vector descriptor. * @param[in] * computeType floating point precision for the SpSV computation. * @param[in] * alg SpSV algorithm for the SpSV computation. * @param[in] * spsvDescr SpSV descriptor. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p x, \p y, \p spsvDescr or * \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION >= 11030) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \details * \p hipsparseSpSV_analysis performs the required analysis needed when solving the * triangular linear system: * \f[ * op(A) \cdot y := \alpha \cdot x, * \f] * where \f$op(A)\f$ is a sparse matrix in CSR or COO storage format, \f$x\f$ and \f$y\f$ are dense vectors. * * \p hipsparseSpSV_analysis supports multiple combinations of data types and compute types. See \ref hipsparseSpSV_solve * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * x vector descriptor. * @param[inout] * y vector descriptor. * @param[in] * computeType floating point precision for the SpSV computation. * @param[in] * alg SpSV algorithm for the SpSV computation. * @param[in] * spsvDescr SpSV descriptor. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p x, \p y, \p spsvDescr or * \p externalBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, void* externalBuffer); #elif(CUDART_VERSION >= 11030) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, void* externalBuffer); #endif /*! \ingroup generic_module * \brief Sparse triangular solve * * \details * \p hipsparseSpSV_solve solves a triangular linear system of equations defined by a sparse \f$m \times m\f$ square matrix * \f$op(A)\f$, given in CSR or COO storage format, such that * \f[ * op(A) \cdot y = \alpha \cdot x, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if trans == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if trans == HIPSPARSE_OPERATION_TRANSPOSE} * \end{array} * \right. * \f] * and where \f$y\f$ is the dense solution vector and \f$x\f$ is the dense right-hand side vector. * * Performing the above operation requires three steps. First, \ref hipsparseSpSV_bufferSize must be called which will * determine the size of the required temporary storage buffer. The user then allocates this buffer and calls * \ref hipsparseSpSV_analysis which will perform analysis on the sparse matrix \f$op(A)\f$. Finally, the user completes * the computation by calling \p hipsparseSpSV_solve. The buffer size and preprecess routines only need to be called once * for a given sparse matrix \f$op(A)\f$ while the computation can be repeatedly used with different \f$x\f$ and \f$y\f$ * vectors. Once all calls to \p hipsparseSpSV_solve are complete, the temporary buffer can be deallocated. * * \p hipsparseSpSV_solve supports \ref HIPSPARSE_INDEX_32I and \ref HIPSPARSE_INDEX_64I index types for * storing the row pointer and column indices arrays of the sparse matrices. \p hipsparseSpSV_solve supports the following * data types for \f$op(A)\f$, \f$x\f$, \f$y\f$ and compute types for \f$\alpha\f$: * * \par Uniform Precisions: * * *
Uniform Precisions
A / X / Y / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * x vector descriptor. * @param[inout] * y vector descriptor. * @param[in] * computeType floating point precision for the SpSV computation. * @param[in] * alg SpSV algorithm for the SpSV computation. * @param[in] * spsvDescr SpSV descriptor. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p x, \p y, or \p spsvDescr * pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p computeType or \p alg is * currently not supported. * * \par Example * \snippet example_hipsparse_spsv.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr); #elif(CUDART_VERSION >= 11030) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSV_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPSV_H */ ./library/include/internal/generic/hipsparse_spsm.h0000664000175100017510000003640415176134511022646 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPSM_H #define HIPSPARSE_SPSM_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSpSM_createDescr creates a sparse matrix triangular solve with multiple rhs descriptor. It should be * destroyed at the end using \ref hipsparseSpSM_destroyDescr(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_createDescr(hipsparseSpSMDescr_t* descr); #endif /*! \ingroup generic_module * \details * \p hipsparseSpSM_destroyDescr destroys a sparse matrix triangular solve with multiple rhs descriptor and releases all * resources used by the descriptor. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_destroyDescr(hipsparseSpSMDescr_t descr); #endif /*! \ingroup generic_module * \details * \p hipsparseSpSM_bufferSize computes the size of the required user allocated buffer needed when solving the * triangular linear system: * \f[ * op(A) \cdot C := \alpha \cdot op(B), * \f] * where \f$op(A)\f$ is a square sparse matrix in CSR or COO storage format, \f$B\f$ and \f$C\f$ are dense matrices. * * \p hipsparseSpSM_bufferSize supports multiple combinations of data types and compute types. See \ref hipsparseSpSM_solve * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type for the sparse matrix \f$A\f$. * @param[in] * opB matrix operation type for the dense matrix \f$B\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA sparse matrix descriptor. * @param[in] * matB dense matrix descriptor. * @param[inout] * matC dense matrix descriptor. * @param[in] * computeType floating point precision for the SpSM computation. * @param[in] * alg SpSM algorithm for the SpSM computation. * @param[in] * spsmDescr SpSM descriptor. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p matB, \p matC, \p spsmDescr or * \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p opB, \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \details * \p hipsparseSpSM_analysis performs the required analysis needed when solving the * triangular linear system: * \f[ * op(A) \cdot C := \alpha \cdot op(B), * \f] * where \f$A\f$ is a sparse matrix in CSR or COO storage format, \f$B\f$ and \f$C\f$ are dense vectors. * * \p hipsparseSpSM_bufferSize supports multiple combinations of data types and compute types. See \ref hipsparseSpSM_solve * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type for the sparse matrix \f$A\f$. * @param[in] * opB matrix operation type for the dense matrix \f$B\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA sparse matrix descriptor. * @param[in] * matB dense matrix descriptor. * @param[inout] * matC dense matrix descriptor. * @param[in] * computeType floating point precision for the SpSM computation. * @param[in] * alg SpSM algorithm for the SpSM computation. * @param[in] * spsmDescr SpSM descriptor. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p matB, \p matC, \p spsmDescr or * \p externalBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p opB, \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer); #elif(CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer); #endif /*! \ingroup generic_module * \brief Sparse triangular system solve * * \details * \p hipsparseSpSM_solve solves a triangular linear system of equations defined by a sparse \f$m \times m\f$ square matrix \f$op(A)\f$, * given in CSR or COO storage format, such that * \f[ * op(A) \cdot C = \alpha \cdot op(B), * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if opA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if opB == HIPSPARSE_OPERATION_TRANSPOSE} * \end{array} * \right. * \f] * and * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if opA == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if opB == HIPSPARSE_OPERATION_TRANSPOSE} * \end{array} * \right. * \f] * and where \f$C\f$ is the dense solution matrix and \f$B\f$ is the dense right-hand side matrix. Both \f$B\f$ * and \f$C\f$ can be in row or column order. * * Performing the above operation requires three steps. First, the user calls \ref hipsparseSpSM_bufferSize in order to * determine the size of the required temporary storage buffer. The user then allocates this buffer and calls * \ref hipsparseSpSM_analysis which will perform analysis on the sparse matrix \f$op(A)\f$. Finally, the user completes * the computation by calling \p hipsparseSpSM_solve. The buffer size and analysis routines only need to be called once * for a given sparse matrix \f$op(A)\f$ while the computation can be called repeatedly with different \f$B\f$ and \f$C\f$ * matrices. Once all calls to \p hipsparseSpSM_solve are complete, the temporary buffer can be deallocated. * * As noted above, both \f$B\f$ and \f$C\f$ can be in row or column order (this includes mixing the order so that \f$B\f$ is * row order and \f$C\f$ is column order and vice versa). When running on an AMD system with the rocSPARSE backend, the kernels * solve the system assuming the matrices \f$B\f$ and \f$C\f$ are in row order as this provides the best memory access. This * means that if the matrix \f$C\f$ is not in row order and/or the matrix \f$B\f$ is not row order (or \f$B^{T}\f$ is not column * order as this is equivalent to being in row order), then internally memory copies and/or transposing of data may be performed * to get them into the correct order (possbily using extra buffer size). Once computation is completed, additional memory copies * and/or transposing of data may be performed to get them back into the user arrays. For best performance and smallest required * temporary storage buffers on an AMD system, use row order for the matrix \f$C\f$ and row order for the matrix \f$B\f$ (or column * order if \f$B\f$ is being transposed). * * \p hipsparseSpSM_solve supports \ref HIPSPARSE_INDEX_32I and \ref HIPSPARSE_INDEX_64I index precisions for storing the * row pointer and column indices arrays of the sparse matrices. \p hipsparseSpSM_solve supports the following data types for * \f$op(A)\f$, \f$op(B)\f$, \f$C\f$ and compute types for \f$\alpha\f$: * * \par Uniform Precisions: * * *
Uniform Precisions
A / B / C / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type for the sparse matrix \f$A\f$. * @param[in] * opB matrix operation type for the dense matrix \f$B\f$. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA sparse matrix descriptor. * @param[in] * matB dense matrix descriptor. * @param[inout] * matC dense matrix descriptor. * @param[in] * computeType floating point precision for the SpSM computation. * @param[in] * alg SpSM algorithm for the SpSM computation. * @param[in] * spsmDescr SpSM descriptor. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p matB, \p matC, \p spsmDescr or * \p externalBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p opB, \p computeType or \p alg is * currently not supported. * * \par Example * \snippet example_hipsparse_spsm.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer); #elif(CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpSM_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPSM_H */ ./library/include/internal/generic/hipsparse_spgemm_reuse.h0000664000175100017510000004556415176134511024366 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPGEMM_REUSE_H #define HIPSPARSE_SPGEMM_REUSE_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \brief Work estimation step of the sparse matrix sparse matrix product: * \f[ * C' := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$C'\f$, \f$A\f$, \f$B\f$, \f$C\f$ are sparse matrices and \f$C'\f$ and \f$C\f$ have the same sparsity pattern. * * \details * \p hipsparseSpGEMMreuse_workEstimation is called twice. We call it to compute the size of the first required user allocated * buffer. After this buffer size is determined, the user allocates it and calls \p hipsparseSpGEMMreuse_workEstimation * a second time with the newly allocated buffer passed in. This second call inspects the matrices \f$A\f$ and \f$B\f$ to * determine the number of intermediate products that will result from multipltying \f$A\f$ and \f$B\f$ together. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA sparse matrix \f$A\f$ operation type. * @param[in] * opB sparse matrix \f$B\f$ operation type. * @param[in] * matA sparse matrix \f$A\f$ descriptor. * @param[in] * matB sparse matrix \f$B\f$ descriptor. * @param[out] * matC sparse matrix \f$C\f$ descriptor. * @param[in] * alg SpGEMM algorithm for the SpGEMM computation. * @param[in] * spgemmDescr SpGEMM descriptor. * @param[out] * bufferSize1 number of bytes of the temporary storage buffer. * @param[in] * externalBuffer1 temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, \p matC or \p bufferSize1 pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p opB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. * * \par Example (See full example below) * \code{.c} * void* dBuffer1 = NULL; * size_t bufferSize1 = 0; * * hipsparseSpGEMMDescr_t spgemmDesc; * hipsparseSpGEMM_createDescr(&spgemmDesc); * * size_t bufferSize1 = 0; * hipsparseSpGEMMreuse_workEstimation(handle, opA, opB, matA, matB, matC, * HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, * &bufferSize1, NULL); * hipMalloc((void**) &dBuffer1, bufferSize1); * * // Determine number of intermediate product when computing A * B * hipsparseSpGEMMreuse_workEstimation(handle, opA, opB, matA, matB, matC, * HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, * &bufferSize1, dBuffer1); * \endcode */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1); #elif(CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1); #endif /*! \ingroup generic_module * \brief Nnz calculation step of the sparse matrix sparse matrix product: * \f[ * C' := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$C'\f$, \f$A\f$, \f$B\f$, \f$C\f$ are sparse matrices and \f$C'\f$ and \f$C\f$ have the same sparsity pattern. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA sparse matrix \f$A\f$ operation type. * @param[in] * opB sparse matrix \f$B\f$ operation type. * @param[in] * matA sparse matrix \f$A\f$ descriptor. * @param[in] * matB sparse matrix \f$B\f$ descriptor. * @param[out] * matC sparse matrix \f$C\f$ descriptor. * @param[in] * alg SpGEMM algorithm for the SpGEMM computation. * @param[in] * spgemmDescr SpGEMM descriptor. * @param[out] * bufferSize2 number of bytes of the temporary storage \p externalBuffer2. * @param[in] * externalBuffer2 temporary storage buffer allocated by the user. * @param[out] * bufferSize3 number of bytes of the temporary storage \p externalBuffer3. * @param[in] * externalBuffer3 temporary storage buffer allocated by the user. * @param[out] * bufferSize4 number of bytes of the temporary storage \p externalBuffer4. * @param[in] * externalBuffer4 temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, \p matC, \p bufferSize2, \p bufferSize3 * or \p bufferSize4 pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p opB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. * * \par Example (See full example below) * \code{.c} * // Determine size of second, third, and fourth user allocated buffer * hipsparseSpGEMMreuse_nnz(handle, opA, opB, matA, matB, * matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, * &bufferSize2, NULL, &bufferSize3, NULL, * &bufferSize4, NULL); * * hipMalloc((void**) &dBuffer2, bufferSize2); * hipMalloc((void**) &dBuffer3, bufferSize3); * hipMalloc((void**) &dBuffer4, bufferSize4); * * // COmpute sparsity pattern of C matrix and store in temporary buffers * hipsparseSpGEMMreuse_nnz(handle, opA, opB, matA, matB, * matC, HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, * &bufferSize2, dBuffer2, &bufferSize3, dBuffer3, * &bufferSize4, dBuffer4); * * // We can now free buffer 1 and 2 * hipFree(dBuffer1); * hipFree(dBuffer2); * \endcode */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_nnz(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2, size_t* bufferSize3, void* externalBuffer3, size_t* bufferSize4, void* externalBuffer4); #elif(CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_nnz(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2, size_t* bufferSize3, void* externalBuffer3, size_t* bufferSize4, void* externalBuffer4); #endif /*! \ingroup generic_module * \brief Copy step of the sparse matrix sparse matrix product: * \f[ * C' := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$C'\f$, \f$A\f$, \f$B\f$, \f$C\f$ are sparse matrices and \f$C'\f$ and \f$C\f$ have the same sparsity pattern. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA sparse matrix \f$A\f$ operation type. * @param[in] * opB sparse matrix \f$B\f$ operation type. * @param[in] * matA sparse matrix \f$A\f$ descriptor. * @param[in] * matB sparse matrix \f$B\f$ descriptor. * @param[out] * matC sparse matrix \f$C\f$ descriptor. * @param[in] * alg SpGEMM algorithm for the SpGEMM computation. * @param[in] * spgemmDescr SpGEMM descriptor. * @param[out] * bufferSize5 number of bytes of the temporary storage \p externalBuffer5. * @param[in] * externalBuffer5 temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, \p matC, or \p bufferSize5 pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p opB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. * * \par Example (See full example below) * \code{.c} * // Get matrix C non-zero entries nnzC * int64_t rowsC, colsC, nnzC; * hipsparseSpMatGetSize(matC, &rowsC, &colsC, &nnzC); * * // Allocate matrix C * hipMalloc((void**) &dcsrColIndC, sizeof(int) * nnzC); * hipMalloc((void**) &dcsrValC, sizeof(float) * nnzC); * * // Update matC with the new pointers. The C values array can be filled with data here * // which is used if beta != 0. * hipsparseCsrSetPointers(matC, dcsrRowPtrC, dcsrColIndC, dcsrValC); * * // Determine size of fifth user allocated buffer * hipsparseSpGEMMreuse_copy(handle, opA, opB, matA, matB, matC, * HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, * &bufferSize5, NULL); * * hipMalloc((void**) &dBuffer5, bufferSize5); * * // Copy data from temporary buffers to the newly allocated C matrix * hipsparseSpGEMMreuse_copy(handle, opA, opB, matA, matB, matC, * HIPSPARSE_SPGEMM_DEFAULT, spgemmDesc, * &bufferSize5, dBuffer5); * * // We can now free buffer 3 * hipFree(dBuffer3); * \endcode */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize5, void* externalBuffer5); #elif(CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize5, void* externalBuffer5); #endif /*! \ingroup generic_module * \brief Copy step of the sparse matrix sparse matrix product: * \f[ * C' := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$C'\f$, \f$A\f$, \f$B\f$, \f$C\f$ are sparse matrices and \f$C'\f$ and \f$C\f$ have the same sparsity pattern. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA sparse matrix \f$A\f$ operation type. * @param[in] * opB sparse matrix \f$B\f$ operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA sparse matrix \f$A\f$ descriptor. * @param[in] * matB sparse matrix \f$B\f$ descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[out] * matC sparse matrix \f$C\f$ descriptor. * @param[in] * computeType floating point precision for the SpGEMM computation. * @param[in] * alg SpGEMM algorithm for the SpGEMM computation. * @param[in] * spgemmDescr SpGEMM descriptor. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p beta, \p matA, \p matB, or \p matC * pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p opB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. * * \par Example * \snippet example_hipsparse_spgemm_reuse.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr); #elif(CUDART_VERSION >= 11031) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMMreuse_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPGEMM_REUSE_H */ ./library/include/internal/generic/hipsparse_spgemm.h0000664000175100017510000004262315176134511023154 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPGEMM_H #define HIPSPARSE_SPGEMM_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSpGEMM_createDescr creates a sparse matrix sparse matrix product descriptor. It should be * destroyed at the end using \ref hipsparseSpGEMM_destroyDescr(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_createDescr(hipsparseSpGEMMDescr_t* descr); #endif /*! \ingroup generic_module * \details * \p hipsparseSpGEMM_destroyDescr destroys a sparse matrix sparse matrix product descriptor and releases all * resources used by the descriptor. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_destroyDescr(hipsparseSpGEMMDescr_t descr); #endif /*! \ingroup generic_module * \brief Work estimation step of the sparse matrix sparse matrix product: * \f[ * C' := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$C'\f$, \f$A\f$, \f$B\f$, \f$C\f$ are sparse matrices and \f$C'\f$ and \f$C\f$ have the same sparsity pattern. * * \details * \p hipsparseSpGEMM_workEstimation is called twice. We call it to compute the size of the first required user allocated * buffer. After this buffer size is determined, the user allocates it and calls \p hipsparseSpGEMM_workEstimation * a second time with the newly allocated buffer passed in. This second call inspects the matrices \f$A\f$ and \f$B\f$ to * determine the number of intermediate products that will result from multipltying \f$A\f$ and \f$B\f$ together. * * \p hipsparseSpGEMM_workEstimation supports multiple combinations of data types and compute types. See \ref hipsparseSpGEMM_copy * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA sparse matrix \f$A\f$ operation type. * @param[in] * opB sparse matrix \f$B\f$ operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA sparse matrix \f$A\f$ descriptor. * @param[in] * matB sparse matrix \f$B\f$ descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[out] * matC sparse matrix \f$C\f$ descriptor. * @param[in] * computeType floating point precision for the SpGEMM computation. * @param[in] * alg SpGEMM algorithm for the SpGEMM computation. * @param[in] * spgemmDescr SpGEMM descriptor. * @param[out] * bufferSize1 number of bytes of the temporary storage buffer. * @param[in] * externalBuffer1 temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p beta, \p matA, \p matB, \p matC * or \p bufferSize1 pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p opB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. * * \par Example (See full example below) * \code{.c} * void* dBuffer1 = NULL; * size_t bufferSize1 = 0; * * hipsparseSpGEMMDescr_t spgemmDesc; * hipsparseSpGEMM_createDescr(&spgemmDesc); * * size_t bufferSize1 = 0; * hipsparseSpGEMM_workEstimation(handle, opA, opB, * &alpha, matA, matB, &beta, matC, * computeType, HIPSPARSE_SPGEMM_DEFAULT, * spgemmDesc, &bufferSize1, NULL); * hipMalloc((void**) &dBuffer1, bufferSize1); * * // Determine number of intermediate product when computing A * B * hipsparseSpGEMM_workEstimation(handle, opA, opB, * &alpha, matA, matB, &beta, matC, * computeType, HIPSPARSE_SPGEMM_DEFAULT, * spgemmDesc, &bufferSize1, dBuffer1); * \endcode */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1); #elif(CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1); #endif /*! \ingroup generic_module * \brief Compute step of the sparse matrix sparse matrix product: * \f[ * C' := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$C'\f$, \f$A\f$, \f$B\f$, \f$C\f$ are sparse matrices and \f$C'\f$ and \f$C\f$ have the same sparsity pattern. * * \details * \p hipsparseSpGEMM_compute is called twice. First to compute the size of the second required user allocated * buffer. After this buffer size is determined, the user allocates it and calls \p hipsparseSpGEMM_compute * a second time with the newly allocated buffer passed in. This second call performs the actual computation * of \f$C' = \alpha \cdot A \cdot B\f$ (the result is stored in the temporary buffers). * * \p hipsparseSpGEMM_compute supports multiple combinations of data types and compute types. See \ref hipsparseSpGEMM_copy * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA sparse matrix \f$A\f$ operation type. * @param[in] * opB sparse matrix \f$B\f$ operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA sparse matrix \f$A\f$ descriptor. * @param[in] * matB sparse matrix \f$B\f$ descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[out] * matC sparse matrix \f$C\f$ descriptor. * @param[in] * computeType floating point precision for the SpGEMM computation. * @param[in] * alg SpGEMM algorithm for the SpGEMM computation. * @param[in] * spgemmDescr SpGEMM descriptor. * @param[out] * bufferSize2 number of bytes of the temporary storage buffer. * @param[in] * externalBuffer2 temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p beta, \p matA, \p matB, \p matC * or \p bufferSize2 pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p opB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. * * \par Example (See full example below) * \code{.c} * void* dBuffer2 = NULL; * size_t bufferSize2 = 0; * * size_t bufferSize2 = 0; * hipsparseSpGEMM_compute(handle, opA, opB, * &alpha, matA, matB, &beta, matC, * computeType, HIPSPARSE_SPGEMM_DEFAULT, * spgemmDesc, &bufferSize2, NULL); * hipMalloc((void**) &dBuffer2, bufferSize2); * * // compute the intermediate product of A * B * hipsparseSpGEMM_compute(handle, opA, opB, * &alpha, matA, matB, &beta, matC, * computeType, HIPSPARSE_SPGEMM_DEFAULT, * spgemmDesc, &bufferSize2, dBuffer2); * \endcode */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2); #elif(CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2); #endif /*! \ingroup generic_module * \brief Copy step of the sparse matrix sparse matrix product: * \f[ * C' := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$C'\f$, \f$A\f$, \f$B\f$, \f$C\f$ are sparse matrices and \f$C'\f$ and \f$C\f$ have the same sparsity pattern. * * \details * \p hipsparseSpGEMM_copy is called once to copy the results (that are currently stored in the temporary arrays) * to the output sparse matrix. If \f$\beta != 0\f$, then the \f$beta \cdot C\f$ portion of the computation: * \f$C' = \alpha \cdot A \cdot B + \beta * C\f$ is handled. This is possible because \f$C'\f$ and \f$C\f$ must have * the same sparsity pattern. * * \p hipsparseSpGEMM_copy supports multiple combinations of data types and compute types. The tables below indicate the currently * supported different data types that can be used for for the sparse matrices \f$op(A)\f$, \f$op(B)\f$, \f$C\f$, and \f$C'\f$ * and the compute type for \f$\alpha\f$ and \f$\beta\f$. The advantage of using different data types is to save on * memory bandwidth and storage when a user application allows while performing the actual computation in a higher precision. * * \par Uniform Precisions: * * *
Uniform Precisions
A / B / C / C' / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \p hipsparseSpGEMM_copy supports \ref HIPSPARSE_INDEX_32I and \ref HIPSPARSE_INDEX_64I index precisions * for storing the row pointer and row/column indices arrays of the sparse matrices. * * \note The two user allocated temporary buffers can only be freed after the call to \p hipsparseSpGEMM_copy * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA sparse matrix \f$A\f$ operation type. * @param[in] * opB sparse matrix \f$B\f$ operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA sparse matrix \f$A\f$ descriptor. * @param[in] * matB sparse matrix \f$B\f$ descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[out] * matC sparse matrix \f$C\f$ descriptor. * @param[in] * computeType floating point precision for the SpGEMM computation. * @param[in] * alg SpGEMM algorithm for the SpGEMM computation. * @param[in] * spgemmDescr SpGEMM descriptor. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p beta, \p matA, \p matB, \p matC pointer is invalid. * \retval HIPSPARSE_STATUS_ALLOC_FAILED additional buffer for long rows could not be * allocated. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED * \p opA != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE or * \p opB != \ref HIPSPARSE_OPERATION_NON_TRANSPOSE. * * \par Example (Full example) * \snippet example_hipsparse_spgemm.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr); #elif(CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpGEMM_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPGEMM_H */ ./library/include/internal/generic/hipsparse_dense2sparse.h0000664000175100017510000002610615176134511024260 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_DENSE2SPARSE_H #define HIPSPARSE_DENSE2SPARSE_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseDenseToSparse_bufferSize computes the required user allocated buffer size needed when converting * a dense matrix to a sparse matrix. This routine currently accepts the sparse matrix descriptor \p matB in CSR, * CSC, or COO format. This routine is used to determine the size of the buffer * needed in \ref hipsparseDenseToSparse_analysis and \ref hipsparseDenseToSparse_convert. * * \p hipsparseDenseToSparse_bufferSize supports different data types for the dense and sparse matrices. See * \ref hipsparseDenseToSparse_convert for a complete listing of all the data types available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * matA dense matrix descriptor. * @param[in] * matB sparse matrix descriptor. * @param[in] * alg algorithm for the dense to sparse computation. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, or \p pBufferSizeInBytes * pointer is invalid. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDenseToSparse_bufferSize(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION >= 11020) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDenseToSparse_bufferSize(hipsparseHandle_t handle, hipsparseDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \details * \p hipsparseDenseToSparse_analysis performs analysis that is later used in \ref hipsparseDenseToSparse_convert when * converting a dense matrix to sparse matrix. This routine currently accepts the sparse matrix descriptor \p matB in CSR, * CSC, or COO format. This routine takes a user allocated buffer whose size must first be computed * using \ref hipsparseDenseToSparse_bufferSize. * * \p hipsparseDenseToSparse_analysis supports different data types for the dense and sparse matrices. See * \ref hipsparseDenseToSparse_convert for a complete listing of all the data types available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * matA dense matrix descriptor. * @param[in] * matB sparse matrix descriptor. * @param[in] * alg algorithm for the dense to sparse computation. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, or \p externalBuffer * pointer is invalid. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDenseToSparse_analysis(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer); #elif(CUDART_VERSION >= 11020) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDenseToSparse_analysis(hipsparseHandle_t handle, hipsparseDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer); #endif /*! \ingroup generic_module * \brief Dense matrix to sparse matrix conversion * * \details * \p hipsparseDenseToSparse_convert converts a dense matrix to a sparse matrix. This routine currently accepts * the sparse matrix descriptor \p matB in CSR, CSC, or COO format. This routine requires a user allocated buffer * whose size must be determined by first calling \ref hipsparseDenseToSparse_bufferSize. * * The conversion of a dense matrix into a sparse one involves three steps. First, the user creates the dense and * sparse matrix descriptors. Because the number of non-zeros that will exist in the sparse matrix is not known apriori, * when creating the sparse matrix descriptor, the user simply sets the arrays to \p NULL and the non-zero count to zero. * For example, in the case of a CSR sparse matrix, this would look like: * \code{.c} * hipsparseCreateCsr(&matB, * m, * n, * 0, * dcsrRowPtrB, // This array can be allocated as its size (i.e. m + 1) is known * NULL, // Column indices array size is not yet known, pass NULL for now * NULL, // Values array size is not yet known, pass NULL for now * rowIdxTypeB, * colIdxTypeB, * idxBaseB, * dataTypeB); * \endcode * In the case of a COO sparse matrix, this would look like: * \code{.c} * hipsparseCreateCoo(&matB, * m, * n, * 0, * NULL, // Row indices array size is not yet known, pass NULL for now * NULL, // Column indices array size is not yet known, pass NULL for now * NULL, // Values array size is not yet known, pass NULL for now * rowIdxTypeB, * colIdxTypeB, * idxBaseB, * dataTypeB); * \endcode * Once the descriptors have been created, the user calls \ref hipsparseDenseToSparse_bufferSize. This routine will * determine the size of the required temporary storage buffer. The user then allocates this buffer and passes it to * \ref hipsparseDenseToSparse_analysis which will perform analysis on the dense matrix in order to determine the number * of non-zeros that will exist in the sparse matrix. Once this \ref hipsparseDenseToSparse_analysis routine has been * called, the non-zero count is stored in the sparse matrix descriptor \p matB. In order to allocate our remaining sparse * matrix arrays, we query the sparse matrix descriptor \p matB for this non-zero count: * \code{.c} * // Grab the non-zero count from the B matrix decriptor * int64_t rows; * int64_t cols; * int64_t nnz; * hipsparseSpMatGetSize(matB, &rows, &cols, &nnz); * \endcode * The remaining arrays are then allocated and set on the sparse matrix descriptor \p matB. Finally, we complete the * conversion by calling \ref hipsparseDenseToSparse_convert. Once the conversion is complete, the user is free to deallocate * the storage buffer. See full example below for details. * * \p hipsparseDenseToSparse_convert supports the following uniform precision data types for the dense and sparse matrices \f$A\f$ * and \f$B\f$: * * \par Uniform Precisions: * * *
Uniform Precisions
A / B *
HIP_R_16F *
HIP_R_16BF *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \note Currently only the sparse matrix formats CSR, CSC, and COO are supported when converting a dense matrix to a sparse matrix. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * matA dense matrix descriptor. * @param[in] * matB sparse matrix descriptor. * @param[in] * alg algorithm for the dense to sparse computation. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, or \p externalBuffer * pointer is invalid. * * \par Example * \snippet example_hipsparse_dense_to_sparse.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDenseToSparse_convert(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer); #elif(CUDART_VERSION >= 11020) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDenseToSparse_convert(hipsparseHandle_t handle, hipsparseDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_DENSE2SPARSE_H */ ./library/include/internal/generic/hipsparse_sparse2dense.h0000664000175100017510000001505315176134511024257 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPARSE2DENSE_H #define HIPSPARSE_SPARSE2DENSE_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSparseToDense_bufferSize computes the required user allocated buffer size needed when converting * a sparse matrix to a dense matrix. This routine currently accepts the sparse matrix descriptor \p matA in CSR, * CSC, or COO format. This routine is used to determine the size of the buffer needed in \ref hipsparseSparseToDense. * * \p hipsparseSparseToDense_bufferSize supports different data types for the sparse and dense matrices. See * \ref hipsparseSparseToDense for a complete listing of all the data types available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * matA sparse matrix descriptor. * @param[in] * matB dense matrix descriptor. * @param[in] * alg algorithm for the sparse to dense computation. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, or \p pBufferSizeInBytes * pointer is invalid. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSparseToDense_bufferSize(hipsparseHandle_t handle, hipsparseConstSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION >= 11020) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSparseToDense_bufferSize(hipsparseHandle_t handle, hipsparseSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \brief Sparse matrix to dense matrix conversion * * \details * \p hipsparseSparseToDense converts a sparse matrix to a dense matrix. This routine currently accepts * the sparse matrix descriptor \p matA in CSR, CSC, or COO format. This routine takes a user allocated buffer * whose size must first be computed by calling \ref hipsparseSparseToDense_bufferSize * * The conversion of a sparse matrix into a dense one involves two steps. First, the user creates the sparse and * dense matrix descriptors and calls \ref hipsparseSparseToDense_bufferSize to determine the size of the required * temporary storage buffer. The user then allocates this buffer and passes it to \ref hipsparseSparseToDense in * order to complete the conversion. Once the conversion is complete, the user is free to deallocate the storage * buffer. See full example below for details. * * \p hipsparseSparseToDense supports the following uniform precision data types for the sparse and dense matrices \f$A\f$ * and \f$B\f$: * * \par Uniform Precisions: * * *
Uniform Precisions
A / B *
HIP_R_16F *
HIP_R_16BF *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \note Currently only the sparse matrix formats CSR, CSC, and COO are supported when converting a sparse matrix to a dense matrix. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * matA sparse matrix descriptor. * @param[in] * matB dense matrix descriptor. * @param[in] * alg algorithm for the sparse to dense computation. * @param[in] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p matA, \p matB, or \p externalBuffer * pointer is invalid. * * \par Example * \snippet example_hipsparse_sparse_to_dense.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSparseToDense(hipsparseHandle_t handle, hipsparseConstSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, void* externalBuffer); #elif(CUDART_VERSION >= 11020) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSparseToDense(hipsparseHandle_t handle, hipsparseSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, void* externalBuffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPARSE2DENSE_H */ ./library/include/internal/generic/hipsparse_gather.h0000664000175100017510000000623215176134511023132 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GATHER_H #define HIPSPARSE_GATHER_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \brief Gather elements from a dense vector and store them into a sparse vector. * * \details * \p hipsparseGather gathers the elements from the dense vector \f$y\f$ and stores * them in the sparse vector \f$x\f$. * * \code{.c} * for(i = 0; i < nnz; ++i) * { * x_val[i] = y[x_ind[i]]; * } * \endcode * * \p hipsparseGather supports the following uniform precision data types for the sparse and dense vectors \f$x\f$ and * \f$y\f$. * * \par Uniform Precisions: * * *
Uniform Precisions
X / Y *
HIP_R_8I *
HIP_R_16F *
HIP_R_16BF *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * vecY dense vector descriptor \f$y\f$. * @param[out] * vecX sparse vector descriptor \f$x\f$. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p vecX or \p vecY pointer is invalid. * * \par Example * \snippet example_hipsparse_gather.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseGather(hipsparseHandle_t handle, hipsparseConstDnVecDescr_t vecY, hipsparseSpVecDescr_t vecX); #elif(CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseGather(hipsparseHandle_t handle, hipsparseDnVecDescr_t vecY, hipsparseSpVecDescr_t vecX); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GATHER_H */ ./library/include/internal/generic/hipsparse_scatter.h0000664000175100017510000000621215176134511023323 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SCATTER_H #define HIPSPARSE_SCATTER_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \brief Scatter elements from a sparse vector into a dense vector. * * \details * \p hipsparseScatter scatters the elements from the sparse vector \f$x\f$ in the dense * vector \f$y\f$. * * \code{.c} * for(i = 0; i < nnz; ++i) * { * y[x_ind[i]] = x_val[i]; * } * \endcode * * \p hipsparseScatter supports the following uniform precision data types for the sparse and dense vectors \f$x\f$ and * \f$y\f$. * * \par Uniform Precisions: * * *
Uniform Precisions
X / Y *
HIP_R_8I *
HIP_R_16F *
HIP_R_16BF *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * vecX sparse vector descriptor \f$x\f$. * @param[out] * vecY dense vector descriptor \f$y\f$. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p vecX or \p vecY pointer is invalid. * * \par Example * \snippet example_hipsparse_scatter.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScatter(hipsparseHandle_t handle, hipsparseConstSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY); #elif(CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseScatter(hipsparseHandle_t handle, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SCATTER_H */ ./library/include/internal/generic/hipsparse_spmm.h0000664000175100017510000004252615176134511022642 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_SPMM_H #define HIPSPARSE_SPMM_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \details * \p hipsparseSpMM_bufferSize computes the required user allocated buffer size needed when computing the * sparse matrix multiplication with a dense matrix: * \f[ * C := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$op(A)\f$ is a sparse \f$m \times k\f$ matrix in CSR, COO, BSR or Blocked ELL storage format, * \f$B\f$ is a dense matrix of size \f$k \times n\f$ and \f$C\f$ is a dense matrix of size \f$m \times n\f$. * * \p hipsparseSpMM_bufferSize supports multiple combinations of data types and compute types. See \ref hipsparseSpMM * for a complete listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * opB matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * matB matrix descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * matC matrix descriptor. * @param[in] * computeType floating point precision for the SpMM computation. * @param[in] * alg SpMM algorithm for the SpMM computation. * @param[out] * pBufferSizeInBytes number of bytes of the temporary storage buffer. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p matB, \p matC, \p beta, or * \p pBufferSizeInBytes pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p opB, \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, size_t* pBufferSizeInBytes); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, size_t* pBufferSizeInBytes); #endif /*! \ingroup generic_module * \details * \p hipsparseSpMM_preprocess performs the required preprocessing used when computing the * sparse matrix multiplication with a dense matrix: * \f[ * C := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * where \f$op(A)\f$ is a sparse \f$m \times k\f$ matrix in CSR, COO, BSR or Blocked ELL storage format, * \f$B\f$ is a dense matrix of size \f$k \times n\f$ and \f$C\f$ is a dense matrix of size \f$m \times n\f$. * * \p hipsparseSpMM_preprocess supports multiple combinations of data types and compute types. See \ref hipsparseSpMM for a complete * listing of all the data type and compute type combinations available. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * opB matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * matB matrix descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * matC matrix descriptor. * @param[in] * computeType floating point precision for the SpMM computation. * @param[in] * alg SpMM algorithm for the SpMM computation. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p matB, \p matC, \p beta, or * \p externalBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p opB, \p computeType or \p alg is * currently not supported. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer); #elif(CUDART_VERSION >= 11021) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer); #endif /*! \ingroup generic_module * \brief Compute the sparse matrix multiplication with a dense matrix * * \details * \p hipsparseSpMM multiplies the scalar \f$\alpha\f$ with a sparse \f$m \times k\f$ matrix \f$op(A)\f$, * defined in CSR, COO, BSR or Blocked ELL storage format, and the dense \f$k \times n\f$ matrix \f$op(B)\f$ * and adds the result to the dense \f$m \times n\f$ matrix \f$C\f$ that is multiplied by the scalar * \f$\beta\f$, such that * \f[ * C := \alpha \cdot op(A) \cdot op(B) + \beta \cdot C, * \f] * with * \f[ * op(A) = \left\{ * \begin{array}{ll} * A, & \text{if trans_A == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * A^T, & \text{if trans_A == HIPSPARSE_OPERATION_TRANSPOSE} \\ * A^H, & \text{if trans_A == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * and * \f[ * op(B) = \left\{ * \begin{array}{ll} * B, & \text{if trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE} \\ * B^T, & \text{if trans_B == HIPSPARSE_OPERATION_TRANSPOSE} \\ * B^H, & \text{if trans_B == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE} * \end{array} * \right. * \f] * Both \f$B\f$ and \f$C\f$ can be in row or column order. * * \p hipsparseSpMM requires three stages to complete. First, the user calls \ref hipsparseSpMM_bufferSize to determine * the size of the required temporary storage buffer. Next, the user allocates this buffer and calls * \ref hipsparseSpMM_preprocess which will perform analysis on the sparse matrix \f$op(A)\f$. Finally, the user calls * \p hipsparseSpMM to perform the actual computation. The buffer size and preprecess routines only need to be called once for a given * sparse matrix \f$op(A)\f$ while the computation routine can be repeatedly used with different \f$B\f$ and \f$C\f$ matrices. * Once all calls to \p hipsparseSpMM are complete, the temporary buffer can be deallocated. * * As noted above, both \f$B\f$ and \f$C\f$ can be in row or column order (this includes mixing the order so that \f$B\f$ is * row order and \f$C\f$ is column order and vice versa). For best performance, use row order for both \f$B\f$ and \f$C\f$ as * this provides the best memory access. * * \p hipsparseSpMM supports multiple different algorithms. These algorithms have different trade offs depending on the sparsity * pattern of the matrix, whether or not the results need to be deterministic, and how many times the sparse-matrix product will * be performed. * * * * * * *
CSR Algorithms
CSR Algorithms *
HIPSPARSE_SPMM_CSR_ALG1
HIPSPARSE_SPMM_CSR_ALG2
HIPSPARSE_SPMM_CSR_ALG3
* * * * * * * *
COO Algorithms
COO Algorithms *
HIPSPARSE_SPMM_COO_ALG1
HIPSPARSE_SPMM_COO_ALG2
HIPSPARSE_SPMM_COO_ALG3
HIPSPARSE_SPMM_COO_ALG4
* * * * *
Blocked-ELL Algorithms
ELL Algorithms *
HIPSPARSE_SPMM_BLOCKED_ELL_ALG1
* * * * *
BSR Algorithms
BSR Algorithms *
CUSPARSE_SPMM_BSR_ALG1
* * One can also pass \ref HIPSPARSE_SPMM_ALG_DEFAULT which will automatically select from the algorithms listed above * based on the sparse matrix format. * * When A is transposed, \p hipsparseSpMM will revert to using \ref HIPSPARSE_SPMM_CSR_ALG2 * for CSR format and \ref HIPSPARSE_SPMM_COO_ALG1 for COO format regardless of algorithm selected. * * \p hipsparseSpMM supports multiple combinations of data types and compute types. The tables below indicate the currently * supported different data types that can be used for for the sparse matrix \f$op(A)\f$ and the dense matrices \f$op(B)\f$ and * \f$C\f$ and the compute type for \f$\alpha\f$ and \f$\beta\f$. The advantage of using different data types is to save on * memory bandwidth and storage when a user application allows while performing the actual computation in a higher precision. * * \par Uniform Precisions: * * *
Uniform Precisions
A / B / C / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * \par Mixed precisions: * * *
Mixed Precisions
A / B C compute_type *
HIP_R_8I HIP_R_32I HIP_R_32I *
HIP_R_8I HIP_R_32F HIP_R_32F *
HIP_R_16F HIP_R_32F HIP_R_32F *
HIP_R_16BF HIP_R_32F HIP_R_32F *
* * \p hipsparseSpMM supports \ref HIPSPARSE_INDEX_32I and \ref HIPSPARSE_INDEX_64I index precisions * for storing the row pointer and column indices arrays of the sparse matrices. * * \p hipsparseSpMM also supports batched computation for CSR and COO matrices. There are three supported batch modes: * \f[ * C_i = A \times B_i \\ * C_i = A_i \times B \\ * C_i = A_i \times B_i * \f] * * The batch mode is determined by the batch count and stride passed for each matrix. For example * to use the first batch mode (\f$C_i = A \times B_i\f$) with 100 batches for non-transposed \f$A\f$, * \f$B\f$, and \f$C\f$, one passes: * \f[ * batchCountA=1 \\ * batchCountB=100 \\ * batchCountC=100 \\ * offsetsBatchStrideA=0 \\ * columnsValuesBatchStrideA=0 \\ * batchStrideB=k*n \\ * batchStrideC=m*n * \f] * To use the second batch mode (\f$C_i = A_i \times B\f$) one could use: * \f[ * batchCountA=100 \\ * batchCountB=1 \\ * batchCountC=100 \\ * offsetsBatchStrideA=m+1 \\ * columnsValuesBatchStrideA=nnz \\ * batchStrideB=0 \\ * batchStrideC=m*n * \f] * And to use the third batch mode (\f$C_i = A_i \times B_i\f$) one could use: * \f[ * batchCountA=100 \\ * batchCountB=100 \\ * batchCountC=100 \\ * offsetsBatchStrideA=m+1 \\ * columnsValuesBatchStrideA=nnz \\ * batchStrideB=k*n \\ * batchStrideC=m*n * \f] * See examples below. * * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * opA matrix operation type. * @param[in] * opB matrix operation type. * @param[in] * alpha scalar \f$\alpha\f$. * @param[in] * matA matrix descriptor. * @param[in] * matB matrix descriptor. * @param[in] * beta scalar \f$\beta\f$. * @param[in] * matC matrix descriptor. * @param[in] * computeType floating point precision for the SpMM computation. * @param[in] * alg SpMM algorithm for the SpMM computation. * @param[out] * externalBuffer temporary storage buffer allocated by the user. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p alpha, \p matA, \p matB, \p matC, \p beta, or * \p externalBuffer pointer is invalid. * \retval HIPSPARSE_STATUS_NOT_SUPPORTED \p opA, \p opB, \p computeType or \p alg is * currently not supported. * * \par Example * \snippet example_hipsparse_spmm.cpp doc example */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_SPMM_H */ ./library/include/internal/generic/hipsparse_rot.h0000664000175100017510000000677615176134511022501 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_ROT_H #define HIPSPARSE_ROT_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \brief Apply Givens rotation to a dense and a sparse vector. * * \details * \p hipsparseRot applies the Givens rotation matrix \f$G\f$ to the sparse vector * \f$x\f$ and the dense vector \f$y\f$, where * \f[ * G = \begin{pmatrix} c & s \\ -s & c \end{pmatrix} * \f] * * \code{.c} * for(i = 0; i < nnz; ++i) * { * x_tmp = x_val[i]; * y_tmp = y[x_ind[i]]; * * x_val[i] = c * x_tmp + s * y_tmp; * y[x_ind[i]] = c * y_tmp - s * x_tmp; * } * \endcode * * \p hipsparseRot supports the following uniform precision data types for the sparse and dense vectors \f$x\f$ and * \f$y\f$ and compute types for the scalars \f$c\f$ and \f$s\f$. * * \par Uniform Precisions: * * *
Uniform Precisions
X / Y / compute_type *
HIP_R_32F *
HIP_R_64F *
HIP_C_32F *
HIP_C_64F *
* * @param[in] * handle handle to the hipsparse library context queue. * @param[in] * c_coeff pointer to the cosine element of \f$G\f$, can be on host or device. * @param[in] * s_coeff pointer to the sine element of \f$G\f$, can be on host or device. * @param[inout] * vecX sparse vector descriptor \f$x\f$. * @param[inout] * vecY dense vector descriptor \f$y\f$. * * \retval HIPSPARSE_STATUS_SUCCESS the operation completed successfully. * \retval HIPSPARSE_STATUS_INVALID_VALUE \p handle, \p c_coeff, \p s_coeff, \p vecX or \p vecY pointer is * invalid. * * \par Example * \snippet example_hipsparse_rot.cpp doc example */ #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11000 && CUDART_VERSION < 13000)) DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseRot(hipsparseHandle_t handle, const void* c_coeff, const void* s_coeff, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_ROT_H */ ./library/include/hipsparse-version.h.in0000664000175100017510000000334615176134305020444 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*!\file * \brief hipsparse-version.h provides the configured version and settings */ #ifndef HIPSPARSE_VERSION_H #define HIPSPARSE_VERSION_H // clang-format off #define hipsparseVersionMajor @hipsparse_VERSION_MAJOR@ #define hipsparseVersionMinor @hipsparse_VERSION_MINOR@ #define hipsparseVersionPatch @hipsparse_VERSION_PATCH@ #define hipsparseVersionTweak @hipsparse_VERSION_TWEAK@ // clang-format on #endif /* HIPSPARSE_VERSION_H */ ./library/include/hipsparse-types.h0000664000175100017510000005216715176134511017522 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_TYPES_H #define HIPSPARSE_TYPES_H /// \cond DO_NOT_DOCUMENT // Forward declarations struct bsrsv2Info; struct bsrsm2Info; struct bsrilu02Info; struct bsric02Info; struct csrsv2Info; struct csrsm2Info; struct csrilu02Info; struct csric02Info; struct csrgemm2Info; struct pruneInfo; struct csru2csrInfo; /// \endcond /*! \ingroup types_module * \brief Handle to the hipSPARSE library context queue. * * \details * The hipSPARSE handle is a structure holding the hipSPARSE library context. It must * be initialized using hipsparseCreate() and the returned handle must be passed to all * subsequent library function calls. It should be destroyed at the end using * hipsparseDestroy(). */ typedef void* hipsparseHandle_t; /*! \ingroup types_module * \brief Descriptor of the matrix. * * \details * The hipSPARSE matrix descriptor is a structure holding all properties of a matrix. * It must be initialized using hipsparseCreateMatDescr() and the returned descriptor * must be passed to all subsequent library calls that involve the matrix. It should be * destroyed at the end using hipsparseDestroyMatDescr(). */ typedef void* hipsparseMatDescr_t; /*! \ingroup types_module * \brief HYB matrix storage format. * * \details * The hipSPARSE HYB matrix structure holds the HYB matrix. It must be initialized using * hipsparseCreateHybMat() and the returned HYB matrix must be passed to all subsequent * library calls that involve the matrix. It should be destroyed at the end using * hipsparseDestroyHybMat(). */ typedef void* hipsparseHybMat_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding coloring info. * * \details * The hipSPARSE ColorInfo structure holds the coloring information. It must be * initialized using hipsparseCreateColorInfo() and the returned structure must be * passed to all subsequent library calls that involve the coloring. It should be * destroyed at the end using hipsparseDestroyColorInfo(). */ typedef void* hipsparseColorInfo_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding bsrsv2 info. * * \details * The hipSPARSE bsrsv2 structure holds the information used by hipsparseXbsrsv2_zeroPivot(), * \ref hipsparseSbsrsv2_bufferSize "hipsparseXbsrsv2_bufferSize()", \ref hipsparseSbsrsv2_bufferSizeExt * "hipsparseXbsrsv2_bufferSizeExt()", \ref hipsparseSbsrsv2_analysis "hipsparseXbsrsv2_analysis()", * and \ref hipsparseSbsrsv2_solve "hipsparseXbsrsv2_solve()". It must be initialized using * hipsparseCreateBsrsv2Info() and the returned structure must be passed to all subsequent library calls * that involve bsrsv2. It should be destroyed at the end using hipsparseDestroyBsrsv2Info(). */ typedef struct bsrsv2Info* bsrsv2Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding bsrsm2 info. * * \details * The hipSPARSE bsrsm2 structure holds the information used by hipsparseXbsrsm2_zeroPivot(), * \ref hipsparseSbsrsm2_bufferSize "hipsparseXbsrsm2_bufferSize()", \ref hipsparseSbsrsm2_analysis * "hipsparseXbsrsm2_analysis()", and \ref hipsparseSbsrsm2_solve "hipsparseXbsrsm2_solve()". It * must be initialized using hipsparseCreateBsrsm2Info() and the returned structure must be * passed to all subsequent library calls that involve bsrsm2. It should be * destroyed at the end using hipsparseDestroyBsrsm2Info(). */ typedef struct bsrsm2Info* bsrsm2Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding bsrilu02 info. * * \details * The hipSPARSE bsrilu02 structure holds the information used by hipsparseXbsrilu02_zeroPivot(), * \ref hipsparseSbsrilu02_numericBoost "hipsparseXbsrilu02_numericBoost()", \ref hipsparseSbsrilu02_bufferSize * "hipsparseXbsrilu02_bufferSize()", \ref hipsparseSbsrilu02_analysis "hipsparseXbsrilu02_analysis()", * and \ref hipsparseSbsrilu02 "hipsparseXbsrilu02()". It must be initialized using hipsparseCreateBsrilu02Info() * and the returned structure must be passed to all subsequent library calls that involve bsrilu02. It should be * destroyed at the end using hipsparseDestroyBsrilu02Info(). */ typedef struct bsrilu02Info* bsrilu02Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding bsric02 info. * * \details * The hipSPARSE bsric02 structure holds the information used by hipsparseXbsric02_zeroPivot(), * \ref hipsparseSbsric02_bufferSize "hipsparseXbsric02_bufferSize()", \ref hipsparseSbsric02_analysis * "hipsparseXbsric02_analysis()", and \ref hipsparseSbsric02 "hipsparseXbsric02()". It must be initialized using * hipsparseCreateBsric02Info() and the returned structure must be passed to all subsequent library calls * that involve bsric02. It should be destroyed at the end using hipsparseDestroyBsric02Info(). */ typedef struct bsric02Info* bsric02Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding csrsv2 info. * * \details * The hipSPARSE csrsv2 structure holds the information used by hipsparseXcsrsv2_zeroPivot(), * \ref hipsparseScsrsv2_bufferSize "hipsparseXcsrsv2_bufferSize()", \ref hipsparseScsrsv2_analysis * "hipsparseXcsrsv2_analysis()", and \ref hipsparseScsrsv2_solve "hipsparseXcsrsv2_solve()". It must be initialized using * hipsparseCreateCsrsv2Info() and the returned structure must be passed to all subsequent library calls * that involve csrsv2. It should be destroyed at the end using hipsparseDestroyCsrsv2Info(). */ typedef struct csrsv2Info* csrsv2Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding csrsm2 info. * * \details * The hipSPARSE csrsm2 structure holds the information used by hipsparseXcsrsm2_zeroPivot(), * \ref hipsparseScsrsm2_bufferSizeExt "hipsparseXcsrsm2_bufferSizeExt()", \ref hipsparseScsrsm2_analysis * "hipsparseXcsrsm2_analysis()", and \ref hipsparseScsrsm2_solve "hipsparseXcsrsm2_solve()". It must be initialized using * hipsparseCreateCsrsm2Info() and the returned structure must be passed to all subsequent library calls * that involve csrsm2. It should be destroyed at the end using hipsparseDestroyCsrsm2Info(). */ typedef struct csrsm2Info* csrsm2Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding csrilu02 info. * * \details * The hipSPARSE csrilu02 structure holds the information used by hipsparseXcsrilu02_zeroPivot(), * \ref hipsparseScsrilu02_numericBoost "hipsparseXcsrilu02_numericBoost()", \ref hipsparseScsrilu02_bufferSize * "hipsparseXcsrilu02_bufferSize()", \ref hipsparseScsrilu02_analysis "hipsparseXcsrilu02_analysis()", * and \ref hipsparseScsrilu02 "hipsparseXcsrilu02()". It must be initialized using hipsparseCreateCsrilu02Info() * and the returned structure must be passed to all subsequent library calls that involve csrilu02. It should be * destroyed at the end using hipsparseDestroyCsrilu02Info(). */ typedef struct csrilu02Info* csrilu02Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding csric02 info. * * \details * The hipSPARSE csric02 structure holds the information used by hipsparseXcsric02_zeroPivot(), * \ref hipsparseScsric02_bufferSize "hipsparseXcsric02_bufferSize()", \ref hipsparseScsric02_analysis * "hipsparseXcsric02_analysis()", and \ref hipsparseScsric02 "hipsparseXcsric02()". It must be * initialized using hipsparseCreateCsric02Info() and the returned structure must be passed to all * subsequent library calls that involve csric02. It should be destroyed at the end using * hipsparseDestroyCsric02Info(). */ typedef struct csric02Info* csric02Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding csrgemm2 info. * * \details * The hipSPARSE csrgemm2 structure holds the information used by \ref hipsparseScsrgemm2_bufferSizeExt * "hipsparseXcsrgemm2_bufferSizeExt()", hipsparseXcsrgemm2Nnz(), and \ref hipsparseScsrgemm2 "hipsparseXcsrgemm2()". * It must be initialized using hipsparseCreateCsrgemm2Info() and the returned structure must be passed to all * subsequent library calls that involve csrgemm2. It should be destroyed at the end using * hipsparseDestroyCsrgemm2Info(). */ typedef struct csrgemm2Info* csrgemm2Info_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding prune info. * * \details * The hipSPARSE prune structure holds the information used by \ref hipsparseSpruneDense2csrByPercentage_bufferSize * "hipsparseXpruneDense2csrByPercentage_bufferSize()", \ref hipsparseSpruneDense2csrByPercentage_bufferSizeExt * "hipsparseXpruneDense2csrByPercentage_bufferSizeExt()", \ref hipsparseSpruneCsr2csrByPercentage_bufferSize * "hipsparseXpruneCsr2csrByPercentage_bufferSize()", \ref hipsparseSpruneCsr2csrByPercentage_bufferSizeExt * "hipsparseXpruneCsr2csrByPercentage_bufferSizeExt()", \ref hipsparseSpruneDense2csrNnzByPercentage * "hipsparseXpruneDense2csrNnzByPercentage()", \ref hipsparseSpruneCsr2csrNnzByPercentage * "hipsparseXpruneCsr2csrNnzByPercentage()", \ref hipsparseSpruneDense2csrByPercentage * "hipsparseXpruneDense2csrByPercentage()", and \ref hipsparseSpruneCsr2csrByPercentage * "hipsparseXpruneCsr2csrByPercentage()". It must be initialized using hipsparseCreatePruneInfo() and the * returned structure must be passed to all subsequent library calls that involve prune. It should be * destroyed at the end using hipsparseDestroyPruneInfo(). */ typedef struct pruneInfo* pruneInfo_t; /*! \ingroup types_module * \brief Pointer type to opaque structure holding csru2csr info. * * \details * The hipSPARSE csru2csr structure holds the information used by \ref hipsparseScsru2csr_bufferSizeExt * "hipsparseXcsru2csr_bufferSizeExt()", \ref hipsparseScsru2csr "hipsparseXcsru2csr()", and * \ref hipsparseScsr2csru "hipsparseXcsr2csru()". It must be initialized using hipsparseCreateCsru2csrInfo() * and the returned structure must be passed to all subsequent library calls that involve csru2csr. It should be * destroyed at the end using hipsparseDestroyCsru2csrInfo(). */ typedef struct csru2csrInfo* csru2csrInfo_t; // clang-format off /*! \ingroup types_module * \brief List of hipsparse status codes definition. * * \details * This is a list of the \ref hipsparseStatus_t types that are used by the hipSPARSE * library. */ #if(!defined(CUDART_VERSION)) typedef enum { HIPSPARSE_STATUS_SUCCESS = 0, /**< Function succeeds */ HIPSPARSE_STATUS_NOT_INITIALIZED = 1, /**< hipSPARSE was not initialized */ HIPSPARSE_STATUS_ALLOC_FAILED = 2, /**< Resource allocation failed */ HIPSPARSE_STATUS_INVALID_VALUE = 3, /**< Unsupported value was passed to the function */ HIPSPARSE_STATUS_ARCH_MISMATCH = 4, /**< Device architecture not supported */ HIPSPARSE_STATUS_MAPPING_ERROR = 5, /**< Access to GPU memory space failed */ HIPSPARSE_STATUS_EXECUTION_FAILED = 6, /**< GPU program failed to execute */ HIPSPARSE_STATUS_INTERNAL_ERROR = 7, /**< An internal hipSPARSE operation failed */ HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED = 8, /**< Matrix type not supported */ HIPSPARSE_STATUS_ZERO_PIVOT = 9, /**< Zero pivot was computed */ HIPSPARSE_STATUS_NOT_SUPPORTED = 10, /**< Operation is not supported */ HIPSPARSE_STATUS_INSUFFICIENT_RESOURCES = 11 /**< Resources are insufficient */ } hipsparseStatus_t; #else #if(CUDART_VERSION >= 11003) typedef enum { HIPSPARSE_STATUS_SUCCESS = 0, /**< Function succeeds */ HIPSPARSE_STATUS_NOT_INITIALIZED = 1, /**< hipSPARSE was not initialized */ HIPSPARSE_STATUS_ALLOC_FAILED = 2, /**< Resource allocation failed */ HIPSPARSE_STATUS_INVALID_VALUE = 3, /**< Unsupported value was passed to the function */ HIPSPARSE_STATUS_ARCH_MISMATCH = 4, /**< Device architecture not supported */ HIPSPARSE_STATUS_MAPPING_ERROR = 5, /**< Access to GPU memory space failed */ HIPSPARSE_STATUS_EXECUTION_FAILED = 6, /**< GPU program failed to execute */ HIPSPARSE_STATUS_INTERNAL_ERROR = 7, /**< An internal hipSPARSE operation failed */ HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED = 8, /**< Matrix type not supported */ HIPSPARSE_STATUS_ZERO_PIVOT = 9, /**< Zero pivot was computed */ HIPSPARSE_STATUS_NOT_SUPPORTED = 10, /**< Operation is not supported */ HIPSPARSE_STATUS_INSUFFICIENT_RESOURCES = 11 /**< Resources are insufficient */ } hipsparseStatus_t; #elif(CUDART_VERSION >= 10010) typedef enum { HIPSPARSE_STATUS_SUCCESS = 0, /**< Function succeeds */ HIPSPARSE_STATUS_NOT_INITIALIZED = 1, /**< hipSPARSE was not initialized */ HIPSPARSE_STATUS_ALLOC_FAILED = 2, /**< Resource allocation failed */ HIPSPARSE_STATUS_INVALID_VALUE = 3, /**< Unsupported value was passed to the function */ HIPSPARSE_STATUS_ARCH_MISMATCH = 4, /**< Device architecture not supported */ HIPSPARSE_STATUS_MAPPING_ERROR = 5, /**< Access to GPU memory space failed */ HIPSPARSE_STATUS_EXECUTION_FAILED = 6, /**< GPU program failed to execute */ HIPSPARSE_STATUS_INTERNAL_ERROR = 7, /**< An internal hipSPARSE operation failed */ HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED = 8, /**< Matrix type not supported */ HIPSPARSE_STATUS_ZERO_PIVOT = 9, /**< Zero pivot was computed */ HIPSPARSE_STATUS_NOT_SUPPORTED = 10 /**< Operation is not supported */ } hipsparseStatus_t; #endif #endif /*! \ingroup types_module * \brief Indicates if the pointer is device pointer or host pointer. * * \details * The \ref hipsparsePointerMode_t indicates whether scalar values are passed by * reference on the host or device. The \ref hipsparsePointerMode_t can be changed by * hipsparseSetPointerMode(). The currently used pointer mode can be obtained by * hipsparseGetPointerMode(). */ typedef enum { HIPSPARSE_POINTER_MODE_HOST = 0, /**< Scalar pointers are in host memory */ HIPSPARSE_POINTER_MODE_DEVICE = 1 /**< Scalar pointers are in device memory */ } hipsparsePointerMode_t; /*! \ingroup types_module * \brief Specify where the operation is performed on. * * \details * The \ref hipsparseAction_t indicates whether the operation is performed on the full * matrix, or only on the sparsity pattern of the matrix. */ typedef enum { HIPSPARSE_ACTION_SYMBOLIC = 0, /**< Operate only on indices */ HIPSPARSE_ACTION_NUMERIC = 1 /**< Operate on data and indices */ } hipsparseAction_t; /*! \ingroup types_module * \brief Specify the matrix type. * * \details * The \ref hipsparseMatrixType_t indices the type of a matrix. For a given * \ref hipsparseMatDescr_t, the \ref hipsparseMatrixType_t can be set using * hipsparseSetMatType(). The current \ref hipsparseMatrixType_t of a matrix can be * obtained by hipsparseGetMatType(). */ typedef enum { HIPSPARSE_MATRIX_TYPE_GENERAL = 0, /**< General matrix type */ HIPSPARSE_MATRIX_TYPE_SYMMETRIC = 1, /**< Symmetric matrix type */ HIPSPARSE_MATRIX_TYPE_HERMITIAN = 2, /**< Hermitian matrix type */ HIPSPARSE_MATRIX_TYPE_TRIANGULAR = 3 /**< Triangular matrix type */ } hipsparseMatrixType_t; /*! \ingroup types_module * \brief Specify the matrix fill mode. * * \details * The \ref hipsparseFillMode_t indicates whether the lower or the upper part is stored * in a sparse triangular matrix. For a given \ref hipsparseMatDescr_t, the * \ref hipsparseFillMode_t can be set using hipsparseSetMatFillMode(). The current * \ref hipsparseFillMode_t of a matrix can be obtained by hipsparseGetMatFillMode(). */ typedef enum { HIPSPARSE_FILL_MODE_LOWER = 0, /**< Lower triangular part is stored */ HIPSPARSE_FILL_MODE_UPPER = 1 /**< Upper triangular part is stored */ } hipsparseFillMode_t; /*! \ingroup types_module * \brief Indicates if the diagonal entries are unity. * * \details * The \ref hipsparseDiagType_t indicates whether the diagonal entries of a matrix are * unity or not. If \ref HIPSPARSE_DIAG_TYPE_UNIT is specified, all present diagonal * values will be ignored. For a given \ref hipsparseMatDescr_t, the * \ref hipsparseDiagType_t can be set using hipsparseSetMatDiagType(). The current * \ref hipsparseDiagType_t of a matrix can be obtained by hipsparseGetMatDiagType(). */ typedef enum { HIPSPARSE_DIAG_TYPE_NON_UNIT = 0, /**< Diagonal entries are non-unity */ HIPSPARSE_DIAG_TYPE_UNIT = 1 /**< Diagonal entries are unity */ } hipsparseDiagType_t; /*! \ingroup types_module * \brief Specify the matrix index base. * * \details * The \ref hipsparseIndexBase_t indicates the index base of the indices. For a * given \ref hipsparseMatDescr_t, the \ref hipsparseIndexBase_t can be set using * hipsparseSetMatIndexBase(). The current \ref hipsparseIndexBase_t of a matrix * can be obtained by hipsparseGetMatIndexBase(). */ typedef enum { HIPSPARSE_INDEX_BASE_ZERO = 0, /**< Zero based indexing */ HIPSPARSE_INDEX_BASE_ONE = 1 /**< One based indexing */ } hipsparseIndexBase_t; /*! \ingroup types_module * \brief Specify whether the matrix is to be transposed or not. * * \details * The \ref hipsparseOperation_t indicates the operation performed with the given matrix. */ typedef enum { HIPSPARSE_OPERATION_NON_TRANSPOSE = 0, /**< Operate with matrix */ HIPSPARSE_OPERATION_TRANSPOSE = 1, /**< Operate with transpose */ HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE = 2 /**< Operate with conj. transpose */ } hipsparseOperation_t; /*! \ingroup types_module * \brief HYB matrix partitioning type. * * \details * The \ref hipsparseHybPartition_t type indicates how the hybrid format partitioning * between COO and ELL storage formats is performed. */ typedef enum { HIPSPARSE_HYB_PARTITION_AUTO = 0, /**< Automatically decide on ELL nnz per row */ HIPSPARSE_HYB_PARTITION_USER = 1, /**< User given ELL nnz per row */ HIPSPARSE_HYB_PARTITION_MAX = 2 /**< Max ELL nnz per row, no COO part */ } hipsparseHybPartition_t; /*! \ingroup types_module * \brief Specify policy in triangular solvers and factorizations. * * \details * The \ref hipsparseSolvePolicy_t type indicates the solve policy for the triangular * solve. */ typedef enum { HIPSPARSE_SOLVE_POLICY_NO_LEVEL = 0, /**< No level information generated */ HIPSPARSE_SOLVE_POLICY_USE_LEVEL = 1 /**< Generate level information */ } hipsparseSolvePolicy_t; /// \cond DO_NOT_DOCUMENT // Note: Add back to types.rst if we get documentation for this in the future typedef enum { HIPSPARSE_SIDE_LEFT = 0, HIPSPARSE_SIDE_RIGHT = 1 } hipsparseSideMode_t; /// \endcond /*! \ingroup types_module * \brief Specify the matrix direction. * * \details * The \ref hipsparseDirection_t indicates whether a dense matrix should be parsed by * rows or by columns, assuming column-major storage. */ typedef enum { HIPSPARSE_DIRECTION_ROW = 0, /**< Parse the matrix by rows */ HIPSPARSE_DIRECTION_COLUMN = 1 /**< Parse the matrix by columns */ } hipsparseDirection_t; /*! \ingroup types_module * \brief List of hipsparse csr2csc algorithms. * * \details * This is a list of the \ref hipsparseCsr2CscAlg_t algorithms that can be used by the hipSPARSE * library routines \ref hipsparseCsr2cscEx2_bufferSize and \ref hipsparseCsr2cscEx2. */ #if(!defined(CUDART_VERSION)) typedef enum { HIPSPARSE_CSR2CSC_ALG_DEFAULT = 0, HIPSPARSE_CSR2CSC_ALG1 = 1, HIPSPARSE_CSR2CSC_ALG2 = 2 } hipsparseCsr2CscAlg_t; #else #if(CUDART_VERSION >= 12000) typedef enum { HIPSPARSE_CSR2CSC_ALG_DEFAULT = 0, HIPSPARSE_CSR2CSC_ALG1 = 1 } hipsparseCsr2CscAlg_t; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) typedef enum { HIPSPARSE_CSR2CSC_ALG1 = 1, HIPSPARSE_CSR2CSC_ALG2 = 2 } hipsparseCsr2CscAlg_t; #endif #endif // clang-format on #endif /* HIPSPARSE_TYPES_H */ ./library/include/hipsparse-auxiliary.h0000664000175100017510000005050115176134511020353 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_AUXILIARY_H #define HIPSPARSE_AUXILIARY_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup aux_module * \brief Create a hipsparse handle * * \details * \p hipsparseCreate creates the hipSPARSE library context. It must be * initialized before any other hipSPARSE API function is invoked and must be passed to * all subsequent library function calls. The handle should be destroyed at the end * using hipsparseDestroy(). */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreate(hipsparseHandle_t* handle); /*! \ingroup aux_module * \brief Destroy a hipsparse handle * * \details * \p hipsparseDestroy destroys the hipSPARSE library context and releases all * resources used by the hipSPARSE library. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroy(hipsparseHandle_t handle); #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10000) /*! \ingroup aux_module * \brief Return the string representation of a hipSPARSE status's matching backend status enum name * * \details * \p hipsparseGetErrorName takes a hipSPARSE status as input and first converts it to the matching backend * status (either rocsparse_status or cusparseStatus_t). It then returns the string representation of this status * enum name. If the status is not recognized, the function returns "Unrecognized status code". * * For example, hipsparseGetErrorName(HIPSPARSE_STATUS_SUCCESS) on a system with a rocSPARSE backend will * return "rocsparse_status_success". On a system with a cuSPARSE backend this function would return * "CUSPARSE_STATUS_SUCCESS". */ HIPSPARSE_EXPORT const char* hipsparseGetErrorName(hipsparseStatus_t status); /*! \ingroup aux_module * \brief Return the hipSPARSE status's matching backend status description as a string * * \details * \p hipsparseGetErrorString takes a hipSPARSE status as input and first converts it to the matching backend * status (either rocsparse_status or cusparseStatus_t). It then returns the string description of this status. * If the status is not recognized, the function returns "Unrecognized status code". */ HIPSPARSE_EXPORT const char* hipsparseGetErrorString(hipsparseStatus_t status); #endif /*! \ingroup aux_module * \brief Get hipSPARSE version * * \details * \p hipsparseGetVersion gets the hipSPARSE library version number. * - patch = version % 100 * - minor = version / 100 % 1000 * - major = version / 100000 */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseGetVersion(hipsparseHandle_t handle, int* version); /*! \ingroup aux_module * \brief Get hipSPARSE git revision * * \details * \p hipsparseGetGitRevision gets the hipSPARSE library git commit revision (SHA-1). */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseGetGitRevision(hipsparseHandle_t handle, char* rev); /*! \ingroup aux_module * \brief Specify user defined HIP stream * * \details * \p hipsparseSetStream specifies the stream to be used by the hipSPARSE library * context and all subsequent function calls. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSetStream(hipsparseHandle_t handle, hipStream_t streamId); /*! \ingroup aux_module * \brief Get current stream from library context * * \details * \p hipsparseGetStream gets the hipSPARSE library context stream which is currently * used for all subsequent function calls. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseGetStream(hipsparseHandle_t handle, hipStream_t* streamId); /*! \ingroup aux_module * \brief Specify pointer mode * * \details * \p hipsparseSetPointerMode specifies the pointer mode to be used by the hipSPARSE * library context and all subsequent function calls. By default, all values are passed * by reference on the host. Valid pointer modes are \ref HIPSPARSE_POINTER_MODE_HOST * or \ref HIPSPARSE_POINTER_MODE_DEVICE. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSetPointerMode(hipsparseHandle_t handle, hipsparsePointerMode_t mode); /*! \ingroup aux_module * \brief Get current pointer mode from library context * * \details * \p hipsparseGetPointerMode gets the hipSPARSE library context pointer mode which * is currently used for all subsequent function calls. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseGetPointerMode(hipsparseHandle_t handle, hipsparsePointerMode_t* mode); /*! \ingroup aux_module * \brief Create a matrix descriptor * \details * \p hipsparseCreateMatDescr creates a matrix descriptor. It initializes * \ref hipsparseMatrixType_t to \ref HIPSPARSE_MATRIX_TYPE_GENERAL and * \ref hipsparseIndexBase_t to \ref HIPSPARSE_INDEX_BASE_ZERO. It should be destroyed * at the end using hipsparseDestroyMatDescr(). */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateMatDescr(hipsparseMatDescr_t* descrA); /*! \ingroup aux_module * \brief Destroy a matrix descriptor * * \details * \p hipsparseDestroyMatDescr destroys a matrix descriptor and releases all * resources used by the descriptor. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyMatDescr(hipsparseMatDescr_t descrA); /*! \ingroup aux_module * \brief Copy a matrix descriptor * \details * \p hipsparseCopyMatDescr copies a matrix descriptor. Both, source and destination * matrix descriptors must be initialized prior to calling \p hipsparseCopyMatDescr. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCopyMatDescr(hipsparseMatDescr_t dest, const hipsparseMatDescr_t src); /*! \ingroup aux_module * \brief Specify the matrix type of a matrix descriptor * * \details * \p hipsparseSetMatType sets the matrix type of a matrix descriptor. Valid * matrix types are \ref HIPSPARSE_MATRIX_TYPE_GENERAL, * \ref HIPSPARSE_MATRIX_TYPE_SYMMETRIC, \ref HIPSPARSE_MATRIX_TYPE_HERMITIAN or * \ref HIPSPARSE_MATRIX_TYPE_TRIANGULAR. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSetMatType(hipsparseMatDescr_t descrA, hipsparseMatrixType_t type); /*! \ingroup aux_module * \brief Get the matrix type of a matrix descriptor * * \details * \p hipsparseGetMatType returns the matrix type of a matrix descriptor. */ HIPSPARSE_EXPORT hipsparseMatrixType_t hipsparseGetMatType(const hipsparseMatDescr_t descrA); /*! \ingroup aux_module * \brief Specify the matrix fill mode of a matrix descriptor * * \details * \p hipsparseSetMatFillMode sets the matrix fill mode of a matrix descriptor. * Valid fill modes are \ref HIPSPARSE_FILL_MODE_LOWER or * \ref HIPSPARSE_FILL_MODE_UPPER. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSetMatFillMode(hipsparseMatDescr_t descrA, hipsparseFillMode_t fillMode); /*! \ingroup aux_module * \brief Get the matrix fill mode of a matrix descriptor * * \details * \p hipsparseGetMatFillMode returns the matrix fill mode of a matrix descriptor. */ HIPSPARSE_EXPORT hipsparseFillMode_t hipsparseGetMatFillMode(const hipsparseMatDescr_t descrA); /*! \ingroup aux_module * \brief Specify the matrix diagonal type of a matrix descriptor * * \details * \p hipsparseSetMatDiagType sets the matrix diagonal type of a matrix * descriptor. Valid diagonal types are \ref HIPSPARSE_DIAG_TYPE_UNIT or * \ref HIPSPARSE_DIAG_TYPE_NON_UNIT. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSetMatDiagType(hipsparseMatDescr_t descrA, hipsparseDiagType_t diagType); /*! \ingroup aux_module * \brief Get the matrix diagonal type of a matrix descriptor * * \details * \p hipsparseGetMatDiagType returns the matrix diagonal type of a matrix * descriptor. */ HIPSPARSE_EXPORT hipsparseDiagType_t hipsparseGetMatDiagType(const hipsparseMatDescr_t descrA); /*! \ingroup aux_module * \brief Specify the index base of a matrix descriptor * * \details * \p hipsparseSetMatIndexBase sets the index base of a matrix descriptor. Valid * options are \ref HIPSPARSE_INDEX_BASE_ZERO or \ref HIPSPARSE_INDEX_BASE_ONE. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSetMatIndexBase(hipsparseMatDescr_t descrA, hipsparseIndexBase_t base); /*! \ingroup aux_module * \brief Get the index base of a matrix descriptor * * \details * \p hipsparseGetMatIndexBase returns the index base of a matrix descriptor. */ HIPSPARSE_EXPORT hipsparseIndexBase_t hipsparseGetMatIndexBase(const hipsparseMatDescr_t descrA); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) /*! \ingroup aux_module * \brief Create a \p HYB matrix structure * * \details * \p hipsparseCreateHybMat creates a structure that holds the matrix in \p HYB * storage format. It should be destroyed at the end using hipsparseDestroyHybMat(). */ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateHybMat(hipsparseHybMat_t* hybA); /*! \ingroup aux_module * \brief Destroy a \p HYB matrix structure * * \details * \p hipsparseDestroyHybMat destroys a \p HYB structure. */ DEPRECATED_CUDA_10000("The routine will be removed in CUDA 11") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyHybMat(hipsparseHybMat_t hybA); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a bsrsv2 info structure * * \details * \p hipsparseCreateBsrsv2Info creates a structure that holds the bsrsv2 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyBsrsv2Info(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateBsrsv2Info(bsrsv2Info_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a bsrsv2 info structure * * \details * \p hipsparseDestroyBsrsv2Info destroys a bsrsv2 info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyBsrsv2Info(bsrsv2Info_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a bsrsm2 info structure * * \details * \p hipsparseCreateBsrsm2Info creates a structure that holds the bsrsm2 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyBsrsm2Info(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateBsrsm2Info(bsrsm2Info_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a bsrsm2 info structure * * \details * \p hipsparseDestroyBsrsm2Info destroys a bsrsm2 info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyBsrsm2Info(bsrsm2Info_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a bsrilu02 info structure * * \details * \p hipsparseCreateBsrilu02Info creates a structure that holds the bsrilu02 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyBsrilu02Info(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateBsrilu02Info(bsrilu02Info_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a bsrilu02 info structure * * \details * \p hipsparseDestroyBsrilu02Info destroys a bsrilu02 info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyBsrilu02Info(bsrilu02Info_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a bsric02 info structure * * \details * \p hipsparseCreateBsric02Info creates a structure that holds the bsric02 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyBsric02Info(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateBsric02Info(bsric02Info_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a bsric02 info structure * * \details * \p hipsparseDestroyBsric02Info destroys a bsric02 info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyBsric02Info(bsric02Info_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /* Info structures */ /*! \ingroup aux_module * \brief Create a csrsv2 info structure * * \details * \p hipsparseCreateCsrsv2Info creates a structure that holds the csrsv2 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyCsrsv2Info(). */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsrsv2Info(csrsv2Info_t* info); /*! \ingroup aux_module * \brief Destroy a csrsv2 info structure * * \details * \p hipsparseDestroyCsrsv2Info destroys a csrsv2 info structure. */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyCsrsv2Info(csrsv2Info_t info); /* Info structures */ /*! \ingroup aux_module * \brief Create a csrsm2 info structure * * \details * \p hipsparseCreateCsrsm2Info creates a structure that holds the csrsm2 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyCsrsm2Info(). */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsrsm2Info(csrsm2Info_t* info); /*! \ingroup aux_module * \brief Destroy a csrsm2 info structure * * \details * \p hipsparseDestroyCsrsm2Info destroys a csrsm2 info structure. */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyCsrsm2Info(csrsm2Info_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a csrilu02 info structure * * \details * \p hipsparseCreateCsrilu02Info creates a structure that holds the csrilu02 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyCsrilu02Info(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsrilu02Info(csrilu02Info_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a csrilu02 info structure * * \details * \p hipsparseDestroyCsrilu02Info destroys a csrilu02 info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyCsrilu02Info(csrilu02Info_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a csric02 info structure * * \details * \p hipsparseCreateCsric02Info creates a structure that holds the csric02 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyCsric02Info(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsric02Info(csric02Info_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a csric02 info structure * * \details * \p hipsparseDestroyCsric02Info destroys a csric02 info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyCsric02Info(csric02Info_t info); #endif /* Info structures */ /*! \ingroup aux_module * \brief Create a csru2csr info structure * * \details * \p hipsparseCreateCsru2csrInfo creates a structure that holds the csru2csr info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyCsru2csrInfo(). */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsru2csrInfo(csru2csrInfo_t* info); /*! \ingroup aux_module * \brief Destroy a csru2csr info structure * * \details * \p hipsparseDestroyCsru2csrInfo destroys a csru2csr info structure. */ HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyCsru2csrInfo(csru2csrInfo_t info); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a color info structure * * \details * \p hipsparseCreateColorInfo creates a structure that holds the color info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyColorInfo(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateColorInfo(hipsparseColorInfo_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a color info structure * * \details * \p hipsparseDestroyColorInfo destroys a color info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyColorInfo(hipsparseColorInfo_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) /* Info structures */ /*! \ingroup aux_module * \brief Create a csrgemm2 info structure * * \details * \p hipsparseCreateCsrgemm2Info creates a structure that holds the csrgemm2 info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyCsrgemm2Info(). */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsrgemm2Info(csrgemm2Info_t* info); /*! \ingroup aux_module * \brief Destroy a csrgemm2 info structure * * \details * \p hipsparseDestroyCsrgemm2Info destroys a csrgemm2 info structure. */ DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyCsrgemm2Info(csrgemm2Info_t info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /* Info structures */ /*! \ingroup aux_module * \brief Create a prune info structure * * \details * \p hipsparseCreatePruneInfo creates a structure that holds the prune info data * that is gathered during the analysis routines available. It should be destroyed * at the end using hipsparseDestroyPruneInfo(). */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreatePruneInfo(pruneInfo_t* info); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) /*! \ingroup aux_module * \brief Destroy a prune info structure * * \details * \p hipsparseDestroyPruneInfo destroys a prune info structure. */ DEPRECATED_CUDA_12000("The routine will be removed in CUDA 13") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyPruneInfo(pruneInfo_t info); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_AUXILIARY_H */ ./library/include/hipsparse-generic-auxiliary.h0000664000175100017510000012705215176134511021773 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #ifndef HIPSPARSE_GENERIC_AUXILIARY_H #define HIPSPARSE_GENERIC_AUXILIARY_H #ifdef __cplusplus extern "C" { #endif /*! \ingroup generic_module * \brief Create a sparse vector. * * \details * \p hipsparseCreateSpVec creates a sparse vector descriptor. It should be * destroyed at the end using hipsparseDestroySpVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateSpVec(hipsparseSpVecDescr_t* spVecDescr, int64_t size, int64_t nnz, void* indices, void* values, hipsparseIndexType_t idxType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a const sparse vector. * * \details * \p hipsparseCreateConstSpVec creates a const sparse vector descriptor. It should be * destroyed at the end using hipsparseDestroySpVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateConstSpVec(hipsparseConstSpVecDescr_t* spVecDescr, int64_t size, int64_t nnz, const void* indices, const void* values, hipsparseIndexType_t idxType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Destroy a sparse vector. * * \details * \p hipsparseDestroySpVec destroys a sparse vector descriptor and releases all * resources used by the descriptor. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroySpVec(hipsparseConstSpVecDescr_t spVecDescr); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroySpVec(hipsparseSpVecDescr_t spVecDescr); #endif /*! \ingroup generic_module * \brief Get the fields of the sparse vector descriptor. * * \details * \p hipsparseSpVecGet gets the fields of the sparse vector descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVecGet(const hipsparseSpVecDescr_t spVecDescr, int64_t* size, int64_t* nnz, void** indices, void** values, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get the fields of the const sparse vector descriptor. * * \details * \p hipsparseConstSpVecGet gets the fields of the const sparse vector descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstSpVecGet(hipsparseConstSpVecDescr_t spVecDescr, int64_t* size, int64_t* nnz, const void** indices, const void** values, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get index base of a sparse vector. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVecGetIndexBase(const hipsparseConstSpVecDescr_t spVecDescr, hipsparseIndexBase_t* idxBase); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVecGetIndexBase(const hipsparseSpVecDescr_t spVecDescr, hipsparseIndexBase_t* idxBase); #endif /*! \ingroup generic_module * \brief Get pointer to a sparse vector data array. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVecGetValues(const hipsparseSpVecDescr_t spVecDescr, void** values); #endif /*! \ingroup generic_module * \brief Get pointer to a sparse vector data array. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstSpVecGetValues(hipsparseConstSpVecDescr_t spVecDescr, const void** values); #endif /*! \ingroup generic_module * \brief Set pointer of a sparse vector data array. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpVecSetValues(hipsparseSpVecDescr_t spVecDescr, void* values); #endif /* Sparse matrix API */ /*! \ingroup generic_module * \brief Create a sparse COO matrix descriptor * \details * \p hipsparseCreateCoo creates a sparse COO matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCoo(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cooRowInd, void* cooColInd, void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse COO matrix descriptor * \details * \p hipsparseCreateConstCoo creates a sparse COO matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateConstCoo(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* cooRowInd, const void* cooColInd, const void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse COO (AoS) matrix descriptor * \details * \p hipsparseCreateCooAoS creates a sparse COO (AoS) matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCooAoS(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cooInd, void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse CSR matrix descriptor * \details * \p hipsparseCreateCsr creates a sparse CSR matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsr(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* csrRowOffsets, void* csrColInd, void* csrValues, hipsparseIndexType_t csrRowOffsetsType, hipsparseIndexType_t csrColIndType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse CSR matrix descriptor * \details * \p hipsparseCreateConstCsr creates a sparse CSR matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12001) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateConstCsr(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* csrRowOffsets, const void* csrColInd, const void* csrValues, hipsparseIndexType_t csrRowOffsetsType, hipsparseIndexType_t csrColIndType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse CSC matrix descriptor * \details * \p hipsparseCreateCsc creates a sparse CSC matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateCsc(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cscColOffsets, void* cscRowInd, void* cscValues, hipsparseIndexType_t cscColOffsetsType, hipsparseIndexType_t cscRowIndType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse CSC matrix descriptor * \details * \p hipsparseCreateConstCsc creates a sparse CSC matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateConstCsc(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* cscColOffsets, const void* cscRowInd, const void* cscValues, hipsparseIndexType_t cscColOffsetsType, hipsparseIndexType_t cscRowIndType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse Blocked ELL matrix descriptor * \details * \p hipsparseCreateCsr creates a sparse Blocked ELL matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateBlockedEll(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t ellBlockSize, int64_t ellCols, void* ellColInd, void* ellValue, hipsparseIndexType_t ellIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create a sparse Blocked ELL matrix descriptor * \details * \p hipsparseCreateConstBlockedEll creates a sparse Blocked ELL matrix descriptor. It should be * destroyed at the end using \p hipsparseDestroySpMat. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateConstBlockedEll(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t ellBlockSize, int64_t ellCols, const void* ellColInd, const void* ellValue, hipsparseIndexType_t ellIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Destroy a sparse matrix descriptor * \details * \p hipsparseDestroySpMat destroys a sparse matrix descriptor and releases all * resources used by the descriptor. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroySpMat(hipsparseConstSpMatDescr_t spMatDescr); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroySpMat(hipsparseSpMatDescr_t spMatDescr); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse COO matrix * \details * \p hipsparseCooGet gets the fields of the sparse COO matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCooGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cooRowInd, void** cooColInd, void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse COO matrix * \details * \p hipsparseConstCooGet gets the fields of the sparse COO matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstCooGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** cooRowInd, const void** cooColInd, const void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse COO (AoS) matrix * \details * \p hipsparseCooAoSGet gets the fields of the sparse COO (AoS) matrix descriptor */ #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCooAoSGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cooInd, void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse CSR matrix * \details * \p hipsparseCsrGet gets the fields of the sparse CSR matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCsrGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** csrRowOffsets, void** csrColInd, void** csrValues, hipsparseIndexType_t* csrRowOffsetsType, hipsparseIndexType_t* csrColIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse CSR matrix * \details * \p hipsparseConstCsrGet gets the fields of the sparse CSR matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12001) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstCsrGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** csrRowOffsets, const void** csrColInd, const void** csrValues, hipsparseIndexType_t* csrRowOffsetsType, hipsparseIndexType_t* csrColIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse CSC matrix * \details * \p hipsparseCscGet gets the fields of the sparse CSC matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12001) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCscGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cscColOffsets, void** cscRowInd, void** cscValues, hipsparseIndexType_t* cscColOffsetsType, hipsparseIndexType_t* cscRowIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse CSC matrix * \details * \p hipsparseConstCscGet gets the fields of the sparse CSC matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12001) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstCscGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** cscColOffsets, const void** cscRowInd, const void** cscValues, hipsparseIndexType_t* cscColOffsetsType, hipsparseIndexType_t* cscRowIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse blocked ELL matrix * \details * \p hipsparseBlockedEllGet gets the fields of the sparse blocked ELL matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseBlockedEllGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* ellBlockSize, int64_t* ellCols, void** ellColInd, void** ellValue, hipsparseIndexType_t* ellIdxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get pointers of a sparse blocked ELL matrix * \details * \p hipsparseConstBlockedEllGet gets the fields of the sparse blocked ELL matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstBlockedEllGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* ellBlockSize, int64_t* ellCols, const void** ellColInd, const void** ellValue, hipsparseIndexType_t* ellIdxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Set pointers of a sparse CSR matrix * \details * \p hipsparseCsrSetPointers sets the fields of the sparse CSR matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCsrSetPointers(hipsparseSpMatDescr_t spMatDescr, void* csrRowOffsets, void* csrColInd, void* csrValues); #endif /*! \ingroup generic_module * \brief Set pointers of a sparse CSC matrix * \details * \p hipsparseCscSetPointers sets the fields of the sparse CSC matrix descriptor */ #if(!defined(CUDART_VERSION)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCscSetPointers(hipsparseSpMatDescr_t spMatDescr, void* cscColOffsets, void* cscRowInd, void* cscValues); #endif /*! \ingroup generic_module * \brief Set pointers of a sparse COO matrix * \details * \p hipsparseCooSetPointers sets the fields of the sparse COO matrix descriptor */ #if(!defined(CUDART_VERSION)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCooSetPointers(hipsparseSpMatDescr_t spMatDescr, void* cooRowInd, void* cooColInd, void* cooValues); #endif /*! \ingroup generic_module * \brief Get the sizes of a sparse matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetSize(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetSize(hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz); #endif /*! \ingroup generic_module * \brief Get the format of a sparse matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetFormat(hipsparseConstSpMatDescr_t spMatDescr, hipsparseFormat_t* format); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetFormat(const hipsparseSpMatDescr_t spMatDescr, hipsparseFormat_t* format); #endif /*! \ingroup generic_module * \brief Get the index base of a sparse matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetIndexBase(hipsparseConstSpMatDescr_t spMatDescr, hipsparseIndexBase_t* idxBase); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetIndexBase(const hipsparseSpMatDescr_t spMatDescr, hipsparseIndexBase_t* idxBase); #endif /*! \ingroup generic_module * \brief Get the pointer of the values array of a sparse matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetValues(hipsparseSpMatDescr_t spMatDescr, void** values); #endif /*! \ingroup generic_module * \brief Get the pointer of the values array of a sparse matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstSpMatGetValues(hipsparseConstSpMatDescr_t spMatDescr, const void** values); #endif /*! \ingroup generic_module * \brief Set the pointer of the values array of a sparse matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatSetValues(hipsparseSpMatDescr_t spMatDescr, void* values); #endif /*! \ingroup generic_module * \brief Get the batch count of the sparse matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetStridedBatch(hipsparseConstSpMatDescr_t spMatDescr, int* batchCount); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int* batchCount); #endif /*! \ingroup generic_module * \brief Set the batch count of the sparse matrix */ #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) DEPRECATED_CUDA_11000("The routine will be removed in CUDA 12") HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount); #endif /*! \ingroup generic_module * \brief Set the batch count and stride of the sparse COO matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCooSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount, int64_t batchStride); #endif /*! \ingroup generic_module * \brief Set the batch count and stride of the sparse CSR matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCsrSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount, int64_t offsetsBatchStride, int64_t columnsValuesBatchStride); #endif /*! \ingroup generic_module * \brief Get attribute from sparse matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetAttribute(hipsparseConstSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, void* data, size_t dataSize); #elif(CUDART_VERSION >= 11030) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatGetAttribute(hipsparseSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, void* data, size_t dataSize); #endif /*! \ingroup generic_module * \brief Set attribute in sparse matrix descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseSpMatSetAttribute(hipsparseSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, const void* data, size_t dataSize); #endif /* Dense vector API */ /*! \ingroup generic_module * \brief Create dense vector * \details * \p hipsparseCreateDnVec creates a dense vector descriptor. It should be * destroyed at the end using hipsparseDestroyDnVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateDnVec(hipsparseDnVecDescr_t* dnVecDescr, int64_t size, void* values, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Create dense vector * \details * \p hipsparseCreateConstDnVec creates a dense vector descriptor. It should be * destroyed at the end using hipsparseDestroyDnVec(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateConstDnVec(hipsparseConstDnVecDescr_t* dnVecDescr, int64_t size, const void* values, hipDataType valueType); #endif /*! \ingroup generic_module * \brief Destroy dense vector * \details * \p hipsparseDestroyDnVec destroys a dense vector descriptor and releases all * resources used by the descriptor. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyDnVec(hipsparseConstDnVecDescr_t dnVecDescr); #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyDnVec(hipsparseDnVecDescr_t dnVecDescr); #endif /*! \ingroup generic_module * \brief Get the fields from a dense vector * \details * \p hipsparseDnVecGet gets the fields of the dense vector descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnVecGet(const hipsparseDnVecDescr_t dnVecDescr, int64_t* size, void** values, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get the fields from a dense vector * \details * \p hipsparseConstDnVecGet gets the fields of the dense vector descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstDnVecGet(hipsparseConstDnVecDescr_t dnVecDescr, int64_t* size, const void** values, hipDataType* valueType); #endif /*! \ingroup generic_module * \brief Get value pointer from a dense vector * \details * \p hipsparseDnVecGetValues gets the fields of the dense vector descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnVecGetValues(const hipsparseDnVecDescr_t dnVecDescr, void** values); #endif /*! \ingroup generic_module * \brief Get value pointer from a dense vector * \details * \p hipsparseConstDnVecGetValues gets the fields of the dense vector descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12001) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstDnVecGetValues(hipsparseConstDnVecDescr_t dnVecDescr, const void** values); #endif /*! \ingroup generic_module * \brief Set value pointer of a dense vector * \details * \p hipsparseDnVecSetValues sets the fields of the dense vector descriptor */ #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnVecSetValues(hipsparseDnVecDescr_t dnVecDescr, void* values); #endif /* Dense matrix API */ /* Description: Create dense matrix */ /*! \ingroup generic_module * \brief Create dense matrix * \details * \p hipsparseCreateDnMat creates a dense matrix descriptor. It should be * destroyed at the end using hipsparseDestroyDnMat(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateDnMat(hipsparseDnMatDescr_t* dnMatDescr, int64_t rows, int64_t cols, int64_t ld, void* values, hipDataType valueType, hipsparseOrder_t order); #endif /*! \ingroup generic_module * \brief Create dense matrix * \details * \p hipsparseCreateConstDnMat creates a dense matrix descriptor. It should be * destroyed at the end using hipsparseDestroyDnMat(). */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseCreateConstDnMat(hipsparseConstDnMatDescr_t* dnMatDescr, int64_t rows, int64_t cols, int64_t ld, const void* values, hipDataType valueType, hipsparseOrder_t order); #endif /*! \ingroup generic_module * \brief Destroy dense matrix * \details * \p hipsparseDestroyDnMat destroys a dense matrix descriptor and releases all * resources used by the descriptor. */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyDnMat(hipsparseConstDnMatDescr_t dnMatDescr); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDestroyDnMat(hipsparseDnMatDescr_t dnMatDescr); #endif /*! \ingroup generic_module * \brief Get fields from a dense matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnMatGet(const hipsparseDnMatDescr_t dnMatDescr, int64_t* rows, int64_t* cols, int64_t* ld, void** values, hipDataType* valueType, hipsparseOrder_t* order); #endif /*! \ingroup generic_module * \brief Get fields from a dense matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstDnMatGet(hipsparseConstDnMatDescr_t dnMatDescr, int64_t* rows, int64_t* cols, int64_t* ld, const void** values, hipDataType* valueType, hipsparseOrder_t* order); #endif /*! \ingroup generic_module * \brief Get value pointer from a dense matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnMatGetValues(const hipsparseDnMatDescr_t dnMatDescr, void** values); #endif /*! \ingroup generic_module * \brief Get value pointer from a dense matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseConstDnMatGetValues(hipsparseConstDnMatDescr_t dnMatDescr, const void** values); #endif /*! \ingroup generic_module * \brief Set value pointer of a dense matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnMatSetValues(hipsparseDnMatDescr_t dnMatDescr, void* values); #endif /*! \ingroup generic_module * \brief Get the batch count and batch stride of the dense matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnMatGetStridedBatch(hipsparseConstDnMatDescr_t dnMatDescr, int* batchCount, int64_t* batchStride); #elif(CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnMatGetStridedBatch(hipsparseDnMatDescr_t dnMatDescr, int* batchCount, int64_t* batchStride); #endif /*! \ingroup generic_module * \brief Set the batch count and batch stride of the dense matrix */ #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) HIPSPARSE_EXPORT hipsparseStatus_t hipsparseDnMatSetStridedBatch(hipsparseDnMatDescr_t dnMatDescr, int batchCount, int64_t batchStride); #endif #ifdef __cplusplus } #endif #endif /* HIPSPARSE_GENERIC_AUXILIARY_H */ ./library/src/0000775000175100017510000000000015176134511013342 5ustar jenkinsjenkins./library/src/hipsparse.f900000664000175100017510000103415415176134305015671 0ustar jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. ! ! Permission is hereby granted, free of charge, to any person obtaining a copy ! of this software and associated documentation files (the "Software"), to deal ! in the Software without restriction, including without limitation the rights ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ! copies of the Software, and to permit persons to whom the Software is ! furnished to do so, subject to the following conditions: ! ! The above copyright notice and this permission notice shall be included in ! all copies or substantial portions of the Software. ! ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ! THE SOFTWARE. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! module hipsparse use hipsparse_enums use iso_c_binding implicit none ! =========================================================================== ! auxiliary SPARSE ! =========================================================================== interface ! hipsparseHandle_t function hipsparseCreate(handle) & bind(c, name = 'hipsparseCreate') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreate type(c_ptr) :: handle end function hipsparseCreate function hipsparseDestroy(handle) & bind(c, name = 'hipsparseDestroy') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroy type(c_ptr), value :: handle end function hipsparseDestroy ! hipsparseVersion function hipsparseGetVersion(handle, version) & bind(c, name = 'hipsparseGetVersion') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseGetVersion type(c_ptr), value :: handle integer(c_int) :: version end function hipsparseGetVersion ! hipsparseStream function hipsparseSetStream(handle, stream) & bind(c, name = 'hipsparseSetStream') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSetStream type(c_ptr), value :: handle type(c_ptr), value :: stream end function hipsparseSetStream function hipsparseGetStream(handle, stream) & bind(c, name = 'hipsparseGetStream') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseGetStream type(c_ptr), value :: handle type(c_ptr) :: stream end function hipsparseGetStream ! hipsparsePointerMode_t function hipsparseSetPointerMode(handle, mode) & bind(c, name = 'hipsparseSetPointerMode') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSetPointerMode type(c_ptr), value :: handle integer(c_int), value :: mode end function hipsparseSetPointerMode function hipsparseGetPointerMode(handle, mode) & bind(c, name = 'hipsparseGetPointerMode') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseGetPointerMode type(c_ptr), value :: handle integer(c_int) :: mode end function hipsparseGetPointerMode ! hipsparseMatDescr_t function hipsparseCreateMatDescr(descr) & bind(c, name = 'hipsparseCreateMatDescr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateMatDescr type(c_ptr) :: descr end function hipsparseCreateMatDescr function hipsparseDestroyMatDescr(descr) & bind(c, name = 'hipsparseDestroyMatDescr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyMatDescr type(c_ptr), value :: descr end function hipsparseDestroyMatDescr function hipsparseCopyMatDescr(dest, src) & bind(c, name = 'hipsparseCopyMatDescr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCopyMatDescr type(c_ptr), value :: dest type(c_ptr), intent(in), value :: src end function hipsparseCopyMatDescr ! hipsparseMatrixType_t function hipsparseSetMatType(descr, mtype) & bind(c, name = 'hipsparseSetMatType') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSetMatType type(c_ptr), value :: descr integer(c_int), value :: mtype end function hipsparseSetMatType function hipsparseGetMatType(descr) & bind(c, name = 'hipsparseGetMatType') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseGetMatType type(c_ptr), intent(in), value :: descr end function hipsparseGetMatType ! hipsparseFillMode_t function hipsparseSetMatFillMode(descr, fill) & bind(c, name = 'hipsparseSetMatFillMode') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSetMatFillMode type(c_ptr), value :: descr integer(c_int), value :: fill end function hipsparseSetMatFillMode function hipsparseGetMatFillMode(descr) & bind(c, name = 'hipsparseGetMatFillMode') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseGetMatFillMode type(c_ptr), intent(in), value :: descr end function hipsparseGetMatFillMode ! hipsparseDiagType_t function hipsparseSetMatDiagType(descr, diag) & bind(c, name = 'hipsparseSetMatDiagType') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSetMatDiagType type(c_ptr), value :: descr integer(c_int), value :: diag end function hipsparseSetMatDiagType function hipsparseGetMatDiagType(descr) & bind(c, name = 'hipsparseGetMatDiagType') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseGetMatDiagType type(c_ptr), intent(in), value :: descr end function hipsparseGetMatDiagType ! hipsparseIndexBase_t function hipsparseSetMatIndexBase(descr, base) & bind(c, name = 'hipsparseSetMatIndexBase') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSetMatIndexBase type(c_ptr), value :: descr integer(c_int), value :: base end function hipsparseSetMatIndexBase function hipsparseGetMatIndexBase(descr) & bind(c, name = 'hipsparseGetMatIndexBase') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseGetMatIndexBase type(c_ptr), intent(in), value :: descr end function hipsparseGetMatIndexBase ! hipsparseHybMat_t function hipsparseCreateHybMat(hyb) & bind(c, name = 'hipsparseCreateHybMat') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateHybMat type(c_ptr) :: hyb end function hipsparseCreateHybMat function hipsparseDestroyHybMat(hyb) & bind(c, name = 'hipsparseDestroyHybMat') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyHybMat type(c_ptr), value :: hyb end function hipsparseDestroyHybMat ! csrsv2Info_t function hipsparseCreateCsrsv2Info(info) & bind(c, name = 'hipsparseCreateCsrsv2Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateCsrsv2Info type(c_ptr) :: info end function hipsparseCreateCsrsv2Info function hipsparseDestroyCsrsv2Info(info) & bind(c, name = 'hipsparseDestroyCsrsv2Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyCsrsv2Info type(c_ptr), value :: info end function hipsparseDestroyCsrsv2Info ! csrsm2Info_t function hipsparseCreateCsrsm2Info(info) & bind(c, name = 'hipsparseCreateCsrsm2Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateCsrsm2Info type(c_ptr) :: info end function hipsparseCreateCsrsm2Info function hipsparseDestroyCsrsm2Info(info) & bind(c, name = 'hipsparseDestroyCsrsm2Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyCsrsm2Info type(c_ptr), value :: info end function hipsparseDestroyCsrsm2Info ! bsrilu02Info_t function hipsparseCreateBsrilu02Info(info) & bind(c, name = 'hipsparseCreateBsrilu02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateBsrilu02Info type(c_ptr) :: info end function hipsparseCreateBsrilu02Info function hipsparseDestroyBsrilu02Info(info) & bind(c, name = 'hipsparseDestroyBsrilu02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyBsrilu02Info type(c_ptr), value :: info end function hipsparseDestroyBsrilu02Info ! csrilu02Info_t function hipsparseCreateCsrilu02Info(info) & bind(c, name = 'hipsparseCreateCsrilu02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateCsrilu02Info type(c_ptr) :: info end function hipsparseCreateCsrilu02Info function hipsparseDestroyCsrilu02Info(info) & bind(c, name = 'hipsparseDestroyCsrilu02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyCsrilu02Info type(c_ptr), value :: info end function hipsparseDestroyCsrilu02Info ! bsric02Info_t function hipsparseCreateBsric02Info(info) & bind(c, name = 'hipsparseCreateBsric02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateBsric02Info type(c_ptr) :: info end function hipsparseCreateBsric02Info function hipsparseDestroyBsric02Info(info) & bind(c, name = 'hipsparseDestroyBsric02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyBsric02Info type(c_ptr), value :: info end function hipsparseDestroyBsric02Info ! csric02Info_t function hipsparseCreateCsric02Info(info) & bind(c, name = 'hipsparseCreateCsric02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateCsric02Info type(c_ptr) :: info end function hipsparseCreateCsric02Info function hipsparseDestroyCsric02Info(info) & bind(c, name = 'hipsparseDestroyCsric02Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyCsric02Info type(c_ptr), value :: info end function hipsparseDestroyCsric02Info ! csrgemm2Info_t function hipsparseCreateCsrgemm2Info(info) & bind(c, name = 'hipsparseCreateCsrgemm2Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateCsrgemm2Info type(c_ptr) :: info end function hipsparseCreateCsrgemm2Info function hipsparseDestroyCsrgemm2Info(info) & bind(c, name = 'hipsparseDestroyCsrgemm2Info') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDestroyCsrgemm2Info type(c_ptr), value :: info end function hipsparseDestroyCsrgemm2Info ! =========================================================================== ! level 1 SPARSE ! =========================================================================== ! hipsparseXaxpyi function hipsparseSaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseSaxpyi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSaxpyi type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseSaxpyi function hipsparseDaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseDaxpyi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDaxpyi type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseDaxpyi function hipsparseCaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseCaxpyi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCaxpyi type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseCaxpyi function hipsparseZaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseZaxpyi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZaxpyi type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseZaxpyi ! hipsparseXdoti function hipsparseSdoti(handle, nnz, xVal, xInd, y, result, idxBase) & bind(c, name = 'hipsparseSdoti') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSdoti type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: y type(c_ptr), value :: result integer(c_int), value :: idxBase end function hipsparseSdoti function hipsparseDdoti(handle, nnz, xVal, xInd, y, result, idxBase) & bind(c, name = 'hipsparseDdoti') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDdoti type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: y type(c_ptr), value :: result integer(c_int), value :: idxBase end function hipsparseDdoti function hipsparseCdoti(handle, nnz, xVal, xInd, y, result, idxBase) & bind(c, name = 'hipsparseCdoti') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCdoti type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: y type(c_ptr), value :: result integer(c_int), value :: idxBase end function hipsparseCdoti function hipsparseZdoti(handle, nnz, xVal, xInd, y, result, idxBase) & bind(c, name = 'hipsparseZdoti') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZdoti type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: y type(c_ptr), value :: result integer(c_int), value :: idxBase end function hipsparseZdoti ! hipsparseXdotci function hipsparseCdotci(handle, nnz, xVal, xInd, y, result, idxBase) & bind(c, name = 'hipsparseCdotci') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCdotci type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: y type(c_ptr), value :: result integer(c_int), value :: idxBase end function hipsparseCdotci function hipsparseZdotci(handle, nnz, xVal, xInd, y, result, idxBase) & bind(c, name = 'hipsparseZdotci') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZdotci type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: y type(c_ptr), value :: result integer(c_int), value :: idxBase end function hipsparseZdotci ! hipsparseXgthr function hipsparseSgthr(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseSgthr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSgthr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseSgthr function hipsparseDgthr(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseDgthr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDgthr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseDgthr function hipsparseCgthr(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseCgthr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCgthr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseCgthr function hipsparseZgthr(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseZgthr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZgthr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseZgthr ! hipsparseXgthrz function hipsparseSgthrz(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseSgthrz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSgthrz type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseSgthrz function hipsparseDgthrz(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseDgthrz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDgthrz type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseDgthrz function hipsparseCgthrz(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseCgthrz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCgthrz type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseCgthrz function hipsparseZgthrz(handle, nnz, y, xVal, xInd, idxBase) & bind(c, name = 'hipsparseZgthrz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZgthrz type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), value :: y type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd integer(c_int), value :: idxBase end function hipsparseZgthrz ! hipsparseXroti function hipsparseSroti(handle, nnz, xVal, xInd, y, c, s, idxBase) & bind(c, name = 'hipsparseSroti') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSroti type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y type(c_ptr), intent(in), value :: c type(c_ptr), intent(in), value :: s integer(c_int), value :: idxBase end function hipsparseSroti function hipsparseDroti(handle, nnz, xVal, xInd, y, c, s, idxBase) & bind(c, name = 'hipsparseDroti') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDroti type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y type(c_ptr), intent(in), value :: c type(c_ptr), intent(in), value :: s integer(c_int), value :: idxBase end function hipsparseDroti ! hipsparseXsctr function hipsparseSsctr(handle, nnz, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseSsctr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSsctr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseSsctr function hipsparseDsctr(handle, nnz, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseDsctr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDsctr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseDsctr function hipsparseCsctr(handle, nnz, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseCsctr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCsctr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseCsctr function hipsparseZsctr(handle, nnz, xVal, xInd, y, idxBase) & bind(c, name = 'hipsparseZsctr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZsctr type(c_ptr), value :: handle integer(c_int), value :: nnz type(c_ptr), intent(in), value :: xVal type(c_ptr), intent(in), value :: xInd type(c_ptr), value :: y integer(c_int), value :: idxBase end function hipsparseZsctr ! =========================================================================== ! level 2 SPARSE ! =========================================================================== ! hipsparseXcsrmv function hipsparseScsrmv(handle, trans, m, n, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, x, beta, y) & bind(c, name = 'hipsparseScsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrmv type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseScsrmv function hipsparseDcsrmv(handle, trans, m, n, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, x, beta, y) & bind(c, name = 'hipsparseDcsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrmv type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseDcsrmv function hipsparseCcsrmv(handle, trans, m, n, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, x, beta, y) & bind(c, name = 'hipsparseCcsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrmv type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseCcsrmv function hipsparseZcsrmv(handle, trans, m, n, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, x, beta, y) & bind(c, name = 'hipsparseZcsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrmv type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseZcsrmv ! hipsparseXcsrsv2_zeroPivot function hipsparseXcsrsv2_zeroPivot(handle, info, position) & bind(c, name = 'hipsparseXcsrsv2_zeroPivot') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrsv2_zeroPivot type(c_ptr), value :: handle type(c_ptr), value :: info type(c_ptr), value :: position end function hipsparseXcsrsv2_zeroPivot ! hipsparseXcsrsv2_bufferSize function hipsparseScsrsv2_bufferSize(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseScsrsv2_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrsv2_bufferSize type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseScsrsv2_bufferSize function hipsparseDcsrsv2_bufferSize(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseDcsrsv2_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrsv2_bufferSize type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDcsrsv2_bufferSize function hipsparseCcsrsv2_bufferSize(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseCcsrsv2_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrsv2_bufferSize type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCcsrsv2_bufferSize function hipsparseZcsrsv2_bufferSize(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseZcsrsv2_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrsv2_bufferSize type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZcsrsv2_bufferSize ! hipsparseXcsrsv2_bufferSizeExt function hipsparseScsrsv2_bufferSizeExt(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseScsrsv2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrsv2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseScsrsv2_bufferSizeExt function hipsparseDcsrsv2_bufferSizeExt(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseDcsrsv2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrsv2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDcsrsv2_bufferSizeExt function hipsparseCcsrsv2_bufferSizeExt(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseCcsrsv2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrsv2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCcsrsv2_bufferSizeExt function hipsparseZcsrsv2_bufferSizeExt(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseZcsrsv2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrsv2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZcsrsv2_bufferSizeExt ! hipsparseXcsrsv2_analysis function hipsparseScsrsv2_analysis(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseScsrsv2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrsv2_analysis type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsrsv2_analysis function hipsparseDcsrsv2_analysis(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseDcsrsv2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrsv2_analysis type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsrsv2_analysis function hipsparseCcsrsv2_analysis(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseCcsrsv2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrsv2_analysis type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsrsv2_analysis function hipsparseZcsrsv2_analysis(handle, trans, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseZcsrsv2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrsv2_analysis type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsrsv2_analysis ! hipsparseXcsrsv2_solve function hipsparseScsrsv2_solve(handle, trans, m, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, info, x, y, policy, buffer) & bind(c, name = 'hipsparseScsrsv2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrsv2_solve type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), intent(in), value :: x type(c_ptr), value :: y integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsrsv2_solve function hipsparseDcsrsv2_solve(handle, trans, m, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, info, x, y, policy, buffer) & bind(c, name = 'hipsparseDcsrsv2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrsv2_solve type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), intent(in), value :: x type(c_ptr), value :: y integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsrsv2_solve function hipsparseCcsrsv2_solve(handle, trans, m, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, info, x, y, policy, buffer) & bind(c, name = 'hipsparseCcsrsv2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrsv2_solve type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), intent(in), value :: x type(c_ptr), value :: y integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsrsv2_solve function hipsparseZcsrsv2_solve(handle, trans, m, nnz, alpha, descr, csrVal, & csrRowPtr, csrColInd, info, x, y, policy, buffer) & bind(c, name = 'hipsparseZcsrsv2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrsv2_solve type(c_ptr), value :: handle integer(c_int), value :: trans integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), intent(in), value :: x type(c_ptr), value :: y integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsrsv2_solve ! hipsparseXhybmv function hipsparseShybmv(handle, trans, alpha, descr, hyb, x, beta, y) & bind(c, name = 'hipsparseShybmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseShybmv type(c_ptr), value :: handle integer(c_int), value :: trans type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: hyb type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseShybmv function hipsparseDhybmv(handle, trans, alpha, descr, hyb, x, beta, y) & bind(c, name = 'hipsparseDhybmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDhybmv type(c_ptr), value :: handle integer(c_int), value :: trans type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: hyb type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseDhybmv function hipsparseChybmv(handle, trans, alpha, descr, hyb, x, beta, y) & bind(c, name = 'hipsparseChybmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseChybmv type(c_ptr), value :: handle integer(c_int), value :: trans type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: hyb type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseChybmv function hipsparseZhybmv(handle, trans, alpha, descr, hyb, x, beta, y) & bind(c, name = 'hipsparseZhybmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZhybmv type(c_ptr), value :: handle integer(c_int), value :: trans type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: hyb type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseZhybmv ! hipsparseXbsrmv function hipsparseSbsrmv(handle, dir, trans, mb, nb, nnzb, alpha, descr, & bsrVal, bsrRowPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseSbsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsrmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseSbsrmv function hipsparseDbsrmv(handle, dir, trans, mb, nb, nnzb, alpha, descr, & bsrVal, bsrRowPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseDbsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsrmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseDbsrmv function hipsparseCbsrmv(handle, dir, trans, mb, nb, nnzb, alpha, descr, & bsrVal, bsrRowPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseCbsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsrmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseCbsrmv function hipsparseZbsrmv(handle, dir, trans, mb, nb, nnzb, alpha, descr, & bsrVal, bsrRowPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseZbsrmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsrmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseZbsrmv ! hipsparseXbsrxmv function hipsparseSbsrxmv(handle, dir, trans, sizeOfMask, & mb, nb, nnzb, alpha, descr, bsrVal, & bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseSbsrxmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsrxmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: sizeOfMask integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrMaskPtr type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrEndPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseSbsrxmv function hipsparseDbsrxmv(handle, dir, trans, sizeOfMask, & mb, nb, nnzb, alpha, descr, bsrVal, & bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseDbsrxmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsrxmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: sizeOfMask integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrMaskPtr type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrEndPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseDbsrxmv function hipsparseCbsrxmv(handle, dir, trans, sizeOfMask, & mb, nb, nnzb, alpha, descr, bsrVal, & bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseCbsrxmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsrxmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: sizeOfMask integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrMaskPtr type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrEndPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseCbsrxmv function hipsparseZbsrxmv(handle, dir, trans, sizeOfMask, & mb, nb, nnzb, alpha, descr, bsrVal, & bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y) & bind(c, name = 'hipsparseZbsrxmv') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsrxmv type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: trans integer(c_int), value :: sizeOfMask integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrMaskPtr type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrEndPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y end function hipsparseZbsrxmv function hipsparseSgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes) & bind(c, name = 'hipsparseSgemvi_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSgemvi_bufferSize type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), value :: pBufferSizeInBytes end function hipsparseSgemvi_bufferSize function hipsparseDgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes) & bind(c, name = 'hipsparseDgemvi_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDgemvi_bufferSize type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), value :: pBufferSizeInBytes end function hipsparseDgemvi_bufferSize function hipsparseCgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes) & bind(c, name = 'hipsparseCgemvi_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCgemvi_bufferSize type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), value :: pBufferSizeInBytes end function hipsparseCgemvi_bufferSize function hipsparseZgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes) & bind(c, name = 'hipsparseZgemvi_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZgemvi_bufferSize type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), value :: pBufferSizeInBytes end function hipsparseZgemvi_bufferSize function hipsparseSgemvi(handle, transA, m, n, alpha, A, lda, nnz, x, xInd, & beta, y, idxBase, pBuffer) & bind(c, name = 'hipsparseSgemvi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSgemvi type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda integer(c_int), value :: nnz type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y integer(c_int), value :: idxBase type(c_ptr), value :: pBuffer end function hipsparseSgemvi function hipsparseDgemvi(handle, transA, m, n, alpha, A, lda, nnz, x, xInd, & beta, y, idxBase, pBuffer) & bind(c, name = 'hipsparseDgemvi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDgemvi type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda integer(c_int), value :: nnz type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y integer(c_int), value :: idxBase type(c_ptr), value :: pBuffer end function hipsparseDgemvi function hipsparseCgemvi(handle, transA, m, n, alpha, A, lda, nnz, x, xInd, & beta, y, idxBase, pBuffer) & bind(c, name = 'hipsparseCgemvi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCgemvi type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda integer(c_int), value :: nnz type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y integer(c_int), value :: idxBase type(c_ptr), value :: pBuffer end function hipsparseCgemvi function hipsparseZgemvi(handle, transA, m, n, alpha, A, lda, nnz, x, xInd, & beta, y, idxBase, pBuffer) & bind(c, name = 'hipsparseZgemvi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZgemvi type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda integer(c_int), value :: nnz type(c_ptr), intent(in), value :: x type(c_ptr), intent(in), value :: xInd type(c_ptr), intent(in), value :: beta type(c_ptr), value :: y integer(c_int), value :: idxBase type(c_ptr), value :: pBuffer end function hipsparseZgemvi ! =========================================================================== ! level 3 SPARSE ! =========================================================================== ! hipsparseXbsrmm function hipsparseSbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, & bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseSbsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsrmm type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: mb integer(c_int), value :: n integer(c_int), value :: kb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseSbsrmm function hipsparseDbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, & bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseDbsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsrmm type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: mb integer(c_int), value :: n integer(c_int), value :: kb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseDbsrmm function hipsparseCbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, & bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseCbsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsrmm type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: mb integer(c_int), value :: n integer(c_int), value :: kb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseCbsrmm function hipsparseZbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, & bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseZbsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsrmm type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: mb integer(c_int), value :: n integer(c_int), value :: kb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseZbsrmm ! hipsparseXcsrmm function hipsparseScsrmm(handle, transA, m, n, k, nnz, alpha, descrA, csrValA, & csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseScsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrmm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseScsrmm function hipsparseDcsrmm(handle, transA, m, n, k, nnz, alpha, descrA, csrValA, & csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseDcsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrmm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseDcsrmm function hipsparseCcsrmm(handle, transA, m, n, k, nnz, alpha, descrA, csrValA, & csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseCcsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrmm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseCcsrmm function hipsparseZcsrmm(handle, transA, m, n, k, nnz, alpha, descrA, csrValA, & csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseZcsrmm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrmm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseZcsrmm ! hipsparseXcsrmm2 function hipsparseScsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descrA, & csrValA, csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseScsrmm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrmm2 type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseScsrmm2 function hipsparseDcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descrA, & csrValA, csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseDcsrmm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrmm2 type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseDcsrmm2 function hipsparseCcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descrA, & csrValA, csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseCcsrmm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrmm2 type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseCcsrmm2 function hipsparseZcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descrA, & csrValA, csrRowPtrA, csrColIndA, B, ldb, beta, C, ldc) & bind(c, name = 'hipsparseZcsrmm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrmm2 type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseZcsrmm2 ! hipsparseXcsrsm2_zeroPivot function hipsparseXcsrsm2_zeroPivot(handle, info, position) & bind(c, name = 'hipsparseXcsrsm2_zeroPivot') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrsm2_zeroPivot type(c_ptr), value :: handle type(c_ptr), value :: info type(c_ptr), value :: position end function hipsparseXcsrsm2_zeroPivot ! hipsparseXcsrsm2_bufferSizeExt function hipsparseScsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, & nnz, alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, & policy, bufferSize) & bind(c, name = 'hipsparseScsrsm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrsm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: bufferSize end function hipsparseScsrsm2_bufferSizeExt function hipsparseDcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, & nnz, alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, & policy, bufferSize) & bind(c, name = 'hipsparseDcsrsm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrsm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: bufferSize end function hipsparseDcsrsm2_bufferSizeExt function hipsparseCcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, & nnz, alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, & policy, bufferSize) & bind(c, name = 'hipsparseCcsrsm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrsm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: bufferSize end function hipsparseCcsrsm2_bufferSizeExt function hipsparseZcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, & nnz, alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, & policy, bufferSize) & bind(c, name = 'hipsparseZcsrsm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrsm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: bufferSize end function hipsparseZcsrsm2_bufferSizeExt ! hipsparseXcsrsm2_analysis function hipsparseScsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseScsrsm2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrsm2_analysis type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsrsm2_analysis function hipsparseDcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseDcsrsm2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrsm2_analysis type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsrsm2_analysis function hipsparseCcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseCcsrsm2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrsm2_analysis type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsrsm2_analysis function hipsparseZcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseZcsrsm2_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrsm2_analysis type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsrsm2_analysis ! hipsparseXcsrsm2_solve function hipsparseScsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseScsrsm2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrsm2_solve type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsrsm2_solve function hipsparseDcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseDcsrsm2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrsm2_solve type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsrsm2_solve function hipsparseCcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseCcsrsm2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrsm2_solve type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsrsm2_solve function hipsparseZcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, & alpha, descrA, csrValA, csrRowPtrA, csrColIndA, B, ldb, info, policy, & buffer) & bind(c, name = 'hipsparseZcsrsm2_solve') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrsm2_solve type(c_ptr), value :: handle integer(c_int), value :: algo integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: nrhs integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: B integer(c_int), value :: ldb type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsrsm2_solve ! hipsparseXgemmi function hipsparseSgemmi(handle, m, n, k, nnz, alpha, A, lda, cscValB, & cscColPtrB, cscRowIndB, beta, C, ldc) & bind(c, name = 'hipsparseSgemmi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSgemmi type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: cscValB type(c_ptr), intent(in), value :: cscColPtrB type(c_ptr), intent(in), value :: cscRowIndB type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseSgemmi function hipsparseDgemmi(handle, m, n, k, nnz, alpha, A, lda, cscValB, & cscColPtrB, cscRowIndB, beta, C, ldc) & bind(c, name = 'hipsparseDgemmi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDgemmi type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: cscValB type(c_ptr), intent(in), value :: cscColPtrB type(c_ptr), intent(in), value :: cscRowIndB type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseDgemmi function hipsparseCgemmi(handle, m, n, k, nnz, alpha, A, lda, cscValB, & cscColPtrB, cscRowIndB, beta, C, ldc) & bind(c, name = 'hipsparseCgemmi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCgemmi type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: cscValB type(c_ptr), intent(in), value :: cscColPtrB type(c_ptr), intent(in), value :: cscRowIndB type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseCgemmi function hipsparseZgemmi(handle, m, n, k, nnz, alpha, A, lda, cscValB, & cscColPtrB, cscRowIndB, beta, C, ldc) & bind(c, name = 'hipsparseZgemmi') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZgemmi type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k integer(c_int), value :: nnz type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: cscValB type(c_ptr), intent(in), value :: cscColPtrB type(c_ptr), intent(in), value :: cscRowIndB type(c_ptr), intent(in), value :: beta type(c_ptr), value :: C integer(c_int), value :: ldc end function hipsparseZgemmi ! =========================================================================== ! extra SPARSE ! =========================================================================== ! hipsparseXcsrgeamNnz function hipsparseXcsrgeamNnz(handle, m, n, descrA, nnzA, csrRowPtrA, & csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, descrC, & csrRowPtrC, nnzTotalDevHostPtr) & bind(c, name = 'hipsparseXcsrgeamNnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrgeamNnz type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: nnzTotalDevHostPtr end function hipsparseXcsrgeamNnz ! hipsparseXcsrgeam function hipsparseScsrgeam(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseScsrgeam') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrgeam type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseScsrgeam function hipsparseDcsrgeam(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseDcsrgeam') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrgeam type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseDcsrgeam function hipsparseCcsrgeam(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseCcsrgeam') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrgeam type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseCcsrgeam function hipsparseZcsrgeam(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseZcsrgeam') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrgeam type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseZcsrgeam ! hipsparseXcsrgeam2_bufferSizeExt function hipsparseScsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize) & bind(c, name = 'hipsparseScsrgeam2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrgeam2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), intent(in), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), intent(in), value :: csrColIndC type(c_ptr), value :: bufferSize end function hipsparseScsrgeam2_bufferSizeExt function hipsparseDcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize) & bind(c, name = 'hipsparseDcsrgeam2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrgeam2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), intent(in), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), intent(in), value :: csrColIndC type(c_ptr), value :: bufferSize end function hipsparseDcsrgeam2_bufferSizeExt function hipsparseCcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize) & bind(c, name = 'hipsparseCcsrgeam2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrgeam2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), intent(in), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), intent(in), value :: csrColIndC type(c_ptr), value :: bufferSize end function hipsparseCcsrgeam2_bufferSizeExt function hipsparseZcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, bufferSize) & bind(c, name = 'hipsparseZcsrgeam2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrgeam2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), intent(in), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), intent(in), value :: csrColIndC type(c_ptr), value :: bufferSize end function hipsparseZcsrgeam2_bufferSizeExt ! hipsparseXcsrgeam2Nnz function hipsparseXcsrgeam2Nnz(handle, m, n, descrA, nnzA, csrRowPtrA, & csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, descrC, & csrRowPtrC, nnzTotalDevHostPtr, workspace) & bind(c, name = 'hipsparseXcsrgeam2Nnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrgeam2Nnz type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: nnzTotalDevHostPtr type(c_ptr), value :: workspace end function hipsparseXcsrgeam2Nnz ! hipsparseXcsrgeam2 function hipsparseScsrgeam2(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, buffer) & bind(c, name = 'hipsparseScsrgeam2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrgeam2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), value :: buffer end function hipsparseScsrgeam2 function hipsparseDcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, buffer) & bind(c, name = 'hipsparseDcsrgeam2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrgeam2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), value :: buffer end function hipsparseDcsrgeam2 function hipsparseCcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, buffer) & bind(c, name = 'hipsparseCcsrgeam2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrgeam2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), value :: buffer end function hipsparseCcsrgeam2 function hipsparseZcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, beta, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC, buffer) & bind(c, name = 'hipsparseZcsrgeam2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrgeam2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), value :: buffer end function hipsparseZcsrgeam2 ! hipsparseXcsrgemmNnz function hipsparseXcsrgemmNnz(handle, transA, transB, m, n, k, descrA, nnzA, & csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, descrC, & csrRowPtrC, nnzTotalDevHostPtr) & bind(c, name = 'hipsparseXcsrgemmNnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrgemmNnz type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: nnzTotalDevHostPtr end function hipsparseXcsrgemmNnz ! hipsparseScsrgemm function hipsparseScsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, & csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseScsrgemm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrgemm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseScsrgemm function hipsparseDcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, & csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseDcsrgemm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrgemm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseDcsrgemm function hipsparseCcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, & csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseCcsrgemm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrgemm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseCcsrgemm function hipsparseZcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, & csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, & csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseZcsrgemm') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrgemm type(c_ptr), value :: handle integer(c_int), value :: transA integer(c_int), value :: transB integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseZcsrgemm ! hipsparseXcsrgemm2_bufferSizeExt function hipsparseScsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, & nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, bufferSize) & bind(c, name = 'hipsparseScsrgemm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrgemm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseScsrgemm2_bufferSizeExt function hipsparseDcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, & nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, bufferSize) & bind(c, name = 'hipsparseDcsrgemm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrgemm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDcsrgemm2_bufferSizeExt function hipsparseCcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, & nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, bufferSize) & bind(c, name = 'hipsparseCcsrgemm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrgemm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCcsrgemm2_bufferSizeExt function hipsparseZcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, & nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, bufferSize) & bind(c, name = 'hipsparseZcsrgemm2_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrgemm2_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZcsrgemm2_bufferSizeExt ! hipsparseXcsrgemm2Nnz function hipsparseXcsrgemm2Nnz(handle, m, n, k, descrA, nnzA, csrRowPtrA, & csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, descrD, nnzD, & csrRowPtrD, csrColIndD, descrC, csrRowPtrC, nnzTotalDevHostPtr, info, & buffer) & bind(c, name = 'hipsparseXcsrgemm2Nnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrgemm2Nnz type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: nnzTotalDevHostPtr type(c_ptr), intent(in), value :: info type(c_ptr), value :: buffer end function hipsparseXcsrgemm2Nnz ! hipsparseXcsrgemm2 function hipsparseScsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, & csrRowPtrC, csrColIndC, info, buffer) & bind(c, name = 'hipsparseScsrgemm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrgemm2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrValD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), intent(in), value :: info type(c_ptr), value :: buffer end function hipsparseScsrgemm2 function hipsparseDcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, & csrRowPtrC, csrColIndC, info, buffer) & bind(c, name = 'hipsparseDcsrgemm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrgemm2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrValD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), intent(in), value :: info type(c_ptr), value :: buffer end function hipsparseDcsrgemm2 function hipsparseCcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, & csrRowPtrC, csrColIndC, info, buffer) & bind(c, name = 'hipsparseCcsrgemm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrgemm2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrValD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), intent(in), value :: info type(c_ptr), value :: buffer end function hipsparseCcsrgemm2 function hipsparseZcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, & csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, & beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, & csrRowPtrC, csrColIndC, info, buffer) & bind(c, name = 'hipsparseZcsrgemm2') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrgemm2 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: k type(c_ptr), intent(in), value :: alpha type(c_ptr), intent(in), value :: descrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: descrB integer(c_int), value :: nnzB type(c_ptr), intent(in), value :: csrValB type(c_ptr), intent(in), value :: csrRowPtrB type(c_ptr), intent(in), value :: csrColIndB type(c_ptr), intent(in), value :: beta type(c_ptr), intent(in), value :: descrD integer(c_int), value :: nnzD type(c_ptr), intent(in), value :: csrValD type(c_ptr), intent(in), value :: csrRowPtrD type(c_ptr), intent(in), value :: csrColIndD type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), intent(in), value :: csrRowPtrC type(c_ptr), value :: csrColIndC type(c_ptr), intent(in), value :: info type(c_ptr), value :: buffer end function hipsparseZcsrgemm2 ! =========================================================================== ! preconditioner SPARSE ! =========================================================================== ! hipsparseXbsrilu02_zeroPivot function hipsparseXbsrilu02_zeroPivot(handle, info, position) & bind(c, name = 'hipsparseXbsrilu02_zeroPivot') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXbsrilu02_zeroPivot type(c_ptr), value :: handle type(c_ptr), value :: info type(c_ptr), value :: position end function hipsparseXbsrilu02_zeroPivot ! hipsparseXbsrilu02_bufferSize function hipsparseSbsrilu02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseSbsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseSbsrilu02_bufferSize function hipsparseDbsrilu02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseDbsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDbsrilu02_bufferSize function hipsparseCbsrilu02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseCbsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCbsrilu02_bufferSize function hipsparseZbsrilu02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseZbsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZbsrilu02_bufferSize ! hipsparseXbsrilu02_analysis function hipsparseSbsrilu02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseSbsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseSbsrilu02_analysis function hipsparseDbsrilu02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseDbsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDbsrilu02_analysis function hipsparseCbsrilu02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseCbsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCbsrilu02_analysis function hipsparseZbsrilu02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseZbsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZbsrilu02_analysis ! hipsparseXbsrilu02 function hipsparseSbsrilu02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseSbsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsrilu02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseSbsrilu02 function hipsparseDbsrilu02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseDbsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsrilu02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDbsrilu02 function hipsparseCbsrilu02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseCbsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsrilu02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCbsrilu02 function hipsparseZbsrilu02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseZbsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsrilu02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZbsrilu02 ! hipsparseXcsrilu02_zeroPivot function hipsparseXcsrilu02_zeroPivot(handle, info, position) & bind(c, name = 'hipsparseXcsrilu02_zeroPivot') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrilu02_zeroPivot type(c_ptr), value :: handle type(c_ptr), value :: info type(c_ptr), value :: position end function hipsparseXcsrilu02_zeroPivot ! hipsparseXcsrilu02_bufferSize function hipsparseScsrilu02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseScsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseScsrilu02_bufferSize function hipsparseDcsrilu02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseDcsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDcsrilu02_bufferSize function hipsparseCcsrilu02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseCcsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCcsrilu02_bufferSize function hipsparseZcsrilu02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseZcsrilu02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrilu02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZcsrilu02_bufferSize ! hipsparseXcsrilu02_bufferSizeExt function hipsparseScsrilu02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseScsrilu02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrilu02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseScsrilu02_bufferSizeExt function hipsparseDcsrilu02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseDcsrilu02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrilu02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDcsrilu02_bufferSizeExt function hipsparseCcsrilu02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseCcsrilu02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrilu02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCcsrilu02_bufferSizeExt function hipsparseZcsrilu02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseZcsrilu02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrilu02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZcsrilu02_bufferSizeExt ! hipsparseXcsrilu02_analysis function hipsparseScsrilu02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseScsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsrilu02_analysis function hipsparseDcsrilu02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseDcsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsrilu02_analysis function hipsparseCcsrilu02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseCcsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsrilu02_analysis function hipsparseZcsrilu02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseZcsrilu02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrilu02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsrilu02_analysis ! hipsparseXcsrilu02 function hipsparseScsrilu02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseScsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsrilu02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsrilu02 function hipsparseDcsrilu02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseDcsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsrilu02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsrilu02 function hipsparseCcsrilu02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseCcsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsrilu02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsrilu02 function hipsparseZcsrilu02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseZcsrilu02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsrilu02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsrilu02 ! hipsparseXbsric02_zeroPivot function hipsparseXbsric02_zeroPivot(handle, info, position) & bind(c, name = 'hipsparseXbsric02_zeroPivot') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXbsric02_zeroPivot type(c_ptr), value :: handle type(c_ptr), value :: info type(c_ptr), value :: position end function hipsparseXbsric02_zeroPivot ! hipsparseXbsric02_bufferSize function hipsparseSbsric02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseSbsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseSbsric02_bufferSize function hipsparseDbsric02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseDbsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDbsric02_bufferSize function hipsparseCbsric02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseCbsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCbsric02_bufferSize function hipsparseZbsric02_bufferSize(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, bufferSize) & bind(c, name = 'hipsparseZbsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZbsric02_bufferSize ! hipsparseXbsric02_analysis function hipsparseSbsric02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseSbsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseSbsric02_analysis function hipsparseDbsric02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseDbsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDbsric02_analysis function hipsparseCbsric02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseCbsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCbsric02_analysis function hipsparseZbsric02_analysis(handle, dir, mb, nnzb, descr, bsrVal, & bsrRowPtr, bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseZbsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZbsric02_analysis ! hipsparseXbsric02 function hipsparseSbsric02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseSbsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsric02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseSbsric02 function hipsparseDbsric02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseDbsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsric02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDbsric02 function hipsparseCbsric02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseCbsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsric02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCbsric02 function hipsparseZbsric02(handle, dir, mb, nnzb, descr, bsrVal, bsrRowPtr, & bsrColInd, blockDim, info, policy, buffer) & bind(c, name = 'hipsparseZbsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsric02 type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: mb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: descr type(c_ptr), value :: bsrVal type(c_ptr), intent(in), value :: bsrRowPtr type(c_ptr), intent(in), value :: bsrColInd integer(c_int), value :: blockDim type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZbsric02 ! hipsparseXcsric02_zeroPivot function hipsparseXcsric02_zeroPivot(handle, info, position) & bind(c, name = 'hipsparseXcsric02_zeroPivot') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsric02_zeroPivot type(c_ptr), value :: handle type(c_ptr), value :: info type(c_ptr), value :: position end function hipsparseXcsric02_zeroPivot ! hipsparseXcsric02_bufferSize function hipsparseScsric02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseScsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseScsric02_bufferSize function hipsparseDcsric02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseDcsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDcsric02_bufferSize function hipsparseCcsric02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseCcsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCcsric02_bufferSize function hipsparseZcsric02_bufferSize(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseZcsric02_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsric02_bufferSize type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZcsric02_bufferSize ! hipsparseXcsric02_bufferSizeExt function hipsparseScsric02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseScsric02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsric02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseScsric02_bufferSizeExt function hipsparseDcsric02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseDcsric02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsric02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseDcsric02_bufferSizeExt function hipsparseCcsric02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseCcsric02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsric02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseCcsric02_bufferSizeExt function hipsparseZcsric02_bufferSizeExt(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, bufferSize) & bind(c, name = 'hipsparseZcsric02_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsric02_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info type(c_ptr), value :: bufferSize end function hipsparseZcsric02_bufferSizeExt ! hipsparseXcsric02_analysis function hipsparseScsric02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseScsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsric02_analysis function hipsparseDcsric02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseDcsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsric02_analysis function hipsparseCcsric02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseCcsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsric02_analysis function hipsparseZcsric02_analysis(handle, m, nnz, descr, csrVal, & csrRowPtr, csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseZcsric02_analysis') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsric02_analysis type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsric02_analysis ! hipsparseXcsric02 function hipsparseScsric02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseScsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsric02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseScsric02 function hipsparseDcsric02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseDcsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsric02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseDcsric02 function hipsparseCcsric02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseCcsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsric02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseCcsric02 function hipsparseZcsric02(handle, m, nnz, descr, csrVal, csrRowPtr, & csrColInd, info, policy, buffer) & bind(c, name = 'hipsparseZcsric02') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsric02 type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: info integer(c_int), value :: policy type(c_ptr), value :: buffer end function hipsparseZcsric02 ! =========================================================================== ! conversion SPARSE ! =========================================================================== ! hipsparseXnnz function hipsparseSnnz(handle, dir, m, n, descrA, A, lda, & nnzPerRowColumn, nnzTotalDevHostPtr) & bind(c, name = 'hipsparseSnnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSnnz type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), value :: nnzPerRowColumn type(c_ptr), value :: nnzTotalDevHostPtr end function hipsparseSnnz function hipsparseDnnz(handle, dir, m, n, descrA, A, lda, & nnzPerRowColumn, nnzTotalDevHostPtr) & bind(c, name = 'hipsparseDnnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDnnz type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), value :: nnzPerRowColumn type(c_ptr), value :: nnzTotalDevHostPtr end function hipsparseDnnz function hipsparseCnnz(handle, dir, m, n, descrA, A, lda, & nnzPerRowColumn, nnzTotalDevHostPtr) & bind(c, name = 'hipsparseCnnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCnnz type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), value :: nnzPerRowColumn type(c_ptr), value :: nnzTotalDevHostPtr end function hipsparseCnnz function hipsparseZnnz(handle, dir, m, n, descrA, A, lda, & nnzPerRowColumn, nnzTotalDevHostPtr) & bind(c, name = 'hipsparseZnnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZnnz type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), value :: nnzPerRowColumn type(c_ptr), value :: nnzTotalDevHostPtr end function hipsparseZnnz ! hipsparseXdense2csr function hipsparseSdense2csr(handle, m, n, descrA, A, lda, nnzPerRows, & csrValA, csrRowPtrA, csrColIndA) & bind(c, name = 'hipsparseSdense2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSdense2csr type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerRows type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseSdense2csr function hipsparseDdense2csr(handle, m, n, descrA, A, lda, nnzPerRows, & csrValA, csrRowPtrA, csrColIndA) & bind(c, name = 'hipsparseDdense2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDdense2csr type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerRows type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseDdense2csr function hipsparseCdense2csr(handle, m, n, descrA, A, lda, nnzPerRows, & csrValA, csrRowPtrA, csrColIndA) & bind(c, name = 'hipsparseCdense2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCdense2csr type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerRows type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseCdense2csr function hipsparseZdense2csr(handle, m, n, descrA, A, lda, nnzPerRows, & csrValA, csrRowPtrA, csrColIndA) & bind(c, name = 'hipsparseZdense2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZdense2csr type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerRows type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseZdense2csr ! hipsparseXdense2csc function hipsparseSdense2csc(handle, m, n, descrA, A, lda, nnzPerColumns, & cscValA, cscRowPtrA, cscColIndA) & bind(c, name = 'hipsparseSdense2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSdense2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerColumns type(c_ptr), value :: cscValA type(c_ptr), value :: cscRowPtrA type(c_ptr), value :: cscColIndA end function hipsparseSdense2csc function hipsparseDdense2csc(handle, m, n, descrA, A, lda, nnzPerColumns, & cscValA, cscRowPtrA, cscColIndA) & bind(c, name = 'hipsparseDdense2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDdense2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerColumns type(c_ptr), value :: cscValA type(c_ptr), value :: cscRowPtrA type(c_ptr), value :: cscColIndA end function hipsparseDdense2csc function hipsparseCdense2csc(handle, m, n, descrA, A, lda, nnzPerColumns, & cscValA, cscRowPtrA, cscColIndA) & bind(c, name = 'hipsparseCdense2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCdense2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerColumns type(c_ptr), value :: cscValA type(c_ptr), value :: cscRowPtrA type(c_ptr), value :: cscColIndA end function hipsparseCdense2csc function hipsparseZdense2csc(handle, m, n, descrA, A, lda, nnzPerColumns, & cscValA, cscRowPtrA, cscColIndA) & bind(c, name = 'hipsparseZdense2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZdense2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: A integer(c_int), value :: lda type(c_ptr), intent(in), value :: nnzPerColumns type(c_ptr), value :: cscValA type(c_ptr), value :: cscRowPtrA type(c_ptr), value :: cscColIndA end function hipsparseZdense2csc ! hipsparseXcsr2dense function hipsparseScsr2dense(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, A, lda) & bind(c, name = 'hipsparseScsr2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsr2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseScsr2dense function hipsparseDcsr2dense(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, A, lda) & bind(c, name = 'hipsparseDcsr2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsr2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseDcsr2dense function hipsparseCcsr2dense(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, A, lda) & bind(c, name = 'hipsparseCcsr2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsr2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseCcsr2dense function hipsparseZcsr2dense(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, A, lda) & bind(c, name = 'hipsparseZcsr2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsr2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseZcsr2dense ! hipsparseXcsc2dense function hipsparseScsc2dense(handle, m, n, descrA, cscValA, cscRowPtrA, & cscColIndA, A, lda) & bind(c, name = 'hipsparseScsc2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsc2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: cscValA type(c_ptr), intent(in), value :: cscRowPtrA type(c_ptr), intent(in), value :: cscColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseScsc2dense function hipsparseDcsc2dense(handle, m, n, descrA, cscValA, cscRowPtrA, & cscColIndA, A, lda) & bind(c, name = 'hipsparseDcsc2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsc2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: cscValA type(c_ptr), intent(in), value :: cscRowPtrA type(c_ptr), intent(in), value :: cscColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseDcsc2dense function hipsparseCcsc2dense(handle, m, n, descrA, cscValA, cscRowPtrA, & cscColIndA, A, lda) & bind(c, name = 'hipsparseCcsc2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsc2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: cscValA type(c_ptr), intent(in), value :: cscRowPtrA type(c_ptr), intent(in), value :: cscColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseCcsc2dense function hipsparseZcsc2dense(handle, m, n, descrA, cscValA, cscRowPtrA, & cscColIndA, A, lda) & bind(c, name = 'hipsparseZcsc2dense') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsc2dense type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: cscValA type(c_ptr), intent(in), value :: cscRowPtrA type(c_ptr), intent(in), value :: cscColIndA type(c_ptr), value :: A integer(c_int), value :: lda end function hipsparseZcsc2dense ! hipsparseXnnz_compress function hipsparseSnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, & nnzPerRow, nnzC, tol) & bind(c, name = 'hipsparseSnnz_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSnnz_compress type(c_ptr), value :: handle integer(c_int), value :: m type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), value :: nnzPerRow type(c_ptr), value :: nnzC real(c_float), value :: tol end function hipsparseSnnz_compress function hipsparseDnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, & nnzPerRow, nnzC, tol) & bind(c, name = 'hipsparseDnnz_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDnnz_compress type(c_ptr), value :: handle integer(c_int), value :: m type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), value :: nnzPerRow type(c_ptr), value :: nnzC real(c_double), value :: tol end function hipsparseDnnz_compress function hipsparseCnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, & nnzPerRow, nnzC, tol) & bind(c, name = 'hipsparseCnnz_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCnnz_compress type(c_ptr), value :: handle integer(c_int), value :: m type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), value :: nnzPerRow type(c_ptr), value :: nnzC complex(c_float_complex), value :: tol end function hipsparseCnnz_compress function hipsparseZnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, & nnzPerRow, nnzC, tol) & bind(c, name = 'hipsparseZnnz_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZnnz_compress type(c_ptr), value :: handle integer(c_int), value :: m type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), value :: nnzPerRow type(c_ptr), value :: nnzC complex(c_double_complex), value :: tol end function hipsparseZnnz_compress ! hipsparseXcsr2coo function hipsparseXcsr2coo(handle, csrRowPtr, nnz, m, cooRowInd, idxBase) & bind(c, name = 'hipsparseXcsr2coo') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsr2coo type(c_ptr), value :: handle type(c_ptr), intent(in), value :: csrRowPtr integer(c_int), value :: nnz integer(c_int), value :: m type(c_ptr), value :: cooRowInd integer(c_int), value :: idxBase end function hipsparseXcsr2coo ! hipsparseXcsr2csc function hipsparseScsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, & cscVal, cscRowInd, cscColPtr, copyValues, idxBase) & bind(c, name = 'hipsparseScsr2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsr2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: cscVal type(c_ptr), value :: cscRowInd type(c_ptr), value :: cscColPtr integer(c_int), value :: copyValues integer(c_int), value :: idxBase end function hipsparseScsr2csc function hipsparseDcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, & cscVal, cscRowInd, cscColPtr, copyValues, idxBase) & bind(c, name = 'hipsparseDcsr2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsr2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: cscVal type(c_ptr), value :: cscRowInd type(c_ptr), value :: cscColPtr integer(c_int), value :: copyValues integer(c_int), value :: idxBase end function hipsparseDcsr2csc function hipsparseCcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, & cscVal, cscRowInd, cscColPtr, copyValues, idxBase) & bind(c, name = 'hipsparseCcsr2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsr2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: cscVal type(c_ptr), value :: cscRowInd type(c_ptr), value :: cscColPtr integer(c_int), value :: copyValues integer(c_int), value :: idxBase end function hipsparseCcsr2csc function hipsparseZcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, & cscVal, cscRowInd, cscColPtr, copyValues, idxBase) & bind(c, name = 'hipsparseZcsr2csc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsr2csc type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: csrVal type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: cscVal type(c_ptr), value :: cscRowInd type(c_ptr), value :: cscColPtr integer(c_int), value :: copyValues integer(c_int), value :: idxBase end function hipsparseZcsr2csc ! hipsparseXcsr2hyb function hipsparseScsr2hyb(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, hybA, userEllWidth, partitionType) & bind(c, name = 'hipsparseScsr2hyb') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsr2hyb type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: hybA integer(c_int), value :: userEllWidth integer(c_int), value :: partitionType end function hipsparseScsr2hyb function hipsparseDcsr2hyb(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, hybA, userEllWidth, partitionType) & bind(c, name = 'hipsparseDcsr2hyb') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsr2hyb type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: hybA integer(c_int), value :: userEllWidth integer(c_int), value :: partitionType end function hipsparseDcsr2hyb function hipsparseCcsr2hyb(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, hybA, userEllWidth, partitionType) & bind(c, name = 'hipsparseCcsr2hyb') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsr2hyb type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: hybA integer(c_int), value :: userEllWidth integer(c_int), value :: partitionType end function hipsparseCcsr2hyb function hipsparseZcsr2hyb(handle, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, hybA, userEllWidth, partitionType) & bind(c, name = 'hipsparseZcsr2hyb') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsr2hyb type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), value :: hybA integer(c_int), value :: userEllWidth integer(c_int), value :: partitionType end function hipsparseZcsr2hyb ! hipsparseXgebsr2gebsc_bufferSize function hipsparseSgebsr2gebsc_bufferSize( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseSgebsr2gebsc_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseSgebsr2gebsc_bufferSize type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseSgebsr2gebsc_bufferSize function hipsparseDgebsr2gebsc_bufferSize( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseDgebsr2gebsc_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseDgebsr2gebsc_bufferSize type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseDgebsr2gebsc_bufferSize function hipsparseCgebsr2gebsc_bufferSize( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseCgebsr2gebsc_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseCgebsr2gebsc_bufferSize type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseCgebsr2gebsc_bufferSize function hipsparseZgebsr2gebsc_bufferSize( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseZgebsr2gebsc_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseZgebsr2gebsc_bufferSize type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseZgebsr2gebsc_bufferSize function hipsparseSgebsr2gebsc( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & bsc_val, & bsc_row_ind, & bsc_col_ptr, & copy_values, & idx_base, & p_buffer) & bind(c, name = 'hipsparseSgebsr2gebsc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseSgebsr2gebsc type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: bsc_val type(c_ptr), intent(in), value :: bsc_row_ind type(c_ptr), intent(in), value :: bsc_col_ptr integer(c_int), value :: copy_values integer(c_int), value :: idx_base type(c_ptr), intent(in), value :: p_buffer end function hipsparseSgebsr2gebsc function hipsparseDgebsr2gebsc( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & bsc_val, & bsc_row_ind, & bsc_col_ptr, & copy_values, & idx_base, & p_buffer) & bind(c, name = 'hipsparseDgebsr2gebsc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseDgebsr2gebsc type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: bsc_val type(c_ptr), intent(in), value :: bsc_row_ind type(c_ptr), intent(in), value :: bsc_col_ptr integer(c_int), value :: copy_values integer(c_int), value :: idx_base type(c_ptr), intent(in), value :: p_buffer end function hipsparseDgebsr2gebsc function hipsparseCgebsr2gebsc( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & bsc_val, & bsc_row_ind, & bsc_col_ptr, & copy_values, & idx_base, & p_buffer) & bind(c, name = 'hipsparseCgebsr2gebsc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseCgebsr2gebsc type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: bsc_val type(c_ptr), intent(in), value :: bsc_row_ind type(c_ptr), intent(in), value :: bsc_col_ptr integer(c_int), value :: copy_values integer(c_int), value :: idx_base type(c_ptr), intent(in), value :: p_buffer end function hipsparseCgebsr2gebsc function hipsparseZgebsr2gebsc( & handle, & mb,& nb, & nnzb, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & bsc_val, & bsc_row_ind, & bsc_col_ptr, & copy_values, & idx_base, & p_buffer) & bind(c, name = 'hipsparseZgebsr2gebsc') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseZgebsr2gebsc type(c_ptr), value :: handle integer(c_int), value :: mb integer(c_int), value :: nb integer(c_int), value :: nnzb type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: bsc_val type(c_ptr), intent(in), value :: bsc_row_ind type(c_ptr), intent(in), value :: bsc_col_ptr integer(c_int), value :: copy_values integer(c_int), value :: idx_base type(c_ptr), intent(in), value :: p_buffer end function hipsparseZgebsr2gebsc ! hipsparseXcsr2gebsr_bufferSize function hipsparseScsr2gebsr_bufferSize( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseScsr2gebsr_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseScsr2gebsr_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseScsr2gebsr_bufferSize function hipsparseDcsr2gebsr_bufferSize( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseDcsr2gebsr_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseDcsr2gebsr_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseDcsr2gebsr_bufferSize function hipsparseCcsr2gebsr_bufferSize( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseCcsr2gebsr_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseCcsr2gebsr_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseCcsr2gebsr_bufferSize function hipsparseZcsr2gebsr_bufferSize( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & row_block_dim, & col_block_dim, & p_buffer_size) & bind(c, name = 'hipsparseZcsr2gebsr_bufferSize') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseZcsr2gebsr_bufferSize type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: p_buffer_size end function hipsparseZcsr2gebsr_bufferSize ! hipsparseXcsr2gebsrNnz function hipsparseXcsr2gebsrNnz( & handle, & dir, & m, & n, & csr_descr, & csr_row_ptr, & csr_col_ind, & bsr_descr, & bsr_row_ptr, & row_block_dim, & col_block_dim, & bsr_nnz_devhost, & p_buffer) & bind(c, name = 'hipsparseXcsr2gebsrNnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseXcsr2gebsrNnz type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind type(c_ptr), intent(in), value :: bsr_descr type(c_ptr), intent(in), value :: bsr_row_ptr integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), value :: bsr_nnz_devhost type(c_ptr), intent(in), value :: p_buffer end function hipsparseXcsr2gebsrNnz ! hipsparseScsr2gebsr function hipsparseScsr2gebsr( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & bsr_descr, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer) & bind(c, name = 'hipsparseScsr2gebsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseScsr2gebsr type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind type(c_ptr), intent(in), value :: bsr_descr type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: p_buffer end function hipsparseScsr2gebsr ! hipsparseDcsr2gebsr function hipsparseDcsr2gebsr( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & bsr_descr, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer) & bind(c, name = 'hipsparseDcsr2gebsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseDcsr2gebsr type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind type(c_ptr), intent(in), value :: bsr_descr type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: p_buffer end function hipsparseDcsr2gebsr function hipsparseCcsr2gebsr( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & bsr_descr, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer) & bind(c, name = 'hipsparseCcsr2gebsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseCcsr2gebsr type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind type(c_ptr), intent(in), value :: bsr_descr type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: p_buffer end function hipsparseCcsr2gebsr function hipsparseZcsr2gebsr( & handle, & dir, & m, & n, & csr_descr, & csr_val, & csr_row_ptr, & csr_col_ind, & bsr_descr, & bsr_val, & bsr_row_ptr, & bsr_col_ind, & row_block_dim, & col_block_dim, & p_buffer) & bind(c, name = 'hipsparseZcsr2gebsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) & :: hipsparseZcsr2gebsr type(c_ptr), value :: handle integer(c_int), value :: dir integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: csr_descr type(c_ptr), intent(in), value :: csr_val type(c_ptr), intent(in), value :: csr_row_ptr type(c_ptr), intent(in), value :: csr_col_ind type(c_ptr), intent(in), value :: bsr_descr type(c_ptr), intent(in), value :: bsr_val type(c_ptr), intent(in), value :: bsr_row_ptr type(c_ptr), intent(in), value :: bsr_col_ind integer(c_int), value :: row_block_dim integer(c_int), value :: col_block_dim type(c_ptr), intent(in), value :: p_buffer end function hipsparseZcsr2gebsr ! hipsparseXcsr2bsrNnz function hipsparseXcsr2bsrNnz(handle, dirA, m, n, descrA, csrRowPtrA, & csrColIndA, blockDim, descrC, bsrRowPtrC, bsrNnzb) & bind(c, name = 'hipsparseXcsr2bsrNnz') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsr2bsrNnz type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: bsrRowPtrC type(c_ptr), value :: bsrNnzb end function hipsparseXcsr2bsrNnz ! hipsparseXcsr2bsr function hipsparseScsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC) & bind(c, name = 'hipsparseScsr2bsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsr2bsr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: bsrValC type(c_ptr), value :: bsrRowPtrC type(c_ptr), value :: bsrColIndC end function hipsparseScsr2bsr function hipsparseDcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC) & bind(c, name = 'hipsparseDcsr2bsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsr2bsr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: bsrValC type(c_ptr), value :: bsrRowPtrC type(c_ptr), value :: bsrColIndC end function hipsparseDcsr2bsr function hipsparseCcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC) & bind(c, name = 'hipsparseCcsr2bsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsr2bsr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: bsrValC type(c_ptr), value :: bsrRowPtrC type(c_ptr), value :: bsrColIndC end function hipsparseCcsr2bsr function hipsparseZcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, & csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC) & bind(c, name = 'hipsparseZcsr2bsr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsr2bsr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrRowPtrA type(c_ptr), intent(in), value :: csrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: bsrValC type(c_ptr), value :: bsrRowPtrC type(c_ptr), value :: bsrColIndC end function hipsparseZcsr2bsr ! hipsparseXbsr2csr function hipsparseSbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseSbsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSbsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseSbsr2csr function hipsparseDbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseDbsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDbsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseDbsr2csr function hipsparseCbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseCbsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCbsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseCbsr2csr function hipsparseZbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseZbsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZbsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: blockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseZbsr2csr ! hipsparseXgebsr2csr function hipsparseSgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, rowBlockDim, colBlockDim,descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseSgebsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseSgebsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: rowBlockDim integer(c_int), value :: colBlockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseSgebsr2csr function hipsparseDgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, rowBlockDim, colBlockDim,descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseDgebsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDgebsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: rowBlockDim integer(c_int), value :: colBlockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseDgebsr2csr function hipsparseCgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, rowBlockDim, colBlockDim,descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseCgebsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCgebsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: rowBlockDim integer(c_int), value :: colBlockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseCgebsr2csr function hipsparseZgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, & bsrColIndA, rowBlockDim, colBlockDim,descrC, csrValC, csrRowPtrC, csrColIndC) & bind(c, name = 'hipsparseZgebsr2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZgebsr2csr type(c_ptr), value :: handle integer(c_int), value :: dirA integer(c_int), value :: mb integer(c_int), value :: nb type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: bsrValA type(c_ptr), intent(in), value :: bsrRowPtrA type(c_ptr), intent(in), value :: bsrColIndA integer(c_int), value :: rowBlockDim integer(c_int), value :: colBlockDim type(c_ptr), intent(in), value :: descrC type(c_ptr), value :: csrValC type(c_ptr), value :: csrRowPtrC type(c_ptr), value :: csrColIndC end function hipsparseZgebsr2csr ! hipsparseXcsr2csr_compress function hipsparseScsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, & csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol) & bind(c, name = 'hipsparseScsr2csr_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseScsr2csr_compress type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: csrRowPtrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: nnzPerRow type(c_ptr), value :: csrValC type(c_ptr), value :: csrColIndC type(c_ptr), value :: csrRowPtrC real(c_float), value :: tol end function hipsparseScsr2csr_compress function hipsparseDcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, & csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol) & bind(c, name = 'hipsparseDcsr2csr_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDcsr2csr_compress type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: csrRowPtrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: nnzPerRow type(c_ptr), value :: csrValC type(c_ptr), value :: csrColIndC type(c_ptr), value :: csrRowPtrC real(c_double), value :: tol end function hipsparseDcsr2csr_compress function hipsparseCcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, & csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol) & bind(c, name = 'hipsparseCcsr2csr_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCcsr2csr_compress type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: csrRowPtrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: nnzPerRow type(c_ptr), value :: csrValC type(c_ptr), value :: csrColIndC type(c_ptr), value :: csrRowPtrC complex(c_float_complex), value :: tol end function hipsparseCcsr2csr_compress function hipsparseZcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, & csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol) & bind(c, name = 'hipsparseZcsr2csr_compress') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZcsr2csr_compress type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: csrValA type(c_ptr), intent(in), value :: csrColIndA type(c_ptr), intent(in), value :: csrRowPtrA integer(c_int), value :: nnzA type(c_ptr), intent(in), value :: nnzPerRow type(c_ptr), value :: csrValC type(c_ptr), value :: csrColIndC type(c_ptr), value :: csrRowPtrC complex(c_double_complex), value :: tol end function hipsparseZcsr2csr_compress ! hipsparseXhyb2csr function hipsparseShyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, & csrColIndA) & bind(c, name = 'hipsparseShyb2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseShyb2csr type(c_ptr), value :: handle type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: hybA type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseShyb2csr function hipsparseDhyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, & csrColIndA) & bind(c, name = 'hipsparseDhyb2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseDhyb2csr type(c_ptr), value :: handle type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: hybA type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseDhyb2csr function hipsparseChyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, & csrColIndA) & bind(c, name = 'hipsparseChyb2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseChyb2csr type(c_ptr), value :: handle type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: hybA type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseChyb2csr function hipsparseZhyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, & csrColIndA) & bind(c, name = 'hipsparseZhyb2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseZhyb2csr type(c_ptr), value :: handle type(c_ptr), intent(in), value :: descrA type(c_ptr), intent(in), value :: hybA type(c_ptr), value :: csrValA type(c_ptr), value :: csrRowPtrA type(c_ptr), value :: csrColIndA end function hipsparseZhyb2csr ! hipsparseXcoo2csr function hipsparseXcoo2csr(handle, cooRowInd, nnz, m, csrRowPtr, idxBase) & bind(c, name = 'hipsparseXcoo2csr') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcoo2csr type(c_ptr), value :: handle type(c_ptr), intent(in), value :: cooRowInd integer(c_int), value :: nnz integer(c_int), value :: m type(c_ptr), value :: csrRowPtr integer(c_int), value :: idxBase end function hipsparseXcoo2csr ! hipsparseCreateIdentityPermutation function hipsparseCreateIdentityPermutation(handle, n, p) & bind(c, name = 'hipsparseCreateIdentityPermutation') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseCreateIdentityPermutation type(c_ptr), value :: handle integer(c_int), value :: n type(c_ptr), value :: p end function hipsparseCreateIdentityPermutation ! hipsparseXcsrsort_bufferSizeExt function hipsparseXcsrsort_bufferSizeExt(handle, m, n, nnz, csrRowPtr, & csrColInd, bufferSize) & bind(c, name = 'hipsparseXcsrsort_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrsort_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), intent(in), value :: csrColInd type(c_ptr), value :: bufferSize end function hipsparseXcsrsort_bufferSizeExt ! hipsparseXcsrsort function hipsparseXcsrsort(handle, m, n, nnz, descr, csrRowPtr, csrColInd, & perm, buffer) & bind(c, name = 'hipsparseXcsrsort') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcsrsort type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: csrRowPtr type(c_ptr), value :: csrColInd type(c_ptr), value :: perm type(c_ptr), value :: buffer end function hipsparseXcsrsort ! hipsparseXcscsort_bufferSizeExt function hipsparseXcscsort_bufferSizeExt(handle, m, n, nnz, cscRowPtr, & cscColInd, bufferSize) & bind(c, name = 'hipsparseXcscsort_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcscsort_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: cscRowPtr type(c_ptr), intent(in), value :: cscColInd type(c_ptr), value :: bufferSize end function hipsparseXcscsort_bufferSizeExt ! hipsparseXcscsort function hipsparseXcscsort(handle, m, n, nnz, descr, cscRowPtr, cscColInd, & perm, buffer) & bind(c, name = 'hipsparseXcscsort') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcscsort type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: descr type(c_ptr), intent(in), value :: cscRowPtr type(c_ptr), value :: cscColInd type(c_ptr), value :: perm type(c_ptr), value :: buffer end function hipsparseXcscsort ! hipsparseXcoosort_bufferSizeExt function hipsparseXcoosort_bufferSizeExt(handle, m, n, nnz, cooRowInd, & cooColInd, bufferSize) & bind(c, name = 'hipsparseXcoosort_bufferSizeExt') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcoosort_bufferSizeExt type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), intent(in), value :: cooRowInd type(c_ptr), intent(in), value :: cooColInd type(c_ptr), value :: bufferSize end function hipsparseXcoosort_bufferSizeExt ! hipsparseXcoosortByRow function hipsparseXcoosortByRow(handle, m, n, nnz, cooRowInd, cooColInd, & perm, buffer) & bind(c, name = 'hipsparseXcoosortByRow') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcoosortByRow type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), value :: cooRowInd type(c_ptr), value :: cooColInd type(c_ptr), value :: perm type(c_ptr), value :: buffer end function hipsparseXcoosortByRow ! hipsparseXcoosortByColumn function hipsparseXcoosortByColumn(handle, m, n, nnz, cooRowInd, cooColInd, & perm, buffer) & bind(c, name = 'hipsparseXcoosortByColumn') use hipsparse_enums use iso_c_binding implicit none integer(kind(HIPSPARSE_STATUS_SUCCESS)) :: hipsparseXcoosortByColumn type(c_ptr), value :: handle integer(c_int), value :: m integer(c_int), value :: n integer(c_int), value :: nnz type(c_ptr), value :: cooRowInd type(c_ptr), value :: cooColInd type(c_ptr), value :: perm type(c_ptr), value :: buffer end function hipsparseXcoosortByColumn end interface end module hipsparse ./library/src/hipsparse_enums.f900000664000175100017510000001016315176134305017071 0ustar jenkinsjenkins!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. ! ! Permission is hereby granted, free of charge, to any person obtaining a copy ! of this software and associated documentation files (the "Software"), to deal ! in the Software without restriction, including without limitation the rights ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ! copies of the Software, and to permit persons to whom the Software is ! furnished to do so, subject to the following conditions: ! ! The above copyright notice and this permission notice shall be included in ! all copies or substantial portions of the Software. ! ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ! THE SOFTWARE. ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! module hipsparse_enums implicit none ! =========================================================================== ! types SPARSE ! =========================================================================== ! hipsparseStatus_t enum, bind(c) enumerator :: HIPSPARSE_STATUS_SUCCESS = 0 enumerator :: HIPSPARSE_STATUS_NOT_INITIALIZED = 1 enumerator :: HIPSPARSE_STATUS_ALLOC_FAILED = 2 enumerator :: HIPSPARSE_STATUS_INVALID_VALUE = 3 enumerator :: HIPSPARSE_STATUS_ARCH_MISMATCH = 4 enumerator :: HIPSPARSE_STATUS_MAPPING_ERROR = 5 enumerator :: HIPSPARSE_STATUS_EXECUTION_FAILED = 6 enumerator :: HIPSPARSE_STATUS_INTERNAL_ERROR = 7 enumerator :: HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED = 8 enumerator :: HIPSPARSE_STATUS_ZERO_PIVOT = 9 end enum ! hipsparsePointerMode_t enum, bind(c) enumerator :: HIPSPARSE_POINTER_MODE_HOST = 0 enumerator :: HIPSPARSE_POINTER_MODE_DEVICE = 1 end enum ! hipsparseAction_t enum, bind(c) enumerator :: HIPSPARSE_ACTION_SYMBOLIC = 0 enumerator :: HIPSPARSE_ACTION_NUMERIC = 1 end enum ! hipsparseMatrixType_t enum, bind(c) enumerator :: HIPSPARSE_MATRIX_TYPE_GENERAL = 0 enumerator :: HIPSPARSE_MATRIX_TYPE_SYMMETRIC = 1 enumerator :: HIPSPARSE_MATRIX_TYPE_HERMITIAN = 2 enumerator :: HIPSPARSE_MATRIX_TYPE_TRIANGULAR = 3 end enum ! hipsparseFillMode_t enum, bind(c) enumerator :: HIPSPARSE_FILL_MODE_LOWER = 0 enumerator :: HIPSPARSE_FILL_MODE_UPPER = 1 end enum ! hipsparseDiagType_t enum, bind(c) enumerator :: HIPSPARSE_DIAG_TYPE_NON_UNIT = 0 enumerator :: HIPSPARSE_DIAG_TYPE_UNIT = 1 end enum ! hipsparseIndexBase_t enum, bind(c) enumerator :: HIPSPARSE_INDEX_BASE_ZERO = 0 enumerator :: HIPSPARSE_INDEX_BASE_ONE = 1 end enum ! hipsparseOperation_t enum, bind(c) enumerator :: HIPSPARSE_OPERATION_NON_TRANSPOSE = 0 enumerator :: HIPSPARSE_OPERATION_TRANSPOSE = 1 enumerator :: HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE = 2 end enum ! hipsparseHybPartition_t enum, bind(c) enumerator :: HIPSPARSE_HYB_PARTITION_AUTO = 0 enumerator :: HIPSPARSE_HYB_PARTITION_USER = 1 enumerator :: HIPSPARSE_HYB_PARTITION_MAX = 2 end enum ! hipsparseSolvePolicy_t enum, bind(c) enumerator :: HIPSPARSE_SOLVE_POLICY_NO_LEVEL = 0 enumerator :: HIPSPARSE_SOLVE_POLICY_USE_LEVEL = 1 end enum ! hipsparseSideMode_t enum, bind(c) enumerator :: HIPSPARSE_SIDE_LEFT = 0 enumerator :: HIPSPARSE_SIDE_RIGHT = 1 end enum ! hipsparseDirection_t enum, bind(c) enumerator :: HIPSPARSE_DIRECTION_ROW = 0 enumerator :: HIPSPARSE_DIRECTION_COLUMN = 1 end enum end module hipsparse_enums ./library/src/CMakeLists.txt0000664000175100017510000000324215176134511016103 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2018 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # hipSPARSE source if(NOT USE_CUDA) # hipSPARSE source FILE(GLOB_RECURSE AMD_DETAIL_SOURCE src/amd_detail/*.cpp) set(hipsparse_source ${AMD_DETAIL_SOURCE}) else() # hipSPARSE CUDA source FILE(GLOB_RECURSE NVIDIA_DETAIL_SOURCE src/nvidia_detail/*.cpp) set(hipsparse_source ${NVIDIA_DETAIL_SOURCE}) endif() # hipSPARSE Fortran source set(hipsparse_fortran_source src/hipsparse.f90 src/hipsparse_enums.f90) ./library/src/amd_detail/0000775000175100017510000000000015176134511015425 5ustar jenkinsjenkins./library/src/amd_detail/level1/0000775000175100017510000000000015176134461016621 5ustar jenkinsjenkins./library/src/amd_detail/level1/hipsparse_axpyi.cpp0000664000175100017510000001042715176134305022536 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSaxpyi(hipsparseHandle_t handle, int nnz, const float* alpha, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_saxpyi( (rocsparse_handle)handle, nnz, alpha, xVal, xInd, y, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseDaxpyi(hipsparseHandle_t handle, int nnz, const double* alpha, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_daxpyi( (rocsparse_handle)handle, nnz, alpha, xVal, xInd, y, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseCaxpyi(hipsparseHandle_t handle, int nnz, const hipComplex* alpha, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_caxpyi((rocsparse_handle)handle, nnz, (const rocsparse_float_complex*)alpha, (const rocsparse_float_complex*)xVal, xInd, (rocsparse_float_complex*)y, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseZaxpyi(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zaxpyi((rocsparse_handle)handle, nnz, (const rocsparse_double_complex*)alpha, (const rocsparse_double_complex*)xVal, xInd, (rocsparse_double_complex*)y, hipsparse::hipBaseToHCCBase(idxBase))); } ./library/src/amd_detail/level1/hipsparse_dotci.cpp0000664000175100017510000000760715176134305022514 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseCdotci(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { // Obtain stream, to explicitly sync (cusparse dotci is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Dotci RETURN_IF_ROCSPARSE_ERROR(rocsparse_cdotci((rocsparse_handle)handle, nnz, (const rocsparse_float_complex*)xVal, xInd, (const rocsparse_float_complex*)y, (rocsparse_float_complex*)result, hipsparse::hipBaseToHCCBase(idxBase))); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZdotci(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { // Obtain stream, to explicitly sync (cusparse dotci is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Dotci RETURN_IF_ROCSPARSE_ERROR(rocsparse_zdotci((rocsparse_handle)handle, nnz, (const rocsparse_double_complex*)xVal, xInd, (const rocsparse_double_complex*)y, (rocsparse_double_complex*)result, hipsparse::hipBaseToHCCBase(idxBase))); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/level1/hipsparse_gthrz.cpp0000664000175100017510000000755715176134305022554 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgthrz(hipsparseHandle_t handle, int nnz, float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_sgthrz( (rocsparse_handle)handle, nnz, y, xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseDgthrz(hipsparseHandle_t handle, int nnz, double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dgthrz( (rocsparse_handle)handle, nnz, y, xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseCgthrz(hipsparseHandle_t handle, int nnz, hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgthrz((rocsparse_handle)handle, nnz, (rocsparse_float_complex*)y, (rocsparse_float_complex*)xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseZgthrz(hipsparseHandle_t handle, int nnz, hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgthrz((rocsparse_handle)handle, nnz, (rocsparse_double_complex*)y, (rocsparse_double_complex*)xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } ./library/src/amd_detail/level1/hipsparse_gthr.cpp0000664000175100017510000000754715176134305022361 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgthr(hipsparseHandle_t handle, int nnz, const float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_sgthr( (rocsparse_handle)handle, nnz, y, xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseDgthr(hipsparseHandle_t handle, int nnz, const double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dgthr( (rocsparse_handle)handle, nnz, y, xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseCgthr(hipsparseHandle_t handle, int nnz, const hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgthr((rocsparse_handle)handle, nnz, (const rocsparse_float_complex*)y, (rocsparse_float_complex*)xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseZgthr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgthr((rocsparse_handle)handle, nnz, (const rocsparse_double_complex*)y, (rocsparse_double_complex*)xVal, xInd, hipsparse::hipBaseToHCCBase(idxBase))); } ./library/src/amd_detail/level1/hipsparse_doti.cpp0000664000175100017510000001411315176134305022337 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSdoti(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, const float* y, float* result, hipsparseIndexBase_t idxBase) { // Obtain stream, to explicitly sync (cusparse doti is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Doti RETURN_IF_ROCSPARSE_ERROR(rocsparse_sdoti((rocsparse_handle)handle, nnz, xVal, xInd, y, result, hipsparse::hipBaseToHCCBase(idxBase))); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDdoti(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, const double* y, double* result, hipsparseIndexBase_t idxBase) { // Obtain stream, to explicitly sync (cusparse doti is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Doti RETURN_IF_ROCSPARSE_ERROR(rocsparse_ddoti((rocsparse_handle)handle, nnz, xVal, xInd, y, result, hipsparse::hipBaseToHCCBase(idxBase))); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCdoti(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { // Obtain stream, to explicitly sync (cusparse doti is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Doti RETURN_IF_ROCSPARSE_ERROR(rocsparse_cdoti((rocsparse_handle)handle, nnz, (const rocsparse_float_complex*)xVal, xInd, (const rocsparse_float_complex*)y, (rocsparse_float_complex*)result, hipsparse::hipBaseToHCCBase(idxBase))); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZdoti(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { // Obtain stream, to explicitly sync (cusparse doti is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Doti RETURN_IF_ROCSPARSE_ERROR(rocsparse_zdoti((rocsparse_handle)handle, nnz, (const rocsparse_double_complex*)xVal, xInd, (const rocsparse_double_complex*)y, (rocsparse_double_complex*)result, hipsparse::hipBaseToHCCBase(idxBase))); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/level1/hipsparse_sctr.cpp0000664000175100017510000000754715176134305022370 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSsctr(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_ssctr( (rocsparse_handle)handle, nnz, xVal, xInd, y, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseDsctr(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dsctr( (rocsparse_handle)handle, nnz, xVal, xInd, y, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseCsctr(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_csctr((rocsparse_handle)handle, nnz, (const rocsparse_float_complex*)xVal, xInd, (rocsparse_float_complex*)y, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseZsctr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zsctr((rocsparse_handle)handle, nnz, (const rocsparse_double_complex*)xVal, xInd, (rocsparse_double_complex*)y, hipsparse::hipBaseToHCCBase(idxBase))); } ./library/src/amd_detail/level1/hipsparse_roti.cpp0000664000175100017510000000530315176134305022356 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSroti(hipsparseHandle_t handle, int nnz, float* xVal, const int* xInd, float* y, const float* c, const float* s, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_sroti( (rocsparse_handle)handle, nnz, xVal, xInd, y, c, s, hipsparse::hipBaseToHCCBase(idxBase))); } hipsparseStatus_t hipsparseDroti(hipsparseHandle_t handle, int nnz, double* xVal, const int* xInd, double* y, const double* c, const double* s, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_droti( (rocsparse_handle)handle, nnz, xVal, xInd, y, c, s, hipsparse::hipBaseToHCCBase(idxBase))); } ./library/src/amd_detail/level3/0000775000175100017510000000000015176134461016623 5ustar jenkinsjenkins./library/src/amd_detail/level3/hipsparse_bsrsm.cpp0000664000175100017510000007265315176134305022545 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXbsrsm2_zeroPivot(hipsparseHandle_t handle, bsrsm2Info_t info, int* position) { // Obtain stream, to explicitly sync (cusparse bsrsm2_zeropivot is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsrsm zero pivot RETURN_IF_ROCSPARSE_ERROR( rocsparse_bsrsm_zero_pivot((rocsparse_handle)handle, (rocsparse_mat_info)info, position)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &size)); *pBufferSizeInBytes = (int)size; return status; } hipsparseStatus_t hipsparseDbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &size)); *pBufferSizeInBytes = (int)size; return status; } hipsparseStatus_t hipsparseCbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &size)); *pBufferSizeInBytes = (int)size; return status; } hipsparseStatus_t hipsparseZbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &size)); *pBufferSizeInBytes = (int)size; return status; } hipsparseStatus_t hipsparseSbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrsm_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrsm_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrsm_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrsm_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseSbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const float* B, int ldb, float* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrsm_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, alpha, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, B, ldb, X, ldx, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const double* B, int ldb, double* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrsm_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, alpha, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, B, ldb, X, ldx, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipComplex* B, int ldb, hipComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrsm_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, (const rocsparse_float_complex*)B, ldb, (rocsparse_float_complex*)X, ldx, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipDoubleComplex* B, int ldb, hipDoubleComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrsm_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transX), mb, nrhs, nnzb, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, (const rocsparse_double_complex*)B, ldb, (rocsparse_double_complex*)X, ldx, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/level3/hipsparse_gemmi.cpp0000664000175100017510000002420215176134305022500 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const float* alpha, const float* A, int lda, const float* cscValB, const int* cscColPtrB, const int* cscRowIndB, const float* beta, float* C, int ldc) { rocsparse_mat_descr descr; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_descr(&descr)); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_sgemmi((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_transpose, m, n, k, nnz, alpha, A, lda, descr, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_descr(descr); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_descr(descr)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const double* alpha, const double* A, int lda, const double* cscValB, const int* cscColPtrB, const int* cscRowIndB, const double* beta, double* C, int ldc) { rocsparse_mat_descr descr; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_descr(&descr)); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dgemmi((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_transpose, m, n, k, nnz, alpha, A, lda, descr, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_descr(descr); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_descr(descr)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipComplex* alpha, const hipComplex* A, int lda, const hipComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipComplex* beta, hipComplex* C, int ldc) { rocsparse_mat_descr descr; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_descr(&descr)); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgemmi((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_transpose, m, n, k, nnz, (const rocsparse_float_complex*)alpha, (const rocsparse_float_complex*)A, lda, descr, (const rocsparse_float_complex*)cscValB, cscColPtrB, cscRowIndB, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)C, ldc)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_descr(descr); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_descr(descr)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, const hipDoubleComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { rocsparse_mat_descr descr; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_descr(&descr)); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgemmi((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_transpose, m, n, k, nnz, (const rocsparse_double_complex*)alpha, (const rocsparse_double_complex*)A, lda, descr, (const rocsparse_double_complex*)cscValB, cscColPtrB, cscRowIndB, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)C, ldc)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_descr(descr); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_descr(descr)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/level3/hipsparse_bsrmm.cpp0000664000175100017510000002357015176134305022531 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrmm((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), mb, n, kb, nnzb, alpha, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseDbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrmm((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), mb, n, kb, nnzb, alpha, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseCbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrmm((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), mb, n, kb, nnzb, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const rocsparse_float_complex*)B, ldb, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)C, ldc)); } hipsparseStatus_t hipsparseZbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrmm((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), mb, n, kb, nnzb, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const rocsparse_double_complex*)B, ldb, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)C, ldc)); } ./library/src/amd_detail/level3/hipsparse_csrsm.cpp0000664000175100017510000007224615176134305022544 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsrsm2_zeroPivot(hipsparseHandle_t handle, csrsm2Info_t info, int* position) { // Obtain stream, to explicitly sync (cusparse csrsm2_zeropivot is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrsm zero pivot RETURN_IF_ROCSPARSE_ERROR( rocsparse_csrsm_zero_pivot((rocsparse_handle)handle, (rocsparse_mat_info)info, position)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, alpha, (const rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, alpha, (const rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_float_complex*)B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrsm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_double_complex*)B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseScsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrsm_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, alpha, (const rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrsm_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, alpha, (const rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrsm_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_float_complex*)B, ldb, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrsm_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_double_complex*)B, ldb, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseScsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrsm_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, alpha, (const rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrsm_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, alpha, (const rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrsm_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_float_complex*)B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrsm_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, nrhs, nnz, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_double_complex*)B, ldb, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/level3/hipsparse_csrmm.cpp0000664000175100017510000004060115176134305022524 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), rocsparse_operation_none, m, n, k, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseDcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), rocsparse_operation_none, m, n, k, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseCcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), rocsparse_operation_none, m, n, k, nnz, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_float_complex*)B, ldb, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)C, ldc)); } hipsparseStatus_t hipsparseZcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), rocsparse_operation_none, m, n, k, nnz, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_double_complex*)B, ldb, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)C, ldc)); } hipsparseStatus_t hipsparseScsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseDcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseCcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, nnz, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_float_complex*)B, ldb, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)C, ldc)); } hipsparseStatus_t hipsparseZcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, nnz, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_double_complex*)B, ldb, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)C, ldc)); } ./library/src/amd_detail/hipsparse_generic_auxiliary.cpp0000664000175100017510000017175115176134511023726 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "utility.h" // // hipsparseSpMVDescr_st // rocsparse_spmv_descr hipsparseSpMVDescr_st::get_spmv_descr() { return this->m_spmv_descr; } void hipsparseSpMVDescr_st::set_spmv_descr(rocsparse_spmv_descr value) { this->m_spmv_descr = value; } bool hipsparseSpMVDescr_st::is_stage_analysis_called() const { return this->m_is_stage_analysis_called; } bool hipsparseSpMVDescr_st::is_implicit_stage_analysis_called() const { return this->m_is_implicit_stage_analysis_called; } size_t hipsparseSpMVDescr_st::get_buffer_size_stage_analysis() const { return this->m_buffer_size_stage_analysis; } size_t hipsparseSpMVDescr_st::get_buffer_size_stage_compute() const { return this->m_buffer_size_stage_compute; } void* hipsparseSpMVDescr_st::get_buffer() { return this->m_buffer; } void** hipsparseSpMVDescr_st::get_buffer_reference() { return &this->m_buffer; } bool hipsparseSpMVDescr_st::is_stage_compute_subsequent() const { return this->m_is_stage_compute_subsequent; } bool hipsparseSpMVDescr_st::is_buffer_size_called() const { return this->m_is_buffer_size_called; } void hipsparseSpMVDescr_st::stage_analysis_called() { this->m_is_stage_analysis_called = true; } void hipsparseSpMVDescr_st::implicit_stage_analysis_called() { this->m_is_implicit_stage_analysis_called = true; } void hipsparseSpMVDescr_st::set_buffer_size_stage_analysis(size_t value) { this->m_buffer_size_stage_analysis = value; } void hipsparseSpMVDescr_st::set_buffer_size_stage_compute(size_t value) { this->m_buffer_size_stage_compute = value; } void hipsparseSpMVDescr_st::set_buffer(void* value) { this->m_buffer = value; } void hipsparseSpMVDescr_st::stage_compute_subsequent() { this->m_is_stage_compute_subsequent = true; } void hipsparseSpMVDescr_st::buffer_size_called() { this->m_is_buffer_size_called = true; } hipsparseSpMVDescr_st::~hipsparseSpMVDescr_st() { (void)hipFree(this->get_buffer()); } // // hipsparseSpMatDescr_st // rocsparse_spmat_descr hipsparseSpMatDescr_st::get_spmat_descr() { return this->m_spmat_descr; } rocsparse_const_spmat_descr hipsparseSpMatDescr_st::get_const_spmat_descr() const { return this->m_spmat_descr; } void hipsparseSpMatDescr_st::set_spmat_descr(rocsparse_spmat_descr value) { this->m_spmat_descr = value; } hipsparseSpMVDescr_st* hipsparseSpMatDescr_st::get_hip_spmv_descr() { return &this->m_hip_spmv_descr; } hipsparseSpMVDescr_st* hipsparseSpMatDescr_st::get_hip_spmv_descr() const { return &this->m_hip_spmv_descr; } rocsparse_spmat_descr* hipsparseSpMatDescr_st::get_spmat_descr_reference() { return &this->m_spmat_descr; } rocsparse_const_spmat_descr* hipsparseSpMatDescr_st::get_const_spmat_descr_reference() const { return (rocsparse_const_spmat_descr*)&this->m_spmat_descr; } // // Cast hipsparseSpMatDescr_st to rocsparse_spmat_descr. // rocsparse_const_spmat_descr to_rocsparse_const_spmat_descr(const hipsparseConstSpMatDescr_t source) { return (source != nullptr) ? source->get_const_spmat_descr() : nullptr; } rocsparse_spmat_descr to_rocsparse_spmat_descr(const hipsparseSpMatDescr_t source) { return (source != nullptr) ? source->get_spmat_descr() : nullptr; } /* Generic API */ hipsparseStatus_t hipsparseCreateSpVec(hipsparseSpVecDescr_t* spVecDescr, int64_t size, int64_t nnz, void* indices, void* values, hipsparseIndexType_t idxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_spvec_descr((rocsparse_spvec_descr*)spVecDescr, size, nnz, indices, values, hipsparse::hipIndexTypeToHCCIndexType(idxType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); } hipsparseStatus_t hipsparseCreateConstSpVec(hipsparseConstSpVecDescr_t* spVecDescr, int64_t size, int64_t nnz, const void* indices, const void* values, hipsparseIndexType_t idxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_const_spvec_descr((rocsparse_const_spvec_descr*)spVecDescr, size, nnz, indices, values, hipsparse::hipIndexTypeToHCCIndexType(idxType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); } hipsparseStatus_t hipsparseDestroySpVec(hipsparseConstSpVecDescr_t spVecDescr) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_spvec_descr((rocsparse_const_spvec_descr)spVecDescr)); } hipsparseStatus_t hipsparseSpVecGet(const hipsparseSpVecDescr_t spVecDescr, int64_t* size, int64_t* nnz, void** indices, void** values, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR(rocsparse_spvec_get((const rocsparse_spvec_descr)spVecDescr, size, nnz, indices, values, idxType != nullptr ? &hcc_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *idxType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseConstSpVecGet(hipsparseConstSpVecDescr_t spVecDescr, int64_t* size, int64_t* nnz, const void** indices, const void** values, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_const_spvec_get((rocsparse_const_spvec_descr)spVecDescr, size, nnz, indices, values, idxType != nullptr ? &hcc_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *idxType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpVecGetIndexBase(const hipsparseConstSpVecDescr_t spVecDescr, hipsparseIndexBase_t* idxBase) { rocsparse_index_base hcc_index_base; RETURN_IF_ROCSPARSE_ERROR( rocsparse_spvec_get_index_base((const rocsparse_const_spvec_descr)spVecDescr, idxBase != nullptr ? &hcc_index_base : nullptr)); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpVecGetValues(const hipsparseSpVecDescr_t spVecDescr, void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spvec_get_values((const rocsparse_spvec_descr)spVecDescr, values)); } hipsparseStatus_t hipsparseConstSpVecGetValues(hipsparseConstSpVecDescr_t spVecDescr, const void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_const_spvec_get_values((rocsparse_const_spvec_descr)spVecDescr, values)); } hipsparseStatus_t hipsparseSpVecSetValues(hipsparseSpVecDescr_t spVecDescr, void* values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spvec_set_values((rocsparse_spvec_descr)spVecDescr, values)); } hipsparseStatus_t hipsparseCreateCoo(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cooRowInd, void* cooColInd, void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_coo_descr(spMatDescr[0]->get_spmat_descr_reference(), rows, cols, nnz, cooRowInd, cooColInd, cooValues, hipsparse::hipIndexTypeToHCCIndexType(cooIdxType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseCreateConstCoo(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* cooRowInd, const void* cooColInd, const void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_const_coo_descr(spMatDescr[0]->get_const_spmat_descr_reference(), rows, cols, nnz, cooRowInd, cooColInd, cooValues, hipsparse::hipIndexTypeToHCCIndexType(cooIdxType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseCreateBlockedEll(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t ellBlockSize, int64_t ellCols, void* ellColInd, void* ellValue, hipsparseIndexType_t ellIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_bell_descr(spMatDescr[0]->get_spmat_descr_reference(), rows, cols, rocsparse_direction_column, ellBlockSize, ellCols, ellColInd, ellValue, hipsparse::hipIndexTypeToHCCIndexType(ellIdxType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseCreateConstBlockedEll(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t ellBlockSize, int64_t ellCols, const void* ellColInd, const void* ellValue, hipsparseIndexType_t ellIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_const_bell_descr(spMatDescr[0]->get_const_spmat_descr_reference(), rows, cols, rocsparse_direction_column, ellBlockSize, ellCols, ellColInd, ellValue, hipsparse::hipIndexTypeToHCCIndexType(ellIdxType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseCreateCooAoS(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cooInd, void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_coo_aos_descr(spMatDescr[0]->get_spmat_descr_reference(), rows, cols, nnz, cooInd, cooValues, hipsparse::hipIndexTypeToHCCIndexType(cooIdxType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } #ifdef __cplusplus extern "C" { #endif ROCSPARSE_EXPORT rocsparse_status rocsparse_create_csr_descr_SWDEV_453599(rocsparse_spmat_descr* descr, int64_t rows, int64_t cols, int64_t nnz, void* csrRowPtr, void* csrColInd, void* csrVal, rocsparse_indextype row_ptr_type, rocsparse_indextype col_ind_type, rocsparse_index_base idx_base, rocsparse_datatype data_type); #ifdef __cplusplus } #endif hipsparseStatus_t hipsparseCreateCsr(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* csrRowOffsets, void* csrColInd, void* csrValues, hipsparseIndexType_t csrRowOffsetsType, hipsparseIndexType_t csrColIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_create_csr_descr_SWDEV_453599( spMatDescr[0]->get_spmat_descr_reference(), rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, hipsparse::hipIndexTypeToHCCIndexType(csrRowOffsetsType), hipsparse::hipIndexTypeToHCCIndexType(csrColIndType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseCreateConstCsr(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* csrRowOffsets, const void* csrColInd, const void* csrValues, hipsparseIndexType_t csrRowOffsetsType, hipsparseIndexType_t csrColIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_const_csr_descr(spMatDescr[0]->get_const_spmat_descr_reference(), rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, hipsparse::hipIndexTypeToHCCIndexType(csrRowOffsetsType), hipsparse::hipIndexTypeToHCCIndexType(csrColIndType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseCreateCsc(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cscColOffsets, void* cscRowInd, void* cscValues, hipsparseIndexType_t cscColOffsetsType, hipsparseIndexType_t cscRowIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_csc_descr(spMatDescr[0]->get_spmat_descr_reference(), rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, hipsparse::hipIndexTypeToHCCIndexType(cscColOffsetsType), hipsparse::hipIndexTypeToHCCIndexType(cscRowIndType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseCreateConstCsc(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* cscColOffsets, const void* cscRowInd, const void* cscValues, hipsparseIndexType_t cscColOffsetsType, hipsparseIndexType_t cscRowIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { if(spMatDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } spMatDescr[0] = new hipsparseSpMatDescr_st(); hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_const_csc_descr(spMatDescr[0]->get_const_spmat_descr_reference(), rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, hipsparse::hipIndexTypeToHCCIndexType(cscColOffsetsType), hipsparse::hipIndexTypeToHCCIndexType(cscRowIndType), hipsparse::hipBaseToHCCBase(idxBase), hipsparse::hipDataTypeToHCCDataType(valueType))); if(status != HIPSPARSE_STATUS_SUCCESS) { delete spMatDescr[0]; } return status; } hipsparseStatus_t hipsparseDestroySpMat(hipsparseConstSpMatDescr_t spMatDescr) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_destroy_spmat_descr(to_rocsparse_const_spmat_descr(spMatDescr))); delete spMatDescr; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseBlockedEllGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* ellBlockSize, int64_t* ellCols, void** ellColInd, void** ellValue, hipsparseIndexType_t* ellIdxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; rocsparse_direction hcc_block_direction; RETURN_IF_ROCSPARSE_ERROR(rocsparse_bell_get(to_rocsparse_spmat_descr(spMatDescr), rows, cols, &hcc_block_direction, ellBlockSize, ellCols, ellColInd, ellValue, ellIdxType != nullptr ? &hcc_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *ellIdxType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseConstBlockedEllGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* ellBlockSize, int64_t* ellCols, const void** ellColInd, const void** ellValue, hipsparseIndexType_t* ellIdxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; rocsparse_direction hcc_block_direction; RETURN_IF_ROCSPARSE_ERROR( rocsparse_const_bell_get(to_rocsparse_const_spmat_descr(spMatDescr), rows, cols, &hcc_block_direction, ellBlockSize, ellCols, ellColInd, ellValue, ellIdxType != nullptr ? &hcc_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *ellIdxType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCooGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cooRowInd, void** cooColInd, void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR(rocsparse_coo_get(to_rocsparse_spmat_descr(spMatDescr), rows, cols, nnz, cooRowInd, cooColInd, cooValues, idxType != nullptr ? &hcc_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *idxType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseConstCooGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** cooRowInd, const void** cooColInd, const void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_const_coo_get(to_rocsparse_const_spmat_descr(spMatDescr), rows, cols, nnz, cooRowInd, cooColInd, cooValues, idxType != nullptr ? &hcc_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *idxType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCooAoSGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cooInd, void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_coo_aos_get(to_rocsparse_spmat_descr(spMatDescr), rows, cols, nnz, cooInd, cooValues, idxType != nullptr ? &hcc_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *idxType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCsrGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** csrRowOffsets, void** csrColInd, void** csrValues, hipsparseIndexType_t* csrRowOffsetsType, hipsparseIndexType_t* csrColIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_row_index_type; rocsparse_indextype hcc_col_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_csr_get(to_rocsparse_spmat_descr(spMatDescr), rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, csrRowOffsetsType != nullptr ? &hcc_row_index_type : nullptr, csrColIndType != nullptr ? &hcc_col_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *csrRowOffsetsType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_row_index_type); *csrColIndType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_col_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseConstCsrGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** csrRowOffsets, const void** csrColInd, const void** csrValues, hipsparseIndexType_t* csrRowOffsetsType, hipsparseIndexType_t* csrColIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_row_index_type; rocsparse_indextype hcc_col_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_const_csr_get(to_rocsparse_const_spmat_descr(spMatDescr), rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, csrRowOffsetsType != nullptr ? &hcc_row_index_type : nullptr, csrColIndType != nullptr ? &hcc_col_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *csrRowOffsetsType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_row_index_type); *csrColIndType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_col_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCsrSetPointers(hipsparseSpMatDescr_t spMatDescr, void* csrRowOffsets, void* csrColInd, void* csrValues) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_csr_set_pointers( to_rocsparse_spmat_descr(spMatDescr), csrRowOffsets, csrColInd, csrValues)); } hipsparseStatus_t hipsparseCscGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cscColOffsets, void** cscRowInd, void** cscValues, hipsparseIndexType_t* cscColOffsetsType, hipsparseIndexType_t* cscRowIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_col_index_type; rocsparse_indextype hcc_row_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_csc_get(to_rocsparse_spmat_descr(spMatDescr), rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, cscColOffsetsType != nullptr ? &hcc_col_index_type : nullptr, cscRowIndType != nullptr ? &hcc_row_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *cscColOffsetsType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_col_index_type); *cscRowIndType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_row_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseConstCscGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** cscColOffsets, const void** cscRowInd, const void** cscValues, hipsparseIndexType_t* cscColOffsetsType, hipsparseIndexType_t* cscRowIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { rocsparse_indextype hcc_col_index_type; rocsparse_indextype hcc_row_index_type; rocsparse_index_base hcc_index_base; rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_const_csc_get(to_rocsparse_const_spmat_descr(spMatDescr), rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, cscColOffsetsType != nullptr ? &hcc_col_index_type : nullptr, cscRowIndType != nullptr ? &hcc_row_index_type : nullptr, idxBase != nullptr ? &hcc_index_base : nullptr, valueType != nullptr ? &hcc_data_type : nullptr)); *cscColOffsetsType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_col_index_type); *cscRowIndType = hipsparse::HCCIndexTypeToHIPIndexType(hcc_row_index_type); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCscSetPointers(hipsparseSpMatDescr_t spMatDescr, void* cscColOffsets, void* cscRowInd, void* cscValues) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_csc_set_pointers( to_rocsparse_spmat_descr(spMatDescr), cscColOffsets, cscRowInd, cscValues)); } hipsparseStatus_t hipsparseCooSetPointers(hipsparseSpMatDescr_t spMatDescr, void* cooRowInd, void* cooColInd, void* cooValues) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_coo_set_pointers( to_rocsparse_spmat_descr(spMatDescr), cooRowInd, cooColInd, cooValues)); } hipsparseStatus_t hipsparseSpMatGetSize(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmat_get_size(to_rocsparse_const_spmat_descr(spMatDescr), rows, cols, nnz)); } hipsparseStatus_t hipsparseSpMatGetFormat(hipsparseConstSpMatDescr_t spMatDescr, hipsparseFormat_t* format) { rocsparse_format hcc_format; RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmat_get_format( to_rocsparse_const_spmat_descr(spMatDescr), format != nullptr ? &hcc_format : nullptr)); *format = hipsparse::HCCFormatToHIPFormat(hcc_format); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpMatGetIndexBase(hipsparseConstSpMatDescr_t spMatDescr, hipsparseIndexBase_t* idxBase) { rocsparse_index_base hcc_index_base; RETURN_IF_ROCSPARSE_ERROR( rocsparse_spmat_get_index_base(to_rocsparse_const_spmat_descr(spMatDescr), idxBase != nullptr ? &hcc_index_base : nullptr)); *idxBase = hipsparse::HCCBaseToHIPBase(hcc_index_base); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpMatGetValues(hipsparseSpMatDescr_t spMatDescr, void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmat_get_values(to_rocsparse_spmat_descr(spMatDescr), values)); } hipsparseStatus_t hipsparseConstSpMatGetValues(hipsparseConstSpMatDescr_t spMatDescr, const void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_const_spmat_get_values(to_rocsparse_const_spmat_descr(spMatDescr), values)); } hipsparseStatus_t hipsparseSpMatSetValues(hipsparseSpMatDescr_t spMatDescr, void* values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmat_set_values(to_rocsparse_spmat_descr(spMatDescr), values)); } hipsparseStatus_t hipsparseSpMatGetStridedBatch(hipsparseConstSpMatDescr_t spMatDescr, int* batchCount) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmat_get_strided_batch(to_rocsparse_const_spmat_descr(spMatDescr), batchCount)); } hipsparseStatus_t hipsparseSpMatSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmat_set_strided_batch(to_rocsparse_spmat_descr(spMatDescr), batchCount)); } hipsparseStatus_t hipsparseCooSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount, int64_t batchStride) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_coo_set_strided_batch( to_rocsparse_spmat_descr(spMatDescr), batchCount, batchStride)); } hipsparseStatus_t hipsparseCsrSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount, int64_t offsetsBatchStride, int64_t columnsValuesBatchStride) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_csr_set_strided_batch(to_rocsparse_spmat_descr(spMatDescr), batchCount, offsetsBatchStride, columnsValuesBatchStride)); } hipsparseStatus_t hipsparseSpMatGetAttribute(hipsparseConstSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, void* data, size_t dataSize) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmat_get_attribute(to_rocsparse_const_spmat_descr(spMatDescr), (rocsparse_spmat_attribute)attribute, data, dataSize)); } hipsparseStatus_t hipsparseSpMatSetAttribute(hipsparseSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, const void* data, size_t dataSize) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmat_set_attribute(to_rocsparse_spmat_descr(spMatDescr), (rocsparse_spmat_attribute)attribute, data, dataSize)); } hipsparseStatus_t hipsparseCreateDnVec(hipsparseDnVecDescr_t* dnVecDescr, int64_t size, void* values, hipDataType valueType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_dnvec_descr((rocsparse_dnvec_descr*)dnVecDescr, size, values, hipsparse::hipDataTypeToHCCDataType(valueType))); } hipsparseStatus_t hipsparseCreateConstDnVec(hipsparseConstDnVecDescr_t* dnVecDescr, int64_t size, const void* values, hipDataType valueType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_const_dnvec_descr((rocsparse_const_dnvec_descr*)dnVecDescr, size, values, hipsparse::hipDataTypeToHCCDataType(valueType))); } hipsparseStatus_t hipsparseDestroyDnVec(hipsparseConstDnVecDescr_t dnVecDescr) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_dnvec_descr((rocsparse_const_dnvec_descr)dnVecDescr)); } hipsparseStatus_t hipsparseDnVecGet(const hipsparseDnVecDescr_t dnVecDescr, int64_t* size, void** values, hipDataType* valueType) { rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR(rocsparse_dnvec_get((const rocsparse_dnvec_descr)dnVecDescr, size, values, valueType != nullptr ? &hcc_data_type : nullptr)); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseConstDnVecGet(hipsparseConstDnVecDescr_t dnVecDescr, int64_t* size, const void** values, hipDataType* valueType) { rocsparse_datatype hcc_data_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_const_dnvec_get((const rocsparse_const_dnvec_descr)dnVecDescr, size, values, valueType != nullptr ? &hcc_data_type : nullptr)); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDnVecGetValues(const hipsparseDnVecDescr_t dnVecDescr, void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dnvec_get_values((const rocsparse_dnvec_descr)dnVecDescr, values)); } hipsparseStatus_t hipsparseConstDnVecGetValues(hipsparseConstDnVecDescr_t dnVecDescr, const void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_const_dnvec_get_values((const rocsparse_const_dnvec_descr)dnVecDescr, values)); } hipsparseStatus_t hipsparseDnVecSetValues(hipsparseDnVecDescr_t dnVecDescr, void* values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dnvec_set_values((rocsparse_dnvec_descr)dnVecDescr, values)); } hipsparseStatus_t hipsparseCreateDnMat(hipsparseDnMatDescr_t* dnMatDescr, int64_t rows, int64_t cols, int64_t ld, void* values, hipDataType valueType, hipsparseOrder_t order) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_dnmat_descr((rocsparse_dnmat_descr*)dnMatDescr, rows, cols, ld, values, hipsparse::hipDataTypeToHCCDataType(valueType), hipsparse::hipOrderToHCCOrder(order))); } hipsparseStatus_t hipsparseCreateConstDnMat(hipsparseConstDnMatDescr_t* dnMatDescr, int64_t rows, int64_t cols, int64_t ld, const void* values, hipDataType valueType, hipsparseOrder_t order) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_const_dnmat_descr((rocsparse_const_dnmat_descr*)dnMatDescr, rows, cols, ld, values, hipsparse::hipDataTypeToHCCDataType(valueType), hipsparse::hipOrderToHCCOrder(order))); } hipsparseStatus_t hipsparseDestroyDnMat(hipsparseConstDnMatDescr_t dnMatDescr) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_dnmat_descr((rocsparse_const_dnmat_descr)dnMatDescr)); } hipsparseStatus_t hipsparseDnMatGet(const hipsparseDnMatDescr_t dnMatDescr, int64_t* rows, int64_t* cols, int64_t* ld, void** values, hipDataType* valueType, hipsparseOrder_t* order) { rocsparse_datatype hcc_data_type; rocsparse_order hcc_order; RETURN_IF_ROCSPARSE_ERROR(rocsparse_dnmat_get((const rocsparse_dnmat_descr)dnMatDescr, rows, cols, ld, values, valueType != nullptr ? &hcc_data_type : nullptr, order != nullptr ? &hcc_order : nullptr)); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); *order = hipsparse::HCCOrderToHIPOrder(hcc_order); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseConstDnMatGet(hipsparseConstDnMatDescr_t dnMatDescr, int64_t* rows, int64_t* cols, int64_t* ld, const void** values, hipDataType* valueType, hipsparseOrder_t* order) { rocsparse_datatype hcc_data_type; rocsparse_order hcc_order; RETURN_IF_ROCSPARSE_ERROR( rocsparse_const_dnmat_get((rocsparse_const_dnmat_descr)dnMatDescr, rows, cols, ld, values, valueType != nullptr ? &hcc_data_type : nullptr, order != nullptr ? &hcc_order : nullptr)); *valueType = hipsparse::HCCDataTypeToHIPDataType(hcc_data_type); *order = hipsparse::HCCOrderToHIPOrder(hcc_order); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDnMatGetValues(const hipsparseDnMatDescr_t dnMatDescr, void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dnmat_get_values((const rocsparse_dnmat_descr)dnMatDescr, values)); } hipsparseStatus_t hipsparseConstDnMatGetValues(hipsparseConstDnMatDescr_t dnMatDescr, const void** values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_const_dnmat_get_values((rocsparse_const_dnmat_descr)dnMatDescr, values)); } hipsparseStatus_t hipsparseDnMatSetValues(hipsparseDnMatDescr_t dnMatDescr, void* values) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dnmat_set_values((rocsparse_dnmat_descr)dnMatDescr, values)); } hipsparseStatus_t hipsparseDnMatGetStridedBatch(hipsparseConstDnMatDescr_t dnMatDescr, int* batchCount, int64_t* batchStride) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dnmat_get_strided_batch( (rocsparse_const_dnmat_descr)dnMatDescr, batchCount, batchStride)); } hipsparseStatus_t hipsparseDnMatSetStridedBatch(hipsparseDnMatDescr_t dnMatDescr, int batchCount, int64_t batchStride) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dnmat_set_strided_batch( (const rocsparse_dnmat_descr)dnMatDescr, batchCount, batchStride)); } ./library/src/amd_detail/conversion/0000775000175100017510000000000015176134511017612 5ustar jenkinsjenkins./library/src/amd_detail/conversion/hipsparse_nnz_compress.cpp0000664000175100017510000001424415176134305025122 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, float tol) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_snnz_compress((rocsparse_handle)handle, m, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, double tol) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dnnz_compress((rocsparse_handle)handle, m, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipComplex tol) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cnnz_compress((rocsparse_handle)handle, m, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrValA, csrRowPtrA, nnzPerRow, nnzC, {hipCrealf(tol), hipCimagf(tol)})); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipDoubleComplex tol) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_znnz_compress((rocsparse_handle)handle, m, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrValA, csrRowPtrA, nnzPerRow, nnzC, {hipCreal(tol), hipCimag(tol)})); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_nnz.cpp0000664000175100017510000001427415176134305023212 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_snnz((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dnnz((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cnnz((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_znnz((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_csr2bsr.cpp0000664000175100017510000002436215176134305023764 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, int* bsrRowPtrC, int* bsrNnzb) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_csr2bsr_nnz((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, csrRowPtrA, csrColIndA, blockDim, (const rocsparse_mat_descr)descrC, bsrRowPtrC, bsrNnzb)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsr2bsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, (const rocsparse_mat_descr)descrC, bsrValC, bsrRowPtrC, bsrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsr2bsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, (const rocsparse_mat_descr)descrC, bsrValC, bsrRowPtrC, bsrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_ccsr2bsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrValA, csrRowPtrA, csrColIndA, blockDim, (const rocsparse_mat_descr)descrC, (rocsparse_float_complex*)bsrValC, bsrRowPtrC, bsrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zcsr2bsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), m, n, (const rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrValA, csrRowPtrA, csrColIndA, blockDim, (const rocsparse_mat_descr)descrC, (rocsparse_double_complex*)bsrValC, bsrRowPtrC, bsrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_coo2csr.cpp0000664000175100017510000000415715176134305023756 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcoo2csr(hipsparseHandle_t handle, const int* cooRowInd, int nnz, int m, int* csrRowPtr, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_coo2csr((rocsparse_handle)handle, cooRowInd, nnz, m, csrRowPtr, hipsparse::hipBaseToHCCBase(idxBase))); } ./library/src/amd_detail/conversion/hipsparse_csr2coo.cpp0000664000175100017510000000415715176134305023756 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsr2coo(hipsparseHandle_t handle, const int* csrRowPtr, int nnz, int m, int* cooRowInd, hipsparseIndexBase_t idxBase) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_csr2coo((rocsparse_handle)handle, csrRowPtr, nnz, m, cooRowInd, hipsparse::hipBaseToHCCBase(idxBase))); } ./library/src/amd_detail/conversion/hipsparse_gebsr2gebsr.cpp0000664000175100017510000005635615176134305024623 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { size_t bufSize; RETURN_IF_ROCSPARSE_ERROR( rocsparse_sgebsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes != nullptr ? &bufSize : nullptr)); if(pBufferSizeInBytes != nullptr) { *pBufferSizeInBytes = bufSize; } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { size_t bufSize; RETURN_IF_ROCSPARSE_ERROR( rocsparse_dgebsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes != nullptr ? &bufSize : nullptr)); if(pBufferSizeInBytes != nullptr) { *pBufferSizeInBytes = bufSize; } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { size_t bufSize; RETURN_IF_ROCSPARSE_ERROR( rocsparse_cgebsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes != nullptr ? &bufSize : nullptr)); if(pBufferSizeInBytes != nullptr) { *pBufferSizeInBytes = bufSize; } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { size_t bufSize; RETURN_IF_ROCSPARSE_ERROR( rocsparse_zgebsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes != nullptr ? &bufSize : nullptr)); if(pBufferSizeInBytes != nullptr) { *pBufferSizeInBytes = bufSize; } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseXgebsr2gebsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, int* bsrRowPtrC, int rowBlockDimC, int colBlockDimC, int* nnzTotalDevHostPtr, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_gebsr2gebsr_nnz((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const rocsparse_mat_descr)descrC, bsrRowPtrC, rowBlockDimC, colBlockDimC, nnzTotalDevHostPtr, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sgebsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const rocsparse_mat_descr)descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dgebsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const rocsparse_mat_descr)descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cgebsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const rocsparse_mat_descr)descrC, (rocsparse_float_complex*)bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zgebsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, nnzb, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const rocsparse_mat_descr)descrC, (rocsparse_double_complex*)bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_prune_csr2csr.cpp0000664000175100017510000004126515176134511025176 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr_nnz((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr_nnz((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer)); } hipsparseStatus_t hipsparseSpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, buffer)); } ./library/src/amd_detail/conversion/hipsparse_cscsort.cpp0000664000175100017510000000665715176134305024073 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcscsort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* cscColPtr, const int* cscRowInd, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_cscsort_buffer_size( (rocsparse_handle)handle, m, n, nnz, cscColPtr, cscRowInd, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcscsort(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, const int* cscColPtr, int* cscRowInd, int* P, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_cscsort((rocsparse_handle)handle, m, n, nnz, (rocsparse_mat_descr)descrA, cscColPtr, cscRowInd, P, pBuffer)); } ./library/src/amd_detail/conversion/hipsparse_hyb2csr.cpp0000664000175100017510000001713015176134305023753 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseShyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, float* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR(rocsparse_hyb2csr_buffer_size((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, csrSortedRowPtrA, &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Format conversion hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_shyb2csr((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } hipsparseStatus_t hipsparseDhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, double* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR(rocsparse_hyb2csr_buffer_size((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, csrSortedRowPtrA, &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Format conversion hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dhyb2csr((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } hipsparseStatus_t hipsparseChyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipComplex* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR(rocsparse_hyb2csr_buffer_size((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, csrSortedRowPtrA, &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Format conversion hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_chyb2csr((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, (rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } hipsparseStatus_t hipsparseZhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipDoubleComplex* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR(rocsparse_hyb2csr_buffer_size((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, csrSortedRowPtrA, &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Format conversion hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zhyb2csr((rocsparse_handle)handle, (const rocsparse_mat_descr)descrA, (const rocsparse_hyb_mat)hybA, (rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } ./library/src/amd_detail/conversion/hipsparse_csc2dense.cpp0000664000175100017510000001461515176134305024255 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* cscVal, const int* cscRowInd, const int* cscColPtr, float* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsc2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, cscVal, cscColPtr, cscRowInd, A, ld)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* cscVal, const int* cscRowInd, const int* cscColPtr, double* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsc2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, cscVal, cscColPtr, cscRowInd, A, ld)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipComplex* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_ccsc2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_float_complex*)cscVal, cscColPtr, cscRowInd, (rocsparse_float_complex*)A, ld)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipDoubleComplex* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zcsc2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_double_complex*)cscVal, cscColPtr, cscRowInd, (rocsparse_double_complex*)A, ld)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_bsr2csr.cpp0000664000175100017510000002125115176134305023756 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sbsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dbsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cbsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const rocsparse_mat_descr)descrC, (rocsparse_float_complex*)csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zbsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const rocsparse_mat_descr)descrC, (rocsparse_double_complex*)csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_csr2gebsr.cpp0000664000175100017510000004460315176134305024300 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_scsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_dcsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_ccsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, (const rocsparse_float_complex*)csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_zcsr2gebsr_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, (const rocsparse_double_complex*)csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseXcsr2gebsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, int* bsrRowPtr, int rowBlockDim, int colBlockDim, int* bsrNnzDevhost, void* pbuffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_csr2gebsr_nnz((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, csrRowPtr, csrColInd, (const rocsparse_mat_descr)bsr_descr, bsrRowPtr, rowBlockDim, colBlockDim, bsrNnzDevhost, pbuffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, float* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, csrVal, csrRowPtr, csrColInd, (const rocsparse_mat_descr)bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, double* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, csrVal, csrRowPtr, csrColInd, (const rocsparse_mat_descr)bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_ccsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, (const rocsparse_float_complex*)csrVal, csrRowPtr, csrColInd, (const rocsparse_mat_descr)bsr_descr, (rocsparse_float_complex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipDoubleComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zcsr2gebsr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), m, n, (const rocsparse_mat_descr)csr_descr, (const rocsparse_double_complex*)csrVal, csrRowPtr, csrColInd, (const rocsparse_mat_descr)bsr_descr, (rocsparse_double_complex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_csr2csr_compress.cpp0000664000175100017510000002045115176134305025673 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, float* csrValC, int* csrColIndC, int* csrRowPtrC, float tol) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsr2csr_compress((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, nnzA, nnzPerRow, csrValC, csrRowPtrC, csrColIndC, tol)); } hipsparseStatus_t hipsparseDcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, double* csrValC, int* csrColIndC, int* csrRowPtrC, double tol) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsr2csr_compress((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, nnzA, nnzPerRow, csrValC, csrRowPtrC, csrColIndC, tol)); } hipsparseStatus_t hipsparseCcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipComplex tol) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsr2csr_compress((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrValA, csrRowPtrA, csrColIndA, nnzA, nnzPerRow, (rocsparse_float_complex*)csrValC, csrRowPtrC, csrColIndC, {hipCrealf(tol), hipCimagf(tol)})); } hipsparseStatus_t hipsparseZcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipDoubleComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipDoubleComplex tol) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsr2csr_compress((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrValA, csrRowPtrA, csrColIndA, nnzA, nnzPerRow, (rocsparse_double_complex*)csrValC, csrRowPtrC, csrColIndC, {hipCreal(tol), hipCimag(tol)})); } ./library/src/amd_detail/conversion/hipsparse_create_identity_permutation.cpp0000664000175100017510000000323415176134305030202 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseCreateIdentityPermutation(hipsparseHandle_t handle, int n, int* p) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_identity_permutation((rocsparse_handle)handle, n, p)); } ./library/src/amd_detail/conversion/hipsparse_csr2csru.cpp0000664000175100017510000002767215176134305024161 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" // csru2csr struct - to hold permutation array struct csru2csrInfo { int size = 0; int* P = nullptr; }; hipsparseStatus_t hipsparseScsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Check for valid permutation array if(info->P == nullptr || info->size != nnz) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Unsort CSR column indices based on the given permutation RETURN_IF_ROCSPARSE_ERROR(rocsparse_isctr((rocsparse_handle)handle, nnz, csrColInd, info->P, (int*)pBuffer, rocsparse_index_base_zero)); // Copy unsorted column indices back to csrColInd RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrColInd, pBuffer, sizeof(int) * nnz, hipMemcpyDeviceToDevice, stream)); // Unsort CSR values based on the given permutation RETURN_IF_HIPSPARSE_ERROR( hipsparseSsctr(handle, nnz, csrVal, info->P, (float*)pBuffer, HIPSPARSE_INDEX_BASE_ZERO)); // Copy unsorted values back to csrVal RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrVal, pBuffer, sizeof(float) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Check for valid permutation array if(info->P == nullptr || info->size != nnz) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Unsort CSR column indices based on the given permutation RETURN_IF_ROCSPARSE_ERROR(rocsparse_isctr((rocsparse_handle)handle, nnz, csrColInd, info->P, (int*)pBuffer, rocsparse_index_base_zero)); // Copy unsorted column indices back to csrColInd RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrColInd, pBuffer, sizeof(int) * nnz, hipMemcpyDeviceToDevice, stream)); // Unsort CSR values based on the given permutation RETURN_IF_HIPSPARSE_ERROR( hipsparseDsctr(handle, nnz, csrVal, info->P, (double*)pBuffer, HIPSPARSE_INDEX_BASE_ZERO)); // Copy unsorted values back to csrVal RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrVal, pBuffer, sizeof(double) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Check for valid permutation array if(info->P == nullptr || info->size != nnz) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Unsort CSR column indices based on the given permutation RETURN_IF_ROCSPARSE_ERROR(rocsparse_isctr((rocsparse_handle)handle, nnz, csrColInd, info->P, (int*)pBuffer, rocsparse_index_base_zero)); // Copy unsorted column indices back to csrColInd RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrColInd, pBuffer, sizeof(int) * nnz, hipMemcpyDeviceToDevice, stream)); // Unsort CSR values based on the given permutation RETURN_IF_HIPSPARSE_ERROR(hipsparseCsctr( handle, nnz, csrVal, info->P, (hipComplex*)pBuffer, HIPSPARSE_INDEX_BASE_ZERO)); // Copy unsorted values back to csrVal RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrVal, pBuffer, sizeof(hipComplex) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Check for valid permutation array if(info->P == nullptr || info->size != nnz) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Unsort CSR column indices based on the given permutation RETURN_IF_ROCSPARSE_ERROR(rocsparse_isctr((rocsparse_handle)handle, nnz, csrColInd, info->P, (int*)pBuffer, rocsparse_index_base_zero)); // Copy unsorted column indices back to csrColInd RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrColInd, pBuffer, sizeof(int) * nnz, hipMemcpyDeviceToDevice, stream)); // Unsort CSR values based on the given permutation RETURN_IF_HIPSPARSE_ERROR(hipsparseZsctr( handle, nnz, csrVal, info->P, (hipDoubleComplex*)pBuffer, HIPSPARSE_INDEX_BASE_ZERO)); // Copy unsorted values back to csrVal RETURN_IF_HIP_ERROR(hipMemcpyAsync( csrVal, pBuffer, sizeof(hipDoubleComplex) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_prune_csr2csr_by_percentage.cpp0000664000175100017510000005052215176134511030061 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr_nnz_by_percentage((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrRowPtrC, nnzTotalDevHostPtr, (rocsparse_mat_info)info, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr_nnz_by_percentage((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrRowPtrC, nnzTotalDevHostPtr, (rocsparse_mat_info)info, buffer)); } hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sprune_csr2csr_by_percentage((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dprune_csr2csr_by_percentage((rocsparse_handle)handle, m, n, nnzA, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, buffer)); } ./library/src/amd_detail/conversion/hipsparse_csru2csr.cpp0000664000175100017510000005025415176134305024151 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #include // csru2csr struct - to hold permutation array struct csru2csrInfo { int size = 0; int* P = nullptr; }; hipsparseStatus_t hipsparseCreateCsru2csrInfo(csru2csrInfo_t* info) { if(info == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } *info = new csru2csrInfo; // Initialize permutation array with nullptr (*info)->size = 0; (*info)->P = nullptr; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDestroyCsru2csrInfo(csru2csrInfo_t info) { // Check if info structure has been created if(info != nullptr) { // Check if permutation array is allocated if(info->P != nullptr) { RETURN_IF_HIP_ERROR(hipFree(info->P)); info->size = 0; } delete info; } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 and pBufferSizeInBytes must be valid if(nnz != 0 || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Determine required buffer size for CSR sort RETURN_IF_HIPSPARSE_ERROR(hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csrRowPtr, csrColInd, pBufferSizeInBytes)); // We need a buffer of at least nnz * sizeof(float) size_t min_size = nnz * sizeof(float); *pBufferSizeInBytes = std::max(*pBufferSizeInBytes, min_size); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 and pBufferSizeInBytes must be valid if(nnz != 0 || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Determine required buffer size for CSR sort RETURN_IF_HIPSPARSE_ERROR(hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csrRowPtr, csrColInd, pBufferSizeInBytes)); // We need a buffer of at least nnz * sizeof(double) size_t min_size = nnz * sizeof(double); *pBufferSizeInBytes = std::max(*pBufferSizeInBytes, min_size); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 and pBufferSizeInBytes must be valid if(nnz != 0 || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Determine required buffer size for CSR sort RETURN_IF_HIPSPARSE_ERROR(hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csrRowPtr, csrColInd, pBufferSizeInBytes)); // We need a buffer of at least nnz * sizeof(hipComplex) size_t min_size = nnz * sizeof(hipComplex); *pBufferSizeInBytes = std::max(*pBufferSizeInBytes, min_size); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 and pBufferSizeInBytes must be valid if(nnz != 0 || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Determine required buffer size for CSR sort RETURN_IF_HIPSPARSE_ERROR(hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csrRowPtr, csrColInd, pBufferSizeInBytes)); // We need a buffer of at least nnz * sizeof(hipDoubleComplex) size_t min_size = nnz * sizeof(hipDoubleComplex); *pBufferSizeInBytes = std::max(*pBufferSizeInBytes, min_size); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // De-allocate permutation array, if already allocated but sizes do not match if(info->P != nullptr && info->size != nnz) { RETURN_IF_HIP_ERROR(hipFree(info->P)); info->size = 0; } // Allocate memory inside info structure to keep track of the permutation // if it has not yet been allocated with matching size if(info->P == nullptr) { // size must be 0 assert(info->size == 0); RETURN_IF_HIP_ERROR(hipMalloc((void**)&info->P, sizeof(int) * nnz)); info->size = nnz; } // Initialize permutation with identity RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, info->P)); // Sort CSR columns RETURN_IF_HIPSPARSE_ERROR( hipsparseXcsrsort(handle, m, n, nnz, descrA, csrRowPtr, csrColInd, info->P, pBuffer)); // Sort CSR values RETURN_IF_HIPSPARSE_ERROR( hipsparseSgthr(handle, nnz, csrVal, (float*)pBuffer, info->P, HIPSPARSE_INDEX_BASE_ZERO)); // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Copy sorted values back to csrVal RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrVal, pBuffer, sizeof(float) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // De-allocate permutation array, if already allocated but sizes do not match if(info->P != nullptr && info->size != nnz) { RETURN_IF_HIP_ERROR(hipFree(info->P)); info->size = 0; } // Allocate memory inside info structure to keep track of the permutation // if it has not yet been allocated with matching size if(info->P == nullptr) { // size must be 0 assert(info->size == 0); RETURN_IF_HIP_ERROR(hipMalloc((void**)&info->P, sizeof(int) * nnz)); info->size = nnz; } // Initialize permutation with identity RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, info->P)); // Sort CSR columns RETURN_IF_HIPSPARSE_ERROR( hipsparseXcsrsort(handle, m, n, nnz, descrA, csrRowPtr, csrColInd, info->P, pBuffer)); // Sort CSR values RETURN_IF_HIPSPARSE_ERROR( hipsparseDgthr(handle, nnz, csrVal, (double*)pBuffer, info->P, HIPSPARSE_INDEX_BASE_ZERO)); // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Copy sorted values back to csrVal RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrVal, pBuffer, sizeof(double) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // De-allocate permutation array, if already allocated but sizes do not match if(info->P != nullptr && info->size != nnz) { RETURN_IF_HIP_ERROR(hipFree(info->P)); info->size = 0; } // Allocate memory inside info structure to keep track of the permutation // if it has not yet been allocated with matching size if(info->P == nullptr) { // size must be 0 assert(info->size == 0); RETURN_IF_HIP_ERROR(hipMalloc((void**)&info->P, sizeof(int) * nnz)); info->size = nnz; } // Initialize permutation with identity RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, info->P)); // Sort CSR columns RETURN_IF_HIPSPARSE_ERROR( hipsparseXcsrsort(handle, m, n, nnz, descrA, csrRowPtr, csrColInd, info->P, pBuffer)); // Sort CSR values RETURN_IF_HIPSPARSE_ERROR(hipsparseCgthr( handle, nnz, csrVal, (hipComplex*)pBuffer, info->P, HIPSPARSE_INDEX_BASE_ZERO)); // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Copy sorted values back to csrVal RETURN_IF_HIP_ERROR( hipMemcpyAsync(csrVal, pBuffer, sizeof(hipComplex) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { // Test for bad args if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Invalid sizes if(m < 0 || n < 0 || nnz < 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Quick return if(m == 0 || n == 0 || nnz == 0) { // nnz must be 0 if(nnz != 0) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } // Invalid pointers if(descrA == nullptr || csrVal == nullptr || csrRowPtr == nullptr || csrColInd == nullptr || info == nullptr || pBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // De-allocate permutation array, if already allocated but sizes do not match if(info->P != nullptr && info->size != nnz) { RETURN_IF_HIP_ERROR(hipFree(info->P)); info->size = 0; } // Allocate memory inside info structure to keep track of the permutation // if it has not yet been allocated with matching size if(info->P == nullptr) { // size must be 0 assert(info->size == 0); RETURN_IF_HIP_ERROR(hipMalloc((void**)&info->P, sizeof(int) * nnz)); info->size = nnz; } // Initialize permutation with identity RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, info->P)); // Sort CSR columns RETURN_IF_HIPSPARSE_ERROR( hipsparseXcsrsort(handle, m, n, nnz, descrA, csrRowPtr, csrColInd, info->P, pBuffer)); // Sort CSR values RETURN_IF_HIPSPARSE_ERROR(hipsparseZgthr( handle, nnz, csrVal, (hipDoubleComplex*)pBuffer, info->P, HIPSPARSE_INDEX_BASE_ZERO)); // Get stream hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Copy sorted values back to csrVal RETURN_IF_HIP_ERROR(hipMemcpyAsync( csrVal, pBuffer, sizeof(hipDoubleComplex) * nnz, hipMemcpyDeviceToDevice, stream)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_csr2dense.cpp0000664000175100017510000001461515176134305024274 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, float* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsr2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, A, ld)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, double* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsr2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, A, ld)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipComplex* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_ccsr2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_float_complex*)csrVal, csrRowPtr, csrColInd, (rocsparse_float_complex*)A, ld)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipDoubleComplex* A, int ld) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zcsr2dense((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_double_complex*)csrVal, csrRowPtr, csrColInd, (rocsparse_double_complex*)A, ld)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_csrsort.cpp0000664000175100017510000000665715176134305024112 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsrsort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_csrsort_buffer_size( (rocsparse_handle)handle, m, n, nnz, csrRowPtr, csrColInd, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcsrsort(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, const int* csrRowPtr, int* csrColInd, int* P, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_csrsort((rocsparse_handle)handle, m, n, nnz, (rocsparse_mat_descr)descrA, csrRowPtr, csrColInd, P, pBuffer)); } ./library/src/amd_detail/conversion/hipsparse_gebsr2csr.cpp0000664000175100017510000002270515176134305024277 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sgebsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dgebsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cgebsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const rocsparse_mat_descr)descrC, (rocsparse_float_complex*)csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zgebsr2csr((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nb, (const rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const rocsparse_mat_descr)descrC, (rocsparse_double_complex*)csrValC, csrRowPtrC, csrColIndC)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_prune_dense2csr_by_percentage.cpp0000664000175100017510000004116115176134511030367 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_sprune_dense2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, (rocsparse_mat_info)info, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_dprune_dense2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, (rocsparse_mat_info)info, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_sprune_dense2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, (rocsparse_mat_info)info, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_dprune_dense2csr_by_percentage_buffer_size((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, (rocsparse_mat_info)info, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_sprune_dense2csr_nnz_by_percentage((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrRowPtr, nnzTotalDevHostPtr, (rocsparse_mat_info)info, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_dprune_dense2csr_nnz_by_percentage((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrRowPtr, nnzTotalDevHostPtr, (rocsparse_mat_info)info, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_sprune_dense2csr_by_percentage((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, (rocsparse_mat_info)info, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_dprune_dense2csr_by_percentage((rocsparse_handle)handle, m, n, A, lda, percentage, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, (rocsparse_mat_info)info, buffer)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_coosort.cpp0000664000175100017510000000673515176134305024100 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcoosort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* cooRows, const int* cooCols, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_coosort_buffer_size( (rocsparse_handle)handle, m, n, nnz, cooRows, cooCols, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcoosortByRow(hipsparseHandle_t handle, int m, int n, int nnz, int* cooRows, int* cooCols, int* P, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_coosort_by_row( (rocsparse_handle)handle, m, n, nnz, cooRows, cooCols, P, pBuffer)); } hipsparseStatus_t hipsparseXcoosortByColumn(hipsparseHandle_t handle, int m, int n, int nnz, int* cooRows, int* cooCols, int* P, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_coosort_by_column( (rocsparse_handle)handle, m, n, nnz, cooRows, cooCols, P, pBuffer)); } ./library/src/amd_detail/conversion/hipsparse_csr2csc.cpp0000664000175100017510000006124515176134305023747 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const float* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, float* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR( rocsparse_csr2csc_buffer_size((rocsparse_handle)handle, m, n, nnz, csrSortedRowPtr, csrSortedColInd, hipsparse::hipActionToHCCAction(copyValues), &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Obtain stream, to explicitly sync (cusparse csr2csc is blocking) hipStream_t stream; hipsparseStatus_t status = hipsparseGetStream(handle, &stream); if(status != HIPSPARSE_STATUS_SUCCESS) { RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } // Format conversion status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsr2csc((rocsparse_handle)handle, m, n, nnz, csrSortedVal, csrSortedRowPtr, csrSortedColInd, cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return status; } hipsparseStatus_t hipsparseDcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const double* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, double* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR( rocsparse_csr2csc_buffer_size((rocsparse_handle)handle, m, n, nnz, csrSortedRowPtr, csrSortedColInd, hipsparse::hipActionToHCCAction(copyValues), &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Obtain stream, to explicitly sync (cusparse csr2csc is blocking) hipStream_t stream; hipsparseStatus_t status = hipsparseGetStream(handle, &stream); if(status != HIPSPARSE_STATUS_SUCCESS) { RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } // Format conversion status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsr2csc((rocsparse_handle)handle, m, n, nnz, csrSortedVal, csrSortedRowPtr, csrSortedColInd, cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return status; } hipsparseStatus_t hipsparseCcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipComplex* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, hipComplex* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR( rocsparse_csr2csc_buffer_size((rocsparse_handle)handle, m, n, nnz, csrSortedRowPtr, csrSortedColInd, hipsparse::hipActionToHCCAction(copyValues), &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Obtain stream, to explicitly sync (cusparse csr2csc is blocking) hipStream_t stream; hipsparseStatus_t status = hipsparseGetStream(handle, &stream); if(status != HIPSPARSE_STATUS_SUCCESS) { RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } // Format conversion status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsr2csc((rocsparse_handle)handle, m, n, nnz, (const rocsparse_float_complex*)csrSortedVal, csrSortedRowPtr, csrSortedColInd, (rocsparse_float_complex*)cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return status; } hipsparseStatus_t hipsparseZcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipDoubleComplex* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, hipDoubleComplex* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { // Determine buffer size size_t buffer_size = 0; RETURN_IF_ROCSPARSE_ERROR( rocsparse_csr2csc_buffer_size((rocsparse_handle)handle, m, n, nnz, csrSortedRowPtr, csrSortedColInd, hipsparse::hipActionToHCCAction(copyValues), &buffer_size)); // Allocate buffer void* buffer = nullptr; RETURN_IF_HIP_ERROR(hipMalloc(&buffer, buffer_size)); // Obtain stream, to explicitly sync (cusparse csr2csc is blocking) hipStream_t stream; hipsparseStatus_t status = hipsparseGetStream(handle, &stream); if(status != HIPSPARSE_STATUS_SUCCESS) { RETURN_IF_HIP_ERROR(hipFree(buffer)); return status; } // Format conversion status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsr2csc((rocsparse_handle)handle, m, n, nnz, (const rocsparse_double_complex*)csrSortedVal, csrSortedRowPtr, csrSortedColInd, (rocsparse_double_complex*)cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); // Free buffer RETURN_IF_HIP_ERROR(hipFree(buffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return status; } hipsparseStatus_t hipsparseCsr2cscEx2_bufferSize(hipsparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, hipDataType valType, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, hipsparseCsr2CscAlg_t alg, size_t* pBufferSizeInBytes) { switch(valType) { case HIP_R_32F: case HIP_R_64F: case HIP_C_32F: case HIP_C_64F: return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_csr2csc_buffer_size((rocsparse_handle)handle, m, n, nnz, csrRowPtr, csrColInd, hipsparse::hipActionToHCCAction(copyValues), pBufferSizeInBytes)); case HIP_R_8I: { // Build Source rocsparse_const_spmat_descr source; RETURN_IF_ROCSPARSE_ERROR( rocsparse_create_const_csr_descr(&source, m, n, nnz, csrRowPtr, csrColInd, (const int8_t*)csrVal, rocsparse_indextype_i32, rocsparse_indextype_i32, hipsparse::hipBaseToHCCBase(idxBase), rocsparse_datatype_i8_r)); // Build target rocsparse_spmat_descr target; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_csc_descr(&target, m, n, nnz, cscColPtr, cscRowInd, (int8_t*)cscVal, rocsparse_indextype_i32, rocsparse_indextype_i32, hipsparse::hipBaseToHCCBase(idxBase), rocsparse_datatype_i8_r)); // Create descriptor rocsparse_sparse_to_sparse_descr descr; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_sparse_to_sparse_descr( &descr, source, target, rocsparse_sparse_to_sparse_alg_default)); size_t buffer_size_analysis; size_t buffer_size_compute; // Analysis phase RETURN_IF_ROCSPARSE_ERROR( rocsparse_sparse_to_sparse_buffer_size((rocsparse_handle)handle, descr, source, target, rocsparse_sparse_to_sparse_stage_analysis, &buffer_size_analysis)); // Calculation phase RETURN_IF_ROCSPARSE_ERROR( rocsparse_sparse_to_sparse_buffer_size((rocsparse_handle)handle, descr, source, target, rocsparse_sparse_to_sparse_stage_compute, &buffer_size_compute)); *pBufferSizeInBytes = std::max(buffer_size_analysis, buffer_size_compute); RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_spmat_descr(source)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_spmat_descr(target)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_sparse_to_sparse_descr(descr)); return HIPSPARSE_STATUS_SUCCESS; } default: return HIPSPARSE_STATUS_NOT_SUPPORTED; } return HIPSPARSE_STATUS_NOT_SUPPORTED; } hipsparseStatus_t hipsparseCsr2cscEx2(hipsparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, hipDataType valType, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, hipsparseCsr2CscAlg_t alg, void* buffer) { switch(valType) { case HIP_R_32F: return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsr2csc((rocsparse_handle)handle, m, n, nnz, (const float*)csrVal, csrRowPtr, csrColInd, (float*)cscVal, cscRowInd, cscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); case HIP_R_64F: return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsr2csc((rocsparse_handle)handle, m, n, nnz, (const double*)csrVal, csrRowPtr, csrColInd, (double*)cscVal, cscRowInd, cscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); case HIP_C_32F: return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsr2csc((rocsparse_handle)handle, m, n, nnz, (const rocsparse_float_complex*)csrVal, csrRowPtr, csrColInd, (rocsparse_float_complex*)cscVal, cscRowInd, cscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); case HIP_C_64F: return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsr2csc((rocsparse_handle)handle, m, n, nnz, (const rocsparse_double_complex*)csrVal, csrRowPtr, csrColInd, (rocsparse_double_complex*)cscVal, cscRowInd, cscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idxBase), buffer)); case HIP_R_8I: { // Build Source rocsparse_const_spmat_descr source; RETURN_IF_ROCSPARSE_ERROR( rocsparse_create_const_csr_descr(&source, m, n, nnz, csrRowPtr, csrColInd, (const int8_t*)csrVal, rocsparse_indextype_i32, rocsparse_indextype_i32, hipsparse::hipBaseToHCCBase(idxBase), rocsparse_datatype_i8_r)); // Build target rocsparse_spmat_descr target; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_csc_descr(&target, m, n, nnz, cscColPtr, cscRowInd, (int8_t*)cscVal, rocsparse_indextype_i32, rocsparse_indextype_i32, hipsparse::hipBaseToHCCBase(idxBase), rocsparse_datatype_i8_r)); // Create descriptor rocsparse_sparse_to_sparse_descr descr; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_sparse_to_sparse_descr( &descr, source, target, rocsparse_sparse_to_sparse_alg_default)); size_t buffer_size; // Analysis phase RETURN_IF_ROCSPARSE_ERROR( rocsparse_sparse_to_sparse_buffer_size((rocsparse_handle)handle, descr, source, target, rocsparse_sparse_to_sparse_stage_analysis, &buffer_size)); RETURN_IF_ROCSPARSE_ERROR( rocsparse_sparse_to_sparse((rocsparse_handle)handle, descr, source, target, rocsparse_sparse_to_sparse_stage_analysis, buffer_size, buffer)); // Calculation phase RETURN_IF_ROCSPARSE_ERROR( rocsparse_sparse_to_sparse_buffer_size((rocsparse_handle)handle, descr, source, target, rocsparse_sparse_to_sparse_stage_compute, &buffer_size)); RETURN_IF_ROCSPARSE_ERROR( rocsparse_sparse_to_sparse((rocsparse_handle)handle, descr, source, target, rocsparse_sparse_to_sparse_stage_compute, buffer_size, buffer)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_spmat_descr(source)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_spmat_descr(target)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_sparse_to_sparse_descr(descr)); return HIPSPARSE_STATUS_SUCCESS; } default: return HIPSPARSE_STATUS_NOT_SUPPORTED; } return HIPSPARSE_STATUS_NOT_SUPPORTED; } ./library/src/amd_detail/conversion/hipsparse_dense2csr.cpp0000664000175100017510000001566115176134305024276 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerRow, float* csrVal, int* csrRowPtr, int* csrColInd) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sdense2csr((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerRow, double* csrVal, int* csrRowPtr, int* csrColInd) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_ddense2csr((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerRow, hipComplex* csrVal, int* csrRowPtr, int* csrColInd) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cdense2csr((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_float_complex*)A, ld, nnzPerRow, (rocsparse_float_complex*)csrVal, csrRowPtr, csrColInd)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerRow, hipDoubleComplex* csrVal, int* csrRowPtr, int* csrColInd) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zdense2csr((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_double_complex*)A, ld, nnzPerRow, (rocsparse_double_complex*)csrVal, csrRowPtr, csrColInd)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_csr2hyb.cpp0000664000175100017510000001463015176134305023755 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsr2hyb((rocsparse_handle)handle, m, n, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_hyb_mat)hybA, userEllWidth, hipsparse::hipHybPartToHCCHybPart(partitionType))); } hipsparseStatus_t hipsparseDcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsr2hyb((rocsparse_handle)handle, m, n, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_hyb_mat)hybA, userEllWidth, hipsparse::hipHybPartToHCCHybPart(partitionType))); } hipsparseStatus_t hipsparseCcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsr2hyb((rocsparse_handle)handle, m, n, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_hyb_mat)hybA, userEllWidth, hipsparse::hipHybPartToHCCHybPart(partitionType))); } hipsparseStatus_t hipsparseZcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsr2hyb((rocsparse_handle)handle, m, n, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_hyb_mat)hybA, userEllWidth, hipsparse::hipHybPartToHCCHybPart(partitionType))); } ./library/src/amd_detail/conversion/hipsparse_gebsr2gebsc.cpp0000664000175100017510000003757215176134305024603 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sgebsr2gebsc_buffer_size((rocsparse_handle)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dgebsr2gebsc_buffer_size((rocsparse_handle)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_cgebsr2gebsc_buffer_size((rocsparse_handle)handle, mb, nb, nnzb, (const rocsparse_float_complex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_zgebsr2gebsc_buffer_size((rocsparse_handle)handle, mb, nb, nnzb, (const rocsparse_double_complex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, float* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idx_base, void* temp_buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sgebsr2gebsc((rocsparse_handle)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idx_base), temp_buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, double* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idx_base, void* temp_buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dgebsr2gebsc((rocsparse_handle)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idx_base), temp_buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idx_base, void* temp_buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cgebsr2gebsc((rocsparse_handle)handle, mb, nb, nnzb, (const rocsparse_float_complex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, (rocsparse_float_complex*)bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idx_base), temp_buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipDoubleComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idx_base, void* temp_buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zgebsr2gebsc((rocsparse_handle)handle, mb, nb, nnzb, (const rocsparse_double_complex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, (rocsparse_double_complex*)bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToHCCAction(copyValues), hipsparse::hipBaseToHCCBase(idx_base), temp_buffer)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_dense2csc.cpp0000664000175100017510000001571115176134305024253 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerColumn, float* cscVal, int* cscRowInd, int* cscColPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sdense2csc((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, A, ld, nnzPerColumn, cscVal, cscColPtr, cscRowInd)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerColumn, double* cscVal, int* cscRowInd, int* cscColPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_ddense2csc((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, A, ld, nnzPerColumn, cscVal, cscColPtr, cscRowInd)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerColumn, hipComplex* cscVal, int* cscRowInd, int* cscColPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_cdense2csc((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_float_complex*)A, ld, nnzPerColumn, (rocsparse_float_complex*)cscVal, cscColPtr, cscRowInd)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerColumn, hipDoubleComplex* cscVal, int* cscRowInd, int* cscColPtr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_zdense2csc((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descr, (const rocsparse_double_complex*)A, ld, nnzPerColumn, (rocsparse_double_complex*)cscVal, cscColPtr, cscRowInd)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/conversion/hipsparse_prune_dense2csr.cpp0000664000175100017510000003456115176134511025506 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_sprune_dense2csr_buffer_size((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_dprune_dense2csr_buffer_size((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_sprune_dense2csr_buffer_size((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_dprune_dense2csr_buffer_size((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sprune_dense2csr_nnz((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrRowPtr, nnzTotalDevHostPtr, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dprune_dense2csr_nnz((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrRowPtr, nnzTotalDevHostPtr, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpruneDense2csr(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_sprune_dense2csr((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, buffer)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDpruneDense2csr(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_dprune_dense2csr((rocsparse_handle)handle, m, n, A, lda, threshold, (const rocsparse_mat_descr)descr, csrVal, csrRowPtr, csrColInd, buffer)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/precond/0000775000175100017510000000000015176134461017063 5ustar jenkinsjenkins./library/src/amd_detail/precond/hipsparse_gtsv_strided_batch.cpp0000664000175100017510000003252415176134305025512 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const float* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgtsv_no_pivot_strided_batch_buffer_size((rocsparse_handle)handle, m, dummy, dummy, dummy, dummy, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const double* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgtsv_no_pivot_strided_batch_buffer_size((rocsparse_handle)handle, m, dummy, dummy, dummy, dummy, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgtsv_no_pivot_strided_batch_buffer_size((rocsparse_handle)handle, m, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipDoubleComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv_no_pivot_strided_batch_buffer_size((rocsparse_handle)handle, m, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsv2StridedBatch(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, float* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_sgtsv_no_pivot_strided_batch( (rocsparse_handle)handle, m, dl, d, du, x, batchCount, batchStride, pBuffer)); } hipsparseStatus_t hipsparseDgtsv2StridedBatch(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, double* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dgtsv_no_pivot_strided_batch( (rocsparse_handle)handle, m, dl, d, du, x, batchCount, batchStride, pBuffer)); } hipsparseStatus_t hipsparseCgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgtsv_no_pivot_strided_batch((rocsparse_handle)handle, m, (const rocsparse_float_complex*)dl, (const rocsparse_float_complex*)d, (const rocsparse_float_complex*)du, (rocsparse_float_complex*)x, batchCount, batchStride, pBuffer)); } hipsparseStatus_t hipsparseZgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv_no_pivot_strided_batch((rocsparse_handle)handle, m, (const rocsparse_double_complex*)dl, (const rocsparse_double_complex*)d, (const rocsparse_double_complex*)du, (rocsparse_double_complex*)x, batchCount, batchStride, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_gtsv_nopivot.cpp0000664000175100017510000002652515176134305024415 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const float* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_sgtsv_no_pivot_buffer_size( (rocsparse_handle)handle, m, n, dummy, dummy, dummy, dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const double* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dgtsv_no_pivot_buffer_size( (rocsparse_handle)handle, m, n, dummy, dummy, dummy, dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgtsv_no_pivot_buffer_size((rocsparse_handle)handle, m, n, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipDoubleComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv_no_pivot_buffer_size((rocsparse_handle)handle, m, n, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgtsv_no_pivot((rocsparse_handle)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseDgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgtsv_no_pivot((rocsparse_handle)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseCgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgtsv_no_pivot((rocsparse_handle)handle, m, n, (const rocsparse_float_complex*)dl, (const rocsparse_float_complex*)d, (const rocsparse_float_complex*)du, (rocsparse_float_complex*)B, ldb, pBuffer)); } hipsparseStatus_t hipsparseZgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv_no_pivot((rocsparse_handle)handle, m, n, (const rocsparse_double_complex*)dl, (const rocsparse_double_complex*)d, (const rocsparse_double_complex*)du, (rocsparse_double_complex*)B, ldb, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_gtsv.cpp0000664000175100017510000002535315176134305022635 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const float* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_sgtsv_buffer_size( (rocsparse_handle)handle, m, n, dummy, dummy, dummy, dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const double* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dgtsv_buffer_size( (rocsparse_handle)handle, m, n, dummy, dummy, dummy, dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgtsv_buffer_size((rocsparse_handle)handle, m, n, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipDoubleComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv_buffer_size((rocsparse_handle)handle, m, n, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsv2(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgtsv((rocsparse_handle)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseDgtsv2(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgtsv((rocsparse_handle)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseCgtsv2(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_cgtsv((rocsparse_handle)handle, m, n, (const rocsparse_float_complex*)dl, (const rocsparse_float_complex*)d, (const rocsparse_float_complex*)du, (rocsparse_float_complex*)B, ldb, pBuffer)); } hipsparseStatus_t hipsparseZgtsv2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv((rocsparse_handle)handle, m, n, (const rocsparse_double_complex*)dl, (const rocsparse_double_complex*)d, (const rocsparse_double_complex*)du, (rocsparse_double_complex*)B, ldb, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_csrilu0.cpp0000664000175100017510000007252315176134305023234 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsrilu02_zeroPivot(hipsparseHandle_t handle, csrilu02Info_t info, int* position) { // Obtain stream, to explicitly sync (cusparse csrilu02_zeropivot is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrilu0 zero pivot RETURN_IF_ROCSPARSE_ERROR( rocsparse_csrilu0_zero_pivot((rocsparse_handle)handle, (rocsparse_mat_info)info, position)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dscsrilu0_numeric_boost( (rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseDcsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dcsrilu0_numeric_boost( (rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseCcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dccsrilu0_numeric_boost((rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, (rocsparse_float_complex*)boost_val)); } hipsparseStatus_t hipsparseZcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrilu0_numeric_boost((rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, (rocsparse_double_complex*)boost_val)); } hipsparseStatus_t hipsparseScsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_scsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseDcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_dcsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_ccsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseZcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_zcsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseScsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrilu0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseScsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrilu0 analysis RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsrilu0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrilu0 analysis RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsrilu0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrilu0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_ccsrilu0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrilu0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_zcsrilu0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_scsrilu0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dcsrilu0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrilu0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrilu0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_csric0.cpp0000664000175100017510000006561415176134305023041 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsric02_zeroPivot(hipsparseHandle_t handle, csric02Info_t info, int* position) { // Obtain stream, to explicitly sync (cusparse csric02_zeropivot is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csric0 zero pivot RETURN_IF_ROCSPARSE_ERROR( rocsparse_csric0_zero_pivot((rocsparse_handle)handle, (rocsparse_mat_info)info, position)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_scsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseDcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_dcsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_ccsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseZcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_zcsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseScsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsric0_buffer_size((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseScsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csric0 analysis RETURN_IF_ROCSPARSE_ERROR(rocsparse_scsric0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csric0 analysis RETURN_IF_ROCSPARSE_ERROR(rocsparse_dcsric0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csric0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_ccsric0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csric0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_zcsric0_analysis((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_scsric0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dcsric0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsric0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsric0((rocsparse_handle)handle, m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_gtsv_interleaved_batch.cpp0000664000175100017510000003471215176134305026357 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const float* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgtsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, dummy, dummy, dummy, dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const double* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgtsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, dummy, dummy, dummy, dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgtsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipDoubleComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* dl, float* d, float* du, float* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgtsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, dl, d, du, x, batchCount, batchCount, pBuffer)); } hipsparseStatus_t hipsparseDgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* dl, double* d, double* du, double* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgtsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, dl, d, du, x, batchCount, batchCount, pBuffer)); } hipsparseStatus_t hipsparseCgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgtsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, (rocsparse_float_complex*)dl, (rocsparse_float_complex*)d, (rocsparse_float_complex*)du, (rocsparse_float_complex*)x, batchCount, batchCount, pBuffer)); } hipsparseStatus_t hipsparseZgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgtsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gtsv_interleaved_alg)algo, m, (rocsparse_double_complex*)dl, (rocsparse_double_complex*)d, (rocsparse_double_complex*)du, (rocsparse_double_complex*)x, batchCount, batchCount, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_gpsv_interleaved_batch.cpp0000664000175100017510000004136715176134305026357 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* ds, const float* dl, const float* d, const float* du, const float* dw, const float* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const float* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgpsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, dummy, dummy, dummy, dummy, dummy, dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* ds, const double* dl, const double* d, const double* du, const double* dw, const double* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const double* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgpsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, dummy, dummy, dummy, dummy, dummy, dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* ds, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* dw, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgpsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, (const rocsparse_float_complex*)dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* ds, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* dw, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { // cusparse allows passing nullptr's for dl, d, du, and B. On the other hand rocsparse checks // if they are nullptr and returns invalid pointer if they are. In both cases the pointers are // never actually de-referenced. In order to work in the same way regardless of the backend // that a user chooses, just pass in non-null dummy pointer. const hipDoubleComplex* dummy = static_cast((void*)0x4); return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgpsv_interleaved_batch_buffer_size((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, (const rocsparse_double_complex*)dummy, batchCount, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* ds, float* dl, float* d, float* du, float* dw, float* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgpsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, ds, dl, d, du, dw, x, batchCount, batchCount, pBuffer)); } hipsparseStatus_t hipsparseDgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* ds, double* dl, double* d, double* du, double* dw, double* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgpsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, ds, dl, d, du, dw, x, batchCount, batchCount, pBuffer)); } hipsparseStatus_t hipsparseCgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* ds, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* dw, hipComplex* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgpsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, (rocsparse_float_complex*)ds, (rocsparse_float_complex*)dl, (rocsparse_float_complex*)d, (rocsparse_float_complex*)du, (rocsparse_float_complex*)dw, (rocsparse_float_complex*)x, batchCount, batchCount, pBuffer)); } hipsparseStatus_t hipsparseZgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* ds, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* dw, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgpsv_interleaved_batch((rocsparse_handle)handle, (rocsparse_gpsv_interleaved_alg)algo, m, (rocsparse_double_complex*)ds, (rocsparse_double_complex*)dl, (rocsparse_double_complex*)d, (rocsparse_double_complex*)du, (rocsparse_double_complex*)dw, (rocsparse_double_complex*)x, batchCount, batchCount, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_bsric0.cpp0000664000175100017510000005543115176134305023034 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXbsric02_zeroPivot(hipsparseHandle_t handle, bsric02Info_t info, int* position) { // Obtain stream, to explicitly sync (cusparse bsric02_zeropivot is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsric0 zero pivot RETURN_IF_ROCSPARSE_ERROR( rocsparse_bsric0_zero_pivot((rocsparse_handle)handle, (rocsparse_mat_info)info, position)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_sbsric0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseDbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_dbsric0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_cbsric0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseZbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_zbsric0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseSbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsric0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_sbsric0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsric0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_dbsric0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsric0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_cbsric0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsric02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsric0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_zbsric0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsric0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsric0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsric0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsric0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/precond/hipsparse_bsrilu0.cpp0000664000175100017510000006230415176134305023227 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXbsrilu02_zeroPivot(hipsparseHandle_t handle, bsrilu02Info_t info, int* position) { // Obtain stream, to explicitly sync (cusparse bsrilu02_zeropivot is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsrilu0 zero pivot RETURN_IF_ROCSPARSE_ERROR( rocsparse_bsrilu0_zero_pivot((rocsparse_handle)handle, (rocsparse_mat_info)info, position)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dsbsrilu0_numeric_boost( (rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseDbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dbsrilu0_numeric_boost( (rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseCbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcbsrilu0_numeric_boost((rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, (rocsparse_float_complex*)boost_val)); } hipsparseStatus_t hipsparseZbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrilu0_numeric_boost((rocsparse_handle)handle, (rocsparse_mat_info)info, enable_boost, tol, (rocsparse_double_complex*)boost_val)); } hipsparseStatus_t hipsparseSbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_sbsrilu0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseDbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_dbsrilu0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_cbsrilu0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseZbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_zbsrilu0_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseSbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsrilu0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_sbsrilu0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsrilu0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_dbsrilu0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsrilu0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_cbsrilu0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse bsrilu02_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // bsrilu0 analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_zbsrilu0_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrilu0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrilu0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrilu0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrilu0((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/level2/0000775000175100017510000000000015176134461016622 5ustar jenkinsjenkins./library/src/amd_detail/level2/hipsparse_bsrsv.cpp0000664000175100017510000010056115176134305022543 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXbsrsv2_zeroPivot(hipsparseHandle_t handle, bsrsv2Info_t info, int* position) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_bsrsv_zero_pivot((rocsparse_handle)handle, (rocsparse_mat_info)info, position)); } hipsparseStatus_t hipsparseSbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_sbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseDbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_dbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_cbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseZbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_zbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseSbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrsv_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrsv_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrsv_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrsv_analysis((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseSbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrsv_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, alpha, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, f, x, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrsv_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, alpha, (rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, f, x, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrsv_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, (const rocsparse_float_complex*)f, (rocsparse_float_complex*)x, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrsv_solve((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(transA), mb, nnzb, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (rocsparse_mat_info)info, (const rocsparse_double_complex*)f, (rocsparse_double_complex*)x, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/level2/hipsparse_bsrxmv.cpp0000664000175100017510000002316015176134305022724 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descr, const float* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const float* x, const float* beta, float* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrxmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(trans), sizeOfMask, mb, nb, nnzb, alpha, (const rocsparse_mat_descr)descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y)); } hipsparseStatus_t hipsparseDbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descr, const double* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const double* x, const double* beta, double* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrxmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(trans), sizeOfMask, mb, nb, nnzb, alpha, (const rocsparse_mat_descr)descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y)); } hipsparseStatus_t hipsparseCbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrxmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(trans), sizeOfMask, mb, nb, nnzb, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descr, (const rocsparse_float_complex*)bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, (const rocsparse_float_complex*)x, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)y)); } hipsparseStatus_t hipsparseZbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrxmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dir), hipsparse::hipOperationToHCCOperation(trans), sizeOfMask, mb, nb, nnzb, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descr, (const rocsparse_double_complex*)bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, (const rocsparse_double_complex*)x, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)y)); } ./library/src/amd_detail/level2/hipsparse_csrmv.cpp0000664000175100017510000001704015176134305022535 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* x, const float* beta, float* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, nullptr, x, beta, y)); } hipsparseStatus_t hipsparseDcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* x, const double* beta, double* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, nullptr, x, beta, y)); } hipsparseStatus_t hipsparseCcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, nullptr, (const rocsparse_float_complex*)x, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)y)); } hipsparseStatus_t hipsparseZcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, nullptr, (const rocsparse_double_complex*)x, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)y)); } ./library/src/amd_detail/level2/hipsparse_bsrmv.cpp0000664000175100017510000002102415176134305022531 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const float* x, const float* beta, float* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sbsrmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), mb, nb, nnzb, alpha, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, nullptr, x, beta, y)); } hipsparseStatus_t hipsparseDbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const double* x, const double* beta, double* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dbsrmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), mb, nb, nnzb, alpha, (const rocsparse_mat_descr)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, nullptr, x, beta, y)); } hipsparseStatus_t hipsparseCbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cbsrmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), mb, nb, nnzb, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, nullptr, (const rocsparse_float_complex*)x, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)y)); } hipsparseStatus_t hipsparseZbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zbsrmv((rocsparse_handle)handle, hipsparse::hipDirectionToHCCDirection(dirA), hipsparse::hipOperationToHCCOperation(transA), mb, nb, nnzb, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, nullptr, (const rocsparse_double_complex*)x, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)y)); } ./library/src/amd_detail/level2/hipsparse_csrsv.cpp0000664000175100017510000007252515176134305022554 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsrsv2_zeroPivot(hipsparseHandle_t handle, csrsv2Info_t info, int* position) { // Obtain stream, to explicitly sync (cusparse csrsv2_zeropivot is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrsv zero pivot RETURN_IF_ROCSPARSE_ERROR(rocsparse_csrsv_zero_pivot( (rocsparse_handle)handle, nullptr, (rocsparse_mat_info)info, position)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_scsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseDcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_dcsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_ccsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseZcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; rocsparse_status status; status = rocsparse_zcsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, &buffer_size); *pBufferSizeInBytes = (int)buffer_size; return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseScsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrsv_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, (rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseScsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrsv2_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrsv analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_scsrsv_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrsv2_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrsv analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_dcsrsv_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrsv2_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrsv analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_ccsrsv_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { // Obtain stream, to explicitly sync (cusparse csrsv2_analysis is blocking) hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // csrsv analysis RETURN_IF_ROCSPARSE_ERROR( rocsparse_zcsrsv_analysis((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, rocsparse_analysis_policy_force, rocsparse_solve_policy_auto, pBuffer)); // Synchronize stream RETURN_IF_HIP_ERROR(hipStreamSynchronize(stream)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrsv_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, f, x, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseDcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrsv_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, alpha, (rocsparse_mat_descr)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, f, x, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseCcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrsv_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, (const rocsparse_float_complex*)f, (rocsparse_float_complex*)x, rocsparse_solve_policy_auto, pBuffer)); } hipsparseStatus_t hipsparseZcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrsv_solve((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, nnz, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (rocsparse_mat_info)info, (const rocsparse_double_complex*)f, (rocsparse_double_complex*)x, rocsparse_solve_policy_auto, pBuffer)); } ./library/src/amd_detail/level2/hipsparse_gemvi.cpp0000664000175100017510000002652615176134305022523 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgemvi_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, &buffer_size)); *pBufferSizeInBytes = (int)buffer_size; return status; } hipsparseStatus_t hipsparseDgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgemvi_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, &buffer_size)); *pBufferSizeInBytes = (int)buffer_size; return status; } hipsparseStatus_t hipsparseCgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgemvi_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, &buffer_size)); *pBufferSizeInBytes = (int)buffer_size; return status; } hipsparseStatus_t hipsparseZgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } size_t buffer_size; hipsparseStatus_t status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgemvi_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, nnz, &buffer_size)); *pBufferSizeInBytes = (int)buffer_size; return status; } hipsparseStatus_t hipsparseSgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const float* alpha, const float* A, int lda, int nnz, const float* x, const int* xInd, const float* beta, float* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sgemvi((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, alpha, A, lda, nnz, x, xInd, beta, y, hipsparse::hipBaseToHCCBase(idxBase), pBuffer)); } hipsparseStatus_t hipsparseDgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const double* alpha, const double* A, int lda, int nnz, const double* x, const int* xInd, const double* beta, double* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dgemvi((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, alpha, A, lda, nnz, x, xInd, beta, y, hipsparse::hipBaseToHCCBase(idxBase), pBuffer)); } hipsparseStatus_t hipsparseCgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipComplex* alpha, const hipComplex* A, int lda, int nnz, const hipComplex* x, const int* xInd, const hipComplex* beta, hipComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_cgemvi((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, (const rocsparse_float_complex*)alpha, (const rocsparse_float_complex*)A, lda, nnz, (const rocsparse_float_complex*)x, xInd, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)y, hipsparse::hipBaseToHCCBase(idxBase), pBuffer)); } hipsparseStatus_t hipsparseZgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, int nnz, const hipDoubleComplex* x, const int* xInd, const hipDoubleComplex* beta, hipDoubleComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zgemvi((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), m, n, (const rocsparse_double_complex*)alpha, (const rocsparse_double_complex*)A, lda, nnz, (const rocsparse_double_complex*)x, xInd, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)y, hipsparse::hipBaseToHCCBase(idxBase), pBuffer)); } ./library/src/amd_detail/level2/hipsparse_hybmv.cpp0000664000175100017510000001247715176134305022541 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseShybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const float* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const float* x, const float* beta, float* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_shybmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), alpha, (rocsparse_mat_descr)descrA, (rocsparse_hyb_mat)hybA, x, beta, y)); } hipsparseStatus_t hipsparseDhybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const double* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const double* x, const double* beta, double* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dhybmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), alpha, (rocsparse_mat_descr)descrA, (rocsparse_hyb_mat)hybA, x, beta, y)); } hipsparseStatus_t hipsparseChybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_chybmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, (rocsparse_hyb_mat)hybA, (const rocsparse_float_complex*)x, (const rocsparse_float_complex*)beta, (rocsparse_float_complex*)y)); } hipsparseStatus_t hipsparseZhybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zhybmv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, (rocsparse_hyb_mat)hybA, (const rocsparse_double_complex*)x, (const rocsparse_double_complex*)beta, (rocsparse_double_complex*)y)); } ./library/src/amd_detail/reorder/0000775000175100017510000000000015176134461017073 5ustar jenkinsjenkins./library/src/amd_detail/reorder/hipsparse_csrcolor.cpp0000664000175100017510000001615015176134305023503 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrcolor((rocsparse_handle)handle, m, nnz, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseDcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrcolor((rocsparse_handle)handle, m, nnz, (const rocsparse_mat_descr)descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrcolor((rocsparse_handle)handle, m, nnz, (const rocsparse_mat_descr)descrA, (const rocsparse_float_complex*)csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseZcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrcolor((rocsparse_handle)handle, m, nnz, (const rocsparse_mat_descr)descrA, (const rocsparse_double_complex*)csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (rocsparse_mat_info)info)); } ./library/src/amd_detail/hipsparse_auxiliary.cpp0000664000175100017510000002666015176134305022231 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "utility.h" #include hipsparseStatus_t hipsparseCreate(hipsparseHandle_t* handle) { // Check if handle is valid if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } int deviceId; hipError_t err; err = hipGetDevice(&deviceId); if(err == hipSuccess) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_handle((rocsparse_handle*)handle)); } return hipsparse::hipErrorToHIPSPARSEStatus(err); } hipsparseStatus_t hipsparseDestroy(hipsparseHandle_t handle) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_handle((rocsparse_handle)handle)); } const char* hipsparseGetErrorName(hipsparseStatus_t status) { return rocsparse_get_status_name(hipsparse::hipSPARSEStatusToRocSPARSEStatus(status)); } const char* hipsparseGetErrorString(hipsparseStatus_t status) { return rocsparse_get_status_description(hipsparse::hipSPARSEStatusToRocSPARSEStatus(status)); } hipsparseStatus_t hipsparseGetVersion(hipsparseHandle_t handle, int* version) { if(handle == nullptr) { return HIPSPARSE_STATUS_NOT_INITIALIZED; } *version = hipsparseVersionMajor * 100000 + hipsparseVersionMinor * 100 + hipsparseVersionPatch; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseGetGitRevision(hipsparseHandle_t handle, char* rev) { // Get hipSPARSE revision if(handle == nullptr) { return HIPSPARSE_STATUS_NOT_INITIALIZED; } if(rev == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } static constexpr char v[] = TO_STR(hipsparseVersionTweak); char hipsparse_rev[64]; memcpy(hipsparse_rev, v, sizeof(v)); // Get rocSPARSE revision char rocsparse_rev[64]; RETURN_IF_ROCSPARSE_ERROR(rocsparse_get_git_rev((rocsparse_handle)handle, rocsparse_rev)); // Get rocSPARSE version int rocsparse_ver; RETURN_IF_ROCSPARSE_ERROR(rocsparse_get_version((rocsparse_handle)handle, &rocsparse_ver)); // Combine snprintf(rev, 256, "%.64s (rocSPARSE %d.%d.%d-%.64s)", hipsparse_rev, rocsparse_ver / 100000, rocsparse_ver / 100 % 1000, rocsparse_ver % 100, rocsparse_rev); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSetStream(hipsparseHandle_t handle, hipStream_t streamId) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_set_stream((rocsparse_handle)handle, streamId)); } hipsparseStatus_t hipsparseGetStream(hipsparseHandle_t handle, hipStream_t* streamId) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_get_stream((rocsparse_handle)handle, streamId)); } hipsparseStatus_t hipsparseSetPointerMode(hipsparseHandle_t handle, hipsparsePointerMode_t mode) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_set_pointer_mode( (rocsparse_handle)handle, hipsparse::hipPtrModeToHCCPtrMode(mode))); } hipsparseStatus_t hipsparseGetPointerMode(hipsparseHandle_t handle, hipsparsePointerMode_t* mode) { rocsparse_pointer_mode_ rocsparse_mode; rocsparse_status status = rocsparse_get_pointer_mode((rocsparse_handle)handle, &rocsparse_mode); *mode = hipsparse::HCCPtrModeToHIPPtrMode(rocsparse_mode); return hipsparse::rocSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCreateMatDescr(hipsparseMatDescr_t* descrA) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_descr((rocsparse_mat_descr*)descrA)); } hipsparseStatus_t hipsparseDestroyMatDescr(hipsparseMatDescr_t descrA) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_descr((rocsparse_mat_descr)descrA)); } hipsparseStatus_t hipsparseCopyMatDescr(hipsparseMatDescr_t dest, const hipsparseMatDescr_t src) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_copy_mat_descr((rocsparse_mat_descr)dest, (const rocsparse_mat_descr)src)); } hipsparseStatus_t hipsparseSetMatType(hipsparseMatDescr_t descrA, hipsparseMatrixType_t type) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_set_mat_type( (rocsparse_mat_descr)descrA, hipsparse::hipMatTypeToHCCMatType(type))); } hipsparseMatrixType_t hipsparseGetMatType(const hipsparseMatDescr_t descrA) { return hipsparse::HCCMatTypeToHIPMatType(rocsparse_get_mat_type((rocsparse_mat_descr)descrA)); } hipsparseStatus_t hipsparseSetMatFillMode(hipsparseMatDescr_t descrA, hipsparseFillMode_t fillMode) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_set_mat_fill_mode( (rocsparse_mat_descr)descrA, hipsparse::hipFillModeToHCCFillMode(fillMode))); } hipsparseFillMode_t hipsparseGetMatFillMode(const hipsparseMatDescr_t descrA) { return hipsparse::HCCFillModeToHIPFillMode( rocsparse_get_mat_fill_mode((rocsparse_mat_descr)descrA)); } hipsparseStatus_t hipsparseSetMatDiagType(hipsparseMatDescr_t descrA, hipsparseDiagType_t diagType) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_set_mat_diag_type( (rocsparse_mat_descr)descrA, hipsparse::hipDiagTypeToHCCDiagType(diagType))); } hipsparseDiagType_t hipsparseGetMatDiagType(const hipsparseMatDescr_t descrA) { return hipsparse::HCCDiagTypeToHIPDiagType( rocsparse_get_mat_diag_type((rocsparse_mat_descr)descrA)); } hipsparseStatus_t hipsparseSetMatIndexBase(hipsparseMatDescr_t descrA, hipsparseIndexBase_t base) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_set_mat_index_base( (rocsparse_mat_descr)descrA, hipsparse::hipBaseToHCCBase(base))); } hipsparseIndexBase_t hipsparseGetMatIndexBase(const hipsparseMatDescr_t descrA) { return hipsparse::HCCBaseToHIPBase(rocsparse_get_mat_index_base((rocsparse_mat_descr)descrA)); } hipsparseStatus_t hipsparseCreateHybMat(hipsparseHybMat_t* hybA) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_hyb_mat((rocsparse_hyb_mat*)hybA)); } hipsparseStatus_t hipsparseDestroyHybMat(hipsparseHybMat_t hybA) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_hyb_mat((rocsparse_hyb_mat)hybA)); } hipsparseStatus_t hipsparseCreateBsrsv2Info(bsrsv2Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyBsrsv2Info(bsrsv2Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateBsrsm2Info(bsrsm2Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyBsrsm2Info(bsrsm2Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateCsrsv2Info(csrsv2Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyCsrsv2Info(csrsv2Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateColorInfo(hipsparseColorInfo_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyColorInfo(hipsparseColorInfo_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateCsrsm2Info(csrsm2Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyCsrsm2Info(csrsm2Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateBsrilu02Info(bsrilu02Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyBsrilu02Info(bsrilu02Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateCsrilu02Info(csrilu02Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyCsrilu02Info(csrilu02Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateBsric02Info(bsric02Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyBsric02Info(bsric02Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateCsric02Info(csric02Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyCsric02Info(csric02Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreateCsrgemm2Info(csrgemm2Info_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyCsrgemm2Info(csrgemm2Info_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } hipsparseStatus_t hipsparseCreatePruneInfo(pruneInfo_t* info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_create_mat_info((rocsparse_mat_info*)info)); } hipsparseStatus_t hipsparseDestroyPruneInfo(pruneInfo_t info) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_destroy_mat_info((rocsparse_mat_info)info)); } ./library/src/amd_detail/extra/0000775000175100017510000000000015176134461016554 5ustar jenkinsjenkins./library/src/amd_detail/extra/hipsparse_csrgemm.cpp0000664000175100017510000016700715176134305023003 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsrgemmNnz(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr) { // Create matrix info rocsparse_mat_info info; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_info(&info)); // Buffer size_t buffer_size; void* temp_buffer; // Initialize alpha = 1.0 hipDoubleComplex one = make_hipDoubleComplex(1.0, 0.0); hipDoubleComplex* alpha; hipsparseStatus_t status; // Get pointer mode rocsparse_pointer_mode pointer_mode; status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_get_pointer_mode((rocsparse_handle)handle, &pointer_mode)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } if(pointer_mode == rocsparse_pointer_mode_host) { alpha = (hipDoubleComplex*)malloc(sizeof(hipDoubleComplex)); *alpha = one; } else { RETURN_IF_HIP_ERROR(hipMalloc((void**)&alpha, sizeof(hipDoubleComplex))); RETURN_IF_HIP_ERROR( hipMemcpy(alpha, &one, sizeof(hipDoubleComplex), hipMemcpyHostToDevice)); } // Obtain temporary buffer size status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrgemm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, info, &buffer_size)); if(status != HIPSPARSE_STATUS_SUCCESS) { if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } rocsparse_destroy_mat_info(info); return status; } RETURN_IF_HIP_ERROR(hipMalloc(&temp_buffer, buffer_size)); // Determine nnz status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_csrgemm_nnz((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, nullptr, 0, nullptr, nullptr, (rocsparse_mat_descr)descrC, csrRowPtrC, nnzTotalDevHostPtr, info, temp_buffer)); if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } RETURN_IF_HIP_ERROR(hipFree(temp_buffer)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_info(info)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC) { // Create matrix info rocsparse_mat_info info; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_info(&info)); // Buffer size_t buffer_size; void* temp_buffer; // Initialize alpha = 1.0 float one = 1.0f; float* alpha; hipsparseStatus_t status; // Get pointer mode rocsparse_pointer_mode pointer_mode; status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_get_pointer_mode((rocsparse_handle)handle, &pointer_mode)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } if(pointer_mode == rocsparse_pointer_mode_host) { alpha = (float*)malloc(sizeof(float)); *alpha = one; } else { RETURN_IF_HIP_ERROR(hipMalloc((void**)&alpha, sizeof(float))); RETURN_IF_HIP_ERROR(hipMemcpy(alpha, &one, sizeof(float), hipMemcpyHostToDevice)); } // Obtain temporary buffer size status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrgemm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, info, &buffer_size)); if(status != HIPSPARSE_STATUS_SUCCESS) { if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } rocsparse_destroy_mat_info(info); return status; } RETURN_IF_HIP_ERROR(hipMalloc(&temp_buffer, buffer_size)); // Perform csrgemm computation status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, nullptr, (rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, info, temp_buffer)); if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } RETURN_IF_HIP_ERROR(hipFree(temp_buffer)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_info(info)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC) { // Create matrix info rocsparse_mat_info info; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_info(&info)); // Buffer size_t buffer_size; void* temp_buffer; // Initialize alpha = 1.0 double one = 1.0; double* alpha; hipsparseStatus_t status; // Get pointer mode rocsparse_pointer_mode pointer_mode; status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_get_pointer_mode((rocsparse_handle)handle, &pointer_mode)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } if(pointer_mode == rocsparse_pointer_mode_host) { alpha = (double*)malloc(sizeof(double)); *alpha = one; } else { RETURN_IF_HIP_ERROR(hipMalloc((void**)&alpha, sizeof(double))); RETURN_IF_HIP_ERROR(hipMemcpy(alpha, &one, sizeof(double), hipMemcpyHostToDevice)); } // Obtain temporary buffer size status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrgemm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, info, &buffer_size)); if(status != HIPSPARSE_STATUS_SUCCESS) { if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } rocsparse_destroy_mat_info(info); return status; } RETURN_IF_HIP_ERROR(hipMalloc(&temp_buffer, buffer_size)); // Perform csrgemm computation status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, nullptr, (rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, info, temp_buffer)); if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } RETURN_IF_HIP_ERROR(hipFree(temp_buffer)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_info(info)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { // Create matrix info rocsparse_mat_info info; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_info(&info)); // Buffer size_t buffer_size; void* temp_buffer; // Initialize alpha = 1.0 hipComplex one = make_hipComplex(1.0f, 0.0f); hipComplex* alpha; hipsparseStatus_t status; // Get pointer mode rocsparse_pointer_mode pointer_mode; status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_get_pointer_mode((rocsparse_handle)handle, &pointer_mode)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } if(pointer_mode == rocsparse_pointer_mode_host) { alpha = (hipComplex*)malloc(sizeof(hipComplex)); *alpha = one; } else { RETURN_IF_HIP_ERROR(hipMalloc((void**)&alpha, sizeof(hipComplex))); RETURN_IF_HIP_ERROR(hipMemcpy(alpha, &one, sizeof(hipComplex), hipMemcpyHostToDevice)); } // Obtain temporary buffer size status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrgemm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, info, &buffer_size)); if(status != HIPSPARSE_STATUS_SUCCESS) { if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } rocsparse_destroy_mat_info(info); return status; } RETURN_IF_HIP_ERROR(hipMalloc(&temp_buffer, buffer_size)); // Perform csrgemm computation status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, (const rocsparse_float_complex*)csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, (const rocsparse_float_complex*)csrValB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, nullptr, (rocsparse_mat_descr)descrC, (rocsparse_float_complex*)csrValC, csrRowPtrC, csrColIndC, info, temp_buffer)); if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } RETURN_IF_HIP_ERROR(hipFree(temp_buffer)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_info(info)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { // Create matrix info rocsparse_mat_info info; RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_mat_info(&info)); // Buffer size_t buffer_size; void* temp_buffer; // Initialize alpha = 1.0 hipDoubleComplex one = make_hipDoubleComplex(1.0, 0.0); hipDoubleComplex* alpha; hipsparseStatus_t status; // Get pointer mode rocsparse_pointer_mode pointer_mode; status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_get_pointer_mode((rocsparse_handle)handle, &pointer_mode)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } if(pointer_mode == rocsparse_pointer_mode_host) { alpha = (hipDoubleComplex*)malloc(sizeof(hipDoubleComplex)); *alpha = one; } else { RETURN_IF_HIP_ERROR(hipMalloc((void**)&alpha, sizeof(hipDoubleComplex))); RETURN_IF_HIP_ERROR( hipMemcpy(alpha, &one, sizeof(hipDoubleComplex), hipMemcpyHostToDevice)); } // Obtain temporary buffer size status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrgemm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, info, &buffer_size)); if(status != HIPSPARSE_STATUS_SUCCESS) { if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } rocsparse_destroy_mat_info(info); return status; } RETURN_IF_HIP_ERROR(hipMalloc(&temp_buffer, buffer_size)); // Perform csrgemm computation status = hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(transA), hipsparse::hipOperationToHCCOperation(transB), m, n, k, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, (const rocsparse_double_complex*)csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, (const rocsparse_double_complex*)csrValB, csrRowPtrB, csrColIndB, nullptr, nullptr, 0, nullptr, nullptr, nullptr, (rocsparse_mat_descr)descrC, (rocsparse_double_complex*)csrValC, csrRowPtrC, csrColIndC, info, temp_buffer)); if(pointer_mode == rocsparse_pointer_mode_host) { free(alpha); } else { RETURN_IF_HIP_ERROR(hipFree(alpha)); } RETURN_IF_HIP_ERROR(hipFree(temp_buffer)); if(status != HIPSPARSE_STATUS_SUCCESS) { rocsparse_destroy_mat_info(info); return status; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_mat_info(info)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseScsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrgemm_buffer_size((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, beta, (rocsparse_mat_descr)descrD, nnzD, csrRowPtrD, csrColIndD, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrgemm_buffer_size((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, beta, (rocsparse_mat_descr)descrD, nnzD, csrRowPtrD, csrColIndD, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrgemm_buffer_size((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, (const rocsparse_float_complex*)beta, (rocsparse_mat_descr)descrD, nnzD, csrRowPtrD, csrColIndD, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrgemm_buffer_size((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, (const rocsparse_double_complex*)beta, (rocsparse_mat_descr)descrD, nnzD, csrRowPtrD, csrColIndD, (rocsparse_mat_info)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcsrgemm2Nnz(hipsparseHandle_t handle, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_csrgemm_nnz((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, (rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, (rocsparse_mat_descr)descrD, nnzD, csrRowPtrD, csrColIndD, (rocsparse_mat_descr)descrC, csrRowPtrC, nnzTotalDevHostPtr, (rocsparse_mat_info)info, pBuffer)); } hipsparseStatus_t hipsparseScsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const float* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_scsrgemm((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, (rocsparse_mat_descr)descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, (rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBuffer)); } hipsparseStatus_t hipsparseDcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const double* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_dcsrgemm((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, alpha, (rocsparse_mat_descr)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, (rocsparse_mat_descr)descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, (rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBuffer)); } hipsparseStatus_t hipsparseCcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrgemm((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, (const rocsparse_float_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, (const rocsparse_float_complex*)csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, (const rocsparse_float_complex*)csrValB, csrRowPtrB, csrColIndB, (const rocsparse_float_complex*)beta, (rocsparse_mat_descr)descrD, nnzD, (const rocsparse_float_complex*)csrValD, csrRowPtrD, csrColIndD, (rocsparse_mat_descr)descrC, (rocsparse_float_complex*)csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBuffer)); } hipsparseStatus_t hipsparseZcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipDoubleComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrgemm((rocsparse_handle)handle, rocsparse_operation_none, rocsparse_operation_none, m, n, k, (const rocsparse_double_complex*)alpha, (rocsparse_mat_descr)descrA, nnzA, (const rocsparse_double_complex*)csrValA, csrRowPtrA, csrColIndA, (rocsparse_mat_descr)descrB, nnzB, (const rocsparse_double_complex*)csrValB, csrRowPtrB, csrColIndB, (const rocsparse_double_complex*)beta, (rocsparse_mat_descr)descrD, nnzD, (const rocsparse_double_complex*)csrValD, csrRowPtrD, csrColIndD, (rocsparse_mat_descr)descrC, (rocsparse_double_complex*)csrValC, csrRowPtrC, csrColIndC, (rocsparse_mat_info)info, pBuffer)); } ./library/src/amd_detail/extra/hipsparse_csrgeam.cpp0000664000175100017510000007507015176134305022765 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsrgeamNnz(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_csrgeam_nnz((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descrA, nnzA, csrRowPtrA, csrColIndA, (const rocsparse_mat_descr)descrB, nnzB, csrRowPtrB, csrColIndB, (const rocsparse_mat_descr)descrC, csrRowPtrC, nnzTotalDevHostPtr)); } hipsparseStatus_t hipsparseScsrgeam(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrgeam((rocsparse_handle)handle, m, n, alpha, (const rocsparse_mat_descr)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, beta, (const rocsparse_mat_descr)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseDcsrgeam(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrgeam((rocsparse_handle)handle, m, n, alpha, (const rocsparse_mat_descr)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, beta, (const rocsparse_mat_descr)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, (const rocsparse_mat_descr)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseCcsrgeam(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrgeam((rocsparse_handle)handle, m, n, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descrA, nnzA, (const rocsparse_float_complex*)csrValA, csrRowPtrA, csrColIndA, (const rocsparse_float_complex*)beta, (const rocsparse_mat_descr)descrB, nnzB, (const rocsparse_float_complex*)csrValB, csrRowPtrB, csrColIndB, (const rocsparse_mat_descr)descrC, (rocsparse_float_complex*)csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseZcsrgeam(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrgeam((rocsparse_handle)handle, m, n, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descrA, nnzA, (const rocsparse_double_complex*)csrValA, csrRowPtrA, csrColIndA, (const rocsparse_double_complex*)beta, (const rocsparse_mat_descr)descrB, nnzB, (const rocsparse_double_complex*)csrValB, csrRowPtrB, csrColIndB, (const rocsparse_mat_descr)descrC, (rocsparse_double_complex*)csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseScsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const float* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseDcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const double* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseCcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseZcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipDoubleComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { *pBufferSizeInBytes = 4; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseXcsrgeam2Nnz(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, int nnzA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, int* csrSortedRowPtrC, int* nnzTotalDevHostPtr, void* workspace) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_csrgeam_nnz((rocsparse_handle)handle, m, n, (const rocsparse_mat_descr)descrA, nnzA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_mat_descr)descrB, nnzB, csrSortedRowPtrB, csrSortedColIndB, (const rocsparse_mat_descr)descrC, csrSortedRowPtrC, nnzTotalDevHostPtr)); } hipsparseStatus_t hipsparseScsrgeam2(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, float* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_scsrgeam((rocsparse_handle)handle, m, n, alpha, (const rocsparse_mat_descr)descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, (const rocsparse_mat_descr)descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const rocsparse_mat_descr)descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC)); } hipsparseStatus_t hipsparseDcsrgeam2(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, double* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dcsrgeam((rocsparse_handle)handle, m, n, alpha, (const rocsparse_mat_descr)descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, (const rocsparse_mat_descr)descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const rocsparse_mat_descr)descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC)); } hipsparseStatus_t hipsparseCcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_ccsrgeam((rocsparse_handle)handle, m, n, (const rocsparse_float_complex*)alpha, (const rocsparse_mat_descr)descrA, nnzA, (const rocsparse_float_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_float_complex*)beta, (const rocsparse_mat_descr)descrB, nnzB, (const rocsparse_float_complex*)csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const rocsparse_mat_descr)descrC, (rocsparse_float_complex*)csrSortedValC, csrSortedRowPtrC, csrSortedColIndC)); } hipsparseStatus_t hipsparseZcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_zcsrgeam((rocsparse_handle)handle, m, n, (const rocsparse_double_complex*)alpha, (const rocsparse_mat_descr)descrA, nnzA, (const rocsparse_double_complex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const rocsparse_double_complex*)beta, (const rocsparse_mat_descr)descrB, nnzB, (const rocsparse_double_complex*)csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const rocsparse_mat_descr)descrC, (rocsparse_double_complex*)csrSortedValC, csrSortedRowPtrC, csrSortedColIndC)); } ./library/src/amd_detail/generic/0000775000175100017510000000000015176134511017041 5ustar jenkinsjenkins./library/src/amd_detail/generic/hipsparse_scatter.cpp0000664000175100017510000000346215176134305023276 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScatter(hipsparseHandle_t handle, hipsparseConstSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_scatter( (rocsparse_handle)handle, (rocsparse_const_spvec_descr)vecX, (rocsparse_dnvec_descr)vecY)); } ./library/src/amd_detail/generic/hipsparse_axpby.cpp0000664000175100017510000000426715176134305022760 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseAxpby(hipsparseHandle_t handle, const void* alpha, hipsparseConstSpVecDescr_t vecX, const void* beta, hipsparseDnVecDescr_t vecY) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_axpby((rocsparse_handle)handle, alpha, (rocsparse_const_spvec_descr)vecX, beta, (rocsparse_dnvec_descr)vecY)); } ./library/src/amd_detail/generic/hipsparse_spgemm_reuse.cpp0000664000175100017510000005711315176134305024326 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" struct hipsparseSpGEMMDescr { size_t bufferSize1{}; size_t bufferSize2{}; size_t bufferSize3{}; size_t bufferSize4{}; size_t bufferSize5{}; void* externalBuffer1{}; void* externalBuffer2{}; void* externalBuffer3{}; void* externalBuffer4{}; void* externalBuffer5{}; }; namespace hipsparse { static hipsparseStatus_t getIndexTypeSize(hipsparseIndexType_t indexType, size_t& size) { switch(indexType) { case HIPSPARSE_INDEX_16U: { size = sizeof(uint16_t); return HIPSPARSE_STATUS_SUCCESS; } case HIPSPARSE_INDEX_32I: { size = sizeof(int32_t); return HIPSPARSE_STATUS_SUCCESS; } case HIPSPARSE_INDEX_64I: { size = sizeof(int64_t); return HIPSPARSE_STATUS_SUCCESS; } } size = 0; return HIPSPARSE_STATUS_INVALID_VALUE; } static hipsparseStatus_t getDataTypeSize(hipDataType dataType, size_t& size) { switch(dataType) { case HIP_R_32F: { size = sizeof(float); return HIPSPARSE_STATUS_SUCCESS; } case HIP_R_64F: { size = sizeof(double); return HIPSPARSE_STATUS_SUCCESS; } case HIP_C_32F: { size = sizeof(hipComplex); return HIPSPARSE_STATUS_SUCCESS; } case HIP_C_64F: { size = sizeof(hipDoubleComplex); return HIPSPARSE_STATUS_SUCCESS; } default: { size = 0; return HIPSPARSE_STATUS_INVALID_VALUE; } } size = 0; return HIPSPARSE_STATUS_INVALID_VALUE; } } hipsparseStatus_t hipsparseSpGEMMreuse_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1) { const void* alpha = (const void*)0x4; const void* beta = (const void*)0x4; // Get data stored in C matrix int64_t rowsC, colsC, nnzC; void* csrRowOffsetsC; void* csrColIndC; void* csrValuesC; hipsparseIndexType_t csrRowOffsetsTypeC; hipsparseIndexType_t csrColIndTypeC; hipsparseIndexBase_t idxBaseC; hipDataType csrValueTypeC; RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrGet(matC, &rowsC, &colsC, &nnzC, &csrRowOffsetsC, &csrColIndC, &csrValuesC, &csrRowOffsetsTypeC, &csrColIndTypeC, &idxBaseC, &csrValueTypeC)); hipDataType computeType = csrValueTypeC; return hipsparseSpGEMM_workEstimation(handle, opA, opB, alpha, matA, matB, beta, matC, computeType, alg, spgemmDescr, bufferSize1, externalBuffer1); } hipsparseStatus_t hipsparseSpGEMMreuse_nnz(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2, size_t* bufferSize3, void* externalBuffer3, size_t* bufferSize4, void* externalBuffer4) { // Match cusparse error handling if(handle == nullptr || matA == nullptr || matB == nullptr || matC == nullptr || spgemmDescr == nullptr || bufferSize2 == nullptr || bufferSize3 == nullptr || bufferSize3 == nullptr || bufferSize4 == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // If any external buffer is nullptr, they must all be nullptr. bool allBuffersNull = (externalBuffer2 == nullptr) & (externalBuffer3 == nullptr) & (externalBuffer4 == nullptr); bool anyBuffersNull = (externalBuffer2 == nullptr) | (externalBuffer3 == nullptr) | (externalBuffer4 == nullptr); if(anyBuffersNull && !allBuffersNull) { return HIPSPARSE_STATUS_INVALID_VALUE; } const void* alpha = (const void*)0x4; // Get data stored in C matrix int64_t rowsC, colsC, nnzC; void* csrRowOffsetsC; void* csrColIndC; void* csrValuesC; hipsparseIndexType_t csrRowOffsetsTypeC; hipsparseIndexType_t csrColIndTypeC; hipsparseIndexBase_t idxBaseC; hipDataType csrValueTypeC; RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrGet(matC, &rowsC, &colsC, &nnzC, &csrRowOffsetsC, &csrColIndC, &csrValuesC, &csrRowOffsetsTypeC, &csrColIndTypeC, &idxBaseC, &csrValueTypeC)); hipDataType computeType = csrValueTypeC; size_t csrRowOffsetsTypeSizeC; size_t csrColIndTypeSizeC; size_t csrValueTypeSizeC; RETURN_IF_HIPSPARSE_ERROR( hipsparse::getIndexTypeSize(csrRowOffsetsTypeC, csrRowOffsetsTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getIndexTypeSize(csrColIndTypeC, csrColIndTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getDataTypeSize(csrValueTypeC, csrValueTypeSizeC)); if(allBuffersNull) { *bufferSize2 = 4; *bufferSize3 = 4; *bufferSize4 = spgemmDescr->bufferSize1; *bufferSize3 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; *bufferSize3 += ((csrValueTypeSizeC * nnzC - 1) / 256 + 1) * 256; spgemmDescr->bufferSize2 = *bufferSize2; spgemmDescr->bufferSize3 = *bufferSize3; spgemmDescr->bufferSize4 = *bufferSize4; } else { hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); spgemmDescr->externalBuffer2 = externalBuffer2; spgemmDescr->externalBuffer3 = externalBuffer3; // stores C column indices and values spgemmDescr->externalBuffer4 = externalBuffer4; // stores C row pointers array + spgemm buffer size_t byteOffset3 = ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; size_t byteOffset4 = ((csrRowOffsetsTypeSizeC * (rowsC + 1) - 1) / 256 + 1) * 256; // Transfer external buffer 1 (which stores C row pointer array) to external buffer 4 because // buffer 1 can be deleted after this function RETURN_IF_HIP_ERROR(hipMemcpyAsync(spgemmDescr->externalBuffer4, spgemmDescr->externalBuffer1, *bufferSize4, hipMemcpyDeviceToDevice, stream)); // Temporarily set in C matrix in order to compute C row pointer array (stored in externalBuffer1) RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrSetPointers( matC, spgemmDescr->externalBuffer4, spgemmDescr->externalBuffer3, static_cast(spgemmDescr->externalBuffer3) + byteOffset3)); size_t bufferSize = (spgemmDescr->bufferSize4 - byteOffset4); RETURN_IF_ROCSPARSE_ERROR( rocsparse_spgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), to_rocsparse_const_spmat_descr(matB), nullptr, to_rocsparse_const_spmat_descr(matC), to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpGEMMAlgToHCCSpGEMMAlg(alg), rocsparse_spgemm_stage_symbolic, &bufferSize, static_cast(spgemmDescr->externalBuffer4) + byteOffset4)); } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpGEMMreuse_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize5, void* externalBuffer5) { if(handle == nullptr || matA == nullptr || matB == nullptr || matC == nullptr || bufferSize5 == nullptr || spgemmDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get data stored in C matrix int64_t rowsC, colsC, nnzC; void* csrRowOffsetsC; void* csrColIndC; void* csrValuesC; hipsparseIndexType_t csrRowOffsetsTypeC; hipsparseIndexType_t csrColIndTypeC; hipsparseIndexBase_t idxBaseC; hipDataType csrValueTypeC; RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrGet(matC, &rowsC, &colsC, &nnzC, &csrRowOffsetsC, &csrColIndC, &csrValuesC, &csrRowOffsetsTypeC, &csrColIndTypeC, &idxBaseC, &csrValueTypeC)); size_t csrRowOffsetsTypeSizeC; size_t csrColIndTypeSizeC; size_t csrValueTypeSizeC; RETURN_IF_HIPSPARSE_ERROR( hipsparse::getIndexTypeSize(csrRowOffsetsTypeC, csrRowOffsetsTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getIndexTypeSize(csrColIndTypeC, csrColIndTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getDataTypeSize(csrValueTypeC, csrValueTypeSizeC)); if(externalBuffer5 == nullptr) { *bufferSize5 = 0; // Need to store temporary space for values array *bufferSize5 += ((csrValueTypeSizeC * nnzC - 1) / 256 + 1) * 256; // Need to store temporary space for indices array used in hipsparseSpGEMM_copy Axpby *bufferSize5 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; // Need to store temporary space for host/device 1 value used in hipsparseSpGEMM_copy Axpby *bufferSize5 += ((16 - 1) / 256 + 1) * 256; spgemmDescr->bufferSize5 = *bufferSize5; } else { spgemmDescr->externalBuffer5 = externalBuffer5; hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); RETURN_IF_HIP_ERROR(hipMemcpyAsync(csrRowOffsetsC, spgemmDescr->externalBuffer4, csrRowOffsetsTypeSizeC * (rowsC + 1), hipMemcpyDeviceToDevice, stream)); RETURN_IF_HIP_ERROR(hipMemcpyAsync(csrColIndC, spgemmDescr->externalBuffer3, csrColIndTypeSizeC * nnzC, hipMemcpyDeviceToDevice, stream)); RETURN_IF_HIPSPARSE_ERROR( hipsparseCsrSetPointers(matC, csrRowOffsetsC, csrColIndC, csrValuesC)); } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpGEMMreuse_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr) { if(handle == nullptr || alpha == nullptr || beta == nullptr || spgemmDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get data stored in C matrix int64_t rowsC, colsC, nnzC; void* csrRowOffsetsC; void* csrColIndC; void* csrValuesC; hipsparseIndexType_t csrRowOffsetsTypeC; hipsparseIndexType_t csrColIndTypeC; hipsparseIndexBase_t idxBaseC; hipDataType csrValueTypeC; RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrGet(matC, &rowsC, &colsC, &nnzC, &csrRowOffsetsC, &csrColIndC, &csrValuesC, &csrRowOffsetsTypeC, &csrColIndTypeC, &idxBaseC, &csrValueTypeC)); size_t csrRowOffsetsTypeSizeC; size_t csrColIndTypeSizeC; size_t csrValueTypeSizeC; RETURN_IF_HIPSPARSE_ERROR( hipsparse::getIndexTypeSize(csrRowOffsetsTypeC, csrRowOffsetsTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getIndexTypeSize(csrColIndTypeC, csrColIndTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getDataTypeSize(csrValueTypeC, csrValueTypeSizeC)); size_t byteOffset4 = ((csrRowOffsetsTypeSizeC * (rowsC + 1) - 1) / 256 + 1) * 256; size_t byteOffset5 = 0; void* csrValuesCFromBuffer5 = spgemmDescr->externalBuffer5; byteOffset5 += ((csrValueTypeSizeC * nnzC - 1) / 256 + 1) * 256; void* indicesArray = (static_cast(spgemmDescr->externalBuffer5) + byteOffset5); byteOffset5 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; void* device_one = (static_cast(spgemmDescr->externalBuffer5) + byteOffset5); // Use external buffer for values array as the original values array may have data in it // that must be accounted for when multiplying by beta. See below. RETURN_IF_HIPSPARSE_ERROR( hipsparseCsrSetPointers(matC, csrRowOffsetsC, csrColIndC, csrValuesCFromBuffer5)); size_t bufferSize = (spgemmDescr->bufferSize4 - byteOffset4); RETURN_IF_ROCSPARSE_ERROR( rocsparse_spgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), to_rocsparse_const_spmat_descr(matB), nullptr, to_rocsparse_const_spmat_descr(matC), to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpGEMMAlgToHCCSpGEMMAlg(alg), rocsparse_spgemm_stage_numeric, &bufferSize, static_cast(spgemmDescr->externalBuffer4) + byteOffset4)); // Get pointer mode hipsparsePointerMode_t pointer_mode; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetPointerMode(handle, &pointer_mode)); hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); float host_sone = 1.0f; double host_done = 1.0f; hipComplex host_cone = make_hipComplex(1.0f, 0.0f); hipDoubleComplex host_zone = make_hipDoubleComplex(1.0, 0.0); void* one = nullptr; if(pointer_mode == HIPSPARSE_POINTER_MODE_HOST) { if(computeType == HIP_R_32F) one = &host_sone; if(computeType == HIP_R_64F) one = &host_done; if(computeType == HIP_C_32F) one = &host_cone; if(computeType == HIP_C_64F) one = &host_zone; } else { if(computeType == HIP_R_32F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_sone, sizeof(float), hipMemcpyHostToDevice, stream)); one = device_one; } if(computeType == HIP_R_64F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_done, sizeof(double), hipMemcpyHostToDevice, stream)); one = device_one; } if(computeType == HIP_C_32F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_cone, sizeof(hipComplex), hipMemcpyHostToDevice, stream)); one = device_one; } if(computeType == HIP_C_64F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_zone, sizeof(hipDoubleComplex), hipMemcpyHostToDevice, stream)); one = device_one; } } if(csrColIndTypeC == HIPSPARSE_INDEX_32I) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_set_identity_permutation((rocsparse_handle)handle, nnzC, static_cast(indicesArray), rocsparse_indextype_i32)); } else if(csrColIndTypeC == HIPSPARSE_INDEX_64I) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_set_identity_permutation((rocsparse_handle)handle, nnzC, static_cast(indicesArray), rocsparse_indextype_i64)); } else { return HIPSPARSE_STATUS_NOT_SUPPORTED; } hipsparseConstSpVecDescr_t vecX; RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateConstSpVec(&vecX, nnzC, nnzC, indicesArray, csrValuesCFromBuffer5, csrColIndTypeC, HIPSPARSE_INDEX_BASE_ZERO, csrValueTypeC)); hipsparseDnVecDescr_t vecY; RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateDnVec(&vecY, nnzC, csrValuesC, csrValueTypeC)); // Axpby computes: Y = alpha * X + beta * Y // What we want to compute: csrValuesC = 1.0 * csrValuesCFromBuffer5 + beta * csrValuesC RETURN_IF_HIPSPARSE_ERROR(hipsparseAxpby(handle, one, vecX, beta, vecY)); RETURN_IF_HIPSPARSE_ERROR(hipsparseDestroySpVec(vecX)); RETURN_IF_HIPSPARSE_ERROR(hipsparseDestroyDnVec(vecY)); // Finally, update C matrix RETURN_IF_HIPSPARSE_ERROR( hipsparseCsrSetPointers(matC, csrRowOffsetsC, csrColIndC, csrValuesC)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/generic/hipsparse_spgemm.cpp0000664000175100017510000005363315176134511023125 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" struct hipsparseSpGEMMDescr { size_t bufferSize1{}; size_t bufferSize2{}; size_t bufferSize3{}; size_t bufferSize4{}; size_t bufferSize5{}; void* externalBuffer1{}; void* externalBuffer2{}; void* externalBuffer3{}; void* externalBuffer4{}; void* externalBuffer5{}; }; hipsparseStatus_t hipsparseSpGEMM_createDescr(hipsparseSpGEMMDescr_t* descr) { *descr = new hipsparseSpGEMMDescr; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpGEMM_destroyDescr(hipsparseSpGEMMDescr_t descr) { // Check if info structure has been created if(descr != nullptr) { descr->externalBuffer1 = nullptr; descr->externalBuffer2 = nullptr; descr->externalBuffer3 = nullptr; descr->externalBuffer4 = nullptr; descr->externalBuffer5 = nullptr; delete descr; } return HIPSPARSE_STATUS_SUCCESS; } namespace hipsparse { static hipsparseStatus_t getIndexTypeSize(hipsparseIndexType_t indexType, size_t& size) { switch(indexType) { case HIPSPARSE_INDEX_16U: { size = sizeof(uint16_t); return HIPSPARSE_STATUS_SUCCESS; } case HIPSPARSE_INDEX_32I: { size = sizeof(int32_t); return HIPSPARSE_STATUS_SUCCESS; } case HIPSPARSE_INDEX_64I: { size = sizeof(int64_t); return HIPSPARSE_STATUS_SUCCESS; } } size = 0; return HIPSPARSE_STATUS_INVALID_VALUE; } static hipsparseStatus_t getDataTypeSize(hipDataType dataType, size_t& size) { switch(dataType) { case HIP_R_32F: { size = sizeof(float); return HIPSPARSE_STATUS_SUCCESS; } case HIP_R_64F: { size = sizeof(double); return HIPSPARSE_STATUS_SUCCESS; } case HIP_C_32F: { size = sizeof(hipComplex); return HIPSPARSE_STATUS_SUCCESS; } case HIP_C_64F: { size = sizeof(hipDoubleComplex); return HIPSPARSE_STATUS_SUCCESS; } default: { size = 0; return HIPSPARSE_STATUS_INVALID_VALUE; } } size = 0; return HIPSPARSE_STATUS_INVALID_VALUE; } } hipsparseStatus_t hipsparseSpGEMM_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1) { // Match cusparse error handling if(handle == nullptr || alpha == nullptr || beta == nullptr || matA == nullptr || matB == nullptr || matC == nullptr || bufferSize1 == nullptr || spgemmDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get data stored in C matrix int64_t rowsC, colsC, nnzC; void* csrRowOffsetsC; void* csrColIndC; void* csrValuesC; hipsparseIndexType_t csrRowOffsetsTypeC; hipsparseIndexType_t csrColIndTypeC; hipsparseIndexBase_t idxBaseC; hipDataType csrValueTypeC; RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrGet(matC, &rowsC, &colsC, &nnzC, &csrRowOffsetsC, &csrColIndC, &csrValuesC, &csrRowOffsetsTypeC, &csrColIndTypeC, &idxBaseC, &csrValueTypeC)); size_t csrRowOffsetsTypeSizeC; RETURN_IF_HIPSPARSE_ERROR( hipsparse::getIndexTypeSize(csrRowOffsetsTypeC, csrRowOffsetsTypeSizeC)); if(externalBuffer1 == nullptr) { // Query for required buffer size RETURN_IF_ROCSPARSE_ERROR(rocsparse_spgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), to_rocsparse_const_spmat_descr(matB), nullptr, to_rocsparse_const_spmat_descr(matC), to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpGEMMAlgToHCCSpGEMMAlg(alg), rocsparse_spgemm_stage_buffer_size, bufferSize1, nullptr)); // Add space for storing matC row ptr array *bufferSize1 += ((csrRowOffsetsTypeSizeC * (rowsC + 1) - 1) / 256 + 1) * 256; spgemmDescr->bufferSize1 = *bufferSize1; } else { spgemmDescr->externalBuffer1 = externalBuffer1; void* csrRowOffsetsCFromBuffer1 = spgemmDescr->externalBuffer1; size_t byteOffset1 = ((csrRowOffsetsTypeSizeC * (rowsC + 1) - 1) / 256 + 1) * 256; // Temporarily set in C matrix in order to compute C row pointer array (stored in externalBuffer1) RETURN_IF_HIPSPARSE_ERROR( hipsparseCsrSetPointers(matC, csrRowOffsetsCFromBuffer1, csrColIndC, csrValuesC)); // Compute number of non-zeros in C matrix size_t bufferSize = (spgemmDescr->bufferSize1 - byteOffset1); RETURN_IF_ROCSPARSE_ERROR( rocsparse_spgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), to_rocsparse_const_spmat_descr(matB), nullptr, to_rocsparse_const_spmat_descr(matC), to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpGEMMAlgToHCCSpGEMMAlg(alg), rocsparse_spgemm_stage_nnz, &bufferSize, (static_cast(spgemmDescr->externalBuffer1) + byteOffset1))); } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpGEMM_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2) { if(handle == nullptr || alpha == nullptr || beta == nullptr || matA == nullptr || matB == nullptr || matC == nullptr || bufferSize2 == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get data stored in C matrix int64_t rowsC, colsC, nnzC; void* csrRowOffsetsC; void* csrColIndC; void* csrValuesC; hipsparseIndexType_t csrRowOffsetsTypeC; hipsparseIndexType_t csrColIndTypeC; hipsparseIndexBase_t idxBaseC; hipDataType csrValueTypeC; RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrGet(matC, &rowsC, &colsC, &nnzC, &csrRowOffsetsC, &csrColIndC, &csrValuesC, &csrRowOffsetsTypeC, &csrColIndTypeC, &idxBaseC, &csrValueTypeC)); size_t csrRowOffsetsTypeSizeC; size_t csrColIndTypeSizeC; size_t csrValueTypeSizeC; RETURN_IF_HIPSPARSE_ERROR( hipsparse::getIndexTypeSize(csrRowOffsetsTypeC, csrRowOffsetsTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getIndexTypeSize(csrColIndTypeC, csrColIndTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getDataTypeSize(csrValueTypeC, csrValueTypeSizeC)); size_t computeTypeSize; RETURN_IF_HIPSPARSE_ERROR(hipsparse::getDataTypeSize(computeType, computeTypeSize)); if(externalBuffer2 == nullptr) { *bufferSize2 = 0; // Need to store temporary space for C matrix column indices and values arrays *bufferSize2 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; *bufferSize2 += ((csrValueTypeSizeC * nnzC - 1) / 256 + 1) * 256; // Need to store temporary space for indices array used in hipsparseSpGEMM_copy Axpby *bufferSize2 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; // Need to store temporary space for host/device 1 value used in hipsparseSpGEMM_copy Axpby *bufferSize2 += ((computeTypeSize - 1) / 256 + 1) * 256; spgemmDescr->bufferSize2 = *bufferSize2; } else { spgemmDescr->externalBuffer2 = externalBuffer2; size_t byteOffset1 = 0; size_t byteOffset2 = 0; void* csrRowOffsetsCFromBuffer1 = spgemmDescr->externalBuffer1; byteOffset1 += ((csrRowOffsetsTypeSizeC * (rowsC + 1) - 1) / 256 + 1) * 256; void* csrColIndCFromBuffer2 = spgemmDescr->externalBuffer2; byteOffset2 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; void* csrValuesCFromBuffer2 = (static_cast(spgemmDescr->externalBuffer2) + byteOffset2); // Set pointers (which now point to the external buffers) so that we can perform the computation and have the results // temporarily stored in the external buffers. The data will then be copied to the final output arrays in hipsparseSpGEMM_copy. RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrSetPointers( matC, csrRowOffsetsCFromBuffer1, csrColIndCFromBuffer2, csrValuesCFromBuffer2)); size_t bufferSize = (spgemmDescr->bufferSize1 - byteOffset1); RETURN_IF_ROCSPARSE_ERROR( rocsparse_spgemm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), to_rocsparse_const_spmat_descr(matB), nullptr, to_rocsparse_const_spmat_descr(matC), to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpGEMMAlgToHCCSpGEMMAlg(alg), rocsparse_spgemm_stage_compute, &bufferSize, (static_cast(spgemmDescr->externalBuffer1) + byteOffset1))); } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpGEMM_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr) { if(handle == nullptr || alpha == nullptr || beta == nullptr || matA == nullptr || matB == nullptr || matC == nullptr || spgemmDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } // Get data stored in C matrix int64_t rowsC, colsC, nnzC; void* csrRowOffsetsC; void* csrColIndC; void* csrValuesC; hipsparseIndexType_t csrRowOffsetsTypeC; hipsparseIndexType_t csrColIndTypeC; hipsparseIndexBase_t idxBaseC; hipDataType csrValueTypeC; RETURN_IF_HIPSPARSE_ERROR(hipsparseCsrGet(matC, &rowsC, &colsC, &nnzC, &csrRowOffsetsC, &csrColIndC, &csrValuesC, &csrRowOffsetsTypeC, &csrColIndTypeC, &idxBaseC, &csrValueTypeC)); size_t csrRowOffsetsTypeSizeC; size_t csrColIndTypeSizeC; size_t csrValueTypeSizeC; RETURN_IF_HIPSPARSE_ERROR( hipsparse::getIndexTypeSize(csrRowOffsetsTypeC, csrRowOffsetsTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getIndexTypeSize(csrColIndTypeC, csrColIndTypeSizeC)); RETURN_IF_HIPSPARSE_ERROR(hipsparse::getDataTypeSize(csrValueTypeC, csrValueTypeSizeC)); size_t byteOffset2 = 0; void* csrRowOffsetsCFromBuffer1 = spgemmDescr->externalBuffer1; void* csrColIndCFromBuffer2 = spgemmDescr->externalBuffer2; byteOffset2 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; void* csrValuesCFromBuffer2 = (static_cast(spgemmDescr->externalBuffer2) + byteOffset2); byteOffset2 += ((csrValueTypeSizeC * nnzC - 1) / 256 + 1) * 256; void* indicesArray = (static_cast(spgemmDescr->externalBuffer2) + byteOffset2); byteOffset2 += ((csrColIndTypeSizeC * nnzC - 1) / 256 + 1) * 256; void* device_one = (static_cast(spgemmDescr->externalBuffer2) + byteOffset2); // Get pointer mode hipsparsePointerMode_t pointer_mode; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetPointerMode(handle, &pointer_mode)); hipStream_t stream; RETURN_IF_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); float host_sone = 1.0f; double host_done = 1.0f; hipComplex host_cone = make_hipComplex(1.0f, 0.0f); hipDoubleComplex host_zone = make_hipDoubleComplex(1.0, 0.0); void* one = nullptr; if(pointer_mode == HIPSPARSE_POINTER_MODE_HOST) { if(computeType == HIP_R_32F) one = &host_sone; if(computeType == HIP_R_64F) one = &host_done; if(computeType == HIP_C_32F) one = &host_cone; if(computeType == HIP_C_64F) one = &host_zone; } else { if(computeType == HIP_R_32F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_sone, sizeof(float), hipMemcpyHostToDevice, stream)); one = device_one; } if(computeType == HIP_R_64F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_done, sizeof(double), hipMemcpyHostToDevice, stream)); one = device_one; } if(computeType == HIP_C_32F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_cone, sizeof(hipComplex), hipMemcpyHostToDevice, stream)); one = device_one; } if(computeType == HIP_C_64F) { RETURN_IF_HIP_ERROR(hipMemcpyAsync( device_one, &host_zone, sizeof(hipDoubleComplex), hipMemcpyHostToDevice, stream)); one = device_one; } } if(csrColIndTypeC == HIPSPARSE_INDEX_32I) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_set_identity_permutation((rocsparse_handle)handle, nnzC, static_cast(indicesArray), rocsparse_indextype_i32)); } else if(csrColIndTypeC == HIPSPARSE_INDEX_64I) { RETURN_IF_ROCSPARSE_ERROR( rocsparse_set_identity_permutation((rocsparse_handle)handle, nnzC, static_cast(indicesArray), rocsparse_indextype_i64)); } else { return HIPSPARSE_STATUS_NOT_SUPPORTED; } // Copy data from external1 buffer to row pointer array RETURN_IF_HIP_ERROR(hipMemcpyAsync(csrRowOffsetsC, csrRowOffsetsCFromBuffer1, csrRowOffsetsTypeSizeC * (rowsC + 1), hipMemcpyDeviceToDevice, stream)); // Copy data from external2 buffer to column indices array RETURN_IF_HIP_ERROR(hipMemcpyAsync(csrColIndC, csrColIndCFromBuffer2, csrColIndTypeSizeC * nnzC, hipMemcpyDeviceToDevice, stream)); hipsparseConstSpVecDescr_t vecX; RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateConstSpVec(&vecX, nnzC, nnzC, indicesArray, csrValuesCFromBuffer2, csrColIndTypeC, HIPSPARSE_INDEX_BASE_ZERO, csrValueTypeC)); hipsparseDnVecDescr_t vecY; RETURN_IF_HIPSPARSE_ERROR(hipsparseCreateDnVec(&vecY, nnzC, csrValuesC, csrValueTypeC)); // Axpby computes: Y = alpha * X + beta * Y // What we want to compute: csrValuesC = 1.0 * csrValuesCFromBuffer2 + beta * csrValuesC RETURN_IF_HIPSPARSE_ERROR(hipsparseAxpby(handle, one, vecX, beta, vecY)); RETURN_IF_HIPSPARSE_ERROR(hipsparseDestroySpVec(vecX)); RETURN_IF_HIPSPARSE_ERROR(hipsparseDestroyDnVec(vecY)); // Finally, update C matrix RETURN_IF_HIPSPARSE_ERROR( hipsparseCsrSetPointers(matC, csrRowOffsetsC, csrColIndC, csrValuesC)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/generic/hipsparse_spmv.cpp0000664000175100017510000005601015176134305022613 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpMV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, size_t* pBufferSizeInBytes) { if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(alpha == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(matA == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(vecX == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(beta == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(vecY == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(pBufferSizeInBytes == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } const rocsparse_datatype datatype = hipsparse::hipDataTypeToHCCDataType(computeType); const rocsparse_operation operation = hipsparse::hipOperationToHCCOperation(opA); rocsparse_spmv_alg spmv_alg = hipsparse::hipSpMVAlgToHCCSpMVAlg(alg); // // Fallback algorithm? // if(spmv_alg == rocsparse_spmv_alg_csr_lrb) { rocsparse_matrix_type matrix_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_spmat_get_attribute(to_rocsparse_const_spmat_descr(matA), rocsparse_spmat_matrix_type, &matrix_type, sizeof(matrix_type))); if((matrix_type == rocsparse_matrix_type_symmetric) || (operation != rocsparse_operation_none)) { spmv_alg = rocsparse_spmv_alg_csr_rowsplit; } } else if((spmv_alg == rocsparse_spmv_alg_csr_adaptive) && (operation != rocsparse_operation_none)) { spmv_alg = rocsparse_spmv_alg_csr_rowsplit; } hipsparseSpMVDescr_st* hip_spmv_descr = matA->get_hip_spmv_descr(); // // If spmv_descr alreay exists, then destroy it. // rocsparse_spmv_descr spmv_descr = hip_spmv_descr->get_spmv_descr(); if(spmv_descr != nullptr) { RETURN_IF_ROCSPARSE_ERROR(rocsparse_destroy_spmv_descr(spmv_descr)); hip_spmv_descr->set_spmv_descr(nullptr); } // // Create spmv_descr. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_spmv_descr(&spmv_descr)); hip_spmv_descr->set_spmv_descr(spmv_descr); RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_alg, &spmv_alg, sizeof(spmv_alg), nullptr)); // // Set operation. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_operation, &operation, sizeof(operation), nullptr)); // // Set datatypes. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_scalar_datatype, &datatype, sizeof(datatype), nullptr)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_compute_datatype, &datatype, sizeof(datatype), nullptr)); // // Buffer size for the analysis phase. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_v2_spmv_buffer_size((rocsparse_handle)handle, spmv_descr, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)vecX, (rocsparse_dnvec_descr)vecY, rocsparse_v2_spmv_stage_analysis, pBufferSizeInBytes, nullptr)); hip_spmv_descr->set_buffer_size_stage_analysis(pBufferSizeInBytes[0]); hip_spmv_descr->buffer_size_called(); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpMV_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer) { if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(alpha == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(matA == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(vecX == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(beta == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(vecY == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } const rocsparse_datatype datatype = hipsparse::hipDataTypeToHCCDataType(computeType); const rocsparse_operation operation = hipsparse::hipOperationToHCCOperation(opA); rocsparse_spmv_alg spmv_alg = hipsparse::hipSpMVAlgToHCCSpMVAlg(alg); // // Fallback algorithm? // if(spmv_alg == rocsparse_spmv_alg_csr_lrb) { rocsparse_matrix_type matrix_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_spmat_get_attribute(to_rocsparse_const_spmat_descr(matA), rocsparse_spmat_matrix_type, &matrix_type, sizeof(matrix_type))); if((matrix_type == rocsparse_matrix_type_symmetric) || (operation != rocsparse_operation_none)) { spmv_alg = rocsparse_spmv_alg_csr_rowsplit; } } else if((spmv_alg == rocsparse_spmv_alg_csr_adaptive) && (operation != rocsparse_operation_none)) { spmv_alg = rocsparse_spmv_alg_csr_rowsplit; } hipsparseSpMVDescr_st* hip_spmv_descr = matA->get_hip_spmv_descr(); rocsparse_spmv_descr spmv_descr = hip_spmv_descr->get_spmv_descr(); if(spmv_descr == nullptr) { // // Create spmv_descr. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_spmv_descr(&spmv_descr)); hip_spmv_descr->set_spmv_descr(spmv_descr); RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_alg, &spmv_alg, sizeof(spmv_alg), nullptr)); // // Set operation. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_operation, &operation, sizeof(operation), nullptr)); // // Set datatypes. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_scalar_datatype, &datatype, sizeof(datatype), nullptr)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_compute_datatype, &datatype, sizeof(datatype), nullptr)); } RETURN_IF_ROCSPARSE_ERROR(rocsparse_v2_spmv((rocsparse_handle)handle, spmv_descr, alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)vecX, beta, (rocsparse_dnvec_descr)vecY, rocsparse_v2_spmv_stage_analysis, hip_spmv_descr->get_buffer_size_stage_analysis(), externalBuffer, nullptr)); hip_spmv_descr->stage_analysis_called(); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpMV(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer) { if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(alpha == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(matA == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(vecX == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(beta == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(vecY == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } const rocsparse_datatype datatype = hipsparse::hipDataTypeToHCCDataType(computeType); const rocsparse_operation operation = hipsparse::hipOperationToHCCOperation(opA); rocsparse_spmv_alg spmv_alg = hipsparse::hipSpMVAlgToHCCSpMVAlg(alg); hipsparseSpMVDescr_st* hip_spmv_descr = matA->get_hip_spmv_descr(); rocsparse_spmv_descr spmv_descr = hip_spmv_descr->get_spmv_descr(); if(spmv_descr == nullptr) { // // Create spmv_descr. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_create_spmv_descr(&spmv_descr)); hip_spmv_descr->set_spmv_descr(spmv_descr); if(spmv_alg == rocsparse_spmv_alg_csr_lrb) { rocsparse_matrix_type matrix_type; RETURN_IF_ROCSPARSE_ERROR( rocsparse_spmat_get_attribute(to_rocsparse_const_spmat_descr(matA), rocsparse_spmat_matrix_type, &matrix_type, sizeof(matrix_type))); if((matrix_type == rocsparse_matrix_type_symmetric) || (operation != rocsparse_operation_none)) { spmv_alg = rocsparse_spmv_alg_csr_rowsplit; } } else if((spmv_alg == rocsparse_spmv_alg_csr_adaptive) && (operation != rocsparse_operation_none)) { spmv_alg = rocsparse_spmv_alg_csr_rowsplit; } else if(((spmv_alg == rocsparse_spmv_alg_csr_adaptive) || (spmv_alg == rocsparse_spmv_alg_csr_lrb)) && (hip_spmv_descr->is_stage_analysis_called() == false)) { spmv_alg = rocsparse_spmv_alg_csr_rowsplit; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_alg, &spmv_alg, sizeof(spmv_alg), nullptr)); // // Set operation. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_operation, &operation, sizeof(operation), nullptr)); // // Set datatypes. // RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_scalar_datatype, &datatype, sizeof(datatype), nullptr)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_spmv_set_input((rocsparse_handle)handle, spmv_descr, rocsparse_spmv_input_compute_datatype, &datatype, sizeof(datatype), nullptr)); } if(hip_spmv_descr->is_stage_analysis_called() == false) { // // No analysis has been performed, we have to call the analysis since this is a requirement for v2_spmv. // if(hip_spmv_descr->is_implicit_stage_analysis_called() == false) { if(hip_spmv_descr->is_buffer_size_called() == false) { size_t buffer_size_in_bytes; RETURN_IF_ROCSPARSE_ERROR( rocsparse_v2_spmv_buffer_size((rocsparse_handle)handle, spmv_descr, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)vecX, (rocsparse_dnvec_descr)vecY, rocsparse_v2_spmv_stage_analysis, &buffer_size_in_bytes, nullptr)); hipStream_t stream{}; RETURN_IF_ROCSPARSE_ERROR(rocsparse_get_stream((rocsparse_handle)handle, &stream)); RETURN_IF_HIP_ERROR(hipMallocAsync( hip_spmv_descr->get_buffer_reference(), buffer_size_in_bytes, stream)); RETURN_IF_ROCSPARSE_ERROR(rocsparse_v2_spmv((rocsparse_handle)handle, spmv_descr, alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)vecX, beta, (const rocsparse_dnvec_descr)vecY, rocsparse_v2_spmv_stage_analysis, buffer_size_in_bytes, hip_spmv_descr->get_buffer(), nullptr)); RETURN_IF_HIP_ERROR(hipFreeAsync(hip_spmv_descr->get_buffer(), stream)); hip_spmv_descr->set_buffer(nullptr); } else { // // We can use the externalBuffer since the user is allocating a buffer for the analysis phase only, but the user // does not know it. // RETURN_IF_ROCSPARSE_ERROR( rocsparse_v2_spmv((rocsparse_handle)handle, spmv_descr, alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)vecX, beta, (const rocsparse_dnvec_descr)vecY, rocsparse_v2_spmv_stage_analysis, hip_spmv_descr->get_buffer_size_stage_analysis(), externalBuffer, nullptr)); } hip_spmv_descr->implicit_stage_analysis_called(); } // // We keep hip_spmv_descr->spmv_analysis_called = false; // because it hasn't been explicitly called. // } if(hip_spmv_descr->is_stage_compute_subsequent() == false) { // // Get the buffer size for the compute phase, the buffer size returned in hipsparseSpMV_bufferSize is the buffer size for the analysis phase. // size_t buffer_size_in_bytes; RETURN_IF_ROCSPARSE_ERROR( rocsparse_v2_spmv_buffer_size((rocsparse_handle)handle, spmv_descr, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)vecX, (rocsparse_dnvec_descr)vecY, rocsparse_v2_spmv_stage_compute, &buffer_size_in_bytes, nullptr)); hip_spmv_descr->set_buffer_size_stage_compute(buffer_size_in_bytes); hipStream_t stream{}; RETURN_IF_ROCSPARSE_ERROR(rocsparse_get_stream((rocsparse_handle)handle, &stream)); RETURN_IF_HIP_ERROR(hipMallocAsync(hip_spmv_descr->get_buffer_reference(), hip_spmv_descr->get_buffer_size_stage_compute(), stream)); hip_spmv_descr->stage_compute_subsequent(); } RETURN_IF_ROCSPARSE_ERROR(rocsparse_v2_spmv((rocsparse_handle)handle, spmv_descr, alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)vecX, beta, (rocsparse_dnvec_descr)vecY, rocsparse_v2_spmv_stage_compute, hip_spmv_descr->get_buffer_size_stage_compute(), hip_spmv_descr->get_buffer(), nullptr)); return HIPSPARSE_STATUS_SUCCESS; } ./library/src/amd_detail/generic/hipsparse_spmm.cpp0000664000175100017510000001410315176134305022577 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnmat_descr)matB, beta, (const rocsparse_dnmat_descr)matC, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpMMAlgToHCCSpMMAlg(alg), rocsparse_spmm_stage_buffer_size, pBufferSizeInBytes, nullptr)); } hipsparseStatus_t hipsparseSpMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer) { size_t bufferSize; return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnmat_descr)matB, beta, (const rocsparse_dnmat_descr)matC, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpMMAlgToHCCSpMMAlg(alg), rocsparse_spmm_stage_preprocess, &bufferSize, externalBuffer)); } hipsparseStatus_t hipsparseSpMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer) { size_t bufferSize; return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnmat_descr)matB, beta, (const rocsparse_dnmat_descr)matC, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpMMAlgToHCCSpMMAlg(alg), rocsparse_spmm_stage_compute, &bufferSize, externalBuffer)); } ./library/src/amd_detail/generic/hipsparse_sparse2dense.cpp0000664000175100017510000000611015176134305024220 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSparseToDense_bufferSize(hipsparseHandle_t handle, hipsparseConstSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sparse_to_dense((rocsparse_handle)handle, to_rocsparse_const_spmat_descr(matA), (rocsparse_dnmat_descr)matB, hipsparse::hipSpToDnAlgToHCCSpToDnAlg(alg), pBufferSizeInBytes, nullptr)); } hipsparseStatus_t hipsparseSparseToDense(hipsparseHandle_t handle, hipsparseConstSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, void* externalBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sparse_to_dense((rocsparse_handle)handle, to_rocsparse_const_spmat_descr(matA), (rocsparse_dnmat_descr)matB, hipsparse::hipSpToDnAlgToHCCSpToDnAlg(alg), nullptr, externalBuffer)); } ./library/src/amd_detail/generic/hipsparse_sddmm.cpp0000664000175100017510000001401115176134305022725 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSDDMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sddmm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, (rocsparse_const_dnmat_descr)matA, (rocsparse_const_dnmat_descr)matB, beta, to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSDDMMAlgToHCCSDDMMAlg(alg), tempBuffer)); } hipsparseStatus_t hipsparseSDDMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sddmm_buffer_size((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, (rocsparse_const_dnmat_descr)matA, (rocsparse_const_dnmat_descr)matB, beta, to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSDDMMAlgToHCCSDDMMAlg(alg), pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSDDMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_sddmm_preprocess((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, (rocsparse_const_dnmat_descr)matA, (rocsparse_const_dnmat_descr)matB, beta, to_rocsparse_spmat_descr(matC), hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSDDMMAlgToHCCSDDMMAlg(alg), tempBuffer)); } ./library/src/amd_detail/generic/hipsparse_rot.cpp0000664000175100017510000000421615176134305022433 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseRot(hipsparseHandle_t handle, const void* c_coeff, const void* s_coeff, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_rot((rocsparse_handle)handle, c_coeff, s_coeff, (rocsparse_spvec_descr)vecX, (rocsparse_dnvec_descr)vecY)); } ./library/src/amd_detail/generic/hipsparse_dense2sparse.cpp0000664000175100017510000001001315176134305024215 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseDenseToSparse_bufferSize(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dense_to_sparse((rocsparse_handle)handle, (rocsparse_const_dnmat_descr)matA, to_rocsparse_spmat_descr(matB), hipsparse::hipDnToSpAlgToHCCDnToSpAlg(alg), pBufferSizeInBytes, nullptr)); } hipsparseStatus_t hipsparseDenseToSparse_analysis(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dense_to_sparse((rocsparse_handle)handle, (rocsparse_const_dnmat_descr)matA, to_rocsparse_spmat_descr(matB), hipsparse::hipDnToSpAlgToHCCDnToSpAlg(alg), nullptr, externalBuffer)); } hipsparseStatus_t hipsparseDenseToSparse_convert(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer) { size_t bufferSize = 4; return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_dense_to_sparse((rocsparse_handle)handle, (rocsparse_const_dnmat_descr)matA, to_rocsparse_spmat_descr(matB), hipsparse::hipDnToSpAlgToHCCDnToSpAlg(alg), externalBuffer != nullptr ? &bufferSize : nullptr, externalBuffer)); } ./library/src/amd_detail/generic/hipsparse_spvv.cpp0000664000175100017510000000704015176134305022623 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpVV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseConstSpVecDescr_t vecX, hipsparseConstDnVecDescr_t vecY, void* result, hipDataType computeType, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spvv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opX), (rocsparse_const_spvec_descr)vecX, (rocsparse_const_dnvec_descr)vecY, result, hipsparse::hipDataTypeToHCCDataType(computeType), pBufferSizeInBytes, nullptr)); } hipsparseStatus_t hipsparseSpVV(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseConstSpVecDescr_t vecX, hipsparseConstDnVecDescr_t vecY, void* result, hipDataType computeType, void* externalBuffer) { size_t bufferSize; // Check for buffer == nullptr as this is not done in rocsparse if(externalBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spvv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opX), (rocsparse_const_spvec_descr)vecX, (rocsparse_const_dnvec_descr)vecY, result, hipsparse::hipDataTypeToHCCDataType(computeType), &bufferSize, externalBuffer)); } ./library/src/amd_detail/generic/hipsparse_spsm.cpp0000664000175100017510000001651015176134511022610 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" struct hipsparseSpSMDescr { void* externalBuffer{}; }; hipsparseStatus_t hipsparseSpSM_createDescr(hipsparseSpSMDescr_t* descr) { *descr = new hipsparseSpSMDescr; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpSM_destroyDescr(hipsparseSpSMDescr_t descr) { if(descr != nullptr) { descr->externalBuffer = nullptr; delete descr; } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpSM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, size_t* pBufferSizeInBytes) { if(spsmDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_spsm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnmat_descr)matB, (const rocsparse_dnmat_descr)matC, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpSMAlgToHCCSpSMAlg(alg), rocsparse_spsm_stage_buffer_size, pBufferSizeInBytes, nullptr)); pBufferSizeInBytes[0] = std::max(pBufferSizeInBytes[0], sizeof(int32_t)); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpSM_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer) { if(spsmDescr == nullptr || externalBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_spsm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnmat_descr)matB, (const rocsparse_dnmat_descr)matC, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpSMAlgToHCCSpSMAlg(alg), rocsparse_spsm_stage_preprocess, nullptr, externalBuffer)); spsmDescr->externalBuffer = externalBuffer; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpSM_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer) { if(spsmDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spsm((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), hipsparse::hipOperationToHCCOperation(opB), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnmat_descr)matB, (const rocsparse_dnmat_descr)matC, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpSMAlgToHCCSpSMAlg(alg), rocsparse_spsm_stage_compute, nullptr, spsmDescr->externalBuffer)); } ./library/src/amd_detail/generic/hipsparse_spsv.cpp0000664000175100017510000001452215176134305022623 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" struct hipsparseSpSVDescr { void* externalBuffer{}; }; hipsparseStatus_t hipsparseSpSV_createDescr(hipsparseSpSVDescr_t* descr) { *descr = new hipsparseSpSVDescr; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpSV_destroyDescr(hipsparseSpSVDescr_t descr) { if(descr != nullptr) { descr->externalBuffer = nullptr; delete descr; } return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpSV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, size_t* pBufferSizeInBytes) { return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spsv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)x, (const rocsparse_dnvec_descr)y, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpSVAlgToHCCSpSVAlg(alg), rocsparse_spsv_stage_buffer_size, pBufferSizeInBytes, nullptr)); } hipsparseStatus_t hipsparseSpSV_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, void* externalBuffer) { if(spsvDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } RETURN_IF_ROCSPARSE_ERROR(rocsparse_spsv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)x, (const rocsparse_dnvec_descr)y, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpSVAlgToHCCSpSVAlg(alg), rocsparse_spsv_stage_preprocess, nullptr, externalBuffer)); spsvDescr->externalBuffer = externalBuffer; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSpSV_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr) { if(spsvDescr == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } return hipsparse::rocSPARSEStatusToHIPStatus( rocsparse_spsv((rocsparse_handle)handle, hipsparse::hipOperationToHCCOperation(opA), alpha, to_rocsparse_const_spmat_descr(matA), (rocsparse_const_dnvec_descr)x, (const rocsparse_dnvec_descr)y, hipsparse::hipDataTypeToHCCDataType(computeType), hipsparse::hipSpSVAlgToHCCSpSVAlg(alg), rocsparse_spsv_stage_compute, nullptr, spsvDescr->externalBuffer)); } ./library/src/amd_detail/generic/hipsparse_gather.cpp0000664000175100017510000000345615176134305023106 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseGather(hipsparseHandle_t handle, hipsparseConstDnVecDescr_t vecY, hipsparseSpVecDescr_t vecX) { return hipsparse::rocSPARSEStatusToHIPStatus(rocsparse_gather( (rocsparse_handle)handle, (rocsparse_const_dnvec_descr)vecY, (rocsparse_spvec_descr)vecX)); } ./library/src/amd_detail/utility.h0000664000175100017510000006071215176134511017307 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #define TO_STR2(x) #x #define TO_STR(x) TO_STR2(x) #define RETURN_IF_HIP_ERROR(INPUT_STATUS_FOR_CHECK) \ { \ hipError_t TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ if(TMP_STATUS_FOR_CHECK != hipSuccess) \ { \ return hipsparse::hipErrorToHIPSPARSEStatus(TMP_STATUS_FOR_CHECK); \ } \ } #define RETURN_IF_HIPSPARSE_ERROR(INPUT_STATUS_FOR_CHECK) \ { \ hipsparseStatus_t TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ if(TMP_STATUS_FOR_CHECK != HIPSPARSE_STATUS_SUCCESS) \ { \ return TMP_STATUS_FOR_CHECK; \ } \ } #define RETURN_IF_ROCSPARSE_ERROR(INPUT_STATUS_FOR_CHECK) \ { \ rocsparse_status TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ if(TMP_STATUS_FOR_CHECK != rocsparse_status_success) \ { \ return hipsparse::rocSPARSEStatusToHIPStatus(TMP_STATUS_FOR_CHECK); \ } \ } namespace hipsparse { inline hipsparseStatus_t hipErrorToHIPSPARSEStatus(hipError_t status) { switch(status) { case hipSuccess: return HIPSPARSE_STATUS_SUCCESS; case hipErrorMemoryAllocation: case hipErrorLaunchOutOfResources: return HIPSPARSE_STATUS_ALLOC_FAILED; case hipErrorInvalidDevicePointer: return HIPSPARSE_STATUS_INVALID_VALUE; case hipErrorInvalidDevice: case hipErrorInvalidResourceHandle: return HIPSPARSE_STATUS_NOT_INITIALIZED; case hipErrorInvalidValue: return HIPSPARSE_STATUS_INVALID_VALUE; case hipErrorNoDevice: case hipErrorUnknown: return HIPSPARSE_STATUS_INTERNAL_ERROR; default: return HIPSPARSE_STATUS_INTERNAL_ERROR; } } inline hipsparseStatus_t rocSPARSEStatusToHIPStatus(rocsparse_status_ status) { switch(status) { case rocsparse_status_success: return HIPSPARSE_STATUS_SUCCESS; case rocsparse_status_invalid_handle: return HIPSPARSE_STATUS_INVALID_VALUE; case rocsparse_status_not_implemented: return HIPSPARSE_STATUS_NOT_SUPPORTED; case rocsparse_status_invalid_pointer: return HIPSPARSE_STATUS_INVALID_VALUE; case rocsparse_status_invalid_size: return HIPSPARSE_STATUS_INVALID_VALUE; case rocsparse_status_memory_error: return HIPSPARSE_STATUS_ALLOC_FAILED; case rocsparse_status_internal_error: return HIPSPARSE_STATUS_INTERNAL_ERROR; case rocsparse_status_invalid_value: return HIPSPARSE_STATUS_INVALID_VALUE; case rocsparse_status_arch_mismatch: return HIPSPARSE_STATUS_ARCH_MISMATCH; case rocsparse_status_zero_pivot: return HIPSPARSE_STATUS_ZERO_PIVOT; case rocsparse_status_not_initialized: return HIPSPARSE_STATUS_NOT_INITIALIZED; case rocsparse_status_type_mismatch: case rocsparse_status_requires_sorted_storage: case rocsparse_status_thrown_exception: return HIPSPARSE_STATUS_INTERNAL_ERROR; case rocsparse_status_continue: return HIPSPARSE_STATUS_SUCCESS; default: throw "Non existent rocsparse_status"; } } inline rocsparse_status_ hipSPARSEStatusToRocSPARSEStatus(hipsparseStatus_t status) { switch(status) { case HIPSPARSE_STATUS_SUCCESS: return rocsparse_status_success; case HIPSPARSE_STATUS_NOT_INITIALIZED: return rocsparse_status_not_initialized; case HIPSPARSE_STATUS_ALLOC_FAILED: return rocsparse_status_memory_error; case HIPSPARSE_STATUS_INVALID_VALUE: return rocsparse_status_invalid_value; case HIPSPARSE_STATUS_ARCH_MISMATCH: return rocsparse_status_arch_mismatch; case HIPSPARSE_STATUS_MAPPING_ERROR: case HIPSPARSE_STATUS_EXECUTION_FAILED: case HIPSPARSE_STATUS_INTERNAL_ERROR: case HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: return rocsparse_status_internal_error; case HIPSPARSE_STATUS_ZERO_PIVOT: return rocsparse_status_zero_pivot; case HIPSPARSE_STATUS_NOT_SUPPORTED: return rocsparse_status_not_implemented; case HIPSPARSE_STATUS_INSUFFICIENT_RESOURCES: return rocsparse_status_internal_error; default: throw "Non existent hipsparseStatus_t"; } } inline rocsparse_pointer_mode_ hipPtrModeToHCCPtrMode(hipsparsePointerMode_t mode) { switch(mode) { case HIPSPARSE_POINTER_MODE_HOST: return rocsparse_pointer_mode_host; case HIPSPARSE_POINTER_MODE_DEVICE: return rocsparse_pointer_mode_device; default: throw "Non existent hipsparsePointerMode_t"; } } inline hipsparsePointerMode_t HCCPtrModeToHIPPtrMode(rocsparse_pointer_mode_ mode) { switch(mode) { case rocsparse_pointer_mode_host: return HIPSPARSE_POINTER_MODE_HOST; case rocsparse_pointer_mode_device: return HIPSPARSE_POINTER_MODE_DEVICE; default: throw "Non existent rocsparse_pointer_mode"; } } inline rocsparse_action_ hipActionToHCCAction(hipsparseAction_t action) { switch(action) { case HIPSPARSE_ACTION_SYMBOLIC: return rocsparse_action_symbolic; case HIPSPARSE_ACTION_NUMERIC: return rocsparse_action_numeric; default: throw "Non existent hipsparseAction_t"; } } inline rocsparse_matrix_type_ hipMatTypeToHCCMatType(hipsparseMatrixType_t type) { switch(type) { case HIPSPARSE_MATRIX_TYPE_GENERAL: return rocsparse_matrix_type_general; case HIPSPARSE_MATRIX_TYPE_SYMMETRIC: return rocsparse_matrix_type_symmetric; case HIPSPARSE_MATRIX_TYPE_HERMITIAN: return rocsparse_matrix_type_hermitian; case HIPSPARSE_MATRIX_TYPE_TRIANGULAR: return rocsparse_matrix_type_triangular; default: throw "Non existent hipsparseMatrixType_t"; } } inline hipsparseMatrixType_t HCCMatTypeToHIPMatType(rocsparse_matrix_type_ type) { switch(type) { case rocsparse_matrix_type_general: return HIPSPARSE_MATRIX_TYPE_GENERAL; case rocsparse_matrix_type_symmetric: return HIPSPARSE_MATRIX_TYPE_SYMMETRIC; case rocsparse_matrix_type_hermitian: return HIPSPARSE_MATRIX_TYPE_HERMITIAN; case rocsparse_matrix_type_triangular: return HIPSPARSE_MATRIX_TYPE_TRIANGULAR; default: throw "Non existent rocsparse_matrix_type"; } } inline rocsparse_fill_mode_ hipFillModeToHCCFillMode(hipsparseFillMode_t fillMode) { switch(fillMode) { case HIPSPARSE_FILL_MODE_LOWER: return rocsparse_fill_mode_lower; case HIPSPARSE_FILL_MODE_UPPER: return rocsparse_fill_mode_upper; default: throw "Non existent hipsparseFillMode_t"; } } inline hipsparseFillMode_t HCCFillModeToHIPFillMode(rocsparse_fill_mode_ fillMode) { switch(fillMode) { case rocsparse_fill_mode_lower: return HIPSPARSE_FILL_MODE_LOWER; case rocsparse_fill_mode_upper: return HIPSPARSE_FILL_MODE_UPPER; default: throw "Non existent rocsparse_fill_mode"; } } inline rocsparse_diag_type_ hipDiagTypeToHCCDiagType(hipsparseDiagType_t diagType) { switch(diagType) { case HIPSPARSE_DIAG_TYPE_UNIT: return rocsparse_diag_type_unit; case HIPSPARSE_DIAG_TYPE_NON_UNIT: return rocsparse_diag_type_non_unit; default: throw "Non existent hipsparseDiagType_t"; } } inline hipsparseDiagType_t HCCDiagTypeToHIPDiagType(rocsparse_diag_type_ diagType) { switch(diagType) { case rocsparse_diag_type_unit: return HIPSPARSE_DIAG_TYPE_UNIT; case rocsparse_diag_type_non_unit: return HIPSPARSE_DIAG_TYPE_NON_UNIT; default: throw "Non existent rocsparse_diag_type"; } } inline rocsparse_index_base_ hipBaseToHCCBase(hipsparseIndexBase_t base) { switch(base) { case HIPSPARSE_INDEX_BASE_ZERO: return rocsparse_index_base_zero; case HIPSPARSE_INDEX_BASE_ONE: return rocsparse_index_base_one; default: throw "Non existent hipsparseIndexBase_t"; } } inline hipsparseIndexBase_t HCCBaseToHIPBase(rocsparse_index_base_ base) { switch(base) { case rocsparse_index_base_zero: return HIPSPARSE_INDEX_BASE_ZERO; case rocsparse_index_base_one: return HIPSPARSE_INDEX_BASE_ONE; default: throw "Non existent rocsparse_index_base"; } } inline rocsparse_operation_ hipOperationToHCCOperation(hipsparseOperation_t op) { switch(op) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: return rocsparse_operation_none; case HIPSPARSE_OPERATION_TRANSPOSE: return rocsparse_operation_transpose; case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: return rocsparse_operation_conjugate_transpose; default: throw "Non existent hipsparseOperation_t"; } } inline hipsparseOperation_t HCCOperationToHIPOperation(rocsparse_operation_ op) { switch(op) { case rocsparse_operation_none: return HIPSPARSE_OPERATION_NON_TRANSPOSE; case rocsparse_operation_transpose: return HIPSPARSE_OPERATION_TRANSPOSE; case rocsparse_operation_conjugate_transpose: return HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE; default: throw "Non existent rocsparse_operation"; } } inline rocsparse_hyb_partition_ hipHybPartToHCCHybPart(hipsparseHybPartition_t partition) { switch(partition) { case HIPSPARSE_HYB_PARTITION_AUTO: return rocsparse_hyb_partition_auto; case HIPSPARSE_HYB_PARTITION_USER: return rocsparse_hyb_partition_user; case HIPSPARSE_HYB_PARTITION_MAX: return rocsparse_hyb_partition_max; default: throw "Non existent hipsparseHybPartition_t"; } } inline hipsparseHybPartition_t HCCHybPartToHIPHybPart(rocsparse_hyb_partition_ partition) { switch(partition) { case rocsparse_hyb_partition_auto: return HIPSPARSE_HYB_PARTITION_AUTO; case rocsparse_hyb_partition_user: return HIPSPARSE_HYB_PARTITION_USER; case rocsparse_hyb_partition_max: return HIPSPARSE_HYB_PARTITION_MAX; default: throw "Non existent rocsparse_hyb_partition"; } } inline rocsparse_direction_ hipDirectionToHCCDirection(hipsparseDirection_t op) { switch(op) { case HIPSPARSE_DIRECTION_ROW: return rocsparse_direction_row; case HIPSPARSE_DIRECTION_COLUMN: return rocsparse_direction_column; default: throw "Non existent hipsparseDirection_t"; } } inline hipsparseDirection_t HCCDirectionToHIPDirection(rocsparse_direction_ op) { switch(op) { case rocsparse_direction_row: return HIPSPARSE_DIRECTION_ROW; case rocsparse_direction_column: return HIPSPARSE_DIRECTION_COLUMN; default: throw "Non existent rocsparse_direction"; } } inline rocsparse_order_ hipOrderToHCCOrder(hipsparseOrder_t op) { switch(op) { case HIPSPARSE_ORDER_ROW: return rocsparse_order_row; case HIPSPARSE_ORDER_COL: return rocsparse_order_column; default: throw "Non existent hipsparseOrder_t"; } } inline hipsparseOrder_t HCCOrderToHIPOrder(rocsparse_order_ op) { switch(op) { case rocsparse_order_row: return HIPSPARSE_ORDER_ROW; case rocsparse_order_column: return HIPSPARSE_ORDER_COL; default: throw "Non existent rocsparse_order"; } } inline rocsparse_indextype_ hipIndexTypeToHCCIndexType(hipsparseIndexType_t indextype) { switch(indextype) { case HIPSPARSE_INDEX_32I: return rocsparse_indextype_i32; case HIPSPARSE_INDEX_64I: return rocsparse_indextype_i64; default: throw "Non existent hipsparseIndexType_t"; } } inline hipsparseIndexType_t HCCIndexTypeToHIPIndexType(rocsparse_indextype_ indextype) { switch(indextype) { case rocsparse_indextype_i32: return HIPSPARSE_INDEX_32I; case rocsparse_indextype_i64: return HIPSPARSE_INDEX_64I; default: throw "Non existent rocsparse_indextype"; } } inline rocsparse_datatype_ hipDataTypeToHCCDataType(hipDataType datatype) { switch(datatype) { case HIP_R_8I: return rocsparse_datatype_i8_r; case HIP_R_32I: return rocsparse_datatype_i32_r; case HIP_R_16F: return rocsparse_datatype_f16_r; case HIP_R_16BF: return rocsparse_datatype_bf16_r; case HIP_R_32F: return rocsparse_datatype_f32_r; case HIP_R_64F: return rocsparse_datatype_f64_r; case HIP_C_32F: return rocsparse_datatype_f32_c; case HIP_C_64F: return rocsparse_datatype_f64_c; default: throw "Non existent hipDataType"; } } inline hipDataType HCCDataTypeToHIPDataType(rocsparse_datatype_ datatype) { switch(datatype) { case rocsparse_datatype_i8_r: return HIP_R_8I; case rocsparse_datatype_i32_r: return HIP_R_32I; case rocsparse_datatype_f16_r: return HIP_R_16F; case rocsparse_datatype_bf16_r: return HIP_R_16BF; case rocsparse_datatype_f32_r: return HIP_R_32F; case rocsparse_datatype_f64_r: return HIP_R_64F; case rocsparse_datatype_f32_c: return HIP_C_32F; case rocsparse_datatype_f64_c: return HIP_C_64F; default: throw "Non existent rocsparse_datatype"; } } inline rocsparse_spmv_alg_ hipSpMVAlgToHCCSpMVAlg(hipsparseSpMVAlg_t alg) { switch(alg) { // case HIPSPARSE_MV_ALG_DEFAULT: case HIPSPARSE_SPMV_ALG_DEFAULT: return rocsparse_spmv_alg_default; // case HIPSPARSE_COOMV_ALG: case HIPSPARSE_SPMV_COO_ALG1: case HIPSPARSE_SPMV_COO_ALG2: return rocsparse_spmv_alg_coo; // case HIPSPARSE_CSRMV_ALG1: case HIPSPARSE_SPMV_CSR_ALG1: return rocsparse_spmv_alg_csr_adaptive; // case HIPSPARSE_CSRMV_ALG2: case HIPSPARSE_SPMV_CSR_ALG2: return rocsparse_spmv_alg_csr_stream; default: throw "Non existent hipsparseSpMVAlg_t"; } } inline rocsparse_spmm_alg_ hipSpMMAlgToHCCSpMMAlg(hipsparseSpMMAlg_t alg) { switch(alg) { // case HIPSPARSE_MM_ALG_DEFAULT: case HIPSPARSE_SPMM_ALG_DEFAULT: return rocsparse_spmm_alg_default; // case HIPSPARSE_COOMM_ALG1: case HIPSPARSE_SPMM_COO_ALG1: return rocsparse_spmm_alg_coo_atomic; // case HIPSPARSE_COOMM_ALG2: case HIPSPARSE_SPMM_COO_ALG2: return rocsparse_spmm_alg_coo_segmented; // case HIPSPARSE_COOMM_ALG3: case HIPSPARSE_SPMM_COO_ALG3: case HIPSPARSE_SPMM_COO_ALG4: return rocsparse_spmm_alg_coo_segmented_atomic; // case HIPSPARSE_CSRMM_ALG1: case HIPSPARSE_SPMM_CSR_ALG1: return rocsparse_spmm_alg_csr_row_split; case HIPSPARSE_SPMM_CSR_ALG2: case HIPSPARSE_SPMM_CSR_ALG3: return rocsparse_spmm_alg_csr; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return rocsparse_spmm_alg_bell; default: throw "Non existent hipsparseSpMMAlg_t"; } } inline rocsparse_sparse_to_dense_alg_ hipSpToDnAlgToHCCSpToDnAlg(hipsparseSparseToDenseAlg_t alg) { switch(alg) { case HIPSPARSE_SPARSETODENSE_ALG_DEFAULT: return rocsparse_sparse_to_dense_alg_default; default: throw "Non existent hipsparseSparseToDenseAlg_t"; } } inline hipsparseSparseToDenseAlg_t HCCSpToDnAlgToHipSpToDnAlg(rocsparse_sparse_to_dense_alg_ alg) { switch(alg) { case rocsparse_sparse_to_dense_alg_default: return HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; default: throw "Non existent rocsparse_sparse_to_dense_alg"; } } inline rocsparse_dense_to_sparse_alg_ hipDnToSpAlgToHCCDnToSpAlg(hipsparseDenseToSparseAlg_t alg) { switch(alg) { case HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT: return rocsparse_dense_to_sparse_alg_default; default: throw "Non existent hipsparseDenseToSparseAlg_t"; } } inline hipsparseDenseToSparseAlg_t HCCDnToSpAlgToHipDnToSpAlg(rocsparse_dense_to_sparse_alg_ alg) { switch(alg) { case rocsparse_dense_to_sparse_alg_default: return HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; default: throw "Non existent rocsparse_dense_to_sparse_alg"; } } inline rocsparse_spgemm_alg_ hipSpGEMMAlgToHCCSpGEMMAlg(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: case HIPSPARSE_SPGEMM_ALG1: case HIPSPARSE_SPGEMM_ALG2: case HIPSPARSE_SPGEMM_ALG3: return rocsparse_spgemm_alg_default; default: throw "Non existent hipSpGEMMAlg_t"; } } inline rocsparse_sddmm_alg_ hipSDDMMAlgToHCCSDDMMAlg(hipsparseSDDMMAlg_t alg) { switch(alg) { case HIPSPARSE_SDDMM_ALG_DEFAULT: return rocsparse_sddmm_alg_default; default: throw "Non existent hipSDDMMAlg_t"; } } inline rocsparse_spsv_alg_ hipSpSVAlgToHCCSpSVAlg(hipsparseSpSVAlg_t alg) { switch(alg) { case HIPSPARSE_SPSV_ALG_DEFAULT: return rocsparse_spsv_alg_default; default: throw "Non existent hipsparseSpSVAlg_t"; } } inline rocsparse_spsm_alg_ hipSpSMAlgToHCCSpSMAlg(hipsparseSpSMAlg_t alg) { switch(alg) { case HIPSPARSE_SPSM_ALG_DEFAULT: return rocsparse_spsm_alg_default; default: throw "Non existent hipsparseSpSMAlg_t"; } } inline rocsparse_format_ hipFormatToHCCFormat(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_CSR: return rocsparse_format_csr; case HIPSPARSE_FORMAT_CSC: return rocsparse_format_csc; case HIPSPARSE_FORMAT_COO: return rocsparse_format_coo; case HIPSPARSE_FORMAT_COO_AOS: return rocsparse_format_coo_aos; case HIPSPARSE_FORMAT_BLOCKED_ELL: return rocsparse_format_bell; default: throw "Non existent hipsparseFormat_t"; } } inline hipsparseFormat_t HCCFormatToHIPFormat(rocsparse_format_ format) { switch(format) { case rocsparse_format_csr: return HIPSPARSE_FORMAT_CSR; case rocsparse_format_csc: return HIPSPARSE_FORMAT_CSC; case rocsparse_format_coo: return HIPSPARSE_FORMAT_COO; case rocsparse_format_coo_aos: return HIPSPARSE_FORMAT_COO_AOS; case rocsparse_format_bell: return HIPSPARSE_FORMAT_BLOCKED_ELL; default: throw "Non existent rocsparse_format"; } } } struct hipsparseSpMVDescr_st { protected: rocsparse_spmv_descr m_spmv_descr{}; bool m_is_stage_analysis_called{}; bool m_is_implicit_stage_analysis_called{}; size_t m_buffer_size_stage_analysis{}; size_t m_buffer_size_stage_compute{}; void* m_buffer{}; bool m_is_stage_compute_subsequent{}; bool m_is_buffer_size_called{}; public: rocsparse_spmv_descr get_spmv_descr(); void set_spmv_descr(rocsparse_spmv_descr value); bool is_stage_analysis_called() const; void stage_analysis_called(); bool is_implicit_stage_analysis_called() const; void implicit_stage_analysis_called(); bool is_stage_compute_subsequent() const; void stage_compute_subsequent(); bool is_buffer_size_called() const; void buffer_size_called(); size_t get_buffer_size_stage_analysis() const; void set_buffer_size_stage_analysis(size_t value); size_t get_buffer_size_stage_compute() const; void set_buffer_size_stage_compute(size_t value); void* get_buffer(); void set_buffer(void* value); void** get_buffer_reference(); hipsparseSpMVDescr_st() = default; ~hipsparseSpMVDescr_st(); }; struct hipsparseSpMatDescr_st { protected: rocsparse_spmat_descr m_spmat_descr{}; mutable hipsparseSpMVDescr_st m_hip_spmv_descr{}; public: hipsparseSpMatDescr_st() = default; ~hipsparseSpMatDescr_st() = default; hipsparseSpMVDescr_st* get_hip_spmv_descr(); hipsparseSpMVDescr_st* get_hip_spmv_descr() const; rocsparse_spmat_descr get_spmat_descr(); rocsparse_const_spmat_descr get_const_spmat_descr() const; rocsparse_spmat_descr* get_spmat_descr_reference(); rocsparse_const_spmat_descr* get_const_spmat_descr_reference() const; void set_spmat_descr(rocsparse_spmat_descr value); }; rocsparse_spmat_descr to_rocsparse_spmat_descr(const hipsparseSpMatDescr_t source); rocsparse_const_spmat_descr to_rocsparse_const_spmat_descr(const hipsparseConstSpMatDescr_t source); ./library/src/hipsparse-config.cmake.in0000664000175100017510000000427715176134305020225 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2018 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Configure hipsparse package to be used in another cmake project. # # Defines the following variables: # # hipsparse_INCLUDE_DIRS - include directories for hipsparse # # Also defines the library variables below as normal # variables. These contain debug/optimized keywords when # a debugging library is found. # # Accepts the following variables as input: # #----------------------- # Example Usage: # # find_package( hipsparse REQUIRED CONFIG # HINTS /package ) # # add_executable( foo foo.cc ) # # uses imported targets from package, including setting header paths # target_link_libraries( foo hipsparse ) # #----------------------- @PACKAGE_INIT@ set_and_check( hipsparse_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@" ) set_and_check( hipsparse_INCLUDE_DIRS "${hipsparse_INCLUDE_DIR}" ) set_and_check( hipsparse_LIB_INSTALL_DIR "@PACKAGE_LIB_INSTALL_DIR@" ) include( "${CMAKE_CURRENT_LIST_DIR}/hipsparse-targets.cmake" ) ./library/src/nvidia_detail/0000775000175100017510000000000015176134511016136 5ustar jenkinsjenkins./library/src/nvidia_detail/level1/0000775000175100017510000000000015176134461017332 5ustar jenkinsjenkins./library/src/nvidia_detail/level1/hipsparse_axpyi.cpp0000664000175100017510000001076215176134305023251 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSaxpyi(hipsparseHandle_t handle, int nnz, const float* alpha, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSaxpyi((cusparseHandle_t)handle, nnz, alpha, xVal, xInd, y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseDaxpyi(hipsparseHandle_t handle, int nnz, const double* alpha, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDaxpyi((cusparseHandle_t)handle, nnz, alpha, xVal, xInd, y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseCaxpyi(hipsparseHandle_t handle, int nnz, const hipComplex* alpha, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCaxpyi((cusparseHandle_t)handle, nnz, (const cuComplex*)alpha, (const cuComplex*)xVal, xInd, (cuComplex*)y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseZaxpyi(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZaxpyi((cusparseHandle_t)handle, nnz, (const cuDoubleComplex*)alpha, (const cuDoubleComplex*)xVal, xInd, (cuDoubleComplex*)y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif ./library/src/nvidia_detail/level1/hipsparse_dotci.cpp0000664000175100017510000000603015176134305023212 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseCdotci(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCdotci((cusparseHandle_t)handle, nnz, (const cuComplex*)xVal, xInd, (const cuComplex*)y, (cuComplex*)result, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseZdotci(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZdotci((cusparseHandle_t)handle, nnz, (const cuDoubleComplex*)xVal, xInd, (const cuDoubleComplex*)y, (cuDoubleComplex*)result, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif ./library/src/nvidia_detail/level1/hipsparse_gthrz.cpp0000664000175100017510000001006715176134305023253 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSgthrz(hipsparseHandle_t handle, int nnz, float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgthrz((cusparseHandle_t)handle, nnz, y, xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseDgthrz(hipsparseHandle_t handle, int nnz, double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgthrz((cusparseHandle_t)handle, nnz, y, xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseCgthrz(hipsparseHandle_t handle, int nnz, hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgthrz((cusparseHandle_t)handle, nnz, (cuComplex*)y, (cuComplex*)xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseZgthrz(hipsparseHandle_t handle, int nnz, hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgthrz((cusparseHandle_t)handle, nnz, (cuDoubleComplex*)y, (cuDoubleComplex*)xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif ./library/src/nvidia_detail/level1/hipsparse_gthr.cpp0000664000175100017510000001004515176134305023055 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSgthr(hipsparseHandle_t handle, int nnz, const float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgthr((cusparseHandle_t)handle, nnz, y, xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseDgthr(hipsparseHandle_t handle, int nnz, const double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgthr((cusparseHandle_t)handle, nnz, y, xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseCgthr(hipsparseHandle_t handle, int nnz, const hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgthr((cusparseHandle_t)handle, nnz, (const cuComplex*)y, (cuComplex*)xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseZgthr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgthr((cusparseHandle_t)handle, nnz, (const cuDoubleComplex*)y, (cuDoubleComplex*)xVal, xInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif ./library/src/nvidia_detail/level1/hipsparse_doti.cpp0000664000175100017510000001070215176134305023050 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseSdoti(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, const float* y, float* result, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSdoti((cusparseHandle_t)handle, nnz, xVal, xInd, y, result, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseDdoti(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, const double* y, double* result, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDdoti((cusparseHandle_t)handle, nnz, xVal, xInd, y, result, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseCdoti(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCdoti((cusparseHandle_t)handle, nnz, (const cuComplex*)xVal, xInd, (const cuComplex*)y, (cuComplex*)result, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseZdoti(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZdoti((cusparseHandle_t)handle, nnz, (const cuDoubleComplex*)xVal, xInd, (const cuDoubleComplex*)y, (cuDoubleComplex*)result, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif ./library/src/nvidia_detail/level1/hipsparse_sctr.cpp0000664000175100017510000001004515176134305023064 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSsctr(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSsctr((cusparseHandle_t)handle, nnz, xVal, xInd, y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseDsctr(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDsctr((cusparseHandle_t)handle, nnz, xVal, xInd, y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseCsctr(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCsctr((cusparseHandle_t)handle, nnz, (const cuComplex*)xVal, xInd, (cuComplex*)y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseZsctr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZsctr((cusparseHandle_t)handle, nnz, (const cuDoubleComplex*)xVal, xInd, (cuDoubleComplex*)y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif ./library/src/nvidia_detail/level1/hipsparse_roti.cpp0000664000175100017510000000600515176134305023067 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSroti(hipsparseHandle_t handle, int nnz, float* xVal, const int* xInd, float* y, const float* c, const float* s, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSroti((cusparseHandle_t)handle, nnz, xVal, xInd, y, c, s, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseDroti(hipsparseHandle_t handle, int nnz, double* xVal, const int* xInd, double* y, const double* c, const double* s, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDroti((cusparseHandle_t)handle, nnz, xVal, xInd, y, c, s, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif ./library/src/nvidia_detail/level3/0000775000175100017510000000000015176134461017334 5ustar jenkinsjenkins./library/src/nvidia_detail/level3/hipsparse_bsrsm.cpp0000664000175100017510000006770315176134305023256 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseXbsrsm2_zeroPivot(hipsparseHandle_t handle, bsrsm2Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXbsrsm2_zeroPivot((cusparseHandle_t)handle, (bsrsm2Info_t)info, position)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrsm2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrsm2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrsm2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, (cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrsm2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, (cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrsm2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrsm2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrsm2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrsm2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const float* B, int ldb, float* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrsm2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, alpha, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, B, ldb, X, ldx, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const double* B, int ldb, double* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrsm2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, alpha, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, B, ldb, X, ldx, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipComplex* B, int ldb, hipComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrsm2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, (const cuComplex*)B, ldb, (cuComplex*)X, ldx, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipDoubleComplex* B, int ldb, hipDoubleComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrsm2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transX), mb, nrhs, nnzb, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsm2Info_t)info, (const cuDoubleComplex*)B, ldb, (cuDoubleComplex*)X, ldx, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/level3/hipsparse_gemmi.cpp0000664000175100017510000002163515176134305023220 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const float* alpha, const float* A, int lda, const float* cscValB, const int* cscColPtrB, const int* cscRowIndB, const float* beta, float* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgemmi((cusparseHandle_t)handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc)); } hipsparseStatus_t hipsparseDgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const double* alpha, const double* A, int lda, const double* cscValB, const int* cscColPtrB, const int* cscRowIndB, const double* beta, double* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgemmi((cusparseHandle_t)handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc)); } hipsparseStatus_t hipsparseCgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipComplex* alpha, const hipComplex* A, int lda, const hipComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCgemmi((cusparseHandle_t)handle, m, n, k, nnz, (const cuComplex*)alpha, (const cuComplex*)A, lda, (const cuComplex*)cscValB, cscColPtrB, cscRowIndB, (const cuComplex*)beta, (cuComplex*)C, ldc)); } hipsparseStatus_t hipsparseZgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, const hipDoubleComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseZgemmi((cusparseHandle_t)handle, m, n, k, nnz, (const cuDoubleComplex*)alpha, (const cuDoubleComplex*)A, lda, (const cuDoubleComplex*)cscValB, cscColPtrB, cscRowIndB, (const cuDoubleComplex*)beta, (cuDoubleComplex*)C, ldc)); } #endif ./library/src/nvidia_detail/level3/hipsparse_bsrmm.cpp0000664000175100017510000002315315176134305023237 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrmm((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), mb, n, kb, nnzb, alpha, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseDbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrmm((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), mb, n, kb, nnzb, alpha, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseCbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrmm((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), mb, n, kb, nnzb, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const cuComplex*)B, ldb, (const cuComplex*)beta, (cuComplex*)C, ldc)); } hipsparseStatus_t hipsparseZbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrmm((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), mb, n, kb, nnzb, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const cuDoubleComplex*)B, ldb, (const cuDoubleComplex*)beta, (cuDoubleComplex*)C, ldc)); } ./library/src/nvidia_detail/level3/hipsparse_csrsm.cpp0000664000175100017510000007201515176134305023247 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseXcsrsm2_zeroPivot(hipsparseHandle_t handle, csrsm2Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrsm2_zeroPivot((cusparseHandle_t)handle, (csrsm2Info_t)info, position)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrsm2_bufferSizeExt((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrsm2_bufferSizeExt((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrsm2_bufferSizeExt((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuComplex*)B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrsm2_bufferSizeExt((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuDoubleComplex*)B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrsm2_analysis((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrsm2_analysis((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrsm2_analysis((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuComplex*)B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrsm2_analysis((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuDoubleComplex*)B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrsm2_solve((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrsm2_solve((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrsm2_solve((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (cuComplex*)B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrsm2_solve((cusparseHandle_t)handle, algo, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, nrhs, nnz, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (cuDoubleComplex*)B, ldb, (csrsm2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/level3/hipsparse_csrmm.cpp0000664000175100017510000003747115176134305023250 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseScsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrmm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, k, nnz, alpha, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseDcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrmm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, k, nnz, alpha, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseCcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrmm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, k, nnz, (const cuComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuComplex*)B, ldb, (const cuComplex*)beta, (cuComplex*)C, ldc)); } hipsparseStatus_t hipsparseZcsrmm(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrmm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, k, nnz, (const cuDoubleComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuDoubleComplex*)B, ldb, (const cuDoubleComplex*)beta, (cuDoubleComplex*)C, ldc)); } #endif #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseScsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrmm2((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, nnz, alpha, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseDcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrmm2((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, nnz, alpha, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, beta, C, ldc)); } hipsparseStatus_t hipsparseCcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrmm2((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, nnz, (const cuComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuComplex*)B, ldb, (const cuComplex*)beta, (cuComplex*)C, ldc)); } hipsparseStatus_t hipsparseZcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrmm2((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, nnz, (const cuDoubleComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuDoubleComplex*)B, ldb, (const cuDoubleComplex*)beta, (cuDoubleComplex*)C, ldc)); } #endif ./library/src/nvidia_detail/hipsparse_generic_auxiliary.cpp0000664000175100017510000016613515176134511024437 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "utility.h" #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseCreateSpVec(hipsparseSpVecDescr_t* spVecDescr, int64_t size, int64_t nnz, void* indices, void* values, hipsparseIndexType_t idxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateSpVec((cusparseSpVecDescr_t*)spVecDescr, size, nnz, indices, values, hipsparse::hipIndexTypeToCudaIndexType(idxType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseCreateConstSpVec(hipsparseConstSpVecDescr_t* spVecDescr, int64_t size, int64_t nnz, const void* indices, const void* values, hipsparseIndexType_t idxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateConstSpVec((cusparseConstSpVecDescr_t*)spVecDescr, size, nnz, indices, values, hipsparse::hipIndexTypeToCudaIndexType(idxType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDestroySpVec(hipsparseConstSpVecDescr_t spVecDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroySpVec((cusparseConstSpVecDescr_t)spVecDescr)); } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseDestroySpVec(hipsparseSpVecDescr_t spVecDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroySpVec((cusparseSpVecDescr_t)spVecDescr)); } #endif #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpVecGet(const hipsparseSpVecDescr_t spVecDescr, int64_t* size, int64_t* nnz, void** indices, void** values, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR(cusparseSpVecGet((const cusparseSpVecDescr_t)spVecDescr, size, nnz, indices, values, idxType != nullptr ? &cuda_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *idxType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstSpVecGet(hipsparseConstSpVecDescr_t spVecDescr, int64_t* size, int64_t* nnz, const void** indices, const void** values, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseConstSpVecGet((const cusparseConstSpVecDescr_t)spVecDescr, size, nnz, indices, values, idxType != nullptr ? &cuda_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *idxType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpVecGetIndexBase(hipsparseConstSpVecDescr_t spVecDescr, hipsparseIndexBase_t* idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSpVecGetIndexBase( (const cusparseConstSpVecDescr_t)spVecDescr, (cusparseIndexBase_t*)idxBase)); } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpVecGetIndexBase(const hipsparseSpVecDescr_t spVecDescr, hipsparseIndexBase_t* idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSpVecGetIndexBase( (const cusparseSpVecDescr_t)spVecDescr, (cusparseIndexBase_t*)idxBase)); } #endif #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpVecGetValues(const hipsparseSpVecDescr_t spVecDescr, void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpVecGetValues((const cusparseSpVecDescr_t)spVecDescr, values)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstSpVecGetValues(hipsparseConstSpVecDescr_t spVecDescr, const void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseConstSpVecGetValues((const cusparseConstSpVecDescr_t)spVecDescr, values)); } #endif #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpVecSetValues(hipsparseSpVecDescr_t spVecDescr, void* values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpVecSetValues((const cusparseSpVecDescr_t)spVecDescr, values)); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseCreateCoo(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cooRowInd, void* cooColInd, void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateCoo((cusparseSpMatDescr_t*)spMatDescr, rows, cols, nnz, cooRowInd, cooColInd, cooValues, hipsparse::hipIndexTypeToCudaIndexType(cooIdxType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseCreateConstCoo(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* cooRowInd, const void* cooColInd, const void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateConstCoo((cusparseConstSpMatDescr_t*)spMatDescr, rows, cols, nnz, cooRowInd, cooColInd, cooValues, hipsparse::hipIndexTypeToCudaIndexType(cooIdxType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseStatus_t hipsparseCreateCooAoS(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cooInd, void* cooValues, hipsparseIndexType_t cooIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateCooAoS((cusparseSpMatDescr_t*)spMatDescr, rows, cols, nnz, cooInd, cooValues, hipsparse::hipIndexTypeToCudaIndexType(cooIdxType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseCreateCsr(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* csrRowOffsets, void* csrColInd, void* csrValues, hipsparseIndexType_t csrRowOffsetsType, hipsparseIndexType_t csrColIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateCsr((cusparseSpMatDescr_t*)spMatDescr, rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, hipsparse::hipIndexTypeToCudaIndexType(csrRowOffsetsType), hipsparse::hipIndexTypeToCudaIndexType(csrColIndType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12001) hipsparseStatus_t hipsparseCreateConstCsr(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* csrRowOffsets, const void* csrColInd, const void* csrValues, hipsparseIndexType_t csrRowOffsetsType, hipsparseIndexType_t csrColIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateConstCsr((cusparseConstSpMatDescr_t*)spMatDescr, rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, hipsparse::hipIndexTypeToCudaIndexType(csrRowOffsetsType), hipsparse::hipIndexTypeToCudaIndexType(csrColIndType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 11020) hipsparseStatus_t hipsparseCreateCsc(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void* cscColOffsets, void* cscRowInd, void* cscValues, hipsparseIndexType_t cscColOffsetsType, hipsparseIndexType_t cscRowIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateCsc((cusparseSpMatDescr_t*)spMatDescr, rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, hipsparse::hipIndexTypeToCudaIndexType(cscColOffsetsType), hipsparse::hipIndexTypeToCudaIndexType(cscRowIndType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseCreateConstCsc(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t nnz, const void* cscColOffsets, const void* cscRowInd, const void* cscValues, hipsparseIndexType_t cscColOffsetsType, hipsparseIndexType_t cscRowIndType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateConstCsc((cusparseConstSpMatDescr_t*)spMatDescr, rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, hipsparse::hipIndexTypeToCudaIndexType(cscColOffsetsType), hipsparse::hipIndexTypeToCudaIndexType(cscRowIndType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 11021) hipsparseStatus_t hipsparseCreateBlockedEll(hipsparseSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t ellBlockSize, int64_t ellCols, void* ellColInd, void* ellValue, hipsparseIndexType_t ellIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateBlockedEll((cusparseSpMatDescr_t*)spMatDescr, rows, cols, ellBlockSize, ellCols, ellColInd, ellValue, hipsparse::hipIndexTypeToCudaIndexType(ellIdxType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseCreateConstBlockedEll(hipsparseConstSpMatDescr_t* spMatDescr, int64_t rows, int64_t cols, int64_t ellBlockSize, int64_t ellCols, const void* ellColInd, const void* ellValue, hipsparseIndexType_t ellIdxType, hipsparseIndexBase_t idxBase, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateConstBlockedEll((cusparseConstSpMatDescr_t*)spMatDescr, rows, cols, ellBlockSize, ellCols, ellColInd, ellValue, hipsparse::hipIndexTypeToCudaIndexType(ellIdxType), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDestroySpMat(hipsparseConstSpMatDescr_t spMatDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroySpMat((cusparseConstSpMatDescr_t)spMatDescr)); } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseDestroySpMat(hipsparseSpMatDescr_t spMatDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroySpMat((cusparseSpMatDescr_t)spMatDescr)); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseCooGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cooRowInd, void** cooColInd, void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR(cusparseCooGet((const cusparseSpMatDescr_t)spMatDescr, rows, cols, nnz, cooRowInd, cooColInd, cooValues, idxType != nullptr ? &cuda_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *idxType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstCooGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** cooRowInd, const void** cooColInd, const void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR(cusparseConstCooGet((const cusparseConstSpMatDescr_t)spMatDescr, rows, cols, nnz, cooRowInd, cooColInd, cooValues, idxType != nullptr ? &cuda_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *idxType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseStatus_t hipsparseCooAoSGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cooInd, void** cooValues, hipsparseIndexType_t* idxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR(cusparseCooAoSGet((const cusparseSpMatDescr_t)spMatDescr, rows, cols, nnz, cooInd, cooValues, idxType != nullptr ? &cuda_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *idxType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseCsrGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** csrRowOffsets, void** csrColInd, void** csrValues, hipsparseIndexType_t* csrRowOffsetsType, hipsparseIndexType_t* csrColIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_row_index_type; cusparseIndexType_t cuda_col_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseCsrGet((const cusparseSpMatDescr_t)spMatDescr, rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, csrRowOffsetsType != nullptr ? &cuda_row_index_type : nullptr, csrColIndType != nullptr ? &cuda_col_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *csrRowOffsetsType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_row_index_type); *csrColIndType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_col_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstCsrGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** csrRowOffsets, const void** csrColInd, const void** csrValues, hipsparseIndexType_t* csrRowOffsetsType, hipsparseIndexType_t* csrColIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_row_index_type; cusparseIndexType_t cuda_col_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseConstCsrGet((const cusparseConstSpMatDescr_t)spMatDescr, rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, csrRowOffsetsType != nullptr ? &cuda_row_index_type : nullptr, csrColIndType != nullptr ? &cuda_col_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *csrRowOffsetsType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_row_index_type); *csrColIndType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_col_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12001) hipsparseStatus_t hipsparseCscGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, void** cscColOffsets, void** cscRowInd, void** cscValues, hipsparseIndexType_t* cscColOffsetsType, hipsparseIndexType_t* cscRowIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_col_index_type; cusparseIndexType_t cuda_row_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseCscGet((const cusparseSpMatDescr_t)spMatDescr, rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, cscColOffsetsType != nullptr ? &cuda_col_index_type : nullptr, cscRowIndType != nullptr ? &cuda_row_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *cscColOffsetsType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_col_index_type); *cscRowIndType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_row_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12001) hipsparseStatus_t hipsparseConstCscGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz, const void** cscColOffsets, const void** cscRowInd, const void** cscValues, hipsparseIndexType_t* cscColOffsetsType, hipsparseIndexType_t* cscRowIndType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_row_index_type; cusparseIndexType_t cuda_col_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseConstCscGet((const cusparseConstSpMatDescr_t)spMatDescr, rows, cols, nnz, cscColOffsets, cscRowInd, cscValues, cscColOffsetsType != nullptr ? &cuda_row_index_type : nullptr, cscRowIndType != nullptr ? &cuda_col_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *cscColOffsetsType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_row_index_type); *cscRowIndType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_col_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 11021) hipsparseStatus_t hipsparseBlockedEllGet(const hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* ellBlockSize, int64_t* ellCols, void** ellColInd, void** ellValue, hipsparseIndexType_t* ellIdxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { // As of cusparse 11.4.1, this routine does not actually exist as a symbol in the cusparse // library (the documentation indicates that it should exist starting at cusparse 11.2.1). #if(CUDART_VERSION >= 11070) cusparseIndexType_t cuda_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseBlockedEllGet((cusparseSpMatDescr_t)spMatDescr, rows, cols, ellBlockSize, ellCols, ellColInd, ellValue, ellIdxType != nullptr ? &cuda_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *ellIdxType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; #else return HIPSPARSE_STATUS_NOT_SUPPORTED; #endif } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstBlockedEllGet(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* ellBlockSize, int64_t* ellCols, const void** ellColInd, const void** ellValue, hipsparseIndexType_t* ellIdxType, hipsparseIndexBase_t* idxBase, hipDataType* valueType) { cusparseIndexType_t cuda_index_type; cusparseIndexBase_t cuda_index_base; cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseConstBlockedEllGet((cusparseConstSpMatDescr_t)spMatDescr, rows, cols, ellBlockSize, ellCols, ellColInd, ellValue, ellIdxType != nullptr ? &cuda_index_type : nullptr, idxBase != nullptr ? &cuda_index_base : nullptr, valueType != nullptr ? &cuda_data_type : nullptr)); *ellIdxType = hipsparse::CudaIndexTypeToHIPIndexType(cuda_index_type); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseCsrSetPointers(hipsparseSpMatDescr_t spMatDescr, void* csrRowOffsets, void* csrColInd, void* csrValues) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCsrSetPointers( (cusparseSpMatDescr_t)spMatDescr, csrRowOffsets, csrColInd, csrValues)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMatGetSize(hipsparseConstSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatGetSize((cusparseConstSpMatDescr_t)spMatDescr, rows, cols, nnz)); } #elif(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseSpMatGetSize(hipsparseSpMatDescr_t spMatDescr, int64_t* rows, int64_t* cols, int64_t* nnz) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatGetSize((cusparseSpMatDescr_t)spMatDescr, rows, cols, nnz)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMatGetFormat(hipsparseConstSpMatDescr_t spMatDescr, hipsparseFormat_t* format) { cusparseFormat_t cuda_format; RETURN_IF_CUSPARSE_ERROR(cusparseSpMatGetFormat((const cusparseConstSpMatDescr_t)spMatDescr, format != nullptr ? &cuda_format : nullptr)); *format = hipsparse::CudaFormatToHIPFormat(cuda_format); return HIPSPARSE_STATUS_SUCCESS; } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseSpMatGetFormat(const hipsparseSpMatDescr_t spMatDescr, hipsparseFormat_t* format) { cusparseFormat_t cuda_format; RETURN_IF_CUSPARSE_ERROR(cusparseSpMatGetFormat((const cusparseSpMatDescr_t)spMatDescr, format != nullptr ? &cuda_format : nullptr)); *format = hipsparse::CudaFormatToHIPFormat(cuda_format); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMatGetIndexBase(hipsparseConstSpMatDescr_t spMatDescr, hipsparseIndexBase_t* idxBase) { cusparseIndexBase_t cuda_index_base; RETURN_IF_CUSPARSE_ERROR( cusparseSpMatGetIndexBase((const cusparseConstSpMatDescr_t)spMatDescr, idxBase != nullptr ? &cuda_index_base : nullptr)); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); return HIPSPARSE_STATUS_SUCCESS; } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseSpMatGetIndexBase(const hipsparseSpMatDescr_t spMatDescr, hipsparseIndexBase_t* idxBase) { cusparseIndexBase_t cuda_index_base; RETURN_IF_CUSPARSE_ERROR(cusparseSpMatGetIndexBase( (const cusparseSpMatDescr_t)spMatDescr, idxBase != nullptr ? &cuda_index_base : nullptr)); *idxBase = hipsparse::CudaIndexBaseToHIPIndexBase(cuda_index_base); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseSpMatGetValues(hipsparseSpMatDescr_t spMatDescr, void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatGetValues((cusparseSpMatDescr_t)spMatDescr, values)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstSpMatGetValues(hipsparseConstSpMatDescr_t spMatDescr, const void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseConstSpMatGetValues((cusparseConstSpMatDescr_t)spMatDescr, values)); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseSpMatSetValues(hipsparseSpMatDescr_t spMatDescr, void* values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatSetValues((cusparseSpMatDescr_t)spMatDescr, values)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMatGetStridedBatch(hipsparseConstSpMatDescr_t spMatDescr, int* batchCount) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatGetStridedBatch((cusparseConstSpMatDescr_t)spMatDescr, batchCount)); } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseSpMatGetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int* batchCount) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatGetStridedBatch((cusparseSpMatDescr_t)spMatDescr, batchCount)); } #endif #if(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseStatus_t hipsparseSpMatSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatSetStridedBatch((cusparseSpMatDescr_t)spMatDescr, batchCount)); } #endif #if(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseCooSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount, int64_t batchStride) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCooSetStridedBatch((cusparseSpMatDescr_t)spMatDescr, batchCount, batchStride)); } #endif #if(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseCsrSetStridedBatch(hipsparseSpMatDescr_t spMatDescr, int batchCount, int64_t offsetsBatchStride, int64_t columnsValuesBatchStride) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCsrSetStridedBatch((cusparseSpMatDescr_t)spMatDescr, batchCount, offsetsBatchStride, columnsValuesBatchStride)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMatGetAttribute(hipsparseConstSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, void* data, size_t dataSize) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatGetAttribute((cusparseConstSpMatDescr_t)spMatDescr, (cusparseSpMatAttribute_t)attribute, data, dataSize)); } #elif(CUDART_VERSION >= 11030) hipsparseStatus_t hipsparseSpMatGetAttribute(hipsparseSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, void* data, size_t dataSize) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSpMatGetAttribute( (cusparseSpMatDescr_t)spMatDescr, (cusparseSpMatAttribute_t)attribute, data, dataSize)); } #endif #if(CUDART_VERSION >= 11030) hipsparseStatus_t hipsparseSpMatSetAttribute(hipsparseSpMatDescr_t spMatDescr, hipsparseSpMatAttribute_t attribute, const void* data, size_t dataSize) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMatSetAttribute((cusparseSpMatDescr_t)spMatDescr, (cusparseSpMatAttribute_t)attribute, const_cast(data), dataSize)); } #endif #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseCreateDnVec(hipsparseDnVecDescr_t* dnVecDescr, int64_t size, void* values, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateDnVec((cusparseDnVecDescr_t*)dnVecDescr, size, values, hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseCreateConstDnVec(hipsparseConstDnVecDescr_t* dnVecDescr, int64_t size, const void* values, hipDataType valueType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateConstDnVec((cusparseConstDnVecDescr_t*)dnVecDescr, size, values, hipsparse::hipDataTypeToCudaDataType(valueType))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDestroyDnVec(hipsparseConstDnVecDescr_t dnVecDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyDnVec((cusparseConstDnVecDescr_t)dnVecDescr)); } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseDestroyDnVec(hipsparseDnVecDescr_t dnVecDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyDnVec((cusparseDnVecDescr_t)dnVecDescr)); } #endif #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseDnVecGet(const hipsparseDnVecDescr_t dnVecDescr, int64_t* size, void** values, hipDataType* valueType) { cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR(cusparseDnVecGet((const cusparseDnVecDescr_t)dnVecDescr, size, values, valueType != nullptr ? &cuda_data_type : nullptr)); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstDnVecGet(hipsparseConstDnVecDescr_t dnVecDescr, int64_t* size, const void** values, hipDataType* valueType) { cudaDataType cuda_data_type; RETURN_IF_CUSPARSE_ERROR( cusparseConstDnVecGet((const cusparseConstDnVecDescr_t)dnVecDescr, size, values, valueType != nullptr ? &cuda_data_type : nullptr)); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseDnVecGetValues(const hipsparseDnVecDescr_t dnVecDescr, void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnVecGetValues((const cusparseDnVecDescr_t)dnVecDescr, values)); } #endif #if(CUDART_VERSION >= 12001) hipsparseStatus_t hipsparseConstDnVecGetValues(hipsparseConstDnVecDescr_t dnVecDescr, const void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseConstDnVecGetValues((const cusparseConstDnVecDescr_t)dnVecDescr, values)); } #endif #if(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseDnVecSetValues(hipsparseDnVecDescr_t dnVecDescr, void* values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnVecSetValues((cusparseDnVecDescr_t)dnVecDescr, values)); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseCreateDnMat(hipsparseDnMatDescr_t* dnMatDescr, int64_t rows, int64_t cols, int64_t ld, void* values, hipDataType valueType, hipsparseOrder_t order) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateDnMat((cusparseDnMatDescr_t*)dnMatDescr, rows, cols, ld, values, hipsparse::hipDataTypeToCudaDataType(valueType), hipsparse::hipOrderToCudaOrder(order))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseCreateConstDnMat(hipsparseConstDnMatDescr_t* dnMatDescr, int64_t rows, int64_t cols, int64_t ld, const void* values, hipDataType valueType, hipsparseOrder_t order) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateConstDnMat((cusparseConstDnMatDescr_t*)dnMatDescr, rows, cols, ld, values, hipsparse::hipDataTypeToCudaDataType(valueType), hipsparse::hipOrderToCudaOrder(order))); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDestroyDnMat(hipsparseConstDnMatDescr_t dnMatDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyDnMat((cusparseConstDnMatDescr_t)dnMatDescr)); } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseDestroyDnMat(hipsparseDnMatDescr_t dnMatDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyDnMat((cusparseDnMatDescr_t)dnMatDescr)); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseDnMatGet(const hipsparseDnMatDescr_t dnMatDescr, int64_t* rows, int64_t* cols, int64_t* ld, void** values, hipDataType* valueType, hipsparseOrder_t* order) { cudaDataType cuda_data_type; cusparseOrder_t cusparse_order; RETURN_IF_CUSPARSE_ERROR(cusparseDnMatGet((const cusparseDnMatDescr_t)dnMatDescr, rows, cols, ld, values, valueType != nullptr ? &cuda_data_type : nullptr, order != nullptr ? &cusparse_order : nullptr)); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); *order = hipsparse::CudaOrderToHIPOrder(cusparse_order); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstDnMatGet(hipsparseConstDnMatDescr_t dnMatDescr, int64_t* rows, int64_t* cols, int64_t* ld, const void** values, hipDataType* valueType, hipsparseOrder_t* order) { cudaDataType cuda_data_type; cusparseOrder_t cusparse_order; RETURN_IF_CUSPARSE_ERROR(cusparseConstDnMatGet((const cusparseConstDnMatDescr_t)dnMatDescr, rows, cols, ld, values, valueType != nullptr ? &cuda_data_type : nullptr, order != nullptr ? &cusparse_order : nullptr)); *valueType = hipsparse::CudaDataTypeToHIPDataType(cuda_data_type); *order = hipsparse::CudaOrderToHIPOrder(cusparse_order); return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseDnMatGetValues(const hipsparseDnMatDescr_t dnMatDescr, void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnMatGetValues((const cusparseDnMatDescr_t)dnMatDescr, values)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseConstDnMatGetValues(hipsparseConstDnMatDescr_t dnMatDescr, const void** values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseConstDnMatGetValues((const cusparseConstDnMatDescr_t)dnMatDescr, values)); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseDnMatSetValues(hipsparseDnMatDescr_t dnMatDescr, void* values) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnMatSetValues((cusparseDnMatDescr_t)dnMatDescr, values)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDnMatGetStridedBatch(hipsparseConstDnMatDescr_t dnMatDescr, int* batchCount, int64_t* batchStride) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDnMatGetStridedBatch( (cusparseConstDnMatDescr_t)dnMatDescr, batchCount, batchStride)); } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseDnMatGetStridedBatch(hipsparseDnMatDescr_t dnMatDescr, int* batchCount, int64_t* batchStride) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnMatGetStridedBatch((cusparseDnMatDescr_t)dnMatDescr, batchCount, batchStride)); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseDnMatSetStridedBatch(hipsparseDnMatDescr_t dnMatDescr, int batchCount, int64_t batchStride) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnMatSetStridedBatch((cusparseDnMatDescr_t)dnMatDescr, batchCount, batchStride)); } #endif ./library/src/nvidia_detail/conversion/0000775000175100017510000000000015176134461020327 5ustar jenkinsjenkins./library/src/nvidia_detail/conversion/hipsparse_nnz_compress.cpp0000664000175100017510000001267115176134305025635 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, float tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSnnz_compress((cusparseHandle_t)handle, m, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol)); } hipsparseStatus_t hipsparseDnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, double tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnnz_compress((cusparseHandle_t)handle, m, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol)); } hipsparseStatus_t hipsparseCnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipComplex tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCnnz_compress((cusparseHandle_t)handle, m, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrValA, csrRowPtrA, nnzPerRow, nnzC, {cuCrealf(tol), cuCimagf(tol)})); } hipsparseStatus_t hipsparseZnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipDoubleComplex tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZnnz_compress((cusparseHandle_t)handle, m, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrValA, csrRowPtrA, nnzPerRow, nnzC, {cuCreal(tol), cuCimag(tol)})); } #endif ./library/src/nvidia_detail/conversion/hipsparse_nnz.cpp0000664000175100017510000001252715176134305023722 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSnnz((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); } hipsparseStatus_t hipsparseDnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDnnz((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); } hipsparseStatus_t hipsparseCnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCnnz((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, (const cuComplex*)A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); } hipsparseStatus_t hipsparseZnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZnnz((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)A, lda, nnzPerRowColumn, nnzTotalDevHostPtr)); } ./library/src/nvidia_detail/conversion/hipsparse_csr2bsr.cpp0000664000175100017510000002140315176134305024466 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsr2bsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, int* bsrRowPtrC, int* bsrNnzb) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsr2bsrNnz((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, csrRowPtrA, csrColIndA, blockDim, (const cusparseMatDescr_t)descrC, bsrRowPtrC, bsrNnzb)); } hipsparseStatus_t hipsparseScsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2bsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, (const cusparseMatDescr_t)descrC, bsrValC, bsrRowPtrC, bsrColIndC)); } hipsparseStatus_t hipsparseDcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2bsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, (const cusparseMatDescr_t)descrC, bsrValC, bsrRowPtrC, bsrColIndC)); } hipsparseStatus_t hipsparseCcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2bsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrValA, csrRowPtrA, csrColIndA, blockDim, (const cusparseMatDescr_t)descrC, (cuComplex*)bsrValC, bsrRowPtrC, bsrColIndC)); } hipsparseStatus_t hipsparseZcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2bsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), m, n, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrValA, csrRowPtrA, csrColIndA, blockDim, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)bsrValC, bsrRowPtrC, bsrColIndC)); } ./library/src/nvidia_detail/conversion/hipsparse_coo2csr.cpp0000664000175100017510000000411415176134305024460 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcoo2csr(hipsparseHandle_t handle, const int* cooRowInd, int nnz, int m, int* csrRowPtr, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcoo2csr((cusparseHandle_t)handle, cooRowInd, nnz, m, csrRowPtr, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } ./library/src/nvidia_detail/conversion/hipsparse_csr2coo.cpp0000664000175100017510000000411415176134305024460 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsr2coo(hipsparseHandle_t handle, const int* csrRowPtr, int nnz, int m, int* cooRowInd, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsr2coo((cusparseHandle_t)handle, csrRowPtr, nnz, m, cooRowInd, hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } ./library/src/nvidia_detail/conversion/hipsparse_gebsr2gebsr.cpp0000664000175100017510000005054215176134305025323 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgebsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgebsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgebsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgebsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXgebsr2gebsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, int* bsrRowPtrC, int rowBlockDimC, int colBlockDimC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXgebsr2gebsrNnz((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (cusparseMatDescr_t)descrC, bsrRowPtrC, rowBlockDimC, colBlockDimC, nnzTotalDevHostPtr, buffer)); } hipsparseStatus_t hipsparseSgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgebsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const cusparseMatDescr_t)descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); } hipsparseStatus_t hipsparseDgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgebsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const cusparseMatDescr_t)descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); } hipsparseStatus_t hipsparseCgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgebsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const cusparseMatDescr_t)descrC, (cuComplex*)bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); } hipsparseStatus_t hipsparseZgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgebsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, nnzb, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer)); } ./library/src/nvidia_detail/conversion/hipsparse_prune_csr2csr.cpp0000664000175100017510000004077515176134305025715 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csrNnz((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csrNnz((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csr((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csr((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, threshold, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, buffer)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_cscsort.cpp0000664000175100017510000000610715176134305024572 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcscsort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* cscColPtr, const int* cscRowInd, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseXcscsort_bufferSizeExt( (cusparseHandle_t)handle, m, n, nnz, cscColPtr, cscRowInd, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcscsort(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, const int* cscColPtr, int* cscRowInd, int* P, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcscsort((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, cscColPtr, cscRowInd, P, pBuffer)); } ./library/src/nvidia_detail/conversion/hipsparse_hyb2csr.cpp0000664000175100017510000001103315176134305024460 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseShyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, float* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseShyb2csr((cusparseHandle_t)handle, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA)); } hipsparseStatus_t hipsparseDhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, double* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDhyb2csr((cusparseHandle_t)handle, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA)); } hipsparseStatus_t hipsparseChyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipComplex* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseChyb2csr((cusparseHandle_t)handle, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA)); } hipsparseStatus_t hipsparseZhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipDoubleComplex* csrSortedValA, int* csrSortedRowPtrA, int* csrSortedColIndA) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZhyb2csr((cusparseHandle_t)handle, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_csc2dense.cpp0000664000175100017510000001305715176134305024765 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* cscVal, const int* cscRowInd, const int* cscColPtr, float* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsc2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, cscVal, cscRowInd, cscColPtr, A, ld)); } hipsparseStatus_t hipsparseDcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* cscVal, const int* cscRowInd, const int* cscColPtr, double* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsc2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, cscVal, cscRowInd, cscColPtr, A, ld)); } hipsparseStatus_t hipsparseCcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipComplex* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsc2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const cuComplex*)cscVal, cscRowInd, cscColPtr, (cuComplex*)A, ld)); } hipsparseStatus_t hipsparseZcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipDoubleComplex* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsc2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const cuDoubleComplex*)cscVal, cscRowInd, cscColPtr, (cuDoubleComplex*)A, ld)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_bsr2csr.cpp0000664000175100017510000001666515176134305024504 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseDbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseCbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const cusparseMatDescr_t)descrC, (cuComplex*)csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseZbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)csrValC, csrRowPtrC, csrColIndC)); } ./library/src/nvidia_detail/conversion/hipsparse_csr2gebsr.cpp0000664000175100017510000004162715176134305025014 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseDcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseCcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, (const cuComplex*)csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseZcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2gebsr_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, (const cuDoubleComplex*)csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseXcsr2gebsrNnz(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, int* bsrRowPtr, int rowBlockDim, int colBlockDim, int* bsrNnzDevhost, void* pbuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsr2gebsrNnz((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, csrRowPtr, csrColInd, (const cusparseMatDescr_t)bsr_descr, bsrRowPtr, rowBlockDim, colBlockDim, bsrNnzDevhost, pbuffer)); } hipsparseStatus_t hipsparseScsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, float* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, csrVal, csrRowPtr, csrColInd, (const cusparseMatDescr_t)bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); } hipsparseStatus_t hipsparseDcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, double* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, csrVal, csrRowPtr, csrColInd, (const cusparseMatDescr_t)bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); } hipsparseStatus_t hipsparseCcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, (const cuComplex*)csrVal, csrRowPtr, csrColInd, (const cusparseMatDescr_t)bsr_descr, (cuComplex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); } hipsparseStatus_t hipsparseZcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipDoubleComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2gebsr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), m, n, (const cusparseMatDescr_t)csr_descr, (const cuDoubleComplex*)csrVal, csrRowPtr, csrColInd, (const cusparseMatDescr_t)bsr_descr, (cuDoubleComplex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer)); } ./library/src/nvidia_detail/conversion/hipsparse_csr2csr_compress.cpp0000664000175100017510000002015115176134305026401 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseScsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, float* csrValC, int* csrColIndC, int* csrRowPtrC, float tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2csr_compress((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol)); } hipsparseStatus_t hipsparseDcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, double* csrValC, int* csrColIndC, int* csrRowPtrC, double tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2csr_compress((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol)); } hipsparseStatus_t hipsparseCcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipComplex tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2csr_compress((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, (cuComplex*)csrValC, csrColIndC, csrRowPtrC, {cuCrealf(tol), cuCimagf(tol)})); } hipsparseStatus_t hipsparseZcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipDoubleComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipDoubleComplex tol) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2csr_compress((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, (cuDoubleComplex*)csrValC, csrColIndC, csrRowPtrC, {cuCreal(tol), cuCimag(tol)})); } ./library/src/nvidia_detail/conversion/hipsparse_create_identity_permutation.cpp0000664000175100017510000000322215176134305030710 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateIdentityPermutation(hipsparseHandle_t handle, int n, int* p) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateIdentityPermutation((cusparseHandle_t)handle, n, p)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_csr2csru.cpp0000664000175100017510000001362115176134305024657 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2csru((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer)); } hipsparseStatus_t hipsparseDcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2csru((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer)); } hipsparseStatus_t hipsparseCcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2csru((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, (cuComplex*)csrVal, csrRowPtr, csrColInd, info, pBuffer)); } hipsparseStatus_t hipsparseZcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2csru((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, (cuDoubleComplex*)csrVal, csrRowPtr, csrColInd, info, pBuffer)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_prune_csr2csr_by_percentage.cpp0000664000175100017510000004760615176134305030604 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (pruneInfo_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (pruneInfo_t)info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (pruneInfo_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (pruneInfo_t)info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csrNnzByPercentage((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrRowPtrC, nnzTotalDevHostPtr, (pruneInfo_t)info, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csrNnzByPercentage((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrRowPtrC, nnzTotalDevHostPtr, (pruneInfo_t)info, buffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneCsr2csrByPercentage((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (pruneInfo_t)info, buffer)); } hipsparseStatus_t hipsparseDpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneCsr2csrByPercentage((cusparseHandle_t)handle, m, n, nnzA, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, percentage, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (pruneInfo_t)info, buffer)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_csru2csr.cpp0000664000175100017510000002576015176134305024666 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseCreateCsru2csrInfo(csru2csrInfo_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateCsru2csrInfo(info)); } hipsparseStatus_t hipsparseDestroyCsru2csrInfo(csru2csrInfo_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyCsru2csrInfo(info)); } #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsru2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsru2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsru2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnz, (cuComplex*)csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsru2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, nnz, (cuDoubleComplex*)csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsru2csr((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer)); } hipsparseStatus_t hipsparseDcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsru2csr((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer)); } hipsparseStatus_t hipsparseCcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsru2csr((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, (cuComplex*)csrVal, csrRowPtr, csrColInd, info, pBuffer)); } hipsparseStatus_t hipsparseZcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsru2csr((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, (cuDoubleComplex*)csrVal, csrRowPtr, csrColInd, info, pBuffer)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_csr2dense.cpp0000664000175100017510000001306115176134305024777 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, float* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, A, ld)); } hipsparseStatus_t hipsparseDcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, double* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, A, ld)); } hipsparseStatus_t hipsparseCcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipComplex* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const hipComplex*)csrVal, csrRowPtr, csrColInd, (hipComplex*)A, ld)); } hipsparseStatus_t hipsparseZcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipDoubleComplex* A, int ld) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2dense((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const cuDoubleComplex*)csrVal, csrRowPtr, csrColInd, (cuDoubleComplex*)A, ld)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_csrsort.cpp0000664000175100017510000000610715176134305024611 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcsrsort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseXcsrsort_bufferSizeExt( (cusparseHandle_t)handle, m, n, nnz, csrRowPtr, csrColInd, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcsrsort(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, const int* csrRowPtr, int* csrColInd, int* P, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrsort((cusparseHandle_t)handle, m, n, nnz, (const cusparseMatDescr_t)descrA, csrRowPtr, csrColInd, P, pBuffer)); } ./library/src/nvidia_detail/conversion/hipsparse_gebsr2csr.cpp0000664000175100017510000002016115176134305025002 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgebsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseDgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgebsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseCgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgebsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const cusparseMatDescr_t)descrC, (cuComplex*)csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseZgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgebsr2csr((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nb, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)csrValC, csrRowPtrC, csrColIndC)); } ./library/src/nvidia_detail/conversion/hipsparse_prune_dense2csr_by_percentage.cpp0000664000175100017510000004017315176134305031103 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, (pruneInfo_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, (pruneInfo_t)info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, (pruneInfo_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csrByPercentage_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, (pruneInfo_t)info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csrNnzByPercentage((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrRowPtr, nnzTotalDevHostPtr, (pruneInfo_t)info, buffer)); } hipsparseStatus_t hipsparseDpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csrNnzByPercentage((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrRowPtr, nnzTotalDevHostPtr, (pruneInfo_t)info, buffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csrByPercentage((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, (pruneInfo_t)info, buffer)); } hipsparseStatus_t hipsparseDpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csrByPercentage((cusparseHandle_t)handle, m, n, A, lda, percentage, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, (pruneInfo_t)info, buffer)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_coosort.cpp0000664000175100017510000000666415176134305024612 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseXcoosort_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, const int* cooRows, const int* cooCols, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseXcoosort_bufferSizeExt( (cusparseHandle_t)handle, m, n, nnz, cooRows, cooCols, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcoosortByRow(hipsparseHandle_t handle, int m, int n, int nnz, int* cooRows, int* cooCols, int* P, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcoosortByRow((cusparseHandle_t)handle, m, n, nnz, cooRows, cooCols, P, pBuffer)); } hipsparseStatus_t hipsparseXcoosortByColumn(hipsparseHandle_t handle, int m, int n, int nnz, int* cooRows, int* cooCols, int* P, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseXcoosortByColumn( (cusparseHandle_t)handle, m, n, nnz, cooRows, cooCols, P, pBuffer)); } ./library/src/nvidia_detail/conversion/hipsparse_csr2csc.cpp0000664000175100017510000002560515176134305024460 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseScsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const float* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, float* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2csc((cusparseHandle_t)handle, m, n, nnz, csrSortedVal, csrSortedRowPtr, csrSortedColInd, cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseDcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const double* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, double* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2csc((cusparseHandle_t)handle, m, n, nnz, csrSortedVal, csrSortedRowPtr, csrSortedColInd, cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseCcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipComplex* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, hipComplex* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2csc((cusparseHandle_t)handle, m, n, nnz, (const cuComplex*)csrSortedVal, csrSortedRowPtr, csrSortedColInd, (cuComplex*)cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } hipsparseStatus_t hipsparseZcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipDoubleComplex* csrSortedVal, const int* csrSortedRowPtr, const int* csrSortedColInd, hipDoubleComplex* cscSortedVal, int* cscSortedRowInd, int* cscSortedColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2csc((cusparseHandle_t)handle, m, n, nnz, (const cuDoubleComplex*)csrSortedVal, csrSortedRowPtr, csrSortedColInd, (cuDoubleComplex*)cscSortedVal, cscSortedRowInd, cscSortedColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase))); } #endif #if(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseCsr2cscEx2_bufferSize(hipsparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, hipDataType valType, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, hipsparseCsr2CscAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCsr2cscEx2_bufferSize((cusparseHandle_t)handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, cscVal, cscColPtr, cscRowInd, hipsparse::hipDataTypeToCudaDataType(valType), hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipCsr2CscAlgToCudaCsr2CscAlg(alg), pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCsr2cscEx2(hipsparseHandle_t handle, int m, int n, int nnz, const void* csrVal, const int* csrRowPtr, const int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, hipDataType valType, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, hipsparseCsr2CscAlg_t alg, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCsr2cscEx2((cusparseHandle_t)handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, cscVal, cscColPtr, cscRowInd, hipsparse::hipDataTypeToCudaDataType(valType), hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), hipsparse::hipCsr2CscAlgToCudaCsr2CscAlg(alg), buffer)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_dense2csr.cpp0000664000175100017510000001376315176134305025010 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerRow, float* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSdense2csr((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd)); } hipsparseStatus_t hipsparseDdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerRow, double* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDdense2csr((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd)); } hipsparseStatus_t hipsparseCdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerRow, hipComplex* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCdense2csr((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const cuComplex*)A, ld, nnzPerRow, (cuComplex*)csrVal, csrRowPtr, csrColInd)); } hipsparseStatus_t hipsparseZdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerRow, hipDoubleComplex* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZdense2csr((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const cuDoubleComplex*)A, ld, nnzPerRow, (cuDoubleComplex*)csrVal, csrRowPtr, csrColInd)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_csr2hyb.cpp0000664000175100017510000001460515176134305024470 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseScsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsr2hyb((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cusparseHybMat_t)hybA, userEllWidth, hipsparse::hipHybPartitionToCudaHybPartition(partitionType))); } hipsparseStatus_t hipsparseDcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsr2hyb((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cusparseHybMat_t)hybA, userEllWidth, hipsparse::hipHybPartitionToCudaHybPartition(partitionType))); } hipsparseStatus_t hipsparseCcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsr2hyb((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cusparseHybMat_t)hybA, userEllWidth, hipsparse::hipHybPartitionToCudaHybPartition(partitionType))); } hipsparseStatus_t hipsparseZcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipsparseHybMat_t hybA, int userEllWidth, hipsparseHybPartition_t partitionType) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsr2hyb((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cusparseHybMat_t)hybA, userEllWidth, hipsparse::hipHybPartitionToCudaHybPartition(partitionType))); } #endif ./library/src/nvidia_detail/conversion/hipsparse_gebsr2gebsc.cpp0000664000175100017510000003456115176134305025307 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgebsr2gebsc_bufferSize((cusparseHandle_t)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseDgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgebsr2gebsc_bufferSize((cusparseHandle_t)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseCgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgebsr2gebsc_bufferSize((cusparseHandle_t)handle, mb, nb, nnzb, (const cuComplex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseZgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { int cu_buffer_size; hipsparseStatus_t status = hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgebsr2gebsc_bufferSize((cusparseHandle_t)handle, mb, nb, nnzb, (const cuDoubleComplex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, &cu_buffer_size)); pBufferSizeInBytes[0] = cu_buffer_size; return status; } hipsparseStatus_t hipsparseSgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, float* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgebsr2gebsc((cusparseHandle_t)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), temp_buffer)); } hipsparseStatus_t hipsparseDgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, double* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgebsr2gebsc((cusparseHandle_t)handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), temp_buffer)); } hipsparseStatus_t hipsparseCgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgebsr2gebsc((cusparseHandle_t)handle, mb, nb, nnzb, (const cuComplex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, (cuComplex*)bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), temp_buffer)); } hipsparseStatus_t hipsparseZgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipDoubleComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgebsr2gebsc((cusparseHandle_t)handle, mb, nb, nnzb, (const cuDoubleComplex*)bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, (cuDoubleComplex*)bscVal, bscRowInd, bscColPtr, hipsparse::hipActionToCudaAction(copyValues), hipsparse::hipIndexBaseToCudaIndexBase(idxBase), temp_buffer)); } ./library/src/nvidia_detail/conversion/hipsparse_dense2csc.cpp0000664000175100017510000001401315176134305024756 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseSdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerColumn, float* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSdense2csc((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr)); } hipsparseStatus_t hipsparseDdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerColumn, double* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDdense2csc((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr)); } hipsparseStatus_t hipsparseCdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerColumn, hipComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCdense2csc((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const cuComplex*)A, ld, nnzPerColumn, (cuComplex*)cscVal, cscRowInd, cscColPtr)); } hipsparseStatus_t hipsparseZdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerColumn, hipDoubleComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZdense2csc((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descr, (const cuDoubleComplex*)A, ld, nnzPerColumn, (cuDoubleComplex*)cscVal, cscRowInd, cscColPtr)); } #endif ./library/src/nvidia_detail/conversion/hipsparse_prune_dense2csr.cpp0000664000175100017510000003247715176134305026224 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csr_bufferSizeExt((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csrNnz((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrRowPtr, nnzTotalDevHostPtr, buffer)); } hipsparseStatus_t hipsparseDpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csrNnz((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrRowPtr, nnzTotalDevHostPtr, buffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSpruneDense2csr(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpruneDense2csr((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, buffer)); } hipsparseStatus_t hipsparseDpruneDense2csr(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDpruneDense2csr((cusparseHandle_t)handle, m, n, A, lda, threshold, (const cusparseMatDescr_t)descr, csrVal, csrRowPtr, csrColInd, buffer)); } #endif ./library/src/nvidia_detail/precond/0000775000175100017510000000000015176134461017574 5ustar jenkinsjenkins./library/src/nvidia_detail/precond/hipsparse_gtsv_strided_batch.cpp0000664000175100017510000002405015176134305026216 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgtsv2StridedBatch_bufferSizeExt( (cusparseHandle_t)handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgtsv2StridedBatch_bufferSizeExt( (cusparseHandle_t)handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgtsv2StridedBatch_bufferSizeExt((cusparseHandle_t)handle, m, (const cuComplex*)dl, (const cuComplex*)d, (const cuComplex*)du, (const cuComplex*)x, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgtsv2StridedBatch_bufferSizeExt((cusparseHandle_t)handle, m, (const cuDoubleComplex*)dl, (const cuDoubleComplex*)d, (const cuDoubleComplex*)du, (const cuDoubleComplex*)x, batchCount, batchStride, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsv2StridedBatch(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, float* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgtsv2StridedBatch( (cusparseHandle_t)handle, m, dl, d, du, x, batchCount, batchStride, pBuffer)); } hipsparseStatus_t hipsparseDgtsv2StridedBatch(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, double* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgtsv2StridedBatch( (cusparseHandle_t)handle, m, dl, d, du, x, batchCount, batchStride, pBuffer)); } hipsparseStatus_t hipsparseCgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgtsv2StridedBatch((cusparseHandle_t)handle, m, (const cuComplex*)dl, (const cuComplex*)d, (const cuComplex*)du, (cuComplex*)x, batchCount, batchStride, pBuffer)); } hipsparseStatus_t hipsparseZgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgtsv2StridedBatch((cusparseHandle_t)handle, m, (const cuDoubleComplex*)dl, (const cuDoubleComplex*)d, (const cuDoubleComplex*)du, (cuDoubleComplex*)x, batchCount, batchStride, pBuffer)); } ./library/src/nvidia_detail/precond/hipsparse_gtsv_nopivot.cpp0000664000175100017510000002327015176134305025120 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgtsv2_nopivot_bufferSizeExt( (cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgtsv2_nopivot_bufferSizeExt( (cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgtsv2_nopivot_bufferSizeExt((cusparseHandle_t)handle, m, n, (const cuComplex*)dl, (const cuComplex*)d, (const cuComplex*)du, (const cuComplex*)B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgtsv2_nopivot_bufferSizeExt((cusparseHandle_t)handle, m, n, (const cuDoubleComplex*)dl, (const cuDoubleComplex*)d, (const cuDoubleComplex*)du, (const cuDoubleComplex*)B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgtsv2_nopivot((cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseDgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgtsv2_nopivot((cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseCgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCgtsv2_nopivot((cusparseHandle_t)handle, m, n, (const cuComplex*)dl, (const cuComplex*)d, (const cuComplex*)du, (cuComplex*)B, ldb, pBuffer)); } hipsparseStatus_t hipsparseZgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgtsv2_nopivot((cusparseHandle_t)handle, m, n, (const cuDoubleComplex*)dl, (const cuDoubleComplex*)d, (const cuDoubleComplex*)du, (cuDoubleComplex*)B, ldb, pBuffer)); } ./library/src/nvidia_detail/precond/hipsparse_gtsv.cpp0000664000175100017510000002220615176134305023340 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgtsv2_bufferSizeExt( (cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgtsv2_bufferSizeExt( (cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgtsv2_bufferSizeExt((cusparseHandle_t)handle, m, n, (const cuComplex*)dl, (const cuComplex*)d, (const cuComplex*)du, (const cuComplex*)B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgtsv2_bufferSizeExt((cusparseHandle_t)handle, m, n, (const cuDoubleComplex*)dl, (const cuDoubleComplex*)d, (const cuDoubleComplex*)du, (const cuDoubleComplex*)B, ldb, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsv2(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgtsv2((cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseDgtsv2(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgtsv2((cusparseHandle_t)handle, m, n, dl, d, du, B, ldb, pBuffer)); } hipsparseStatus_t hipsparseCgtsv2(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCgtsv2((cusparseHandle_t)handle, m, n, (const cuComplex*)dl, (const cuComplex*)d, (const cuComplex*)du, (cuComplex*)B, ldb, pBuffer)); } hipsparseStatus_t hipsparseZgtsv2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseZgtsv2((cusparseHandle_t)handle, m, n, (const cuDoubleComplex*)dl, (const cuDoubleComplex*)d, (const cuDoubleComplex*)du, (cuDoubleComplex*)B, ldb, pBuffer)); } ./library/src/nvidia_detail/precond/hipsparse_csrilu0.cpp0000664000175100017510000005625415176134305023750 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseXcsrilu02_zeroPivot(hipsparseHandle_t handle, csrilu02Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrilu02_zeroPivot((cusparseHandle_t)handle, (csrilu02Info_t)info, position)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseScsrilu02_numericBoost( (cusparseHandle_t)handle, (csrilu02Info_t)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseDcsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDcsrilu02_numericBoost( (cusparseHandle_t)handle, (csrilu02Info_t)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseCcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCcsrilu02_numericBoost( (cusparseHandle_t)handle, (csrilu02Info_t)info, enable_boost, tol, (cuComplex*)boost_val)); } hipsparseStatus_t hipsparseZcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrilu02_numericBoost((cusparseHandle_t)handle, (csrilu02Info_t)info, enable_boost, tol, (cuDoubleComplex*)boost_val)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrilu02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrilu02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrilu02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrilu02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, pBufferSizeInBytes)); } #endif hipsparseStatus_t hipsparseScsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseDcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseCcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseZcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrilu02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrilu02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrilu02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrilu02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrilu02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrilu02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrilu02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuComplex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrilu02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/precond/hipsparse_csric0.cpp0000664000175100017510000005170115176134305023542 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseXcsric02_zeroPivot(hipsparseHandle_t handle, csric02Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsric02_zeroPivot((cusparseHandle_t)handle, (csric02Info_t)info, position)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsric02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsric02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsric02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsric02_bufferSize((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, pBufferSizeInBytes)); } #endif hipsparseStatus_t hipsparseScsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseDcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseCcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseZcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsric02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsric02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsric02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsric02_analysis((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsric02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsric02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsric02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuComplex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsric02((cusparseHandle_t)handle, m, nnz, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, (csric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/precond/hipsparse_gtsv_interleaved_batch.cpp0000664000175100017510000002425615176134305027072 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgtsvInterleavedBatch_bufferSizeExt( (cusparseHandle_t)handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgtsvInterleavedBatch_bufferSizeExt( (cusparseHandle_t)handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgtsvInterleavedBatch_bufferSizeExt((cusparseHandle_t)handle, algo, m, (const cuComplex*)dl, (const cuComplex*)d, (const cuComplex*)du, (const cuComplex*)x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgtsvInterleavedBatch_bufferSizeExt((cusparseHandle_t)handle, algo, m, (const cuDoubleComplex*)dl, (const cuDoubleComplex*)d, (const cuDoubleComplex*)du, (const cuDoubleComplex*)x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* dl, float* d, float* du, float* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgtsvInterleavedBatch( (cusparseHandle_t)handle, algo, m, dl, d, du, x, batchCount, pBuffer)); } hipsparseStatus_t hipsparseDgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* dl, double* d, double* du, double* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgtsvInterleavedBatch( (cusparseHandle_t)handle, algo, m, dl, d, du, x, batchCount, pBuffer)); } hipsparseStatus_t hipsparseCgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgtsvInterleavedBatch((cusparseHandle_t)handle, algo, m, (cuComplex*)dl, (cuComplex*)d, (cuComplex*)du, (cuComplex*)x, batchCount, pBuffer)); } hipsparseStatus_t hipsparseZgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgtsvInterleavedBatch((cusparseHandle_t)handle, algo, m, (cuDoubleComplex*)dl, (cuDoubleComplex*)d, (cuDoubleComplex*)du, (cuDoubleComplex*)x, batchCount, pBuffer)); } ./library/src/nvidia_detail/precond/hipsparse_gpsv_interleaved_batch.cpp0000664000175100017510000002342715176134305027065 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* ds, const float* dl, const float* d, const float* du, const float* dw, const float* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgpsvInterleavedBatch_bufferSizeExt( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* ds, const double* dl, const double* d, const double* du, const double* dw, const double* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgpsvInterleavedBatch_bufferSizeExt( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* ds, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* dw, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCgpsvInterleavedBatch_bufferSizeExt( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* ds, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* dw, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseZgpsvInterleavedBatch_bufferSizeExt( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseSgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* ds, float* dl, float* d, float* du, float* dw, float* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSgpsvInterleavedBatch( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer)); } hipsparseStatus_t hipsparseDgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* ds, double* dl, double* d, double* du, double* dw, double* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDgpsvInterleavedBatch( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer)); } hipsparseStatus_t hipsparseCgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* ds, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* dw, hipComplex* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCgpsvInterleavedBatch( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer)); } hipsparseStatus_t hipsparseZgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* ds, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* dw, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseZgpsvInterleavedBatch( (cusparseHandle_t)handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer)); } ./library/src/nvidia_detail/precond/hipsparse_bsric0.cpp0000664000175100017510000004766515176134305023557 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseXbsric02_zeroPivot(hipsparseHandle_t handle, bsric02Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXbsric02_zeroPivot((cusparseHandle_t)handle, (bsric02Info_t)info, position)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsric02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsric02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsric02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsric02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsric02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsric02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsric02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (const cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsric02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsric02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsric02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsric02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsric02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)bsrValA, bsrRowPtrA, bsrColIndA, blockDim, (bsric02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/precond/hipsparse_bsrilu0.cpp0000664000175100017510000005622015176134305023740 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseXbsrilu02_zeroPivot(hipsparseHandle_t handle, bsrilu02Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXbsrilu02_zeroPivot((cusparseHandle_t)handle, (bsrilu02Info_t)info, position)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSbsrilu02_numericBoost( (cusparseHandle_t)handle, (bsrilu02Info_t)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseDbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDbsrilu02_numericBoost( (cusparseHandle_t)handle, (bsrilu02Info_t)info, enable_boost, tol, boost_val)); } hipsparseStatus_t hipsparseCbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCbsrilu02_numericBoost( (cusparseHandle_t)handle, (bsrilu02Info_t)info, enable_boost, tol, (cuComplex*)boost_val)); } hipsparseStatus_t hipsparseZbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrilu02_numericBoost((cusparseHandle_t)handle, (bsrilu02Info_t)info, enable_boost, tol, (cuDoubleComplex*)boost_val)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrilu02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrilu02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrilu02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrilu02_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, pBufferSizeInBytes)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrilu02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrilu02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrilu02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrilu02_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrilu02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA_valM, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrilu02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA_valM, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrilu02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuComplex*)bsrSortedValA_valM, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrilu02((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)bsrSortedValA_valM, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrilu02Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/level2/0000775000175100017510000000000015176134461017333 5ustar jenkinsjenkins./library/src/nvidia_detail/level2/hipsparse_bsrsv.cpp0000664000175100017510000007001715176134305023256 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseXbsrsv2_zeroPivot(hipsparseHandle_t handle, bsrsv2Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXbsrsv2_zeroPivot((cusparseHandle_t)handle, (bsrsv2Info_t)info, position)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, pBufferSizeInBytes)); } #endif hipsparseStatus_t hipsparseSbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseDbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseCbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseZbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, (const cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, alpha, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, f, x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, alpha, (cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, f, x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (const cuComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, (const cuComplex*)f, (cuComplex*)x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(transA), mb, nnzb, (const cuDoubleComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (bsrsv2Info_t)info, (const cuDoubleComplex*)f, (cuDoubleComplex*)x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/level2/hipsparse_bsrxmv.cpp0000664000175100017510000002256115176134305023441 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseSbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descr, const float* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const float* x, const float* beta, float* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrxmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(trans), sizeOfMask, mb, nb, nnzb, alpha, (const cusparseMatDescr_t)descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y)); } hipsparseStatus_t hipsparseDbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descr, const double* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const double* x, const double* beta, double* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrxmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(trans), sizeOfMask, mb, nb, nnzb, alpha, (const cusparseMatDescr_t)descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y)); } hipsparseStatus_t hipsparseCbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrxmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(trans), sizeOfMask, mb, nb, nnzb, (const cuComplex*)alpha, (const cusparseMatDescr_t)descr, (const cuComplex*)bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, (const cuComplex*)x, (const cuComplex*)beta, (cuComplex*)y)); } hipsparseStatus_t hipsparseZbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrxmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dir), hipsparse::hipOperationToCudaOperation(trans), sizeOfMask, mb, nb, nnzb, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descr, (const cuDoubleComplex*)bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, (const cuDoubleComplex*)x, (const cuDoubleComplex*)beta, (cuDoubleComplex*)y)); } #endif ./library/src/nvidia_detail/level2/hipsparse_csrmv.cpp0000664000175100017510000001632515176134305023253 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseScsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* x, const float* beta, float* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, x, beta, y)); } hipsparseStatus_t hipsparseDcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* x, const double* beta, double* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, alpha, (const cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, x, beta, y)); } hipsparseStatus_t hipsparseCcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuComplex*)x, (const cuComplex*)beta, (cuComplex*)y)); } hipsparseStatus_t hipsparseZcsrmv(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuDoubleComplex*)x, (const cuDoubleComplex*)beta, (cuDoubleComplex*)y)); } #endif ./library/src/nvidia_detail/level2/hipsparse_bsrmv.cpp0000664000175100017510000002020315176134305023240 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" hipsparseStatus_t hipsparseSbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const float* x, const float* beta, float* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSbsrmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), mb, nb, nnzb, alpha, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y)); } hipsparseStatus_t hipsparseDbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const double* x, const double* beta, double* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDbsrmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), mb, nb, nnzb, alpha, (const cusparseMatDescr_t)descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y)); } hipsparseStatus_t hipsparseCbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCbsrmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), mb, nb, nnzb, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (const cuComplex*)x, (const cuComplex*)beta, (cuComplex*)y)); } hipsparseStatus_t hipsparseZbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZbsrmv((cusparseHandle_t)handle, hipsparse::hipDirectionToCudaDirection(dirA), hipsparse::hipOperationToCudaOperation(transA), mb, nb, nnzb, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, (const cuDoubleComplex*)x, (const cuDoubleComplex*)beta, (cuDoubleComplex*)y)); } ./library/src/nvidia_detail/level2/hipsparse_csrsv.cpp0000664000175100017510000006014315176134305023256 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseXcsrsv2_zeroPivot(hipsparseHandle_t handle, csrsv2Info_t info, int* position) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrsv2_zeroPivot((cusparseHandle_t)handle, (csrsv2Info_t)info, position)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, (cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrsv2_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, (cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, pBufferSizeInBytes)); } #endif hipsparseStatus_t hipsparseScsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseDcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseCcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseZcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrsv2_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, alpha, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, f, x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseDcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, alpha, (cusparseMatDescr_t)descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, f, x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseCcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (const cuComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, (const cuComplex*)f, (cuComplex*)x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } hipsparseStatus_t hipsparseZcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrsv2_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, nnz, (const cuDoubleComplex*)alpha, (cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (csrsv2Info_t)info, (const cuDoubleComplex*)f, (cuDoubleComplex*)x, hipsparse::hipPolicyToCudaPolicy(policy), pBuffer)); } #endif ./library/src/nvidia_detail/level2/hipsparse_gemvi.cpp0000664000175100017510000002463315176134305023231 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) hipsparseStatus_t hipsparseSgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgemvi_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgemvi_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgemvi_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgemvi_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, nnz, pBufferSizeInBytes)); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) hipsparseStatus_t hipsparseSgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const float* alpha, const float* A, int lda, int nnz, const float* x, const int* xInd, const float* beta, float* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSgemvi((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, alpha, A, lda, nnz, x, xInd, beta, y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase), pBuffer)); } hipsparseStatus_t hipsparseDgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const double* alpha, const double* A, int lda, int nnz, const double* x, const int* xInd, const double* beta, double* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDgemvi((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, alpha, A, lda, nnz, x, xInd, beta, y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase), pBuffer)); } hipsparseStatus_t hipsparseCgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipComplex* alpha, const hipComplex* A, int lda, int nnz, const hipComplex* x, const int* xInd, const hipComplex* beta, hipComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCgemvi((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, (const cuComplex*)alpha, (const cuComplex*)A, lda, nnz, (const cuComplex*)x, xInd, (const cuComplex*)beta, (cuComplex*)y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase), pBuffer)); } hipsparseStatus_t hipsparseZgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, int nnz, const hipDoubleComplex* x, const int* xInd, const hipDoubleComplex* beta, hipDoubleComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZgemvi((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), m, n, (const cuDoubleComplex*)alpha, (const cuDoubleComplex*)A, lda, nnz, (const cuDoubleComplex*)x, xInd, (const cuDoubleComplex*)beta, (cuDoubleComplex*)y, hipsparse::hipIndexBaseToCudaIndexBase(idxBase), pBuffer)); } #endif ./library/src/nvidia_detail/level2/hipsparse_hybmv.cpp0000664000175100017510000001231715176134305023243 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseShybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const float* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const float* x, const float* beta, float* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseShybmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), alpha, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, x, beta, y)); } hipsparseStatus_t hipsparseDhybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const double* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const double* x, const double* beta, double* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDhybmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), alpha, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, x, beta, y)); } hipsparseStatus_t hipsparseChybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseChybmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, (const cuComplex*)x, (const cuComplex*)beta, (cuComplex*)y)); } hipsparseStatus_t hipsparseZhybmv(hipsparseHandle_t handle, hipsparseOperation_t transA, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZhybmv((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, (const cusparseHybMat_t)hybA, (const cuDoubleComplex*)x, (const cuDoubleComplex*)beta, (cuDoubleComplex*)y)); } #endif ./library/src/nvidia_detail/reorder/0000775000175100017510000000000015176134461017604 5ustar jenkinsjenkins./library/src/nvidia_detail/reorder/hipsparse_csrcolor.cpp0000664000175100017510000001576115176134305024223 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseScsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrcolor((cusparseHandle_t)handle, m, nnz, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (cusparseColorInfo_t)info)); } hipsparseStatus_t hipsparseDcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrcolor((cusparseHandle_t)handle, m, nnz, (const cusparseMatDescr_t)descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (cusparseColorInfo_t)info)); } hipsparseStatus_t hipsparseCcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrcolor((cusparseHandle_t)handle, m, nnz, (const cusparseMatDescr_t)descrA, (const cuComplex*)csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (cusparseColorInfo_t)info)); } hipsparseStatus_t hipsparseZcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrcolor((cusparseHandle_t)handle, m, nnz, (const cusparseMatDescr_t)descrA, (const cuDoubleComplex*)csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, (cusparseColorInfo_t)info)); } #endif ./library/src/nvidia_detail/hipsparse_auxiliary.cpp0000664000175100017510000002570315176134305022737 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "utility.h" hipsparseStatus_t hipsparseCreate(hipsparseHandle_t* handle) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreate((cusparseHandle_t*)handle)); } hipsparseStatus_t hipsparseDestroy(hipsparseHandle_t handle) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroy((cusparseHandle_t)handle)); } #if CUDART_VERSION > 10000 const char* hipsparseGetErrorName(hipsparseStatus_t status) { return cusparseGetErrorName(hipsparse::hipSPARSEStatusToCUSPARSEStatus(status)); } const char* hipsparseGetErrorString(hipsparseStatus_t status) { return cusparseGetErrorString(hipsparse::hipSPARSEStatusToCUSPARSEStatus(status)); } #endif hipsparseStatus_t hipsparseGetVersion(hipsparseHandle_t handle, int* version) { if(handle == nullptr) { return HIPSPARSE_STATUS_NOT_INITIALIZED; } *version = hipsparseVersionMajor * 100000 + hipsparseVersionMinor * 100 + hipsparseVersionPatch; return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseGetGitRevision(hipsparseHandle_t handle, char* rev) { // Get hipSPARSE revision if(handle == nullptr) { return HIPSPARSE_STATUS_NOT_INITIALIZED; } if(rev == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } static constexpr char v[] = TO_STR(hipsparseVersionTweak); char hipsparse_rev[64]; memcpy(hipsparse_rev, v, sizeof(v)); // Get cuSPARSE version int cusparse_ver; RETURN_IF_CUSPARSE_ERROR(cusparseGetVersion((cusparseHandle_t)handle, &cusparse_ver)); // Combine snprintf(rev, 256, "%.64s (cuSPARSE %d.%d.%d)", hipsparse_rev, cusparse_ver / 100000, cusparse_ver / 100 % 1000, cusparse_ver % 100); return HIPSPARSE_STATUS_SUCCESS; } hipsparseStatus_t hipsparseSetStream(hipsparseHandle_t handle, hipStream_t streamId) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSetStream((cusparseHandle_t)handle, streamId)); } hipsparseStatus_t hipsparseGetStream(hipsparseHandle_t handle, hipStream_t* streamId) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseGetStream((cusparseHandle_t)handle, streamId)); } hipsparseStatus_t hipsparseSetPointerMode(hipsparseHandle_t handle, hipsparsePointerMode_t mode) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSetPointerMode( (cusparseHandle_t)handle, hipsparse::hipPointerModeToCudaPointerMode(mode))); } hipsparseStatus_t hipsparseGetPointerMode(hipsparseHandle_t handle, hipsparsePointerMode_t* mode) { cusparsePointerMode_t cusparseMode; cusparseStatus_t status = cusparseGetPointerMode((cusparseHandle_t)handle, &cusparseMode); *mode = hipsparse::CudaPointerModeToHIPPointerMode(cusparseMode); return hipsparse::hipCUSPARSEStatusToHIPStatus(status); } hipsparseStatus_t hipsparseCreateMatDescr(hipsparseMatDescr_t* descrA) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateMatDescr((cusparseMatDescr_t*)descrA)); } hipsparseStatus_t hipsparseDestroyMatDescr(hipsparseMatDescr_t descrA) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyMatDescr((cusparseMatDescr_t)descrA)); } hipsparseStatus_t hipsparseCopyMatDescr(hipsparseMatDescr_t dest, const hipsparseMatDescr_t src) { return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseStatus_t hipsparseSetMatType(hipsparseMatDescr_t descrA, hipsparseMatrixType_t type) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSetMatType( (cusparseMatDescr_t)descrA, hipsparse::hipMatrixTypeToCudaMatrixType(type))); } hipsparseMatrixType_t hipsparseGetMatType(const hipsparseMatDescr_t descrA) { return hipsparse::CudaMatrixTypeToHIPMatrixType( cusparseGetMatType((const cusparseMatDescr_t)descrA)); } hipsparseStatus_t hipsparseSetMatFillMode(hipsparseMatDescr_t descrA, hipsparseFillMode_t fillMode) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSetMatFillMode((cusparseMatDescr_t)descrA, hipsparse::hipFillToCudaFill(fillMode))); } hipsparseFillMode_t hipsparseGetMatFillMode(const hipsparseMatDescr_t descrA) { return hipsparse::CudaFillToHIPFill(cusparseGetMatFillMode((const cusparseMatDescr_t)descrA)); } hipsparseStatus_t hipsparseSetMatDiagType(hipsparseMatDescr_t descrA, hipsparseDiagType_t diagType) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSetMatDiagType( (cusparseMatDescr_t)descrA, hipsparse::hipDiagonalToCudaDiagonal(diagType))); } hipsparseDiagType_t hipsparseGetMatDiagType(const hipsparseMatDescr_t descrA) { return hipsparse::CudaDiagonalToHIPDiagonal( cusparseGetMatDiagType((const cusparseMatDescr_t)descrA)); } hipsparseStatus_t hipsparseSetMatIndexBase(hipsparseMatDescr_t descrA, hipsparseIndexBase_t base) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseSetMatIndexBase( (cusparseMatDescr_t)descrA, hipsparse::hipIndexBaseToCudaIndexBase(base))); } hipsparseIndexBase_t hipsparseGetMatIndexBase(const hipsparseMatDescr_t descrA) { return hipsparse::CudaIndexBaseToHIPIndexBase( cusparseGetMatIndexBase((const cusparseMatDescr_t)descrA)); } #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseCreateHybMat(hipsparseHybMat_t* hybA) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateHybMat((cusparseHybMat_t*)hybA)); } hipsparseStatus_t hipsparseDestroyHybMat(hipsparseHybMat_t hybA) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyHybMat((cusparseHybMat_t)hybA)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateBsrsv2Info(bsrsv2Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateBsrsv2Info((bsrsv2Info_t*)info)); } hipsparseStatus_t hipsparseDestroyBsrsv2Info(bsrsv2Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyBsrsv2Info((bsrsv2Info_t)info)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateBsrsm2Info(bsrsm2Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateBsrsm2Info((bsrsm2Info_t*)info)); } hipsparseStatus_t hipsparseDestroyBsrsm2Info(bsrsm2Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyBsrsm2Info((bsrsm2Info_t)info)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateBsrilu02Info(bsrilu02Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateBsrilu02Info((bsrilu02Info_t*)info)); } hipsparseStatus_t hipsparseDestroyBsrilu02Info(bsrilu02Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyBsrilu02Info((bsrilu02Info_t)info)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseCreateCsrsv2Info(csrsv2Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateCsrsv2Info((csrsv2Info_t*)info)); } hipsparseStatus_t hipsparseDestroyCsrsv2Info(csrsv2Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyCsrsv2Info((csrsv2Info_t)info)); } hipsparseStatus_t hipsparseCreateCsrsm2Info(csrsm2Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateCsrsm2Info((csrsm2Info_t*)info)); } hipsparseStatus_t hipsparseDestroyCsrsm2Info(csrsm2Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyCsrsm2Info((csrsm2Info_t)info)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateColorInfo(hipsparseColorInfo_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateColorInfo((cusparseColorInfo_t*)info)); } hipsparseStatus_t hipsparseDestroyColorInfo(hipsparseColorInfo_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyColorInfo((cusparseColorInfo_t)info)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateCsrilu02Info(csrilu02Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateCsrilu02Info((csrilu02Info_t*)info)); } hipsparseStatus_t hipsparseDestroyCsrilu02Info(csrilu02Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyCsrilu02Info((csrilu02Info_t)info)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateBsric02Info(bsric02Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateBsric02Info((bsric02Info_t*)info)); } hipsparseStatus_t hipsparseDestroyBsric02Info(bsric02Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyBsric02Info((bsric02Info_t)info)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreateCsric02Info(csric02Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreateCsric02Info((csric02Info_t*)info)); } hipsparseStatus_t hipsparseDestroyCsric02Info(csric02Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyCsric02Info((csric02Info_t)info)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseCreateCsrgemm2Info(csrgemm2Info_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCreateCsrgemm2Info((csrgemm2Info_t*)info)); } hipsparseStatus_t hipsparseDestroyCsrgemm2Info(csrgemm2Info_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDestroyCsrgemm2Info((csrgemm2Info_t)info)); } #endif #if CUDART_VERSION < 13000 hipsparseStatus_t hipsparseCreatePruneInfo(pruneInfo_t* info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseCreatePruneInfo((pruneInfo_t*)info)); } hipsparseStatus_t hipsparseDestroyPruneInfo(pruneInfo_t info) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseDestroyPruneInfo((pruneInfo_t)info)); } #endif ./library/src/nvidia_detail/extra/0000775000175100017510000000000015176134461017265 5ustar jenkinsjenkins./library/src/nvidia_detail/extra/hipsparse_csrgemm.cpp0000664000175100017510000011511315176134305023503 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseXcsrgemmNnz(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrgemmNnz((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, (const cusparseMatDescr_t)descrA, nnzA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, csrRowPtrC, nnzTotalDevHostPtr)); } hipsparseStatus_t hipsparseScsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrgemm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, (const cusparseMatDescr_t)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseDcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrgemm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, (const cusparseMatDescr_t)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseCcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrgemm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, (const cusparseMatDescr_t)descrA, nnzA, (const cuComplex*)csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, (const cuComplex*)csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, (cuComplex*)csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseZcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrgemm((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(transA), hipsparse::hipOperationToCudaOperation(transB), m, n, k, (const cusparseMatDescr_t)descrA, nnzA, (const cuDoubleComplex*)csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, (const cuDoubleComplex*)csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)csrValC, csrRowPtrC, csrColIndC)); } #endif #if CUDART_VERSION < 12000 hipsparseStatus_t hipsparseScsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrgemm2_bufferSizeExt((cusparseHandle_t)handle, m, n, k, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrRowPtrB, csrColIndB, beta, (const cusparseMatDescr_t)descrD, nnzD, csrRowPtrD, csrColIndD, (csrgemm2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrgemm2_bufferSizeExt((cusparseHandle_t)handle, m, n, k, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrRowPtrB, csrColIndB, beta, (const cusparseMatDescr_t)descrD, nnzD, csrRowPtrD, csrColIndD, (csrgemm2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrgemm2_bufferSizeExt((cusparseHandle_t)handle, m, n, k, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrRowPtrB, csrColIndB, (const cuComplex*)beta, (const cusparseMatDescr_t)descrD, nnzD, csrRowPtrD, csrColIndD, (csrgemm2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrgemm2_bufferSizeExt((cusparseHandle_t)handle, m, n, k, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrRowPtrB, csrColIndB, (const cuDoubleComplex*)beta, (const cusparseMatDescr_t)descrD, nnzD, csrRowPtrD, csrColIndD, (csrgemm2Info_t)info, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcsrgemm2Nnz(hipsparseHandle_t handle, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrgemm2Nnz((cusparseHandle_t)handle, m, n, k, (const cusparseMatDescr_t)descrA, nnzA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrD, nnzD, csrRowPtrD, csrColIndD, (const cusparseMatDescr_t)descrC, csrRowPtrC, nnzTotalDevHostPtr, (const csrgemm2Info_t)info, pBuffer)); } hipsparseStatus_t hipsparseScsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const float* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrgemm2((cusparseHandle_t)handle, m, n, k, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, (const cusparseMatDescr_t)descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (const csrgemm2Info_t)info, pBuffer)); } hipsparseStatus_t hipsparseDcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const double* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrgemm2((cusparseHandle_t)handle, m, n, k, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, (const cusparseMatDescr_t)descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC, (const csrgemm2Info_t)info, pBuffer)); } hipsparseStatus_t hipsparseCcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrgemm2((cusparseHandle_t)handle, m, n, k, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuComplex*)csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, (const cuComplex*)csrValB, csrRowPtrB, csrColIndB, (const cuComplex*)beta, (const cusparseMatDescr_t)descrD, nnzD, (const cuComplex*)csrValD, csrRowPtrD, csrColIndD, (const cusparseMatDescr_t)descrC, (cuComplex*)csrValC, csrRowPtrC, csrColIndC, (const csrgemm2Info_t)info, pBuffer)); } hipsparseStatus_t hipsparseZcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipDoubleComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrgemm2((cusparseHandle_t)handle, m, n, k, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuDoubleComplex*)csrValA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, (const cuDoubleComplex*)csrValB, csrRowPtrB, csrColIndB, (const cuDoubleComplex*)beta, (const cusparseMatDescr_t)descrD, nnzD, (const cuDoubleComplex*)csrValD, csrRowPtrD, csrColIndD, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)csrValC, csrRowPtrC, csrColIndC, (const csrgemm2Info_t)info, pBuffer)); } #endif ./library/src/nvidia_detail/extra/hipsparse_csrgeam.cpp0000664000175100017510000010545015176134305023472 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if CUDART_VERSION < 11000 hipsparseStatus_t hipsparseXcsrgeamNnz(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrgeamNnz((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, nnzA, csrRowPtrA, csrColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, csrRowPtrC, nnzTotalDevHostPtr)); } hipsparseStatus_t hipsparseScsrgeam(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrgeam((cusparseHandle_t)handle, m, n, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, beta, (const cusparseMatDescr_t)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseDcsrgeam(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrgeam((cusparseHandle_t)handle, m, n, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, beta, (const cusparseMatDescr_t)descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseCcsrgeam(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrgeam((cusparseHandle_t)handle, m, n, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuComplex*)csrValA, csrRowPtrA, csrColIndA, (const cuComplex*)beta, (const cusparseMatDescr_t)descrB, nnzB, (const cuComplex*)csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, (cuComplex*)csrValC, csrRowPtrC, csrColIndC)); } hipsparseStatus_t hipsparseZcsrgeam(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrgeam((cusparseHandle_t)handle, m, n, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuDoubleComplex*)csrValA, csrRowPtrA, csrColIndA, (const cuDoubleComplex*)beta, (const cusparseMatDescr_t)descrB, nnzB, (const cuDoubleComplex*)csrValB, csrRowPtrB, csrColIndB, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)csrValC, csrRowPtrC, csrColIndC)); } #endif hipsparseStatus_t hipsparseScsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const float* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrgeam2_bufferSizeExt((cusparseHandle_t)handle, m, n, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, (const cusparseMatDescr_t)descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseDcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const double* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrgeam2_bufferSizeExt((cusparseHandle_t)handle, m, n, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, (const cusparseMatDescr_t)descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseCcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrgeam2_bufferSizeExt((cusparseHandle_t)handle, m, n, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuComplex*)beta, (const cusparseMatDescr_t)descrB, nnzB, (const cuComplex*)csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, (cuComplex*)csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseZcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipDoubleComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrgeam2_bufferSizeExt((cusparseHandle_t)handle, m, n, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuDoubleComplex*)beta, (const cusparseMatDescr_t)descrB, nnzB, (const cuDoubleComplex*)csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes)); } hipsparseStatus_t hipsparseXcsrgeam2Nnz(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, int nnzA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, int* csrSortedRowPtrC, int* nnzTotalDevHostPtr, void* workspace) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseXcsrgeam2Nnz((cusparseHandle_t)handle, m, n, (const cusparseMatDescr_t)descrA, nnzA, csrSortedRowPtrA, csrSortedColIndA, (const cusparseMatDescr_t)descrB, nnzB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, csrSortedRowPtrC, nnzTotalDevHostPtr, workspace)); } hipsparseStatus_t hipsparseScsrgeam2(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, float* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseScsrgeam2((cusparseHandle_t)handle, m, n, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, (const cusparseMatDescr_t)descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer)); } hipsparseStatus_t hipsparseDcsrgeam2(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, double* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDcsrgeam2((cusparseHandle_t)handle, m, n, alpha, (const cusparseMatDescr_t)descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, (const cusparseMatDescr_t)descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer)); } hipsparseStatus_t hipsparseCcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseCcsrgeam2((cusparseHandle_t)handle, m, n, (const cuComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuComplex*)beta, (const cusparseMatDescr_t)descrB, nnzB, (const cuComplex*)csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, (cuComplex*)csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer)); } hipsparseStatus_t hipsparseZcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseZcsrgeam2((cusparseHandle_t)handle, m, n, (const cuDoubleComplex*)alpha, (const cusparseMatDescr_t)descrA, nnzA, (const cuDoubleComplex*)csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, (const cuDoubleComplex*)beta, (const cusparseMatDescr_t)descrB, nnzB, (const cuDoubleComplex*)csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, (const cusparseMatDescr_t)descrC, (cuDoubleComplex*)csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer)); } ./library/src/nvidia_detail/generic/0000775000175100017510000000000015176134511017552 5ustar jenkinsjenkins./library/src/nvidia_detail/generic/hipsparse_scatter.cpp0000664000175100017510000000425315176134305024006 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseScatter(hipsparseHandle_t handle, hipsparseConstSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseScatter( (cusparseHandle_t)handle, (cusparseConstSpVecDescr_t)vecX, (cusparseDnVecDescr_t)vecY)); } #elif(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseScatter(hipsparseHandle_t handle, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseScatter( (cusparseHandle_t)handle, (cusparseSpVecDescr_t)vecX, (cusparseDnVecDescr_t)vecY)); } #endif ./library/src/nvidia_detail/generic/hipsparse_axpby.cpp0000664000175100017510000000565315176134305023471 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseAxpby(hipsparseHandle_t handle, const void* alpha, hipsparseConstSpVecDescr_t vecX, const void* beta, hipsparseDnVecDescr_t vecY) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseAxpby((cusparseHandle_t)handle, alpha, (cusparseConstSpVecDescr_t)vecX, beta, (cusparseDnVecDescr_t)vecY)); } #elif(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseAxpby(hipsparseHandle_t handle, const void* alpha, hipsparseSpVecDescr_t vecX, const void* beta, hipsparseDnVecDescr_t vecY) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseAxpby((cusparseHandle_t)handle, alpha, (cusparseSpVecDescr_t)vecX, beta, (cusparseDnVecDescr_t)vecY)); } #endif ./library/src/nvidia_detail/generic/hipsparse_spgemm_reuse.cpp0000664000175100017510000003560715176134305025043 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpGEMMreuse_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_workEstimation((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), (cusparseConstSpMatDescr_t)matA, (cusparseConstSpMatDescr_t)matB, (cusparseSpMatDescr_t)matC, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize1, externalBuffer1)); } #elif(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpGEMMreuse_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_workEstimation((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), (cusparseSpMatDescr_t)matA, (cusparseSpMatDescr_t)matB, (cusparseSpMatDescr_t)matC, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize1, externalBuffer1)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpGEMMreuse_nnz(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2, size_t* bufferSize3, void* externalBuffer3, size_t* bufferSize4, void* externalBuffer4) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_nnz((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), (cusparseConstSpMatDescr_t)matA, (cusparseConstSpMatDescr_t)matB, (cusparseSpMatDescr_t)matC, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize2, externalBuffer2, bufferSize3, externalBuffer3, bufferSize4, externalBuffer4)); } #elif(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpGEMMreuse_nnz(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2, size_t* bufferSize3, void* externalBuffer3, size_t* bufferSize4, void* externalBuffer4) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_nnz((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), (cusparseSpMatDescr_t)matA, (cusparseSpMatDescr_t)matB, (cusparseSpMatDescr_t)matC, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize2, externalBuffer2, bufferSize3, externalBuffer3, bufferSize4, externalBuffer4)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpGEMMreuse_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_compute((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr)); } #elif(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpGEMMreuse_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_compute((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseSpMatDescr_t)matA, (cusparseSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpGEMMreuse_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize5, void* externalBuffer5) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_copy((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), (cusparseConstSpMatDescr_t)matA, (cusparseConstSpMatDescr_t)matB, (cusparseSpMatDescr_t)matC, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize5, externalBuffer5)); } #elif(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpGEMMreuse_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseSpMatDescr_t matC, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize5, void* externalBuffer5) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMMreuse_copy((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), (cusparseSpMatDescr_t)matA, (cusparseSpMatDescr_t)matB, (cusparseSpMatDescr_t)matC, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize5, externalBuffer5)); } #endif ./library/src/nvidia_detail/generic/hipsparse_spgemm.cpp0000664000175100017510000003035515176134305023633 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseSpGEMM_createDescr(hipsparseSpGEMMDescr_t* descr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_createDescr((cusparseSpGEMMDescr_t*)descr)); } #endif #if(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseSpGEMM_destroyDescr(hipsparseSpGEMMDescr_t descr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_destroyDescr((cusparseSpGEMMDescr_t)descr)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpGEMM_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_workEstimation((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize1, externalBuffer1)); } #elif(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseSpGEMM_workEstimation(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize1, void* externalBuffer1) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_workEstimation((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseSpMatDescr_t)matA, (cusparseSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize1, externalBuffer1)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpGEMM_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_compute((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize2, externalBuffer2)); } #elif(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseSpGEMM_compute(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr, size_t* bufferSize2, void* externalBuffer2) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_compute((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseSpMatDescr_t)matA, (cusparseSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr, bufferSize2, externalBuffer2)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpGEMM_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_copy((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr)); } #elif(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseSpGEMM_copy(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseSpMatDescr_t matA, hipsparseSpMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSpGEMMAlg_t alg, hipsparseSpGEMMDescr_t spgemmDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpGEMM_copy((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseSpMatDescr_t)matA, (cusparseSpMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, computeType, hipsparse::hipSpGEMMAlgToCudaSpGEMMAlg(alg), (cusparseSpGEMMDescr_t)spgemmDescr)); } #endif ./library/src/nvidia_detail/generic/hipsparse_spmv.cpp0000664000175100017510000002235215176134511023325 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMV_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnVecDescr_t)vecX, beta, (const cusparseDnVecDescr_t)vecY, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMVAlgToCudaSpMVAlg(alg), pBufferSizeInBytes)); } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpMV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMV_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnVecDescr_t)vecX, beta, (const cusparseDnVecDescr_t)vecY, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMVAlgToCudaSpMVAlg(alg), pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMV_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer) { if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(matA == nullptr || vecX == nullptr || vecY == nullptr || alpha == nullptr || beta == nullptr || externalBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpMV_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer) { if(handle == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } if(matA == nullptr || vecX == nullptr || vecY == nullptr || alpha == nullptr || beta == nullptr || externalBuffer == nullptr) { return HIPSPARSE_STATUS_INVALID_VALUE; } return HIPSPARSE_STATUS_SUCCESS; } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMV(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMV((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnVecDescr_t)vecX, beta, (const cusparseDnVecDescr_t)vecY, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMVAlgToCudaSpMVAlg(alg), externalBuffer)); } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpMV(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t vecX, const void* beta, const hipsparseDnVecDescr_t vecY, hipDataType computeType, hipsparseSpMVAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMV((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnVecDescr_t)vecX, beta, (const cusparseDnVecDescr_t)vecY, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMVAlgToCudaSpMVAlg(alg), externalBuffer)); } #endif ./library/src/nvidia_detail/generic/hipsparse_spmm.cpp0000664000175100017510000002511515176134305023315 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMM_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, beta, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMMAlgToCudaSpMMAlg(alg), pBufferSizeInBytes)); } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseSpMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMM_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, beta, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMMAlgToCudaSpMMAlg(alg), pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMM_preprocess((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, beta, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMMAlgToCudaSpMMAlg(alg), externalBuffer)); } #elif(CUDART_VERSION >= 11021) hipsparseStatus_t hipsparseSpMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMM_preprocess((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, beta, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMMAlgToCudaSpMMAlg(alg), externalBuffer)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMM((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, beta, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMMAlgToCudaSpMMAlg(alg), externalBuffer)); } #elif(CUDART_VERSION >= 10010) hipsparseStatus_t hipsparseSpMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpMMAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpMM((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, beta, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpMMAlgToCudaSpMMAlg(alg), externalBuffer)); } #endif ./library/src/nvidia_detail/generic/hipsparse_sparse2dense.cpp0000664000175100017510000001121715176134305024735 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSparseToDense_bufferSize(hipsparseHandle_t handle, hipsparseConstSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSparseToDense_bufferSize((cusparseHandle_t)handle, (cusparseConstSpMatDescr_t)matA, (cusparseDnMatDescr_t)matB, hipsparse::hipSpToDnAlgToCudaSpToDnAlg(alg), pBufferSizeInBytes)); } #elif(CUDART_VERSION >= 11020) hipsparseStatus_t hipsparseSparseToDense_bufferSize(hipsparseHandle_t handle, hipsparseSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSparseToDense_bufferSize((cusparseHandle_t)handle, (cusparseSpMatDescr_t)matA, (cusparseDnMatDescr_t)matB, hipsparse::hipSpToDnAlgToCudaSpToDnAlg(alg), pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSparseToDense(hipsparseHandle_t handle, hipsparseConstSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSparseToDense((cusparseHandle_t)handle, (cusparseConstSpMatDescr_t)matA, (cusparseDnMatDescr_t)matB, hipsparse::hipSpToDnAlgToCudaSpToDnAlg(alg), externalBuffer)); } #elif(CUDART_VERSION >= 11020) hipsparseStatus_t hipsparseSparseToDense(hipsparseHandle_t handle, hipsparseSpMatDescr_t matA, hipsparseDnMatDescr_t matB, hipsparseSparseToDenseAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSparseToDense((cusparseHandle_t)handle, (cusparseSpMatDescr_t)matA, (cusparseDnMatDescr_t)matB, hipsparse::hipSpToDnAlgToCudaSpToDnAlg(alg), externalBuffer)); } #endif ./library/src/nvidia_detail/generic/hipsparse_sddmm.cpp0000664000175100017510000002517015176134305023446 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSDDMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSDDMM_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstDnMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSDDMMAlgToCudaSDDMMAlg(alg), pBufferSizeInBytes)); } #elif(CUDART_VERSION >= 11022) hipsparseStatus_t hipsparseSDDMM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseDnMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSDDMM_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseDnMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSDDMMAlgToCudaSDDMMAlg(alg), pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSDDMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSDDMM_preprocess((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstDnMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSDDMMAlgToCudaSDDMMAlg(alg), tempBuffer)); } #elif(CUDART_VERSION >= 11022) hipsparseStatus_t hipsparseSDDMM_preprocess(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseDnMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSDDMM_preprocess((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseDnMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSDDMMAlgToCudaSDDMMAlg(alg), tempBuffer)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSDDMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstDnMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSDDMM((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstDnMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSDDMMAlgToCudaSDDMMAlg(alg), tempBuffer)); } #elif(CUDART_VERSION >= 11022) hipsparseStatus_t hipsparseSDDMM(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseDnMatDescr_t matA, const hipsparseDnMatDescr_t matB, const void* beta, hipsparseSpMatDescr_t matC, hipDataType computeType, hipsparseSDDMMAlg_t alg, void* tempBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSDDMM((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseDnMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, beta, (cusparseSpMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSDDMMAlgToCudaSDDMMAlg(alg), tempBuffer)); } #endif ./library/src/nvidia_detail/generic/hipsparse_rot.cpp0000664000175100017510000000424015176134305023141 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 11000 && CUDART_VERSION < 13000) hipsparseStatus_t hipsparseRot(hipsparseHandle_t handle, const void* c_coeff, const void* s_coeff, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseRot((cusparseHandle_t)handle, c_coeff, s_coeff, (cusparseSpVecDescr_t)vecX, (cusparseDnVecDescr_t)vecY)); } #endif ./library/src/nvidia_detail/generic/hipsparse_dense2sparse.cpp0000664000175100017510000001475615176134305024750 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDenseToSparse_bufferSize(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDenseToSparse_bufferSize((cusparseHandle_t)handle, (cusparseConstDnMatDescr_t)matA, (cusparseSpMatDescr_t)matB, hipsparse::hipDnToSpAlgToCudaDnToSpAlg(alg), pBufferSizeInBytes)); } #elif(CUDART_VERSION >= 11020) hipsparseStatus_t hipsparseDenseToSparse_bufferSize(hipsparseHandle_t handle, hipsparseDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDenseToSparse_bufferSize((cusparseHandle_t)handle, (cusparseDnMatDescr_t)matA, (cusparseSpMatDescr_t)matB, hipsparse::hipDnToSpAlgToCudaDnToSpAlg(alg), pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDenseToSparse_analysis(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDenseToSparse_analysis((cusparseHandle_t)handle, (cusparseConstDnMatDescr_t)matA, (cusparseSpMatDescr_t)matB, hipsparse::hipDnToSpAlgToCudaDnToSpAlg(alg), externalBuffer)); } #elif(CUDART_VERSION >= 11020) hipsparseStatus_t hipsparseDenseToSparse_analysis(hipsparseHandle_t handle, hipsparseDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDenseToSparse_analysis((cusparseHandle_t)handle, (cusparseDnMatDescr_t)matA, (cusparseSpMatDescr_t)matB, hipsparse::hipDnToSpAlgToCudaDnToSpAlg(alg), externalBuffer)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseDenseToSparse_convert(hipsparseHandle_t handle, hipsparseConstDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDenseToSparse_convert((cusparseHandle_t)handle, (cusparseConstDnMatDescr_t)matA, (cusparseSpMatDescr_t)matB, hipsparse::hipDnToSpAlgToCudaDnToSpAlg(alg), externalBuffer)); } #elif(CUDART_VERSION >= 11020) hipsparseStatus_t hipsparseDenseToSparse_convert(hipsparseHandle_t handle, hipsparseDnMatDescr_t matA, hipsparseSpMatDescr_t matB, hipsparseDenseToSparseAlg_t alg, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseDenseToSparse_convert((cusparseHandle_t)handle, (cusparseDnMatDescr_t)matA, (cusparseSpMatDescr_t)matB, hipsparse::hipDnToSpAlgToCudaDnToSpAlg(alg), externalBuffer)); } #endif ./library/src/nvidia_detail/generic/hipsparse_spvv.cpp0000664000175100017510000001255515176134305023343 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpVV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseConstSpVecDescr_t vecX, hipsparseConstDnVecDescr_t vecY, void* result, hipDataType computeType, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpVV_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opX), (cusparseConstSpVecDescr_t)vecX, (cusparseConstDnVecDescr_t)vecY, result, hipsparse::hipDataTypeToCudaDataType(computeType), pBufferSizeInBytes)); } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpVV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY, void* result, hipDataType computeType, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpVV_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opX), (cusparseSpVecDescr_t)vecX, (cusparseDnVecDescr_t)vecY, result, hipsparse::hipDataTypeToCudaDataType(computeType), pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpVV(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseConstSpVecDescr_t vecX, hipsparseConstDnVecDescr_t vecY, void* result, hipDataType computeType, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpVV((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opX), (cusparseConstSpVecDescr_t)vecX, (cusparseConstDnVecDescr_t)vecY, result, hipsparse::hipDataTypeToCudaDataType(computeType), externalBuffer)); } #elif(CUDART_VERSION > 10010 || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) hipsparseStatus_t hipsparseSpVV(hipsparseHandle_t handle, hipsparseOperation_t opX, hipsparseSpVecDescr_t vecX, hipsparseDnVecDescr_t vecY, void* result, hipDataType computeType, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpVV((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opX), (cusparseSpVecDescr_t)vecX, (cusparseDnVecDescr_t)vecY, result, hipsparse::hipDataTypeToCudaDataType(computeType), externalBuffer)); } #endif ./library/src/nvidia_detail/generic/hipsparse_spsm.cpp0000664000175100017510000002645515176134511023332 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpSM_createDescr(hipsparseSpSMDescr_t* descr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_createDescr((cusparseSpSMDescr_t*)descr)); } #endif #if(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpSM_destroyDescr(hipsparseSpSMDescr_t descr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_destroyDescr((cusparseSpSMDescr_t)descr)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpSM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSMAlgToCudaSpSMAlg(alg), (cusparseSpSMDescr_t)spsmDescr, pBufferSizeInBytes)); } #elif(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpSM_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSMAlgToCudaSpSMAlg(alg), (cusparseSpSMDescr_t)spsmDescr, pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpSM_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSMAlgToCudaSpSMAlg(alg), (cusparseSpSMDescr_t)spsmDescr, externalBuffer)); } #elif(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpSM_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSMAlgToCudaSpSMAlg(alg), (cusparseSpSMDescr_t)spsmDescr, externalBuffer)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpSM_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnMatDescr_t)matB, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSMAlgToCudaSpSMAlg(alg), (cusparseSpSMDescr_t)spsmDescr)); } #elif(CUDART_VERSION >= 11031) hipsparseStatus_t hipsparseSpSM_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, hipsparseOperation_t opB, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnMatDescr_t matB, const hipsparseDnMatDescr_t matC, hipDataType computeType, hipsparseSpSMAlg_t alg, hipsparseSpSMDescr_t spsmDescr, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSM_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), hipsparse::hipOperationToCudaOperation(opB), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnMatDescr_t)matB, (const cusparseDnMatDescr_t)matC, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSMAlgToCudaSpSMAlg(alg), (cusparseSpSMDescr_t)spsmDescr)); } #endif ./library/src/nvidia_detail/generic/hipsparse_spsv.cpp0000664000175100017510000002430715176134305023336 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 11030) hipsparseStatus_t hipsparseSpSV_createDescr(hipsparseSpSVDescr_t* descr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_createDescr((cusparseSpSVDescr_t*)descr)); } #endif #if(CUDART_VERSION >= 11030) hipsparseStatus_t hipsparseSpSV_destroyDescr(hipsparseSpSVDescr_t descr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_destroyDescr((cusparseSpSVDescr_t)descr)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpSV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnVecDescr_t)x, (const cusparseDnVecDescr_t)y, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSVAlgToCudaSpSVAlg(alg), (cusparseSpSVDescr_t)spsvDescr, pBufferSizeInBytes)); } #elif(CUDART_VERSION >= 11030) hipsparseStatus_t hipsparseSpSV_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, size_t* pBufferSizeInBytes) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_bufferSize((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnVecDescr_t)x, (const cusparseDnVecDescr_t)y, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSVAlgToCudaSpSVAlg(alg), (cusparseSpSVDescr_t)spsvDescr, pBufferSizeInBytes)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpSV_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnVecDescr_t)x, (const cusparseDnVecDescr_t)y, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSVAlgToCudaSpSVAlg(alg), (cusparseSpSVDescr_t)spsvDescr, externalBuffer)); } #elif(CUDART_VERSION >= 11030) hipsparseStatus_t hipsparseSpSV_analysis(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr, void* externalBuffer) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_analysis((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnVecDescr_t)x, (const cusparseDnVecDescr_t)y, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSVAlgToCudaSpSVAlg(alg), (cusparseSpSVDescr_t)spsvDescr, externalBuffer)); } #endif #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseSpSV_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, hipsparseConstSpMatDescr_t matA, hipsparseConstDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (cusparseConstSpMatDescr_t)matA, (cusparseConstDnVecDescr_t)x, (const cusparseDnVecDescr_t)y, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSVAlgToCudaSpSVAlg(alg), (cusparseSpSVDescr_t)spsvDescr)); } #elif(CUDART_VERSION >= 11030) hipsparseStatus_t hipsparseSpSV_solve(hipsparseHandle_t handle, hipsparseOperation_t opA, const void* alpha, const hipsparseSpMatDescr_t matA, const hipsparseDnVecDescr_t x, const hipsparseDnVecDescr_t y, hipDataType computeType, hipsparseSpSVAlg_t alg, hipsparseSpSVDescr_t spsvDescr) { return hipsparse::hipCUSPARSEStatusToHIPStatus( cusparseSpSV_solve((cusparseHandle_t)handle, hipsparse::hipOperationToCudaOperation(opA), alpha, (const cusparseSpMatDescr_t)matA, (const cusparseDnVecDescr_t)x, (const cusparseDnVecDescr_t)y, hipsparse::hipDataTypeToCudaDataType(computeType), hipsparse::hipSpSVAlgToCudaSpSVAlg(alg), (cusparseSpSVDescr_t)spsvDescr)); } #endif ./library/src/nvidia_detail/generic/hipsparse_gather.cpp0000664000175100017510000000424315176134305023612 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #include "../utility.h" #if(CUDART_VERSION >= 12000) hipsparseStatus_t hipsparseGather(hipsparseHandle_t handle, hipsparseConstDnVecDescr_t vecY, hipsparseSpVecDescr_t vecX) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseGather( (cusparseHandle_t)handle, (cusparseConstDnVecDescr_t)vecY, (cusparseSpVecDescr_t)vecX)); } #elif(CUDART_VERSION >= 11000) hipsparseStatus_t hipsparseGather(hipsparseHandle_t handle, hipsparseDnVecDescr_t vecY, hipsparseSpVecDescr_t vecX) { return hipsparse::hipCUSPARSEStatusToHIPStatus(cusparseGather( (cusparseHandle_t)handle, (cusparseDnVecDescr_t)vecY, (cusparseSpVecDescr_t)vecX)); } #endif ./library/src/nvidia_detail/utility.h0000664000175100017510000010154315176134511020016 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.h" #include #include #include #define TO_STR2(x) #x #define TO_STR(x) TO_STR2(x) #define RETURN_IF_CUSPARSE_ERROR(INPUT_STATUS_FOR_CHECK) \ { \ cusparseStatus_t TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ if(TMP_STATUS_FOR_CHECK != CUSPARSE_STATUS_SUCCESS) \ { \ return hipsparse::hipCUSPARSEStatusToHIPStatus(TMP_STATUS_FOR_CHECK); \ } \ } namespace hipsparse { inline hipsparseStatus_t hipCUSPARSEStatusToHIPStatus(cusparseStatus_t cuStatus) { #if(CUDART_VERSION >= 11003) switch(cuStatus) { case CUSPARSE_STATUS_SUCCESS: return HIPSPARSE_STATUS_SUCCESS; case CUSPARSE_STATUS_NOT_INITIALIZED: return HIPSPARSE_STATUS_NOT_INITIALIZED; case CUSPARSE_STATUS_ALLOC_FAILED: return HIPSPARSE_STATUS_ALLOC_FAILED; case CUSPARSE_STATUS_INVALID_VALUE: return HIPSPARSE_STATUS_INVALID_VALUE; case CUSPARSE_STATUS_ARCH_MISMATCH: return HIPSPARSE_STATUS_ARCH_MISMATCH; case CUSPARSE_STATUS_MAPPING_ERROR: return HIPSPARSE_STATUS_MAPPING_ERROR; case CUSPARSE_STATUS_EXECUTION_FAILED: return HIPSPARSE_STATUS_EXECUTION_FAILED; case CUSPARSE_STATUS_INTERNAL_ERROR: return HIPSPARSE_STATUS_INTERNAL_ERROR; case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: return HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED; case CUSPARSE_STATUS_ZERO_PIVOT: return HIPSPARSE_STATUS_ZERO_PIVOT; case CUSPARSE_STATUS_NOT_SUPPORTED: return HIPSPARSE_STATUS_NOT_SUPPORTED; case CUSPARSE_STATUS_INSUFFICIENT_RESOURCES: return HIPSPARSE_STATUS_INSUFFICIENT_RESOURCES; default: throw "Non existent cusparseStatus_t"; } #elif(CUDART_VERSION >= 10010) switch(cuStatus) { case CUSPARSE_STATUS_SUCCESS: return HIPSPARSE_STATUS_SUCCESS; case CUSPARSE_STATUS_NOT_INITIALIZED: return HIPSPARSE_STATUS_NOT_INITIALIZED; case CUSPARSE_STATUS_ALLOC_FAILED: return HIPSPARSE_STATUS_ALLOC_FAILED; case CUSPARSE_STATUS_INVALID_VALUE: return HIPSPARSE_STATUS_INVALID_VALUE; case CUSPARSE_STATUS_ARCH_MISMATCH: return HIPSPARSE_STATUS_ARCH_MISMATCH; case CUSPARSE_STATUS_MAPPING_ERROR: return HIPSPARSE_STATUS_MAPPING_ERROR; case CUSPARSE_STATUS_EXECUTION_FAILED: return HIPSPARSE_STATUS_EXECUTION_FAILED; case CUSPARSE_STATUS_INTERNAL_ERROR: return HIPSPARSE_STATUS_INTERNAL_ERROR; case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: return HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED; case CUSPARSE_STATUS_ZERO_PIVOT: return HIPSPARSE_STATUS_ZERO_PIVOT; case CUSPARSE_STATUS_NOT_SUPPORTED: return HIPSPARSE_STATUS_NOT_SUPPORTED; default: throw "Non existent cusparseStatus_t"; } #else #error "CUDART_VERSION is not supported" #endif } inline cusparseStatus_t hipSPARSEStatusToCUSPARSEStatus(hipsparseStatus_t hipStatus) { #if(CUDART_VERSION >= 11003) switch(hipStatus) { case HIPSPARSE_STATUS_SUCCESS: return CUSPARSE_STATUS_SUCCESS; case HIPSPARSE_STATUS_NOT_INITIALIZED: return CUSPARSE_STATUS_NOT_INITIALIZED; case HIPSPARSE_STATUS_ALLOC_FAILED: return CUSPARSE_STATUS_ALLOC_FAILED; case HIPSPARSE_STATUS_INVALID_VALUE: return CUSPARSE_STATUS_INVALID_VALUE; case HIPSPARSE_STATUS_ARCH_MISMATCH: return CUSPARSE_STATUS_ARCH_MISMATCH; case HIPSPARSE_STATUS_MAPPING_ERROR: return CUSPARSE_STATUS_MAPPING_ERROR; case HIPSPARSE_STATUS_EXECUTION_FAILED: return CUSPARSE_STATUS_EXECUTION_FAILED; case HIPSPARSE_STATUS_INTERNAL_ERROR: return CUSPARSE_STATUS_INTERNAL_ERROR; case HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: return CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED; case HIPSPARSE_STATUS_ZERO_PIVOT: return CUSPARSE_STATUS_ZERO_PIVOT; case HIPSPARSE_STATUS_NOT_SUPPORTED: return CUSPARSE_STATUS_NOT_SUPPORTED; case HIPSPARSE_STATUS_INSUFFICIENT_RESOURCES: return CUSPARSE_STATUS_INSUFFICIENT_RESOURCES; default: throw "Non existent hipsparseStatus_t"; } #elif(CUDART_VERSION >= 10010) switch(hipStatus) { case HIPSPARSE_STATUS_SUCCESS: return CUSPARSE_STATUS_SUCCESS; case HIPSPARSE_STATUS_NOT_INITIALIZED: return CUSPARSE_STATUS_NOT_INITIALIZED; case HIPSPARSE_STATUS_ALLOC_FAILED: return CUSPARSE_STATUS_ALLOC_FAILED; case HIPSPARSE_STATUS_INVALID_VALUE: return CUSPARSE_STATUS_INVALID_VALUE; case HIPSPARSE_STATUS_ARCH_MISMATCH: return CUSPARSE_STATUS_ARCH_MISMATCH; case HIPSPARSE_STATUS_MAPPING_ERROR: return CUSPARSE_STATUS_MAPPING_ERROR; case HIPSPARSE_STATUS_EXECUTION_FAILED: return CUSPARSE_STATUS_EXECUTION_FAILED; case HIPSPARSE_STATUS_INTERNAL_ERROR: return CUSPARSE_STATUS_INTERNAL_ERROR; case HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: return CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED; case HIPSPARSE_STATUS_ZERO_PIVOT: return CUSPARSE_STATUS_ZERO_PIVOT; case HIPSPARSE_STATUS_NOT_SUPPORTED: return CUSPARSE_STATUS_NOT_SUPPORTED; default: throw "Non existent hipsparseStatus_t"; } #else #error "CUDART_VERSION is not supported" #endif } inline cusparsePointerMode_t hipPointerModeToCudaPointerMode(hipsparsePointerMode_t mode) { switch(mode) { case HIPSPARSE_POINTER_MODE_HOST: return CUSPARSE_POINTER_MODE_HOST; case HIPSPARSE_POINTER_MODE_DEVICE: return CUSPARSE_POINTER_MODE_DEVICE; default: throw "Non existent hipsparsePointerMode_t"; } } inline hipsparsePointerMode_t CudaPointerModeToHIPPointerMode(cusparsePointerMode_t mode) { switch(mode) { case CUSPARSE_POINTER_MODE_HOST: return HIPSPARSE_POINTER_MODE_HOST; case CUSPARSE_POINTER_MODE_DEVICE: return HIPSPARSE_POINTER_MODE_DEVICE; default: throw "Non existent cusparsePointerMode_t"; } } inline cusparseAction_t hipActionToCudaAction(hipsparseAction_t action) { switch(action) { case HIPSPARSE_ACTION_SYMBOLIC: return CUSPARSE_ACTION_SYMBOLIC; case HIPSPARSE_ACTION_NUMERIC: return CUSPARSE_ACTION_NUMERIC; default: throw "Non existent hipsparseAction_t"; } } inline hipsparseAction_t CudaActionToHIPAction(cusparseAction_t action) { switch(action) { case CUSPARSE_ACTION_SYMBOLIC: return HIPSPARSE_ACTION_SYMBOLIC; case CUSPARSE_ACTION_NUMERIC: return HIPSPARSE_ACTION_NUMERIC; default: throw "Non existent cusparseAction_t"; } } inline cusparseMatrixType_t hipMatrixTypeToCudaMatrixType(hipsparseMatrixType_t type) { switch(type) { case HIPSPARSE_MATRIX_TYPE_GENERAL: return CUSPARSE_MATRIX_TYPE_GENERAL; case HIPSPARSE_MATRIX_TYPE_SYMMETRIC: return CUSPARSE_MATRIX_TYPE_SYMMETRIC; case HIPSPARSE_MATRIX_TYPE_HERMITIAN: return CUSPARSE_MATRIX_TYPE_HERMITIAN; case HIPSPARSE_MATRIX_TYPE_TRIANGULAR: return CUSPARSE_MATRIX_TYPE_TRIANGULAR; default: throw "Non existent hipsparseMatrixType_t"; } } inline hipsparseMatrixType_t CudaMatrixTypeToHIPMatrixType(cusparseMatrixType_t type) { switch(type) { case CUSPARSE_MATRIX_TYPE_GENERAL: return HIPSPARSE_MATRIX_TYPE_GENERAL; case CUSPARSE_MATRIX_TYPE_SYMMETRIC: return HIPSPARSE_MATRIX_TYPE_SYMMETRIC; case CUSPARSE_MATRIX_TYPE_HERMITIAN: return HIPSPARSE_MATRIX_TYPE_HERMITIAN; case CUSPARSE_MATRIX_TYPE_TRIANGULAR: return HIPSPARSE_MATRIX_TYPE_TRIANGULAR; default: throw "Non existent cusparseMatrixType_t"; } } inline cusparseFillMode_t hipFillToCudaFill(hipsparseFillMode_t fill) { switch(fill) { case HIPSPARSE_FILL_MODE_LOWER: return CUSPARSE_FILL_MODE_LOWER; case HIPSPARSE_FILL_MODE_UPPER: return CUSPARSE_FILL_MODE_UPPER; default: throw "Non existent hipsparseFillMode_t"; } } inline hipsparseFillMode_t CudaFillToHIPFill(cusparseFillMode_t fill) { switch(fill) { case CUSPARSE_FILL_MODE_LOWER: return HIPSPARSE_FILL_MODE_LOWER; case CUSPARSE_FILL_MODE_UPPER: return HIPSPARSE_FILL_MODE_UPPER; default: throw "Non existent cusparseFillMode_t"; } } inline cusparseDiagType_t hipDiagonalToCudaDiagonal(hipsparseDiagType_t diagonal) { switch(diagonal) { case HIPSPARSE_DIAG_TYPE_NON_UNIT: return CUSPARSE_DIAG_TYPE_NON_UNIT; case HIPSPARSE_DIAG_TYPE_UNIT: return CUSPARSE_DIAG_TYPE_UNIT; default: throw "Non existent hipsparseDiagType_t"; } } inline hipsparseDiagType_t CudaDiagonalToHIPDiagonal(cusparseDiagType_t diagonal) { switch(diagonal) { case CUSPARSE_DIAG_TYPE_NON_UNIT: return HIPSPARSE_DIAG_TYPE_NON_UNIT; case CUSPARSE_DIAG_TYPE_UNIT: return HIPSPARSE_DIAG_TYPE_UNIT; default: throw "Non existent cusparseDiagType_t"; } } inline cusparseIndexBase_t hipIndexBaseToCudaIndexBase(hipsparseIndexBase_t base) { switch(base) { case HIPSPARSE_INDEX_BASE_ZERO: return CUSPARSE_INDEX_BASE_ZERO; case HIPSPARSE_INDEX_BASE_ONE: return CUSPARSE_INDEX_BASE_ONE; default: throw "Non existent hipsparseIndexBase_t"; } } inline hipsparseIndexBase_t CudaIndexBaseToHIPIndexBase(cusparseIndexBase_t base) { switch(base) { case CUSPARSE_INDEX_BASE_ZERO: return HIPSPARSE_INDEX_BASE_ZERO; case CUSPARSE_INDEX_BASE_ONE: return HIPSPARSE_INDEX_BASE_ONE; default: throw "Non existent cusparseIndexBase_t"; } } inline cusparseOperation_t hipOperationToCudaOperation(hipsparseOperation_t op) { switch(op) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: return CUSPARSE_OPERATION_NON_TRANSPOSE; case HIPSPARSE_OPERATION_TRANSPOSE: return CUSPARSE_OPERATION_TRANSPOSE; case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: return CUSPARSE_OPERATION_CONJUGATE_TRANSPOSE; default: throw "Non existent hipsparseOperation_t"; } } inline hipsparseOperation_t CudaOperationToHIPOperation(cusparseOperation_t op) { switch(op) { case CUSPARSE_OPERATION_NON_TRANSPOSE: return HIPSPARSE_OPERATION_NON_TRANSPOSE; case CUSPARSE_OPERATION_TRANSPOSE: return HIPSPARSE_OPERATION_TRANSPOSE; case CUSPARSE_OPERATION_CONJUGATE_TRANSPOSE: return HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE; default: throw "Non existent cusparseOperation_t"; } } inline cusparseDirection_t hipDirectionToCudaDirection(hipsparseDirection_t op) { switch(op) { case HIPSPARSE_DIRECTION_ROW: return CUSPARSE_DIRECTION_ROW; case HIPSPARSE_DIRECTION_COLUMN: return CUSPARSE_DIRECTION_COLUMN; default: throw "Non existent hipsparseDirection_t"; } } inline hipsparseDirection_t CudaDirectionToHIPDirection(cusparseDirection_t op) { switch(op) { case CUSPARSE_DIRECTION_ROW: return HIPSPARSE_DIRECTION_ROW; case CUSPARSE_DIRECTION_COLUMN: return HIPSPARSE_DIRECTION_COLUMN; default: throw "Non existent cusparseDirection_t"; } } #if CUDART_VERSION < 11000 inline cusparseHybPartition_t hipHybPartitionToCudaHybPartition(hipsparseHybPartition_t part) { switch(part) { case HIPSPARSE_HYB_PARTITION_AUTO: return CUSPARSE_HYB_PARTITION_AUTO; case HIPSPARSE_HYB_PARTITION_USER: return CUSPARSE_HYB_PARTITION_USER; case HIPSPARSE_HYB_PARTITION_MAX: return CUSPARSE_HYB_PARTITION_MAX; default: throw "Non existent hipsparseHybPartition_t"; } } #endif inline cusparseSolvePolicy_t hipPolicyToCudaPolicy(hipsparseSolvePolicy_t policy) { switch(policy) { case HIPSPARSE_SOLVE_POLICY_NO_LEVEL: return CUSPARSE_SOLVE_POLICY_NO_LEVEL; case HIPSPARSE_SOLVE_POLICY_USE_LEVEL: return CUSPARSE_SOLVE_POLICY_USE_LEVEL; default: throw "Non existent hipsparseSolvePolicy_t"; } } #if CUDART_VERSION < 11050 inline cusparseSideMode_t hipSideToCudaSide(hipsparseSideMode_t side) { switch(side) { case HIPSPARSE_SIDE_LEFT: return CUSPARSE_SIDE_LEFT; case HIPSPARSE_SIDE_RIGHT: return CUSPARSE_SIDE_RIGHT; default: throw "Non existent hipsparseSideMode_t"; } } inline hipsparseSideMode_t CudaSideToHIPSide(cusparseSideMode_t side) { switch(side) { case CUSPARSE_SIDE_LEFT: return HIPSPARSE_SIDE_LEFT; case CUSPARSE_SIDE_RIGHT: return HIPSPARSE_SIDE_RIGHT; default: throw "Non existent cusparseSideMode_t"; } } #endif #if CUDART_VERSION > 10000 inline cudaDataType hipDataTypeToCudaDataType(hipDataType datatype) { switch(datatype) { case HIP_R_8I: return CUDA_R_8I; case HIP_R_32I: return CUDA_R_32I; case HIP_R_16F: return CUDA_R_16F; case HIP_R_16BF: return CUDA_R_16BF; case HIP_R_32F: return CUDA_R_32F; case HIP_R_64F: return CUDA_R_64F; case HIP_C_32F: return CUDA_C_32F; case HIP_C_64F: return CUDA_C_64F; default: throw "Non existent hipDataType"; } } inline hipDataType CudaDataTypeToHIPDataType(cudaDataType datatype) { switch(datatype) { case CUDA_R_8I: return HIP_R_8I; case CUDA_R_32I: return HIP_R_32I; case CUDA_R_16F: return HIP_R_16F; case CUDA_R_16BF: return HIP_R_16BF; case CUDA_R_32F: return HIP_R_32F; case CUDA_R_64F: return HIP_R_64F; case CUDA_C_32F: return HIP_C_32F; case CUDA_C_64F: return HIP_C_64F; default: throw "Non existent cudaDataType"; } } #endif #if(CUDART_VERSION >= 12000) inline cusparseCsr2CscAlg_t hipCsr2CscAlgToCudaCsr2CscAlg(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG1: return CUSPARSE_CSR2CSC_ALG1; case HIPSPARSE_CSR2CSC_ALG_DEFAULT: return CUSPARSE_CSR2CSC_ALG_DEFAULT; default: throw "Non existant hipsparseCsr2CscAlg_t"; } } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) inline cusparseCsr2CscAlg_t hipCsr2CscAlgToCudaCsr2CscAlg(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG1: return CUSPARSE_CSR2CSC_ALG1; case HIPSPARSE_CSR2CSC_ALG2: return CUSPARSE_CSR2CSC_ALG2; default: throw "Non existant hipsparseCsr2CscAlg_t"; } } #endif /* Generic API */ #if(CUDART_VERSION >= 12000) inline cusparseFormat_t hipFormatToCudaFormat(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_CSR: return CUSPARSE_FORMAT_CSR; case HIPSPARSE_FORMAT_CSC: return CUSPARSE_FORMAT_CSC; case HIPSPARSE_FORMAT_COO: return CUSPARSE_FORMAT_COO; case HIPSPARSE_FORMAT_BLOCKED_ELL: return CUSPARSE_FORMAT_BLOCKED_ELL; default: throw "Non existent hipsparseFormat_t"; } } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) inline cusparseFormat_t hipFormatToCudaFormat(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_CSR: return CUSPARSE_FORMAT_CSR; case HIPSPARSE_FORMAT_CSC: return CUSPARSE_FORMAT_CSC; case HIPSPARSE_FORMAT_COO: return CUSPARSE_FORMAT_COO; case HIPSPARSE_FORMAT_COO_AOS: return CUSPARSE_FORMAT_COO_AOS; case HIPSPARSE_FORMAT_BLOCKED_ELL: return CUSPARSE_FORMAT_BLOCKED_ELL; default: throw "Non existent hipsparseFormat_t"; } } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) inline cusparseFormat_t hipFormatToCudaFormat(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_CSR: return CUSPARSE_FORMAT_CSR; case HIPSPARSE_FORMAT_COO: return CUSPARSE_FORMAT_COO; case HIPSPARSE_FORMAT_COO_AOS: return CUSPARSE_FORMAT_COO_AOS; default: throw "Non existent hipsparseFormat_t"; } } #endif #if(CUDART_VERSION >= 12000) inline hipsparseFormat_t CudaFormatToHIPFormat(cusparseFormat_t format) { switch(format) { case CUSPARSE_FORMAT_CSR: return HIPSPARSE_FORMAT_CSR; case CUSPARSE_FORMAT_CSC: return HIPSPARSE_FORMAT_CSC; case CUSPARSE_FORMAT_COO: return HIPSPARSE_FORMAT_COO; case CUSPARSE_FORMAT_BLOCKED_ELL: return HIPSPARSE_FORMAT_BLOCKED_ELL; default: throw "Non existent cusparseFormat_t"; } } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) inline hipsparseFormat_t CudaFormatToHIPFormat(cusparseFormat_t format) { switch(format) { case CUSPARSE_FORMAT_CSR: return HIPSPARSE_FORMAT_CSR; case CUSPARSE_FORMAT_CSC: return HIPSPARSE_FORMAT_CSC; case CUSPARSE_FORMAT_COO: return HIPSPARSE_FORMAT_COO; case CUSPARSE_FORMAT_COO_AOS: return HIPSPARSE_FORMAT_COO_AOS; case CUSPARSE_FORMAT_BLOCKED_ELL: return HIPSPARSE_FORMAT_BLOCKED_ELL; default: throw "Non existent cusparseFormat_t"; } } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) inline hipsparseFormat_t CudaFormatToHIPFormat(cusparseFormat_t format) { switch(format) { case CUSPARSE_FORMAT_CSR: return HIPSPARSE_FORMAT_CSR; case CUSPARSE_FORMAT_COO: return HIPSPARSE_FORMAT_COO; case CUSPARSE_FORMAT_COO_AOS: return HIPSPARSE_FORMAT_COO_AOS; default: throw "Non existent cusparseFormat_t"; } } #endif #if(CUDART_VERSION >= 11000) inline cusparseOrder_t hipOrderToCudaOrder(hipsparseOrder_t op) { switch(op) { case HIPSPARSE_ORDER_ROW: return CUSPARSE_ORDER_ROW; case HIPSPARSE_ORDER_COL: return CUSPARSE_ORDER_COL; default: throw "Non existent hipsparseOrder_t"; } } inline hipsparseOrder_t CudaOrderToHIPOrder(cusparseOrder_t op) { switch(op) { case CUSPARSE_ORDER_ROW: return HIPSPARSE_ORDER_ROW; case CUSPARSE_ORDER_COL: return HIPSPARSE_ORDER_COL; default: throw "Non existent cusparseOrder_t"; } } #elif(CUDART_VERSION >= 10010) inline cusparseOrder_t hipOrderToCudaOrder(hipsparseOrder_t op) { switch(op) { case HIPSPARSE_ORDER_COL: return CUSPARSE_ORDER_COL; default: throw "Non existent hipsparseOrder_t"; } } inline hipsparseOrder_t CudaOrderToHIPOrder(cusparseOrder_t op) { switch(op) { case CUSPARSE_ORDER_COL: return HIPSPARSE_ORDER_COL; default: throw "Non existent cusparseOrder_t"; } } #endif #if(CUDART_VERSION >= 10010) inline cusparseIndexType_t hipIndexTypeToCudaIndexType(hipsparseIndexType_t type) { switch(type) { case HIPSPARSE_INDEX_16U: return CUSPARSE_INDEX_16U; case HIPSPARSE_INDEX_32I: return CUSPARSE_INDEX_32I; case HIPSPARSE_INDEX_64I: return CUSPARSE_INDEX_64I; default: throw "Non existant hipsparseIndexType_t"; } } inline hipsparseIndexType_t CudaIndexTypeToHIPIndexType(cusparseIndexType_t type) { switch(type) { case CUSPARSE_INDEX_16U: return HIPSPARSE_INDEX_16U; case CUSPARSE_INDEX_32I: return HIPSPARSE_INDEX_32I; case CUSPARSE_INDEX_64I: return HIPSPARSE_INDEX_64I; default: throw "Non existant cusparseIndexType_t"; } } #endif #if(CUDART_VERSION >= 12000) inline cusparseSpMVAlg_t hipSpMVAlgToCudaSpMVAlg(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return CUSPARSE_SPMV_ALG_DEFAULT; case HIPSPARSE_SPMV_COO_ALG1: return CUSPARSE_SPMV_COO_ALG1; case HIPSPARSE_SPMV_COO_ALG2: return CUSPARSE_SPMV_COO_ALG2; case HIPSPARSE_SPMV_CSR_ALG1: return CUSPARSE_SPMV_CSR_ALG1; case HIPSPARSE_SPMV_CSR_ALG2: return CUSPARSE_SPMV_CSR_ALG2; default: throw "Non existant hipsparseSpMVAlg_t"; } } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) inline cusparseSpMVAlg_t hipSpMVAlgToCudaSpMVAlg(hipsparseSpMVAlg_t alg) { switch(alg) { // case HIPSPARSE_MV_ALG_DEFAULT: case HIPSPARSE_SPMV_ALG_DEFAULT: return CUSPARSE_SPMV_ALG_DEFAULT; // case HIPSPARSE_COOMV_ALG: case HIPSPARSE_SPMV_COO_ALG1: return CUSPARSE_SPMV_COO_ALG1; case HIPSPARSE_SPMV_COO_ALG2: return CUSPARSE_SPMV_COO_ALG2; // case HIPSPARSE_CSRMV_ALG1: case HIPSPARSE_SPMV_CSR_ALG1: return CUSPARSE_SPMV_CSR_ALG1; // case HIPSPARSE_CSRMV_ALG2: case HIPSPARSE_SPMV_CSR_ALG2: return CUSPARSE_SPMV_CSR_ALG2; default: throw "Non existant hipsparseSpMVAlg_t"; } } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) inline cusparseSpMVAlg_t hipSpMVAlgToCudaSpMVAlg(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_MV_ALG_DEFAULT: return CUSPARSE_MV_ALG_DEFAULT; case HIPSPARSE_COOMV_ALG: return CUSPARSE_COOMV_ALG; case HIPSPARSE_CSRMV_ALG1: return CUSPARSE_CSRMV_ALG1; case HIPSPARSE_CSRMV_ALG2: return CUSPARSE_CSRMV_ALG2; default: throw "Non existant hipsparseSpMVAlg_t"; } } #endif #if(CUDART_VERSION >= 12000) inline cusparseSpMMAlg_t hipSpMMAlgToCudaSpMMAlg(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return CUSPARSE_SPMM_ALG_DEFAULT; case HIPSPARSE_SPMM_COO_ALG1: return CUSPARSE_SPMM_COO_ALG1; case HIPSPARSE_SPMM_COO_ALG2: return CUSPARSE_SPMM_COO_ALG2; case HIPSPARSE_SPMM_COO_ALG3: return CUSPARSE_SPMM_COO_ALG3; case HIPSPARSE_SPMM_COO_ALG4: return CUSPARSE_SPMM_COO_ALG4; case HIPSPARSE_SPMM_CSR_ALG1: return CUSPARSE_SPMM_CSR_ALG1; case HIPSPARSE_SPMM_CSR_ALG2: return CUSPARSE_SPMM_CSR_ALG2; case HIPSPARSE_SPMM_CSR_ALG3: return CUSPARSE_SPMM_CSR_ALG3; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return CUSPARSE_SPMM_BLOCKED_ELL_ALG1; default: throw "Non existant hipsparseSpMMAlg_t"; } } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) inline cusparseSpMMAlg_t hipSpMMAlgToCudaSpMMAlg(hipsparseSpMMAlg_t alg) { switch(alg) { // case HIPSPARSE_MM_ALG_DEFAULT: case HIPSPARSE_SPMM_ALG_DEFAULT: return CUSPARSE_SPMM_ALG_DEFAULT; // case HIPSPARSE_COOMM_ALG1: case HIPSPARSE_SPMM_COO_ALG1: return CUSPARSE_SPMM_COO_ALG1; // case HIPSPARSE_COOMM_ALG2: case HIPSPARSE_SPMM_COO_ALG2: return CUSPARSE_SPMM_COO_ALG2; // case HIPSPARSE_COOMM_ALG3: case HIPSPARSE_SPMM_COO_ALG3: return CUSPARSE_SPMM_COO_ALG3; case HIPSPARSE_SPMM_COO_ALG4: return CUSPARSE_SPMM_COO_ALG4; // case HIPSPARSE_CSRMM_ALG1: case HIPSPARSE_SPMM_CSR_ALG1: return CUSPARSE_SPMM_CSR_ALG1; case HIPSPARSE_SPMM_CSR_ALG2: return CUSPARSE_SPMM_CSR_ALG2; case HIPSPARSE_SPMM_CSR_ALG3: return CUSPARSE_SPMM_CSR_ALG3; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return CUSPARSE_SPMM_BLOCKED_ELL_ALG1; default: throw "Non existant hipsparseSpMMAlg_t"; } } #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) inline cusparseSpMMAlg_t hipSpMMAlgToCudaSpMMAlg(hipsparseSpMMAlg_t alg) { switch(alg) { // case HIPSPARSE_MM_ALG_DEFAULT: case HIPSPARSE_SPMM_ALG_DEFAULT: return CUSPARSE_SPMM_ALG_DEFAULT; // case HIPSPARSE_COOMM_ALG1: case HIPSPARSE_SPMM_COO_ALG1: return CUSPARSE_SPMM_COO_ALG1; // case HIPSPARSE_COOMM_ALG2: case HIPSPARSE_SPMM_COO_ALG2: return CUSPARSE_SPMM_COO_ALG2; // case HIPSPARSE_COOMM_ALG3: case HIPSPARSE_SPMM_COO_ALG3: return CUSPARSE_SPMM_COO_ALG3; case HIPSPARSE_SPMM_COO_ALG4: return CUSPARSE_SPMM_COO_ALG4; // case HIPSPARSE_CSRMM_ALG1: case HIPSPARSE_SPMM_CSR_ALG1: return CUSPARSE_SPMM_CSR_ALG1; case HIPSPARSE_SPMM_CSR_ALG2: return CUSPARSE_SPMM_CSR_ALG2; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return CUSPARSE_SPMM_BLOCKED_ELL_ALG1; default: throw "Non existant hipsparseSpMMAlg_t"; } } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) inline cusparseSpMMAlg_t hipSpMMAlgToCudaSpMMAlg(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_MM_ALG_DEFAULT: return CUSPARSE_MM_ALG_DEFAULT; case HIPSPARSE_COOMM_ALG1: return CUSPARSE_COOMM_ALG1; case HIPSPARSE_COOMM_ALG2: return CUSPARSE_COOMM_ALG2; case HIPSPARSE_COOMM_ALG3: return CUSPARSE_COOMM_ALG3; case HIPSPARSE_CSRMM_ALG1: return CUSPARSE_CSRMM_ALG1; default: throw "Non existant hipsparseSpMMAlg_t"; } } #endif #if(CUDART_VERSION >= 12000) inline cusparseSpGEMMAlg_t hipSpGEMMAlgToCudaSpGEMMAlg(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return CUSPARSE_SPGEMM_DEFAULT; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return CUSPARSE_SPGEMM_CSR_ALG_NONDETERMINITIC; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return CUSPARSE_SPGEMM_CSR_ALG_DETERMINITIC; case HIPSPARSE_SPGEMM_ALG1: return CUSPARSE_SPGEMM_ALG1; case HIPSPARSE_SPGEMM_ALG2: return CUSPARSE_SPGEMM_ALG2; case HIPSPARSE_SPGEMM_ALG3: return CUSPARSE_SPGEMM_ALG3; default: throw "Non existant cusparseSpGEMMAlg_t"; } } #elif(CUDART_VERSION >= 11031) inline cusparseSpGEMMAlg_t hipSpGEMMAlgToCudaSpGEMMAlg(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return CUSPARSE_SPGEMM_DEFAULT; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return CUSPARSE_SPGEMM_CSR_ALG_NONDETERMINITIC; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return CUSPARSE_SPGEMM_CSR_ALG_DETERMINITIC; default: throw "Non existant cusparseSpGEMMAlg_t"; } } #elif(CUDART_VERSION >= 11000) inline cusparseSpGEMMAlg_t hipSpGEMMAlgToCudaSpGEMMAlg(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return CUSPARSE_SPGEMM_DEFAULT; default: throw "Non existant cusparseSpGEMMAlg_t"; } } #endif #if(CUDART_VERSION >= 11020) inline cusparseSparseToDenseAlg_t hipSpToDnAlgToCudaSpToDnAlg(hipsparseSparseToDenseAlg_t alg) { switch(alg) { case HIPSPARSE_SPARSETODENSE_ALG_DEFAULT: return CUSPARSE_SPARSETODENSE_ALG_DEFAULT; default: throw "Non existent hipsparseSparseToDenseAlg_t"; } } inline hipsparseSparseToDenseAlg_t CudaSpToDnAlgToHipSpToDnAlg(cusparseSparseToDenseAlg_t alg) { switch(alg) { case CUSPARSE_SPARSETODENSE_ALG_DEFAULT: return HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; default: throw "Non existent cusparseSparseToDenseAlg_t"; } } #endif #if(CUDART_VERSION >= 11020) inline cusparseDenseToSparseAlg_t hipDnToSpAlgToCudaDnToSpAlg(hipsparseDenseToSparseAlg_t alg) { switch(alg) { case HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT: return CUSPARSE_DENSETOSPARSE_ALG_DEFAULT; default: throw "Non existent hipsparseDenseToSparseAlg_t"; } } inline hipsparseDenseToSparseAlg_t CudaDnToSpAlgToHipDnToSpAlg(cusparseDenseToSparseAlg_t alg) { switch(alg) { case CUSPARSE_DENSETOSPARSE_ALG_DEFAULT: return HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; default: throw "Non existent cusparseDenseToSparseAlg_t"; } } #endif #if(CUDART_VERSION >= 11022) inline cusparseSDDMMAlg_t hipSDDMMAlgToCudaSDDMMAlg(hipsparseSDDMMAlg_t alg) { switch(alg) { case HIPSPARSE_SDDMM_ALG_DEFAULT: return CUSPARSE_SDDMM_ALG_DEFAULT; default: throw "Non existant cusparseSDDMMAlg_t"; } } #endif #if(CUDART_VERSION >= 11030) inline cusparseSpSVAlg_t hipSpSVAlgToCudaSpSVAlg(hipsparseSpSVAlg_t alg) { switch(alg) { case HIPSPARSE_SPSV_ALG_DEFAULT: return CUSPARSE_SPSV_ALG_DEFAULT; default: throw "Non existant cusparseSpSVAlg_t"; } } #endif #if(CUDART_VERSION >= 11031) inline cusparseSpSMAlg_t hipSpSMAlgToCudaSpSMAlg(hipsparseSpSMAlg_t alg) { switch(alg) { case HIPSPARSE_SPSM_ALG_DEFAULT: return CUSPARSE_SPSM_ALG_DEFAULT; default: throw "Non existant cusparseSpSMAlg_t"; } } #endif } ./rmake.py0000664000175100017510000002260015176134511012560 0ustar jenkinsjenkins#!/usr/bin/python3 """Copyright (C) 2021-2023 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Manage build and installation""" import re import sys import os import platform import subprocess import argparse import pathlib from fnmatch import fnmatchcase args = {} param = {} OS_info = {} def parse_args(): """Parse command-line arguments""" parser = argparse.ArgumentParser(description="""Checks build arguments""") # common parser.add_argument('-g', '--debug', required=False, default = False, action='store_true', help='Generate Debug build (optional, default: False)') parser.add_argument( '--build_dir', type=str, required=False, default = "build", help='Build directory path (optional, default: build)') parser.add_argument( '--skip_ld_conf_entry', required=False, default = False) parser.add_argument( '--static', required=False, default = False, dest='static_lib', action='store_true', help='Generate static library build (optional, default: False)') parser.add_argument('-c', '--clients', required=False, default = False, dest='build_clients', action='store_true', help='Generate all client builds (optional, default: False)') parser.add_argument('-i', '--install', required=False, default = False, dest='install', action='store_true', help='Install after build (optional, default: False)') parser.add_argument( '--cmake-darg', required=False, dest='cmake_dargs', action='append', default=[], help='List of additional cmake defines for builds (optional, e.g. CMAKE)') parser.add_argument('-v', '--verbose', required=False, default = False, action='store_true', help='Verbose build (optional, default: False)') # hipsparse parser.add_argument( '--rocm_dev', type=str, required=False, default = "", help='Set specific rocm-dev version') parser.add_argument( '--cpu_ref_lib', type=str, required=False, default = "blis", help='Specify library to use for CPU reference code in testing (blis or lapack)') parser.add_argument( '--clients-only', dest='clients_only', required=False, default = False, action='store_true', help='Build only clients with a pre-built library') # rocsparse parser.add_argument('-b', '--rocsparse', dest='rocsparse_version', type=str, required=False, default="", help='Set a specific rocSPARSE vesrion (optional)') parser.add_argument('--rocsparse-path', dest='rocsparse_path', type=str, required=False, default=None, help='Set specific path to custom build rocSPARSE (optional)') return parser.parse_args() def os_detect(): global OS_info if os.name == "nt": OS_info["ID"] = platform.system() else: inf_file = "/etc/os-release" if os.path.exists(inf_file): with open(inf_file) as f: for line in f: if "=" in line: k,v = line.strip().split("=") OS_info[k] = v.replace('"','') OS_info["NUM_PROC"] = os.cpu_count() print(OS_info) def create_dir(dir_path): full_path = "" if os.path.isabs(dir_path): full_path = dir_path else: full_path = os.path.join( os.getcwd(), dir_path ) pathlib.Path(full_path).mkdir(parents=True, exist_ok=True) return def delete_dir(dir_path) : if (not os.path.exists(dir_path)): return if os.name == "nt": run_cmd( "RMDIR" , f"/S /Q {dir_path}") else: run_cmd( "rm" , f"-rf {dir_path}") def cmake_path(os_path): if os.name == "nt": return os_path.replace("\\", "/") else: return os_path def config_cmd(): global args global OS_info cwd_path = os.getcwd() cmake_executable = "cmake" cmake_options = [] src_path = cmake_path(cwd_path) cmake_platform_opts = [] if os.name == "nt": generator = f"-G Ninja" cmake_options.append( generator ) # CMAKE_PREFIX_PATH set to rocm_path and HIP_PATH set BY SDK Installer raw_rocm_path = cmake_path(os.getenv('HIP_PATH', "C:/hip")) rocm_path = f'"{raw_rocm_path}"' # guard against spaces in path #set CPACK_PACKAGING_INSTALL_PREFIX= defined as blank as it is appended to end of path for archive creation cmake_platform_opts.append( f"-DCPACK_PACKAGING_INSTALL_PREFIX={rocm_path}" ) toolchain = os.path.join( src_path, "toolchain-windows.cmake" ) else: rocm_path = os.getenv( 'ROCM_PATH', "/opt/rocm") cmake_platform_opts.append( f"-DROCM_DIR:PATH={rocm_path} -DCPACK_PACKAGING_INSTALL_PREFIX={rocm_path}" ) cmake_platform_opts.append( f"-DCMAKE_INSTALL_PREFIX=\"hipsparse-install\"" ) toolchain = "toolchain-linux.cmake" print( f"Build source path: {src_path}") tools = f"-DCMAKE_TOOLCHAIN_FILE={toolchain}" cmake_options.append( tools ) cmake_options.extend( cmake_platform_opts ) cmake_base_options = f"-DROCM_PATH={rocm_path} -DCMAKE_PREFIX_PATH:PATH={rocm_path}" cmake_options.append( cmake_base_options ) # packaging options cmake_pack_options = f"-DCPACK_SET_DESTDIR=OFF" cmake_options.append( cmake_pack_options ) if os.getenv('CMAKE_CXX_COMPILER_LAUNCHER'): cmake_options.append( f"-DCMAKE_CXX_COMPILER_LAUNCHER={os.getenv('CMAKE_CXX_COMPILER_LAUNCHER')}" ) cmake_options.append("-DBUILD_TESTING=OFF") print( cmake_options ) # build type cmake_config = "" build_dir = os.path.abspath(args.build_dir) if not args.debug: build_path = os.path.join(build_dir, "release") cmake_config="Release" else: build_path = os.path.join(build_dir, "debug") cmake_config="Debug" cmake_options.append( f"-DCMAKE_BUILD_TYPE={cmake_config}" ) # clean delete_dir( build_path ) create_dir( os.path.join(build_path, "clients") ) os.chdir( build_path ) if args.static_lib: cmake_options.append( f"-DBUILD_SHARED_LIBS=OFF" ) if args.skip_ld_conf_entry: cmake_options.append( f"-DROCM_DISABLE_LDCONFIG=ON" ) if args.build_clients: cmake_build_dir = cmake_path(build_dir) cmake_options.append( f"-DBUILD_CLIENTS_TESTS=ON -DBUILD_CLIENTS_BENCHMARKS=ON -DBUILD_CLIENTS_SAMPLES=ON -DBUILD_DIR={cmake_build_dir} " ) if args.rocsparse_path is not None: # "Custom" rocsparse raw_rocsparse_path = cmake_path(args.rocsparse_path) rocsparse_path_cmake = f'"{raw_rocsparse_path}"' cmake_options.append( f"-DCUSTOM_ROCSPARSE={rocsparse_path_cmake}") else: args.rocsparse_path = "C:/hipSDK" raw_rocsparse_path = cmake_path(args.rocsparse_path) rocsparse_path_cmake = f'"{raw_rocsparse_path}"' cmake_options.append( f"-DROCSPARSE_PATH={args.rocsparse_path}") if args.clients_only: cmake_options.append( f"-DBUILD_CLIENTS_ONLY=ON -DBUILD_CLIENTS_SAMPLES=ON -DBUILD_CLIENTS_TESTS=ON -DBUILD_CLIENTS_BENCHMARKS=ON" ) if args.cmake_dargs: for i in args.cmake_dargs: cmake_options.append( f"-D{i}" ) cmake_options.append( f"{src_path}") cmd_opts = " ".join(cmake_options) return cmake_executable, cmd_opts def make_cmd(): global args global OS_info make_options = [] nproc = OS_info["NUM_PROC"] if os.name == "nt": make_executable = f"cmake.exe --build . " # ninja if args.verbose: make_options.append( "--verbose" ) make_options.append( "--target all" ) if args.install: make_options.append( "--target package --target install" ) else: make_executable = f"make -j{nproc}" if args.verbose: make_options.append( "VERBOSE=1" ) if True: # args.install: make_options.append( "install" ) cmd_opts = " ".join(make_options) return make_executable, cmd_opts def run_cmd(exe, opts): program = f"{exe} {opts}" print(program) proc = subprocess.run(program, check=True, stderr=subprocess.STDOUT, shell=True) return proc.returncode def main(): global args os_detect() args = parse_args() # configure exe, opts = config_cmd() run_cmd(exe, opts) # make exe, opts = make_cmd() run_cmd(exe, opts) if __name__ == '__main__': main() ./cmake/0000775000175100017510000000000015176134511012167 5ustar jenkinsjenkins./cmake/hipsparse_clientmatrices.cmake0000664000175100017510000001345615176134511020266 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## find_program(HIPSPARSE_MTX2CSR hipsparse_mtx2csr PATHS /opt/rocm/bin ${ROCM_PATH}/bin) set(TEST_MATRICES SNAP/amazon0312 Muite/Chebyshev4 FEMLAB/sme3Dc Williams/webbase-1M Bova/rma10 JGD_BIBD/bibd_22_8 Williams/mac_econ_fwd500 Williams/mc2depi Hamm/scircuit Sandia/ASIC_320k GHS_psdef/bmwcra_1 HB/nos1 HB/nos2 HB/nos3 HB/nos4 HB/nos5 HB/nos6 HB/nos7 DNVS/shipsec1 ) set(TEST_MD5HASH f567e5f5029d052e3004bc69bb3f13f5 e39879103dafab21f4cf942e0fe42a85 a95eee14d980a9cfbbaf5df4a3c64713 2d4c239daad6f12d66a1e6a2af44cbdb a899a0c48b9a58d081c52ffd88a84955 455d5b699ea10232bbab5bc002219ae6 f1b0e56fbb75d1d6862874e3d7d33060 8c8633eada6455c1784269b213c85ea6 3e62f7ea83914f7e20019aefb2a5176f fcfaf8a25c8f49b8d29f138f3c65c08f 8a3cf5448a4fe73dcbdb5a16b326715f b203f7605cb1f20f83280061068f7ec7 b0f812ffcc9469f0bf9be701205522c4 f185514062a0eeabe86d2909275fe1dc 04b781415202db404733ca0c159acbef c98e35f1cfd1ee8177f37bdae155a6e7 c39375226aa5c495293003a5f637598f 9a6481268847e6cf0d70671f2ff1ddcd 73372e7d6a0848f8b19d64a924fab73e ) if(NOT CMAKE_MATRICES_DIR) set(CMAKE_MATRICES_DIR "./") message(WARNING "Unspecified CMAKE_MATRICES_DIR, the default value of CMAKE_MATRICES_DIR is set to './'") endif() # convert relative path to absolute get_filename_component(PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") get_filename_component(CMAKE_MATRICES_DIR "${CMAKE_MATRICES_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}) list(LENGTH TEST_MATRICES len) math(EXPR len1 "${len} - 1") foreach(i RANGE 0 ${len1}) list(GET TEST_MATRICES ${i} m) list(GET TEST_MD5HASH ${i} md5) string(REPLACE "/" ";" sep_m ${m}) list(GET sep_m 0 dir) list(GET sep_m 1 mat) # Download test matrices if not already downloaded if(NOT EXISTS "${CMAKE_MATRICES_DIR}/${mat}.bin") if(NOT HIPSPARSE_MTX_DIR) # First try user specified mirror, if available if(DEFINED ENV{HIPSPARSE_TEST_MIRROR} AND NOT $ENV{HIPSPARSE_TEST_MIRROR} STREQUAL "") message("-- Downloading and extracting test matrix ${m}.tar.gz from user specified test mirror: $ENV{HIPSPARSE_TEST_MIRROR}") file(DOWNLOAD $ENV{HIPSPARSE_TEST_MIRROR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "-- Timeout has been reached, specified test mirror is not reachable: ${msg}") endif() else() message("-- Downloading and extracting test matrix ${m}.tar.gz") file(DOWNLOAD https://sparse.tamu.edu/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message("-- Timeout has been reached, trying mirror ...") # Try again using ufl links file(DOWNLOAD https://www.cise.ufl.edu/research/sparse/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "${msg}") endif() endif() endif() # Check MD5 hash before continuing file(MD5 ${CMAKE_MATRICES_DIR}/${mat}.tar.gz hash) # Compare hash if(NOT hash STREQUAL md5) message(FATAL_ERROR "${mat}.tar.gz is corrupted") endif() execute_process(COMMAND tar xf ${mat}.tar.gz RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "uncompressing failed, aborting.") endif() file(RENAME ${CMAKE_MATRICES_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) else() file(RENAME ${HIPSPARSE_MTX_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() execute_process(COMMAND ${HIPSPARSE_MTX2CSR} ${mat}.mtx ${mat}.bin RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "${HIPSPARSE_MTX2CSR} failed, aborting.") else() message(STATUS "${mat} success.") endif() # TODO: add 'COMMAND_ERROR_IS_FATAL ANY' once cmake supported version is 3.19 file(REMOVE_RECURSE ${CMAKE_MATRICES_DIR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat} ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() endforeach() ./cmake/get-cli-arguments.cmake0000664000175100017510000000200015176134511016510 0ustar jenkinsjenkins# Attempt (best effort) to return a list of user specified parameters cmake was invoked with # NOTE: Even if the user specifies CMAKE_INSTALL_PREFIX on the command line, the parameter is # not returned because it does not have the matching helpstring function( append_cmake_cli_arguments initial_cli_args return_cli_args ) # Retrieves the contents of CMakeCache.txt get_cmake_property( cmake_properties CACHE_VARIABLES ) foreach( property ${cmake_properties} ) get_property(help_string CACHE ${property} PROPERTY HELPSTRING ) # Properties specified on the command line have boilerplate text if( help_string MATCHES "variable specified on the command line" ) # message( STATUS "property: ${property}") # message( STATUS "value: ${${property}}") list( APPEND cli_args "-D${property}=${${property}}") endif( ) endforeach( ) # message( STATUS "get_command_line_arguments: ${cli_args}") set( ${return_cli_args} ${${initial_cli_args}} ${cli_args} PARENT_SCOPE ) endfunction( ) ./cmake/ClientMatrices.cmake0000664000175100017510000001425715176134511016110 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2018-2023 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## set(TEST_MATRICES SNAP/amazon0312 Muite/Chebyshev4 FEMLAB/sme3Dc Williams/webbase-1M Bova/rma10 JGD_BIBD/bibd_22_8 Williams/mac_econ_fwd500 Williams/mc2depi Hamm/scircuit Sandia/ASIC_320k GHS_psdef/bmwcra_1 HB/nos1 HB/nos2 HB/nos3 HB/nos4 HB/nos5 HB/nos6 HB/nos7 DNVS/shipsec1 ) set(TEST_MD5HASH f567e5f5029d052e3004bc69bb3f13f5 e39879103dafab21f4cf942e0fe42a85 a95eee14d980a9cfbbaf5df4a3c64713 2d4c239daad6f12d66a1e6a2af44cbdb a899a0c48b9a58d081c52ffd88a84955 455d5b699ea10232bbab5bc002219ae6 f1b0e56fbb75d1d6862874e3d7d33060 8c8633eada6455c1784269b213c85ea6 3e62f7ea83914f7e20019aefb2a5176f fcfaf8a25c8f49b8d29f138f3c65c08f 8a3cf5448a4fe73dcbdb5a16b326715f b203f7605cb1f20f83280061068f7ec7 b0f812ffcc9469f0bf9be701205522c4 f185514062a0eeabe86d2909275fe1dc 04b781415202db404733ca0c159acbef c98e35f1cfd1ee8177f37bdae155a6e7 c39375226aa5c495293003a5f637598f 9a6481268847e6cf0d70671f2ff1ddcd 73372e7d6a0848f8b19d64a924fab73e ) if(NOT CMAKE_MATRICES_DIR) message(FATAL_ERROR "Unspecified CMAKE_MATRICES_DIR") endif() if(NOT CONVERT_SOURCE) set(CONVERT_SOURCE ${CMAKE_SOURCE_DIR}/deps/convert.cpp) endif() # convert relative path to absolute get_filename_component(PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") get_filename_component(CMAKE_MATRICES_DIR "${CMAKE_MATRICES_DIR}" ABSOLUTE BASE_DIR "${CMAKE_SOURCE_DIR}") file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}) if(BUILD_ADDRESS_SANITIZER) execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -fsanitize=address -shared-libasan -o ${PROJECT_BINARY_DIR}/mtx2csr.exe RESULT_VARIABLE STATUS) else() execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -O3 -o ${PROJECT_BINARY_DIR}/mtx2csr.exe RESULT_VARIABLE STATUS) endif() if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "mtx2csr.exe failed to build, aborting.") endif() list(LENGTH TEST_MATRICES len) math(EXPR len1 "${len} - 1") foreach(i RANGE 0 ${len1}) list(GET TEST_MATRICES ${i} m) list(GET TEST_MD5HASH ${i} md5) string(REPLACE "/" ";" sep_m ${m}) list(GET sep_m 0 dir) list(GET sep_m 1 mat) # Download test matrices if not already downloaded if(NOT EXISTS "${CMAKE_MATRICES_DIR}/${mat}.bin") if(NOT HIPSPARSE_MTX_DIR) # First try user specified mirror, if available if(DEFINED ENV{HIPSPARSE_TEST_MIRROR} AND NOT $ENV{HIPSPARSE_TEST_MIRROR} STREQUAL "") message("-- Downloading and extracting test matrix ${m}.tar.gz from user specified test mirror: $ENV{HIPSPARSE_TEST_MIRROR}") file(DOWNLOAD $ENV{HIPSPARSE_TEST_MIRROR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "-- Timeout has been reached, specified test mirror is not reachable: ${msg}") endif() else() message("-- Downloading and extracting test matrix ${m}.tar.gz") file(DOWNLOAD https://sparse.tamu.edu/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message("-- Timeout has been reached, trying mirror ...") # Try again using ufl links file(DOWNLOAD https://www.cise.ufl.edu/research/sparse/MM/${m}.tar.gz ${CMAKE_MATRICES_DIR}/${mat}.tar.gz INACTIVITY_TIMEOUT 3 STATUS DL) list(GET DL 0 stat) list(GET DL 1 msg) if(NOT stat EQUAL 0) message(FATAL_ERROR "${msg}") endif() endif() endif() # Check MD5 hash before continuing file(MD5 ${CMAKE_MATRICES_DIR}/${mat}.tar.gz hash) # Compare hash if(NOT hash STREQUAL md5) message(FATAL_ERROR "${mat}.tar.gz is corrupted") endif() execute_process(COMMAND tar xf ${mat}.tar.gz RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "uncompressing failed, aborting.") endif() file(RENAME ${CMAKE_MATRICES_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) else() file(RENAME ${HIPSPARSE_MTX_DIR}/${mat}/${mat}.mtx ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() execute_process(COMMAND ${PROJECT_BINARY_DIR}/mtx2csr.exe ${mat}.mtx ${mat}.bin RESULT_VARIABLE STATUS WORKING_DIRECTORY ${CMAKE_MATRICES_DIR}) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "mtx2csr.exe failed, aborting.") else() message(STATUS "${mat} success.") endif() # TODO: add 'COMMAND_ERROR_IS_FATAL ANY' once cmake supported version is 3.19 file(REMOVE_RECURSE ${CMAKE_MATRICES_DIR}/${mat}.tar.gz ${CMAKE_MATRICES_DIR}/${mat} ${CMAKE_MATRICES_DIR}/${mat}.mtx) endif() endforeach() ./cmake/Dependencies.cmake0000664000175100017510000000645015176134511015564 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Dependencies include(FetchContent) if( NOT DEFINED ENV{HIP_PATH}) if(WIN32) set( HIP_PATH "C:/hip" ) else () set( HIP_PATH "/opt/rocm" ) endif() else( ) file(TO_CMAKE_PATH "$ENV{HIP_PATH}" HIP_PATH) endif( ) # Either rocSPARSE or cuSPARSE is required if(NOT USE_CUDA) if(WIN32) find_package(hip REQUIRED CONFIG PATHS ${HIP_PATH} ${ROCM_PATH}) if( CUSTOM_ROCSPARSE ) set ( ENV{rocsparse_DIR} ${CUSTOM_ROCSPARSE}) find_package( rocsparse REQUIRED CONFIG NO_CMAKE_PATH ) else() find_package( rocsparse 4.0.1 REQUIRED CONFIG PATHS ${ROCSPARSE_PATH} ) endif() else() find_package(hip REQUIRED CONFIG PATHS ${HIP_PATH} ${ROCM_PATH} /opt/rocm) find_package( rocsparse 4.0.1 REQUIRED CONFIG PATHS /opt/rocm /opt/rocm/rocsparse /usr/local/rocsparse ) endif() else() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${HIP_PATH}/cmake") find_package(HIP MODULE REQUIRED) list( APPEND HIP_INCLUDE_DIRS "${HIP_ROOT_DIR}/include" ) find_package(CUDA REQUIRED) endif() # ROCm cmake package find_package(ROCmCMakeBuildTools 0.11.0 QUIET CONFIG PATHS ${CMAKE_PREFIX_PATH}) if(NOT ROCmCMakeBuildTools_FOUND) find_package(ROCM 0.7.3 QUIET CONFIG PATHS ${CMAKE_PREFIX_PATH}) # deprecated fallback if(NOT ROCM_FOUND) message(STATUS "ROCmCMakeBuildTools not found. Fetching...") set(PROJECT_EXTERN_DIR ${CMAKE_CURRENT_BINARY_DIR}/extern) set(rocm_cmake_tag "rocm-6.4.0" CACHE STRING "rocm-cmake tag to download") FetchContent_Declare( rocm-cmake GIT_REPOSITORY https://github.com/ROCm/rocm-cmake.git GIT_TAG ${rocm_cmake_tag} SOURCE_SUBDIR "DISABLE ADDING TO BUILD" ) FetchContent_MakeAvailable(rocm-cmake) find_package(ROCmCMakeBuildTools CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${rocm-cmake_SOURCE_DIR}") endif() endif() include(ROCMSetupVersion) include(ROCMCreatePackage) include(ROCMInstallTargets) include(ROCMPackageConfigHelpers) include(ROCMInstallSymlinks) include(ROCMClients) include(ROCMHeaderWrapper) ./cmake/Verbose.cmake0000664000175100017510000000625215176134511014603 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2018 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## message(STATUS "hipsparse_VERSION : ${hipsparse_VERSION}") message(STATUS "\t==>CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}") message(STATUS "\t==>BUILD_SHARED_LIBS : ${BUILD_SHARED_LIBS}") message(STATUS "\t==>CMAKE_INSTALL_PREFIX link : ${CMAKE_INSTALL_PREFIX}") message(STATUS "\t==>CMAKE_MODULE_PATH link : ${CMAKE_MODULE_PATH}") message(STATUS "\t==>CMAKE_PREFIX_PATH link : ${CMAKE_PREFIX_PATH}") message(STATUS "==============") message(STATUS "\t==>CMAKE_SYSTEM_NAME : ${CMAKE_SYSTEM_NAME}") message(STATUS "\t>>=HIP_ROOT_DIR : ${HIP_ROOT_DIR}") message(STATUS "\t==>CMAKE_CXX_COMPILER : ${CMAKE_CXX_FLAGS}") message(STATUS "\t==>CMAKE_CXX_COMPILER_VERSION : ${CMAKE_CXX_COMPILER_VERSION}") message(STATUS "\t==>CMAKE_CXX_COMPILER debug : ${CMAKE_CXX_FLAGS_DEBUG}") message(STATUS "\t==>CMAKE_CXX_COMPILER release : ${CMAKE_CXX_FLAGS_RELEASE}") message(STATUS "\t==>CMAKE_CXX_COMPILER relwithdebinfo : ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") message(STATUS "\t==>CMAKE_EXE_LINKER_FLAGS : ${CMAKE_EXE_LINKER_FLAGS}") message(STATUS "\t==>CMAKE_EXE_LINKER_FLAGS_RELEASE : ${CMAKE_EXE_LINKER_FLAGS_RELEASE}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS : ${CMAKE_SHARED_LINKER_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS_RELEASE : ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") message(STATUS "==============" ) message(STATUS "\t==>CMAKE_SHARED_LIBRARY_C_FLAGS : ${CMAKE_SHARED_LIBRARY_C_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LIBRARY_CXX_FLAGS : ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS : ${CMAKE_SHARED_LINKER_FLAGS}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS_DEBUG : ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") message(STATUS "\t==>CMAKE_SHARED_LINKER_FLAGS_RELEASE : ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") ./toolchain-windows.cmake0000664000175100017510000000363215176134511015565 0ustar jenkinsjenkins if (DEFINED ENV{HIP_PATH}) file(TO_CMAKE_PATH "$ENV{HIP_PATH}" HIP_DIR) set(rocm_bin "${HIP_DIR}/bin") elseif (DEFINED ENV{HIP_DIR}) file(TO_CMAKE_PATH "$ENV{HIP_DIR}" HIP_DIR) set(rocm_bin "${HIP_DIR}/bin") else() set(HIP_DIR "C:/hip") set(rocm_bin "C:/hip/bin") endif() set(CMAKE_CXX_COMPILER "${rocm_bin}/clang++.exe") set(CMAKE_C_COMPILER "${rocm_bin}/clang.exe") set(python "python") # working #set(CMAKE_Fortran_COMPILER "C:/Strawberry/c/bin/gfortran.exe") #set(CMAKE_Fortran_PREPROCESS_SOURCE " -E -cpp -o ") # TODO remove, just to speed up slow cmake #set(CMAKE_C_COMPILER_WORKS 1) #set(CMAKE_CXX_COMPILER_WORKS 1) #set(CMAKE_Fortran_COMPILER_WORKS 1) # our usage flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWIN32 -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING") # flags for clang direct use # -Wno-ignored-attributes to avoid warning: __declspec attribute 'dllexport' is not supported [-Wignored-attributes] which is used by msvc compiler #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14-fms-extensions -fms-compatibility -Wno-ignored-attributes") # # -I${HIP_PATH}/include -I${HIP_PATH}/include/hip add -x hip ?? set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__HIP_PLATFORM_HCC__ -D__HIP_ROCclr__ -DHIP_CLANG_HCC_COMPAT_MODE=1") find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") # CMake 3.9+ endif() if (DEFINED ENV{VCPKG_PATH}) file(TO_CMAKE_PATH "$ENV{VCPKG_PATH}" VCPKG_PATH) else() set(VCPKG_PATH "C:/github/vcpkg") endif() include("${VCPKG_PATH}/scripts/buildsystems/vcpkg.cmake") set(CMAKE_STATIC_LIBRARY_SUFFIX ".a") set(CMAKE_STATIC_LIBRARY_PREFIX "static_") set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll") set(CMAKE_SHARED_LIBRARY_PREFIX "") ./clients/0000775000175100017510000000000015176134511012550 5ustar jenkinsjenkins./clients/common/0000775000175100017510000000000015176134511014040 5ustar jenkinsjenkins./clients/common/arg_check.cpp0000664000175100017510000001276215176134305016463 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "arg_check.hpp" #include #include #include #ifdef GOOGLE_TEST #include #endif #define PRINT_IF_HIP_ERROR(INPUT_STATUS_FOR_CHECK) \ { \ hipError_t TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ if(TMP_STATUS_FOR_CHECK != hipSuccess) \ { \ fprintf(stderr, \ "hip error code: %d at %s:%d\n", \ TMP_STATUS_FOR_CHECK, \ __FILE__, \ __LINE__); \ } \ } void verify_hipsparse_status(hipsparseStatus_t status, hipsparseStatus_t expected_status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, expected_status); #else if(status != expected_status) { std::cerr << "hipSPARSE TEST ERROR: status(=" << status << ") != expected_status(= " << expected_status << "), "; std::cerr << message << std::endl; } #endif } void verify_hipsparse_status_invalid_pointer(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_INVALID_VALUE); #else if(status != HIPSPARSE_STATUS_INVALID_VALUE) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_INVALID_VALUE, "; std::cerr << message << std::endl; } #endif } void verify_hipsparse_status_invalid_size(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_INVALID_VALUE); #else if(status != HIPSPARSE_STATUS_INVALID_VALUE) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_INVALID_VALUE, "; std::cerr << message << std::endl; } #endif } void verify_hipsparse_status_invalid_value(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_INVALID_VALUE); #else if(status != HIPSPARSE_STATUS_INVALID_VALUE) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_INVALID_VALUE, "; std::cerr << message << std::endl; } #endif } void verify_hipsparse_status_zero_pivot(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_ZERO_PIVOT); #else if(status != HIPSPARSE_STATUS_ZERO_PIVOT) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_ZERO_PIVOT, "; std::cerr << message << std::endl; } #endif } void verify_hipsparse_status_invalid_handle(hipsparseStatus_t status) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_INVALID_VALUE); #else if(status != HIPSPARSE_STATUS_INVALID_VALUE) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_INVALID_VALUE" << std::endl; } #endif } void verify_hipsparse_status_internal_error(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_INTERNAL_ERROR); #else if(status != HIPSPARSE_STATUS_INTERNAL_ERROR) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_INTERNAL_ERROR, "; std::cerr << message << std::endl; } #endif } void verify_hipsparse_status_not_supported(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_NOT_SUPPORTED); #else if(status != HIPSPARSE_STATUS_NOT_SUPPORTED) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_NOT_SUPPORTED, "; std::cerr << message << std::endl; } #endif } void verify_hipsparse_status_success(hipsparseStatus_t status, const char* message) { #ifdef GOOGLE_TEST ASSERT_EQ(status, HIPSPARSE_STATUS_SUCCESS); #else if(status != HIPSPARSE_STATUS_SUCCESS) { std::cerr << "hipSPARSE TEST ERROR: status != HIPSPARSE_STATUS_SUCCESS, "; std::cerr << message << std::endl; } #endif } ./clients/common/hipsparse_template_specialization.cpp0000664000175100017510000203526515176134305023551 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse.hpp" #include namespace hipsparse { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const float* alpha, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparseSaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const double* alpha, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparseDaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const hipComplex* alpha, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseCaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseZaxpyi(handle, nnz, alpha, xVal, xInd, y, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, const float* y, float* result, hipsparseIndexBase_t idxBase) { return hipsparseSdoti(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, const double* y, double* result, hipsparseIndexBase_t idxBase) { return hipsparseDdoti(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseCdoti(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseZdoti(handle, nnz, xVal, xInd, y, result, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, const hipComplex* y, hipComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseCdotci(handle, nnz, xVal, xInd, y, result, idxBase); } template <> hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, const hipDoubleComplex* y, hipDoubleComplex* result, hipsparseIndexBase_t idxBase) { return hipsparseZdotci(handle, nnz, xVal, xInd, y, result, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseSgthr(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseDgthr(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseCgthr(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseZgthr(handle, nnz, y, xVal, xInd, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, float* y, float* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseSgthrz(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, double* y, double* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseDgthrz(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, hipComplex* y, hipComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseCgthrz(handle, nnz, y, xVal, xInd, idxBase); } template <> hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, hipDoubleComplex* y, hipDoubleComplex* xVal, const int* xInd, hipsparseIndexBase_t idxBase) { return hipsparseZgthrz(handle, nnz, y, xVal, xInd, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, float* xVal, const int* xInd, float* y, const float* c, const float* s, hipsparseIndexBase_t idxBase) { return hipsparseSroti(handle, nnz, xVal, xInd, y, c, s, idxBase); } template <> hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, double* xVal, const int* xInd, double* y, const double* c, const double* s, hipsparseIndexBase_t idxBase) { return hipsparseDroti(handle, nnz, xVal, xInd, y, c, s, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const float* xVal, const int* xInd, float* y, hipsparseIndexBase_t idxBase) { return hipsparseSsctr(handle, nnz, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const double* xVal, const int* xInd, double* y, hipsparseIndexBase_t idxBase) { return hipsparseDsctr(handle, nnz, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const hipComplex* xVal, const int* xInd, hipComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseCsctr(handle, nnz, xVal, xInd, y, idxBase); } template <> hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const hipDoubleComplex* xVal, const int* xInd, hipDoubleComplex* y, hipsparseIndexBase_t idxBase) { return hipsparseZsctr(handle, nnz, xVal, xInd, y, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const float* alpha, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const float* x, const float* beta, float* y) { return hipsparseScsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const double* alpha, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const double* x, const double* beta, double* y) { return hipsparseDcsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseCcsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } template <> hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZcsrmv( handle, trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseScsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseDcsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseCcsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseZcsrsv2_bufferSize(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsrsv2_bufferSizeExt(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsv2_analysis(handle, transA, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsv2_solve(handle, transA, m, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, f, x, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const float* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const float* x, const float* beta, float* y) { return hipsparseShybmv(handle, trans, alpha, descr, hyb, x, beta, y); } template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const double* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const double* x, const double* beta, double* y) { return hipsparseDhybmv(handle, trans, alpha, descr, hyb, x, beta, y); } template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseChybmv(handle, trans, alpha, descr, hyb, x, beta, y); } template <> hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZhybmv(handle, trans, alpha, descr, hyb, x, beta, y); } #endif template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const float* x, const float* beta, float* y) { return hipsparseSbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const double* x, const double* beta, double* y) { return hipsparseDbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseCbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZbsrmv(handle, dirA, transA, mb, nb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, x, beta, y); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const float* alpha, const hipsparseMatDescr_t descr, const float* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const float* x, const float* beta, float* y) { return hipsparseSbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const double* alpha, const hipsparseMatDescr_t descr, const double* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const double* x, const double* beta, double* y) { return hipsparseDbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipComplex* x, const hipComplex* beta, hipComplex* y) { return hipsparseCbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } template <> hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const hipDoubleComplex* x, const hipDoubleComplex* beta, hipDoubleComplex* y) { return hipsparseZbsrxmv(handle, dir, trans, sizeOfMask, mb, nb, nnzb, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsrsv2_bufferSize(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseSbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZbsrsv2_bufferSizeExt(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsv2_analysis(handle, dir, transA, mb, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const float* f, float* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const double* f, double* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipComplex* f, hipComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const hipDoubleComplex* f, hipDoubleComplex* x, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsv2_solve(handle, dir, transA, mb, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, f, x, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseSgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseDgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseCgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes) { return hipsparseZgemvi_bufferSize(handle, transA, m, n, nnz, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const float* alpha, const float* A, int lda, int nnz, const float* x, const int* xInd, const float* beta, float* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseSgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const double* alpha, const double* A, int lda, int nnz, const double* x, const int* xInd, const double* beta, double* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseDgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipComplex* alpha, const hipComplex* A, int lda, int nnz, const hipComplex* x, const int* xInd, const hipComplex* beta, hipComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseCgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } template <> hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, int nnz, const hipDoubleComplex* x, const int* xInd, const hipDoubleComplex* beta, hipDoubleComplex* y, hipsparseIndexBase_t idxBase, void* pBuffer) { return hipsparseZgemvi( handle, transA, m, n, alpha, A, lda, nnz, x, xInd, beta, y, idxBase, pBuffer); } #endif template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparseSbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparseDbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparseCbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparseZbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, alpha, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, B, ldb, beta, C, ldc); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const float* alpha, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const float* B, int ldb, const float* beta, float* C, int ldc) { return hipsparseScsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const double* alpha, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const double* B, int ldb, const double* beta, double* C, int ldc) { return hipsparseDcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipComplex* B, int ldb, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparseCcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipDoubleComplex* B, int ldb, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparseZcsrmm2(handle, transA, transB, m, n, k, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, B, ldb, beta, C, ldc); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const float* alpha, const hipsparseMatDescr_t descrA, const float* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const float* B, int ldb, float* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const double* alpha, const hipsparseMatDescr_t descrA, const double* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const double* B, int ldb, double* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipComplex* B, int ldb, hipComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const hipDoubleComplex* B, int ldb, hipDoubleComplex* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, alpha, descrA, bsrSortedValA, bsrSortedRowPtrA, bsrSortedColIndA, blockDim, info, B, ldb, X, ldx, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseScsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseDcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseCcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes) { return hipsparseZcsrsm2_bufferSizeExt(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsm2_analysis(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const float* alpha, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, float* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const double* alpha, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, double* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipComplex* alpha, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, hipDoubleComplex* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrsm2_solve(handle, algo, transA, transB, m, nrhs, nnz, alpha, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, B, ldb, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const float* alpha, const float* A, int lda, const float* cscValB, const int* cscColPtrB, const int* cscRowIndB, const float* beta, float* C, int ldc) { return hipsparseSgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const double* alpha, const double* A, int lda, const double* cscValB, const int* cscColPtrB, const int* cscRowIndB, const double* beta, double* C, int ldc) { return hipsparseDgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipComplex* alpha, const hipComplex* A, int lda, const hipComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipComplex* beta, hipComplex* C, int ldc) { return hipsparseCgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } template <> hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const hipDoubleComplex* alpha, const hipDoubleComplex* A, int lda, const hipDoubleComplex* cscValB, const int* cscColPtrB, const int* cscRowIndB, const hipDoubleComplex* beta, hipDoubleComplex* C, int ldc) { return hipsparseZgemmi( handle, m, n, k, nnz, alpha, A, lda, cscValB, cscColPtrB, cscRowIndB, beta, C, ldc); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, float* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseScsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, double* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseDcsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseCcsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } template <> hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC) { return hipsparseZcsrgeam(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC); } #endif template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const float* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseScsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const double* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseDcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseCcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, const hipDoubleComplex* csrSortedValC, const int* csrSortedRowPtrC, const int* csrSortedColIndC, size_t* pBufferSizeInBytes) { return hipsparseZcsrgeam2_bufferSizeExt(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const float* beta, const hipsparseMatDescr_t descrB, int nnzB, const float* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, float* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseScsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const double* beta, const hipsparseMatDescr_t descrB, int nnzB, const double* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, double* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseDcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseCcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrSortedValB, const int* csrSortedRowPtrB, const int* csrSortedColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrSortedValC, int* csrSortedRowPtrC, int* csrSortedColIndC, void* pBuffer) { return hipsparseZcsrgeam2(handle, m, n, alpha, descrA, nnzA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, beta, descrB, nnzB, csrSortedValB, csrSortedRowPtrB, csrSortedColIndB, descrC, csrSortedValC, csrSortedRowPtrC, csrSortedColIndC, pBuffer); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseScsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseDcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseCcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC) { return hipsparseZcsrgemm(handle, transA, transB, m, n, k, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, descrC, csrValC, csrRowPtrC, csrColIndC); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsrgemm2_bufferSizeExt(handle, m, n, k, alpha, descrA, nnzA, csrRowPtrA, csrColIndA, descrB, nnzB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrRowPtrD, csrColIndD, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const float* alpha, const hipsparseMatDescr_t descrA, int nnzA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const float* csrValB, const int* csrRowPtrB, const int* csrColIndB, const float* beta, const hipsparseMatDescr_t descrD, int nnzD, const float* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseScsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const double* alpha, const hipsparseMatDescr_t descrA, int nnzA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const double* csrValB, const int* csrRowPtrB, const int* csrColIndB, const double* beta, const hipsparseMatDescr_t descrD, int nnzD, const double* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseDcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseCcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const hipDoubleComplex* alpha, const hipsparseMatDescr_t descrA, int nnzA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const hipDoubleComplex* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipDoubleComplex* beta, const hipsparseMatDescr_t descrD, int nnzD, const hipDoubleComplex* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer) { return hipsparseZcsrgemm2(handle, m, n, k, alpha, descrA, nnzA, csrValA, csrRowPtrA, csrColIndA, descrB, nnzB, csrValB, csrRowPtrB, csrColIndB, beta, descrD, nnzD, csrValD, csrRowPtrD, csrColIndD, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparseSbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparseDbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparseCbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXbsrilu02_numericBoost(hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparseZbsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsrilu02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrilu02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsrilu02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, float* boost_val) { return hipsparseScsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, double* boost_val) { return hipsparseDcsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipComplex* boost_val) { return hipsparseCcsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } template <> hipsparseStatus_t hipsparseXcsrilu02_numericBoost(hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, hipDoubleComplex* boost_val) { return hipsparseZcsrilu02_numericBoost(handle, info, enable_boost, tol, boost_val); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseScsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseDcsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseCcsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes) { return hipsparseZcsrilu02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsrilu02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrilu02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsrilu02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseSbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseDbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseCbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, int* pBufferSizeInBytes) { return hipsparseZbsric02_bufferSize(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsric02_analysis(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseSbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZbsric02(handle, dirA, mb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseScsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseDcsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseCcsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes) { return hipsparseZcsric02_bufferSize(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #endif template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseScsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsric02_bufferSizeExt(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsric02_analysis(handle, m, nnz, descrA, csrSortedValA, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, float* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseScsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, double* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseDcsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseCcsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } template <> hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer) { return hipsparseZcsric02(handle, m, nnz, descrA, csrSortedValA_valM, csrSortedRowPtrA, csrSortedColIndA, info, policy, pBuffer); } #endif template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseSnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseDnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseCnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } template <> hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { return hipsparseZnnz( handle, dirA, m, n, descrA, A, lda, nnzPerRowColumn, nnzTotalDevHostPtr); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, float tol) { return hipsparseSnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, double tol) { return hipsparseDnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipComplex tol) { return hipsparseCnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } template <> hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, hipDoubleComplex tol) { return hipsparseZnnz_compress(handle, m, descrA, csrValA, csrRowPtrA, nnzPerRow, nnzC, tol); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerRow, float* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseSdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerRow, double* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseDdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerRow, hipComplex* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseCdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } template <> hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerRow, hipDoubleComplex* csrVal, int* csrRowPtr, int* csrColInd) { return hipsparseZdense2csr( handle, m, n, descr, A, ld, nnzPerRow, csrVal, csrRowPtr, csrColInd); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csr_bufferSize(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csr_bufferSize(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csr_bufferSizeExt(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csr_bufferSizeExt(handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseSpruneDense2csrNnz( handle, m, n, A, lda, threshold, descr, csrRowPtr, nnzTotalDevHostPtr, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseDpruneDense2csrNnz( handle, m, n, A, lda, threshold, descr, csrRowPtr, nnzTotalDevHostPtr, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csr(hipsparseHandle_t handle, int m, int n, const float* A, int lda, const float* threshold, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { return hipsparseSpruneDense2csr( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csr(hipsparseHandle_t handle, int m, int n, const double* A, int lda, const double* threshold, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer) { return hipsparseDpruneDense2csr( handle, m, n, A, lda, threshold, descr, csrVal, csrRowPtr, csrColInd, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csrByPercentage_bufferSize(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csrByPercentage_bufferSize(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneDense2csrByPercentage_bufferSizeExt(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneDense2csrByPercentage_bufferSizeExt(handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseSpruneDense2csrNnzByPercentage( handle, m, n, A, lda, percentage, descr, csrRowPtr, nnzTotalDevHostPtr, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseDpruneDense2csrNnzByPercentage( handle, m, n, A, lda, percentage, descr, csrRowPtr, nnzTotalDevHostPtr, info, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const float* A, int lda, float percentage, const hipsparseMatDescr_t descr, float* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { return hipsparseSpruneDense2csrByPercentage( handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const double* A, int lda, double percentage, const hipsparseMatDescr_t descr, double* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer) { return hipsparseDpruneDense2csrByPercentage( handle, m, n, A, lda, percentage, descr, csrVal, csrRowPtr, csrColInd, info, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* A, int ld, const int* nnzPerColumn, float* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseSdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* A, int ld, const int* nnzPerColumn, double* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseDdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* A, int ld, const int* nnzPerColumn, hipComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseCdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } template <> hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* A, int ld, const int* nnzPerColumn, hipDoubleComplex* cscVal, int* cscRowInd, int* cscColPtr) { return hipsparseZdense2csc( handle, m, n, descr, A, ld, nnzPerColumn, cscVal, cscRowInd, cscColPtr); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, float* A, int ld) { return hipsparseScsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, double* A, int ld) { return hipsparseDcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipComplex* A, int ld) { return hipsparseCcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } template <> hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipDoubleComplex* A, int ld) { return hipsparseZcsr2dense(handle, m, n, descr, csrVal, csrRowPtr, csrColInd, A, ld); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* cscVal, const int* cscRowInd, const int* cscColPtr, float* A, int ld) { return hipsparseScsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* cscVal, const int* cscRowInd, const int* cscColPtr, double* A, int ld) { return hipsparseDcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipComplex* A, int ld) { return hipsparseCcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } template <> hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* cscVal, const int* cscRowInd, const int* cscColPtr, hipDoubleComplex* A, int ld) { return hipsparseZcsc2dense(handle, m, n, descr, cscVal, cscRowInd, cscColPtr, A, ld); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const float* csrVal, const int* csrRowPtr, const int* csrColInd, float* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseScsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const double* csrVal, const int* csrRowPtr, const int* csrColInd, double* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseDcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipComplex* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseCcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } template <> hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipDoubleComplex* csc_val, int* cscRowInd, int* cscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase) { return hipsparseZcsr2csc(handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, csc_val, cscRowInd, cscColPtr, copyValues, idxBase); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseScsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseDcsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseCcsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } template <> hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type) { return hipsparseZcsr2hyb( handle, m, n, descr, csrVal, csrRowPtr, csrColInd, hyb, user_ell_width, partition_type); } #endif template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseSgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseDgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseCgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseZgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const float* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, float* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseSgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const double* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, double* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseDgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseCgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const hipDoubleComplex* bsrVal, const int* bsrRowPtr, const int* bsrColInd, int rowBlockDim, int colBlockDim, hipDoubleComplex* bscVal, int* bscRowInd, int* bscColPtr, hipsparseAction_t copyValues, hipsparseIndexBase_t idxBase, void* temp_buffer) { return hipsparseZgebsr2gebsc(handle, mb, nb, nnzb, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, bscVal, bscRowInd, bscColPtr, copyValues, idxBase, temp_buffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseZcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseScsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseDcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, int rowBlockDim, int colBlockDim, size_t* pBufferSizeInBytes) { return hipsparseCcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, rowBlockDim, colBlockDim, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const float* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, float* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseScsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const double* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, double* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseDcsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseCcsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const hipDoubleComplex* csrVal, const int* csrRowPtr, const int* csrColInd, const hipsparseMatDescr_t bsr_descr, hipDoubleComplex* bsrVal, int* bsrRowPtr, int* bsrColInd, int rowBlockDim, int colBlockDim, void* pbuffer) { return hipsparseZcsr2gebsr(handle, dir, m, n, csr_descr, csrVal, csrRowPtr, csrColInd, bsr_descr, bsrVal, bsrRowPtr, bsrColInd, rowBlockDim, colBlockDim, pbuffer); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseScsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseDcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseCcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC) { return hipsparseZcsr2bsr(handle, dirA, m, n, descrA, csrValA, csrRowPtrA, csrColIndA, blockDim, descrC, bsrValC, bsrRowPtrC, bsrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseSbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseDbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseCbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseZbsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, blockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, float* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseSgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, double* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseDgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseCgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } template <> hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, hipDoubleComplex* csrValC, int* csrRowPtrC, int* csrColIndC) { return hipsparseZgebsr2csr(handle, dirA, mb, nb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDim, colBlockDim, descrC, csrValC, csrRowPtrC, csrColIndC); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, float* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseShyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, double* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseDhyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipComplex* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseChyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } template <> hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, hipDoubleComplex* csrValA, int* csrRowPtrA, int* csrColIndA) { return hipsparseZhyb2csr(handle, descrA, hybA, csrValA, csrRowPtrA, csrColIndA); } #endif template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, float* csrValC, int* csrColIndC, int* csrRowPtrC, float tol) { return hipsparseScsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, double* csrValC, int* csrColIndC, int* csrRowPtrC, double tol) { return hipsparseDcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipComplex tol) { return hipsparseCcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, hipDoubleComplex* csrValC, int* csrColIndC, int* csrRowPtrC, hipDoubleComplex tol) { return hipsparseZcsr2csr_compress(handle, m, n, descrA, csrValA, csrColIndA, csrRowPtrA, nnzA, nnzPerRow, csrValC, csrColIndC, csrRowPtrC, tol); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csr_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csr_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csr_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csr_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseSpruneCsr2csrNnz(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer) { return hipsparseDpruneCsr2csrNnz(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrRowPtrC, nnzTotalDevHostPtr, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* threshold, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparseSpruneCsr2csr(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* threshold, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer) { return hipsparseDpruneCsr2csr(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, threshold, descrC, csrValC, csrRowPtrC, csrColIndC, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csrByPercentage_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csrByPercentage_bufferSize(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, const float* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseSpruneCsr2csrByPercentage_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, const double* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDpruneCsr2csrByPercentage_bufferSizeExt(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseSpruneCsr2csrNnzByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrRowPtrC, nnzTotalDevHostPtr, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer) { return hipsparseDpruneCsr2csrNnzByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrRowPtrC, nnzTotalDevHostPtr, info, buffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, float percentage, const hipsparseMatDescr_t descrC, float* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparseSpruneCsr2csrByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, buffer); } template <> hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, double percentage, const hipsparseMatDescr_t descrC, double* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer) { return hipsparseDpruneCsr2csrByPercentage(handle, m, n, nnzA, descrA, csrValA, csrRowPtrA, csrColIndA, percentage, descrC, csrValC, csrRowPtrC, csrColIndC, info, buffer); } #endif template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseSgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseDgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseCgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* pBufferSizeInBytes) { return hipsparseZgebsr2gebsr_bufferSize(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, rowBlockDimC, colBlockDimC, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const float* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, float* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseSgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const double* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, double* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseDgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseCgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } template <> hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const hipDoubleComplex* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, hipDoubleComplex* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer) { return hipsparseZgebsr2gebsr(handle, dirA, mb, nb, nnzb, descrA, bsrValA, bsrRowPtrA, bsrColIndA, rowBlockDimA, colBlockDimA, descrC, bsrValC, bsrRowPtrC, bsrColIndC, rowBlockDimC, colBlockDimC, buffer); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseScsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseDcsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseCcsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes) { return hipsparseZcsru2csr_bufferSizeExt( handle, m, n, nnz, csrVal, csrRowPtr, csrColInd, info, pBufferSizeInBytes); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseScsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseDcsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseCcsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseZcsru2csr( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, float* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseScsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, double* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseDcsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseCcsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } template <> hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, hipDoubleComplex* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer) { return hipsparseZcsr2csru( handle, m, n, nnz, descrA, csrVal, csrRowPtr, csrColInd, info, pBuffer); } #endif template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* ds, const float* dl, const float* d, const float* du, const float* dw, const float* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseSgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* ds, const double* dl, const double* d, const double* du, const double* dw, const double* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseDgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* ds, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* dw, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseCgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* ds, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* dw, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseZgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* ds, float* dl, float* d, float* du, float* dw, float* x, int batchCount, void* pBuffer) { return hipsparseSgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* ds, double* dl, double* d, double* du, double* dw, double* x, int batchCount, void* pBuffer) { return hipsparseDgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* ds, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* dw, hipComplex* x, int batchCount, void* pBuffer) { return hipsparseCgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* ds, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* dw, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparseZgpsvInterleavedBatch( handle, algo, m, ds, dl, d, du, dw, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseSgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseDgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseCgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes) { return hipsparseZgtsv2StridedBatch_bufferSizeExt( handle, m, dl, d, du, x, batchCount, batchStride, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const float* dl, const float* d, const float* du, float* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseSgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const double* dl, const double* d, const double* du, double* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseDgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseCgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, int batchStride, void* pBuffer) { return hipsparseZgtsv2StridedBatch( handle, m, dl, d, du, x, batchCount, batchStride, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseSgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseDgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseCgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseZgtsv2_bufferSizeExt(handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparseSgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparseDgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparseCgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparseZgtsv2(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, const float* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseSgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, const double* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseDgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseCgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* B, int ldb, size_t* pBufferSizeInBytes) { return hipsparseZgtsv2_nopivot_bufferSizeExt( handle, m, n, dl, d, du, B, ldb, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const float* dl, const float* d, const float* du, float* B, int ldb, void* pBuffer) { return hipsparseSgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const double* dl, const double* d, const double* du, double* B, int ldb, void* pBuffer) { return hipsparseDgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipComplex* dl, const hipComplex* d, const hipComplex* du, hipComplex* B, int ldb, void* pBuffer) { return hipsparseCgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, hipDoubleComplex* B, int ldb, void* pBuffer) { return hipsparseZgtsv2_nopivot(handle, m, n, dl, d, du, B, ldb, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const float* dl, const float* d, const float* du, const float* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseSgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const double* dl, const double* d, const double* du, const double* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseDgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipComplex* dl, const hipComplex* d, const hipComplex* du, const hipComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseCgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const hipDoubleComplex* dl, const hipDoubleComplex* d, const hipDoubleComplex* du, const hipDoubleComplex* x, int batchCount, size_t* pBufferSizeInBytes) { return hipsparseZgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, dl, d, du, x, batchCount, pBufferSizeInBytes); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, float* dl, float* d, float* du, float* x, int batchCount, void* pBuffer) { return hipsparseSgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, double* dl, double* d, double* du, double* x, int batchCount, void* pBuffer) { return hipsparseDgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipComplex* dl, hipComplex* d, hipComplex* du, hipComplex* x, int batchCount, void* pBuffer) { return hipsparseCgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } template <> hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, hipDoubleComplex* dl, hipDoubleComplex* d, hipDoubleComplex* du, hipDoubleComplex* x, int batchCount, void* pBuffer) { return hipsparseZgtsvInterleavedBatch(handle, algo, m, dl, d, du, x, batchCount, pBuffer); } #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const float* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseScsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const double* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseDcsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const float* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseCcsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } template <> hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const hipDoubleComplex* csrValA, const int* csrRowPtrA, const int* csrColIndA, const double* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info) { return hipsparseZcsrcolor(handle, m, nnz, descrA, csrValA, csrRowPtrA, csrColIndA, fractionToColor, ncolors, coloring, reordering, info); } #endif } // namespace hipsparse ./clients/common/unit.cpp0000664000175100017510000002052515176134305015530 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "unit.hpp" #include #include #include #include #ifdef GOOGLE_TEST #include #else #ifdef NDEBUG #undef NDEBUG #include #define NDEBUG #else #include #endif #endif /* ========================================Gtest Unit Check * ==================================================== */ /*! \brief Template: gtest unit compare two matrices float/double/complex */ // Do not put a wrapper over ASSERT_FLOAT_EQ, sincer assert exit the current function NOT the test // case // a wrapper will cause the loop keep going template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, int8_t* hCPU, int8_t* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_FLOAT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, float* hCPU, float* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_FLOAT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, double* hCPU, double* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_DOUBLE_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, hipComplex* hCPU, hipComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_FLOAT_EQ(hCPU[i + j * lda].x, hGPU[i + j * lda].x); ASSERT_FLOAT_EQ(hCPU[i + j * lda].y, hGPU[i + j * lda].y); #else assert(hCPU[i + j * lda].x == hGPU[i + j * lda].x); assert(hCPU[i + j * lda].y == hGPU[i + j * lda].y); #endif } } } template <> void unit_check_general( int64_t M, int64_t N, int64_t lda, hipDoubleComplex* hCPU, hipDoubleComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_DOUBLE_EQ(hCPU[i + j * lda].x, hGPU[i + j * lda].x); ASSERT_DOUBLE_EQ(hCPU[i + j * lda].y, hGPU[i + j * lda].y); #else assert(hCPU[i + j * lda].x == hGPU[i + j * lda].x); assert(hCPU[i + j * lda].y == hGPU[i + j * lda].y); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, int* hCPU, int* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, int64_t* hCPU, int64_t* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } template <> void unit_check_general(int64_t M, int64_t N, int64_t lda, size_t* hCPU, size_t* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { #ifdef GOOGLE_TEST ASSERT_EQ(hCPU[i + j * lda], hGPU[i + j * lda]); #else assert(hCPU[i + j * lda] == hGPU[i + j * lda]); #endif } } } /*! \brief Template: gtest unit compare two matrices float/double/complex */ // Do not put a wrapper over ASSERT_FLOAT_EQ, since assert exit the current function NOT the test // case // a wrapper will cause the loop keep going template <> void unit_check_near(int64_t M, int64_t N, int64_t lda, float* hCPU, float* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { float compare_val = std::max(std::abs(hCPU[i + j * lda] * 1e-3f), 10 * std::numeric_limits::epsilon()); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda], hGPU[i + j * lda], compare_val); #else assert(std::abs(hCPU[i + j * lda] - hGPU[i + j * lda]) < compare_val); #endif } } } template <> void unit_check_near(int64_t M, int64_t N, int64_t lda, double* hCPU, double* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { double compare_val = std::max(std::abs(hCPU[i + j * lda] * 1e-10), 10 * std::numeric_limits::epsilon()); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda], hGPU[i + j * lda], compare_val); #else assert(std::abs(hCPU[i + j * lda] - hGPU[i + j * lda]) < compare_val); #endif } } } template <> void unit_check_near(int64_t M, int64_t N, int64_t lda, hipComplex* hCPU, hipComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { hipComplex compare_val = make_hipFloatComplex(std::max(std::abs(hCPU[i + j * lda].x * 1e-3f), 10 * std::numeric_limits::epsilon()), std::max(std::abs(hCPU[i + j * lda].y * 1e-3f), 10 * std::numeric_limits::epsilon())); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda].x, hGPU[i + j * lda].x, compare_val.x); ASSERT_NEAR(hCPU[i + j * lda].y, hGPU[i + j * lda].y, compare_val.y); #else assert(std::abs(hCPU[i + j * lda].x - hGPU[i + j * lda].x) < compare_val.x); assert(std::abs(hCPU[i + j * lda].y - hGPU[i + j * lda].y) < compare_val.y); #endif } } } template <> void unit_check_near( int64_t M, int64_t N, int64_t lda, hipDoubleComplex* hCPU, hipDoubleComplex* hGPU) { for(int64_t j = 0; j < N; j++) { for(int64_t i = 0; i < M; i++) { hipDoubleComplex compare_val = make_hipDoubleComplex(std::max(std::abs(hCPU[i + j * lda].x * 1e-10), 10 * std::numeric_limits::epsilon()), std::max(std::abs(hCPU[i + j * lda].y * 1e-10), 10 * std::numeric_limits::epsilon())); #ifdef GOOGLE_TEST ASSERT_NEAR(hCPU[i + j * lda].x, hGPU[i + j * lda].x, compare_val.x); ASSERT_NEAR(hCPU[i + j * lda].y, hGPU[i + j * lda].y, compare_val.y); #else assert(std::abs(hCPU[i + j * lda].x - hGPU[i + j * lda].x) < compare_val.x); assert(std::abs(hCPU[i + j * lda].y - hGPU[i + j * lda].y) < compare_val.y); #endif } } } ./clients/common/hipsparse_gentest.py0000664000175100017510000004263515176134305020154 0ustar jenkinsjenkins#!/usr/bin/env python3 # ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## """Expand hipSPARSE YAML test data file into binary Arguments records""" import re import sys import os import argparse import ctypes import glob from fnmatch import fnmatchcase try: # Import either the C or pure-Python YAML parser from yaml import CLoader as Loader except ImportError: from yaml import Loader import yaml # Regex for type names in the YAML file. Optional *nnn indicates array. TYPE_RE = re.compile(r'[a-z_A-Z]\w*(:?\s*\*\s*\d+)?$') # Regex for integer ranges A..B[..C] INT_RANGE_RE = re.compile(r'\s*(-?\d+)\s*\.\.\s*(-?\d+)\s*(?:\.\.\s*(-?\d+)\s*)?$') # Regex for include: YAML extension INCLUDE_RE = re.compile(r'include\s*:\s*(.*)') # Regex for complex types COMPLEX_RE = re.compile(r'f\d+_c$') args = {} testcases = set() datatypes = {} param = {} def main(): args.update(parse_args().__dict__) for doc in get_yaml_docs(): process_doc(doc) def process_doc(doc): """Process one document in the YAML file""" # Ignore empty documents if not doc or not doc.get('Tests'): return # Clear datatypes and params from previous documents datatypes.clear() param.clear() # Return dictionary of all known datatypes datatypes.update(get_datatypes(doc)) # Arguments structure corresponding to C/C++ structure param['Arguments'] = type('Arguments', (ctypes.Structure,), {'_fields_': get_arguments(doc)}) # Special names which get expanded as lists of arguments param['dict_lists_to_expand'] = doc.get('Dictionary lists to expand') or () # Lists which are not expanded param['lists_to_not_expand'] = doc.get('Lists to not expand') or () # Defaults defaults = doc.get('Defaults') or {} # Known Bugs param['known_bugs'] = doc.get('Known bugs') or [] # Functions param['Functions'] = doc.get('Functions') or {} # Instantiate all of the tests, starting with defaults for test in doc['Tests']: case = defaults.copy() case.update(test) generate(case, instantiate) def parse_args(): """Parse command-line arguments, returning input and output files""" parser = argparse.ArgumentParser(description=""" Expand hipSPARSE YAML test data file into binary Arguments records """) parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin) parser.add_argument('-o', '--out', dest='outfile', type=argparse.FileType('wb'), default=sys.stdout) parser.add_argument('-I', help="Add include path", action='append', dest='includes', default=[]) parser.add_argument('-t', '--template', type=argparse.FileType('r')) parser.add_argument('-m', '--matrices-dir', dest='matrices-dir', default='./') return parser.parse_args() def read_yaml_file(file): """Read the YAML file, processing include: lines as an extension""" file_dir = os.path.dirname(file.name) or os.getcwd() source = [] for line_no, line in enumerate(file, start=1): # Keep track of file names and line numbers for each line of YAML match = line.startswith('include') and INCLUDE_RE.match(line) if not match: source.append([line, file.name, line_no]) else: include_file = match.group(1) include_dirs = [file_dir] + args['includes'] for path in include_dirs: path = os.path.join(path, include_file) if os.path.exists(path): source.extend(read_yaml_file(open(path, 'r'))) break else: sys.exit("In file " + file.name + ", line " + str(line_no) + ", column " + str(match.start(1)+1) + ":\n" + line.rstrip() + "\n" + " " * match.start(1) + "^\nCannot open " + include_file + "\n\nInclude paths:\n" + "\n".join(include_dirs)) file.close() return source def get_yaml_docs(): """Parse the YAML file""" source = read_yaml_file(args['infile']) if args.get('template'): source = read_yaml_file(args['template']) + source source_str = ''.join([line[0] for line in source]) def mark_str(mark): line = source[mark.line] return("In file " + line[1] + ", line " + str(line[2]) + ", column " + str(mark.column + 1) + ":\n" + line[0].rstrip() + "\n" + ' ' * mark.column + "^\n") # We iterate through all of the documents to properly diagnose errors, # because the load_all generator does not handle exceptions correctly. docs = [] load = Loader(source_str) while load.check_data(): try: doc = load.get_data() except yaml.YAMLError as err: sys.exit((mark_str(err.problem_mark) if err.problem_mark else "") + (err.problem + "\n" if err.problem else "") + (err.note + "\n" if err.note else "")) else: docs.append(doc) return docs def get_datatypes(doc): """ Get datatypes from YAML doc""" dt = ctypes.__dict__.copy() for declaration in doc.get('Datatypes') or (): for name, decl in declaration.items(): if isinstance(decl, dict): # Create derived class type based on bases and attr entries dt[name] = type(name, tuple([eval(t, dt) for t in decl.get('bases') or () if TYPE_RE.match(t)] ), decl.get('attr') or {}) # Import class' attributes into the datatype namespace for subtype in decl.get('attr') or {}: if TYPE_RE.match(subtype): dt[subtype] = eval(name+'.'+subtype, dt) elif isinstance(decl, str) and TYPE_RE.match(decl): dt[name] = dt[decl] else: sys.exit("Unrecognized data type "+name+": "+repr(decl)) return dt def get_arguments(doc): """The kernel argument list, with argument names and types""" return [(var, eval(decl[var], datatypes)) for decl in doc.get('Arguments') or () if len(decl) == 1 for var in decl if TYPE_RE.match(decl[var])] def setdefaults(test): """Set default values for parameters""" # Do not put constant defaults here -- use hipsparse_common.yaml for that. # These are only for dynamic defaults # TODO: This should be ideally moved to YAML file, with eval'd expressions. if test['transA'] == 111 or test['transB'] == 111: test.setdefault('lda', 0) test.setdefault('ldb', 0) test.setdefault('ldc', 0) test.setdefault('ldd', 0) else: test.setdefault('lda', test['M'] if test['transA'] == 111 else test['K']) test.setdefault('ldb', test['K'] if test['transB'] == 111 else test['N']) test.setdefault('ldc', test['M']) test.setdefault('ldd', test['M']) def write_signature(out): """Write the signature used to verify binary file compatibility""" if 'signature_written' not in args: sig = 0 byt = bytearray("hipSPARSE", 'utf_8') byt.append(0) last_ofs = 0 for (name, ctype) in param['Arguments']._fields_: member = getattr(param['Arguments'], name) for i in range(0, member.offset - last_ofs): byt.append(0) for i in range(0, member.size): byt.append(sig ^ i) sig = (sig + 89) % 256 last_ofs = member.offset + member.size for i in range(0, ctypes.sizeof(param['Arguments']) - last_ofs): byt.append(0) byt.extend(bytes("HIPsparse", 'utf_8')) byt.append(0) out.write(byt) args['signature_written'] = True def write_test(test): """Write the test case out to the binary file if not seen already""" # For each argument declared in arguments, we generate a positional # argument in the Arguments constructor. For strings, we pass the # value of the string directly. For arrays, we unpack their contents # into the ctype array constructor and pass the ctype array. For # scalars, we coerce the string/numeric value into ctype. arg = [] for name, ctype in param['Arguments']._fields_: try: if issubclass(ctype, ctypes.Array): if issubclass(ctype._type_, ctypes.c_char): arg.append(bytes(test[name], 'utf_8')) else: arg.append(ctype(*test[name])) elif issubclass(ctype, ctypes.c_char): arg.append(bytes(test[name], 'utf_8')) else: arg.append(ctype(test[name])) except TypeError as err: sys.exit("TypeError: " + str(err) + " for " + name + ", which has type " + str(type(test[name])) + "\n") byt = bytes(param['Arguments'](*arg)) if byt not in testcases: testcases.add(byt) write_signature(args['outfile']) args['outfile'].write(byt) def instantiate(test): """Instantiate a given test case""" test = test.copy() # Any Arguments fields declared as enums enum_args = [decl[0] for decl in param['Arguments']._fields_ if decl[1].__module__ == '__main__'] try: setdefaults(test) # If no enum arguments are complex, clear alphai and betai for typename in enum_args: if COMPLEX_RE.match(test[typename]): break else: for name in ('alphai', 'betai', 'boostvali'): if name in test: test[name] = 0.0 # For enum arguments, replace name with value for typename in enum_args: test[typename] = datatypes[test[typename]] # Match known bugs if test['category'] not in ('known_bug', 'disabled'): for bug in param['known_bugs']: for key, value in bug.items(): if key not in test: break if key == 'function': if not fnmatchcase(test[key], value): break # For keys declared as enums, compare resulting values elif test[key] != (datatypes.get(value) if key in enum_args else value): break else: # All values specified in known bug match test case test['category'] = 'known_bug' break write_test(test) except KeyError as err: sys.exit("Undefined value " + str(err) + "\n" + str(test)) def generate(test, function): """Generate test combinations by iterating across lists recursively""" test = test.copy() # For specially named lists, they are expanded and merged into the test # argument list. When the list name is a dictionary of length 1, its pairs # indicate that the argument named by its key takes on values paired with # the argument named by its value, which is another dictionary list. We # process the value dictionaries' keys in alphabetic order, to ensure # deterministic test ordering. for argname in param['dict_lists_to_expand']: if type(argname) == dict: if len(argname) == 1: arg, target = list(argname.items())[0] if arg in test and type(test[arg]) == dict: pairs = sorted(list(test[arg].items()), key=lambda x: x[0]) for test[arg], test[target] in pairs: generate(test, function) return elif argname in test and type(test[argname]) in (tuple, list, dict): # Pop the list and iterate across it ilist = test.pop(argname) # For a bare dictionary, wrap it in a list and apply it once for item in [ilist] if type(ilist) == dict else ilist: try: case = test.copy() case.update(item) # original test merged with each item generate(case, function) except TypeError as err: sys.exit("TypeError: " + str(err) + " for " + argname + ", which has type " + str(type(item)) + "\nA name listed in \"Dictionary lists to expand\" " "must be a defined as a dictionary.\n") return matrices_dir = str(args['matrices-dir']) if matrices_dir[-1] != "/": matrices_dir+="/" for key in sorted(list(test)): # Integer arguments which are ranges (A..B[..C]) are expanded if type(test[key]) == str: match = INT_RANGE_RE.match(str(test[key])) if match: for test[key] in range(int(match.group(1)), int(match.group(2))+1, int(match.group(3) or 1)): generate(test, function) return # For sequence arguments, they are expanded into scalars elif (type(test[key]) in (tuple, list) and key not in param['lists_to_not_expand']): if key == "filename" and test[key] != "*": cleanlist=[] for test[key] in test[key]: # # Get argument. # filename_arg = matrices_dir + str(test[key]) # # Check if this is a valid argument # if ((not os.path.isdir(filename_arg)) and (not glob.glob(filename_arg)) and (not glob.glob(filename_arg + ".bin"))): print("skip unrecognized filename, directory or filename glob expression: '" + test[key] + "'") else: cleanlist.append(test[key]) if not cleanlist: return; test[key] = cleanlist for test[key] in test[key]: # # Get argument. # filename_arg = matrices_dir + str(test[key]) # # It is a directory. # if os.path.isdir(filename_arg): # # List the files. # names = glob.glob(filename_arg + "/*") for name in names: subpath=os.path.splitext(name.replace(matrices_dir,""))[0] test[key]=[subpath] generate(test,function) else: # # Might be a glob expression # names = glob.glob(filename_arg) if not names: names = glob.glob(filename_arg + ".bin") generate(test,function) else: for name in names: subpath=os.path.splitext(name.replace(matrices_dir,""))[0] test[key]=[subpath] generate(test,function) else: for test[key] in test[key]: generate(test,function) return # Replace typed function names with generic functions and types if 'hipsparse_function' in test: func = test.pop('hipsparse_function') if func in param['Functions']: test.update(param['Functions'][func]) else: test['function'] = func generate(test, function) return function(test) if __name__ == '__main__': main()./clients/common/hipsparse_parse_data.cpp0000664000175100017510000000311415176134305020725 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_parse_data.hpp" #include "hipsparse_data.hpp" bool hipsparse_parse_data(int& argc, char** argv, const std::string& default_file) { std::cout << "default_file: " << default_file << std::endl; HipSPARSE_TestData::set_filename(default_file, false); return true; }./clients/common/utility.cpp0000664000175100017510000002050115176134511016245 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include #ifdef WIN32 #include #endif #include "utility.hpp" #include #include #ifdef WIN32 #define strSUITEcmp(A, B) _stricmp(A, B) #endif #ifdef __cpp_lib_filesystem #include namespace fs = std::filesystem; #else #include namespace fs = std::experimental::filesystem; #endif /* ============================================================================================ */ // Return path of this executable std::string hipsparse_exepath() { #ifdef WIN32 std::vector result(MAX_PATH + 1); // Ensure result is large enough to accomodate the path DWORD length = 0; for(;;) { length = GetModuleFileNameA(nullptr, result.data(), result.size()); if(length < result.size() - 1) { result.resize(length + 1); break; } result.resize(result.size() * 2); } fs::path exepath(result.begin(), result.end()); exepath = exepath.remove_filename(); exepath += exepath.empty() ? "" : "/"; return exepath.string(); #else std::string pathstr; char* path = realpath("/proc/self/exe", 0); if(path) { char* p = strrchr(path, '/'); if(p) { p[1] = 0; pathstr = path; } free(path); } return pathstr; #endif } /* ==================================================================================== */ // Return path where the test data file (hipsparse_test.data) is located std::string hipsparse_datapath() { #ifdef WIN32 fs::path share_path = fs::path(hipsparse_exepath() + "../share/hipsparse/test"); std::error_code ec; fs::path path = fs::canonical(share_path, ec); if(!ec) { if(fs::exists(path, ec) && !ec) { path += path.empty() ? "" : "/"; return path.string(); } } #else std::string pathstr; std::string share_path = hipsparse_exepath() + "../share/hipsparse/test"; char* path = realpath(share_path.c_str(), 0); if(path != NULL) { pathstr = path; pathstr += "/"; free(path); return pathstr; } #endif return hipsparse_exepath(); } #ifdef __cplusplus extern "C" { #endif /* ============================================================================================ */ /* query for hipsparse version and git commit SHA-1. */ void query_version(char* version) { int hipsparse_ver; char hipsparse_rev[256]; hipsparseStatus_t status; hipsparseHandle_t handle; status = hipsparseCreate(&handle); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "The creation of the hipsparseHandle_t failed." << std::endl; throw(status); } status = hipsparseGetVersion(handle, &hipsparse_ver); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "hipsparseGetVersion failed." << std::endl; throw(status); } status = hipsparseGetGitRevision(handle, hipsparse_rev); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "hipsparseGetGitRevision failed." << std::endl; throw(status); } status = hipsparseDestroy(handle); if(HIPSPARSE_STATUS_SUCCESS != status) { std::cerr << "rocsparse_destroy_handle failed." << std::endl; throw(status); } snprintf(version, 512, "v%d.%d.%d-%.256s", hipsparse_ver / 100000, hipsparse_ver / 100 % 1000, hipsparse_ver % 100, hipsparse_rev); } /* ============================================================================================ */ /* device query and print out their ID and name; return number of compute-capable devices. */ int query_device_property() { int device_count; { hipsparseStatus_t status = (hipsparseStatus_t)hipGetDeviceCount(&device_count); if(status != HIPSPARSE_STATUS_SUCCESS) { printf("Query device error: cannot get device count.\n"); return -1; } else { printf("Query device success: there are %d devices\n", device_count); } } for(int i = 0; i < device_count; i++) { hipDeviceProp_t props; hipsparseStatus_t status = (hipsparseStatus_t)hipGetDeviceProperties(&props, i); if(status != HIPSPARSE_STATUS_SUCCESS) { printf("Query device error: cannot get device ID %d's property\n", i); } else { printf("Device ID %d : %s\n", i, props.name); printf("-------------------------------------------------------------------------\n"); printf("with %ldMB memory, clock rate %dMHz @ computing capability %d.%d \n", props.totalGlobalMem >> 20, (int)(props.clockRate / 1000), props.major, props.minor); printf("maxGridDimX %d, sharedMemPerBlock %ldKB, maxThreadsPerBlock %d, warpSize %d\n", props.maxGridSize[0], props.sharedMemPerBlock >> 10, props.maxThreadsPerBlock, props.warpSize); printf("-------------------------------------------------------------------------\n"); } } return device_count; } /* set current device to device_id */ void set_device(int device_id) { hipsparseStatus_t status = (hipsparseStatus_t)hipSetDevice(device_id); if(status != HIPSPARSE_STATUS_SUCCESS) { printf("Set device error: cannot set device ID %d, there may not be such device ID\n", (int)device_id); } } /* ============================================================================================ */ /* timing:*/ /*! \brief CPU Timer(in microsecond): synchronize with the default device and return wall time */ double get_time_us(void) { std::ignore = hipDeviceSynchronize(); auto now = std::chrono::steady_clock::now(); // struct timeval tv; // gettimeofday(&tv, NULL); // return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; auto duration = std::chrono::duration_cast(now.time_since_epoch()).count(); return (static_cast(duration)); // hipDeviceSynchronize(); //struct timeval tv; //gettimeofday(&tv, NULL); //return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; }; /*! \brief CPU Timer(in microsecond): synchronize with given queue/stream and return wall time */ double get_time_us_sync(hipStream_t stream) { std::ignore = hipStreamSynchronize(stream); auto now = std::chrono::steady_clock::now(); // struct timeval tv; // gettimeofday(&tv, NULL); // return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; auto duration = std::chrono::duration_cast(now.time_since_epoch()).count(); return (static_cast(duration)); // hipStreamSynchronize(stream); // struct timeval tv; // gettimeofday(&tv, NULL); // return (tv.tv_sec * 1000 * 1000) + tv.tv_usec; }; #ifdef __cplusplus } #endif ./clients/CMakeLists.txt0000664000175100017510000001521715176134511015316 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # The ROCm platform requires Ubuntu 16.04 or Fedora 24, which has cmake 3.5 cmake_minimum_required(VERSION 3.5 FATAL_ERROR) # Consider removing this in the future # This should appear before the project command, because it does not use FORCE if(WIN32) set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories") else() set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories") endif() # This has to be initialized before the project() command appears # Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE if(NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel.") endif() # This project may compile dependencies for clients project(hipsparse-clients LANGUAGES CXX) if (BUILD_CLIENTS_ONLY) find_package(hipsparse 4.0.0 REQUIRED) endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # This option only works for make/nmake and the ninja generators, but no reason it shouldn't be on all the time # This tells cmake to create a compile_commands.json file that can be used with clang tooling or vim set(CMAKE_EXPORT_COMPILE_COMMANDS ON) if(NOT TARGET hipsparse) find_package(hipsparse REQUIRED CONFIG PATHS /opt/rocm/hipsparse) option(BUILD_CLIENTS_TESTS "Build tests (requires googletest)" OFF) option(BUILD_CLIENTS_SAMPLES "Build examples" ON) option(BUILD_CLIENTS_BENCHMARKS "Build benchmarks" ON) endif() # Set CXX flags if (NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Set CXX standard if (CMAKE_CXX_STANDARD EQUAL 14) message( DEPRECATION "Builds using the C++14 standard will no longer be supported in the next major release" ) elseif(NOT CMAKE_CXX_STANDARD EQUAL 17) message(FATAL_ERROR "Only C++14 and C++17 are supported") endif() # If OpenMP is available, we can use it to speed up some tests find_package(OpenMP QUIET) find_package(Threads QUIET) if(OPENMP_FOUND AND THREADS_FOUND) if(NOT TARGET OpenMP::OpenMP_CXX) # OpenMP cmake fix for cmake <= 3.9 add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE) set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS}) set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads) endif() endif() if(BUILD_CLIENTS_SAMPLES) add_subdirectory(samples) endif() if(BUILD_CLIENTS_BENCHMARKS) add_subdirectory(benchmarks) endif() if(BUILD_CLIENTS_TESTS) enable_testing() add_subdirectory(tests) if(NOT CONVERT_SOURCE) set(CONVERT_SOURCE ${CMAKE_SOURCE_DIR}/deps/convert.cpp) endif() execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CONVERT_SOURCE} -Wl,--build-id=sha1 -O3 -o ${PROJECT_BINARY_DIR}/mtx2csr.exe RESULT_VARIABLE STATUS) if(STATUS AND NOT STATUS EQUAL 0) message(FATAL_ERROR "mtx2csr.exe failed to build, aborting.") endif() set(HIPSPARSE_CLIENTMATRICES "${CMAKE_SOURCE_DIR}/cmake/hipsparse_clientmatrices.cmake") set(HIPSPARSE_CONVERT "${PROJECT_BINARY_DIR}/hipsparse_mtx2csr") add_custom_command(OUTPUT "${HIPSPARSE_CONVERT}" COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_BINARY_DIR}/mtx2csr.exe" "${HIPSPARSE_CONVERT}" DEPENDS "${PROJECT_BINARY_DIR}/mtx2csr.exe" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") set(HIPSPARSE_COMMON "${PROJECT_BINARY_DIR}/staging/hipsparse_common.yaml") add_custom_command(OUTPUT "${HIPSPARSE_COMMON}" COMMAND ${CMAKE_COMMAND} -E copy include/hipsparse_common.yaml "${HIPSPARSE_COMMON}" DEPENDS include/hipsparse_common.yaml WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") set(HIPSPARSE_TEMPLATE "${PROJECT_BINARY_DIR}/staging/hipsparse_template.yaml") add_custom_command(OUTPUT "${HIPSPARSE_TEMPLATE}" COMMAND ${CMAKE_COMMAND} -E copy include/hipsparse_template.yaml "${HIPSPARSE_TEMPLATE}" DEPENDS include/hipsparse_template.yaml WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") set(HIPSPARSE_GENTEST "${PROJECT_BINARY_DIR}/staging/hipsparse_gentest.py") add_custom_command(OUTPUT "${HIPSPARSE_GENTEST}" COMMAND ${CMAKE_COMMAND} -E copy common/hipsparse_gentest.py "${HIPSPARSE_GENTEST}" DEPENDS common/hipsparse_gentest.py WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") add_custom_target(hipsparse-common DEPENDS "${HIPSPARSE_COMMON}" "${HIPSPARSE_TEMPLATE}" "${HIPSPARSE_CLIENTMATRICES}" "${HIPSPARSE_GENTEST}" "${HIPSPARSE_CONVERT}") rocm_install( FILES "${HIPSPARSE_COMMON}" "${HIPSPARSE_TEMPLATE}" COMPONENT clients-common DESTINATION "${CMAKE_INSTALL_DATADIR}/hipsparse/test" ) # rocm_install( PROGRAMS "${HIPSPARSE_GENTEST}" COMPONENT clients-common DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/hipsparse/test" ) rocm_install( PROGRAMS "${HIPSPARSE_CONVERT}" COMPONENT clients-common DESTINATION ${CMAKE_INSTALL_BINDIR} ) rocm_install( FILES "${HIPSPARSE_CLIENTMATRICES}" COMPONENT clients-common DESTINATION "${CMAKE_INSTALL_DATADIR}/hipsparse/test" ) endif() ./clients/include/0000775000175100017510000000000015176134511014173 5ustar jenkinsjenkins./clients/include/testing_spvv.hpp0000664000175100017510000002456615176134511017454 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPVV_HPP #define TESTING_SPVV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_spvv_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t size = 100; int64_t nnz = 100; float result; hipsparseOperation_t opType = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // SpVV bufferSize size_t bufferSize; verify_hipsparse_status_invalid_handle( hipsparseSpVV_bufferSize(nullptr, opType, x, y, &result, dataType, &bufferSize)); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, nullptr, y, &result, dataType, &bufferSize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, x, nullptr, &result, dataType, &bufferSize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, x, y, nullptr, dataType, &bufferSize), "Error: result is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV_bufferSize(handle, opType, x, y, &result, dataType, nullptr), "Error: bufferSize is nullptr"); // SpVV void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, 100)); verify_hipsparse_status_invalid_handle( hipsparseSpVV(nullptr, opType, x, y, &result, dataType, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, nullptr, y, &result, dataType, buffer), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, x, nullptr, &result, dataType, buffer), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, x, y, nullptr, dataType, buffer), "Error: result is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVV(handle, opType, x, y, &result, dataType, nullptr), "Error: buffer is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); CHECK_HIP_ERROR(hipFree(buffer)); #endif } template hipsparseStatus_t testing_spvv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) I size = argus.N; I nnz = argus.nnz; hipsparseOperation_t trans = argus.transA; hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, size); // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; auto dresult_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult = (T*)dresult_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); T hresult; T hresult_gold; T hresult_copied_from_device; // SpVV_bufferSize size_t bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseSpVV_bufferSize(handle, trans, x, y, &hresult, dataType, &bufferSize)); void* externalBuffer; CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, &hresult, dataType, externalBuffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, dresult, dataType, externalBuffer)); // Copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(&hresult_copied_from_device, dresult, sizeof(T), hipMemcpyDeviceToHost)); // CPU solution if(trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { hresult_gold = make_DataType(0); for(I i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(testing_conj(hx_val[i]), hy[hx_ind[i] - idxBase]); } } else { hresult_gold = make_DataType(0); for(I i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(hx_val[i], hy[hx_ind[i] - idxBase]); } } // Verify results against host unit_check_general(1, 1, 1, &hresult_gold, &hresult); unit_check_general(1, 1, 1, &hresult_gold, &hresult_copied_from_device); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, &hresult, dataType, externalBuffer)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpVV(handle, trans, x, y, &hresult, dataType, externalBuffer)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(externalBuffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPVV_HPP ./clients/include/testing_spmv_coo_aos.hpp0000664000175100017510000003462715176134511021144 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMV_COO_AOS_HPP #define TESTING_SPMV_COO_AOS_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spmv_coo_aos_bad_arg(void) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION > 10010 && CUDART_VERSION < 12000) \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1 && CUDART_VERSION < 12000)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #endif #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dind = (int*)dind_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; size_t bsize; // Create SpMV structures verify_hipsparse_status_success( hipsparseCreateCooAoS(&A, m, n, nnz, dind, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, n, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpMV buffer verify_hipsparse_status_invalid_handle( hipsparseSpMV_bufferSize(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, nullptr, A, x, &beta, y, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, &beta, y, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMV verify_hipsparse_status_invalid_handle( hipsparseSpMV(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spmv_coo_aos(Arguments argus) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) I m = argus.M; I n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMVAlg_t alg = static_cast(argus.spmv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hind(2 * nnz); // Convert to COO (AoS) for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i] - idx_base; j < hrow_ptr[i + 1] - idx_base; ++j) { hind[2 * j] = i + idx_base; hind[2 * j + 1] = hcol_ind[j]; } } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * 2 * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dind = (I*)dind_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dind, hind.data(), sizeof(I) * 2 * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR(hipsparseCreateCooAoS(&A, m, n, nnz, dind, dval, typeI, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, n, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); // Query SpMV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMV_bufferSize( handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, d_alpha, A, x, d_beta, y2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Host SpMV #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < m; ++i) { hy_gold[i] = testing_mult(h_beta, hy_gold[i]); } for(I i = 0; i < nnz; ++i) { hy_gold[hind[2 * i] - idx_base] = testing_fma(testing_mult(h_alpha, hval[i]), hx[hind[2 * i + 1] - idx_base], hy_gold[hind[2 * i] - idx_base]); } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gbyte_count = coomv_gbyte_count(m, n, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::transA, transA, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMV_COO_AOS_HPP ./clients/include/testing_spsv_coo.hpp0000664000175100017510000003721315176134511020302 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSV_COO_HPP #define TESTING_SPSV_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsv_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSVAlg_t alg = HIPSPARSE_SPSV_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* drow = (int*)drow_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; hipsparseSpSVDescr_t descr; verify_hipsparse_status_success(hipsparseSpSV_createDescr(&descr), "success"); size_t bsize; // Create SpSV structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, m, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpSV buffer verify_hipsparse_status_invalid_handle( hipsparseSpSV_bufferSize(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, nullptr, A, x, y, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSV analysis verify_hipsparse_status_invalid_handle( hipsparseSpSV_analysis(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, nullptr, A, x, y, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, dbuf), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); #endif // SpSV solve verify_hipsparse_status_invalid_handle( hipsparseSpSV_solve(nullptr, transA, &alpha, A, x, y, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, nullptr, A, x, y, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, y, dataType, alg, nullptr), "Error: descr is nullptr"); #endif // Destruct verify_hipsparse_status_success(hipsparseSpSV_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spsv_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) I m = argus.M; I n = argus.N; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSVAlg_t alg = static_cast(argus.spsv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } std::vector hx(m); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, m); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSVDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, m, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_bufferSize( handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, d_alpha, A, x, y2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, d_alpha, A, x, y2, typeT, alg, descr)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); I struct_pivot = -1; I numeric_pivot = -1; host_coosv(transA, m, nnz, h_alpha, hrow_ind, hcol_ind, hval, hx, hy_gold, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = coosv_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSV_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSV_COO_HPP ./clients/include/testing_gtsv2_strided_batch.hpp0000664000175100017510000002500515176134511022367 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV2_NOPIVOT_STRIDED_BATCH_HPP #define TESTING_GTSV2_NOPIVOT_STRIDED_BATCH_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv2_strided_batch_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int m = 10; int batch_count = 10; int batch_stride = m; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsv2StridedBatch_bufferSize verify_hipsparse_status_invalid_handle(hipsparseXgtsv2StridedBatch_bufferSizeExt( nullptr, m, ddl, dd, ddu, dx, batch_count, batch_stride, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, -1, ddl, dd, ddu, dx, batch_count, batch_stride, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, -1, batch_stride, &bsize), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_value(hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, batch_count, -1, &bsize), "Error: batch_stride is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, nullptr), "Error: bsize is nullptr"); // gtsv2StridedBatch verify_hipsparse_status_invalid_handle( hipsparseXgtsv2StridedBatch(nullptr, m, ddl, dd, ddu, dx, batch_count, batch_stride, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch(handle, -1, ddl, dd, ddu, dx, batch_count, batch_stride, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch(handle, m, ddl, dd, ddu, dx, -1, batch_stride, dbuf), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2StridedBatch(handle, m, ddl, dd, ddu, dx, batch_count, -1, dbuf), "Error: batch_stride is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, (const T*)nullptr, dd, ddu, dx, batch_count, batch_stride, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, ddl, (const T*)nullptr, ddu, dx, batch_count, batch_stride, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, (const T*)nullptr, dx, batch_count, batch_stride, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, (T*)nullptr, batch_count, batch_stride, dbuf), "Error: dx is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2_strided_batch(Arguments argus) { int m = argus.M; int batch_count = argus.batch_count; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; int batch_stride = 2 * m; // Host structures std::vector hdl(batch_stride * batch_count, make_DataType(1)); std::vector hd(batch_stride * batch_count, make_DataType(2)); std::vector hdu(batch_stride * batch_count, make_DataType(1)); std::vector hx(batch_stride * batch_count, make_DataType(3)); for(int i = 0; i < batch_count; i++) { hdl[batch_stride * i + 0] = make_DataType(0); hdu[batch_stride * i + m - 1] = make_DataType(0); } std::vector hx_original = hx; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_stride * batch_count), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(ddl, hdl.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dd, hd.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(ddu, hdu.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dx, hx.data(), sizeof(T) * batch_stride * batch_count, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch_bufferSizeExt( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy( hx.data(), dx, sizeof(T) * batch_stride * batch_count, hipMemcpyDeviceToHost)); // Check std::vector hresult(batch_stride * batch_count, make_DataType(3)); for(int j = 0; j < batch_count; j++) { hresult[batch_stride * j] = testing_mult(hd[batch_stride * j + 0], hx[batch_stride * j]) + testing_mult(hdu[batch_stride * j + 0], hx[batch_stride * j + 1]); hresult[batch_stride * j + m - 1] = testing_mult(hdl[batch_stride * j + m - 1], hx[batch_stride * j + m - 2]) + testing_mult(hd[batch_stride * j + m - 1], hx[batch_stride * j + m - 1]); for(int i = 1; i < m - 1; i++) { hresult[batch_stride * j + i] = testing_mult(hdl[batch_stride * j + i], hx[batch_stride * j + i - 1]) + testing_mult(hd[batch_stride * j + i], hx[batch_stride * j + i]) + testing_mult(hdu[batch_stride * j + i], hx[batch_stride * j + i + 1]); } } unit_check_near(1, batch_stride * batch_count, 1, hx_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2StridedBatch( handle, m, ddl, dd, ddu, dx, batch_count, batch_stride, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_strided_batch_gbyte_count(m, batch_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::batch_count, batch_count, display_key_t::batch_stride, batch_stride, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_NOPIVOT_STRIDED_BATCH_HPP ./clients/include/testing_csrcolor.hpp0000664000175100017510000003173015176134511020273 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRCOLOR_HPP #define TESTING_CSRCOLOR_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrcolor_bad_arg(void) { #if(!defined(CUDART_VERSION)) static constexpr int M = 10; static constexpr int NNZ = 10; floating_data_t fractionToColor = make_DataType>(1.0); hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto m_coloring = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_reordering = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csr_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_csr_row_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csr_col_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_csr_val = (T*)m_csr_val.get(); int* d_coloring = (int*)m_coloring.get(); int* d_reordering = (int*)m_reordering.get(); int* d_csr_row_ptr = (int*)m_csr_row_ptr.get(); int* d_csr_col_ind = (int*)m_csr_col_ind.get(); int ncolors; hipsparseColorInfo_t colorInfo = (hipsparseColorInfo_t)0x4; status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, nullptr, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, nullptr, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, nullptr, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, d_csr_row_ptr, nullptr, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, d_csr_val, nullptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, descr, nullptr, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(handle, M, NNZ, nullptr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid pointer must be detected.u"); status = hipsparseXcsrcolor(nullptr, M, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_handle(status); status = hipsparseXcsrcolor(handle, -1, NNZ, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_value(status, "Error: an invalid value must be detected.u"); status = hipsparseXcsrcolor(handle, M, -1, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, &fractionToColor, &ncolors, d_coloring, d_reordering, colorInfo); verify_hipsparse_status_invalid_pointer(status, "Error: an invalid value must be detected.u"); #endif } template hipsparseStatus_t testing_csrcolor() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) // Determine absolute path of test matrix // Matrices are stored at the same path in matrices directory std::string filename = "nos3.bin"; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; // Initial Data on CPU srand(12345ULL); floating_data_t fractionToColor = make_DataType>(1.0); int m; int k; int nnz; if(!generate_csr_matrix(filename, m, k, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } hipsparseColorInfo_t colorInfo; hipsparseCreateColorInfo(&colorInfo); // allocate memory on device auto drow_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcoloring_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * m), device_free}; auto dreordering_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * m), device_free}; int* drow_ptr = (int*)drow_ptr_managed.get(); int* dcol_ind = (int*)dcol_ind_managed.get(); T* dval = (T*)dval_managed.get(); int* dcoloring = (int*)dcoloring_managed.get(); int* dreordering = (int*)dreordering_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drow_ptr, hrow_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol_ind, hcol_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); int ncolors; CHECK_HIPSPARSE_ERROR(hipsparseXcsrcolor(handle, m, nnz, descr, dval, drow_ptr, dcol_ind, &fractionToColor, &ncolors, dcoloring, dreordering, colorInfo)); hipsparseDestroyColorInfo(colorInfo); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRCOLOR_HPP ./clients/include/testing_hybmv.hpp0000664000175100017510000003411215176134511017567 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_HYBMV_HPP #define TESTING_HYBMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; #define ELL_IND_ROW(i, el, m, width) (el) * (m) + (i) #define ELL_IND_EL(i, el, m, width) (el) + (width) * (i) #define ELL_IND(i, el, m, width) ELL_IND_ROW(i, el, m, width) template void testing_hybmv_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; testhyb* dhyb = (testhyb*)hyb; dhyb->m = safe_size; dhyb->n = safe_size; dhyb->ell_nnz = safe_size; dhyb->coo_nnz = safe_size; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, (T*)nullptr, &beta, dy), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, &beta, (T*)nullptr), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, (T*)nullptr, descr, hyb, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, hyb, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, descr, (hipsparseHybMat_t) nullptr, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhybmv(handle, transA, &alpha, (hipsparseMatDescr_t) nullptr, hyb, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXhybmv((hipsparseHandle_t) nullptr, transA, &alpha, descr, hyb, dx, &beta, dy)); #endif } template hipsparseStatus_t testing_hybmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string filename = argus.filename; T zero = make_DataType(0.0); T one = make_DataType(1.0); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // ELL width limit int width_limit = (m > 0) ? ((2 * nnz - 1) / m + 1) : 0; // Limit ELL user width if(part == HIPSPARSE_HYB_PARTITION_USER) { user_ell_width = (m > 0) ? (user_ell_width * nnz / m) : 0; user_ell_width = std::min(width_limit, user_ell_width); } // Convert CSR to HYB hipsparseStatus_t status = hipsparseXcsr2hyb(handle, m, n, descr, dval, dptr, dcol, hyb, user_ell_width, part); if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Compute max ELL width int ell_max_width = 0; for(int i = 0; i < m; ++i) { ell_max_width = std::max(hcsr_row_ptr[i + 1] - hcsr_row_ptr[i], ell_max_width); } if(ell_max_width > width_limit) { verify_hipsparse_status_invalid_value(status, "ell_max_width > width_limit"); return HIPSPARSE_STATUS_SUCCESS; } } if(argus.unit_check) { // Copy HYB structure to CPU testhyb* dhyb = (testhyb*)hyb; int ell_nnz = dhyb->ell_nnz; int coo_nnz = dhyb->coo_nnz; std::vector hell_col(ell_nnz); std::vector hell_val(ell_nnz); std::vector hcoo_row(coo_nnz); std::vector hcoo_col(coo_nnz); std::vector hcoo_val(coo_nnz); if(ell_nnz > 0) { CHECK_HIP_ERROR(hipMemcpy( hell_col.data(), dhyb->ell_col_ind, sizeof(int) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hell_val.data(), dhyb->ell_val, sizeof(T) * ell_nnz, hipMemcpyDeviceToHost)); } if(coo_nnz > 0) { CHECK_HIP_ERROR(hipMemcpy( hcoo_row.data(), dhyb->coo_row_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_col.data(), dhyb->coo_col_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_val.data(), dhyb->coo_val, sizeof(T) * coo_nnz, hipMemcpyDeviceToHost)); } CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, d_alpha, descr, hyb, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // CPU // ELL part if(ell_nnz > 0) { for(int i = 0; i < m; ++i) { T sum = zero; for(int p = 0; p < dhyb->ell_width; ++p) { int idx = ELL_IND(i, p, m, dhyb->ell_width); int col = hell_col[idx] - idx_base; if(col >= 0 && col < n) { sum = sum + testing_mult(hell_val[idx], hx[col]); } else { break; } } if(h_beta != zero) { hy_gold[i] = testing_mult(h_beta, hy_gold[i]) + testing_mult(h_alpha, sum); } else { hy_gold[i] = testing_mult(h_alpha, sum); } } } // COO part if(coo_nnz >= 0) { T coo_beta = (ell_nnz > 0) ? one : h_beta; for(int i = 0; i < m; ++i) { hy_gold[i] = testing_mult(hy_gold[i], coo_beta); } for(int i = 0; i < coo_nnz; ++i) { int row = hcoo_row[i] - idx_base; int col = hcoo_col[i] - idx_base; hy_gold[row] = hy_gold[row] + testing_mult(h_alpha, testing_mult(hcoo_val[i], hx[col])); } } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhybmv(handle, transA, &h_alpha, descr, hyb, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::partition, hipsparse_partition2string(part), display_key_t::ell_width, user_ell_width, display_key_t::gflops, gpu_gflops, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYBMV_HPP ./clients/include/testing_sddmm_csc.hpp0000664000175100017510000005002615176134511020400 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_CSC_HPP #define TESTING_SDDMM_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCsc(&C, m, n, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_csc(Arguments argus) { // only csr format supported when using cusparse backend #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, n, m, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(nnz_A); std::vector hB(nnz_B); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (C_n + 1)), device_free}; auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dind = (J*)dind_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (C_n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dind, hcsc_row_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsc_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsc_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&C1, C_m, C_n, nnz, dptr, dind, dval1, typeI, typeJ, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&C2, C_m, C_n, nnz, dptr, dind, dval2, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(J c = 0; c < C_n; c++) { I start = hcsc_col_ptr[c] - idx_base; I end = hcsc_col_ptr[c + 1] - idx_base; for(I j = start; j < end; j++) { J r = hcsc_row_ind[j] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I s = 0; s < k; ++s) { sum = testing_fma(Aptr[incA * s], Bptr[incB * s], sum); } hcsc_val[j] = testing_mult(hcsc_val[j], h_beta) + testing_mult(h_alpha, sum); } } unit_check_near(1, nnz, 1, hval1.data(), hcsc_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsc_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_csc_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_CSC), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_CSC_HPP ./clients/include/testing_gather.hpp0000664000175100017510000001535615176134511017725 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GATHER_HPP #define TESTING_GATHER_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_gather_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Gather verify_hipsparse_status_invalid_handle(hipsparseGather(nullptr, y, x)); verify_hipsparse_status_invalid_pointer(hipsparseGather(handle, nullptr, x), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseGather(handle, y, nullptr), "Error: x is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_gather(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I size = argus.N; I nnz = argus.nnz; hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hy, 1, size); // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); if(argus.unit_check) { // Gather CHECK_HIPSPARSE_ERROR(hipsparseGather(handle, y, x)); // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < nnz; ++i) { hx_val_gold[i] = hy[hx_ind[i] - idxBase]; } // Verify results against host unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseGather(handle, y, x)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseGather(handle, y, x)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GATHER_HPP ./clients/include/testing_csru2csr.hpp0000664000175100017510000004027315176134511020215 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRU2CSR_HPP #define TESTING_CSRU2CSR_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csru2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csru2csr(new csru2csr_struct); csru2csrInfo_t info = unique_ptr_csru2csr->info; size_t bufferSize; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); float* csr_val = (float*)csr_val_managed.get(); void* buffer = (void*)buffer_managed.get(); // Testing csru2csr_bufferSizeExt for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking verify_hipsparse_status_invalid_handle(hipsparseXcsru2csr_bufferSizeExt( nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize)); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, (float*)nullptr, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, nullptr, csr_col_ind, info, &bufferSize), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, nullptr, info, &bufferSize), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, nullptr, &bufferSize), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: bufferSize is nullptr"); #endif verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, -1, n, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, m, -1, nnz, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, m, n, -1, csr_val, csr_row_ptr, csr_col_ind, info, &bufferSize), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, 0, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsru2csr_bufferSizeExt( handle, m, 0, 0, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, nnz, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr_bufferSizeExt( handle, 0, n, 0, (float*)nullptr, nullptr, nullptr, nullptr, nullptr), "Error: bufferSize is invalid"); #endif // Testing csru2csr for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_invalid_handle(hipsparseXcsru2csr( nullptr, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr, buffer), "Error: info is nullptr"); #endif verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, (float*)nullptr, csr_row_ptr, csr_col_ind, info, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr(handle, m, n, nnz, descr, csr_val, nullptr, csr_col_ind, info, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr(handle, m, n, nnz, descr, csr_val, csr_row_ptr, nullptr, info, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsru2csr( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, -1, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, m, -1, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, m, n, -1, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsru2csr( handle, 0, n, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsru2csr( handle, m, 0, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsru2csr( handle, 0, n, nnz, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); #endif // Testing csr2csru for bad args #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_invalid_handle(hipsparseXcsr2csru( nullptr, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr, buffer), "Error: info is nullptr"); #endif verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, (float*)nullptr, csr_row_ptr, csr_col_ind, info, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru(handle, m, n, nnz, descr, csr_val, nullptr, csr_col_ind, info, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru(handle, m, n, nnz, descr, csr_val, csr_row_ptr, nullptr, info, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2csru( handle, m, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, -1, n, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, m, -1, nnz, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, m, n, -1, descr, csr_val, csr_row_ptr, csr_col_ind, info, buffer), "Error: nnz is invalid"); #ifndef __HIP_PLATFORM_NVIDIA__ // cusparse seem to not have any error checking for some parts verify_hipsparse_status_success( hipsparseXcsr2csru( handle, 0, n, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_success( hipsparseXcsr2csru( handle, m, 0, 0, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Success"); verify_hipsparse_status_invalid_size( hipsparseXcsr2csru( handle, 0, n, nnz, nullptr, (float*)nullptr, nullptr, nullptr, nullptr, &bufferSize), "Error: nnz is invalid"); #endif #endif } template hipsparseStatus_t testing_csru2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; hipsparseSetMatIndexBase(descr, idx_base); std::unique_ptr unique_ptr_info(new csru2csr_struct); csru2csrInfo_t info = unique_ptr_info->info; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind_gold, hcsr_val_gold, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort CSR columns std::vector hperm(nnz); std::vector hcsr_col_ind_unsorted_gold(nnz); std::vector hcsr_val_unsorted_gold(nnz); hcsr_col_ind_unsorted_gold = hcsr_col_ind_gold; hcsr_val_unsorted_gold = hcsr_val_gold; for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; int row_nnz = row_end - row_begin; for(int j = row_begin; j < row_end; ++j) { int rng = row_begin + rand() % row_nnz; int temp_col = hcsr_col_ind_unsorted_gold[j] - idx_base; T temp_val = hcsr_val_unsorted_gold[j]; hcsr_col_ind_unsorted_gold[j] = hcsr_col_ind_unsorted_gold[rng]; hcsr_val_unsorted_gold[j] = hcsr_val_unsorted_gold[rng]; hcsr_col_ind_unsorted_gold[rng] = temp_col + idx_base; hcsr_val_unsorted_gold[rng] = temp_val; } } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_unsorted_gold.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_unsorted_gold.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXcsru2csr_bufferSizeExt( handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, &buffer_size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * buffer_size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { // Sort CSR columns CHECK_HIPSPARSE_ERROR(hipsparseXcsru2csr( handle, m, n, nnz, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, dbuffer)); // Copy output from device to host std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unsort CSR columns back to original state CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csru( handle, m, n, nnz, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, info, dbuffer)); // Copy output from device to host std::vector hcsr_col_ind_unsorted(nnz); std::vector hcsr_val_unsorted(nnz); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_unsorted.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_unsorted.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, nnz, 1, hcsr_col_ind.data(), hcsr_col_ind_gold.data()); unit_check_general(1, nnz, 1, hcsr_val.data(), hcsr_val_gold.data()); unit_check_general( 1, nnz, 1, hcsr_col_ind_unsorted.data(), hcsr_col_ind_unsorted_gold.data()); unit_check_general(1, nnz, 1, hcsr_val_unsorted.data(), hcsr_val_unsorted_gold.data()); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRU2CSR_HPP ./clients/include/testing_spmm_batched_csr.hpp0000664000175100017510000005267615176134511021756 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BATCHED_CSR_HPP #define TESTING_SPMM_BATCHED_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_batched_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; float alpha = 0.6; float beta = 0.2; size_t safe_size = 100; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, k, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); int batch_count_A; int batch_count_B; int batch_count_C; int64_t offsets_batch_stride_A; int64_t columns_values_batch_stride_A; int64_t batch_stride_B; int64_t batch_stride_C; // C_i = A * B_i batch_count_A = 1; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = 0; columns_values_batch_stride_A = 0; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B batch_count_A = 10; batch_count_B = 1; batch_count_C = 5; offsets_batch_stride_A = (m + 1); columns_values_batch_stride_A = nnz; batch_stride_B = 0; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B_i batch_count_A = 10; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = (m + 1); columns_values_batch_stride_A = nnz; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_batched_csr(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; J batch_count_A = 1; J batch_count_B = 3; J batch_count_C = 3; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr_temp; std::vector hcsr_col_ind_temp; std::vector hcsr_val_temp; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hcsr_row_ptr_temp, hcsr_col_ind_temp, hcsr_val_temp, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; int64_t offsets_batch_stride_A = (batch_count_A > 1) ? (A_m + 1) : 0; int64_t columns_values_batch_stride_A = (batch_count_A > 1) ? nnz_A : 0; int64_t batch_stride_B = (batch_count_B > 1) ? nnz_B : 0; int64_t batch_stride_C = (batch_count_C > 1) ? nnz_C : 0; // Allocate host memory for all batches of A matrix std::vector hcsr_row_ptr(batch_count_A * (A_m + 1)); std::vector hcsr_col_ind(batch_count_A * nnz_A); std::vector hcsr_val(batch_count_A * nnz_A); for(J i = 0; i < batch_count_A; i++) { for(J j = 0; j < (A_m + 1); j++) { hcsr_row_ptr[(A_m + 1) * i + j] = hcsr_row_ptr_temp[j]; } for(I j = 0; j < nnz_A; j++) { hcsr_col_ind[nnz_A * i + j] = hcsr_col_ind_temp[j]; hcsr_val[nnz_A * i + j] = hcsr_val_temp[j]; } } std::vector hB(batch_count_B * nnz_B); std::vector hC_1(batch_count_C * nnz_C); std::vector hC_2(batch_count_C * nnz_C); std::vector hC_gold(batch_count_C * nnz_C); hipsparseInit(hB, batch_count_B * nnz_B, 1); hipsparseInit(hC_1, batch_count_C * nnz_C, 1); // copy vector is easy in STL; hC_gold = hC: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_B * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (A_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dB, hB.data(), sizeof(T) * batch_count_B * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, A_m, A_n, nnz_A, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, columns_values_batch_stride_A)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C1, batch_count_C, batch_stride_C)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C2, batch_count_C, batch_stride_C)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hC_1.data(), dC_1, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); // CPU host_csrmm_batched(A_m, n, A_n, batch_count_A, (I)offsets_batch_stride_A, (I)columns_values_batch_stride_A, transA, transB, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hB.data(), (J)ldb, batch_count_B, (I)batch_stride_B, orderB, h_beta, hC_gold.data(), (J)ldc, batch_count_C, (I)batch_stride_C, orderC, idx_base, false); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = batch_count_C * spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrmm_batched_gbyte_count(A_m, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, batch_count_A, batch_count_B, batch_count_C, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::batch_countA, batch_count_A, display_key_t::batch_countB, batch_count_B, display_key_t::batch_countC, batch_count_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BATCHED_CSR_HPP ./clients/include/hipsparse_parse_data.hpp0000664000175100017510000000300615176134305021065 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_PARSE_DATA_HPP #define HIPSPARSE_PARSE_DATA_HPP #include bool hipsparse_parse_data(int& argc, char** argv, const std::string& default_file = ""); #endif // HIPSPARSE_PARSE_DATA_HPP./clients/include/hipsparse_datatype2string.hpp0000664000175100017510000003625215176134511022116 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2019-2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include #include constexpr auto hipsparse_indextype2string(hipsparseIndexType_t type) { switch(type) { case HIPSPARSE_INDEX_16U: return "u16"; case HIPSPARSE_INDEX_32I: return "i32"; case HIPSPARSE_INDEX_64I: return "i64"; } return "invalid"; } constexpr auto hipsparse_datatype2string(hipDataType type) { switch(type) { case HIP_R_32F: return "f32_r"; case HIP_R_64F: return "f64_r"; case HIP_C_32F: return "f32_c"; case HIP_C_64F: return "f64_c"; default: return "invalid"; } } constexpr auto hipsparse_indexbase2string(hipsparseIndexBase_t base) { switch(base) { case HIPSPARSE_INDEX_BASE_ZERO: return "0b"; case HIPSPARSE_INDEX_BASE_ONE: return "1b"; } return "invalid"; } constexpr auto hipsparse_operation2string(hipsparseOperation_t trans) { switch(trans) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: return "NT"; case HIPSPARSE_OPERATION_TRANSPOSE: return "T"; case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: return "CT"; } return "invalid"; } constexpr auto hipsparse_direction2string(hipsparseDirection_t direction) { switch(direction) { case HIPSPARSE_DIRECTION_ROW: return "row"; case HIPSPARSE_DIRECTION_COLUMN: return "column"; } return "invalid"; } #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_ROW: return "row"; case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #else #if(CUDART_VERSION >= 11000) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_ROW: return "row"; case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #elif(CUDART_VERSION >= 10010) constexpr auto hipsparse_order2string(hipsparseOrder_t order) { switch(order) { case HIPSPARSE_ORDER_COL: return "col"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; case HIPSPARSE_FORMAT_CSC: return "csc"; case HIPSPARSE_FORMAT_BLOCKED_ELL: return "bell"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) constexpr auto hipsparse_format2string(hipsparseFormat_t format) { switch(format) { case HIPSPARSE_FORMAT_COO: return "coo"; case HIPSPARSE_FORMAT_COO_AOS: return "coo_aos"; case HIPSPARSE_FORMAT_CSR: return "csr"; } return "invalid"; } #endif #endif constexpr auto hipsparse_action2string(hipsparseAction_t action) { switch(action) { case HIPSPARSE_ACTION_SYMBOLIC: return "sym"; case HIPSPARSE_ACTION_NUMERIC: return "num"; } return "invalid"; } constexpr auto hipsparse_partition2string(hipsparseHybPartition_t part) { switch(part) { case HIPSPARSE_HYB_PARTITION_AUTO: return "auto"; case HIPSPARSE_HYB_PARTITION_USER: return "user"; case HIPSPARSE_HYB_PARTITION_MAX: return "max"; } return "invalid"; } constexpr auto hipsparse_diagtype2string(hipsparseDiagType_t diag_type) { switch(diag_type) { case HIPSPARSE_DIAG_TYPE_NON_UNIT: return "ND"; case HIPSPARSE_DIAG_TYPE_UNIT: return "UD"; } return "invalid"; } constexpr auto hipsparse_fillmode2string(hipsparseFillMode_t fill_mode) { switch(fill_mode) { case HIPSPARSE_FILL_MODE_LOWER: return "L"; case HIPSPARSE_FILL_MODE_UPPER: return "U"; } return "invalid"; } constexpr auto hipsparse_solvepolicy2string(hipsparseSolvePolicy_t policy) { switch(policy) { case HIPSPARSE_SOLVE_POLICY_NO_LEVEL: return "no_level"; case HIPSPARSE_SOLVE_POLICY_USE_LEVEL: return "use_level"; } return "invalid"; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) constexpr auto hipsparse_sddmmalg2string(hipsparseSDDMMAlg_t alg) { switch(alg) { case HIPSPARSE_SDDMM_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spgemmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return "deterministic"; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return "nondeterministic"; case HIPSPARSE_SPGEMM_ALG1: return "alg1"; case HIPSPARSE_SPGEMM_ALG2: return "alg2"; case HIPSPARSE_SPGEMM_ALG3: return "alg3"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spgemmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return "deterministic"; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return "nondeterministic"; case HIPSPARSE_SPGEMM_ALG1: return "alg1"; case HIPSPARSE_SPGEMM_ALG2: return "alg2"; case HIPSPARSE_SPGEMM_ALG3: return "alg3"; } return "invalid"; } #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; case HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: return "deterministic"; case HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: return "nondeterministic"; } return "invalid"; } #elif(CUDART_VERSION >= 11000) constexpr auto hipsparse_spmmalg2string(hipsparseSpGEMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPGEMM_DEFAULT: return "default"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_CSR_ALG3: return "csr_alg3"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_SPMM_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMM_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMM_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMM_COO_ALG3: return "coo_alg3"; case HIPSPARSE_SPMM_COO_ALG4: return "coo_alg4"; case HIPSPARSE_SPMM_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMM_CSR_ALG2: return "csr_alg2"; case HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: return "bell_alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) constexpr auto hipsparse_spmmalg2string(hipsparseSpMMAlg_t alg) { switch(alg) { case HIPSPARSE_MM_ALG_DEFAULT: return "default"; case HIPSPARSE_COOMM_ALG1: return "coo_alg1"; case HIPSPARSE_COOMM_ALG2: return "coo_alg2"; case HIPSPARSE_COOMM_ALG3: return "coo_alg3"; case HIPSPARSE_CSRMM_ALG1: return "csr_alg1"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_SPMV_ALG_DEFAULT: return "default"; case HIPSPARSE_SPMV_COO_ALG1: return "coo_alg1"; case HIPSPARSE_SPMV_COO_ALG2: return "coo_alg2"; case HIPSPARSE_SPMV_CSR_ALG1: return "csr_alg1"; case HIPSPARSE_SPMV_CSR_ALG2: return "csr_alg2"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) constexpr auto hipsparse_spmvalg2string(hipsparseSpMVAlg_t alg) { switch(alg) { case HIPSPARSE_MV_ALG_DEFAULT: return "default"; case HIPSPARSE_COOMV_ALG: return "coo_alg1"; case HIPSPARSE_CSRMV_ALG1: return "csr_alg1"; case HIPSPARSE_CSRMV_ALG2: return "csr_alg2"; } return "invalid"; } #endif #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) constexpr auto hipsparse_spsmalg2string(hipsparseSpSMAlg_t alg) { switch(alg) { case HIPSPARSE_SPSM_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) constexpr auto hipsparse_spsvalg2string(hipsparseSpSVAlg_t alg) { switch(alg) { case HIPSPARSE_SPSV_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) constexpr auto hipsparse_sparsetodensealg2string(hipsparseSparseToDenseAlg_t alg) { switch(alg) { case HIPSPARSE_SPARSETODENSE_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) constexpr auto hipsparse_densetosparsealg2string(hipsparseDenseToSparseAlg_t alg) { switch(alg) { case HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT: return "default"; } return "invalid"; } #endif #if(!defined(CUDART_VERSION)) constexpr auto hipsparse_csr2cscalg2string(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG_DEFAULT: return "default"; case HIPSPARSE_CSR2CSC_ALG1: return "alg1"; case HIPSPARSE_CSR2CSC_ALG2: return "alg2"; } return "invalid"; } #else #if(CUDART_VERSION >= 12000) constexpr auto hipsparse_csr2cscalg2string(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG_DEFAULT: return "default"; case HIPSPARSE_CSR2CSC_ALG1: return "alg1"; } return "invalid"; } #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) constexpr auto hipsparse_csr2cscalg2string(hipsparseCsr2CscAlg_t alg) { switch(alg) { case HIPSPARSE_CSR2CSC_ALG1: return "alg1"; case HIPSPARSE_CSR2CSC_ALG2: return "alg2"; } return "invalid"; } #endif #endif ./clients/include/hipsparse.hpp0000664000175100017510000031721515176134305016714 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef _HIPSPARSE_HPP_ #define _HIPSPARSE_HPP_ #include namespace hipsparse { template struct floating_traits { using data_t = T; }; template <> struct floating_traits { using data_t = float; }; template <> struct floating_traits { using data_t = double; }; template using floating_data_t = typename floating_traits::data_t; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXaxpyi(hipsparseHandle_t handle, int nnz, const T* alpha, const T* x_val, const int* x_ind, T* y, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXdoti(hipsparseHandle_t handle, int nnz, const T* x_val, const int* x_ind, const T* y, T* result, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXdotci(hipsparseHandle_t handle, int nnz, const T* x_val, const int* x_ind, const T* y, T* result, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgthr(hipsparseHandle_t handle, int nnz, const T* y, T* x_val, const int* x_ind, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgthrz(hipsparseHandle_t handle, int nnz, T* y, T* x_val, const int* x_ind, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXroti(hipsparseHandle_t handle, int nnz, T* x_val, const int* x_ind, T* y, const T* c, const T* s, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXsctr(hipsparseHandle_t handle, int nnz, const T* x_val, const int* x_ind, T* y, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrmv(hipsparseHandle_t handle, hipsparseOperation_t trans, int m, int n, int nnz, const T* alpha, const hipsparseMatDescr_t descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const T* x, const T* beta, T* y); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXcsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsv2_analysis(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsv2_solve(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrsv2Info_t info, const T* f, T* x, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXhybmv(hipsparseHandle_t handle, hipsparseOperation_t trans, const T* alpha, const hipsparseMatDescr_t descr, const hipsparseHybMat_t hyb, const T* x, const T* beta, T* y); #endif template hipsparseStatus_t hipsparseXbsrmv(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, int mb, int nb, int nnzb, const T* alpha, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, const T* x, const T* beta, T* y); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrxmv(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t trans, int sizeOfMask, int mb, int nb, int nnzb, const T* alpha, const hipsparseMatDescr_t descr, const T* bsrVal, const int* bsrMaskPtr, const int* bsrRowPtr, const int* bsrEndPtr, const int* bsrColInd, int blockDim, const T* x, const T* beta, T* y); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsv2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXbsrsv2_bufferSizeExt(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsv2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsv2_solve(hipsparseHandle_t handle, hipsparseDirection_t dir, hipsparseOperation_t transA, int mb, int nnzb, const T* alpha, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsv2Info_t info, const T* f, T* x, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgemvi_bufferSize(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, int nnz, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgemvi(hipsparseHandle_t handle, hipsparseOperation_t transA, int m, int n, const T* alpha, const T* A, int lda, int nnz, const T* x, const int* xInd, const T* beta, T* y, hipsparseIndexBase_t idxBase, void* pBuffer); #endif template hipsparseStatus_t hipsparseXbsrmm(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transB, int mb, int n, int kb, int nnzb, const T* alpha, const hipsparseMatDescr_t descr, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const T* B, int ldb, const T* beta, T* C, int ldc); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrmm2(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, int nnz, const T* alpha, const hipsparseMatDescr_t descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const T* B, int ldb, const T* beta, T* C, int ldc); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsm2_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsm2_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrsm2_solve(hipsparseHandle_t handle, hipsparseDirection_t dirA, hipsparseOperation_t transA, hipsparseOperation_t transX, int mb, int nrhs, int nnzb, const T* alpha, const hipsparseMatDescr_t descrA, const T* bsrSortedValA, const int* bsrSortedRowPtrA, const int* bsrSortedColIndA, int blockDim, bsrsm2Info_t info, const T* B, int ldb, T* X, int ldx, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsm2_bufferSizeExt(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const T* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, size_t* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsm2_analysis(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, const T* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrsm2_solve(hipsparseHandle_t handle, int algo, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int nrhs, int nnz, const T* alpha, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, T* B, int ldb, csrsm2Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXgemmi(hipsparseHandle_t handle, int m, int n, int k, int nnz, const T* alpha, const T* A, int lda, const T* cscValB, const int* cscColPtrB, const int* cscRowIndB, const T* beta, T* C, int ldc); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrgeam(hipsparseHandle_t handle, int m, int n, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* beta, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC); #endif template hipsparseStatus_t hipsparseXcsrgeam2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* beta, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXcsrgeam2(hipsparseHandle_t handle, int m, int n, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* beta, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC, void* pBuffer); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsrgemm(hipsparseHandle_t handle, hipsparseOperation_t transA, hipsparseOperation_t transB, int m, int n, int k, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrgemm2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int k, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const int* csrRowPtrB, const int* csrColIndB, const T* beta, const hipsparseMatDescr_t descrD, int nnzD, const int* csrRowPtrD, const int* csrColIndD, csrgemm2Info_t info, size_t* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsrgemm2(hipsparseHandle_t handle, int m, int n, int k, const T* alpha, const hipsparseMatDescr_t descrA, int nnzA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const hipsparseMatDescr_t descrB, int nnzB, const T* csrValB, const int* csrRowPtrB, const int* csrColIndB, const T* beta, const hipsparseMatDescr_t descrD, int nnzD, const T* csrValD, const int* csrRowPtrD, const int* csrColIndD, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC, const csrgemm2Info_t info, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02_numericBoost( hipsparseHandle_t handle, bsrilu02Info_t info, int enable_boost, double* tol, T* boost_val); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsrilu02Info_t info, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsrilu02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02_numericBoost( hipsparseHandle_t handle, csrilu02Info_t info, int enable_boost, double* tol, T* boost_val); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXcsrilu02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrilu02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csrilu02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsric02_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsric02Info_t info, int* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsric02_analysis(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXbsric02(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nnzb, const hipsparseMatDescr_t descrA, T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int block_dim, bsric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsric02_bufferSize(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, int* pBufferSizeInBytes); #endif template hipsparseStatus_t hipsparseXcsric02_bufferSizeExt(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, size_t* pBufferSizeInBytes); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsric02_analysis(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrSortedValA, const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsric02(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, T* csrSortedValA_valM, /* matrix A values are updated inplace to be the preconditioner M values */ const int* csrSortedRowPtrA, const int* csrSortedColIndA, csric02Info_t info, hipsparseSolvePolicy_t policy, void* pBuffer); #endif template hipsparseStatus_t hipsparseXnnz(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const T* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXnnz_compress(hipsparseHandle_t handle, int m, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, int* nnzPerRow, int* nnzC, T tol); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXdense2csr(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* A, int ld, const int* nnzPerRow, T* csrVal, int* csrRowPtr, int* csrColInd); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csr_bufferSize(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrNnz(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csr(hipsparseHandle_t handle, int m, int n, const T* A, int lda, const T* threshold, const hipsparseMatDescr_t descr, T* csrVal, const int* csrRowPtr, int* csrColInd, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, int* csrRowPtr, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneDense2csrByPercentage(hipsparseHandle_t handle, int m, int n, const T* A, int lda, T percentage, const hipsparseMatDescr_t descr, T* csrVal, const int* csrRowPtr, int* csrColInd, pruneInfo_t info, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXdense2csc(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* A, int ld, const int* nnzPerColumn, T* cscVal, int* cscRowInd, int* cscColPtr); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsr2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* csrVal, const int* csrRowPtr, const int* csrColInd, T* A, int ld); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) template hipsparseStatus_t hipsparseXcsc2dense(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* cscVal, const int* cscRowInd, const int* cscColPtr, T* A, int ld); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsr2csc(hipsparseHandle_t handle, int m, int n, int nnz, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, T* csc_val, int* csc_row_ind, int* csc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXcsr2hyb(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, hipsparseHybMat_t hyb, int user_ell_width, hipsparseHybPartition_t partition_type); #endif template hipsparseStatus_t hipsparseXgebsr2gebsc_bufferSize(hipsparseHandle_t handle, int mb, int nb, int nnzb, const T* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, size_t* p_buffer_size); template hipsparseStatus_t hipsparseXgebsr2gebsc(hipsparseHandle_t handle, int mb, int nb, int nnzb, const T* bsr_val, const int* bsr_row_ptr, const int* bsr_col_ind, int row_block_dim, int col_block_dim, T* bsc_val, int* bsc_row_ind, int* bsc_col_ptr, hipsparseAction_t copy_values, hipsparseIndexBase_t idx_base, void* temp_buffer); template hipsparseStatus_t hipsparseXcsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, int row_block_dim, int col_block_dim, size_t* p_buffer_size); template hipsparseStatus_t hipsparseXcsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dir, int m, int n, const hipsparseMatDescr_t csr_descr, const T* csr_val, const int* csr_row_ptr, const int* csr_col_ind, const hipsparseMatDescr_t bsr_descr, T* bsr_val, int* bsr_row_ptr, int* bsr_col_ind, int row_block_dim, int col_block_dim, void* p_buffer); template hipsparseStatus_t hipsparseXcsr2bsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, int blockDim, const hipsparseMatDescr_t descrC, T* bsrValC, int* bsrRowPtrC, int* bsrColIndC); template hipsparseStatus_t hipsparseXbsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int blockDim, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC); template hipsparseStatus_t hipsparseXgebsr2csr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDim, int colBlockDim, const hipsparseMatDescr_t descrC, T* csrValC, int* csrRowPtrC, int* csrColIndC); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) template hipsparseStatus_t hipsparseXhyb2csr(hipsparseHandle_t handle, const hipsparseMatDescr_t descrA, const hipsparseHybMat_t hybA, T* csr_val, int* csr_row_ptr, int* csr_col_ind); #endif template hipsparseStatus_t hipsparseXcsr2csr_compress(hipsparseHandle_t handle, int m, int n, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrColIndA, const int* csrRowPtrA, int nnzA, const int* nnzPerRow, T* csrValC, int* csrColIndC, int* csrRowPtrC, T tol); template hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* bufferSize); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrNnz(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csr(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const T* threshold, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSize(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, const T* csrValC, const int* csrRowPtrC, const int* csrColIndC, pruneInfo_t info, size_t* bufferSize); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrNnzByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, int* csrRowPtrC, int* nnzTotalDevHostPtr, pruneInfo_t info, void* buffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXpruneCsr2csrByPercentage(hipsparseHandle_t handle, int m, int n, int nnzA, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, T percentage, const hipsparseMatDescr_t descrC, T* csrValC, const int* csrRowPtrC, int* csrColIndC, pruneInfo_t info, void* buffer); #endif template hipsparseStatus_t hipsparseXgebsr2gebsr_bufferSize(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, int rowBlockDimC, int colBlockDimC, int* bufferSize); template hipsparseStatus_t hipsparseXgebsr2gebsr(hipsparseHandle_t handle, hipsparseDirection_t dirA, int mb, int nb, int nnzb, const hipsparseMatDescr_t descrA, const T* bsrValA, const int* bsrRowPtrA, const int* bsrColIndA, int rowBlockDimA, int colBlockDimA, const hipsparseMatDescr_t descrC, T* bsrValC, int* bsrRowPtrC, int* bsrColIndC, int rowBlockDimC, int colBlockDimC, void* buffer); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsru2csr_bufferSizeExt(hipsparseHandle_t handle, int m, int n, int nnz, T* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, size_t* pBufferSizeInBytes); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsru2csr(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, T* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); #endif #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsr2csru(hipsparseHandle_t handle, int m, int n, int nnz, const hipsparseMatDescr_t descrA, T* csrVal, const int* csrRowPtr, int* csrColInd, csru2csrInfo_t info, void* pBuffer); #endif template hipsparseStatus_t hipsparseXgpsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const T* ds, const T* dl, const T* d, const T* du, const T* dw, const T* x, int batchCount, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgpsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, T* ds, T* dl, T* d, T* du, T* dw, T* x, int batchCount, void* pBuffer); template hipsparseStatus_t hipsparseXgtsv2StridedBatch_bufferSizeExt(hipsparseHandle_t handle, int m, const T* dl, const T* d, const T* du, const T* x, int batchCount, int batchStride, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsv2StridedBatch(hipsparseHandle_t handle, int m, const T* dl, const T* d, const T* du, T* x, int batchCount, int batchStride, void* pBuffer); template hipsparseStatus_t hipsparseXgtsv2_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, const T* B, int ldb, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsv2(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, T* B, int ldb, void* pBuffer); template hipsparseStatus_t hipsparseXgtsv2_nopivot_bufferSizeExt(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, const T* B, int ldb, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsv2_nopivot(hipsparseHandle_t handle, int m, int n, const T* dl, const T* d, const T* du, T* B, int ldb, void* pBuffer); template hipsparseStatus_t hipsparseXgtsvInterleavedBatch_bufferSizeExt(hipsparseHandle_t handle, int algo, int m, const T* dl, const T* d, const T* du, const T* x, int batchCount, size_t* pBufferSizeInBytes); template hipsparseStatus_t hipsparseXgtsvInterleavedBatch(hipsparseHandle_t handle, int algo, int m, T* dl, T* d, T* du, T* x, int batchCount, void* pBuffer); #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) template hipsparseStatus_t hipsparseXcsrcolor(hipsparseHandle_t handle, int m, int nnz, const hipsparseMatDescr_t descrA, const T* csrValA, const int* csrRowPtrA, const int* csrColIndA, const floating_data_t* fractionToColor, int* ncolors, int* coloring, int* reordering, hipsparseColorInfo_t info); #endif } // namespace hipsparse #endif // _HIPSPARSE_HPP_ ./clients/include/hipsparse_data.hpp0000664000175100017510000001131715176134305017677 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_DATA_HPP #define HIPSPARSE_DATA_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_cleanup.hpp" #include #include #include #include #include #include // Class used to read Arguments data into the tests class HipSPARSE_TestData { // data filename static auto& filename() { static std::string filename = "(Uninitialized data. HipSPARSE_TestData::set_filename needs to be called first.)"; return filename; } // filter iterator class iterator : public std::istream_iterator { bool (*const filter)(const Arguments&) = nullptr; // Skip entries for which filter is false void skip_filter() { if(filter) while(*this != std::istream_iterator{} && !filter(**this)) ++*static_cast*>(this); } public: // Constructor takes a filter and iterator explicit iterator(bool filter_(const Arguments&), std::istream_iterator iter) : std::istream_iterator(iter) , filter(filter_) { skip_filter(); } // Default end iterator and nullptr filter iterator() = default; // Preincrement iterator operator with filtering iterator& operator++() { ++*static_cast*>(this); skip_filter(); return *this; } // We do not need a postincrement iterator operator // We delete it here so that the base class's isn't silently called // To implement it, use "auto old = *this; ++*this; return old;" iterator operator++(int) = delete; }; public: // Initialize filename, optionally removing it at exit static void set_filename(std::string name, bool remove_atexit = false) { filename() = std::move(name); if(remove_atexit) { auto cleanup = [] { remove(filename().c_str()); }; atexit(cleanup); auto err = at_quick_exit(cleanup); if(err) { } } } // begin() iterator which accepts an optional filter. static iterator begin(bool filter(const Arguments&) = nullptr) { static std::ifstream* ifs; // If this is the first time, or after test_cleanup::cleanup() has been called if(!ifs) { // Allocate a std::ifstream and register it to be deleted during cleanup ifs = test_cleanup::allocate(&ifs, filename(), std::ifstream::binary); if(!ifs || ifs->fail()) { std::cerr << "Cannot open " << filename() << ": " << strerror(errno) << std::endl; exit(EXIT_FAILURE); } } // We re-seek the file back to position 0 ifs->clear(); ifs->seekg(0); // Validate the data file format Arguments::validate(*ifs); // We create a filter iterator which will choose only the test cases we want right now. // This is to preserve Gtest structure while not creating no-op tests which "always pass". return iterator(filter, std::istream_iterator(*ifs)); } // end() iterator static iterator end() { return {}; } }; #endif // HIPSPARSE_DATA_HPP./clients/include/testing_dense2csx.hpp0000664000175100017510000003746315176134511020354 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE2CSX_HPP #define TESTING_DENSE2CSX_HPP #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; #include template void testing_dense2csx_bad_arg(FUNC& dense2csx) { #if(!defined(CUDART_VERSION)) static constexpr int M = 1; static constexpr int N = 1; static constexpr int LD = M; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_nnzPerRowColumn = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (1 + 1)), device_free}; auto m_csx_row_col_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_dense_val = (T*)m_dense_val.get(); T* d_csx_val = (T*)m_csx_val.get(); int* d_nnzPerRowColumn = (int*)m_nnzPerRowColumn.get(); int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); int* d_csx_col_row_ind = (int*)m_csx_row_col_ind.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(d_csx_row_col_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(dense2csx( nullptr, 0, 0, nullptr, (const T*)nullptr, 0, nullptr, (T*)nullptr, nullptr, nullptr)); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, nullptr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, nullptr, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, nullptr, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, nullptr, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, nullptr, d_csx_col_row_ind), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, nullptr), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_size(dense2csx(handle, -1, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: An invalid size must be detected."); verify_hipsparse_status_invalid_size(dense2csx(handle, M, -1, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: An invalid size must be detected."); verify_hipsparse_status_invalid_size(dense2csx(handle, M, N, descr, d_dense_val, M - 1, d_nnzPerRowColumn, d_csx_val, d_csx_row_col_ptr, d_csx_col_row_ind), "Error: An invalid size must be detected."); #endif } template hipsparseStatus_t testing_dense2csx(const Arguments& argus, FUNC& dense2csx) { int M = argus.M; int N = argus.N; int LD = argus.lda; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } int DIMDIR = (HIPSPARSE_DIRECTION_ROW == DIRA) ? M : N; std::vector h_dense_val(LD * N); std::vector h_nnzPerRowColumn(DIMDIR); // Create the dense matrix. auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * LD * N), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * DIMDIR), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_dense_val = (T*)m_dense_val.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LD; ++i) { for(int j = 0; j < N; ++j) { h_dense_val[j * LD + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_dense_val.data(), LD, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR( hipMemcpy(d_dense_val, h_dense_val.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); int nnz; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXnnz(handle, DIRA, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, &nnz)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( h_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * DIMDIR, hipMemcpyDeviceToHost)); auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (DIMDIR + 1)), device_free}; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto m_csx_col_row_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); int* d_csx_col_row_ind = (int*)m_csx_col_row_ind.get(); T* d_csx_val = (T*)m_csx_val.get(); std::vector cpu_csx_row_col_ptr(DIMDIR + 1); std::vector cpu_csx_val(nnz); std::vector cpu_csx_col_row_ind(nnz); if(argus.unit_check) { // Compute the reference host first. host_dense2csx(M, N, hipsparseGetMatIndexBase(descr), h_dense_val.data(), LD, h_nnzPerRowColumn.data(), cpu_csx_val.data(), cpu_csx_row_col_ptr.data(), cpu_csx_col_row_ind.data()); CHECK_HIPSPARSE_ERROR( dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); void* buffer = malloc(std::max(sizeof(T), sizeof(int)) * std::max(DIMDIR + 1, nnz)); // Transfer and check results. CHECK_HIP_ERROR(hipMemcpy(buffer, d_csx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); unit_check_general(1, nnz, 1, cpu_csx_val.data(), (T*)buffer); CHECK_HIP_ERROR( hipMemcpy(buffer, d_csx_col_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); unit_check_general(1, nnz, 1, cpu_csx_col_row_ind.data(), (int*)buffer); CHECK_HIP_ERROR(hipMemcpy( buffer, d_csx_row_col_ptr, sizeof(int) * (DIMDIR + 1), hipMemcpyDeviceToHost)); unit_check_general(1, (DIMDIR + 1), 1, cpu_csx_row_col_ptr.data(), (int*)buffer); free(buffer); buffer = nullptr; } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(dense2csx( handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(dense2csx( handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2csx_gbyte_count(M, N, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); std::cout << "GBytes/s: " << gpu_gbyte << " time (ms): " << get_gpu_time_msec(gpu_time_used) << std::endl; } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE2CSX_HPP ./clients/include/testing_gebsr2gebsr.hpp0000664000175100017510000017403015176134511020655 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEBSR2GEBSR_HPP #define TESTING_GEBSR2GEBSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2gebsr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int mb = 1; int nb = 1; int nnzb = 1; int safe_size = 1; int row_block_dim_A = 2; int col_block_dim_A = 2; int row_block_dim_C = 2; int col_block_dim_C = 2; hipsparseIndexBase_t idx_base_A = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idx_base_C = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; hipsparseSetMatIndexBase(descr_A, idx_base_A); hipsparseSetMatIndexBase(descr_C, idx_base_C); auto bsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto bsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr_A = (int*)bsr_row_ptr_A_managed.get(); int* bsr_col_ind_A = (int*)bsr_col_ind_A_managed.get(); T* bsr_val_A = (T*)bsr_val_A_managed.get(); int* bsr_row_ptr_C = (int*)bsr_row_ptr_C_managed.get(); int* bsr_col_ind_C = (int*)bsr_col_ind_C_managed.get(); T* bsr_val_C = (T*)bsr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr_A, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Testing hipsparseXgebsr2gebsr_bufferSize() int buffer_size; // Test invalid handle status = hipsparseXgebsr2gebsr_bufferSize(nullptr, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, nullptr, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, (const T*)nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, -1, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, -1, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, -1, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, row_block_dim_C, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, -1, col_block_dim_C, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, -1, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); // Testing hipsparseXgebsr2gebsrNnz() int nnz_total_dev_host_ptr; // Test invalid handle status = hipsparseXgebsr2gebsrNnz(nullptr, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, nullptr, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, nullptr, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_C is nullptr"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsrNnz(handle, dir, -1, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, -1, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, -1, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, descr_C, bsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, -1, col_block_dim_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_row_ptr_C, row_block_dim_C, -1, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); // Test hipsparseXgebsr2gebsr() // Test invalid handle status = hipsparseXgebsr2gebsr(nullptr, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_handle(status); // Test invalid pointers status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, nullptr, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, (const T*)nullptr, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, nullptr, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, nullptr, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_A is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, nullptr, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, (T*)nullptr, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, nullptr, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr_C is nullptr"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, nullptr, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind_C is nullptr"); // Test invalid sizes status = hipsparseXgebsr2gebsr(handle, dir, -1, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, -1, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, -1, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, -1, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, -1, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_A is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, -1, col_block_dim_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim_C is invalid"); status = hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, bsr_val_C, bsr_row_ptr_C, bsr_col_ind_C, row_block_dim_C, -1, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim_C is invalid"); #endif } template hipsparseStatus_t testing_gebsr2gebsr(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim_A = argus.row_block_dimA; int col_block_dim_A = argus.col_block_dimA; int row_block_dim_C = argus.row_block_dimB; int col_block_dim_C = argus.col_block_dimB; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_C = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; hipsparseSetMatIndexBase(descr_A, idx_base_A); hipsparseSetMatIndexBase(descr_C, idx_base_C); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // mb and nb can be modified if reading from a file int mb = (m + row_block_dim_A - 1) / row_block_dim_A; int nb = (n + col_block_dim_A - 1) / col_block_dim_A; int mb_C = (mb * row_block_dim_A + row_block_dim_C - 1) / row_block_dim_C; int nb_C = (nb * col_block_dim_A + col_block_dim_C - 1) / col_block_dim_C; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr_A = (int*)dbsr_row_ptr_A_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t buffer_size_conversion; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr_bufferSize(handle, dir, m, n, descr_A, dcsr_val, dcsr_row_ptr, dcsr_col_ind, row_block_dim_A, col_block_dim_A, &buffer_size_conversion)); auto dbuffer_conversion_managed = hipsparse_unique_ptr{device_malloc(buffer_size_conversion), device_free}; void* dbuffer_conversion = dbuffer_conversion_managed.get(); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsrNnz(handle, dir, m, n, descr_A, dcsr_row_ptr, dcsr_col_ind, descr_A, dbsr_row_ptr_A, row_block_dim_A, col_block_dim_A, &nnzb, dbuffer_conversion)); // Allocate memory on the device auto dbsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_A_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * row_block_dim_A * col_block_dim_A), device_free}; auto dbsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb_C + 1)), device_free}; int* dbsr_col_ind_A = (int*)dbsr_col_ind_A_managed.get(); T* dbsr_val_A = (T*)dbsr_val_A_managed.get(); int* dbsr_row_ptr_C = (int*)dbsr_row_ptr_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, descr_A, dcsr_val, dcsr_row_ptr, dcsr_col_ind, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, dbuffer_conversion)); // Copy output from device to host std::vector hbsr_row_ptr_A(mb + 1); std::vector hbsr_col_ind_A(nnzb); std::vector hbsr_val_A(nnzb * row_block_dim_A * col_block_dim_A); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr_A.data(), dbsr_row_ptr_A, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind_A.data(), dbsr_col_ind_A, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_A.data(), dbsr_val_A, sizeof(T) * nnzb * row_block_dim_A * col_block_dim_A, hipMemcpyDeviceToHost)); int buffer_size = 0; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr_bufferSize(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, &buffer_size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * buffer_size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnzb_C; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_row_ptr_C, row_block_dim_C, col_block_dim_C, &hnnzb_C, dbuffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dnnzb_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnzb_C = (int*)dnnzb_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsrNnz(handle, dir, mb, nb, nnzb, descr_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_row_ptr_C, row_block_dim_C, col_block_dim_C, dnnzb_C, dbuffer)); int hnnzb_C_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hnnzb_C_copied_from_device, dnnzb_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Check that using host and device pointer mode gives the same result unit_check_general(1, 1, 1, &hnnzb_C_copied_from_device, &hnnzb_C); } // Allocate memory on the device auto dbsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnzb_C), device_free}; auto dbsr_val_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hnnzb_C * row_block_dim_C * col_block_dim_C), device_free}; int* dbsr_col_ind_C = (int*)dbsr_col_ind_C_managed.get(); T* dbsr_val_C = (T*)dbsr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); // Copy output from device to host std::vector hbsr_row_ptr_C(mb_C + 1); std::vector hbsr_col_ind_C(hnnzb_C); std::vector hbsr_val_C(hnnzb_C * row_block_dim_C * col_block_dim_C); CHECK_HIP_ERROR(hipMemcpy(hbsr_row_ptr_C.data(), dbsr_row_ptr_C, sizeof(int) * (mb_C + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind_C.data(), dbsr_col_ind_C, sizeof(int) * hnnzb_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_C.data(), dbsr_val_C, sizeof(T) * hnnzb_C * row_block_dim_C * col_block_dim_C, hipMemcpyDeviceToHost)); // Host csr2bsr conversion std::vector hbsr_row_ptr_C_gold; std::vector hbsr_col_ind_C_gold; std::vector hbsr_val_C_gold; // call host gebsr2gebsr here host_gebsr_to_gebsr(dir, mb, nb, nnzb, hbsr_val_A, hbsr_row_ptr_A, hbsr_col_ind_A, row_block_dim_A, col_block_dim_A, idx_base_A, hbsr_val_C_gold, hbsr_row_ptr_C_gold, hbsr_col_ind_C_gold, row_block_dim_C, col_block_dim_C, idx_base_C); int nnzb_C_gold = hbsr_row_ptr_C_gold[mb_C] - hbsr_row_ptr_C_gold[0]; // Unit check unit_check_general(1, 1, 1, &nnzb_C_gold, &hnnzb_C); unit_check_general(1, mb_C + 1, 1, hbsr_row_ptr_C_gold.data(), hbsr_row_ptr_C.data()); unit_check_general(1, hnnzb_C, 1, hbsr_col_ind_C_gold.data(), hbsr_col_ind_C.data()); unit_check_general(1, hnnzb_C * row_block_dim_C * col_block_dim_C, 1, hbsr_val_C_gold.data(), hbsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsr(handle, dir, mb, nb, nnzb, descr_A, dbsr_val_A, dbsr_row_ptr_A, dbsr_col_ind_A, row_block_dim_A, col_block_dim_A, descr_C, dbsr_val_C, dbsr_row_ptr_C, dbsr_col_ind_C, row_block_dim_C, col_block_dim_C, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2gebsr_gbyte_count(mb, mb_C, row_block_dim_A, col_block_dim_A, row_block_dim_C, col_block_dim_C, nnzb, hnnzb_C); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::MbA, mb, display_key_t::NbA, nb, display_key_t::MbC, mb_C, display_key_t::NbC, nb_C, display_key_t::row_block_dimA, row_block_dim_A, display_key_t::col_block_dimA, col_block_dim_A, display_key_t::row_block_dimC, row_block_dim_C, display_key_t::col_block_dimC, col_block_dim_C, display_key_t::nnzbA, nnzb, display_key_t::nnzbC, hnnzb_C, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSR_HPP ./clients/include/testing_csr2bsr.hpp0000664000175100017510000010366715176134511020036 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2BSR_HPP #define TESTING_CSR2BSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2bsr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); int bsr_nnzb; verify_hipsparse_status_invalid_handle(hipsparseXcsr2bsrNnz(nullptr, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, nullptr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, nullptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, nullptr, bsr_row_ptr, &bsr_nnzb), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, nullptr, &bsr_nnzb), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, nullptr), "Error: bsr_nnzb is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, -1, n, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, m, -1, csr_descr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, csr_row_ptr, csr_col_ind, -1, bsr_descr, bsr_row_ptr, &bsr_nnzb), "Error: block_dim is invalid"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2bsr(nullptr, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, nullptr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, nullptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, nullptr, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, nullptr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, nullptr, bsr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, nullptr), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, -1, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, m, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind, block_dim, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, csr_val, csr_row_ptr, csr_col_ind, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_csr2bsr(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 or n == 0 for csr2bsr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain BSR nnzb first on the host and then using the device and ensure they give the same results CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hbsr_nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_row_ptr, &hbsr_nnzb)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dbsr_nnzb_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dbsr_nnzb = (int*)dbsr_nnzb_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_row_ptr, dbsr_nnzb)); int hbsr_nnzb_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hbsr_nnzb_copied_from_device, dbsr_nnzb, sizeof(int), hipMemcpyDeviceToHost)); // Check that using host and device pointer mode gives the same result unit_check_general(1, 1, 1, &hbsr_nnzb_copied_from_device, &hbsr_nnzb); // Allocate memory on the device auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hbsr_nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Copy output from device to host std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(hbsr_nnzb); std::vector hbsr_val(hbsr_nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * hbsr_nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * hbsr_nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Host csr2bsr conversion std::vector hbsr_row_ptr_gold(mb + 1); std::vector hbsr_col_ind_gold(hbsr_nnzb, 0); std::vector hbsr_val_gold(hbsr_nnzb * block_dim * block_dim); // call host csr2bsr here int bsr_nnzb_gold; host_csr_to_bsr(dir, m, n, block_dim, bsr_nnzb_gold, csr_idx_base, hcsr_row_ptr, hcsr_col_ind, hcsr_val, bsr_idx_base, hbsr_row_ptr_gold, hbsr_col_ind_gold, hbsr_val_gold); // Unit check unit_check_general(1, 1, 1, &bsr_nnzb_gold, &hbsr_nnzb); unit_check_general(1, mb + 1, 1, hbsr_row_ptr_gold.data(), hbsr_row_ptr.data()); unit_check_general(1, hbsr_nnzb, 1, hbsr_col_ind_gold.data(), hbsr_col_ind.data()); unit_check_general( 1, hbsr_nnzb * block_dim * block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2bsr_gbyte_count(m, mb, nnz, hbsr_nnzb, block_dim); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::block_dim, block_dim, display_key_t::nnzb, hbsr_nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2BSR_HPP ./clients/include/unit.hpp0000664000175100017510000000432415176134305015667 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef UNIT_HPP #define UNIT_HPP #include /* ===================================================================== Google Unit check: ASSERT_EQ( elementof(A), elementof(B)) =================================================================== */ /*!\file * \brief compares two results (usually, CPU and GPU results); provides Google Unit check. */ /* ========================================Gtest Unit Check * ==================================================== */ /*! \brief Template: gtest unit compare two matrices float/double/complex */ // Do not put a wrapper over ASSERT_FLOAT_EQ, since assert exit the current function NOT the test // case // a wrapper will cause the loop keep going template void unit_check_general(int64_t M, int64_t N, int64_t lda, T* hCPU, T* hGPU); template void unit_check_near(int64_t M, int64_t N, int64_t lda, T* hCPU, T* hGPU); #endif // UNIT_HPP ./clients/include/testing_csr2gebsr.hpp0000664000175100017510000006123215176134511020341 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2GEBSR_HPP #define TESTING_CSR2GEBSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2gebsr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; static const size_t safe_size = 1; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; void* buffer = buffer_managed.get(); int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); { // int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); } // std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); // // Declaration of arguments. // hipsparseDirection_t arg_direction; int arg_m; int arg_n; hipsparseMatDescr_t arg_csr_descr; const T* arg_csr_val; const int* arg_csr_row_ptr; const int* arg_csr_col_ind; hipsparseMatDescr_t arg_bsr_descr; T* arg_bsr_val; int* arg_bsr_row_ptr; int* arg_bsr_col_ind; int arg_row_block_dim; int arg_col_block_dim; void* arg_p_buffer; int* arg_bsr_nnz_devhost; size_t* arg_p_buffer_size; int hbsr_nnzb; size_t buffer_size; // // Macro to set arguments. // #define ARGSET \ arg_direction = HIPSPARSE_DIRECTION_ROW; \ arg_m = safe_size; \ arg_n = safe_size; \ arg_csr_descr = csr_descr; \ arg_csr_val = (T*)csr_val; \ arg_csr_row_ptr = csr_row_ptr; \ arg_csr_col_ind = csr_col_ind; \ arg_bsr_descr = bsr_descr; \ arg_bsr_val = (T*)bsr_val; \ arg_bsr_row_ptr = bsr_row_ptr; \ arg_bsr_col_ind = bsr_col_ind; \ arg_row_block_dim = safe_size; \ arg_col_block_dim = safe_size; \ arg_p_buffer = (void*)((T*)buffer); \ arg_bsr_nnz_devhost = &hbsr_nnzb; \ arg_p_buffer_size = &buffer_size // // BUFFER_SIZE ############ // #define CALL_ARG_BUFFER_SIZE \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_val, arg_csr_row_ptr, arg_csr_col_ind, \ arg_row_block_dim, arg_col_block_dim, arg_p_buffer_size #define CALL_BUFFER_SIZE hipsparseXcsr2gebsr_bufferSize(handle, CALL_ARG_BUFFER_SIZE) { ARGSET; status = hipsparseXcsr2gebsr_bufferSize(nullptr, CALL_ARG_BUFFER_SIZE); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_val = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_csr_col_ind = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } { ARGSET; arg_p_buffer_size = nullptr; status = CALL_BUFFER_SIZE; verify_hipsparse_status_invalid_pointer(status, "Error: p_buffer_size is nullptr"); } #undef CALL_ARG_BUFFER_SIZE #undef CALL_BUFFER_SIZE // // NNZ ############ // #define CALL_ARG_NNZ \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_row_ptr, arg_csr_col_ind, arg_bsr_descr, \ arg_bsr_row_ptr, arg_row_block_dim, arg_col_block_dim, arg_bsr_nnz_devhost, arg_p_buffer #define CALL_NNZ hipsparseXcsr2gebsrNnz(handle, CALL_ARG_NNZ) { ARGSET; status = hipsparseXcsr2gebsrNnz(nullptr, CALL_ARG_NNZ); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_bsr_descr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); } { ARGSET; arg_bsr_row_ptr = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_NNZ; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } { ARGSET; arg_bsr_nnz_devhost = nullptr; status = CALL_NNZ; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_nnz_devhost is nullptr"); } #undef CALL_NNZ #undef CALL_ARG_NNZ #undef ARGSET #define ARGSET \ arg_direction = HIPSPARSE_DIRECTION_ROW; \ arg_m = safe_size; \ arg_n = safe_size; \ arg_csr_descr = csr_descr; \ arg_csr_val = (T*)csr_val; \ arg_csr_row_ptr = csr_row_ptr; \ arg_csr_col_ind = csr_col_ind; \ arg_bsr_descr = bsr_descr; \ arg_bsr_val = (T*)bsr_val; \ arg_bsr_row_ptr = bsr_row_ptr; \ arg_bsr_col_ind = bsr_col_ind; \ arg_row_block_dim = safe_size; \ arg_col_block_dim = safe_size; \ arg_p_buffer = (void*)((T*)buffer); \ arg_p_buffer_size = &buffer_size #define CALL_ARG_FUNC \ arg_direction, arg_m, arg_n, arg_csr_descr, arg_csr_val, arg_csr_row_ptr, arg_csr_col_ind, \ arg_bsr_descr, arg_bsr_val, arg_bsr_row_ptr, arg_bsr_col_ind, arg_row_block_dim, \ arg_col_block_dim, arg_p_buffer #define CALL_FUNC hipsparseXcsr2gebsr(handle, CALL_ARG_FUNC) { ARGSET; status = hipsparseXcsr2gebsr(nullptr, CALL_ARG_FUNC); verify_hipsparse_status_invalid_handle(status); } { ARGSET; arg_m = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: m is invalid"); } { ARGSET; arg_n = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: n is invalid"); } { ARGSET; arg_csr_descr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_descr is nullptr"); } { ARGSET; arg_csr_val = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); } { ARGSET; arg_csr_row_ptr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); } { ARGSET; arg_csr_col_ind = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); } { ARGSET; arg_bsr_descr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_descr is nullptr"); } { ARGSET; arg_bsr_val = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); } { ARGSET; arg_bsr_row_ptr = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); } { ARGSET; arg_bsr_col_ind = nullptr; status = CALL_FUNC; verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); } { ARGSET; arg_row_block_dim = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); } { ARGSET; arg_col_block_dim = -1; status = CALL_FUNC; verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); } #undef CALL_FUNC #undef CALL_ARG_FUNC #undef ARGSET #endif } template hipsparseStatus_t testing_csr2gebsr(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(row_block_dim == 1 || m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // Do not test cusparse with block dim 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + row_block_dim - 1) / row_block_dim; int nb = (n + col_block_dim - 1) / col_block_dim; // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr_bufferSize(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, row_block_dim, col_block_dim, &buffer_size)); auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; void* dbuffer = dbuffer_managed.get(); int hbsr_nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsrNnz(handle, dir, m, n, csr_descr, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_row_ptr, row_block_dim, col_block_dim, &hbsr_nnzb, dbuffer)); // Allocate memory on the device auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hbsr_nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * hbsr_nnzb * row_block_dim * col_block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); // Copy output from device to host std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(hbsr_nnzb); std::vector hbsr_val(hbsr_nnzb * row_block_dim * col_block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * hbsr_nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * hbsr_nnzb * row_block_dim * col_block_dim, hipMemcpyDeviceToHost)); // Host csr2gebsr conversion std::vector hbsr_row_ptr_gold(mb + 1); std::vector hbsr_col_ind_gold(hbsr_nnzb, 0); std::vector hbsr_val_gold(hbsr_nnzb * row_block_dim * col_block_dim); // call host csr2gebsr here int bsr_nnzb_gold; host_csr_to_gebsr(dir, m, n, row_block_dim, col_block_dim, bsr_nnzb_gold, csr_idx_base, hcsr_row_ptr, hcsr_col_ind, hcsr_val, bsr_idx_base, hbsr_row_ptr_gold, hbsr_col_ind_gold, hbsr_val_gold); // Unit check unit_check_general(1, 1, 1, &bsr_nnzb_gold, &hbsr_nnzb); unit_check_general(1, mb + 1, 1, hbsr_row_ptr_gold.data(), hbsr_row_ptr.data()); unit_check_general(1, hbsr_nnzb, 1, hbsr_col_ind_gold.data(), hbsr_col_ind.data()); unit_check_general( 1, hbsr_nnzb * row_block_dim * col_block_dim, 1, hbsr_val_gold.data(), hbsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2gebsr(handle, dir, m, n, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2gebsr_gbyte_count(m, mb, nnz, hbsr_nnzb, row_block_dim, col_block_dim); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::nnzb, hbsr_nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2GEBSR_HPP ./clients/include/testing_csrilu02.hpp0000664000175100017510000004205615176134511020113 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRILU0_HPP #define TESTING_CSRILU0_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrilu02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrilu02(new csrilu02_struct); csrilu02Info_t info = unique_ptr_csrilu02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; auto dboost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto dboost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); double* dboost_tol = (double*)dboost_tol_managed.get(); T* dboost_val = (T*)dboost_val_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, dval, dptr, dcol, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, (csrilu02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02_bufferSize( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, &size)); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02_numericBoost( (hipsparseHandle_t) nullptr, info, 1, dboost_tol, dboost_val)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_numericBoost( handle, (csrilu02Info_t) nullptr, 1, dboost_tol, dboost_val), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_numericBoost(handle, info, 1, (double*)nullptr, dboost_val), "Error: boost_tol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_numericBoost(handle, info, 1, dboost_tol, (T*)nullptr), "Error: boost_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval, dptr, dcol, (csrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02_analysis( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02(handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02( handle, m, nnz, descr, dval, dptr, dcol, (csrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrilu02( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrilu02_zeroPivot(handle, (csrilu02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrilu02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrilu02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int boost = argus.numericboost; double boost_tol = argus.boosttol; T boost_val = make_DataType(argus.boostval, argus.boostvali); hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrilu02(new csrilu02_struct); csrilu02Info_t info = unique_ptr_csrilu02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts m > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_val_orig(hcsr_val); // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto boost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto boost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); int* d_position = (int*)d_position_managed.get(); double* dboost_tol = (double*)boost_tol_managed.get(); T* dboost_val = (T*)boost_val_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain csrilu02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr, dval1, dptr, dcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dboost_tol, &boost_tol, sizeof(double), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dboost_val, &boost_val, sizeof(T), hipMemcpyHostToDevice)); // Pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_numericBoost(handle, info, boost, &boost_tol, &boost_val)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02(handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXcsrilu02_zeroPivot(handle, info, &hposition_1); // Pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_analysis( handle, m, nnz, descr, dval2, dptr, dcol, info, policy, dbuffer)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_numericBoost(handle, info, boost, dboost_tol, dboost_val)); CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02(handle, m, nnz, descr, dval2, dptr, dcol, info, policy, dbuffer)); int hposition_2; hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXcsrilu02_zeroPivot(handle, info, d_position); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Copy output from device to CPU std::vector result1(nnz); std::vector result2(nnz); CHECK_HIP_ERROR(hipMemcpy(result1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csrilu02 int position_gold = csrilu0(m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), idx_base, boost, boost_tol, boost_val); unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } #if defined(__HIP_PLATFORM_AMD__) unit_check_general(1, nnz, 1, hcsr_val.data(), result1.data()); unit_check_general(1, nnz, 1, hcsr_val.data(), result2.data()); #elif defined(__HIP_PLATFORM_NVIDIA__) // do weaker check for cusparse unit_check_near(1, nnz, 1, hcsr_val.data(), result1.data()); unit_check_near(1, nnz, 1, hcsr_val.data(), result2.data()); #endif } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02( handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); } double gpu_time_used = 0; // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02( handle, m, nnz, descr, dval1, dptr, dcol, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csrilu0_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRILU0_HPP ./clients/include/testing_gemvi.hpp0000664000175100017510000003463615176134511017564 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEMVI_HPP #define TESTING_GEMVI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gemvi_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int lda = 100; static constexpr hipsparseOperation_t opType = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; T alpha = make_DataType(0.6); T beta = make_DataType(0.1); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; auto x_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto xInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto y_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; T* A = (T*)A_managed.get(); T* x = (T*)x_managed.get(); int* xInd = (int*)xInd_managed.get(); T* y = (T*)y_managed.get(); // gemvi void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, 100)); verify_hipsparse_status_invalid_handle(hipsparseXgemvi( nullptr, opType, m, n, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXgemvi( handle, opType, m, n, (T*)nullptr, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemvi(handle, opType, m, n, &alpha, (T*)nullptr, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemvi(handle, opType, m, n, &alpha, A, lda, nnz, (T*)nullptr, xInd, &beta, y, idxBase, buffer), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, nullptr, &beta, y, idxBase, buffer), "Error: xInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, nnz, x, xInd, (T*)nullptr, y, idxBase, buffer), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemvi(handle, opType, m, n, &alpha, A, lda, nnz, x, xInd, &beta, (T*)nullptr, idxBase, buffer), "Error: y is nullptr"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, -1, n, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: m is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, -1, &alpha, A, lda, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: n is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, n, &alpha, A, -1, nnz, x, xInd, &beta, y, idxBase, buffer), "Error: lda is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, -1, x, xInd, &beta, y, idxBase, buffer), "Error: nnz is invalid"); verify_hipsparse_status_invalid_size( hipsparseXgemvi( handle, opType, m, n, &alpha, A, lda, n + 1, x, xInd, &beta, y, idxBase, buffer), "Error: nnz is invalid"); CHECK_HIP_ERROR(hipFree(buffer)); #endif } template hipsparseStatus_t testing_gemvi(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int nnz = argus.nnz; T alpha = make_DataType(argus.alpha); T beta = make_DataType(argus.beta); hipsparseOperation_t trans = argus.transA; hipsparseIndexBase_t idxBase = argus.baseA; std::string filename = argus.filename; int lda = m; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hA(m * n); std::vector hx_val(nnz); std::vector hx_ind(nnz); std::vector hy(m); std::vector hy_gold(m); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, n); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, m); hy_gold = hy; for(int i = 0; i < m * n; ++i) { hA[i] = random_generator(); } // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dA = (T*)dA_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); // gemvi bufferSize int bufferSize; void* externalBuffer; CHECK_HIPSPARSE_ERROR(hipsparseXgemvi_bufferSize(handle, trans, m, n, nnz, &bufferSize)); CHECK_HIP_ERROR(hipMalloc(&externalBuffer, bufferSize)); if(argus.unit_check) { // gemvi CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); // CPU for(int i = 0; i < m; ++i) { T sum = make_DataType(0); for(int j = 0; j < nnz; ++j) { sum = testing_fma(hx_val[j], hA[(hx_ind[j] - idxBase) * lda + i], sum); } hy_gold[i] = testing_fma(alpha, sum, testing_mult(beta, hy_gold[i])); } // Verify results against host CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * m, hipMemcpyDeviceToHost)); unit_check_near(m, 1, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemvi(handle, trans, m, n, &alpha, dA, lda, nnz, dx_val, dx_ind, &beta, dy, idxBase, externalBuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = gemvi_gflop_count(m, nnz); double gbyte_count = gemvi_gbyte_count((trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : n, nnz, beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::alpha, alpha, display_key_t::beta, beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(externalBuffer)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMVI_HPP ./clients/include/testing_const_dnmat_descr.hpp0000664000175100017510000001251215176134305022134 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_DNMAT_DESCR_HPP #define TESTING_CONST_DNMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_const_dnmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t ld = 100; hipsparseOrder_t order = HIPSPARSE_ORDER_ROW; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * rows * cols), device_free}; const float* val_data = (const float*)val_data_managed.get(); hipsparseConstDnMatDescr_t x; // hipsparseCreateConstDnMat verify_hipsparse_status_invalid_pointer( hipsparseCreateConstDnMat(nullptr, rows, cols, ld, val_data, dataType, order), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstDnMat(&x, -1, cols, ld, val_data, dataType, order), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstDnMat(&x, rows, -1, ld, val_data, dataType, order), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstDnMat(&x, rows, cols, -1, val_data, dataType, order), "Error: ld is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstDnMat(&x, rows, cols, ld, nullptr, dataType, order), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnMat(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateConstDnMat(&x, rows, cols, ld, val_data, dataType, order), "Success"); // hipsparseConstDnMatGet const void* data; verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(nullptr, &rows, &cols, &ld, &data, &dataType, &order), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, nullptr, &cols, &ld, &data, &dataType, &order), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, nullptr, &ld, &data, &dataType, &order), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, nullptr, &data, &dataType, &order), "Error: ld is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, &ld, nullptr, &dataType, &order), "Error: data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, &ld, &data, nullptr, &order), "Error: dataType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstDnMatGet(x, &rows, &cols, &ld, &data, &dataType, nullptr), "Error: order is nullptr"); // hipsparseConstDnMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstDnMatGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnMatGetValues(x, nullptr), "Error: val is nullptr"); int batch_count = 100; int64_t batch_stride = 100; // hipsparseDnMatGetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(nullptr, &batch_count, &batch_stride), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(x, nullptr, &batch_stride), "Error: batch_count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetStridedBatch(x, &batch_count, nullptr), "Error: batch_stride is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_CONST_DNMAT_DESCR_HPP ./clients/include/testing_sparse_to_dense_csc.hpp0000664000175100017510000003144215176134511022452 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPARSE_TO_DENSE_CSC_HPP #define TESTING_SPARSE_TO_DENSE_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_sparse_to_dense_csc_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsc_col_ptr = (int32_t*)dcsc_col_ptr_managed.get(); int32_t* dcsc_row_ind = (int32_t*)dcsc_row_ind_managed.get(); float* dcsc_val = (float*)dcsc_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseSpMatDescr_t matA; hipsparseDnVecDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success(hipsparseCreateCsr(&matA, m, n, nnz, dcsc_col_ptr, dcsc_row_ind, dcsc_val, iType, jType, idxBase, dataType), "success"); verify_hipsparse_status_success( hipsparseCreateDnMat(&matB, m, n, ld, ddense_val, dataType, order), "success"); // SparseToDense buffer size verify_hipsparse_status_invalid_handle( hipsparseSparseToDense_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // SparseToDense verify_hipsparse_status_invalid_handle(hipsparseSparseToDense(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(matB), "success"); #endif } template hipsparseStatus_t testing_sparse_to_dense_csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) J m = argus.M; J n = argus.N; hipsparseOrder_t order = argus.orderA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSparseToDenseAlg_t alg = static_cast(argus.sparse2dense_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures for CSR matrix std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; I nrows = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncols = (order == HIPSPARSE_ORDER_COL) ? n : ld; // Convert CSR matrix to CSC std::vector hcsc_col_ptr(n + 1); std::vector hcsc_row_ind(nnz); std::vector hcsc_val(nnz); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++hcsc_col_ptr[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(J i = 0; i < n; ++i) { hcsc_col_ptr[i + 1] += hcsc_col_ptr[i]; } // Fill row indices and values for(J i = 0; i < m; ++i) { for(I j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { J col = hcsr_col_ind[j - idx_base] - idx_base; I idx = hcsc_col_ptr[col]; hcsc_row_ind[idx] = i + idx_base; hcsc_val[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr[col]; } } // Shift column pointer array for(J i = n; i > 0; --i) { hcsc_col_ptr[i] = hcsc_col_ptr[i - 1] + idx_base; } hcsc_col_ptr[0] = idx_base; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (n + 1)), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrows * ncols), device_free}; I* dptr = (I*)dptr_managed.get(); J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* ddense = (T*)ddense_managed.get(); // Dense matrix std::vector hdense(nrows * ncols); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(drow, hcsc_row_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsc_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t matA; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&matA, m, n, nnz, dptr, drow, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrix hipsparseDnMatDescr_t matB; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matB, m, n, ld, ddense, typeT, order)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hdense.data(), ddense, sizeof(T) * nrows * ncols, hipMemcpyDeviceToHost)); std::vector hdense_cpu(nrows * ncols); if(order == HIPSPARSE_ORDER_COL) { for(J col = 0; col < n; ++col) { for(J row = 0; row < m; ++row) { hdense_cpu[row + ld * col] = make_DataType(0.0); } } for(J col = 0; col < n; ++col) { I start = hcsc_col_ptr[col] - idx_base; I end = hcsc_col_ptr[col + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[(hcsc_row_ind[at] - idx_base) + ld * col] = hcsc_val[at]; } } } else { for(I row = 0; row < m; ++row) { for(I col = 0; col < n; ++col) { hdense_cpu[ld * row + col] = make_DataType(0.0); } } for(J col = 0; col < n; ++col) { I start = hcsc_col_ptr[col] - idx_base; I end = hcsc_col_ptr[col + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[ld * (hcsc_row_ind[at] - idx_base) + col] = hcsc_val[at]; } } } unit_check_general(1, nrows * ncols, 1, hdense_cpu.data(), hdense.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csx2dense_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_sparsetodensealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPARSE_TO_DENSE_CSC_HPP ./clients/include/testing_sparse_to_dense_coo.hpp0000664000175100017510000002652415176134511022467 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPARSE_TO_DENSE_COO_HPP #define TESTING_SPARSE_TO_DENSE_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_sparse_to_dense_coo_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcoo_row_ind = (int32_t*)dcoo_row_ind_managed.get(); int32_t* dcoo_col_ind = (int32_t*)dcoo_col_ind_managed.get(); float* dcoo_val = (float*)dcoo_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseSpMatDescr_t matA; hipsparseDnVecDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateCoo( &matA, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dcoo_val, iType, idxBase, dataType), "success"); verify_hipsparse_status_success( hipsparseCreateDnMat(&matB, m, n, ld, ddense_val, dataType, order), "success"); // SparseToDense buffer size verify_hipsparse_status_invalid_handle( hipsparseSparseToDense_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // SparseToDense verify_hipsparse_status_invalid_handle(hipsparseSparseToDense(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); // cuda returns success here #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); #endif // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(matB), "success"); #endif } template hipsparseStatus_t testing_sparse_to_dense_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) I m = argus.M; I n = argus.N; hipsparseOrder_t order = argus.orderA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSparseToDenseAlg_t alg = static_cast(argus.sparse2dense_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; I nrows = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncols = (order == HIPSPARSE_ORDER_COL) ? n : ld; // Fill host COO arrays std::vector hcoo_row_ind(nnz); std::vector hcoo_col_ind = hcsr_col_ind; std::vector hcoo_val = hcsr_val; for(I i = 0; i < m; i++) { I start = hcsr_row_ptr[i] - idx_base; I end = hcsr_row_ptr[i + 1] - idx_base; for(I j = start; j < end; j++) { hcoo_row_ind[j] = i + idx_base; } } // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrows * ncols), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* ddense = (T*)ddense_managed.get(); // Dense matrix std::vector hdense(nrows * ncols); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hcoo_row_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcoo_col_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcoo_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t matA; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&matA, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense matrix hipsparseDnMatDescr_t matB; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matB, m, n, ld, ddense, typeT, order)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hdense.data(), ddense, sizeof(T) * nrows * ncols, hipMemcpyDeviceToHost)); std::vector hdense_cpu(nrows * ncols); if(order == HIPSPARSE_ORDER_COL) { for(I col = 0; col < n; ++col) { for(I row = 0; row < m; ++row) { hdense_cpu[row + ld * col] = make_DataType(0.0); } } for(I i = 0; i < nnz; i++) { I row = hcoo_row_ind[i] - idx_base; I col = hcoo_col_ind[i] - idx_base; hdense_cpu[ld * col + row] = hcoo_val[i]; } } else { for(I row = 0; row < m; ++row) { for(I col = 0; col < n; ++col) { hdense_cpu[ld * row + col] = make_DataType(0.0); } } for(I i = 0; i < nnz; i++) { I row = hcoo_row_ind[i] - idx_base; I col = hcoo_col_ind[i] - idx_base; hdense_cpu[col + ld * row] = hcoo_val[i]; } } unit_check_general(1, nrows * ncols, 1, hdense_cpu.data(), hdense.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = coo2dense_gbyte_count(m, n, (I)nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_sparsetodensealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPARSE_TO_DENSE_COO_HPP ./clients/include/hipsparse_template.yaml0000664000175100017510000000254615176134305020760 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Template used to process YAML from log files --- include: hipsparse_common.yaml Functions: Tests:./clients/include/testing_dnvec_descr.hpp0000664000175100017510000001014515176134305020722 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DNVEC_DESCR_HPP #define TESTING_DNVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_dnvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* val_data = (float*)val_data_managed.get(); hipsparseDnVecDescr_t x; // hipsparseCreateDnVec verify_hipsparse_status_invalid_pointer(hipsparseCreateDnVec(nullptr, size, val_data, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size(hipsparseCreateDnVec(&x, -1, val_data, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_pointer(hipsparseCreateDnVec(&x, size, nullptr, dataType), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success(hipsparseCreateDnVec(&x, size, val_data, dataType), "Success"); // hipsparseDnVecGet void* data; verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(nullptr, &size, &data, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(x, nullptr, &data, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(x, &size, nullptr, &dataType), "Error: val_data is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGet(x, &size, &data, nullptr), "Error: dataType is nullptr"); // hipsparseDnVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseDnVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecGetValues(x, nullptr), "Error: val is nullptr"); // hipsparseDnVecSetValues verify_hipsparse_status_invalid_pointer(hipsparseDnVecSetValues(nullptr, data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnVecSetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_DNVEC_DESCR_HPP ./clients/include/testing_nnz.hpp0000664000175100017510000003210315176134511017245 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_NNZ_HPP #define TESTING_NNZ_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_nnz_bad_arg(void) { static constexpr size_t safe_size = 100; static constexpr int M = 10; static constexpr int N = 10; static constexpr int lda = M; static constexpr hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descrA = unique_ptr_descr->descr; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_A = (T*)A_managed.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); int* d_nnzTotalDevHostPtr = (int*)nnzTotalDevHostPtr_managed.get(); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_handle(hipsparseXnnz( nullptr, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr)); verify_hipsparse_status_invalid_pointer(hipsparseXnnz(handle, dirA, M, N, nullptr, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: descrA as invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer(hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)nullptr, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: A as invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, nullptr, d_nnzTotalDevHostPtr), "Error: nnzPerRowColumn as invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, nullptr), "Error: nnzTotalDevHostPtr as invalid pointer must be detected."); #endif // Testing invalid direction try { hipsparseXnnz(handle, (hipsparseDirection_t)77, -1, -1, descrA, (const T*)nullptr, -1, nullptr, nullptr); // An exception should be thrown. verify_hipsparse_status_internal_error( HIPSPARSE_STATUS_SUCCESS, "Error: an exception must be thrown from the conversion of the hipsparseDirection_t."); } catch(...) { } verify_hipsparse_status_invalid_size(hipsparseXnnz(handle, dirA, -1, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: M < 0 must be detected."); verify_hipsparse_status_invalid_size(hipsparseXnnz(handle, dirA, M, -1, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: N < 0 must be detected."); verify_hipsparse_status_invalid_size(hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)d_A, M - 1, d_nnzPerRowColumn, d_nnzTotalDevHostPtr), "Error: lda < M must be detected."); } template hipsparseStatus_t testing_nnz(Arguments argus) { int M = argus.M; int N = argus.N; int lda = argus.lda; hipsparseDirection_t dirA = argus.dirA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descrA = unique_ptr_descr->descr; if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Create the dense matrix. int MN = (dirA == HIPSPARSE_DIRECTION_ROW) ? M : N; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * lda * N), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * MN), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_A = (T*)A_managed.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); int* d_nnzTotalDevHostPtr = (int*)nnzTotalDevHostPtr_managed.get(); std::vector h_A(lda * N); std::vector h_nnzPerRowColumn(MN); std::vector hd_nnzPerRowColumn(MN); std::vector h_nnzTotalDevHostPtr(1); std::vector hd_nnzTotalDevHostPtr(1); // Initialize the entire allocated memory. for(int i = 0; i < lda; ++i) { for(int j = 0; j < N; ++j) { h_A[j * lda + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), lda, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * lda * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // Compute the reference host first. host_nnz(dirA, M, N, descrA, h_A.data(), lda, h_nnzPerRowColumn.data(), h_nnzTotalDevHostPtr.data()); // Pointer mode device for nnz and call. CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXnnz(handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, d_nnzTotalDevHostPtr)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( hd_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * MN, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hd_nnzTotalDevHostPtr.data(), d_nnzTotalDevHostPtr, sizeof(int) * 1, hipMemcpyDeviceToHost)); // Check results. unit_check_general(1, MN, 1, hd_nnzPerRowColumn.data(), h_nnzPerRowColumn.data()); unit_check_general(1, 1, 1, hd_nnzTotalDevHostPtr.data(), h_nnzTotalDevHostPtr.data()); // Pointer mode host for nnz and call. int dh_nnz; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, &dh_nnz)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( hd_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * MN, hipMemcpyDeviceToHost)); // Check results. unit_check_general(1, MN, 1, hd_nnzPerRowColumn.data(), h_nnzPerRowColumn.data()); unit_check_general(1, 1, 1, &dh_nnz, h_nnzTotalDevHostPtr.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm-up int h_nnz; for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, &h_nnz)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXnnz( handle, dirA, M, N, descrA, (const T*)d_A, lda, d_nnzPerRowColumn, &h_nnz)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = nnz_gbyte_count(M, N, dirA); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::LD, lda, display_key_t::nnz, h_nnz, display_key_t::direction, hipsparse_direction2string(dirA), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_NNZ_HPP ./clients/include/testing_csrgeam.hpp0000664000175100017510000017311315176134511020070 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEAM_HPP #define TESTING_CSRGEAM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgeam_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 1; T alpha = 1.0; T beta = 1.0; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); const int M = safe_size; std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // testing hipsparseXcsrgeamNnz verify_hipsparse_status_invalid_handle(hipsparseXcsrgeamNnz(nullptr, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, nullptr, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, nullptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, nullptr, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, nullptr, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, nullptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, nullptr, descr_C, dCptr, &nnz_C), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, nullptr, dCptr, &nnz_C), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, nullptr, &nnz_C), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, nullptr), "Error: invalid nnz_C pointer"); // testing hipsparseXcsrgeam verify_hipsparse_status_invalid_handle(hipsparseXcsrgeam(nullptr, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, (T*)nullptr, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid alpha pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, nullptr, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, (T*)nullptr, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dAval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, nullptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, nullptr, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, (T*)nullptr, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid beta pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, nullptr, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, (T*)nullptr, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dBval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, nullptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, nullptr, descr_C, dCval, dCptr, dCcol), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, nullptr, dCval, dCptr, dCcol), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr, dCcol), "Error: invalid dCval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, nullptr, dCcol), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, nullptr), "Error: invalid dCcol pointer"); // testing invalid sizes verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, -1, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, safe_size, -1, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, -1, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeamNnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, -1, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: invalid nnz_B size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, -1, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, safe_size, -1, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, -1, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, -1, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: invalid nnz_B size"); #endif } template hipsparseStatus_t testing_csrgeam(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int M = argus.M; int N = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // B = A int nnz_B = nnz_A; std::vector hcsr_row_ptr_B(M + 1, 0); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); for(int i = 0; i < M + 1; ++i) { hcsr_row_ptr_B[i] = hcsr_row_ptr_A[i] - idx_base_A + idx_base_B; } for(int i = 0; i < nnz_A; ++i) { hcsr_col_ind_B[i] = hcsr_col_ind_A[i] - idx_base_A + idx_base_B; } hcsr_val_B = hcsr_val_A; // Allocate memory on device auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dCptr_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dCptr_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr_1 = (int*)dCptr_1_managed.get(); int* dCptr_2 = (int*)dCptr_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeamNnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_1, &hnnz_C_1)); // Allocate result matrix auto dCcol_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; auto dCcol_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; int* dCcol_1 = (int*)dCcol_1_managed.get(); T* dCval_1 = (T*)dCval_1_managed.get(); int* dCcol_2 = (int*)dCcol_2_managed.get(); T* dCval_2 = (T*)dCval_2_managed.get(); // hipsparse pointer mode device auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dbeta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; T* d_alpha = (T*)dalpha_managed.get(); T* d_beta = (T*)dbeta_managed.get(); int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeamNnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_2, dnnz_C)); // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Compute csrgeam CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, d_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, d_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_2, dCptr_2, dCcol_2)); // Copy output from device to CPU std::vector hcsr_row_ptr_C_1(M + 1); std::vector hcsr_col_ind_C_1(hnnz_C_1); std::vector hcsr_val_C_1(hnnz_C_1); std::vector hcsr_row_ptr_C_2(M + 1); std::vector hcsr_col_ind_C_2(hnnz_C_2); std::vector hcsr_val_C_2(hnnz_C_2); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_1.data(), dCptr_1, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_1.data(), dCcol_1, sizeof(int) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval_1, sizeof(T) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_2.data(), dCptr_2, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_2.data(), dCcol_2, sizeof(int) * hnnz_C_2, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval_2, sizeof(T) * hnnz_C_2, hipMemcpyDeviceToHost)); // Compute csrgeam host solution std::vector hcsr_row_ptr_C_gold(M + 1); int nnz_C_gold = host_csrgeam_nnz(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgeam(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_1.data()); unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_2.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_2.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrgeam_gflop_count(nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gbyte_count = csrgeam_gbyte_count(M, nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzB, nnz_B, display_key_t::nnzC, hnnz_C_1, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEAM_HPP ./clients/include/testing_cscsort.hpp0000664000175100017510000002712715176134511020132 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSCSORT_HPP #define TESTING_CSCSORT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_cscsort_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; size_t buffer_size = 0; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto perm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* perm = (int*)perm_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, (int*)nullptr, csc_row_ind, &buffer_size), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr, (int*)nullptr, &buffer_size), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, csc_col_ptr, csc_row_ind, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcscsort_bufferSizeExt( (hipsparseHandle_t) nullptr, m, n, nnz, csc_col_ptr, csc_row_ind, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort(handle, m, n, nnz, descr, (int*)nullptr, csc_row_ind, perm, buffer), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort(handle, m, n, nnz, descr, csc_col_ptr, (int*)nullptr, perm, buffer), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcscsort(handle, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcscsort(handle, m, n, nnz, (hipsparseMatDescr_t) nullptr, csc_col_ptr, csc_row_ind, perm, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcscsort( (hipsparseHandle_t) nullptr, m, n, nnz, descr, csc_col_ptr, csc_row_ind, perm, buffer)); #endif } hipsparseStatus_t testing_cscsort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int permute = argus.permute; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Read or construct CSC matrix int nnz = 0; if(!generate_csr_matrix(filename, n, m, nnz, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort CSC columns std::vector hperm(nnz); std::vector hcsc_row_ind_unsorted(nnz); std::vector hcsc_val_unsorted(nnz); hcsc_row_ind_unsorted = hcsc_row_ind; hcsc_val_unsorted = hcsc_val; for(int i = 0; i < n; ++i) { int col_begin = hcsc_col_ptr[i] - idx_base; int col_end = hcsc_col_ptr[i + 1] - idx_base; int col_nnz = col_end - col_begin; for(int j = col_begin; j < col_end; ++j) { int rng = col_begin + rand() % col_nnz; int temp_row = hcsc_row_ind_unsorted[j]; float temp_val = hcsc_val_unsorted[j]; hcsc_row_ind_unsorted[j] = hcsc_row_ind_unsorted[rng]; hcsc_val_unsorted[j] = hcsc_val_unsorted[rng]; hcsc_row_ind_unsorted[rng] = temp_row; hcsc_val_unsorted[rng] = temp_val; } } // Allocate memory on the device auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dcsc_val_sorted_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dperm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); float* dcsc_val = (float*)dcsc_val_managed.get(); float* dcsc_val_sorted = (float*)dcsc_val_sorted_managed.get(); // Set permutation vector, if asked for #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not allow nullptr int* dperm = (int*)dperm_managed.get(); #else int* dperm = permute ? (int*)dperm_managed.get() : nullptr; #endif // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsc_col_ptr, hcsc_col_ptr.data(), sizeof(int) * (n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsc_row_ind, hcsc_row_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsc_val, hcsc_val_unsorted.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcscsort_bufferSizeExt( handle, m, n, nnz, dcsc_col_ptr, dcsc_row_ind, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } if(argus.unit_check) { // Sort CSC columns CHECK_HIPSPARSE_ERROR(hipsparseXcscsort( handle, m, n, nnz, descr, dcsc_col_ptr, dcsc_row_ind, dperm, dbuffer)); if(permute) { // Sort CSC values CHECK_HIPSPARSE_ERROR(hipsparseSgthr( handle, nnz, dcsc_val, dcsc_val_sorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); } // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsc_row_ind_unsorted.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); if(permute) { CHECK_HIP_ERROR(hipMemcpy(hcsc_val_unsorted.data(), dcsc_val_sorted, sizeof(float) * nnz, hipMemcpyDeviceToHost)); } // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind.data(), hcsc_row_ind_unsorted.data()); if(permute) { unit_check_general(1, nnz, 1, hcsc_val.data(), hcsc_val_unsorted.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcscsort( handle, m, n, nnz, descr, dcsc_col_ptr, dcsc_row_ind, dperm, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcscsort( handle, m, n, nnz, descr, dcsc_col_ptr, dcsc_row_ind, dperm, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = cscsort_gbyte_count(n, nnz, permute); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::permute, (permute ? "yes" : "no"), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSCSORT_HPP ./clients/include/testing_gthr.hpp0000664000175100017510000001440115176134511017405 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTHR_HPP #define TESTING_GTHR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gthr_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, dy, dx_val, (int*)nullptr, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, dy, (T*)nullptr, dx_ind, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthr(handle, nnz, (T*)nullptr, dx_val, dx_ind, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXgthr((hipsparseHandle_t) nullptr, nnz, dy, dx_val, dx_ind, idx_base)); #endif } template hipsparseStatus_t testing_gthr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hx_val_gold[i] = hy[hx_ind[i] - idx_base]; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthr(handle, nnz, dy, dx_val, dx_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHR_HPP ./clients/include/testing_csrilusv.hpp0000664000175100017510000005027215176134511020321 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRILUSV_HPP #define TESTING_CSRILUSV_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template hipsparseStatus_t testing_csrilusv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_M(new descr_struct); hipsparseMatDescr_t descr_M = unique_ptr_descr_M->descr; std::unique_ptr unique_ptr_csrilu02_info(new csrilu02_struct); csrilu02Info_t info_M = unique_ptr_csrilu02_info->info; // Initialize the matrix descriptor CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_M, idx_base)); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU int m; int n; int nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain csrilu02 buffer size int size; CHECK_HIPSPARSE_ERROR( hipsparseXcsrilu02_bufferSize(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, &size)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * size), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrilu02 analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02_analysis(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // Compute incomplete LU factorization CHECK_HIPSPARSE_ERROR(hipsparseXcsrilu02(handle, m, nnz, descr_M, dval, dptr, dcol, info_M, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); // Check for zero pivot int hposition_1, hposition_2; hipsparseStatus_t pivot_status_1, pivot_status_2; // Host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); pivot_status_1 = hipsparseXcsrilu02_zeroPivot(handle, info_M, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); pivot_status_2 = hipsparseXcsrilu02_zeroPivot(handle, info_M, d_position); // Copy output to CPU std::vector iluresult(nnz); CHECK_HIP_ERROR(hipMemcpy(iluresult.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Compute host reference csrilu0 int position_gold = csrilu0(m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), idx_base, false, 0.0, make_DataType(0.0, 0.0)); // Check zero pivot results unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); // If zero pivot was found, do not go further if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } // Check csrilu0 factorization #if defined(__HIP_PLATFORM_AMD__) unit_check_general(1, nnz, 1, hcsr_val.data(), iluresult.data()); #elif defined(__HIP_PLATFORM_NVIDIA__) unit_check_near(1, nnz, 1, hcsr_val.data(), iluresult.data()); #endif // Create info structs for lower and upper part std::unique_ptr unique_ptr_csrsv2_lower(new csrsv2_struct); std::unique_ptr unique_ptr_csrsv2_upper(new csrsv2_struct); csrsv2Info_t info_L = unique_ptr_csrsv2_lower->info; csrsv2Info_t info_U = unique_ptr_csrsv2_upper->info; // Create matrix descriptors for csrsv std::unique_ptr unique_ptr_descr_L(new descr_struct); hipsparseMatDescr_t descr_L = unique_ptr_descr_L->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_L, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr_L, HIPSPARSE_FILL_MODE_LOWER)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr_L, HIPSPARSE_DIAG_TYPE_UNIT)); std::unique_ptr unique_ptr_descr_U(new descr_struct); hipsparseMatDescr_t descr_U = unique_ptr_descr_U->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_U, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr_U, HIPSPARSE_FILL_MODE_UPPER)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr_U, HIPSPARSE_DIAG_TYPE_NON_UNIT)); // Obtain csrsv buffer sizes int size_lower, size_upper; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_L, dval, dptr, dcol, info_L, &size_lower)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_U, dval, dptr, dcol, info_U, &size_upper)); // Pick maximum size so that we need only one buffer size = std::max(size_lower, size_upper); // Allocate buffer on the device auto dbuffer_sv_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * size), device_free}; void* dbuffer_sv = (void*)dbuffer_sv_managed.get(); // csrsv analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_L, dval, dptr, dcol, info_L, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, descr_U, dval, dptr, dcol, info_U, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Initialize some more structures required for Lz = x T h_alpha = static_cast(1); std::vector hx(m, static_cast(1)); std::vector hy_gold(m); std::vector hz_gold(m); // Allocate device memory auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dz_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dz_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dz_1 = (T*)dz_1_managed.get(); T* dz_2 = (T*)dz_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // Copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Solve Lz = x // host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, &h_alpha, descr_L, dval, dptr, dcol, info_L, dx, dz_1, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info_L, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, d_alpha, descr_L, dval, dptr, dcol, info_L, dx, dz_2, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info_L, d_position); // Host csrsv hipDeviceProp_t prop; CHECK_HIP_ERROR(hipGetDeviceProperties(&prop, 0)); position_gold = csr_lsolve(HIPSPARSE_OPERATION_NON_TRANSPOSE, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hz_gold.data(), idx_base, HIPSPARSE_DIAG_TYPE_UNIT, prop.warpSize); // Check zero pivot results unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); // If zero pivot was found, do not go further if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } // Copy output from device to CPU std::vector hz_1(m); std::vector hz_2(m); CHECK_HIP_ERROR(hipMemcpy(hz_1.data(), dz_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hz_2.data(), dz_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Check z #if defined(__HIP_PLATFORM_AMD__) unit_check_general(1, m, 1, hz_gold.data(), hz_1.data()); unit_check_general(1, m, 1, hz_gold.data(), hz_2.data()); #elif defined(__HIP_PLATFORM_NVIDIA__) unit_check_near(1, m, 1, hz_gold.data(), hz_1.data()); unit_check_near(1, m, 1, hz_gold.data(), hz_2.data()); #endif // Solve Uy = z // host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, &h_alpha, descr_U, dval, dptr, dcol, info_U, dz_1, dy_1, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info_U, &hposition_1); // device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, HIPSPARSE_OPERATION_NON_TRANSPOSE, m, nnz, d_alpha, descr_U, dval, dptr, dcol, info_U, dz_2, dy_2, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer_sv)); // Check for zero pivot pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info_U, d_position); // Host csrsv position_gold = csr_usolve(HIPSPARSE_OPERATION_NON_TRANSPOSE, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hz_gold.data(), hy_gold.data(), idx_base, HIPSPARSE_DIAG_TYPE_NON_UNIT, prop.warpSize); // Check zero pivot results unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); // If zero pivot was found, do not go further if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } // Copy output from device to CPU std::vector hy_1(m); std::vector hy_2(m); CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Check z unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRILUSOLVE_HPP ./clients/include/testing_spmm_batched_csc.hpp0000664000175100017510000005254715176134511021734 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BATCHED_CSC_HPP #define TESTING_SPMM_BATCHED_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_batched_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; float alpha = 0.6; float beta = 0.2; size_t safe_size = 100; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* drow = (int32_t*)drow_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsc(&A, m, k, nnz, dptr, drow, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); int batch_count_A; int batch_count_B; int batch_count_C; int64_t offsets_batch_stride_A; int64_t rows_values_batch_stride_A; int64_t batch_stride_B; int64_t batch_stride_C; // C_i = A * B_i batch_count_A = 1; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = 0; rows_values_batch_stride_A = 0; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B batch_count_A = 10; batch_count_B = 1; batch_count_C = 5; offsets_batch_stride_A = (k + 1); rows_values_batch_stride_A = nnz; batch_stride_B = 0; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B_i batch_count_A = 10; batch_count_B = 10; batch_count_C = 5; offsets_batch_stride_A = (k + 1); rows_values_batch_stride_A = nnz; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success( hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_batched_csc(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; J batch_count_A = 1; J batch_count_B = 3; J batch_count_C = 3; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsc_col_ptr_temp; std::vector hcsc_row_ind_temp; std::vector hcsc_val_temp; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, nnz_A, hcsc_col_ptr_temp, hcsc_row_ind_temp, hcsc_val_temp, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; int64_t offsets_batch_stride_A = (batch_count_A > 1) ? (A_n + 1) : 0; int64_t rows_values_batch_stride_A = (batch_count_A > 1) ? nnz_A : 0; int64_t batch_stride_B = (batch_count_B > 1) ? nnz_B : 0; int64_t batch_stride_C = (batch_count_C > 1) ? nnz_C : 0; // Allocate host memory for all batches of A matrix std::vector hcsc_col_ptr(batch_count_A * (A_n + 1)); std::vector hcsc_row_ind(batch_count_A * nnz_A); std::vector hcsc_val(batch_count_A * nnz_A); for(J i = 0; i < batch_count_A; i++) { for(J j = 0; j < (A_n + 1); j++) { hcsc_col_ptr[(A_n + 1) * i + j] = hcsc_col_ptr_temp[j]; } for(I j = 0; j < nnz_A; j++) { hcsc_row_ind[nnz_A * i + j] = hcsc_row_ind_temp[j]; hcsc_val[nnz_A * i + j] = hcsc_val_temp[j]; } } // Allocate host memory for vectors std::vector hB(batch_count_B * nnz_B); std::vector hC_1(batch_count_C * nnz_C); std::vector hC_2(batch_count_C * nnz_C); std::vector hC_gold(batch_count_C * nnz_C); hipsparseInit(hB, batch_count_B * nnz_B, 1); hipsparseInit(hC_1, batch_count_C * nnz_C, 1); // copy vector is easy in STL; hC_gold = hC: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_n + 1)), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_B * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (A_n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(drow, hcsc_row_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsc_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dB, hB.data(), sizeof(T) * batch_count_B * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&A, A_m, A_n, nnz_A, dptr, drow, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCsrSetStridedBatch( A, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C1, batch_count_C, batch_stride_C)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C2, batch_count_C, batch_stride_C)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hC_1.data(), dC_1, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); // CPU host_cscmm_batched(A_m, n, A_n, batch_count_A, (I)offsets_batch_stride_A, (I)rows_values_batch_stride_A, transA, transB, h_alpha, hcsc_col_ptr.data(), hcsc_row_ind.data(), hcsc_val.data(), hB.data(), (J)ldb, batch_count_B, (I)batch_stride_B, orderB, h_beta, hC_gold.data(), (J)ldc, batch_count_C, (I)batch_stride_C, orderC, idx_base); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = batch_count_C * spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = cscmm_batched_gbyte_count(A_n, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, batch_count_A, batch_count_B, batch_count_C, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::batch_countA, batch_count_A, display_key_t::batch_countB, batch_count_B, display_key_t::batch_countC, batch_count_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BATCHED_CSC_HPP ./clients/include/testing_csrsort.hpp0000664000175100017510000002655015176134511020150 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSORT_HPP #define TESTING_CSRSORT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_csrsort_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; size_t buffer_size = 0; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto perm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); int* perm = (int*)perm_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, (int*)nullptr, csr_col_ind, &buffer_size), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr, (int*)nullptr, &buffer_size), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, csr_row_ptr, csr_col_ind, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsort_bufferSizeExt( (hipsparseHandle_t) nullptr, m, n, nnz, csr_row_ptr, csr_col_ind, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort(handle, m, n, nnz, descr, (int*)nullptr, csr_col_ind, perm, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort(handle, m, n, nnz, descr, csr_row_ptr, (int*)nullptr, perm, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsort(handle, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsort(handle, m, n, nnz, (hipsparseMatDescr_t) nullptr, csr_row_ptr, csr_col_ind, perm, buffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsort( (hipsparseHandle_t) nullptr, m, n, nnz, descr, csr_row_ptr, csr_col_ind, perm, buffer)); #endif } hipsparseStatus_t testing_csrsort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int permute = argus.permute; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort CSR columns std::vector hperm(nnz); std::vector hcsr_col_ind_unsorted(nnz); std::vector hcsr_val_unsorted(nnz); hcsr_col_ind_unsorted = hcsr_col_ind; hcsr_val_unsorted = hcsr_val; for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; int row_nnz = row_end - row_begin; for(int j = row_begin; j < row_end; ++j) { int rng = row_begin + rand() % row_nnz; int temp_col = hcsr_col_ind_unsorted[j]; float temp_val = hcsr_val_unsorted[j]; hcsr_col_ind_unsorted[j] = hcsr_col_ind_unsorted[rng]; hcsr_val_unsorted[j] = hcsr_val_unsorted[rng]; hcsr_col_ind_unsorted[rng] = temp_col; hcsr_val_unsorted[rng] = temp_val; } } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dcsr_val_sorted_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dperm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); float* dcsr_val = (float*)dcsr_val_managed.get(); float* dcsr_val_sorted = (float*)dcsr_val_sorted_managed.get(); // Set permutation vector, if asked for int* dperm = permute ? (int*)dperm_managed.get() : nullptr; // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_unsorted.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort_bufferSizeExt( handle, m, n, nnz, dcsr_row_ptr, dcsr_col_ind, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } if(argus.unit_check) { // Sort CSR columns CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort( handle, m, n, nnz, descr, dcsr_row_ptr, dcsr_col_ind, dperm, dbuffer)); if(permute) { // Sort CSR values CHECK_HIPSPARSE_ERROR(hipsparseSgthr( handle, nnz, dcsr_val, dcsr_val_sorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); } // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_unsorted.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); if(permute) { CHECK_HIP_ERROR(hipMemcpy(hcsr_val_unsorted.data(), dcsr_val_sorted, sizeof(float) * nnz, hipMemcpyDeviceToHost)); } // Unit check unit_check_general(1, nnz, 1, hcsr_col_ind.data(), hcsr_col_ind_unsorted.data()); if(permute) { unit_check_general(1, nnz, 1, hcsr_val.data(), hcsr_val_unsorted.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort( handle, m, n, nnz, descr, dcsr_row_ptr, dcsr_col_ind, dperm, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsort( handle, m, n, nnz, descr, dcsr_row_ptr, dcsr_col_ind, dperm, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csrsort_gbyte_count(m, nnz, permute); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::permute, (permute ? "yes" : "no"), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSORT_HPP ./clients/include/testing_bsrxmv.hpp0000664000175100017510000007260415176134511017773 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRXMV_HPP #define TESTING_BSRXMV_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrxmv_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 100; int safe_dim = 2; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dend_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dmask_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dend_ptr = (int*)dend_ptr_managed.get(); int* dmask_ptr = (int*)dmask_ptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); // Test hipsparseXbsrxmv verify_hipsparse_status_invalid_handle(hipsparseXbsrxmv(nullptr, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, (T*)nullptr, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, nullptr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, (T*)nullptr, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, nullptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_mask_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, nullptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, nullptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_end_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, nullptr, safe_dim, dx, &beta, dy), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, (T*)nullptr, &beta, dy), "Error: xy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, (T*)nullptr), "Error: y is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, -1, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: sizeOfMask is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, -1, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, -1, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: nb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, -1, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, safe_dim, dx, &beta, dy), "Error: nnzb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrxmv(handle, dirA, transA, safe_size, safe_size, safe_size, safe_size, &alpha, descr, dval, dmask_ptr, dptr, dend_ptr, dcol, -1, dx, &beta, dy), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsrxmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) hipsparseDirection_t dir = HIPSPARSE_DIRECTION_COLUMN; hipsparseOperation_t trans = HIPSPARSE_OPERATION_NON_TRANSPOSE; static constexpr int size_of_mask = 1; static constexpr int mb = 2; static constexpr int nb = 3; static constexpr int nnzb = 5; static constexpr int block_dim = 2; T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); // clang-format off std::vector hbsr_val = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0), make_DataType(17.0), make_DataType(18.0), make_DataType(19.0), make_DataType(20.0)}; std::vector hbsr_mask_ptr = {2}; std::vector hbsr_row_ptr = {1, 4}; std::vector hbsr_end_ptr = {1, 5}; std::vector hbsr_col_ind = {1, 2, 1, 2, 3}; std::vector hx = {make_DataType(1.0), make_DataType(1.0), make_DataType(1.0), make_DataType(1.0), make_DataType(1.0), make_DataType(1.0)}; std::vector hy = { make_DataType(2.0), make_DataType(2.0), make_DataType(2.0), make_DataType(2.0)}; std::vector hyref = {make_DataType(2.0), make_DataType(2.0), make_DataType(58.0), make_DataType(62.0)}; // clang-format on auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * block_dim * block_dim * nnzb), device_free}; auto dbsr_mask_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * size_of_mask), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * mb), device_free}; auto dbsr_end_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * mb), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * block_dim * nb), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * block_dim * mb), device_free}; T* dbsr_val = (T*)dbsr_val_managed.get(); int* dbsr_mask_ptr = (int*)dbsr_mask_ptr_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_end_ptr = (int*)dbsr_end_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dbsr_mask_ptr, hbsr_mask_ptr.data(), sizeof(int) * size_of_mask, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * mb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_end_ptr, hbsr_end_ptr.data(), sizeof(int) * mb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * nb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ONE; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); hipsparseStatus_t status = hipsparseXbsrxmv(handle, dir, trans, size_of_mask, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_mask_ptr, dbsr_row_ptr, dbsr_end_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy); verify_hipsparse_status_success(status, "bsrxmv failed."); CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); unit_check_near(1, mb * block_dim, 1, hyref.data(), hy.data()); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRXMV_HPP ./clients/include/display.hpp0000664000175100017510000004135615176134305016363 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief display.hpp provides common testing utilities. */ #pragma once #ifndef DISPLAY_HPP #define DISPLAY_HPP #include #include #include #include #include #include #include #include static constexpr const char* s_timing_info_perf = "GFlop/s"; static constexpr const char* s_timing_info_bandwidth = "GB/s"; static constexpr const char* s_timing_info_time = "msec"; static constexpr const char* s_analysis_timing_info_time = "analysis msec"; hipsparseStatus_t hipsparse_record_output_legend(const std::string& s); hipsparseStatus_t hipsparse_record_output(const std::string& s); hipsparseStatus_t hipsparse_record_timing(double msec, double gflops, double gbs); bool display_timing_info_is_stdout_disabled(); inline auto& operator<<(std::ostream& out, const hipComplex& z) { std::stringstream ss; ss << '(' << z.x << ',' << z.y << ')'; return out << ss.str(); } inline auto& operator<<(std::ostream& out, const hipDoubleComplex& z) { std::stringstream ss; ss << '(' << z.x << ',' << z.y << ')'; return out << ss.str(); } struct display_key_t { // // Enumerate keys. // typedef enum enum_ { gflops = 0, bandwidth, time_ms, iters, function, ctype, itype, jtype, size, M, N, K, LD, Mb, MbA, MbC, Nb, NbA, NbC, Kb, nrhs, ell_width, ell_nnz, coo_nnz, nnz, nnzA, nnzB, nnzC, nnzb, nnzbA, nnzbC, block_dim, row_block_dim, row_block_dimA, row_block_dimC, col_block_dim, col_block_dimA, col_block_dimC, batch_count, batch_countA, batch_countB, batch_countC, batch_stride, alpha, beta, percentage, threshold, trans, transA, transB, transC, transX, direction, order, format, fill_mode, diag_type, solve_policy, action, partition, algorithm, permute } key_t; static const char* to_str(key_t key_) { switch(key_) { case gflops: { return s_timing_info_perf; } case bandwidth: { return s_timing_info_bandwidth; } case time_ms: { return s_timing_info_time; } case iters: { return "iters"; } case function: { return "function"; } case ctype: { return "ctype"; } case itype: { return "itype"; } case jtype: { return "jtype"; } case size: { return "size"; } case M: { return "M"; } case N: { return "N"; } case K: { return "K"; } case LD: { return "LD"; } case Mb: { return "Mb"; } case MbA: { return "MbA"; } case MbC: { return "MbC"; } case Nb: { return "Nb"; } case NbA: { return "NbA"; } case NbC: { return "NbC"; } case Kb: { return "Kb"; } case nrhs: { return "nrhs"; } case ell_width: { return "ell_width"; } case ell_nnz: { return "ell_nnz"; } case coo_nnz: { return "coo_nnz"; } case nnz: { return "nnz"; } case nnzA: { return "nnzA"; } case nnzB: { return "nnzB"; } case nnzC: { return "nnzC"; } case nnzb: { return "nnzb"; } case nnzbA: { return "nnzbA"; } case nnzbC: { return "nnzbC"; } case block_dim: { return "block_dim"; } case row_block_dim: { return "row_block_dim"; } case row_block_dimA: { return "row_block_dimA"; } case row_block_dimC: { return "row_block_dimC"; } case col_block_dim: { return "col_block_dim"; } case col_block_dimA: { return "col_block_dimA"; } case col_block_dimC: { return "col_block_dimC"; } case batch_count: { return "batch_count"; } case batch_countA: { return "batch_countA"; } case batch_countB: { return "batch_countB"; } case batch_countC: { return "batch_countC"; } case batch_stride: { return "batch_stride"; } case alpha: { return "alpha"; } case beta: { return "beta"; } case percentage: { return "percentage"; } case threshold: { return "threshold"; } case trans: { return "trans"; } case transA: { return "transA"; } case transB: { return "transB"; } case transC: { return "transC"; } case transX: { return "transX"; } case direction: { return "dir"; } case order: { return "order"; } case format: { return "format"; } case fill_mode: { return "uplo"; } case diag_type: { return "diag"; } case solve_policy: { return "solve_policy"; } case action: { return "action"; } case partition: { return "partition"; } case algorithm: { return "algorithm"; } case permute: { return "permute"; } default: { return nullptr; } } } }; template inline const char* display_to_string(S s) { return s; }; template <> inline const char* display_to_string(display_key_t::key_t s) { return display_key_t::to_str(s); }; // // Template to display timing information. // template inline void display_timing_info_legend(std::ostream& out, int n, S name, T t) { out << std::setw(n) << display_to_string(name); } template inline void display_timing_info_legend(std::ostream& out, int n, S name, T t, Ts... ts) { out << std::setw(n) << display_to_string(name); display_timing_info_legend(out, n, ts...); } template inline void display_timing_info_values(std::ostream& out, int n, S name, T t) { out << std::setw(n) << t; } template inline void display_timing_info_values(std::ostream& out, int n, S name, T t, Ts... ts) { out << std::setw(n) << t; display_timing_info_values(out, n, ts...); } template inline void display_timing_info_legend_noresults(std::ostream& out, int n, S name_, T t) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << name; } } template inline void display_timing_info_legend_noresults(std::ostream& out, int n, S name_, T t, Ts... ts) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << name; } display_timing_info_legend_noresults(out, n, ts...); } template inline void display_timing_info_values_noresults(std::ostream& out, int n, S name_, T t) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << t; } } template inline void display_timing_info_values_noresults(std::ostream& out, int n, S name_, T t, Ts... ts) { const char* name = display_to_string(name_); if(strcmp(name, s_timing_info_perf) && strcmp(name, s_timing_info_bandwidth) && strcmp(name, s_timing_info_time)) { out << " " << t; } display_timing_info_values_noresults(out, n, ts...); } template inline void grab_results(double values[3], display_key_t::key_t key, T t) { } template <> inline void grab_results(double values[3], display_key_t::key_t key, double t) { const char* name = display_to_string(key); if(!strcmp(name, s_timing_info_perf)) { values[1] = t; } else if(!strcmp(name, s_timing_info_bandwidth)) { values[2] = t; } else if(!strcmp(name, s_timing_info_time)) { values[0] = t; } } template inline void grab_results(double values[3], const char* name, T t) { } template <> inline void grab_results(double values[3], const char* name, double t) { if(!strcmp(name, s_timing_info_perf)) { values[1] = t; } else if(!strcmp(name, s_timing_info_bandwidth)) { values[2] = t; } else if(!strcmp(name, s_timing_info_time)) { values[0] = t; } } template inline void display_timing_info_grab_results(double values[3], S name, T t) { grab_results(values, name, t); } template inline void display_timing_info_grab_results(double values[3], S name, T t, Ts... ts) { grab_results(values, name, t); display_timing_info_grab_results(values, ts...); } //bool display_timing_info_is_stdout_disabled(); template inline void display_timing_info_generate(std::ostream& out, int n, S name, T t, Ts... ts) { double values[3]{}; display_timing_info_grab_results(values, name, t, ts...); hipsparse_record_timing(values[0], values[1], values[2]); display_timing_info_values(out, n, name, t, ts...); } template inline void display_timing_info_generate_params(std::ostream& out, int n, S name, T t, Ts... ts) { double values[3]{}; display_timing_info_grab_results(values, name, t, ts...); hipsparse_record_timing(values[0], values[1], values[2]); display_timing_info_values_noresults(out, n, name, t, ts...); } template inline void display_timing_info_max_size_strings(int mx[1], S name_, T t) { const char* name = display_to_string(name_); int len = strlen(name); mx[0] = std::max(len, mx[0]); } template inline void display_timing_info_max_size_strings(int mx[1], S name_, T t, Ts... ts) { const char* name = display_to_string(name_); int len = strlen(name); mx[0] = std::max(len, mx[0]); display_timing_info_max_size_strings(mx, ts...); } template inline void display_timing_info_main(S name, Ts... ts) { // // To configure the size of std::setw. // int n = 0; display_timing_info_max_size_strings(&n, name, ts...); // // // n += 4; // // Legend // { std::ostringstream out_legend; out_legend.precision(2); out_legend.setf(std::ios::fixed); out_legend.setf(std::ios::left); if(!display_timing_info_is_stdout_disabled()) { display_timing_info_legend(out_legend, n, name, ts...); std::cout << out_legend.str() << std::endl; } else { // store the string. display_timing_info_legend_noresults(out_legend, n, name, ts...); hipsparse_record_output_legend(out_legend.str()); } } std::ostringstream out; out.precision(2); out.setf(std::ios::fixed); out.setf(std::ios::left); if(!display_timing_info_is_stdout_disabled()) { display_timing_info_generate(out, n, name, ts...); std::cout << out.str() << std::endl; } else { display_timing_info_generate_params(out, n, name, ts...); // store the string. hipsparse_record_output(out.str()); } } inline void hipsparse_get_matrixname(const char* f, char* name) { int n = 0; while(f[n] != '\0') ++n; int cdir = 0; for(int i = 0; i < n; ++i) { if(f[i] == '/' || f[i] == '\\') { cdir = i + 1; } } int ddir = cdir; for(int i = cdir; i < n; ++i) { if(f[i] == '.') { ddir = i; } } if(ddir == cdir) { ddir = n; } for(int i = cdir; i < ddir; ++i) { name[i - cdir] = f[i]; } name[ddir - cdir] = '\0'; } #define display_timing_info(...) \ do \ { \ const char* ctypename = hipsparse_datatype2string(argus.compute_type); \ const char* itypename = hipsparse_indextype2string(argus.index_type_I); \ const char* jtypename = hipsparse_indextype2string(argus.index_type_J); \ \ display_timing_info_main(__VA_ARGS__, \ display_key_t::iters, \ argus.iters, \ "verified", \ (argus.unit_check ? "yes" : "no"), \ display_key_t::function, \ &argus.function[0], \ display_key_t::ctype, \ ctypename, \ display_key_t::itype, \ itypename, \ display_key_t::jtype, \ jtypename); \ } while(false) #endif // DISPLAY_HPP ./clients/include/testing_spmm_csr.hpp0000664000175100017510000004634615176134511020301 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_CSR_HPP #define TESTING_SPMM_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // // ! // #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, k, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); #endif // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMMAlg_t alg = static_cast(argus.spmm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; // Allocate host memory for vectors std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, nnz_B, 1); hipsparseInit(hC_1, nnz_C, 1); hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // Copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (A_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, A_m, A_n, nnz_A, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // CPU host_csrmm(A_m, n, A_n, transA, transB, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hB.data(), (J)ldb, orderB, h_beta, hC_gold.data(), (J)ldc, orderC, idx_base, false); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrmm_gbyte_count( A_m, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_CSR_HPP ./clients/include/testing_dense_to_sparse_csr.hpp0000664000175100017510000003360615176134511022475 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE_TO_SPARSE_CSR_HPP #define TESTING_DENSE_TO_SPARSE_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_dense_to_sparse_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsr_row_ptr = (int32_t*)dcsr_row_ptr_managed.get(); int32_t* dcsr_col_ind = (int32_t*)dcsr_col_ind_managed.get(); float* dcsr_val = (float*)dcsr_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseDnVecDescr_t matA; hipsparseSpMatDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateDnMat(&matA, m, n, ld, ddense_val, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&matB, m, n, nnz, dcsr_row_ptr, dcsr_col_ind, dcsr_val, iType, jType, idxBase, dataType), "success"); // denseToSparse buffer size verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse analysis verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_analysis(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse_convert verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_convert(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(matB), "success"); #endif } template hipsparseStatus_t testing_dense_to_sparse_csr(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDenseToSparseAlg_t alg = static_cast(argus.dense2sparse_alg); hipsparseOrder_t order = argus.orderA; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; // Host structures I nrow = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncol = (order == HIPSPARSE_ORDER_COL) ? n : ld; std::vector hdense_val(nrow * ncol); if(order == HIPSPARSE_ORDER_COL) { for(int i = 0; i < n; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } else { for(int i = 0; i < m; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, order, 0.2); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrow * ncol), device_free}; I* dptr = (I*)dptr_managed.get(); T* ddense = (T*)ddense_managed.get(); // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * nrow * ncol, hipMemcpyHostToDevice)); // Create dense matrix hipsparseDnMatDescr_t matA; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matA, m, n, ld, ddense, typeT, order)); // Create matrices hipsparseSpMatDescr_t matB; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&matB, m, n, 0, dptr, nullptr, nullptr, typeI, typeJ, idx_base, typeT)); // Query DenseToSparse buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_analysis(handle, matA, matB, alg, buffer)); int64_t rows, cols, nnz; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(matB, &rows, &cols, &nnz)); auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseCsrSetPointers(matB, dptr, dcol, dval)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); // copy output from device to CPU std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr.data(), dptr, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcol, sizeof(J) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_val.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); std::vector hcsr_row_ptr_cpu(m + 1); std::vector hcsr_col_ind_cpu(nnz); std::vector hcsr_val_cpu(nnz); std::vector hnnz_per_row(m, 0); if(order == HIPSPARSE_ORDER_COL) { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hnnz_per_row[i]++; } } } } else { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hnnz_per_row[i]++; } } } } hcsr_row_ptr_cpu[0] = idx_base; for(J i = 0; i < m; ++i) { hcsr_row_ptr_cpu[i + 1] = hnnz_per_row[i] + hcsr_row_ptr_cpu[i]; } if(order == HIPSPARSE_ORDER_COL) { int index = 0; for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hcsr_val_cpu[index] = hdense_val[j * ld + i]; hcsr_col_ind_cpu[index] = j + idx_base; index++; } } } } else { int index = 0; for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hcsr_val_cpu[index] = hdense_val[i * ld + j]; hcsr_col_ind_cpu[index] = j + idx_base; index++; } } } } unit_check_general(1, (m + 1), 1, hcsr_row_ptr_cpu.data(), hcsr_row_ptr.data()); unit_check_general(1, nnz, 1, hcsr_col_ind_cpu.data(), hcsr_col_ind.data()); unit_check_general(1, nnz, 1, hcsr_val_cpu.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2csx_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_densetosparsealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE_TO_SPARSE_CSR_HPP ./clients/include/testing_doti.hpp0000664000175100017510000001731315176134511017405 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DOTI_HPP #define TESTING_DOTI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_doti_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); T result; verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, (T*)nullptr, dx_ind, dy, &result, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, (int*)nullptr, dy, &result, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, dx_ind, (T*)nullptr, &result, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, idx_base), "Error: result is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXdoti((hipsparseHandle_t) nullptr, nnz, dx_val, dx_ind, dy, &result, idx_base)); #endif } template hipsparseStatus_t testing_doti(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Grab stream used by handle hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); T hresult_1; T hresult_2; T hresult_gold; // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dresult_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult_2 = (T*)dresult_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, dresult_2, idx_base)); // copy output from device to CPU^ CHECK_HIP_ERROR(hipMemcpy(&hresult_2, dresult_2, sizeof(T), hipMemcpyDeviceToHost)); // CPU hresult_gold = make_DataType(0.0); for(int i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(hy[hx_ind[i] - idx_base], hx_val[i]); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, 1, 1, &hresult_gold, &hresult_1); unit_check_general(1, 1, 1, &hresult_gold, &hresult_2); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdoti(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTI_HPP ./clients/include/testing_csrsm2.hpp0000664000175100017510000016060615176134511017663 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSM2_HPP #define TESTING_CSRSM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrsm2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nrhs = 100; int nnz = 100; int safe_size = 100; T h_alpha = make_DataType(0.6); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsm2_info(new csrsm2_struct); csrsm2Info_t info = unique_ptr_csrsm2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); size_t size; int position; verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size), "Error: dalpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (size_t*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, &size), "Error: dB is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsm2_bufferSizeExt((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dalpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, dbuffer), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsm2_analysis((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, dB, safe_size, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, (T*)nullptr, safe_size, info, policy, dbuffer), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, (csrsm2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsm2_solve((hipsparseHandle_t) nullptr, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB, safe_size, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsm2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsm2_zeroPivot(handle, (csrsm2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsm2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrsm2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int nrhs = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsm2_info(new csrsm2_struct); csrsm2Info_t info = unique_ptr_csrsm2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, uplo)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int ldb = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : nrhs; std::vector hB_1(m * nrhs); std::vector hB_2(m * nrhs); std::vector hB_gold(m * nrhs); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; hipsparseInit(hB_1, 1, m * nrhs); hB_2 = hB_1; hB_gold = hB_1; // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * nrhs), device_free}; auto dB_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * nrhs), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB_1 = (T*)dB_1_managed.get(); T* dB_2 = (T*)dB_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB_1, hB_1.data(), sizeof(T) * m * nrhs, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrsm2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_bufferSizeExt(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; CHECK_HIP_ERROR(hipMemcpy(dB_2, hB_2.data(), sizeof(T) * m * nrhs, hipMemcpyHostToDevice)); // csrsm2 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXcsrsm2_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csrsm2 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_analysis(handle, 0, transA, transB, m, nrhs, nnz, d_alpha, descr, dval, dptr, dcol, dB_2, ldb, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXcsrsm2_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } if(argus.unit_check) { // csrsm2 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXcsrsm2_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csrsm2 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, d_alpha, descr, dval, dptr, dcol, dB_2, ldb, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXcsrsm2_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hB_1.data(), dB_1, sizeof(T) * m * nrhs, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hB_2.data(), dB_2, sizeof(T) * m * nrhs, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host csrsm2 host_csrsm2(m, nrhs, nnz, transA, transB, h_alpha, hcsr_row_ptr, hcsr_col_ind, hcsr_val, hB_gold, ldb, HIPSPARSE_ORDER_COL, diag, uplo, idx_base, &h_analysis_pivot_gold, &h_solve_pivot_gold); // Check pivots unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); // Check solution matrix if no pivot has been found if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, m * nrhs, 1, hB_gold.data(), hB_1.data()); unit_check_near(1, m * nrhs, 1, hB_gold.data(), hB_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsm2_solve(handle, 0, transA, transB, m, nrhs, nnz, &h_alpha, descr, dval, dptr, dcol, dB_1, ldb, info, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, nnz, diag) * nrhs; double gbyte_count = csrsv_gbyte_count(m, nnz) * nrhs; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::nrhs, nrhs, display_key_t::alpha, h_alpha, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::diag_type, hipsparse_diagtype2string(diag), display_key_t::fill_mode, hipsparse_fillmode2string(uplo), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSM2_HPP ./clients/include/testing_spsm_csr.hpp0000664000175100017510000004466115176134511020305 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSM_CSR_HPP #define TESTING_SPSM_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSMAlg_t alg = HIPSPARSE_SPSM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; hipsparseSpSMDescr_t descr; verify_hipsparse_status_success(hipsparseSpSM_createDescr(&descr), "success"); size_t bsize; // Create SpSM structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, idxType, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, m, k, m, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, k, m, dC, dataType, order), "success"); // SpSM buffer verify_hipsparse_status_invalid_handle(hipsparseSpSM_bufferSize( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, &bsize), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSM analysis verify_hipsparse_status_invalid_handle(hipsparseSpSM_analysis( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); // SpSM solve verify_hipsparse_status_invalid_handle( hipsparseSpSM_solve(nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseSpSM_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spsm_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSMAlg_t alg = static_cast(argus.spsm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } if(m != n) { // Skip non-square matrices return HIPSPARSE_STATUS_SUCCESS; } // Some matrix properties J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J C_m = m; J C_n = k; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * m) : (int64_t(ld_multiplier_B) * k)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * m)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * k); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, 1, nnz_B); hC_1 = hB; hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSMDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, m, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_bufferSize( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); J struct_pivot = -1; J numeric_pivot = -1; host_csrsm(m, k, nnz, transA, transB, h_alpha, hcsr_row_ptr, hcsr_col_ind, hcsr_val, hB, (J)ldb, orderB, hC_gold, (J)ldc, orderC, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag) * k; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrsv_gbyte_count(m, nnz) * k; double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSM_CSR_HPP ./clients/include/testing_csrmv.hpp0000664000175100017510000003432315176134511017600 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRMV_HPP #define TESTING_CSRMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrmv_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int n = 100; int m = 100; int nnz = 100; int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, (int*)nullptr, dcol, dx, &beta, dy), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, (int*)nullptr, dx, &beta, dy), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, (T*)nullptr, dptr, dcol, dx, &beta, dy), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, (T*)nullptr, &beta, dy), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, (T*)nullptr), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, (T*)nullptr, descr, dval, dptr, dcol, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrmv( handle, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmv(handle, transA, m, n, nnz, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrmv((hipsparseHandle_t) nullptr, transA, m, n, nnz, &alpha, descr, dval, dptr, dcol, dx, &beta, dy)); #endif } template hipsparseStatus_t testing_csrmv(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int nrow = argus.M; int ncol = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, nrow, ncol, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrow : ncol; int n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ncol : nrow; std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (nrow + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (nrow + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv( handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv( handle, transA, nrow, ncol, nnz, d_alpha, descr, dval, dptr, dcol, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); host_csrmv(transA, nrow, ncol, nnz, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hx.data(), h_beta, hy_gold.data(), idx_base); unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv(handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmv(handle, transA, nrow, ncol, nnz, &h_alpha, descr, dval, dptr, dcol, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(nrow, nnz, h_beta != make_DataType(0.0)); double gbyte_count = csrmv_gbyte_count(nrow, ncol, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, nrow, display_key_t::N, ncol, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMV_HPP ./clients/include/testing_csrgemm2_a.hpp0000664000175100017510000024436715176134511020500 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEMM2_A_HPP #define TESTING_CSRGEMM2_A_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgemm2_a_bad_arg(void) { #if(!defined(CUDART_VERSION)) int M = 1; int N = 1; int K = 1; int nnz_A = 1; int nnz_B = 1; int safe_size = 1; T alpha = 1.0; size_t size; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // Scenario: alpha != 0 and beta == 0 verify_hipsparse_status_invalid_handle( hipsparseXcsrgemm2_bufferSizeExt((hipsparseHandle_t) nullptr, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, (T*)nullptr, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, (hipsparseMatDescr_t) nullptr, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, (int*)nullptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, (int*)nullptr, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, (int*)nullptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, (int*)nullptr, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, &size), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, (csrgemm2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, &alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (int*)nullptr, (int*)nullptr, info, (size_t*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemm2Nnz((hipsparseHandle_t) nullptr, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, (hipsparseMatDescr_t) nullptr, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, (int*)nullptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, (int*)nullptr, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, (int*)nullptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, (int*)nullptr, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, (hipsparseMatDescr_t) nullptr, dCptr, &nnz_C, info, dbuffer), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, (int*)nullptr, &nnz_C, info, dbuffer), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, (int*)nullptr, info, dbuffer), "Error: nnz_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, (csrgemm2Info_t) nullptr, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, nullptr, 0, nullptr, nullptr, descr_C, dCptr, &nnz_C, info, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemm2((hipsparseHandle_t) nullptr, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, (T*)nullptr, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, (hipsparseMatDescr_t) nullptr, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, (T*)nullptr, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dAval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, (int*)nullptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, (int*)nullptr, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, (T*)nullptr, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dBval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, (int*)nullptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, (int*)nullptr, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, (hipsparseMatDescr_t) nullptr, dCval, dCptr, dCcol, info, dbuffer), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, (T*)nullptr, dCptr, dCcol, info, dbuffer), "Error: dCval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, (int*)nullptr, dCcol, info, dbuffer), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, (int*)nullptr, info, dbuffer), "Error: dCcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, (csrgemm2Info_t) nullptr, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm2(handle, M, N, K, &alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, (hipsparseMatDescr_t) nullptr, 0, (T*)nullptr, (int*)nullptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol, info, (void*)nullptr), "Error: dbuffer is nullptr"); #endif } template hipsparseStatus_t testing_csrgemm2_a(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; int K = argus.K; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; T alpha = make_DataType(argus.alpha); T* h_alpha = α std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = unique_ptr_descr_D->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); if(M == 0 || N == 0 || K == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, K, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_row_ptr_B; std::vector hcsr_col_ind_B; std::vector hcsr_val_B; std::vector hcsr_row_ptr_D; std::vector hcsr_col_ind_D; std::vector hcsr_val_D; // B = A^T so that we can compute the square of A N = M; int nnz_B = nnz_A; hcsr_row_ptr_B.resize(K + 1, 0); hcsr_col_ind_B.resize(nnz_B); hcsr_val_B.resize(nnz_B); // B = A^T transpose_csr(M, K, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idx_base_A, idx_base_B); // Allocate memory on device int one = 1; int safe_K = std::max(K, one); int safe_nnz_A = std::max(nnz_A, one); int safe_nnz_B = std::max(nnz_B, one); auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_K + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_B), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); T* dalpha = (T*)dalpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (K + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dalpha, h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrgemm2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, K, h_alpha, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (T*)nullptr, descr_D, 0, nullptr, nullptr, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrgemm2 nnz // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_D, 0, nullptr, nullptr, descr_C, dCptr, &hnnz_C_1, info, dbuffer)); // Allocate result matrix int safe_nnz_C = std::max(hnnz_C_1, one); auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_C), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_C), device_free}; int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); if(argus.unit_check) { // hipsparse pointer mode device auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_D, 0, nullptr, nullptr, descr_C, dCptr, dnnz_C, info, dbuffer)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); double cpu_time_used = get_time_us(); int nnz_C_gold = host_csrgemm2_nnz(M, N, K, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), (T*)nullptr, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C, HIPSPARSE_INDEX_BASE_ZERO); // If nnz_C == 0, we are done if(nnz_C_gold == 0) { return HIPSPARSE_STATUS_SUCCESS; } std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(M, N, K, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), (T*)nullptr, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_val_D.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C, HIPSPARSE_INDEX_BASE_ZERO); cpu_time_used = get_time_us() - cpu_time_used; // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Compute csrgemm2 CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, K, h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, descr_D, 0, (T*)nullptr, nullptr, nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer)); // Copy output from device to CPU std::vector hcsr_row_ptr_C(M + 1); std::vector hcsr_col_ind_C(nnz_C_gold); std::vector hcsr_val_C_1(nnz_C_gold); std::vector hcsr_val_C_2(nnz_C_gold); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr_C.data(), dCptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C.data(), dCcol, sizeof(int) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemset(dCval, 0, sizeof(T) * nnz_C_gold)); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); #ifdef __HIP_PLATFORM_AMD__ // Device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, K, dalpha, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (T*)nullptr, descr_D, 0, (T*)nullptr, nullptr, nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); // Check device pointer results unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); #endif } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEMM2_A_HPP ./clients/include/testing_coosort.hpp0000664000175100017510000003206015176134511020132 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_COOSORT_HPP #define TESTING_COOSORT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_coosort_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; size_t buffer_size = 0; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto coo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto perm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* coo_row_ind = (int*)coo_row_ind_managed.get(); int* coo_col_ind = (int*)coo_col_ind_managed.get(); int* perm = (int*)perm_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, (int*)nullptr, coo_col_ind, &buffer_size), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind, (int*)nullptr, &buffer_size), "Error: coo_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, coo_row_ind, coo_col_ind, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcoosort_bufferSizeExt( (hipsparseHandle_t) nullptr, m, n, nnz, coo_row_ind, coo_col_ind, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByRow(handle, m, n, nnz, (int*)nullptr, coo_col_ind, perm, buffer), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByRow(handle, m, n, nnz, coo_row_ind, (int*)nullptr, perm, buffer), "Error: coo_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByRow(handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcoosortByRow( (hipsparseHandle_t) nullptr, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByColumn(handle, m, n, nnz, (int*)nullptr, coo_col_ind, perm, buffer), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByColumn(handle, m, n, nnz, coo_row_ind, (int*)nullptr, perm, buffer), "Error: coo_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoosortByColumn(handle, m, n, nnz, coo_row_ind, coo_col_ind, perm, (int*)nullptr), "Error: buffer is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcoosortByColumn( (hipsparseHandle_t) nullptr, m, n, nnz, coo_row_ind, coo_col_ind, perm, buffer)); #endif } hipsparseStatus_t testing_coosort(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; int n = argus.N; int by_row = (argus.transA == HIPSPARSE_OPERATION_NON_TRANSPOSE); int permute = argus.permute; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcoo_row_ind; std::vector hcoo_col_ind; std::vector hcoo_val; // Read or construct CSR matrix int nnz = 0; if(!generate_coo_matrix(filename, m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Unsort COO columns std::vector hcoo_row_ind_unsorted(nnz); std::vector hcoo_col_ind_unsorted(nnz); std::vector hcoo_val_unsorted(nnz); hcoo_row_ind_unsorted = hcoo_row_ind; hcoo_col_ind_unsorted = hcoo_col_ind; hcoo_val_unsorted = hcoo_val; for(int i = 0; i < nnz; ++i) { int rng = rand() % nnz; int temp_row = hcoo_row_ind_unsorted[i]; int temp_col = hcoo_col_ind_unsorted[i]; float temp_val = hcoo_val_unsorted[i]; hcoo_row_ind_unsorted[i] = hcoo_row_ind_unsorted[rng]; hcoo_col_ind_unsorted[i] = hcoo_col_ind_unsorted[rng]; hcoo_val_unsorted[i] = hcoo_val_unsorted[rng]; hcoo_row_ind_unsorted[rng] = temp_row; hcoo_col_ind_unsorted[rng] = temp_col; hcoo_val_unsorted[rng] = temp_val; } // If coosort by column, sort host arrays by column if(!by_row) { std::vector hperm(nnz); for(int i = 0; i < nnz; ++i) { hperm[i] = i; } std::sort(hperm.begin(), hperm.end(), [&](const int& a, const int& b) { if(hcoo_col_ind_unsorted[a] < hcoo_col_ind_unsorted[b]) { return true; } else if(hcoo_col_ind_unsorted[a] == hcoo_col_ind_unsorted[b]) { return (hcoo_row_ind_unsorted[a] < hcoo_row_ind_unsorted[b]); } else { return false; } }); for(int i = 0; i < nnz; ++i) { hcoo_row_ind[i] = hcoo_row_ind_unsorted[hperm[i]]; hcoo_col_ind[i] = hcoo_col_ind_unsorted[hperm[i]]; hcoo_val[i] = hcoo_val_unsorted[hperm[i]]; } } // Allocate memory on the device auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcoo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcoo_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dcoo_val_sorted_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dperm_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); int* dcoo_col_ind = (int*)dcoo_col_ind_managed.get(); float* dcoo_val = (float*)dcoo_val_managed.get(); float* dcoo_val_sorted = (float*)dcoo_val_sorted_managed.get(); // Set permutation vector, if asked for int* dperm = permute ? (int*)dperm_managed.get() : nullptr; // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcoo_row_ind, hcoo_row_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcoo_col_ind, hcoo_col_ind_unsorted.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcoo_val, hcoo_val_unsorted.data(), sizeof(float) * nnz, hipMemcpyHostToDevice)); // Obtain buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcoosort_bufferSizeExt( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(permute) { // Initialize perm with identity permutation CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, nnz, dperm)); } if(argus.unit_check) { // Sort CSR columns if(by_row) { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByRow( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } else { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByColumn( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } if(permute) { // Sort CSR values CHECK_HIPSPARSE_ERROR(hipsparseSgthr( handle, nnz, dcoo_val, dcoo_val_sorted, dperm, HIPSPARSE_INDEX_BASE_ZERO)); } // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcoo_row_ind_unsorted.data(), dcoo_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcoo_col_ind_unsorted.data(), dcoo_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); if(permute) { CHECK_HIP_ERROR(hipMemcpy(hcoo_val_unsorted.data(), dcoo_val_sorted, sizeof(float) * nnz, hipMemcpyDeviceToHost)); } // Unit check unit_check_general(1, nnz, 1, hcoo_row_ind.data(), hcoo_row_ind_unsorted.data()); unit_check_general(1, nnz, 1, hcoo_col_ind.data(), hcoo_col_ind_unsorted.data()); if(permute) { unit_check_general(1, nnz, 1, hcoo_val.data(), hcoo_val_unsorted.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { if(by_row) { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByRow( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } else { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByColumn( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { if(by_row) { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByRow( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } else { CHECK_HIPSPARSE_ERROR(hipsparseXcoosortByColumn( handle, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dperm, dbuffer)); } } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = coosort_gbyte_count(nnz, permute); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::permute, (permute ? "yes" : "no"), display_key_t::direction, (by_row ? "row" : "column"), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_COOSORT_HPP ./clients/include/testing_axpyi.hpp0000664000175100017510000002003415176134511017572 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_AXPYI_HPP #define TESTING_AXPYI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_axpyi_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; T alpha = make_DataType(0.6); hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dxVal_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dxInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dxVal = (T*)dxVal_managed.get(); int* dxInd = (int*)dxInd_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, dxVal, (int*)nullptr, dy, idx_base), "Error: xInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, (T*)nullptr, dxInd, dy, idx_base), "Error: xVal is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, &alpha, dxVal, dxInd, (T*)nullptr, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXaxpyi(handle, nnz, (T*)nullptr, dxVal, dxInd, dy, idx_base), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXaxpyi((hipsparseHandle_t) nullptr, nnz, &alpha, dxVal, dxInd, dy, idx_base)); #endif } template hipsparseStatus_t testing_axpyi(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hxInd(nnz); std::vector hxVal(nnz); std::vector hy_1(N); std::vector hy_2(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hxInd.data(), nnz, 1, N); hipsparseInit(hxVal, 1, nnz); hipsparseInit(hy_1, 1, N); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dxInd_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dxVal_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dxInd = (int*)dxInd_managed.get(); T* dxVal = (T*)dxVal_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dxInd, hxInd.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dxVal, hxVal.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * N, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXaxpyi(handle, nnz, d_alpha, dxVal, dxInd, dy_2, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * N, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hy_gold[hxInd[i] - idx_base] = hy_gold[hxInd[i] - idx_base] + testing_mult(h_alpha, hxVal[i]); } unit_check_general(1, N, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXaxpyi(handle, nnz, &h_alpha, dxVal, dxInd, dy_1, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = axpyi_gflop_count(nnz); double gbyte_count = axpby_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::size, N, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_AXPYI_HPP ./clients/include/testing_prune_csr2csr_by_percentage.hpp0000664000175100017510000014017415176134511024131 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP #define TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_csr2csr_by_percentage_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int nnz_A = 1; T percentage = static_cast(0); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneCsr2csrByPercentage_bufferSize status = hipsparseXpruneCsr2csrByPercentage_bufferSize(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrByPercentage_bufferSize(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneCsr2csrNnzByPercentage status = hipsparseXpruneCsr2csrNnzByPercentage(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)-1, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is less than 0"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)101, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is greater than 100"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, nullptr, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, nullptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); status = hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); // Test hipsparseXpruneCsr2csrByPercentage status = hipsparseXpruneCsr2csrByPercentage(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrByPercentage(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)-1, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is less than 0"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (T)101, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: percentage is greater than 100"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_A is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, nullptr, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, (T*)nullptr, csr_row_ptr_C, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, nullptr, csr_col_ind_C, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_C is nullptr"); status = hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, percentage, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_csr2csr_by_percentage(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; T percentage = make_DataType(argus.percentage); hipsparseIndexBase_t csr_idx_base_A = argus.baseA; hipsparseIndexBase_t csr_idx_base_C = argus.baseB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, csr_idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, csr_idx_base_C)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate device memory auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto d_csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr_C = (int*)d_csr_row_ptr_C_managed.get(); int* d_csr_row_ptr_A = (int*)d_csr_row_ptr_A_managed.get(); int* d_csr_col_ind_A = (int*)d_csr_col_ind_A_managed.get(); T* d_csr_val_A = (T*)d_csr_val_A_managed.get(); // Transfer. CHECK_HIP_ERROR(hipMemcpy( d_csr_row_ptr_A, h_csr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( d_csr_col_ind_A, h_csr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(d_csr_val_A, h_csr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage_bufferSize(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, (const T*)nullptr, d_csr_row_ptr_C, (const int*)nullptr, info, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); std::vector h_nnz_total_dev_host_ptr(1); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_row_ptr_C, &h_nnz_total_dev_host_ptr[0], info, d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnzByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_row_ptr_C, d_nnz_total_dev_host_ptr, info, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind_C = (int*)d_csr_col_ind_C_managed.get(); T* d_csr_val_C = (T*)d_csr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); std::vector h_csr_row_ptr_C(M + 1); std::vector h_csr_col_ind_C(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val_C(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr_C.data(), d_csr_row_ptr_C, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind_C.data(), d_csr_col_ind_C, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val_C.data(), d_csr_val_C, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_C_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_csr_to_csr_by_percentage(M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, h_nnz_C_cpu[0], h_csr_row_ptr_cpu, h_csr_col_ind_cpu, h_csr_val_cpu, csr_idx_base_A, csr_idx_base_C, percentage); unit_check_general(1, 1, 1, h_nnz_C_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrByPercentage(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, percentage, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, info, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_csr2csr_by_percentage_gbyte_count(M, nnz_A, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzC, h_nnz_total_dev_host_ptr[0], display_key_t::percentage, percentage, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_BY_PERCENTAGE_HPP ./clients/include/testing_scatter.hpp0000664000175100017510000001552715176134511020120 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SCATTER_HPP #define TESTING_SCATTER_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_scatter_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Scatter verify_hipsparse_status_invalid_handle(hipsparseScatter(nullptr, x, y)); verify_hipsparse_status_invalid_pointer(hipsparseScatter(handle, nullptr, y), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseScatter(handle, x, nullptr), "Error: y is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_scatter(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I size = argus.N; I nnz = argus.nnz; hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(size); std::vector hy_gold(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, size); hy_gold = hy; // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); if(argus.unit_check) { // Scatter CHECK_HIPSPARSE_ERROR(hipsparseScatter(handle, x, y)); // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * size, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < nnz; ++i) { hy_gold[hx_ind[i] - idxBase] = hx_val[i]; } // Verify results against host unit_check_general(1, size, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseScatter(handle, x, y)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseScatter(handle, x, y)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = sctr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SCATTER_HPP ./clients/include/testing_sparse_to_dense_csr.hpp0000664000175100017510000002765015176134511022477 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPARSE_TO_DENSE_CSR_HPP #define TESTING_SPARSE_TO_DENSE_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_sparse_to_dense_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseSparseToDenseAlg_t alg = HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsr_row_ptr = (int32_t*)dcsr_row_ptr_managed.get(); int32_t* dcsr_col_ind = (int32_t*)dcsr_col_ind_managed.get(); float* dcsr_val = (float*)dcsr_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseSpMatDescr_t matA; hipsparseDnVecDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success(hipsparseCreateCsr(&matA, m, n, nnz, dcsr_row_ptr, dcsr_col_ind, dcsr_val, iType, jType, idxBase, dataType), "success"); verify_hipsparse_status_success( hipsparseCreateDnMat(&matB, m, n, ld, ddense_val, dataType, order), "success"); // SparseToDense buffer size verify_hipsparse_status_invalid_handle( hipsparseSparseToDense_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // SparseToDense verify_hipsparse_status_invalid_handle(hipsparseSparseToDense(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSparseToDense(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(matB), "success"); #endif } template hipsparseStatus_t testing_sparse_to_dense_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) J m = argus.M; J n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSparseToDenseAlg_t alg = static_cast(argus.sparse2dense_alg); hipsparseOrder_t order = argus.orderA; std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; I nrows = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncols = (order == HIPSPARSE_ORDER_COL) ? n : ld; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrows * ncols), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* ddense = (T*)ddense_managed.get(); // Dense matrix std::vector hdense(nrows * ncols); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t matA; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&matA, m, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrix hipsparseDnMatDescr_t matB; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matB, m, n, ld, ddense, typeT, order)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hdense.data(), ddense, sizeof(T) * nrows * ncols, hipMemcpyDeviceToHost)); std::vector hdense_cpu(nrows * ncols); if(order == HIPSPARSE_ORDER_COL) { for(I col = 0; col < n; ++col) { for(I row = 0; row < m; ++row) { hdense_cpu[row + ld * col] = make_DataType(0.0); } } for(J row = 0; row < m; ++row) { I start = hcsr_row_ptr[row] - idx_base; I end = hcsr_row_ptr[row + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[ld * (hcsr_col_ind[at] - idx_base) + row] = hcsr_val[at]; } } unit_check_general(m, n, ld, hdense_cpu.data(), hdense.data()); } else { for(I row = 0; row < m; ++row) { for(I col = 0; col < n; ++col) { hdense_cpu[ld * row + col] = make_DataType(0.0); } } for(J row = 0; row < m; ++row) { I start = hcsr_row_ptr[row] - idx_base; I end = hcsr_row_ptr[row + 1] - idx_base; for(I at = start; at < end; ++at) { hdense_cpu[(hcsr_col_ind[at] - idx_base) + ld * row] = hcsr_val[at]; } } } unit_check_general(1, nrows * ncols, 1, hdense_cpu.data(), hdense.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSparseToDense(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csx2dense_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_sparsetodensealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPARSE_TO_DENSE_CSR_HPP ./clients/include/testing_const_spmat_descr.hpp0000664000175100017510000013616515176134305022170 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_SPMAT_DESCR_HPP #define TESTING_CONST_SPMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include #include using namespace hipsparse_test; void testing_const_spmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t nnz = 100; int64_t ell_cols = 10; int64_t ell_blocksize = 2; hipsparseIndexType_t rowType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t colType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; hipsparseFormat_t format = HIPSPARSE_FORMAT_CSR; // Allocate memory on device auto row_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto col_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; const int* row_data = (int*)row_data_managed.get(); const int* col_data = (int*)col_data_managed.get(); const float* val_data = (float*)val_data_managed.get(); hipsparseConstSpMatDescr_t A; // hipsparseCreateConstCoo verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCoo( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCoo( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCoo( &A, rows, cols, -1, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCoo( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateConstCsr verify_hipsparse_status_invalid_pointer(hipsparseCreateConstCsr(nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsr( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsr( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsr( &A, rows, cols, -1, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsr( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, colType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsr( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, colType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsr( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, colType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateConstCsc verify_hipsparse_status_invalid_pointer(hipsparseCreateConstCsc(nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsc( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsc( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstCsc( &A, rows, cols, -1, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsc( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, colType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsc( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, colType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstCsc( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, colType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateConstBlockedEll verify_hipsparse_status_invalid_pointer(hipsparseCreateConstBlockedEll(nullptr, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, -1, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, rows, -1, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, rows, cols, -1, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: ell_blocksize is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstBlockedEll( &A, rows, cols, ell_blocksize, -1, col_data, val_data, colType, idxBase, dataType), "Error: ell_cols is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, nullptr, val_data, colType, idxBase, dataType), "Error: ellColInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, col_data, nullptr, colType, idxBase, dataType), "Error: ellValue is nullptr"); // hipsparseDestroySpMat verify_hipsparse_status_invalid_pointer(hipsparseDestroySpMat(nullptr), "Error: A is nullptr"); // Create valid descriptors hipsparseConstSpMatDescr_t coo; hipsparseConstSpMatDescr_t csr; hipsparseConstSpMatDescr_t csc; hipsparseConstSpMatDescr_t bell; verify_hipsparse_status_success(hipsparseCreateConstBlockedEll(&bell, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success( hipsparseCreateConstCoo( &coo, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateConstCsr(&csr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateConstCsc(&csc, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Success"); const void* row_ptr; const void* col_ptr; const void* val_ptr; // hipsparseConstCooGet verify_hipsparse_status_invalid_pointer(hipsparseConstCooGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCooGet(coo, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseConstCsrGet verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &colType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &colType, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseConstCsrGet verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(nullptr, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, nullptr, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, nullptr, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, nullptr, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, nullptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, nullptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, nullptr, &colType, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseConstBlockedEllGet verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(nullptr, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, nullptr, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, nullptr, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, nullptr, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_blocksize is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, nullptr, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, nullptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ellColInd"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, nullptr, &colType, &idxBase, &dataType), "Error: ellValue is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: ellIdxType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, nullptr), "Error: valueType is nullptr"); // hipsparseSpMatGetSize verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(nullptr, &rows, &cols, &nnz), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, nullptr, &cols, &nnz), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, nullptr, &nnz), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, &cols, nullptr), "Error: nnz is nullptr"); // hipsparseSpMatGetFormat verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(nullptr, &format), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(coo, nullptr), "Error: format is nullptr"); // hipsparseSpMatGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(nullptr, &idxBase), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(coo, nullptr), "Error: idxBase is nullptr"); // hipsparseConstSpMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstSpMatGetValues(nullptr, &val_ptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstSpMatGetValues(coo, nullptr), "Error: val_ptr is nullptr"); int batch_count = 100; // hipsparseSpMatGetStridedBatch verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(nullptr, &batch_count), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(coo, nullptr), "Error: batch count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(csr, nullptr), "Error: batch count is nullptr"); // Destroy valid descriptors verify_hipsparse_status_success(hipsparseDestroySpMat(coo), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csc), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csr), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(bell), "Success"); #endif } #endif // TESTING_CONST_SPMAT_DESCR_HPP ./clients/include/testing_bsrilu02.hpp0000664000175100017510000011616315176134511020113 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRILU02_HPP #define TESTING_BSRILU02_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrilu02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int mb = 100; int nnzb = 100; int block_dim = 4; int safe_size = 100; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrilu02(new bsrilu02_struct); bsrilu02Info_t info = unique_ptr_bsrilu02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; auto dboost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto dboost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); double* dboost_tol = (double*)dboost_tol_managed.get(); T* dboost_val = (T*)dboost_val_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_bufferSize(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_bufferSize(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsrilu02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsrilu02_bufferSize((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_handle(hipsparseXbsrilu02_numericBoost( (hipsparseHandle_t) nullptr, info, 1, dboost_tol, dboost_val)); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_numericBoost( handle, (bsrilu02Info_t) nullptr, 1, dboost_tol, dboost_val), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_numericBoost(handle, info, 1, (double*)nullptr, dboost_val), "Error: boost_tol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_numericBoost(handle, info, 1, dboost_tol, (T*)nullptr), "Error: boost_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrilu02_analysis((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrilu02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsrilu02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrilu02((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrilu02_zeroPivot(handle, (bsrilu02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsrilu02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_bsrilu02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int block_dim = argus.block_dim; int boost = argus.numericboost; double boost_tol = argus.boosttol; T boost_val = make_DataType(argus.boostval, argus.boostvali); hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrilu02(new bsrilu02_struct); bsrilu02Info_t info = unique_ptr_bsrilu02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto boost_tol_managed = hipsparse_unique_ptr{device_malloc(sizeof(double)), device_free}; auto boost_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); double* dboost_tol = (double*)boost_tol_managed.get(); T* dboost_val = (T*)boost_val_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_1_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto dbsr_val_2_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val_1 = (T*)dbsr_val_1_managed.get(); T* dbsr_val_2 = (T*)dbsr_val_2_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind)); CHECK_HIP_ERROR(hipMemcpy( dbsr_val_2, dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToDevice)); // Host BSR matrix std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); std::vector hbsr_val_orig(nnzb * block_dim * block_dim); // Copy device BSR matrix to host CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_orig.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Obtain bsrilu02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_bufferSize(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; if(argus.unit_check) { hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; CHECK_HIP_ERROR(hipMemcpy(dboost_tol, &boost_tol, sizeof(double), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dboost_val, &boost_val, sizeof(T), hipMemcpyHostToDevice)); // bsrilu02 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXbsrilu02_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsrilu02 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXbsrilu02_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsrilu02 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXbsrilu02_numericBoost(handle, info, boost, &boost_tol, &boost_val)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXbsrilu02_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsrilu02 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXbsrilu02_numericBoost(handle, info, boost, dboost_tol, dboost_val)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXbsrilu02_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU std::vector result_1(block_dim * block_dim * nnzb); std::vector result_2(block_dim * block_dim * nnzb); CHECK_HIP_ERROR(hipMemcpy(result_1.data(), dbsr_val_1, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result_2.data(), dbsr_val_2, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrilu02 int numerical_pivot; int structural_pivot; host_bsrilu02(dir, mb, block_dim, hbsr_row_ptr, hbsr_col_ind, hbsr_val, idx_base, &structural_pivot, &numerical_pivot, boost, boost_tol, boost_val); h_analysis_pivot_gold = structural_pivot; // Solve pivot gives the first numerical or structural non-invertible block if(structural_pivot == -1) { h_solve_pivot_gold = numerical_pivot; } else if(numerical_pivot == -1) { h_solve_pivot_gold = structural_pivot; } else { h_solve_pivot_gold = std::min(numerical_pivot, structural_pivot); } unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_1.data()); unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXbsrilu02_numericBoost(handle, info, 0, (double*)nullptr, (T*)nullptr)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); } double gpu_time_used = 0; // Solve run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXbsrilu02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = gpu_time_used / number_hot_calls; double gbyte_count = bsrilu0_gbyte_count(mb, block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::Mb, mb, display_key_t::nnzb, nnzb, display_key_t::block_dim, block_dim, display_key_t::direction, hipsparse_direction2string(dir), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRILU02_HPP ./clients/include/testing_bsrsv2.hpp0000664000175100017510000012730115176134511017666 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRSV2_HPP #define TESTING_BSRSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrsv2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int block_dim = 2; int safe_size = 100; T h_alpha = make_DataType(0.6); hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsv2_info(new bsrsv2_struct); bsrsv2Info_t info = unique_ptr_bsrsv2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, (int*)nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, dptr, (int*)nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize( handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_bufferSize(handle, dirA, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_bufferSize(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_bufferSize((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_analysis(handle, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_analysis((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, block_dim, info, dx, dy, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, (T*)nullptr, dy, policy, dbuffer), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, (T*)nullptr, policy, dbuffer), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, (T*)nullptr, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_solve(handle, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, (bsrsv2Info_t) nullptr, dx, dy, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsrsv2_solve((hipsparseHandle_t) nullptr, dirA, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, block_dim, info, dx, dy, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsv2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsrsv2_zeroPivot(handle, (bsrsv2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsrsv2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_bsrsv2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int block_dim = argus.block_dim; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDirection_t dir = argus.dirA; hipsparseOperation_t trans = argus.transA; hipsparseDiagType_t diag_type = argus.diag_type; hipsparseFillMode_t fill_mode = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsv2_info(new bsrsv2_struct); bsrsv2Info_t info = unique_ptr_bsrsv2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag_type)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, fill_mode)); if(m == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; std::vector hx(mb * block_dim); std::vector hy_1(mb * block_dim); std::vector hy_2(mb * block_dim); std::vector hy_gold(mb * block_dim); hipsparseInit(hx, 1, mb * block_dim); // Allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dy_1, hy_1.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Obtain bsrsv2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_bufferSize(handle, dir, trans, mb, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // bsrsv2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_analysis(handle, dir, trans, mb, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); if(argus.unit_check) { CHECK_HIP_ERROR( hipMemcpy(dy_2, hy_2.data(), sizeof(T) * mb * block_dim, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXbsrsv2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, d_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_2, policy, dbuffer)); hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXbsrsv2_zeroPivot(handle, info, d_position); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR( hipMemcpy(hy_1.data(), dy_1, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hy_2.data(), dy_2, sizeof(T) * mb * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrsv2 std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); int struct_position_gold; int position_gold; bsrsv(trans, dir, mb, nnzb, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hx.data(), hy_gold.data(), diag_type, fill_mode, idx_base, &struct_position_gold, &position_gold); unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(1, mb * block_dim, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, mb * block_dim, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsv2_solve(handle, dir, trans, mb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dx, dy_1, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(mb * block_dim, size_t(nnzb) * block_dim * block_dim, diag_type); double gbyte_count = bsrsv_gbyte_count(mb, nnzb, block_dim); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnzb * block_dim * block_dim, display_key_t::alpha, h_alpha, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::diag_type, hipsparse_diagtype2string(diag_type), display_key_t::fill_mode, hipsparse_fillmode2string(fill_mode), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP ./clients/include/testing_dotci.hpp0000664000175100017510000001740415176134511017551 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2019-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DOTCI_HPP #define TESTING_DOTCI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_dotci_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); T result; verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, (T*)nullptr, dx_ind, dy, &result, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, (int*)nullptr, dy, &result, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, dx_ind, (T*)nullptr, &result, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, idx_base), "Error: result is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXdotci((hipsparseHandle_t) nullptr, nnz, dx_val, dx_ind, dy, &result, idx_base)); #endif } template hipsparseStatus_t testing_dotci(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Grab stream used by handle hipStream_t stream; CHECK_HIPSPARSE_ERROR(hipsparseGetStream(handle, &stream)); // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); T hresult_1; T hresult_2; T hresult_gold; // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dresult_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); T* dresult_2 = (T*)dresult_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, dresult_2, idx_base)); // copy output from device to CPU^ CHECK_HIP_ERROR(hipMemcpy(&hresult_2, dresult_2, sizeof(T), hipMemcpyDeviceToHost)); // CPU hresult_gold = make_DataType(0.0); for(int i = 0; i < nnz; ++i) { hresult_gold = hresult_gold + testing_mult(testing_conj(hx_val[i]), hy[hx_ind[i] - idx_base]); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, 1, 1, &hresult_gold, &hresult_1); unit_check_general(1, 1, 1, &hresult_gold, &hresult_2); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXdotci(handle, nnz, dx_val, dx_ind, dy, &hresult_1, idx_base)); CHECK_HIP_ERROR(hipStreamSynchronize(stream)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = doti_gflop_count(nnz); double gbyte_count = doti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DOTCI_HPP ./clients/include/testing_gebsr2gebsc.hpp0000664000175100017510000007570015176134511020642 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEBSR2GEBSC_HPP #define TESTING_GEBSR2GEBSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2gebsc_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; static const size_t safe_size = 1; auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); auto bsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; void* buffer = buffer_managed.get(); int* bsc_row_ind = (int*)bsc_row_ind_managed.get(); int* bsc_col_ptr = (int*)bsc_col_ptr_managed.get(); T* bsc_val = (T*)bsc_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(bsc_col_ptr, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); size_t buffer_size; status = hipsparseXgebsr2gebsc_bufferSize(nullptr, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXgebsr2gebsc_bufferSize(handle, -1, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, -1, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, -1, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, nullptr, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_val is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, nullptr, bsr_col_ind, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, nullptr, safe_size, safe_size, &buffer_size); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, -1, safe_size, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, -1, &buffer_size); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); status = hipsparseXgebsr2gebsc_bufferSize(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer_size is nullptr"); // Test hipsparseXgebsr2gebsc() status = hipsparseXgebsr2gebsc(nullptr, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXgebsr2gebsc(handle, -1, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: mb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, -1, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: nb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, -1, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: nnzb is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, nullptr, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: bsr_val is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, nullptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_row_ptr is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, nullptr, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsr_col_ind is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, -1, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: row_block_dim is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, -1, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_size(status, "Error: col_block_dim is invalid"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, nullptr, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_val is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, nullptr, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_row_ind is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, nullptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, buffer); verify_hipsparse_status_invalid_pointer(status, "Error: bsc_col_ptr is nullptr"); status = hipsparseXgebsr2gebsc(handle, safe_size, safe_size, safe_size, bsr_val, bsr_row_ptr, bsr_col_ind, safe_size, safe_size, bsc_val, bsc_row_ind, bsc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is invalid"); #endif } #define DEVICE_ALLOC(TYPE, NAME, SIZE) \ auto NAME##_managed = hipsparse_unique_ptr{device_malloc(sizeof(TYPE) * SIZE), device_free}; \ TYPE* NAME = (TYPE*)NAME##_managed.get() template hipsparseStatus_t testing_gebsr2gebsc(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; hipsparseAction_t action = argus.action; hipsparseIndexBase_t base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } int mb = m * row_block_dim; int nb = n * col_block_dim; srand(12345ULL); // Host structures std::vector hbsr_row_ptr; std::vector hbsr_col_ind; std::vector hbsr_val; // Read or construct CSR matrix int nnzb = 0; if(!generate_csr_matrix(filename, mb, nb, nnzb, hbsr_row_ptr, hbsr_col_ind, hbsr_val, base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } m = mb * row_block_dim; n = nb * col_block_dim; size_t nnz = nnzb * row_block_dim * col_block_dim; // Now use the csr matrix as the symbolic for the gebsr matrix. hbsr_val.resize(nnz); for(size_t i = 0; i < nnz; ++i) { hbsr_val[i] = random_generator(); } DEVICE_ALLOC(int, dbsr_row_ptr, (mb + 1)); DEVICE_ALLOC(int, dbsr_col_ind, nnzb); DEVICE_ALLOC(T, dbsr_val, (nnzb * row_block_dim * col_block_dim)); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * row_block_dim * col_block_dim, hipMemcpyHostToDevice)); // Obtain required buffer size (from host) size_t buffer_size; CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc_bufferSize(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, &buffer_size)); // Allocate the buffer size. auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; void* dbuffer = dbuffer_managed.get(); DEVICE_ALLOC(int, dbsc_row_ind, nnzb); DEVICE_ALLOC(int, dbsc_col_ptr, (nb + 1)); DEVICE_ALLOC(T, dbsc_val, (nnzb * row_block_dim * col_block_dim)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); // Transfer to host. std::vector hbsc_from_device_row_ind(nnzb); std::vector hbsc_from_device_col_ptr(nb + 1); std::vector hbsc_from_device_val(nnzb * row_block_dim * col_block_dim); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_col_ptr.data(), dbsc_col_ptr, sizeof(int) * (nb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_row_ind.data(), dbsc_row_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsc_from_device_val.data(), dbsc_val, sizeof(T) * nnzb * row_block_dim * col_block_dim, hipMemcpyDeviceToHost)); // Allocate host bsc matrix. std::vector hbsc_row_ind(nnzb); std::vector hbsc_col_ptr(nb + 1); std::vector hbsc_val(nnzb * row_block_dim * col_block_dim); host_gebsr_to_gebsc(mb, nb, nnzb, hbsr_row_ptr, hbsr_col_ind, hbsr_val, row_block_dim, col_block_dim, hbsc_row_ind, hbsc_col_ptr, hbsc_val, action, base); unit_check_general(1, nb + 1, 1, hbsc_from_device_col_ptr.data(), hbsc_col_ptr.data()); unit_check_general(1, nnzb, 1, hbsc_from_device_row_ind.data(), hbsc_row_ind.data()); if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnzb * row_block_dim * col_block_dim, 1, hbsc_from_device_val.data(), hbsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2gebsc(handle, mb, nb, nnzb, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, dbsc_val, dbsc_row_ind, dbsc_col_ptr, action, base, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2gebsc_gbyte_count(mb, nb, nnzb, row_block_dim, col_block_dim, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::nnzb, nnzb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2GEBSC_HPP ./clients/include/testing_csr2coo.hpp0000664000175100017510000001466315176134511020025 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2COO_HPP #define TESTING_CSR2COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2coo_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* coo_row_ind = (int*)coo_row_ind_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2coo(handle, (int*)nullptr, nnz, m, coo_row_ind, idx_base), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsr2coo(handle, csr_row_ptr, nnz, m, (int*)nullptr, idx_base), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsr2coo((hipsparseHandle_t) nullptr, csr_row_ptr, nnz, m, coo_row_ind, idx_base)); #endif } template hipsparseStatus_t testing_csr2coo(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); // Copy output from device to host std::vector hcoo_row_ind(nnz); CHECK_HIP_ERROR( hipMemcpy(hcoo_row_ind.data(), dcoo_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); // CPU conversion to COO std::vector hcoo_row_ind_gold(nnz); for(int i = 0; i < m; ++i) { int row_begin = hcsr_row_ptr[i] - idx_base; int row_end = hcsr_row_ptr[i + 1] - idx_base; for(int j = row_begin; j < row_end; ++j) { hcoo_row_ind_gold[j] = i + idx_base; } } // Unit check unit_check_general(1, nnz, 1, hcoo_row_ind_gold.data(), hcoo_row_ind.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcsr2coo(handle, dcsr_row_ptr, nnz, m, dcoo_row_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2coo_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2COO_HPP ./clients/include/hipsparse_test_cleanup.hpp0000664000175100017510000000445515176134305021461 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_TEST_CLEANUP_HPP #define HIPSPARSE_TEST_CLEANUP_HPP #include #include /*! \brief Test cleanup handler. Frees memory or performs other cleanup at specified points in program. */ class test_cleanup { static auto& stack() { // Placed inside function to avoid dependency on initialization order static std::stack> stack; return stack; } public: // Run all cleanup handlers pushed so far, in LIFO order static void cleanup() { while(!stack().empty()) { stack().top()(); stack().pop(); } } // Create an object and register a cleanup handler template static T* allocate(T** ptr, Args&&... args) { *ptr = nullptr; stack().push([=] { delete *ptr; *ptr = nullptr; }); return new T(std::forward(args)...); } }; #endif // HIPSPARSE_TEST_CLEANUP_HPP./clients/include/testing_csrmm.hpp0000664000175100017510000007150515176134511017572 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRMM_HPP #define TESTING_CSRMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrmm_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int N = 100; int M = 100; int K = 100; int ldb = 100; int ldc = 100; int nnz = 100; int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, -1, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: M < 0"); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, M, -1, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: N < 0"); verify_hipsparse_status_invalid_size(hipsparseXcsrmm2(handle, transA, transB, M, N, -1, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: K < 0"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, (int*)nullptr, dcol, dB, ldb, &beta, dC, ldc), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, (int*)nullptr, dB, ldb, &beta, dC, ldc), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, (T*)nullptr, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, (T*)nullptr, ldb, &beta, dC, ldc), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, (T*)nullptr, ldc), "Error: dC is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, (T*)nullptr, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, (T*)nullptr, dC, ldc), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc), "Error: descr is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrmm2((hipsparseHandle_t) nullptr, transA, transB, M, N, K, nnz, &alpha, descr, dval, dptr, dcol, dB, ldb, &beta, dC, ldc)); #endif } template hipsparseStatus_t testing_csrmm(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int M = argus.M; int N = argus.N; int K = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptrA; std::vector hcsr_col_indA; std::vector hcsr_valA; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, M, K, nnz, hcsr_row_ptrA, hcsr_col_indA, hcsr_valA, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties int A_m = M; int B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? K : M) : N; int B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? N : (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? K : M); int C_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE ? M : K); int C_n = N; int ldb = B_m; int ldc = C_m; int nrowB = ldb; int ncolB = B_n; int nrowC = ldc; int ncolC = C_n; int Bnnz = nrowB * ncolB; int Cnnz = nrowC * ncolC; // Host structures - Dense matrix B and C std::vector hB(Bnnz); std::vector hC_1(Cnnz); std::vector hC_2(Cnnz); std::vector hC_gold(Cnnz); hipsparseInit(hB, nrowB, ncolB); hipsparseInit(hC_1, nrowC, ncolC); // copy vector is easy in STL; hC_gold = hC_1: save a copy in hy_gold which will be output of // CPU hC_gold = hC_1; hC_2 = hC_1; // allocate memory on device auto dcsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (A_m + 1)), device_free}; auto dcsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_valA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Bnnz), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptrA = (int*)dcsr_row_ptrA_managed.get(); int* dcsr_col_indA = (int*)dcsr_col_indA_managed.get(); T* dcsr_valA = (T*)dcsr_valA_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptrA, hcsr_row_ptrA.data(), sizeof(int) * (A_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indA, hcsr_col_indA.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_valA, hcsr_valA.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * Bnnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, d_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, d_beta, dC_2, ldc)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); // CPU host_csrmm(M, N, K, transA, transB, h_alpha, hcsr_row_ptrA.data(), hcsr_col_indA.data(), hcsr_valA.data(), hB.data(), ldb, HIPSPARSE_ORDER_COL, h_beta, hC_gold.data(), ldc, HIPSPARSE_ORDER_COL, idx_base, false); unit_check_near(nrowC, ncolC, ldc, hC_gold.data(), hC_1.data()); unit_check_near(nrowC, ncolC, ldc, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrmm2(handle, transA, transB, M, N, K, nnz, &h_alpha, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, dB, ldb, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrmm_gflop_count(B_m, nnz, C_m * C_n, h_beta != make_DataType(0.0)); double gbyte_count = csrmm_gbyte_count( A_m, nnz, B_m * B_n, C_m * C_n, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::nnzA, nnz, display_key_t::nnzB, B_m * B_n, display_key_t::nnzC, C_m * C_n, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRMM_HPP ./clients/include/testing_prune_csr2csr.hpp0000664000175100017510000011165515176134511021244 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_CSR2CSR_HPP #define TESTING_PRUNE_CSR2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_csr2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int nnz_A = 1; T threshold = static_cast(1); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (safe_size + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneCsr2csr_bufferSize status = hipsparseXpruneCsr2csr_bufferSize(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csr_bufferSize(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneCsr2csrNnz status = hipsparseXpruneCsr2csrNnz(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csrNnz(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, &threshold, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (const T*)nullptr, descr_C, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, nullptr, csr_row_ptr_C, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, nullptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_row_ptr_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test hipsparseXpruneCsr2csr status = hipsparseXpruneCsr2csr(nullptr, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneCsr2csr(handle, -1, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneCsr2csr(handle, M, -1, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneCsr2csr(handle, M, N, -1, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: nnz_A is invalid"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, nullptr, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, (const T*)nullptr, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, nullptr, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, nullptr, &threshold, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_A is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, (const T*)nullptr, descr_C, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, nullptr, csr_val_C, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, (T*)nullptr, csr_row_ptr_C, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, nullptr, csr_col_ind_C, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr_C is nullptr"); status = hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, csr_val_A, csr_row_ptr_A, csr_col_ind_A, &threshold, descr_C, csr_val_C, csr_row_ptr_C, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind_C is nullptr"); #endif } template hipsparseStatus_t testing_prune_csr2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; T threshold = make_DataType(argus.threshold); hipsparseIndexBase_t csr_idx_base_A = argus.baseA; hipsparseIndexBase_t csr_idx_base_C = argus.baseB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, csr_idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, csr_idx_base_C)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector h_csr_row_ptr_A; std::vector h_csr_col_ind_A; std::vector h_csr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, csr_idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate device memory auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto d_csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto d_csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr_C = (int*)d_csr_row_ptr_C_managed.get(); int* d_csr_row_ptr_A = (int*)d_csr_row_ptr_A_managed.get(); int* d_csr_col_ind_A = (int*)d_csr_col_ind_A_managed.get(); T* d_csr_val_A = (T*)d_csr_val_A_managed.get(); // Transfer. CHECK_HIP_ERROR(hipMemcpy( d_csr_row_ptr_A, h_csr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( d_csr_col_ind_A, h_csr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(d_csr_val_A, h_csr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); size_t buffer_size = 4; CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr_bufferSize(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, (const T*)nullptr, d_csr_row_ptr_C, (const int*)nullptr, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_threshold, &threshold, sizeof(T), hipMemcpyHostToDevice)); std::vector h_nnz_total_dev_host_ptr(1); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_row_ptr_C, &h_nnz_total_dev_host_ptr[0], d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csrNnz(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, d_threshold, descr_C, d_csr_row_ptr_C, d_nnz_total_dev_host_ptr, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_C_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind_C = (int*)d_csr_col_ind_C_managed.get(); T* d_csr_val_C = (T*)d_csr_val_C_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); std::vector h_csr_row_ptr_C(M + 1); std::vector h_csr_col_ind_C(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val_C(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr_C.data(), d_csr_row_ptr_C, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind_C.data(), d_csr_col_ind_C, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val_C.data(), d_csr_val_C, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_C_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_csr_to_csr(M, N, nnz_A, h_csr_row_ptr_A, h_csr_col_ind_A, h_csr_val_A, h_nnz_C_cpu[0], h_csr_row_ptr_cpu, h_csr_col_ind_cpu, h_csr_val_cpu, csr_idx_base_A, csr_idx_base_C, threshold); unit_check_general(1, 1, 1, h_nnz_C_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind_C.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneCsr2csr(handle, M, N, nnz_A, descr_A, d_csr_val_A, d_csr_row_ptr_A, d_csr_col_ind_A, &threshold, descr_C, d_csr_val_C, d_csr_row_ptr_C, d_csr_col_ind_C, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_csr2csr_gbyte_count(M, nnz_A, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzC, h_nnz_total_dev_host_ptr[0], display_key_t::threshold, threshold, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_CSR2CSR_HPP ./clients/include/testing_spgemm_csr.hpp0000664000175100017510000011754615176134511020616 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPGEMM_CSR_HPP #define TESTING_SPGEMM_CSR_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spgemm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz_A = 100; int64_t nnz_B = 100; int64_t nnz_C = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBaseA = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseB = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseC = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpGEMMAlg_t alg = HIPSPARSE_SPGEMM_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dcsr_row_ptr_A = (int*)dcsr_row_ptr_A_managed.get(); int* dcsr_col_ind_A = (int*)dcsr_col_ind_A_managed.get(); float* dcsr_val_A = (float*)dcsr_val_A_managed.get(); int* dcsr_row_ptr_B = (int*)dcsr_row_ptr_B_managed.get(); int* dcsr_col_ind_B = (int*)dcsr_col_ind_B_managed.get(); float* dcsr_val_B = (float*)dcsr_val_B_managed.get(); int* dcsr_row_ptr_C = (int*)dcsr_row_ptr_C_managed.get(); int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); float* dcsr_val_C = (float*)dcsr_val_C_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpGEMM structures hipsparseSpMatDescr_t A, B, C; size_t bufferSize; // Create SpGEMM structures verify_hipsparse_status_success(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, idxType, idxType, idxBaseA, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, idxType, idxType, idxBaseB, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&C, m, n, nnz_C, dcsr_row_ptr_C, dcsr_col_ind_C, dcsr_val_C, idxType, idxType, idxBaseC, dataType), "success"); // SpGEMM work estimation verify_hipsparse_status_invalid_handle(hipsparseSpGEMM_workEstimation(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr, &bufferSize, nullptr)); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr, &bufferSize, nullptr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr, &bufferSize, nullptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr, &bufferSize, nullptr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr, &bufferSize, nullptr), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_workEstimation(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr, &bufferSize, nullptr), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_workEstimation( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr, nullptr, nullptr), "Error: bufferSize is nullptr"); // SpGEMM compute verify_hipsparse_status_invalid_handle(hipsparseSpGEMM_compute( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr, &bufferSize, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr, &bufferSize, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr, &bufferSize, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr, &bufferSize, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr, &bufferSize, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpGEMM_compute(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr, &bufferSize, dbuf), "Error: C is nullptr"); // SpGEMM copy verify_hipsparse_status_invalid_handle(hipsparseSpGEMM_copy( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMM_copy( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr), "Error: C is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_spgemm_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) J m = argus.M; J k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idxBaseA = argus.baseA; hipsparseIndexBase_t idxBaseB = argus.baseB; hipsparseIndexBase_t idxBaseC = argus.baseC; hipsparseSpGEMMAlg_t alg = static_cast(argus.spgemm_alg); std::string filename = argus.filename; T h_beta = make_DataType(0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handles std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix( filename, m, k, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idxBaseA)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // For sparse matrix B, use the transpose of A J n = m; I nnz_B = nnz_A; std::vector hcsr_row_ptr_B(k + 1); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); transpose_csr(m, k, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idxBaseA, idxBaseB); // allocate memory on device auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (k + 1)), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_B), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dcsr_row_ptr_C_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcsr_row_ptr_C_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (n + 1)), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dcsr_row_ptr_A = (I*)dcsr_row_ptr_A_managed.get(); J* dcsr_col_ind_A = (J*)dcsr_col_ind_A_managed.get(); T* dcsr_val_A = (T*)dcsr_val_A_managed.get(); I* dcsr_row_ptr_B = (I*)dcsr_row_ptr_B_managed.get(); J* dcsr_col_ind_B = (J*)dcsr_col_ind_B_managed.get(); T* dcsr_val_B = (T*)dcsr_val_B_managed.get(); I* dcsr_row_ptr_C_1 = (I*)dcsr_row_ptr_C_1_managed.get(); I* dcsr_row_ptr_C_2 = (I*)dcsr_row_ptr_C_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_B, hcsr_row_ptr_B.data(), sizeof(I) * (k + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_B, hcsr_col_ind_B.data(), sizeof(J) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_B, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A, B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, typeI, typeJ, idxBaseA, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, typeI, typeJ, idxBaseB, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &C1, m, n, 0, dcsr_row_ptr_C_1, nullptr, nullptr, typeI, typeJ, idxBaseC, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &C2, m, n, 0, dcsr_row_ptr_C_2, nullptr, nullptr, typeI, typeJ, idxBaseC, typeT)); // Query SpGEMM work estimation buffer size_t bufferSize1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize1, nullptr)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize1, nullptr)); void* externalBuffer1; CHECK_HIP_ERROR(hipMalloc(&externalBuffer1, bufferSize1)); // SpGEMM work estimation CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize1, externalBuffer1)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_workEstimation(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize1, externalBuffer1)); // Query SpGEMM compute buffer size_t bufferSize2; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize2, nullptr)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize2, nullptr)); void* externalBuffer2; CHECK_HIP_ERROR(hipMalloc(&externalBuffer2, bufferSize2)); // SpGEMM compute CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr, &bufferSize2, externalBuffer2)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_compute(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr, &bufferSize2, externalBuffer2)); // Get nnz of C int64_t rows_C, cols_C, nnz_C_1, nnz_C_2; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(C1, &rows_C, &cols_C, &nnz_C_1)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(C2, &rows_C, &cols_C, &nnz_C_2)); // Allocate C auto dcsr_col_ind_C_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_C_1), device_free}; auto dcsr_val_C_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C_1), device_free}; auto dcsr_col_ind_C_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_C_2), device_free}; auto dcsr_val_C_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C_2), device_free}; J* dcsr_col_ind_C_1 = (J*)dcsr_col_ind_C_1_managed.get(); T* dcsr_val_C_1 = (T*)dcsr_val_C_1_managed.get(); J* dcsr_col_ind_C_2 = (J*)dcsr_col_ind_C_2_managed.get(); T* dcsr_val_C_2 = (T*)dcsr_val_C_2_managed.get(); CHECK_HIP_ERROR(hipMemset(dcsr_val_C_1, 0, sizeof(T) * nnz_C_1)); CHECK_HIP_ERROR(hipMemset(dcsr_val_C_2, 0, sizeof(T) * nnz_C_2)); // Set C pointers CHECK_HIPSPARSE_ERROR( hipsparseCsrSetPointers(C1, dcsr_row_ptr_C_1, dcsr_col_ind_C_1, dcsr_val_C_1)); CHECK_HIPSPARSE_ERROR( hipsparseCsrSetPointers(C2, dcsr_row_ptr_C_2, dcsr_col_ind_C_2, dcsr_val_C_2)); // SpGEMM copy CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMM_copy( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, descr)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpGEMM_copy(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, descr)); // Copy output from device to CPU std::vector hcsr_row_ptr_C_1(m + 1); std::vector hcsr_row_ptr_C_2(m + 1); std::vector hcsr_col_ind_C_1(nnz_C_1); std::vector hcsr_col_ind_C_2(nnz_C_2); std::vector hcsr_val_C_1(nnz_C_1); std::vector hcsr_val_C_2(nnz_C_2); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_1.data(), dcsr_row_ptr_C_1, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_2.data(), dcsr_row_ptr_C_2, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_1.data(), dcsr_col_ind_C_1, sizeof(J) * nnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_2.data(), dcsr_col_ind_C_2, sizeof(J) * nnz_C_2, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dcsr_val_C_1, sizeof(T) * nnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dcsr_val_C_2, sizeof(T) * nnz_C_2, hipMemcpyDeviceToHost)); // Compute SpGEMM nnz of C on host std::vector hcsr_row_ptr_C_gold(m + 1); int64_t nnz_C_gold = host_csrgemm2_nnz(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, hcsr_row_ptr_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify nnz and row pointer array unit_check_general(1, 1, 1, &nnz_C_gold, &nnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &nnz_C_2); unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_1.data()); unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_2.data()); // Compute SpGEMM on host std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, (const T*)nullptr, hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify column and value array unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_2.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); // Free buffers CHECK_HIP_ERROR(hipFree(externalBuffer1)); CHECK_HIP_ERROR(hipFree(externalBuffer2)); // Clean up CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPGEMM_CSR_HPP ./clients/include/arg_check.hpp0000664000175100017510000000437715176134305016626 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef ARG_CHECK_HPP #define ARG_CHECK_HPP #include void verify_hipsparse_status(hipsparseStatus_t status, hipsparseStatus_t expected_status, const char* message); void verify_hipsparse_status_invalid_pointer(hipsparseStatus_t status, const char* message); void verify_hipsparse_status_invalid_size(hipsparseStatus_t status, const char* message); void verify_hipsparse_status_invalid_value(hipsparseStatus_t status, const char* message); void verify_hipsparse_status_zero_pivot(hipsparseStatus_t status, const char* message); void verify_hipsparse_status_invalid_handle(hipsparseStatus_t status); void verify_hipsparse_status_internal_error(hipsparseStatus_t status, const char* message); void verify_hipsparse_status_not_supported(hipsparseStatus_t status, const char* message); void verify_hipsparse_status_success(hipsparseStatus_t status, const char* message); #endif // ARG_CHECK_HPP ./clients/include/testing_spmm_csc.hpp0000664000175100017510000004643215176134511020256 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_CSC_HPP #define TESTING_SPMM_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_CSR_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* drow = (int32_t*)drow_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCsc(&A, m, k, nnz, dptr, drow, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); #endif // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11061) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMMAlg_t alg = static_cast(argus.spmm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsc_col_ptr; std::vector hcsc_row_ind; std::vector hcsc_val; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, nnz_A, hcsc_col_ptr, hcsc_row_ind, hcsc_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; // Allocate host memory for vectors std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, nnz_B, 1); hipsparseInit(hC_1, nnz_C, 1); // copy vector is easy in STL; hC_gold = hB: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (A_n + 1)), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsc_col_ptr.data(), sizeof(I) * (A_n + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(drow, hcsc_row_ind.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsc_val.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&A, A_m, A_n, nnz_A, dptr, drow, dval, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // CPU host_cscmm(A_m, n, A_n, transA, transB, h_alpha, hcsc_col_ptr.data(), hcsc_row_ind.data(), hcsc_val.data(), hB.data(), (J)ldb, orderB, h_beta, hC_gold.data(), (J)ldc, orderC, idx_base); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = cscmm_gbyte_count( A_n, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_CSC_HPP ./clients/include/testing_dnmat_descr.hpp0000664000175100017510000001377415176134305020741 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DNMAT_DESCR_HPP #define TESTING_DNMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_dnmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t ld = 100; hipsparseOrder_t order = HIPSPARSE_ORDER_ROW; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * rows * cols), device_free}; float* val_data = (float*)val_data_managed.get(); hipsparseDnMatDescr_t x; // hipsparseCreateDnMat verify_hipsparse_status_invalid_pointer( hipsparseCreateDnMat(nullptr, rows, cols, ld, val_data, dataType, order), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateDnMat(&x, -1, cols, ld, val_data, dataType, order), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateDnMat(&x, rows, -1, ld, val_data, dataType, order), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateDnMat(&x, rows, cols, -1, val_data, dataType, order), "Error: ld is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateDnMat(&x, rows, cols, ld, nullptr, dataType, order), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnMat(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateDnMat(&x, rows, cols, ld, val_data, dataType, order), "Success"); // hipsparseDnMatGet void* data; verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(nullptr, &rows, &cols, &ld, &data, &dataType, &order), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, nullptr, &cols, &ld, &data, &dataType, &order), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, nullptr, &ld, &data, &dataType, &order), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, nullptr, &data, &dataType, &order), "Error: ld is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, &ld, nullptr, &dataType, &order), "Error: data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, &ld, &data, nullptr, &order), "Error: dataType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGet(x, &rows, &cols, &ld, &data, &dataType, nullptr), "Error: order is nullptr"); // hipsparseDnMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetValues(x, nullptr), "Error: val is nullptr"); // hipsparseDnVecSetValues verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetValues(nullptr, data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetValues(x, nullptr), "Error: val is nullptr"); int batch_count = 100; int64_t batch_stride = 100; // hipsparseDnMatSetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseDnMatSetStridedBatch(nullptr, batch_count, batch_stride), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetStridedBatch(x, -1, batch_stride), "Error: batch_count < 0"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatSetStridedBatch(x, batch_count, -1), "Error: batch_stride < 0"); // hipsparseDnMatGetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(nullptr, &batch_count, &batch_stride), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDnMatGetStridedBatch(x, nullptr, &batch_stride), "Error: batch_count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseDnMatGetStridedBatch(x, &batch_count, nullptr), "Error: batch_stride is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_DNMAT_DESCR_HPP ./clients/include/testing_csrgemm.hpp0000664000175100017510000015570115176134511020107 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEMM_HPP #define TESTING_CSRGEMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgemm_bad_arg(void) { #if(!defined(CUDART_VERSION)) int M = 1; int N = 1; int K = 1; int nnz_A = 1; int nnz_B = 1; hipsparseOperation_t trans_A = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t trans_B = HIPSPARSE_OPERATION_NON_TRANSPOSE; int safe_size = 1; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // testing hipsparseXcsrgemmNnz int nnz_C; verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, (int*)nullptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, (int*)nullptr, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, (int*)nullptr, dBcol, descr_C, dCptr, &nnz_C), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, (int*)nullptr, descr_C, dCptr, &nnz_C), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, (int*)nullptr, &nnz_C), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, (int*)nullptr), "Error: nnz_C is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, (hipsparseMatDescr_t) nullptr, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, (hipsparseMatDescr_t) nullptr, dCptr, &nnz_C), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemmNnz((hipsparseHandle_t) nullptr, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &nnz_C)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, (T*)nullptr, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dAval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, (int*)nullptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dAptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, (int*)nullptr, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dAcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, (T*)nullptr, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dBval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, (int*)nullptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: dBptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, (int*)nullptr, descr_C, dCval, dCptr, dCcol), "Error: dBcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr, dCcol), "Error: dCval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, (int*)nullptr, dCcol), "Error: dCptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, (int*)nullptr), "Error: dCcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, (hipsparseMatDescr_t) nullptr, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: descr_A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, (hipsparseMatDescr_t) nullptr, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol), "Error: descr_B is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, (hipsparseMatDescr_t) nullptr, dCval, dCptr, dCcol), "Error: descr_C is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrgemm((hipsparseHandle_t) nullptr, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); #endif } static int csrgemm_nnz(int m, int n, int k, const int* csr_row_ptr_A, const int* csr_col_ind_A, const int* csr_row_ptr_B, const int* csr_col_ind_B, int* csr_row_ptr_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C) { std::vector nnz(n, -1); // Index base csr_row_ptr_C[0] = idx_base_C; // Loop over rows of A for(int i = 0; i < m; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = csr_row_ptr_C[i]; int row_begin_A = csr_row_ptr_A[i] - idx_base_A; int row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(int j = row_begin_A; j < row_end_A; ++j) { // Current column of A int col_A = csr_col_ind_A[j] - idx_base_A; int row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; int row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(int l = row_begin_B; l < row_end_B; ++l) { // Current column of B int col_B = csr_col_ind_B[l] - idx_base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } return csr_row_ptr_C[m] - idx_base_C; } template static void csrgemm(int m, int n, int k, const int* csr_row_ptr_A, const int* csr_col_ind_A, const T* csr_val_A, const int* csr_row_ptr_B, const int* csr_col_ind_B, const T* csr_val_B, const int* csr_row_ptr_C, int* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C) { std::vector nnz(n, -1); // Loop over rows of A for(int i = 0; i < m; ++i) { int row_begin_A = csr_row_ptr_A[i] - idx_base_A; int row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; int row_begin_C = csr_row_ptr_C[i] - idx_base_C; int row_end_C = row_begin_C; // Loop over columns of A for(int j = row_begin_A; j < row_end_A; ++j) { // Current column of A int col_A = csr_col_ind_A[j] - idx_base_A; // Current value of A T val_A = csr_val_A[j]; int row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; int row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(int l = row_begin_B; l < row_end_B; ++l) { // Current column of B int col_B = csr_col_ind_B[l] - idx_base_B; // Current value of B T val_B = csr_val_B[l]; // Check if a new nnz is generated or if the product is appended if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + idx_base_C; csr_val_C[row_end_C] = testing_mult(val_A, val_B); ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + testing_mult(val_A, val_B); } } } } // Sort column indices within each row for(int i = 0; i < m; ++i) { int row_begin = csr_row_ptr_C[i] - idx_base_C; int row_end = csr_row_ptr_C[i + 1] - idx_base_C; for(int j = row_begin; j < row_end; ++j) { for(int jj = row_begin; jj < row_end - 1; ++jj) { if(csr_col_ind_C[jj] > csr_col_ind_C[jj + 1]) { // swap elements int ind = csr_col_ind_C[jj]; T val = csr_val_C[jj]; csr_col_ind_C[jj] = csr_col_ind_C[jj + 1]; csr_val_C[jj] = csr_val_C[jj + 1]; csr_col_ind_C[jj + 1] = ind; csr_val_C[jj + 1] = val; } } } } } template hipsparseStatus_t testing_csrgemm(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int M = argus.M; int N = argus.N; int K = argus.K; hipsparseOperation_t trans_A = argus.transA; hipsparseOperation_t trans_B = argus.transB; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, K, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // B = A^T so that we can compute the square of A N = M; int nnz_B = nnz_A; std::vector hcsr_row_ptr_B(K + 1, 0); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); // B = A^T transpose_csr(M, K, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idx_base_A, idx_base_B); // Allocate memory on device auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (K + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (K + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); // csrgemm nnz // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, &hnnz_C_1)); // Allocate result matrix auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); // hipsparse pointer mode device auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemmNnz(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr, dnnz_C)); // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Compute csrgemm CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); // Copy output from device to CPU std::vector hcsr_row_ptr_C(M + 1); std::vector hcsr_col_ind_C(hnnz_C_1); std::vector hcsr_val_C(hnnz_C_1); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr_C.data(), dCptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind_C.data(), dCcol, sizeof(int) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C.data(), dCval, sizeof(T) * hnnz_C_1, hipMemcpyDeviceToHost)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); int nnz_C_gold = csrgemm_nnz(M, N, K, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); csrgemm(M, N, K, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm(handle, trans_A, trans_B, M, N, K, descr_A, nnz_A, dAval, dAptr, dAcol, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrgemm_gflop_count( M, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), idx_base_A); double gbyte_count = csrgemm_gbyte_count(M, N, K, nnz_A, nnz_B, hnnz_C_1); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::transA, hipsparse_operation2string(trans_A), display_key_t::transB, hipsparse_operation2string(trans_B), display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::nnzA, nnz_A, display_key_t::nnzB, nnz_B, display_key_t::nnzC, hnnz_C_1, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEMM_HPP ./clients/include/testing_gtsv2_nopivot.hpp0000664000175100017510000002170115176134511021265 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV2_NOPIVOT_HPP #define TESTING_GTSV2_NOPIVOT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv2_nopivot_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int m = 10; int n = 10; int ldb = m; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsv_nopivot buffer size verify_hipsparse_status_invalid_handle( hipsparseXgtsv2_nopivot_bufferSizeExt(nullptr, m, n, ddl, dd, ddu, dB, ldb, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, -1, n, ddl, dd, ddu, dB, ldb, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, -1, ddl, dd, ddu, dB, ldb, &bsize), "Error: n is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, -1, &bsize), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, nullptr), "Error: bsize is nullptr"); // gtsv_nopivot verify_hipsparse_status_invalid_handle( hipsparseXgtsv2_nopivot(nullptr, m, n, ddl, dd, ddu, dB, ldb, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot(handle, -1, n, ddl, dd, ddu, dB, ldb, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot(handle, m, -1, ddl, dd, ddu, dB, ldb, dbuf), "Error: n is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, -1, dbuf), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, (const T*)nullptr, dd, ddu, dB, ldb, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, ddl, (const T*)nullptr, ddu, dB, ldb, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, (const T*)nullptr, dB, ldb, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, (T*)nullptr, ldb, dbuf), "Error: dB is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2_nopivot(Arguments argus) { int m = argus.M; int n = argus.N; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; int ldb = 2 * m; // Host structures std::vector hdl(m, make_DataType(1)); std::vector hd(m, make_DataType(2)); std::vector hdu(m, make_DataType(1)); std::vector hB(ldb * n, make_DataType(3)); hdl[0] = make_DataType(0); hdu[m - 1] = make_DataType(0); std::vector hB_original = hB; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * ldb * n), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * ldb * n, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_nopivot_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hB.data(), dB, sizeof(T) * ldb * n, hipMemcpyDeviceToHost)); // Check std::vector hresult(ldb * n, make_DataType(3)); for(int j = 0; j < n; j++) { hresult[ldb * j] = testing_mult(hd[0], hB[ldb * j]) + testing_mult(hdu[0], hB[ldb * j + 1]); hresult[ldb * j + m - 1] = testing_mult(hdl[m - 1], hB[ldb * j + m - 2]) + testing_mult(hd[m - 1], hB[ldb * j + m - 1]); for(int i = 1; i < m - 1; i++) { hresult[ldb * j + i] = testing_mult(hdl[i], hB[ldb * j + i - 1]) + testing_mult(hd[i], hB[ldb * j + i]) + testing_mult(hdu[i], hB[ldb * j + i + 1]); } } unit_check_near(m, n, ldb, hB_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_nopivot(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_gbyte_count(m, n); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_NOPIVOT_HPP ./clients/include/gbyte.hpp0000664000175100017510000005076715176134511016035 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief gbyte.hpp provides data transfer counts of Sparse Linear Algebra Subprograms * of Level 1, 2 and 3. */ #pragma once #ifndef GBYTE_HPP #define GBYTE_HPP // Compute gbytes inline double get_gpu_gbyte(double gpu_time_used, double gbyte_count) { return gbyte_count / gpu_time_used * 1e6; } template inline double get_gpu_gbyte(double gpu_time_used, F count, Ts... ts) { return get_gpu_gbyte(gpu_time_used, count(ts...)); } inline double get_gpu_time_msec(double gpu_time_used) { return gpu_time_used / 1e3; } /* * =========================================================================== * level 1 SPARSE * =========================================================================== */ template constexpr double axpby_gbyte_count(I nnz) { return (nnz * sizeof(I) + (3.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double doti_gbyte_count(I nnz) { return (nnz * sizeof(I) + nnz * (sizeof(X) + sizeof(Y))) / 1e9; } template constexpr double gthr_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double gthrz_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double roti_gbyte_count(I nnz) { return (nnz * sizeof(I) + (3.0 * nnz) * sizeof(T)) / 1e9; } template constexpr double sctr_gbyte_count(I nnz) { return (nnz * sizeof(I) + (2.0 * nnz) * sizeof(T)) / 1e9; } /* * =========================================================================== * level 2 SPARSE * =========================================================================== */ template constexpr double bsrmv_gbyte_count(J mb, J nb, I nnzb, J block_dim, bool beta = false) { return (sizeof(I) * (mb + 1) + sizeof(J) * nnzb + sizeof(A) * nnzb * block_dim * block_dim + sizeof(Y) * (mb * block_dim + (beta ? mb * block_dim : 0)) + sizeof(X) * (nb * block_dim)) / 1e9; } template constexpr double bsrmv_gbyte_count(J mb, J nb, I nnzb, J block_dim, bool beta = false) { return bsrmv_gbyte_count(mb, nb, nnzb, block_dim, beta); } template constexpr double bsrsv_gbyte_count(int mb, int nnzb, int bsr_dim) { return ((mb + 1 + nnzb) * sizeof(int) + (bsr_dim * (mb + mb + nnzb * bsr_dim)) * sizeof(T)) / 1e9; } template constexpr double coomv_gbyte_count(I M, I N, int64_t nnz, bool beta = false) { return (sizeof(I) * 2.0 * nnz + sizeof(A) * nnz + sizeof(Y) * (M + (beta ? M : 0)) + sizeof(X) * N) / 1e9; } template constexpr double coomv_gbyte_count(I M, I N, int64_t nnz, bool beta = false) { return coomv_gbyte_count(M, N, nnz, beta); } template constexpr double csrsv_gbyte_count(J M, I nnz) { return ((M + 1) * sizeof(I) + nnz * sizeof(J) + (M + M + nnz) * sizeof(T)) / 1e9; } template constexpr double coosv_gbyte_count(I M, int64_t nnz) { return (2 * nnz * sizeof(I) + (M + M + nnz) * sizeof(T)) / 1e9; } template constexpr double csrmv_gbyte_count(J M, J N, I nnz, bool beta = false) { return (sizeof(I) * (M + 1) + sizeof(J) * nnz + sizeof(A) * nnz + sizeof(Y) * (M + (beta ? M : 0)) + sizeof(X) * N) / 1e9; } template constexpr double csrmv_gbyte_count(J M, J N, I nnz, bool beta = false) { return csrmv_gbyte_count(M, N, nnz, beta); } template constexpr double gemvi_gbyte_count(I m, I nnz, bool beta = false) { return ((nnz) * sizeof(I) + (m * nnz + nnz + m + (beta ? m : 0)) * sizeof(T)) / 1e9; } /* * =========================================================================== * level 3 SPARSE * =========================================================================== */ template constexpr double bsrmm_gbyte_count(int Mb, int nnzb, int block_dim, int nnz_B, int nnz_C, bool beta = false) { //reads size_t reads = (Mb + 1 + nnzb) * sizeof(int) + (block_dim * block_dim * nnzb + nnz_B + (beta ? nnz_C : 0)) * sizeof(T); //writes size_t writes = nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csrmm_gbyte_count(J M, I nnz_A, I nnz_B, I nnz_C, bool beta = false) { return ((M + 1) * sizeof(I) + nnz_A * sizeof(J) + (nnz_A + nnz_B + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double cscmm_gbyte_count(J N, I nnz_A, I nnz_B, I nnz_C, bool beta = false) { return csrmm_gbyte_count(N, nnz_A, nnz_B, nnz_C, beta); } template constexpr double coomm_gbyte_count(int64_t nnz_A, int64_t nnz_B, int64_t nnz_C, bool beta = false) { return (2.0 * nnz_A * sizeof(I) + (nnz_A + nnz_B + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double csrmm_batched_gbyte_count(J M, I nnz_A, I nnz_B, I nnz_C, J batch_count_A, J batch_count_B, J batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * ((M + 1) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double cscmm_batched_gbyte_count(J N, I nnz_A, I nnz_B, I nnz_C, J batch_count_A, J batch_count_B, J batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * ((N + 1) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double coomm_batched_gbyte_count(I M, int64_t nnz_A, int64_t nnz_B, int64_t nnz_C, I batch_count_A, I batch_count_B, I batch_count_C, bool beta = false) { // read A matrix size_t readA = batch_count_A * (nnz_A * sizeof(I) + nnz_A * sizeof(I) + nnz_A * sizeof(T)); // read B matrix size_t readB = batch_count_B * nnz_B * sizeof(T); // read C matrix size_t readC = batch_count_C * (beta ? nnz_C : 0) * sizeof(T); // write C matrix size_t writeC = batch_count_C * nnz_C * sizeof(T); return (readA + readB + readC + writeC) / 1e9; } template constexpr double gemmi_gbyte_count(J N, I nnz_B, I nnz_A, I nnz_C, bool beta = false) { return ((N + 1) * sizeof(I) + nnz_B * sizeof(J) + (nnz_B + nnz_A + nnz_C + (beta ? nnz_C : 0)) * sizeof(T)) / 1e9; } template constexpr double sddmm_csr_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return ((size_t(M) + 1) * sizeof(I) + size_t(nnz) * sizeof(J) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } template constexpr double sddmm_csc_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return ((size_t(N) + 1) * sizeof(I) + size_t(nnz) * sizeof(J) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } template constexpr double sddmm_coo_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return (size_t(nnz) * 2 * sizeof(I) + size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T)) / 1e9; } template constexpr double sddmm_coo_aos_gbyte_count(J M, J N, J K, I nnz, bool beta = false) { return (size_t(nnz) * 2 * sizeof(I) + (size_t(nnz) * (K * 2 + ((beta) ? 1 : 0)) * sizeof(T))) / 1e9; } /* * =========================================================================== * precond SPARSE * =========================================================================== */ template constexpr double bsric0_gbyte_count(int Mb, int block_dim, int nnzb) { return ((Mb + 1 + nnzb) * sizeof(int) + 2.0 * block_dim * block_dim * nnzb * sizeof(T)) / 1e9; } template constexpr double bsrilu0_gbyte_count(int Mb, int block_dim, int nnzb) { return ((Mb + 1 + nnzb) * sizeof(int) + 2.0 * block_dim * block_dim * nnzb * sizeof(T)) / 1e9; } template constexpr double csric0_gbyte_count(int M, int nnz) { return ((M + 1 + nnz) * sizeof(int) + 2.0 * nnz * sizeof(T)) / 1e9; } template constexpr double csrilu0_gbyte_count(int M, int nnz) { return ((M + 1 + nnz) * sizeof(int) + 2.0 * nnz * sizeof(T)) / 1e9; } template constexpr double gtsv_gbyte_count(int M, int N) { return ((3 * M + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gtsv_strided_batch_gbyte_count(int M, int N) { return ((3 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gtsv_interleaved_batch_gbyte_count(int M, int N) { return ((3 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } template constexpr double gpsv_interleaved_batch_gbyte_count(int M, int N) { return ((5 * M * N + 2 * M * N) * sizeof(T)) / 1e9; } /* * =========================================================================== * conversion SPARSE * =========================================================================== */ template constexpr double nnz_gbyte_count(int M, int N, hipsparseDirection_t dir) { return ((M * N) * sizeof(T) + ((dir == HIPSPARSE_DIRECTION_ROW) ? M : N) * sizeof(int)) / 1e9; } template constexpr double bsr2csr_gbyte_count(int Mb, int block_dim, int nnzb) { // reads size_t reads = nnzb * block_dim * block_dim * sizeof(T) + (Mb + 1 + nnzb) * sizeof(int); // writes size_t writes = nnzb * block_dim * block_dim * sizeof(T) + (Mb * block_dim + 1 + nnzb * block_dim * block_dim) * sizeof(int); return (reads + writes) / 1e9; } template constexpr double csr2coo_gbyte_count(int M, int nnz) { return (M + 1 + nnz) * sizeof(int) / 1e9; } template constexpr double coo2csr_gbyte_count(int M, int nnz) { return (M + 1 + nnz) * sizeof(int) / 1e9; } template constexpr double csr2csc_gbyte_count(int M, int N, int nnz, hipsparseAction_t action) { return ((M + N + 2 + 2.0 * nnz) * sizeof(int) + (action == HIPSPARSE_ACTION_NUMERIC ? (2.0 * nnz) * sizeof(T) : 0.0)) / 1e9; } template constexpr double csr2hyb_gbyte_count(int M, int nnz, int ell_nnz, int coo_nnz) { return ((M + 1.0 + ell_nnz + 2.0 * coo_nnz) * sizeof(int) + (nnz + ell_nnz + coo_nnz) * sizeof(T)) / 1e9; } template constexpr double hyb2csr_gbyte_count(int M, int csr_nnz, int ell_nnz, int coo_nnz) { return ((M + 1.0 + csr_nnz + ell_nnz + 2.0 * coo_nnz) * sizeof(int) + (csr_nnz + ell_nnz + coo_nnz) * sizeof(T)) / 1e9; } template constexpr double csr2bsr_gbyte_count(int M, int Mb, int nnz, int nnzb, int block_dim) { // reads size_t reads = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); // writes size_t writes = (Mb + 1 + nnzb * block_dim * block_dim) * sizeof(int) + (nnzb * block_dim * block_dim) * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csr2gebsr_gbyte_count(int M, int Mb, int nnz, int nnzb, int row_block_dim, int col_block_dim) { // reads size_t reads = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); // writes size_t writes = (Mb + 1 + nnzb * row_block_dim * col_block_dim) * sizeof(int) + (nnzb * row_block_dim * col_block_dim) * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csr2csr_compress_gbyte_count(int M, int nnz_A, int nnz_C) { size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double csx2dense_gbyte_count(J M, J N, I nnz) { J L = (DIRA == HIPSPARSE_DIRECTION_ROW) ? M : N; size_t read_csx = nnz * sizeof(T) + nnz * sizeof(J) + (L + 1) * sizeof(I); size_t write_dense = M * N * sizeof(T) + nnz * sizeof(T); return (read_csx + write_dense) / 1e9; } template constexpr double dense2csx_gbyte_count(J M, J N, I nnz) { J L = (DIRA == HIPSPARSE_DIRECTION_ROW) ? M : N; size_t write_csx_ptr = (L + 1) * sizeof(I); size_t read_csx_ptr = (L + 1) * sizeof(I); size_t build_csx_ptr = write_csx_ptr + read_csx_ptr; size_t write_csx = nnz * sizeof(T) + nnz * sizeof(J) + (L + 1) * sizeof(I); size_t read_dense = M * N * sizeof(T); return (read_dense + build_csx_ptr + write_csx) / 1e9; } template constexpr double dense2coo_gbyte_count(I M, I N, I nnz) { size_t reads = (M * N) * sizeof(T); size_t writes = 2 * nnz * sizeof(I) + nnz * sizeof(T); return (reads + writes) / 1e9; } template constexpr double coo2dense_gbyte_count(I M, I N, I nnz) { size_t reads = 2 * nnz * sizeof(I) + nnz * sizeof(T); size_t writes = (M * N) * sizeof(T); return (reads + writes) / 1e9; } constexpr double csrsort_gbyte_count(int M, int nnz, bool permute) { return ((2.0 * M + 2.0 + 2.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } constexpr double cscsort_gbyte_count(int N, int nnz, bool permute) { return ((2.0 * N + 2.0 + 2.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } constexpr double coosort_gbyte_count(int nnz, bool permute) { return ((4.0 * nnz + (permute ? 2.0 * nnz : 0.0)) * sizeof(int)) / 1e9; } template constexpr double gebsr2csr_gbyte_count(int Mb, int row_block_dim, int col_block_dim, int nnzb) { // reads size_t reads = nnzb * row_block_dim * col_block_dim * sizeof(T) + (Mb + 1 + nnzb) * sizeof(int); // writes size_t writes = nnzb * row_block_dim * col_block_dim * sizeof(T) + (Mb * row_block_dim + 1 + nnzb * row_block_dim * col_block_dim) * sizeof(int); return (reads + writes) / 1e9; } template constexpr double gebsr2gebsc_gbyte_count( int Mb, int Nb, int nnzb, int row_block_dim, int col_block_dim, hipsparseAction_t action) { return ((Mb + Nb + 2 + 2.0 * nnzb) * sizeof(int) + (action == HIPSPARSE_ACTION_NUMERIC ? (2.0 * nnzb * row_block_dim * col_block_dim) * sizeof(T) : 0.0)) / 1e9; } template constexpr double gebsr2gebsr_gbyte_count(int Mb_A, int Mb_C, int row_block_dim_A, int col_block_dim_A, int row_block_dim_C, int col_block_dim_C, int nnzb_A, int nnzb_C) { // reads size_t reads = nnzb_A * row_block_dim_A * col_block_dim_A * sizeof(T) + (Mb_A + 1 + nnzb_A) * sizeof(int); // writes size_t writes = nnzb_C * row_block_dim_C * col_block_dim_C * sizeof(T) + (Mb_C + 1 + nnzb_C) * sizeof(int); return (reads + writes) / 1e9; } constexpr double identity_gbyte_count(int N) { return N * sizeof(int) / 1e9; } template constexpr double prune_csr2csr_gbyte_count(int M, int nnz_A, int nnz_C) { // reads size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); // writes size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_csr2csr_by_percentage_gbyte_count(int M, int nnz_A, int nnz_C) { // reads size_t reads = (M + 1 + nnz_A) * sizeof(int) + nnz_A * sizeof(T); // writes size_t writes = (M + 1 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_dense2csr_gbyte_count(int M, int N, int nnz) { size_t reads = M * N * sizeof(T); size_t writes = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); return (reads + writes) / 1e9; } template constexpr double prune_dense2csr_by_percentage_gbyte_count(int M, int N, int nnz) { size_t reads = M * N * sizeof(T); size_t writes = (M + 1 + nnz) * sizeof(int) + nnz * sizeof(T); return (reads + writes) / 1e9; } /* * =========================================================================== * extra SPARSE * =========================================================================== */ template constexpr double csrgeam_gbyte_count(int M, int nnz_A, int nnz_B, int nnz_C, const T* alpha, const T* beta) { double size_A = alpha ? (M + 1.0 + nnz_A) * sizeof(int) + nnz_A * sizeof(T) : 0.0; double size_B = beta ? (M + 1.0 + nnz_B) * sizeof(int) + nnz_B * sizeof(T) : 0.0; double size_C = (M + 1.0 + nnz_C) * sizeof(int) + nnz_C * sizeof(T); return (size_A + size_B + size_C) / 1e9; } template constexpr double csrgemm_gbyte_count(J M, J N, J K, I nnz_A, I nnz_B, I nnz_C) { double size_A = (M + 1.0) * sizeof(I) + nnz_A * sizeof(J) + nnz_A * sizeof(T); double size_B = (K + 1.0) * sizeof(I) + nnz_B * sizeof(J) + nnz_B * sizeof(T); double size_C = (M + 1.0) * sizeof(I) + nnz_C * sizeof(J) + nnz_C * sizeof(T); return (size_A + size_B + size_C) / 1e9; } #endif // GBYTE_HPP ./clients/include/testing_spmv_csr.hpp0000664000175100017510000004304715176134511020305 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMV_CSR_HPP #define TESTING_SPMV_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spmv_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #endif #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; size_t bsize; // Create SpMV structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, idxType, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, n, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpMV buffer verify_hipsparse_status_invalid_handle( hipsparseSpMV_bufferSize(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, nullptr, A, x, &beta, y, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, &beta, y, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMV preprocess (optional) verify_hipsparse_status_invalid_handle( hipsparseSpMV_preprocess(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_preprocess( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SpMV verify_hipsparse_status_invalid_handle( hipsparseSpMV(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spmv_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) J m = argus.M; J n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMVAlg_t alg = static_cast(argus.spmv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, n, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); // Query SpMV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMV_bufferSize( handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // Preprocess (optional) CHECK_HIPSPARSE_ERROR( hipsparseSpMV_preprocess(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, d_alpha, A, x, d_beta, y2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Query for warpSize hipDeviceProp_t prop; CHECK_HIP_ERROR(hipGetDeviceProperties(&prop, 0)); int WF_SIZE; I nnz_per_row = nnz / m; if(prop.warpSize == 32) { if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else WF_SIZE = 32; } else if(prop.warpSize == 64) { if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else if(nnz_per_row < 64) WF_SIZE = 32; else WF_SIZE = 64; } else { return HIPSPARSE_STATUS_INTERNAL_ERROR; } for(J i = 0; i < m; ++i) { std::vector sum(WF_SIZE, make_DataType(0.0)); for(I j = hcsr_row_ptr[i] - idx_base; j < hcsr_row_ptr[i + 1] - idx_base; j += WF_SIZE) { for(int k = 0; k < WF_SIZE; ++k) { if(j + k < hcsr_row_ptr[i + 1] - idx_base) { sum[k] = testing_fma(testing_mult(h_alpha, hval[j + k]), hx[hcol_ind[j + k] - idx_base], sum[k]); } } } for(int j = 1; j < WF_SIZE; j <<= 1) { for(int k = 0; k < WF_SIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(h_beta == make_DataType(0.0)) { hy_gold[i] = sum[0]; } else { hy_gold[i] = testing_fma(h_beta, hy_gold[i], sum[0]); } } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gbyte_count = csrmv_gbyte_count(m, n, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::transA, transA, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMV_CSR_HPP ./clients/include/testing_spmm_coo.hpp0000664000175100017510000004656715176134511020277 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_COO_HPP #define TESTING_SPMM_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int32_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // // ! // #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_COO_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_MM_ALG_DEFAULT; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drow = (int32_t*)drow_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, k, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); #endif // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMMAlg_t alg = static_cast(argus.spmm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz_A); // Convert to COO I mk = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; for(I i = 0; i < mk; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, nnz_B, 1); hipsparseInit(hC_1, nnz_C, 1); // copy vector is easy in STL; hC_gold = hB: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz_A), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, A_m, A_n, nnz_A, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // CPU host_coomm(A_m, n, A_n, nnz_A, transA, transB, h_alpha, hrow_ind.data(), hcol_ind.data(), hval.data(), hB.data(), (I)ldb, orderB, h_beta, hC_gold.data(), (I)ldc, orderC, idx_base); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gbyte_count = coomm_gbyte_count( nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_COO_HPP ./clients/include/testing_csric02.hpp0000664000175100017510000004057715176134511017723 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRIC0_HPP #define TESTING_CSRIC0_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csric02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csric02(new csric02_struct); csric02Info_t info = unique_ptr_csric02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval, dptr, dcol, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_bufferSize( handle, m, nnz, descr, dval, dptr, dcol, (csric02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsric02_bufferSize( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, &size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_analysis( handle, m, nnz, descr, dval, dptr, dcol, (csric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsric02_analysis( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02(handle, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02( handle, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02( handle, m, nnz, descr, dval, dptr, dcol, (csric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsric02( (hipsparseHandle_t) nullptr, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsric02_zeroPivot(handle, (csric02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsric02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csric02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csric02(new csric02_struct); csric02Info_t info = unique_ptr_csric02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts m > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_val_orig(hcsr_val); // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval_1 = (T*)dval_1_managed.get(); T* dval_2 = (T*)dval_2_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval_1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval_2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Obtain csric02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXcsric02_bufferSize(handle, m, nnz, descr, dval_1, dptr, dcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; if(argus.unit_check) { // csric02 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02_analysis( handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXcsric02_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csric02 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02_analysis( handle, m, nnz, descr, dval_2, dptr, dcol, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXcsric02_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csric02 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXcsric02(handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXcsric02_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // csric02 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXcsric02(handle, m, nnz, descr, dval_2, dptr, dcol, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXcsric02_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU std::vector result_1(nnz); std::vector result_2(nnz); CHECK_HIP_ERROR(hipMemcpy(result_1.data(), dval_1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result_2.data(), dval_2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host csric02 csric0(m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), idx_base, h_analysis_pivot_gold, h_solve_pivot_gold); #ifndef __HIP_PLATFORM_NVIDIA__ // Do not check pivots in cusparse unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); #endif if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, nnz, 1, hcsr_val.data(), result_1.data()); unit_check_near(1, nnz, 1, hcsr_val.data(), result_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval_1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02( handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); } double gpu_time_used = 0; // Solve run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR( hipMemcpy(dval_1, hcsr_val_orig.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXcsric02( handle, m, nnz, descr, dval_1, dptr, dcol, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = gpu_time_used / number_hot_calls; double gbyte_count = csric0_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRIC0_HPP ./clients/include/testing_csx2dense.hpp0000664000175100017510000003040215176134511020336 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSX2DENSE_HPP #define TESTING_CSX2DENSE_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; #include template void testing_csx2dense_bad_arg(FUNC& csx2dense) { #if(!defined(CUDART_VERSION)) static constexpr int M = 1; static constexpr int N = 1; static constexpr int LD = M; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * 1), device_free}; auto m_nnzPerRowColumn = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; auto m_csx_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (1 + 1)), device_free}; auto m_csx_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; int* d_csx_row = (HIPSPARSE_DIRECTION_ROW == DIRA) ? ((int*)m_csx_ptr.get()) : ((int*)m_csx_ind.get()); int* d_csx_col = (HIPSPARSE_DIRECTION_ROW == DIRA) ? ((int*)m_csx_ind.get()) : ((int*)m_csx_ptr.get()); T* d_dense_val = (T*)m_dense_val.get(); T* d_csx_val = (T*)m_csx_val.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(m_csx_ptr.get(), local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle( csx2dense(nullptr, 0, 0, nullptr, (const T*)nullptr, nullptr, nullptr, (T*)nullptr, 0)); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, nullptr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, (const T*)nullptr, d_csx_row, d_csx_col, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, d_csx_val, nullptr, d_csx_col, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, d_csx_val, d_csx_row, nullptr, d_dense_val, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_pointer( csx2dense(handle, M, N, descr, d_csx_val, d_csx_row, d_csx_col, (T*)nullptr, LD), "Error: an invalid pointer must be detected."); verify_hipsparse_status_invalid_size( csx2dense(handle, -1, N, descr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, LD), "Error: invalid size for m detected."); verify_hipsparse_status_invalid_size( csx2dense(handle, M, -1, descr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, LD), "Error: invalid size for n detected."); verify_hipsparse_status_invalid_size( csx2dense(handle, M, N, descr, d_csx_val, d_csx_row, d_csx_col, d_dense_val, M - 1), "Error: invalid size for LD detected."); #endif } template hipsparseStatus_t testing_csx2dense(const Arguments& argus, FUNC1& csx2dense, FUNC2& dense2csx) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; int LD = argus.lda; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); int DIMDIR = (HIPSPARSE_DIRECTION_ROW == DIRA) ? M : N; std::vector h_dense_val_ref(LD * N); std::vector h_dense_val(LD * N); std::vector h_nnzPerRowColumn(DIMDIR); // Create the dense matrix. auto m_dense_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * LD * N), device_free}; auto nnzPerRowColumn_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * DIMDIR), device_free}; auto nnzTotalDevHostPtr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 1), device_free}; T* d_dense_val = (T*)m_dense_val.get(); int* d_nnzPerRowColumn = (int*)nnzPerRowColumn_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LD; ++i) { for(int j = 0; j < N; ++j) { h_dense_val_ref[j * LD + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_dense_val_ref.data(), LD, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR( hipMemcpy(d_dense_val, h_dense_val_ref.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); int nnz; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXnnz(handle, DIRA, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, &nnz)); // Transfer. CHECK_HIP_ERROR(hipMemcpy( h_nnzPerRowColumn.data(), d_nnzPerRowColumn, sizeof(int) * DIMDIR, hipMemcpyDeviceToHost)); auto m_csx_row_col_ptr = hipsparse_unique_ptr{device_malloc(sizeof(int) * (DIMDIR + 1)), device_free}; auto m_csx_val = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto m_csx_col_row_ind = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; int* d_csx_row_col_ptr = (int*)m_csx_row_col_ptr.get(); int* d_csx_col_row_ind = (int*)m_csx_col_row_ind.get(); T* d_csx_val = (T*)m_csx_val.get(); std::vector cpu_csx_row_col_ptr(DIMDIR + 1); std::vector cpu_csx_val(nnz); std::vector cpu_csx_col_row_ind(nnz); CHECK_HIPSPARSE_ERROR( dense2csx(handle, M, N, descr, d_dense_val, LD, d_nnzPerRowColumn, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr)); // Copy on host. CHECK_HIP_ERROR(hipMemcpy(cpu_csx_row_col_ptr.data(), d_csx_row_col_ptr, sizeof(int) * (DIMDIR + 1), hipMemcpyDeviceToHost)); if(nnz > 0) { CHECK_HIP_ERROR( hipMemcpy(cpu_csx_val.data(), d_csx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(cpu_csx_col_row_ind.data(), d_csx_col_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); } if(argus.unit_check) { for(int i = 0; i < LD; ++i) { for(int j = 0; j < N; ++j) { h_dense_val[j * LD + i] = make_DataType(-2); } } CHECK_HIP_ERROR( hipMemcpy(d_dense_val, h_dense_val.data(), sizeof(T) * LD * N, hipMemcpyHostToDevice)); host_csx2dense(M, N, hipsparseGetMatIndexBase(descr), cpu_csx_val.data(), cpu_csx_row_col_ptr.data(), cpu_csx_col_row_ind.data(), h_dense_val.data(), LD); CHECK_HIPSPARSE_ERROR( csx2dense(handle, M, N, descr, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr, d_dense_val, LD)); void* buffer = malloc(sizeof(T) * LD * N); CHECK_HIP_ERROR(hipMemcpy(buffer, d_dense_val, sizeof(T) * LD * N, hipMemcpyDeviceToHost)); unit_check_general(M, N, LD, h_dense_val.data(), (T*)buffer); unit_check_general(M, N, LD, h_dense_val.data(), h_dense_val_ref.data()); free(buffer); buffer = nullptr; } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( csx2dense(handle, M, N, descr, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr, d_dense_val, LD)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( csx2dense(handle, M, N, descr, d_csx_val, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_row_col_ptr : d_csx_col_row_ind, (DIRA == HIPSPARSE_DIRECTION_ROW) ? d_csx_col_row_ind : d_csx_row_col_ptr, d_dense_val, LD)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csx2dense_gbyte_count(M, N, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::LD, LD, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSX2DENSE_HPP ./clients/include/hipsparse_common.yaml0000664000175100017510000003212115176134511020424 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## # Data types are defined as either aliases to Python-recognized ctypes, # or enums defined with c_int base clases and attributes. Datatypes: - hipsparseIndexType_t: bases: [ c_int ] attr: u16: 1 i32: 2 i64: 3 - hipDataType: bases: [ c_int ] attr: f32_r: 0 f64_r: 1 f16_r: 2 i8_r: 3 f32_c: 4 f64_c: 5 u8_r: 8 i32_r: 10 u32_r: 12 - { single: f32_r, double: f64_r } - { single complex: f32_c, double complex: f64_c } - hipsparseOperation_t: bases: [ c_int ] attr: HIPSPARSE_OPERATION_NON_TRANSPOSE: 0 HIPSPARSE_OPERATION_TRANSPOSE: 1 HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: 2 - hipsparseIndexBase_t: bases: [ c_int ] attr: HIPSPARSE_INDEX_BASE_ZERO: 0 HIPSPARSE_INDEX_BASE_ONE: 1 - hipsparseDiagType_t: bases: [ c_int ] attr: HIPSPARSE_DIAG_TYPE_NON_UNIT: 0 HIPSPARSE_DIAG_TYPE_UNIT: 1 - hipsparseFillMode_t: bases: [ c_int ] attr: HIPSPARSE_FILL_MODE_LOWER: 0 HIPSPARSE_FILL_MODE_UPPER: 1 - hipsparseAction_t: bases: [ c_int ] attr: HIPSPARSE_ACTION_SYMBOLIC: 0 HIPSPARSE_ACTION_NUMERIC: 1 - hipsparseHybPartition_t: bases: [ c_int ] attr: HIPSPARSE_HYB_PARTITION_AUTO: 0 HIPSPARSE_HYB_PARTITION_USER: 1 HIPSPARSE_HYB_PARTITION_MAX: 2 - hipsparseSolvePolicy_t: bases: [ c_int ] attr: HIPSPARSE_SOLVE_POLICY_NO_LEVEL: 0 HIPSPARSE_SOLVE_POLICY_USE_LEVEL: 1 - hipsparseDirection_t: bases: [ c_int ] attr: HIPSPARSE_DIRECTION_ROW: 0 HIPSPARSE_DIRECTION_COLUMN: 1 - hipsparseOrder_t: bases: [c_int ] attr: HIPSPARSE_ORDER_COL: 1 HIPSPARSE_ORDER_ROW: 2 - hipsparseFormat_t: bases: [c_int ] attr: HIPSPARSE_FORMAT_CSR: 1 HIPSPARSE_FORMAT_CSC: 2 HIPSPARSE_FORMAT_COO: 3 HIPSPARSE_FORMAT_COO_AOS: 4 HIPSPARSE_FORMAT_BLOCKED_ELL: 5 - hipsparseCsr2CscAlg_t: bases: [c_int ] attr: HIPSPARSE_CSR2CSC_ALG_DEFAULT: 0 HIPSPARSE_CSR2CSC_ALG1: 1 HIPSPARSE_CSR2CSC_ALG2: 2 - hipsparseDenseToSparseAlg_t: bases: [c_int ] attr: HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT: 0 - hipsparseSparseToDenseAlg_t: bases: [c_int ] attr: HIPSPARSE_SPARSETODENSE_ALG_DEFAULT: 0 - hipsparseSDDMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SDDMM_ALG_DEFAULT: 0 - hipsparseSpGEMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPGEMM_DEFAULT: 0 - hipsparseSpMVAlg_t: bases: [c_int ] attr: HIPSPARSE_SPMV_ALG_DEFAULT: 0 HIPSPARSE_SPMV_COO_ALG1: 1 HIPSPARSE_SPMV_CSR_ALG1: 2 HIPSPARSE_SPMV_CSR_ALG2: 3 HIPSPARSE_SPMV_COO_ALG2: 4 - hipsparseSpSVAlg_t: bases: [c_int ] attr: HIPSPARSE_SPSV_ALG_DEFAULT: 0 - hipsparseSpSMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPSM_ALG_DEFAULT: 0 - hipsparseSpMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPMM_ALG_DEFAULT: 0 HIPSPARSE_SPMM_COO_ALG1: 1 HIPSPARSE_SPMM_COO_ALG2: 2 HIPSPARSE_SPMM_COO_ALG3: 3 HIPSPARSE_SPMM_COO_ALG4: 5 HIPSPARSE_SPMM_CSR_ALG1: 4 HIPSPARSE_SPMM_CSR_ALG2: 6 HIPSPARSE_SPMM_CSR_ALG3: 12 HIPSPARSE_SPMM_BLOCKED_ELL_ALG1: 13 - hipsparseSPGEMMAlg_t: bases: [c_int ] attr: HIPSPARSE_SPGEMM_DEFAULT: 0 HIPSPARSE_SPGEMM_CSR_ALG_DETERMINISTIC: 1 HIPSPARSE_SPGEMM_CSR_ALG_NONDETERMINISTIC: 2 HIPSPARSE_SPGEMM_ALG1: 3 HIPSPARSE_SPGEMM_ALG2: 4 HIPSPARSE_SPGEMM_ALG3: 5 indextype i32: &i32 - index_type_I: i32 index_type_J: i32 indextype i64i32 mixture: &i64i32 - index_type_I: i64 index_type_J: i32 indextype i64: &i64 - index_type_I: i64 index_type_J: i64 indextype i32 and i64: &i32_i64 - index_type_I: i32 index_type_J: i32 - index_type_I: i64 index_type_J: i64 indextype i32 i64i32 mixture and i64: &i32i32_i64i32_i64i64 - index_type_I: i32 index_type_J: i32 - index_type_I: i64 index_type_J: i32 - index_type_I: i64 index_type_J: i64 Real precisions: &real_precisions - &int8_int8_int32_xyt_precision { x_type: i8_r, y_type: i8_r, compute_type: i32_r } - &int8_int8_float32_xyt_precision { x_type: i8_r, y_type: i8_r, compute_type: f32_r } - &float16_float16_float32_xyt_precision { x_type: f16_r, y_type: f16_r, compute_type: f32_r } - &int8_int8_int32_int32_axyt_precision { a_type: i8_r, x_type: i8_r, y_type: i32_r, compute_type: i32_r } - &int8_int8_float32_float32_axyt_precision { a_type: i8_r, x_type: i8_r, y_type: f32_r, compute_type: f32_r } - &int8_int8_int32_int32_abct_precision { a_type: i8_r, b_type: i8_r, c_type: i32_r, compute_type: i32_r } - &int8_int8_float32_float32_abct_precision { a_type: i8_r, b_type: i8_r, c_type: f32_r, compute_type: f32_r } - &float16_float16_float32_float32_abct_precision { a_type: f16_r, b_type: f16_r, c_type: f32_r, compute_type: f32_r } - &int8_precision { a_type: i8_r, b_type: i8_r, c_type: i8_r, x_type: i8_r, y_type: i8_r, compute_type: i8_r } - &half_precision { a_type: f16_r, b_type: f16_r, c_type: f16_r, x_type: f16_r, y_type: f16_r, compute_type: f16_r } - &single_precision { a_type: f32_r, b_type: f32_r, c_type: f32_r, x_type: f32_r, y_type: f32_r, compute_type: f32_r } - &double_precision { a_type: f64_r, b_type: f64_r, c_type: f64_r, x_type: f64_r, y_type: f64_r, compute_type: f64_r } - &float32_float64_float64_float64 { a_type: f32_r, x_type: f64_r, y_type: f64_r, compute_type: f64_r } Complex precisions: &complex_precisions - &float32_cmplx32_cmplx32_cmplx32_axyt_precision { a_type: f32_r, x_type: f32_c, y_type: f32_c, compute_type: f32_c } - &float64_cmplx64_cmplx64_cmplx64_axyt_precision { a_type: f64_r, x_type: f64_c, y_type: f64_c, compute_type: f64_c } - &single_precision_complex { a_type: f32_c, b_type: f32_c, c_type: f32_c, x_type: f32_c, y_type: f32_c, compute_type: f32_c } - &double_precision_complex { a_type: f64_c, b_type: f64_c, c_type: f64_c, x_type: f64_c, y_type: f64_c, compute_type: f64_c } - &cmplx32_cmplx64_cmplx64_cmplx64 { a_type: f32_c, x_type: f64_c, y_type: f64_c, compute_type: f64_c } C precisions real: &single_only_precisions - *single_precision C precisions real: &double_only_precisions - *double_precision C precisions real: &single_double_precisions - *single_precision - *double_precision C precisions complex: &single_only_precisions_complex - *single_precision_complex C precisions complex: &double_only_precisions_complex - *double_precision_complex C precisions complex: &single_double_precisions_complex - *single_precision_complex - *double_precision_complex C precisions complex and real: &single_double_precisions_complex_real - *single_precision - *double_precision - *single_precision_complex - *double_precision_complex C precisions complex and real: &single_only_precisions_complex_real - *single_precision - *single_precision_complex C precisions complex and real: &double_only_precisions_complex_real - *double_precision - *double_precision_complex # The Arguments struct passed directly to C++. See hipsparse_arguments.hpp. # The order of the entries is significant, so it can't simply be a dictionary. # The types on the RHS are eval'd for Python-recognized types including ctypes # and datatypes defined in Datatypes above. T*n represents array of length n. Arguments: - M: c_int - N: c_int - K: c_int - nnz: c_int - block_dim: c_int - row_block_dimA: c_int - col_block_dimA: c_int - row_block_dimB: c_int - col_block_dimB: c_int - lda: c_int - ldb: c_int - ldc: c_int - batch_count: c_int - index_type_I: hipsparseIndexType_t - index_type_J: hipsparseIndexType_t - compute_type: hipDataType - alpha: c_double - alphai: c_double - beta: c_double - betai: c_double - threshold: c_double - percentage: c_double - c: c_double - s: c_double - transA: hipsparseOperation_t - transB: hipsparseOperation_t - baseA: hipsparseIndexBase_t - baseB: hipsparseIndexBase_t - baseC: hipsparseIndexBase_t - baseD: hipsparseIndexBase_t - action: hipsparseAction_t - part: hipsparseHybPartition_t - diag_type: hipsparseDiagType_t - fill_mode: hipsparseFillMode_t - solve_policy: hipsparseSolvePolicy_t - dirA: hipsparseDirection_t - orderA: hipsparseOrder_t - orderB: hipsparseOrder_t - orderC: hipsparseOrder_t - formatA: hipsparseFormat_t - formatB: hipsparseFormat_t - csr2csc_alg: hipsparseCsr2CscAlg_t - dense2sparse_alg: hipsparseDenseToSparseAlg_t - sparse2dense_alg: hipsparseSparseToDenseAlg_t - sddmm_alg: hipsparseSDDMMAlg_t - spgemm_alg: hipsparseSpGEMMAlg_t - spmm_alg: hipsparseSpMMAlg_t - spmv_alg: hipsparseSpMVAlg_t - spsm_alg: hipsparseSpSMAlg_t - spsv_alg: hipsparseSpSVAlg_t - numericboost: c_int - boosttol: c_double - boostval: c_double - boostvali: c_double - ell_width: c_int - permute: c_int - gtsv_alg: c_int - gpsv_alg: c_int - unit_check: c_int - timing: c_int - iters: c_int - filename: c_char*192 - function: c_char*64 - category: c_char*32 # These named dictionary lists [ {dict1}, {dict2}, etc. ] supply subsets of # test arguments in a structured way. The dictionaries are applied to the test # one at a time, to generate combinations. If one of this table's entries is # a dictionary of size one, it means that the argument named by its key takes # on values paired with argument named by its value. For example: # # - function: precision # # when used with the code: # # function: # func1: prec1 # func2: prec2 # func3: prec3 # # causes (function, precision) to take on the values (func1, prec1), # (func2, prec2), (func3, prec3), etc. Dictionary lists to expand: - arguments - M_N - M_N_K - transA_transB - alpha_beta - alpha_alphai - beta_betai - alphai_betai - boostval_boostvali - indextype - precision - function: precision # In case an array argument needs to be passed directly to C as an array, # it needs to be listed here to avoid being expanded into multiple test # cases with each of its elements. Lists to not expand: - e.g., an array argument not to be expanded # Defaults Defaults: M: -1 N: -1 K: -1 nnz: -1 block_dim: 2 row_block_dimA: 2 col_block_dimA: 2 row_block_dimB: 2 col_block_dimB: 2 lda: 1 ldb: 1 ldc: 1 batch_count: -1 index_type_I: i32 index_type_J: i32 compute_type: f32_r alpha: 1.0 alphai: 0.0 beta: 0.0 betai: 0.0 threshold: 1.0 percentage: 0.0 c: 1.0 s: 1.0 transA: HIPSPARSE_OPERATION_NON_TRANSPOSE transB: HIPSPARSE_OPERATION_NON_TRANSPOSE baseA: HIPSPARSE_INDEX_BASE_ZERO baseB: HIPSPARSE_INDEX_BASE_ZERO baseC: HIPSPARSE_INDEX_BASE_ZERO baseD: HIPSPARSE_INDEX_BASE_ZERO action: HIPSPARSE_ACTION_NUMERIC part: HIPSPARSE_HYB_PARTITION_AUTO diag_type: HIPSPARSE_DIAG_TYPE_NON_UNIT fill_mode: HIPSPARSE_FILL_MODE_LOWER solve_policy: HIPSPARSE_SOLVE_POLICY_USE_LEVEL dirA: HIPSPARSE_DIRECTION_ROW orderA: HIPSPARSE_ORDER_COL orderB: HIPSPARSE_ORDER_COL orderC: HIPSPARSE_ORDER_COL formatA: HIPSPARSE_FORMAT_CSR formatB: HIPSPARSE_FORMAT_CSR csr2csc_alg: HIPSPARSE_CSR2CSC_ALG_DEFAULT dense2sparse_alg: HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT sparse2dense_alg: HIPSPARSE_SPARSETODENSE_ALG_DEFAULT sddmm_alg: HIPSPARSE_SDDMM_ALG_DEFAULT spgemm_alg: HIPSPARSE_SPGEMM_DEFAULT spmm_alg: HIPSPARSE_SPMM_ALG_DEFAULT spmv_alg: HIPSPARSE_SPMV_ALG_DEFAULT spsm_alg: HIPSPARSE_SPSM_ALG_DEFAULT spsv_alg: HIPSPARSE_SPSV_ALG_DEFAULT numericboost: 0 boosttol: 0.0 boostval: 1.0 boostvali: 0.0 ell_width: 0 permute: 0 gtsv_alg: 0 gpsv_alg: 0 unit_check: 1 timing: 0 iters: 10 filename: '*' function: '*' category: '*'./clients/include/testing_sddmm_csr.hpp0000664000175100017510000004773515176134511020434 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_CSR_HPP #define TESTING_SDDMM_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_64I; hipsparseIndexType_t idxTypeJ = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int64_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int64_t* dptr = (int64_t*)dptr_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCsr(&C, m, n, nnz, dptr, dcol, dval, idxTypeI, idxTypeJ, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_csr(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; J k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Some matrix properties J A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; J A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; J B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; J B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; J C_m = m; J C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(nnz_A); std::vector hB(nnz_B); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (C_m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (C_m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&C1, C_m, C_n, nnz, dptr, dcol, dval1, typeI, typeJ, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&C2, C_m, C_n, nnz, dptr, dcol, dval2, typeI, typeJ, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(J r = 0; r < C_m; r++) { I start = hcsr_row_ptr[r] - idx_base; I end = hcsr_row_ptr[r + 1] - idx_base; for(I j = start; j < end; j++) { J c = hcsr_col_ind[j] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I s = 0; s < k; ++s) { sum = testing_fma(Aptr[incA * s], Bptr[incB * s], sum); } hcsr_val[j] = testing_mult(hcsr_val[j], h_beta) + testing_mult(h_alpha, sum); } } unit_check_near(1, nnz, 1, hval1.data(), hcsr_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_csr_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_CSR), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_CSR_HPP ./clients/include/testing_gemmi.hpp0000664000175100017510000006525415176134511017553 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEMMI_HPP #define TESTING_GEMMI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gemmi_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* drow = (int*)drow_managed.get(); T* dval = (T*)dval_managed.get(); T* dA = (T*)dA_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_handle(hipsparseXgemmi(nullptr, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size)); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, nullptr, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, nullptr, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, nullptr, dptr, drow, &beta, dC, safe_size), "Error: cscValB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, nullptr, drow, &beta, dC, safe_size), "Error: cscColPtrB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, nullptr, &beta, dC, safe_size), "Error: cscRowIndB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, nullptr, dC, safe_size), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, nullptr, safe_size), "Error: C is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, -1, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, -1, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, -1, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: k is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, -1, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, safe_size), "Error: nnz is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, -1, dval, dptr, drow, &beta, dC, safe_size), "Error: lda is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgemmi(handle, safe_size, safe_size, safe_size, safe_size, &alpha, dA, safe_size, dval, dptr, drow, &beta, dC, -1), "Error: ldc is invalid"); #endif } template hipsparseStatus_t testing_gemmi(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; int K = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(M == 0 || N == 0 || K == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsc_col_ptrB; std::vector hcsc_row_indB; std::vector hcsc_valB; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, N, K, nnz, hcsc_col_ptrB, hcsc_row_indB, hcsc_valB, HIPSPARSE_INDEX_BASE_ZERO)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int lda = std::max(1, M); int ldc = std::max(1, M); int Annz = lda * K; int Cnnz = ldc * N; // Host structures - Dense matrix B and C std::vector hA(Annz); std::vector hC_1(Cnnz); std::vector hC_2(Cnnz); std::vector hC_gold(Cnnz); hipsparseInit(hA, M, K); hipsparseInit(hC_gold, M, N); // allocate memory on device auto dcsc_col_ptrB_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (N + 1)), device_free}; auto dcsc_row_indB_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_valB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Annz), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * Cnnz), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsc_col_ptrB = (int*)dcsc_col_ptrB_managed.get(); int* dcsc_row_indB = (int*)dcsc_row_indB_managed.get(); T* dcsc_valB = (T*)dcsc_valB_managed.get(); T* dA = (T*)dA_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsc_col_ptrB, hcsc_col_ptrB.data(), sizeof(int) * (N + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsc_row_indB, hcsc_row_indB.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsc_valB, hcsc_valB.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * Annz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_gold.data(), sizeof(T) * Cnnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dC_2, dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); // pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, d_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, d_beta, dC_2, ldc)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * Cnnz, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < M; ++i) { for(int j = 0; j < N; ++j) { T sum = make_DataType(0); int col_begin = hcsc_col_ptrB[j]; int col_end = hcsc_col_ptrB[j + 1]; for(int k = col_begin; k < col_end; ++k) { int row_B = hcsc_row_indB[k]; T val_B = hcsc_valB[k]; T val_A = hA[row_B * lda + i]; sum = testing_fma(val_A, val_B, sum); } hC_gold[j * ldc + i] = testing_fma(h_beta, hC_gold[j * ldc + i], testing_mult(h_alpha, sum)); } } unit_check_near(M, N, ldc, hC_gold.data(), hC_1.data()); unit_check_near(M, N, ldc, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgemmi(handle, M, N, K, nnz, &h_alpha, dA, lda, dcsc_valB, dcsc_col_ptrB, dcsc_row_indB, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = gemmi_gflop_count(M, nnz, M * N, h_beta != make_DataType(0.0)); double gbyte_count = gemmi_gbyte_count(N, nnz, M * K, M * N, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::K, K, display_key_t::nnzA, M * K, display_key_t::nnzB, nnz, display_key_t::nnzC, M * N, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEMMI_HPP ./clients/include/testing_gtsv_interleaved_batch.hpp0000664000175100017510000002347515176134511023162 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV_INTERLEAVED_BATCH_HPP #define TESTING_GTSV_INTERLEAVED_BATCH_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv_interleaved_batch_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int algo = 0; int m = 10; int batch_count = 10; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsvInterleavedBatch_bufferSizeExt verify_hipsparse_status_invalid_handle(hipsparseXgtsvInterleavedBatch_bufferSizeExt( nullptr, algo, m, ddl, dd, ddu, dx, batch_count, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch_bufferSizeExt( handle, algo, -1, ddl, dd, ddu, dx, batch_count, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch_bufferSizeExt(handle, algo, m, ddl, dd, ddu, dx, -1, &bsize), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, ddl, dd, ddu, dx, batch_count, nullptr), "Error: bsize is nullptr"); // gtsvInterleavedBatch verify_hipsparse_status_invalid_handle( hipsparseXgtsvInterleavedBatch(nullptr, algo, m, ddl, dd, ddu, dx, batch_count, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch(handle, algo, -1, ddl, dd, ddu, dx, batch_count, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, -1, dbuf), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, (T*)nullptr, dd, ddu, dx, batch_count, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, (T*)nullptr, ddu, dx, batch_count, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, (T*)nullptr, dx, batch_count, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, ddu, (T*)nullptr, batch_count, dbuf), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, batch_count, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gtsv_interleaved_batch(Arguments argus) { int m = argus.M; int batch_count = argus.batch_count; int algo = argus.gtsv_alg; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hdl(m * batch_count, make_DataType(1)); std::vector hd(m * batch_count, make_DataType(2)); std::vector hdu(m * batch_count, make_DataType(1)); std::vector hx(m * batch_count, make_DataType(3)); for(int i = 0; i < batch_count; i++) { hdl[i] = make_DataType(0); hdu[batch_count * (m - 1) + i] = make_DataType(0); } std::vector hx_original = hx; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dx = (T*)dx_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXgtsvInterleavedBatch_bufferSizeExt( handle, algo, m, ddl, dd, ddu, dx, batch_count, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXgtsvInterleavedBatch(handle, algo, m, ddl, dd, ddu, dx, batch_count, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx.data(), dx, sizeof(T) * m * batch_count, hipMemcpyDeviceToHost)); // Check std::vector hresult(m * batch_count, make_DataType(3)); for(int j = 0; j < batch_count; j++) { hresult[j] = testing_mult(hd[j], hx[j]) + testing_mult(hdu[j], hx[batch_count + j]); hresult[batch_count * (m - 1) + j] = testing_mult(hdl[batch_count * (m - 1) + j], hx[batch_count * (m - 2) + j]) + testing_mult(hd[batch_count * (m - 1) + j], hx[batch_count * (m - 1) + j]); } for(int i = 1; i < m - 1; i++) { for(int j = 0; j < batch_count; j++) { hresult[batch_count * i + j] = testing_mult(hdl[batch_count * i + j], hx[batch_count * (i - 1) + j]) + testing_mult(hd[batch_count * i + j], hx[batch_count * i + j]) + testing_mult(hdu[batch_count * i + j], hx[batch_count * (i + 1) + j]); } } unit_check_near(1, m * batch_count, 1, hx_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, ddu, dx, batch_count, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsvInterleavedBatch( handle, algo, m, ddl, dd, ddu, dx, batch_count, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_interleaved_batch_gbyte_count(m, batch_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::batch_count, batch_count, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV_INTERLEAVED_BATCH_HPP ./clients/include/testing_dense2csr.hpp0000664000175100017510000000401315176134511020327 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE2CSR_HPP #define TESTING_DENSE2CSR_HPP #include "testing_dense2csx.hpp" template void testing_dense2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_dense2csx_bad_arg(hipsparseXdense2csr); #endif } template hipsparseStatus_t testing_dense2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_dense2csx(argus, hipsparseXdense2csr); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_DENSE2CSR ./clients/include/testing_csr2csr_compress.hpp0000664000175100017510000007451415176134511021750 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2CSR_COMPRESS_HPP #define TESTING_CSR2CSR_COMPRESS_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csr_compress_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int nnz_A = 1; int safe_size = 1; T tol = make_DataType(0); hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); auto csr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto nnz_per_row_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto nnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* csr_row_ptr_A = (int*)csr_row_ptr_A_managed.get(); int* csr_col_ind_A = (int*)csr_col_ind_A_managed.get(); T* csr_val_A = (T*)csr_val_A_managed.get(); int* csr_row_ptr_C = (int*)csr_row_ptr_C_managed.get(); int* csr_col_ind_C = (int*)csr_col_ind_C_managed.get(); T* csr_val_C = (T*)csr_val_C_managed.get(); int* nnz_per_row = (int*)nnz_per_row_managed.get(); int* nnz_C = (int*)nnz_C_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_A, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr_C, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); int local_nnz[1] = {1}; CHECK_HIP_ERROR(hipMemcpy(nnz_per_row, local_nnz, sizeof(int), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXnnz_compress( nullptr, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol)); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress( handle, m, nullptr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol), "Error: Matrix descriptor is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, nullptr, nnz_per_row, nnz_C, tol), "Error: CSR row pointer array is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nullptr, nnz_C, tol), "Error: Number of elements per row array is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXnnz_compress( handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nullptr, tol), "Error: Total number of elements pointer is invalid"); verify_hipsparse_status_invalid_size( hipsparseXnnz_compress( handle, -1, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXnnz_compress(handle, m, csr_descr, csr_val_A, csr_row_ptr_A, nnz_per_row, nnz_C, make_DataType(-1)), "Error: Tolerance is invalid"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2csr_compress(nullptr, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol)); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, nullptr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix descriptor is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, (const T*)nullptr, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix values array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, nullptr, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix column indices array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, nullptr, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix row pointer array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nullptr, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Number of elements per row array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, (T*)nullptr, csr_col_ind_C, csr_row_ptr_C, tol), "Error: CSR matrix values array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, nullptr, csr_row_ptr_C, tol), "Error: CSR matrix column indices array is invalid"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, nullptr, tol), "Error: CSR matrix row pointer array is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, -1, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, m, -1, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_size(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, -1, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, tol), "Error: Matrix size is invalid"); verify_hipsparse_status_invalid_value(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, csr_val_A, csr_col_ind_A, csr_row_ptr_A, nnz_A, nnz_per_row, csr_val_C, csr_col_ind_C, csr_row_ptr_C, static_cast(-1)), "Error: Tolerance is invalid"); #endif } template hipsparseStatus_t testing_csr2csr_compress(Arguments argus) { int m = argus.M; int n = argus.N; T tol = make_DataType(argus.alpha); hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; hipsparseSetMatIndexBase(csr_descr, idx_base); hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int hnnz_A = 0; if(!generate_csr_matrix( filename, m, n, hnnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_A), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_A), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dnnz_per_row_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * m), device_free}; int* dcsr_row_ptr_A = (int*)dcsr_row_ptr_A_managed.get(); int* dcsr_col_ind_A = (int*)dcsr_col_ind_A_managed.get(); T* dcsr_val_A = (T*)dcsr_val_A_managed.get(); int* dcsr_row_ptr_C = (int*)dcsr_row_ptr_C_managed.get(); int* dnnz_per_row = (int*)dnnz_per_row_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(int) * hnnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(T) * hnnz_A, hipMemcpyHostToDevice)); if(argus.unit_check) { // Use both host and device pointers for nnz_C and confirm they give the same answer CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnz_C; CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, &hnnz_C, tol)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, dnnz_C, tol)); int hnnz_C_copied_from_device; CHECK_HIP_ERROR( hipMemcpy(&hnnz_C_copied_from_device, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); unit_check_general(1, 1, 1, &hnnz_C_copied_from_device, &hnnz_C); if(hnnz_C == 0) { return HIPSPARSE_STATUS_SUCCESS; } // Allocate device memory for compressed CSR columns indices and values auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C), device_free}; int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); // Copy output from device to host std::vector hcsr_row_ptr_C(m + 1); std::vector hcsr_col_ind_C(hnnz_C); std::vector hcsr_val_C(hnnz_C); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C.data(), dcsr_row_ptr_C, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C.data(), dcsr_col_ind_C, sizeof(int) * hnnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C.data(), dcsr_val_C, sizeof(T) * hnnz_C, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsr_row_ptr_C_gold; std::vector hcsr_col_ind_C_gold; std::vector hcsr_val_gold; // Call host conversion here host_csr_to_csr_compress(m, n, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, hcsr_row_ptr_C_gold, hcsr_col_ind_C_gold, hcsr_val_gold, idx_base, tol); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, hnnz_C, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_general(1, hnnz_C, 1, hcsr_val_gold.data(), hcsr_val_C.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); int hnnz_C; CHECK_HIPSPARSE_ERROR(hipsparseXnnz_compress( handle, m, csr_descr, dcsr_val_A, dcsr_row_ptr_A, dnnz_per_row, &hnnz_C, tol)); // Allocate device memory for compressed CSR columns indices and values auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C), device_free}; int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csr_compress(handle, m, n, csr_descr, dcsr_val_A, dcsr_col_ind_A, dcsr_row_ptr_A, hnnz_A, dnnz_per_row, dcsr_val_C, dcsr_col_ind_C, dcsr_row_ptr_C, tol)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csr_compress_gbyte_count(m, hnnz_A, hnnz_C); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnzA, hnnz_A, display_key_t::nnzC, hnnz_C, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSR_COMPRESS_HPP ./clients/include/testing_dense_to_sparse_csc.hpp0000664000175100017510000003357215176134511022460 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE_TO_SPARSE_CSC_HPP #define TESTING_DENSE_TO_SPARSE_CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_dense_to_sparse_csc_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t jType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcsc_col_ptr = (int32_t*)dcsc_col_ptr_managed.get(); int32_t* dcsc_row_ind = (int32_t*)dcsc_row_ind_managed.get(); float* dcsc_val = (float*)dcsc_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseDnVecDescr_t matA; hipsparseSpMatDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateDnMat(&matA, m, n, ld, ddense_val, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateCsc(&matB, m, n, nnz, dcsc_col_ptr, dcsc_row_ind, dcsc_val, iType, jType, idxBase, dataType), "success"); // denseToSparse buffer size verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse analysis verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_analysis(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse_convert verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_convert(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(matB), "success"); #endif } template hipsparseStatus_t testing_dense_to_sparse_csc(Arguments argus) { #if(!defined(CUDART_VERSION)) J m = argus.M; J n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDenseToSparseAlg_t alg = static_cast(argus.dense2sparse_alg); hipsparseOrder_t order = argus.orderA; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; // Host structures I nrow = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncol = (order == HIPSPARSE_ORDER_COL) ? n : ld; std::vector hdense_val(nrow * ncol); if(order == HIPSPARSE_ORDER_COL) { for(int i = 0; i < n; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } else { for(int i = 0; i < m; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, order, 0.2); // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (n + 1)), device_free}; auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrow * ncol), device_free}; I* dptr = (I*)dptr_managed.get(); T* ddense = (T*)ddense_managed.get(); // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * nrow * ncol, hipMemcpyHostToDevice)); // Create dense matrix hipsparseDnMatDescr_t matA; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matA, m, n, ld, ddense, typeT, order)); // Create matrices hipsparseSpMatDescr_t matB; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsc(&matB, m, n, 0, dptr, nullptr, nullptr, typeI, typeJ, idx_base, typeT)); // Query DenseToSparse buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_analysis(handle, matA, matB, alg, buffer)); int64_t rows, cols, nnz; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(matB, &rows, &cols, &nnz)); auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; J* drow = (J*)drow_managed.get(); T* dval = (T*)dval_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseCscSetPointers(matB, dptr, drow, dval)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); // copy output from device to CPU std::vector hcsc_col_ptr(n + 1); std::vector hcsc_row_ind(nnz); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_col_ptr.data(), dptr, sizeof(I) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), drow, sizeof(J) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsc_val.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); std::vector hcsc_col_ptr_cpu(n + 1); std::vector hcsc_row_ind_cpu(nnz); std::vector hcsc_val_cpu(nnz); std::vector hnnz_per_column(n, 0); if(order == HIPSPARSE_ORDER_COL) { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hnnz_per_column[j]++; } } } } else { for(J i = 0; i < m; ++i) { for(J j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hnnz_per_column[j]++; } } } } hcsc_col_ptr_cpu[0] = idx_base; for(J i = 0; i < n; ++i) { hcsc_col_ptr_cpu[i + 1] = hnnz_per_column[i] + hcsc_col_ptr_cpu[i]; } if(order == HIPSPARSE_ORDER_COL) { int index = 0; for(J i = 0; i < n; ++i) { for(J j = 0; j < m; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hcsc_val_cpu[index] = hdense_val[i * ld + j]; hcsc_row_ind_cpu[index] = j + idx_base; index++; } } } } else { int index = 0; for(J i = 0; i < n; ++i) { for(J j = 0; j < m; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hcsc_val_cpu[index] = hdense_val[j * ld + i]; hcsc_row_ind_cpu[index] = j + idx_base; index++; } } } } unit_check_general(1, (n + 1), 1, hcsc_col_ptr_cpu.data(), hcsc_col_ptr.data()); unit_check_general(1, nnz, 1, hcsc_row_ind_cpu.data(), hcsc_row_ind.data()); unit_check_general(1, nnz, 1, hcsc_val_cpu.data(), hcsc_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2csx_gbyte_count(m, n, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_densetosparsealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE_TO_SPARSE_CSC_HPP ./clients/include/testing_csrgeam2.hpp0000664000175100017510000020542415176134511020153 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEAM2_HPP #define TESTING_CSRGEAM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgeam2_bad_arg(void) { #if(!defined(CUDART_VERSION)) int safe_size = 1; T alpha = 1.0; T beta = 1.0; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); void* dbuffer = dbuf_managed.get(); const int M = safe_size; std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // skip bufferSizeExt as there is no implementation in rocsparse // testing hipsparseXcsrgeam2Nnz verify_hipsparse_status_invalid_handle(hipsparseXcsrgeam2Nnz(nullptr, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, nullptr, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, nullptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, nullptr, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, nullptr, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, nullptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, nullptr, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, nullptr, dCptr, &nnz_C, dbuffer), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, nullptr, &nnz_C, dbuffer), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, nullptr, dbuffer), "Error: invalid nnz_C pointer"); // testing hipsparseXcsrgeam2 verify_hipsparse_status_invalid_handle(hipsparseXcsrgeam2(nullptr, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, (T*)nullptr, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid alpha pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, nullptr, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid descr_A pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, (T*)nullptr, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dAval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, nullptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dAptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, nullptr, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dAcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, (T*)nullptr, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid beta pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, nullptr, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid descr_B pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, (T*)nullptr, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dBval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, nullptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dBptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, nullptr, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid dBcol pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, nullptr, dCval, dCptr, dCcol, dbuffer), "Error: invalid descr_C pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr, dCcol, dbuffer), "Error: invalid dCval pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, nullptr, dCcol, dbuffer), "Error: invalid dCptr pointer"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, nullptr, dbuffer), "Error: invalid dCcol pointer"); // testing invalid sizes verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, -1, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, safe_size, -1, descr_A, safe_size, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, -1, dAptr, dAcol, descr_B, safe_size, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2Nnz(handle, safe_size, safe_size, descr_A, safe_size, dAptr, dAcol, descr_B, -1, dBptr, dBcol, descr_C, dCptr, &nnz_C, dbuffer), "Error: invalid nnz_B size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, -1, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid M size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, safe_size, -1, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid N size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, -1, dAval, dAptr, dAcol, &beta, descr_B, safe_size, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid nnz_A size"); verify_hipsparse_status_invalid_size(hipsparseXcsrgeam2(handle, safe_size, safe_size, &alpha, descr_A, safe_size, dAval, dAptr, dAcol, &beta, descr_B, -1, dBval, dBptr, dBcol, descr_C, dCval, dCptr, dCcol, dbuffer), "Error: invalid nnz_B size"); #endif } template hipsparseStatus_t testing_csrgeam2(Arguments argus) { int M = argus.M; int N = argus.N; hipsparseIndexBase_t idx_base_A = argus.baseA; hipsparseIndexBase_t idx_base_B = argus.baseB; hipsparseIndexBase_t idx_base_C = argus.baseC; std::string filename = argus.filename; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_A, idx_base_A)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_B, idx_base_B)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Read or construct CSR matrix int nnz_A = 0; if(!generate_csr_matrix( filename, M, N, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idx_base_A)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // B = A so that we can compute the square of A int nnz_B = nnz_A; std::vector hcsr_row_ptr_B(M + 1, 0); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); for(int i = 0; i < M + 1; ++i) { hcsr_row_ptr_B[i] = hcsr_row_ptr_A[i] - idx_base_A + idx_base_B; } for(int i = 0; i < nnz_A; ++i) { hcsr_col_ind_B[i] = hcsr_col_ind_A[i] - idx_base_A + idx_base_B; } hcsr_val_B = hcsr_val_A; // Allocate memory on device auto dAptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dAcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_A), device_free}; auto dAval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dBptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dBcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz_B), device_free}; auto dBval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dCptr_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dCptr_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dbeta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dAptr = (int*)dAptr_managed.get(); int* dAcol = (int*)dAcol_managed.get(); T* dAval = (T*)dAval_managed.get(); int* dBptr = (int*)dBptr_managed.get(); int* dBcol = (int*)dBcol_managed.get(); T* dBval = (T*)dBval_managed.get(); int* dCptr_1 = (int*)dCptr_1_managed.get(); int* dCptr_2 = (int*)dCptr_2_managed.get(); T* dalpha = (T*)dalpha_managed.get(); T* dbeta = (T*)dbeta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dAptr, hcsr_row_ptr_A.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dAcol, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dAval, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBptr, hcsr_row_ptr_B.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dBcol, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dBval, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); // Obtain csrgeam2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2_bufferSizeExt(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, (T*)nullptr, dCptr_1, (int*)nullptr, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2Nnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_1, &hnnz_C_1, dbuffer)); // Allocate result matrix auto dCcol_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; int* dCcol_1 = (int*)dCcol_1_managed.get(); T* dCval_1 = (T*)dCval_1_managed.get(); CHECK_HIP_ERROR(hipMemcpy(dalpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbeta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // hipsparse pointer mode device auto dCcol_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * hnnz_C_1), device_free}; auto dCval_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * hnnz_C_1), device_free}; auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dCcol_2 = (int*)dCcol_2_managed.get(); T* dCval_2 = (T*)dCval_2_managed.get(); int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2Nnz(handle, M, N, descr_A, nnz_A, dAptr, dAcol, descr_B, nnz_B, dBptr, dBcol, descr_C, dCptr_2, dnnz_C, dbuffer)); // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { // Compute csrgeam2 CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1, dbuffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, dalpha, descr_A, nnz_A, dAval, dAptr, dAcol, dbeta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_2, dCptr_2, dCcol_2, dbuffer)); // Copy output from device to CPU std::vector hcsr_row_ptr_C_1(M + 1); std::vector hcsr_row_ptr_C_2(M + 1); std::vector hcsr_col_ind_C_1(hnnz_C_1); std::vector hcsr_col_ind_C_2(hnnz_C_2); std::vector hcsr_val_C_1(hnnz_C_1); std::vector hcsr_val_C_2(hnnz_C_2); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_1.data(), dCptr_1, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C_2.data(), dCptr_2, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_1.data(), dCcol_1, sizeof(int) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C_2.data(), dCcol_2, sizeof(int) * hnnz_C_2, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval_1, sizeof(T) * hnnz_C_1, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval_2, sizeof(T) * hnnz_C_2, hipMemcpyDeviceToHost)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); int nnz_C_gold = host_csrgeam_nnz(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_row_ptr_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgeam(M, N, h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), h_beta, hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idx_base_A, idx_base_B, idx_base_C); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_1.data()); unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C_2.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_1.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C_2.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrgeam2(handle, M, N, &h_alpha, descr_A, nnz_A, dAval, dAptr, dAcol, &h_beta, descr_B, nnz_B, dBval, dBptr, dBcol, descr_C, dCval_1, dCptr_1, dCcol_1, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrgeam_gflop_count(nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gbyte_count = csrgeam_gbyte_count(M, nnz_A, nnz_B, hnnz_C_1, &h_alpha, &h_beta); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::nnzA, nnz_A, display_key_t::nnzB, nnz_B, display_key_t::nnzC, hnnz_C_1, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEAM2_HPP ./clients/include/testing_axpby.hpp0000664000175100017510000001776615176134511017605 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_AXPBY_HPP #define TESTING_AXPBY_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_axpby_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int64_t size = 100; int64_t nnz = 100; float alpha = 3.7f; float beta = 1.2f; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Axpby verify_hipsparse_status_invalid_handle(hipsparseAxpby(nullptr, &alpha, x, &beta, y)); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, nullptr, x, &beta, y), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, &alpha, nullptr, &beta, y), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, &alpha, x, nullptr, y), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseAxpby(handle, &alpha, x, &beta, nullptr), "Error: y is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_axpby(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) I size = argus.N; I nnz = argus.nnz; T alpha = make_DataType(argus.alpha); T beta = make_DataType(argus.beta); hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(size); std::vector hy_gold(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, size); hy_gold = hy; // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * size, hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y, size, dy, dataType)); if(argus.unit_check) { // Axpby CHECK_HIPSPARSE_ERROR(hipsparseAxpby(handle, &alpha, x, &beta, y)); // Copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * size, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < size; ++i) { hy_gold[i] = testing_mult(beta, hy_gold[i]); } for(int64_t i = 0; i < nnz; ++i) { hy_gold[hx_ind[i] - idxBase] = testing_fma(alpha, hx_val[i], hy_gold[hx_ind[i] - idxBase]); } // Verify results against host unit_check_general(1, size, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseAxpby(handle, &alpha, x, &beta, y)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseAxpby(handle, &alpha, x, &beta, y)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = axpby_gflop_count(nnz); double gbyte_count = axpby_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::size, size, display_key_t::nnz, nnz, display_key_t::alpha, alpha, display_key_t::beta, beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_AXPBY_HPP ./clients/include/testing_spsm_coo.hpp0000664000175100017510000004477315176134511020302 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSM_COO_HPP #define TESTING_SPSM_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsm_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSMAlg_t alg = HIPSPARSE_SPSM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* drow = (int*)drow_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSM structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t B, C; hipsparseSpSMDescr_t descr; verify_hipsparse_status_success(hipsparseSpSM_createDescr(&descr), "success"); size_t bsize; // Create SpSM structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, m, k, m, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, k, m, dC, dataType, order), "success"); // SpSM buffer verify_hipsparse_status_invalid_handle(hipsparseSpSM_bufferSize( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, &bsize), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_bufferSize( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSM analysis verify_hipsparse_status_invalid_handle(hipsparseSpSM_analysis( nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_analysis( handle, transA, transB, &alpha, A, B, C, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); // SpSM solve verify_hipsparse_status_invalid_handle( hipsparseSpSM_solve(nullptr, transA, transB, &alpha, A, B, C, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, nullptr, A, B, C, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, nullptr, B, C, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, nullptr, C, dataType, alg, descr, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve( handle, transA, transB, &alpha, A, B, nullptr, dataType, alg, descr, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSM_solve(handle, transA, transB, &alpha, A, B, C, dataType, alg, nullptr, dbuf), "Error: descr is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseSpSM_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spsm_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSMAlg_t alg = static_cast(argus.spsm_alg); std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } if(m != n) { // Skip non-square matrices return HIPSPARSE_STATUS_SUCCESS; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I C_m = m; I C_n = k; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * m) : (int64_t(ld_multiplier_B) * k)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * m)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * k); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, 1, nnz_B); hC_1 = hB; hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSMDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSM_bufferSize( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_analysis( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, d_alpha, A, B, C2, typeT, alg, descr, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); I struct_pivot = -1; I numeric_pivot = -1; host_coosm(m, k, nnz, transA, transB, h_alpha, hrow_ind, hcol_ind, hval, hB, (I)ldb, orderB, hC_gold, (I)ldc, orderC, diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpSM_solve( handle, transA, transB, &h_alpha, A, B, C1, typeT, alg, descr, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag) * k; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = coosv_gbyte_count(m, nnz) * k; double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSM_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSM_COO_HPP ./clients/include/testing_spmm_batched_coo.hpp0000664000175100017510000005202415176134511021732 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2022 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BATCHED_COO_HPP #define TESTING_SPMM_BATCHED_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_batched_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t m = 100; int32_t n = 100; int32_t k = 100; int64_t nnz = 100; float alpha = 0.6; float beta = 0.2; size_t safe_size = 100; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_COO_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_COOMM_ALG1; #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drow = (int32_t*)drow_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, k, nnz, drow, dcol, dval, idxTypeI, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); int batch_count_A; int batch_count_B; int batch_count_C; int64_t batch_stride_A; int64_t batch_stride_B; int64_t batch_stride_C; // C_i = A * B_i batch_count_A = 1; batch_count_B = 10; batch_count_C = 5; batch_stride_A = 0; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B batch_count_A = 10; batch_count_B = 1; batch_count_C = 5; batch_stride_A = nnz; batch_stride_B = 0; batch_stride_C = m * n; verify_hipsparse_status_success(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // C_i = A_i * B_i batch_count_A = 10; batch_count_B = 10; batch_count_C = 5; batch_stride_A = nnz; batch_stride_B = k * n; batch_stride_C = m * n; verify_hipsparse_status_success(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B), "success"); verify_hipsparse_status_success(hipsparseDnMatSetStridedBatch(C, batch_count_C, batch_stride_C), "success"); verify_hipsparse_status_invalid_value( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf), "Error: Combination of strided batch parameters is invald"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_batched_coo(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderB = argus.orderB; hipsparseOrder_t orderC = argus.orderC; hipsparseIndexBase_t idx_base = argus.baseA; I batch_count_A = 1; I batch_count_B = 10; I batch_count_C = 10; #if(CUDART_VERSION >= 11003) hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_COO_ALG1; #else hipsparseSpMMAlg_t alg = HIPSPARSE_COOMM_ALG1; #endif std::string filename = argus.filename; #if(defined(CUDART_VERSION)) if(orderB != orderC || orderB != HIPSPARSE_ORDER_COL) { return HIPSPARSE_STATUS_SUCCESS; } #endif // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix(filename, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k, (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m, nnz_A, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz_A); // Convert to COO I mk = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; for(I i = 0; i < mk; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_B = 1; int ld_multiplier_C = 1; int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); int64_t ldc = (orderC == HIPSPARSE_ORDER_COL) ? (int64_t(ld_multiplier_C) * m) : (int64_t(ld_multiplier_C) * n); ldb = std::max(int64_t(1), ldb); ldc = std::max(int64_t(1), ldc); int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nrowC = (orderC == HIPSPARSE_ORDER_COL) ? ldc : C_m; int64_t ncolC = (orderC == HIPSPARSE_ORDER_COL) ? C_n : ldc; int64_t nnz_B = nrowB * ncolB; int64_t nnz_C = nrowC * ncolC; int64_t batch_stride_A = (batch_count_A > 1) ? nnz_A : 0; int64_t batch_stride_B = (batch_count_B > 1) ? nnz_B : 0; int64_t batch_stride_C = (batch_count_C > 1) ? nnz_C : 0; // Allocate host memory for all batches of A matrix std::vector hcoo_row_ind(batch_count_A * nnz_A); std::vector hcoo_col_ind(batch_count_A * nnz_A); std::vector hcoo_val(batch_count_A * nnz_A); for(I i = 0; i < batch_count_A; i++) { for(int64_t j = 0; j < nnz_A; j++) { hcoo_row_ind[nnz_A * i + j] = hrow_ind[j]; hcoo_col_ind[nnz_A * i + j] = hcol_ind[j]; hcoo_val[nnz_A * i + j] = hval[j]; } } std::vector hB(batch_count_B * nnz_B); std::vector hC_1(batch_count_C * nnz_C); std::vector hC_2(batch_count_C * nnz_C); std::vector hC_gold(batch_count_C * nnz_C); hipsparseInit(hB, batch_count_B * nnz_B, 1); hipsparseInit(hC_1, batch_count_C * nnz_C, 1); // copy vector is easy in STL; hC_gold = hC: save a copy in hy_gold which will be output of CPU hC_2 = hC_1; hC_gold = hC_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * batch_count_A * nnz_A), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * batch_count_A * nnz_A), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_A * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_B * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * batch_count_C * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dcoo_row_ind = (I*)drow_managed.get(); I* dcoo_col_ind = (I*)dcol_managed.get(); T* dcoo_val = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dcoo_row_ind, hcoo_row_ind.data(), sizeof(I) * batch_count_A * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcoo_col_ind, hcoo_col_ind.data(), sizeof(I) * batch_count_A * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcoo_val, hcoo_val.data(), sizeof(T) * batch_count_A * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dB, hB.data(), sizeof(T) * batch_count_B * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_1, hC_1.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dC_2, hC_2.data(), sizeof(T) * batch_count_C * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR(hipsparseCreateCoo( &A, A_m, A_n, nnz_A, dcoo_row_ind, dcoo_col_ind, dcoo_val, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, C_m, C_n, ldc, dC_1, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, C_m, C_n, ldc, dC_2, typeT, orderC)); CHECK_HIPSPARSE_ERROR(hipsparseCooSetStridedBatch(A, batch_count_A, batch_stride_A)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(B, batch_count_B, batch_stride_B)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C1, batch_count_C, batch_stride_C)); CHECK_HIPSPARSE_ERROR(hipsparseDnMatSetStridedBatch(C2, batch_count_C, batch_stride_C)); // Query SpMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) //When using cusparse backend, cant pass nullptr for buffer to preprocess if(bufferSize == 0) { bufferSize = 4; } #endif void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); #endif // HIPSPARSE pointer mode device #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); #endif if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hC_1.data(), dC_1, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hC_2.data(), dC_2, sizeof(T) * batch_count_C * nnz_C, hipMemcpyDeviceToHost)); // CPU host_coomm_batched(A_m, n, A_n, nnz_A, batch_count_A, (I)batch_stride_A, transA, transB, h_alpha, hrow_ind.data(), hcol_ind.data(), hval.data(), hB.data(), (I)ldb, batch_count_B, (I)batch_stride_B, orderB, h_beta, hC_gold.data(), (I)ldc, batch_count_C, (I)batch_stride_C, orderC, idx_base); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, batch_count_C * nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = batch_count_C * spmm_gflop_count(n, nnz_A, (I)C_m * (I)C_n, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = coomm_batched_gbyte_count(A_m, nnz_A, (I)B_m * (I)B_n, (I)C_m * (I)C_n, batch_count_A, batch_count_B, batch_count_C, h_beta != make_DataType(0)); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnzA, nnz_A, display_key_t::batch_countA, batch_count_A, display_key_t::batch_countB, batch_count_B, display_key_t::batch_countC, batch_count_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BATCHED_COO_HPP ./clients/include/testing_const_spvec_descr.hpp0000664000175100017510000001325515176134305022156 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_SPVEC_DESCR_HPP #define TESTING_CONST_SPVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_const_spvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto idx_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; const int* idx_data = (const int*)idx_data_managed.get(); const float* val_data = (const float*)val_data_managed.get(); hipsparseConstSpVecDescr_t x; // hipsparseCreateConstSpVec verify_hipsparse_status_invalid_pointer( hipsparseCreateConstSpVec( nullptr, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateConstSpVec(&x, -1, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateConstSpVec(&x, size, -1, idx_data, val_data, idxType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstSpVec(&x, size, nnz, nullptr, val_data, idxType, idxBase, dataType), "Error: idx_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateConstSpVec(&x, size, nnz, idx_data, nullptr, idxType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseDestroySpVec verify_hipsparse_status_invalid_pointer(hipsparseDestroySpVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateConstSpVec(&x, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Success"); // hipsparseConstSpVecGet const void* idx; const void* data; verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(nullptr, &size, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, nullptr, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, nullptr, &idx, &data, &idxType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, nullptr, &data, &idxType, &idxBase, &dataType), "Error: idx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, nullptr, &idxType, &idxBase, &dataType), "Error: val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, &data, nullptr, &idxBase, &dataType), "Error: idxType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, &data, &idxType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseConstSpVecGet(x, &size, &nnz, &idx, &data, &idxType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseSpVecGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(nullptr, &idxBase), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(x, nullptr), "Error: idxBase is nullptr"); // hipsparseConstSpVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstSpVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstSpVecGetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); #endif } #endif // TESTING_CONST_SPVEC_DESCR_HPP ./clients/include/testing_bsrmv.hpp0000664000175100017510000007261315176134511017603 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRMV_HPP #define TESTING_BSRMV_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrmv_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; int safe_dim = 2; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); // Test hipsparseXbsrmv verify_hipsparse_status_invalid_handle(hipsparseXbsrmv((hipsparseHandle_t) nullptr, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, (T*)nullptr, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, (T*)nullptr, dptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, (int*)nullptr, dcol, safe_dim, dx, &beta, dy), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, (int*)nullptr, safe_dim, dx, &beta, dy), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, (T*)nullptr, &beta, dy), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, (T*)nullptr, dy), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, (T*)nullptr), "Error: y is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, -1, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, -1, safe_size, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: nb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, -1, &alpha, descr, dval, dptr, dcol, safe_dim, dx, &beta, dy), "Error: nnzb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmv(handle, dirA, transA, safe_size, safe_size, safe_size, &alpha, descr, dval, dptr, dcol, -1, dx, &beta, dy), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsrmv(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; if(block_dim == 1 || mb == 0 || nb == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse only accepts block_dim > 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } mb = (m + block_dim - 1) / block_dim; nb = (n + block_dim - 1) / block_dim; std::vector hx(nb * block_dim); std::vector hy_1(mb * block_dim); std::vector hy_2(mb * block_dim); std::vector hy_gold(mb * block_dim); hipsparseInit(hx, 1, nb * block_dim); hipsparseInit(hy_1, 1, mb * block_dim); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nb * block_dim), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * mb * block_dim), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, n, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, d_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, d_beta, dy_2)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Host bsrmv std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); host_bsrmv(dir, transA, mb, nb, nnzb, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hx.data(), h_beta, hy_gold.data(), idx_base); unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmv(handle, dir, transA, mb, nb, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dx, &h_beta, dy_1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnzb * block_dim * block_dim, h_beta != make_DataType(0.0)); double gbyte_count = bsrmv_gbyte_count(mb, nb, nnzb, block_dim, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::block_dim, block_dim, display_key_t::direction, hipsparse_direction2string(dir), display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMV_HPP ./clients/include/testing_spmat_descr.hpp0000664000175100017510000017234315176134511020757 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMAT_DESCR_HPP #define TESTING_SPMAT_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include #include "hipsparse_arguments.hpp" #include "utility.hpp" #include using namespace hipsparse_test; void testing_spmat_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t rows = 100; int64_t cols = 100; int64_t nnz = 100; int64_t ell_cols = 10; int64_t ell_blocksize = 2; hipsparseIndexType_t rowType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t colType = HIPSPARSE_INDEX_32I; hipsparseIndexType_t cooType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; hipsparseFormat_t format = HIPSPARSE_FORMAT_CSR; // Allocate memory on device auto row_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto col_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto ind_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * 2 * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; int* row_data = (int*)row_data_managed.get(); int* col_data = (int*)col_data_managed.get(); int* ind_data = (int*)ind_data_managed.get(); float* val_data = (float*)val_data_managed.get(); hipsparseSpMatDescr_t A; // hipsparseCreateCoo verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateCoo( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCoo( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCoo( &A, rows, cols, -1, row_data, col_data, val_data, rowType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCoo( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateCooAoS verify_hipsparse_status_invalid_pointer( hipsparseCreateCooAoS( nullptr, rows, cols, nnz, ind_data, val_data, cooType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateCooAoS(&A, -1, cols, nnz, ind_data, val_data, cooType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCooAoS(&A, rows, -1, nnz, ind_data, val_data, cooType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCooAoS(&A, rows, cols, -1, ind_data, val_data, cooType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCooAoS(&A, rows, cols, nnz, nullptr, val_data, cooType, idxBase, dataType), "Error: ind_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCooAoS(&A, rows, cols, nnz, ind_data, nullptr, cooType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateCsr verify_hipsparse_status_invalid_pointer(hipsparseCreateCsr(nullptr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateCsr( &A, -1, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCsr( &A, rows, -1, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateCsr( &A, rows, cols, -1, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCsr( &A, rows, cols, nnz, nullptr, col_data, val_data, rowType, colType, idxBase, dataType), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCsr( &A, rows, cols, nnz, row_data, nullptr, val_data, rowType, colType, idxBase, dataType), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateCsr( &A, rows, cols, nnz, row_data, col_data, nullptr, rowType, colType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseCreateBlockedEll verify_hipsparse_status_invalid_pointer(hipsparseCreateBlockedEll(nullptr, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, -1, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: rows is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, rows, -1, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: cols is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, rows, cols, -1, ell_cols, col_data, val_data, colType, idxBase, dataType), "Error: ell_blocksize is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateBlockedEll( &A, rows, cols, ell_blocksize, -1, col_data, val_data, colType, idxBase, dataType), "Error: ell_cols is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, nullptr, val_data, colType, idxBase, dataType), "Error: ellColInd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateBlockedEll( &A, rows, cols, ell_blocksize, ell_cols, col_data, nullptr, colType, idxBase, dataType), "Error: ellValue is nullptr"); // hipsparseDestroySpMat verify_hipsparse_status_invalid_pointer(hipsparseDestroySpMat(nullptr), "Error: A is nullptr"); // Create valid descriptors hipsparseSpMatDescr_t coo; hipsparseSpMatDescr_t coo_aos; hipsparseSpMatDescr_t csr; hipsparseSpMatDescr_t csc; hipsparseSpMatDescr_t bell; verify_hipsparse_status_success(hipsparseCreateBlockedEll(&bell, rows, cols, ell_blocksize, ell_cols, col_data, val_data, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success( hipsparseCreateCoo( &coo, rows, cols, nnz, row_data, col_data, val_data, rowType, idxBase, dataType), "Success"); verify_hipsparse_status_success( hipsparseCreateCooAoS( &coo_aos, rows, cols, nnz, ind_data, val_data, cooType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateCsr(&csr, rows, cols, nnz, row_data, col_data, val_data, rowType, colType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateCsc(&csc, rows, cols, nnz, col_data, row_data, val_data, colType, rowType, idxBase, dataType), "Success"); void* row_ptr; void* col_ptr; void* ind_ptr; void* val_ptr; // hipsparseCooGet verify_hipsparse_status_invalid_pointer(hipsparseCooGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCooGet(coo, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooGet( coo, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseCooAoSGet verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( nullptr, &rows, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, nullptr, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, nullptr, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, nullptr, &ind_ptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, nullptr, &val_ptr, &cooType, &idxBase, &dataType), "Error: ind_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, nullptr, &cooType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: cooType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCooAoSGet( coo_aos, &rows, &cols, &nnz, &ind_ptr, &val_ptr, &cooType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseCsrGet verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(nullptr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, nullptr, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, nullptr, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, nullptr, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, nullptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, nullptr, &val_ptr, &rowType, &colType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, nullptr, &rowType, &colType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, nullptr, &colType, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, nullptr, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsrGet(csr, &rows, &cols, &nnz, &row_ptr, &col_ptr, &val_ptr, &rowType, &colType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseCscGet verify_hipsparse_status_invalid_pointer(hipsparseCscGet(nullptr, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, nullptr, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, nullptr, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, nullptr, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, nullptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, nullptr, &val_ptr, &colType, &rowType, &idxBase, &dataType), "Error: row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, nullptr, &colType, &rowType, &idxBase, &dataType), "Error: val_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, nullptr, &rowType, &idxBase, &dataType), "Error: colType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, nullptr, &idxBase, &dataType), "Error: rowType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCscGet(csc, &rows, &cols, &nnz, &col_ptr, &row_ptr, &val_ptr, &colType, &rowType, &idxBase, nullptr), "Error: dataType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(nullptr, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, nullptr, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, nullptr, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, nullptr, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_blocksize is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, nullptr, &col_ptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ell_cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, nullptr, &val_ptr, &colType, &idxBase, &dataType), "Error: ellColInd"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, nullptr, &colType, &idxBase, &dataType), "Error: ellValue is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, nullptr, &idxBase, &dataType), "Error: ellIdxType is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseBlockedEllGet(bell, &rows, &cols, &ell_blocksize, &ell_cols, &col_ptr, &val_ptr, &colType, &idxBase, nullptr), "Error: valueType is nullptr"); // hipsparseCsrSetPointers verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(nullptr, row_data, col_data, val_data), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(csr, nullptr, col_data, val_data), "Error: row_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(csr, row_data, nullptr, val_data), "Error: col_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsrSetPointers(csr, row_data, col_data, nullptr), "Error: val_data is nullptr"); // hipsparseSpMatGetSize verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(nullptr, &rows, &cols, &nnz), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, nullptr, &cols, &nnz), "Error: rows is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, nullptr, &nnz), "Error: cols is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetSize(coo, &rows, &cols, nullptr), "Error: nnz is nullptr"); // hipsparseSpMatGetFormat verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(nullptr, &format), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetFormat(coo, nullptr), "Error: format is nullptr"); // hipsparseSpMatGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(nullptr, &idxBase), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetIndexBase(coo, nullptr), "Error: idxBase is nullptr"); // hipsparseSpMatGetValues verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetValues(nullptr, &val_ptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetValues(coo, nullptr), "Error: val_ptr is nullptr"); // hipsparseSpMatSetValues verify_hipsparse_status_invalid_pointer(hipsparseSpMatSetValues(nullptr, val_ptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatSetValues(coo, nullptr), "Error: val_ptr is nullptr"); int batch_count = 100; int64_t batch_stride = 100; int64_t offsets_batch_stride = 100; int64_t columns_values_batch_stride = 100; // hipsparseSpMatGetStridedBatch verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(nullptr, &batch_count), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(coo, nullptr), "Error: batch count is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpMatGetStridedBatch(csr, nullptr), "Error: batch count is nullptr"); // hipsparseSpMatSetStridedBatch verify_hipsparse_status_invalid_pointer(hipsparseSpMatSetStridedBatch(nullptr, batch_count), "Error: A is nullptr"); verify_hipsparse_status_invalid_size(hipsparseSpMatSetStridedBatch(coo, -1), "Error: batch count is invalid"); verify_hipsparse_status_invalid_size(hipsparseSpMatSetStridedBatch(csr, -1), "Error: batch count is invalid"); // hipsparseCooSetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseCooSetStridedBatch(nullptr, batch_count, batch_stride), "Error: A is nullptr"); verify_hipsparse_status_invalid_size(hipsparseCooSetStridedBatch(coo, -1, batch_stride), "Error: batch count is invalid"); verify_hipsparse_status_invalid_size(hipsparseCooSetStridedBatch(coo, batch_count, -1), "Error: batch stride is invalid"); verify_hipsparse_status_invalid_size(hipsparseCooSetStridedBatch(coo, -1, -1), "Error: batch count and batch stride is invalid"); // hipsparseCsrSetStridedBatch verify_hipsparse_status_invalid_pointer( hipsparseCsrSetStridedBatch( nullptr, batch_count, offsets_batch_stride, columns_values_batch_stride), "Error: A is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, -1, offsets_batch_stride, columns_values_batch_stride), "Error: batch count is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, batch_count, -1, columns_values_batch_stride), "Error: batch stride is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, batch_count, offsets_batch_stride, -1), "Error: batch stride is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, -1, -1, columns_values_batch_stride), "Error: batch count and batch stride is invalid"); verify_hipsparse_status_invalid_size(hipsparseCsrSetStridedBatch(csr, batch_count, -1, -1), "Error: batch count and batch stride is invalid"); verify_hipsparse_status_invalid_size( hipsparseCsrSetStridedBatch(csr, -1, offsets_batch_stride, -1), "Error: batch count and batch stride is invalid"); verify_hipsparse_status_invalid_size(hipsparseCsrSetStridedBatch(csr, -1, -1, -1), "Error: batch count and batch stride is invalid"); // Destroy valid descriptors verify_hipsparse_status_success(hipsparseDestroySpMat(coo), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(coo_aos), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csr), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(csc), "Success"); verify_hipsparse_status_success(hipsparseDestroySpMat(bell), "Success"); #endif } hipsparseStatus_t testing_spmat_descr(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) int m = 2; int n = 2; int nnzC = 4; // C std::vector hcsr_row_ptrC = {0, 2, 4}; std::vector hcsr_col_indC = {0, 2, 0, 1}; std::vector hcsr_valC = {5.0f, 6.0f, 7.0f, 8.0f, 1.0f, 2.0f}; int* dcsr_row_ptrC = NULL; int* dcsr_col_indC = NULL; float* dcsr_valC = NULL; CHECK_HIP_ERROR(hipMalloc((void**)&dcsr_row_ptrC, (m + 1) * sizeof(int))); CHECK_HIP_ERROR(hipMalloc((void**)&dcsr_col_indC, nnzC * sizeof(int))); CHECK_HIP_ERROR(hipMalloc((void**)&dcsr_valC, nnzC * sizeof(float))); CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptrC, hcsr_row_ptrC.data(), (m + 1) * sizeof(int), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indC, hcsr_col_indC.data(), nnzC * sizeof(int), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_valC, hcsr_valC.data(), nnzC * sizeof(float), hipMemcpyHostToDevice)); hipsparseHandle_t handle = NULL; hipsparseSpMatDescr_t matA, matB, matC, matD, matE, matF, matG, matH, matI, matJ, matK, matL, matM, matN, matO; CHECK_HIPSPARSE_ERROR(hipsparseCreate(&handle)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matA, 0, 0, 0, NULL, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matB, m, n, 0, NULL, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matC, 0, 0, 0, dcsr_row_ptrC, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matD, m, n, 0, dcsr_row_ptrC, NULL, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matE, m, n, nnzC, dcsr_row_ptrC, dcsr_col_indC, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matF, m, n, 0, NULL, dcsr_col_indC, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matG, 0, 0, 0, NULL, dcsr_col_indC, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matH, m, n, 0, NULL, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matI, 0, 0, 0, NULL, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matJ, m, n, 0, NULL, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matK, 0, 0, 0, NULL, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matL, m, n, 0, dcsr_row_ptrC, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matM, 0, 0, 0, dcsr_row_ptrC, dcsr_col_indC, NULL, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matN, m, n, 0, dcsr_row_ptrC, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&matO, 0, 0, 0, dcsr_row_ptrC, NULL, dcsr_valC, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_32I, HIPSPARSE_INDEX_BASE_ZERO, HIP_R_32F)); // destroy matrix/vector descriptors CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matC)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matD)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matE)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matF)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matG)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matH)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matI)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matJ)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matK)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matL)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matM)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matN)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matO)); CHECK_HIPSPARSE_ERROR(hipsparseDestroy(handle)); CHECK_HIP_ERROR(hipFree(dcsr_row_ptrC)); CHECK_HIP_ERROR(hipFree(dcsr_col_indC)); CHECK_HIP_ERROR(hipFree(dcsr_valC)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMAT_DESCR_HPP ./clients/include/testing_const_dnvec_descr.hpp0000664000175100017510000000753615176134305022142 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CONST_DNVEC_DESCR_HPP #define TESTING_CONST_DNVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_const_dnvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; const float* val_data = (float*)val_data_managed.get(); hipsparseConstDnVecDescr_t x; // hipsparseCreateConstDnVec verify_hipsparse_status_invalid_pointer( hipsparseCreateConstDnVec(nullptr, size, val_data, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size(hipsparseCreateConstDnVec(&x, -1, val_data, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_pointer(hipsparseCreateConstDnVec(&x, size, nullptr, dataType), "Error: val_data is nullptr"); // hipsparseDestroyDnVec verify_hipsparse_status_invalid_pointer(hipsparseDestroyDnVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success(hipsparseCreateConstDnVec(&x, size, val_data, dataType), "Success"); // hipsparseConstDnVecGet const void* data; verify_hipsparse_status_invalid_pointer( hipsparseConstDnVecGet(nullptr, &size, &data, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGet(x, nullptr, &data, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGet(x, &size, nullptr, &dataType), "Error: val_data is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGet(x, &size, &data, nullptr), "Error: dataType is nullptr"); // hipsparseConstDnVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseConstDnVecGetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "Success"); #endif } #endif // TESTING_CONST_DNVEC_DESCR_HPP ./clients/include/testing_spmv_coo.hpp0000664000175100017510000003525615176134511020301 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMV_COO_HPP #define TESTING_SPMV_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spmv_coo_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_SPMV_COO_ALG1; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t alg = HIPSPARSE_MV_ALG_DEFAULT; #endif #endif std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* drow = (int*)drow_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; size_t bsize; // Create SpMV structures verify_hipsparse_status_success( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, n, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpMV buffer verify_hipsparse_status_invalid_handle( hipsparseSpMV_bufferSize(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, nullptr, A, x, &beta, y, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize( handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV_bufferSize(handle, transA, &alpha, A, x, &beta, y, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMV verify_hipsparse_status_invalid_handle( hipsparseSpMV(nullptr, transA, &alpha, A, x, &beta, y, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, nullptr, A, x, &beta, y, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, nullptr, x, &beta, y, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, nullptr, &beta, y, dataType, alg, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, nullptr, y, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, dbuf), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMV(handle, transA, &alpha, A, x, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spmv_coo(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) I m = argus.M; I n = argus.N; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSpMVAlg_t alg = static_cast(argus.spmv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hrow_ptr; std::vector hcol_ind; std::vector hval; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hrow_ptr, hcol_ind, hval, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hrow_ptr[i]; j < hrow_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } std::vector hx(n); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, n); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * n), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&A, m, n, nnz, drow, dcol, dval, typeI, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, n, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); // Query SpMV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpMV_bufferSize( handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, d_alpha, A, x, d_beta, y2, typeT, alg, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); // Host SpMV #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < m; ++i) { hy_gold[i] = testing_mult(h_beta, hy_gold[i]); } for(I i = 0; i < nnz; ++i) { hy_gold[hrow_ind[i] - idx_base] = testing_fma(testing_mult(h_alpha, hval[i]), hx[hcol_ind[i] - idx_base], hy_gold[hrow_ind[i] - idx_base]); } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpMV(handle, transA, &h_alpha, A, x, &h_beta, y1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spmv_gflop_count(m, nnz, h_beta != make_DataType(0.0)); double gbyte_count = coomv_gbyte_count(m, n, nnz, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::transA, transA, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_spmvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMV_COO_HPP ./clients/include/flops.hpp0000664000175100017510000001434315176134305016035 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief flops.hpp provides floating point counts of Sparse Linear Algebra Subprograms * of Level 1, 2 and 3. */ #pragma once #ifndef FLOPS_HPP #define FLOPS_HPP #include "hipsparse.h" // Compute gflops inline double get_gpu_gflops(double gpu_time_used, double gflop_count) { return gflop_count / gpu_time_used * 1e6; } template inline double get_gpu_gflops(double gpu_time_used, F count, Ts... ts) { return get_gpu_gflops(gpu_time_used, count(ts...)); } /* * =========================================================================== * level 1 SPARSE * =========================================================================== */ template constexpr double axpyi_gflop_count(I nnz) { return (2.0 * nnz) / 1e9; } template constexpr double axpby_gflop_count(I nnz) { return (3.0 * nnz) / 1e9; } template constexpr double doti_gflop_count(I nnz) { return (2.0 * nnz) / 1e9; } template constexpr double roti_gflop_count(I nnz) { return (6.0 * nnz) / 1e9; } /* * =========================================================================== * level 2 SPARSE * =========================================================================== */ template constexpr double spmv_gflop_count(J M, I nnz, bool beta = false) { return (2.0 * nnz + (beta ? M : 0)) / 1e9; } template constexpr double csrsv_gflop_count(J M, I nnz, hipsparseDiagType_t diag) { return (2.0 * nnz + M + (diag == HIPSPARSE_DIAG_TYPE_NON_UNIT ? M : 0)) / 1e9; } template constexpr double spsv_gflop_count(J M, I nnz, hipsparseDiagType_t diag) { return csrsv_gflop_count(M, nnz, diag); } template constexpr double gemvi_gflop_count(I M, I nnz) { return (M + 2.0 * nnz * M) / 1e9; } /* * =========================================================================== * level 3 SPARSE * =========================================================================== */ constexpr double bsrmm_gflop_count(int N, int nnzb, int block_dim, int nnz_C, bool beta = false) { return (2.0 * nnzb * block_dim * block_dim * N + (beta ? nnz_C : 0)) / 1e9; } template constexpr double csrmm_gflop_count(J N, I nnz_A, I nnz_C, bool beta = false) { // Multiplication by 2 comes from 1 addition and 1 multiplication in product. Multiplication // by alpha and beta not counted. return (2.0 * nnz_A * N + (beta ? nnz_C : 0)) / 1e9; } template constexpr double gemmi_gflop_count(J M, I nnz_B, I nnz_C, bool beta = false) { // Multiplication by 2 comes from 1 addition and 1 multiplication in product. Multiplication // by alpha and beta not counted. return (2.0 * nnz_B * M + (beta ? nnz_C : 0)) / 1e9; } template constexpr double spmm_gflop_count(J N, I nnz_A, I nnz_C, bool beta = false) { return csrmm_gflop_count(N, nnz_A, nnz_C, beta); } template constexpr double sddmm_gflop_count(J K, I nnz, bool beta = false) { return (size_t(nnz) * ((size_t(K) + (size_t(K) - 1)) + 1 + ((beta) ? 2 : 0))) / 1e9; } /* * =========================================================================== * extra SPARSE * =========================================================================== */ template constexpr double csrgeam_gflop_count(int nnz_A, int nnz_B, int nnz_C, const T* alpha, const T* beta) { // Flop counter double flops = 0.0; if(alpha && beta) { // Count alpha * A flops += static_cast(nnz_A); // Count beta * B flops += static_cast(nnz_B); // Count A + B flops += static_cast(nnz_C); } else if(!alpha) { // Count beta * B flops += static_cast(nnz_B); } else { // Count alpha * A flops += static_cast(nnz_A); } return flops / 1e9; } template constexpr double csrgemm_gflop_count(J M, const I* csr_row_ptr_A, const J* csr_col_ind_A, const I* csr_row_ptr_B, hipsparseIndexBase_t baseA) { // Flop counter double flops = 0.0; // Loop over rows of A for(J i = 0; i < M; ++i) { I row_begin_A = csr_row_ptr_A[i] - baseA; I row_end_A = csr_row_ptr_A[i + 1] - baseA; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - baseA; // Count flops generated by A * B flops += 2.0 * (csr_row_ptr_B[col_A + 1] - csr_row_ptr_B[col_A]) + 1.0; } } return flops / 1e9; } #endif // FLOPS_HPP ./clients/include/testing_dense_to_sparse_coo.hpp0000664000175100017510000003060315176134511022460 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE_TO_SPARSE_COO_HPP #define TESTING_DENSE_TO_SPARSE_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_dense_to_sparse_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t safe_size = 100; int32_t m = 10; int32_t n = 10; int64_t nnz = 10; int64_t ld = m; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDenseToSparseAlg_t alg = HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; // Index and data type hipsparseIndexType_t iType = HIPSPARSE_INDEX_64I; hipDataType dataType = HIP_R_32F; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddense_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcoo_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; float* ddense_val = (float*)ddense_val_managed.get(); int32_t* dcoo_row_ind = (int32_t*)dcoo_row_ind_managed.get(); int32_t* dcoo_col_ind = (int32_t*)dcoo_col_ind_managed.get(); float* dcoo_val = (float*)dcoo_val_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // Matrix structures hipsparseDnVecDescr_t matA; hipsparseSpMatDescr_t matB; size_t bsize; // Create matrix structures verify_hipsparse_status_success( hipsparseCreateDnMat(&matA, m, n, ld, ddense_val, dataType, order), "success"); verify_hipsparse_status_success( hipsparseCreateCoo( &matB, m, n, nnz, dcoo_row_ind, dcoo_col_ind, dcoo_val, iType, idxBase, dataType), "success"); // denseToSparse buffer size verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_bufferSize(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse analysis verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_analysis(nullptr, matA, matB, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, nullptr, matB, alg, &bsize), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, nullptr, alg, &bsize), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_analysis(handle, matA, matB, alg, nullptr), "Error: bsize is nullptr"); // denseToSparse_convert verify_hipsparse_status_invalid_handle( hipsparseDenseToSparse_convert(nullptr, matA, matB, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, nullptr, matB, alg, dbuf), "Error: matA is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, nullptr, alg, dbuf), "Error: matB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseDenseToSparse_convert(handle, matA, matB, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(matA), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(matB), "success"); #endif } template hipsparseStatus_t testing_dense_to_sparse_coo(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDenseToSparseAlg_t alg = static_cast(argus.dense2sparse_alg); hipsparseOrder_t order = argus.orderA; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; I ld = (order == HIPSPARSE_ORDER_COL) ? m : n; // Host structures I nrow = (order == HIPSPARSE_ORDER_COL) ? ld : m; I ncol = (order == HIPSPARSE_ORDER_COL) ? n : ld; std::vector hdense_val(nrow * ncol); if(order == HIPSPARSE_ORDER_COL) { for(int i = 0; i < n; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } else { for(int i = 0; i < m; ++i) { for(int j = 0; j < ld; ++j) { hdense_val[i * ld + j] = make_DataType(-1); } } } srand(0); gen_dense_random_sparsity_pattern(m, n, hdense_val.data(), ld, order, 0.2); // allocate memory on device auto ddense_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrow * ncol), device_free}; T* ddense = (T*)ddense_managed.get(); // Copy host dense matrix to device CHECK_HIP_ERROR( hipMemcpy(ddense, hdense_val.data(), sizeof(T) * nrow * ncol, hipMemcpyHostToDevice)); // Create dense matrix hipsparseDnMatDescr_t matA; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&matA, m, n, ld, ddense, typeT, order)); // Create matrices hipsparseSpMatDescr_t matB; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&matB, m, n, 0, nullptr, nullptr, nullptr, typeI, idx_base, typeT)); // Query DenseToSparse buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_bufferSize(handle, matA, matB, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_analysis(handle, matA, matB, alg, buffer)); int64_t rows, cols, nnz; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(matB, &rows, &cols, &nnz)); auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseCooSetPointers(matB, drow, dcol, dval)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); // copy output from device to CPU std::vector hcoo_row_ind(nnz); std::vector hcoo_col_ind(nnz); std::vector hcoo_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcoo_row_ind.data(), drow, sizeof(I) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcoo_col_ind.data(), dcol, sizeof(I) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcoo_val.data(), dval, sizeof(T) * nnz, hipMemcpyDeviceToHost)); std::vector hcoo_row_ind_cpu(nnz); std::vector hcoo_col_ind_cpu(nnz); std::vector hcoo_val_cpu(nnz); if(order == HIPSPARSE_ORDER_COL) { int index = 0; for(I i = 0; i < m; ++i) { for(I j = 0; j < n; ++j) { if(hdense_val[j * ld + i] != make_DataType(0.0)) { hcoo_row_ind_cpu[index] = i + idx_base; hcoo_col_ind_cpu[index] = j + idx_base; hcoo_val_cpu[index] = hdense_val[j * ld + i]; index++; } } } } else { int index = 0; for(I i = 0; i < m; ++i) { for(I j = 0; j < n; ++j) { if(hdense_val[i * ld + j] != make_DataType(0.0)) { hcoo_row_ind_cpu[index] = i + idx_base; hcoo_col_ind_cpu[index] = j + idx_base; hcoo_val_cpu[index] = hdense_val[i * ld + j]; index++; } } } } unit_check_general(1, nnz, 1, hcoo_row_ind_cpu.data(), hcoo_row_ind.data()); unit_check_general(1, nnz, 1, hcoo_col_ind_cpu.data(), hcoo_col_ind.data()); unit_check_general(1, nnz, 1, hcoo_val_cpu.data(), hcoo_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm-up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseDenseToSparse_convert(handle, matA, matB, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = dense2coo_gbyte_count(m, n, (I)nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::order, order, display_key_t::algorithm, hipsparse_densetosparsealg2string(alg), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(matA)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(matB)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_DENSE_TO_SPARSE_COO_HPP ./clients/include/testing_coo2csr.hpp0000664000175100017510000001502415176134511020015 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_COO2CSR_HPP #define TESTING_COO2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_coo2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto coo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* coo_row_ind = (int*)coo_row_ind_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXcoo2csr(handle, (int*)nullptr, nnz, m, csr_row_ptr, idx_base), "Error: coo_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcoo2csr(handle, coo_row_ind, nnz, m, (int*)nullptr, idx_base), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcoo2csr((hipsparseHandle_t) nullptr, coo_row_ind, nnz, m, csr_row_ptr, idx_base)); #endif } template hipsparseStatus_t testing_coo2csr(Arguments argus) { int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcoo_row_ind; std::vector hcoo_col_ind; std::vector hcoo_val; // Read or construct CSR matrix int nnz = 0; if(!generate_coo_matrix(filename, m, n, nnz, hcoo_row_ind, hcoo_col_ind, hcoo_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_row_ptr(m + 1); std::vector hcsr_row_ptr_gold(m + 1, 0); // Allocate memory on the device auto dcoo_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; int* dcoo_row_ind = (int*)dcoo_row_ind_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcoo_row_ind, hcoo_row_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); // CPU // coo2csr on host for(int i = 0; i < nnz; ++i) { ++hcsr_row_ptr_gold[hcoo_row_ind[i] + 1 - idx_base]; } hcsr_row_ptr_gold[0] = idx_base; for(int i = 0; i < m; ++i) { hcsr_row_ptr_gold[i + 1] += hcsr_row_ptr_gold[i]; } // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXcoo2csr(handle, dcoo_row_ind, nnz, m, dcsr_row_ptr, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = coo2csr_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_COO2CSR_HPP ./clients/include/testing_bsr2csr.hpp0000664000175100017510000006215615176134511020033 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSR2CSR_HPP #define TESTING_BSR2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsr2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXbsr2csr((hipsparseHandle_t) nullptr, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, (hipsparseMatDescr_t) nullptr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, (int*)nullptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, (int*)nullptr, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, (hipsparseMatDescr_t) nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, (int*)nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, (int*)nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, -1, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, m, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: block_dim is invalid"); #endif } template hipsparseStatus_t testing_bsr2csr(Arguments argus) { int m = argus.M; int n = argus.N; int block_dim = argus.block_dim; hipsparseIndexBase_t bsr_idx_base = argus.baseA; hipsparseIndexBase_t csr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0 || block_dim == 1) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 or n == 0 for bsr2csr // cusparse does not support asynchronous execution if block_dim == 1 return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, csr_row_ptr, csr_col_ind, csr_val, csr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m and n can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; int nb = (n + block_dim - 1) / block_dim; // Host BSR matrix std::vector hbsr_row_ptr; std::vector hbsr_col_ind; std::vector hbsr_val; // Convert CSR matrix to BSR int nnzb; host_csr_to_bsr(dir, m, n, block_dim, nnzb, csr_idx_base, csr_row_ptr, csr_col_ind, csr_val, bsr_idx_base, hbsr_row_ptr, hbsr_col_ind, hbsr_val); // Determine the size of the output CSR matrix based on the size of the input BSR matrix m = mb * block_dim; n = nb * block_dim; // Host CSR matrix std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnzb * block_dim * block_dim); std::vector hcsr_val(nnzb * block_dim * block_dim); // Allocate memory on the device auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * nnzb * block_dim * block_dim), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dbsr_row_ptr, hbsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, hbsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, hbsr_val.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Host computed bsr2csr conversion std::vector hcsr_row_ptr_gold(m + 1); std::vector hcsr_col_ind_gold(nnzb * block_dim * block_dim, 0); std::vector hcsr_val_gold(nnzb * block_dim * block_dim); // Host bsr2csr host_bsr_to_csr(dir, mb, nb, block_dim, bsr_idx_base, hbsr_row_ptr, hbsr_col_ind, hbsr_val, csr_idx_base, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); unit_check_general( 1, nnzb * block_dim * block_dim, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); unit_check_general( 1, nnzb * block_dim * block_dim, 1, hcsr_val_gold.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = bsr2csr_gbyte_count(mb, block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::block_dim, block_dim, display_key_t::nnzb, nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSR2CSR_HPP ./clients/include/testing_dense2csc.hpp0000664000175100017510000000402115176134511020307 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_DENSE2CSC_HPP #define TESTING_DENSE2CSC_HPP #include "testing_dense2csx.hpp" template void testing_dense2csc_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_dense2csx_bad_arg(hipsparseXdense2csc); #endif } template hipsparseStatus_t testing_dense2csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_dense2csx(argus, hipsparseXdense2csc); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_DENSE2CSC ./clients/include/testing_prune_dense2csr_by_percentage.hpp0000664000175100017510000007704715176134511024450 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP #define TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_dense2csr_by_percentage_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 1; int M = 1; int N = 1; int LDA = M; T percentage = static_cast(1); int nnz_total_dev_host_ptr = 1; size_t buffer_size = 1; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); T* A = (T*)A_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneDense2csrByPercentage_bufferSize status = hipsparseXpruneDense2csrByPercentage_bufferSize(nullptr, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrByPercentage_bufferSize( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrNnzByPercentage status = hipsparseXpruneDense2csrNnzByPercentage(nullptr, M, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrNnzByPercentage(handle, -1, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, -1, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, -1, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, (T)-1.0, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is less than 0"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, (T)101.0, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is more than 100"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, (const T*)nullptr, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, nullptr, csr_row_ptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, descr, nullptr, &nnz_total_dev_host_ptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage( handle, M, N, A, LDA, percentage, descr, csr_row_ptr, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); status = hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, A, LDA, percentage, descr, csr_row_ptr, &nnz_total_dev_host_ptr, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrByPercentage status = hipsparseXpruneDense2csrByPercentage(nullptr, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrByPercentage(handle, -1, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrByPercentage(handle, M, -1, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, -1, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, (T)-1.0, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is less than 0"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, (T)101.0, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: percentage is more than 100"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, (const T*)nullptr, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, percentage, nullptr, csr_val, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrByPercentage(handle, M, N, A, LDA, percentage, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, nullptr, csr_col_ind, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, nullptr, info, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); status = hipsparseXpruneDense2csrByPercentage( handle, M, N, A, LDA, percentage, descr, csr_val, csr_row_ptr, csr_col_ind, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_prune_dense2csr_by_percentage(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; int LDA = argus.lda; T percentage = argus.get_percentage(); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new prune_struct); pruneInfo_t info = unique_ptr_info->info; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Allocate host memory std::vector h_A(LDA * N); std::vector h_nnz_total_dev_host_ptr(1); // Allocate device memory auto d_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * LDA * N), device_free}; auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; T* d_A = (T*)d_A_managed.get(); int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr = (int*)d_csr_row_ptr_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LDA; ++i) { for(int j = 0; j < N; ++j) { h_A[j * LDA + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), LDA, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * LDA * N, hipMemcpyHostToDevice)); size_t buffer_size = 512; CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage_bufferSize(handle, M, N, d_A, LDA, percentage, descr, (const T*)nullptr, d_csr_row_ptr, (const int*)nullptr, info, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_row_ptr, &h_nnz_total_dev_host_ptr[0], info, d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnzByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_row_ptr, d_nnz_total_dev_host_ptr, info, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind = (int*)d_csr_col_ind_managed.get(); T* d_csr_val = (T*)d_csr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); std::vector h_csr_row_ptr(M + 1); std::vector h_csr_col_ind(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr.data(), d_csr_row_ptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind.data(), d_csr_col_ind, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val.data(), d_csr_val, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_dense2csr_by_percentage(M, N, h_A, LDA, idx_base, percentage, h_nnz_cpu[0], h_csr_val_cpu, h_csr_row_ptr_cpu, h_csr_col_ind_cpu); unit_check_general(1, 1, 1, h_nnz_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrByPercentage(handle, M, N, d_A, LDA, percentage, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, info, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_dense2csr_by_percentage_gbyte_count(M, N, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::M, N, display_key_t::nnz, h_nnz_total_dev_host_ptr[0], display_key_t::percentage, percentage, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_BY_PERCENTAGE_HPP ./clients/include/hipsparse_arguments_support.hpp0000664000175100017510000006754015176134305022600 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include #include #if(defined(CUDART_VERSION)) #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) static void print_cuda_12_0_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.7.1|11.8.0|12.0.0|12.0.1|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_11_3_1_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.2.2|11.3.0|11.3.1|11.4.0|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_11_2_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|11.1.0|11.1.1|11.2.0|11.2.1|...|12.4.1|12.5.0|12.5.1|\n" " |<--------------supported------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_12_5_1_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.2|....|12.4.1|12.5.0|12.5.1|...\n" "|<---------------supported-------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_11_8_0_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.2|....|11.7.0|11.7.1|11.8.0|12.0.0|12.0.1|...\n" "|<--------------supported--------------->| "; std::cout << table << std::endl; } static void print_cuda_10_0_0_to_10_2_0_support_string() { std::cout << "Warning: You are using CUDA version: " << TOSTRING(CUDART_VERSION) << " but this routine is not supported. See CUDA support table for this" << " routine below: " << std::endl; std::string table = " CUDA Version \n" "|10.0|10.1|10.1.1|10.1.2|10.2.0|11.0.1|11.0.2|...\n" "|<---------supported---------->| "; std::cout << table << std::endl; } #undef STRINGIFY #undef TOSTRING #endif struct routine_support { // Level 1 static bool is_axpyi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_doti_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_dotci_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_gthr_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_gthrz_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_roti_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_sctr_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } // Level2 static bool is_bsrsv2_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_coomv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) return true; #else return false; #endif } static bool is_csrmv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) return true; #else return false; #endif } static bool is_csrsv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return true; #else return false; #endif } static bool is_gemvi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_hybmv_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Level3 static bool is_bsrmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_bsrsm2_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) return true; #else return false; #endif } static bool is_coomm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_cscmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_csrmm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) return true; #else return false; #endif } static bool is_coosm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return true; #else return false; #endif } static bool is_csrsm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return true; #else return false; #endif } static bool is_gemmi_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Extra static bool is_csrgeam_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } static bool is_csrgemm_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) return true; #else return false; #endif } // Precond static bool is_bsric02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_bsrilu02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_csric02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_csrilu02_supported() { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) return true; #else return false; #endif } static bool is_gtsv2_supported() { return true; } static bool is_gtsv2_nopivot_supported() { return true; } static bool is_gtsv2_strided_batch_supported() { return true; } static bool is_gtsv_interleaved_batch_supported() { return true; } static bool is_gpsv_interleaved_batch_supported() { return true; } // Conversion static bool is_bsr2csr_supported() { return true; } static bool is_csr2coo_supported() { return true; } static bool is_csr2csc_supported() { return true; } static bool is_csr2hyb_supported() { return true; } static bool is_csr2bsr_supported() { return true; } static bool is_csr2gebsr_supported() { return true; } static bool is_csr2csr_compress_supported() { return true; } static bool is_coo2csr_supported() { return true; } static bool is_hyb2csr_supported() { return true; } static bool is_csr2dense_supported() { return true; } static bool is_csc2dense_supported() { return true; } static bool is_coo2dense_supported() { return true; } static bool is_dense2csr_supported() { return true; } static bool is_dense2csc_supported() { return true; } static bool is_dense2coo_supported() { return true; } static bool is_gebsr2csr_supported() { return true; } static bool is_gebsr2gebsc_supported() { return true; } static bool is_gebsr2gebsr_supported() { return true; } // Level 1 static void print_axpyi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_doti_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_dotci_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_gthr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_gthrz_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_roti_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_sctr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } // Level 2 static void print_bsrsv2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coomv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrmv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrsv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_gemvi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } static void print_hybmv_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } // Level 3 static void print_bsrmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_bsrsm2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coomm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_cscmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrmm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coosm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_3_1_to_12_5_1_support_string(); #endif } static void print_csrsm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_3_1_to_12_5_1_support_string(); #endif } static void print_gemmi_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_11_8_0_support_string(); #endif } // Extra static void print_csrgeam_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } static void print_csrgemm_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_10_2_0_support_string(); #endif } // Precond static void print_bsric02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_bsrilu02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csric02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csrilu02_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_nopivot_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv2_strided_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gtsv_interleaved_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gpsv_interleaved_batch_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } // Conversion static void print_bsr2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2coo_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2csc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2hyb_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2bsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2gebsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2csr_compress_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_coo2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_hyb2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_csr2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_csc2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_coo2dense_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2csc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_dense2coo_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_11_2_0_to_12_5_1_support_string(); #endif } static void print_gebsr2csr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gebsr2gebsc_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } static void print_gebsr2gebsr_support_warning() { #if(defined(CUDART_VERSION)) print_cuda_10_0_0_to_12_5_1_support_string(); #endif } }; struct csr2csc_alg_support { static hipsparseCsr2CscAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_CSR2CSC_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_CSR2CSC_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return HIPSPARSE_CSR2CSC_ALG1; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 0, Alg1: 1, Alg2: 2 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 0, Alg1: 1 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running csr2csc. Possible choices are " "default: 1, Alg1: 1, Alg2: 2 (default:1)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } static std::vector get_supported_algorithms() { #if(!defined(CUDART_VERSION)) return std::vector( {HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1, HIPSPARSE_CSR2CSC_ALG2}); #else #if(CUDART_VERSION >= 12000) return std::vector({HIPSPARSE_CSR2CSC_ALG_DEFAULT, HIPSPARSE_CSR2CSC_ALG1}); #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 12000) return std::vector({HIPSPARSE_CSR2CSC_ALG1, HIPSPARSE_CSR2CSC_ALG2}); #endif #endif return std::vector(); } }; struct dense2sparse_alg_support { static hipsparseDenseToSparseAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return HIPSPARSE_DENSETOSPARSE_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return "Indicates what algorithm to use when running dense2sparse. Possible choices are " "default: 0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct sparse2dense_alg_support { static hipsparseSparseToDenseAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return HIPSPARSE_SPARSETODENSE_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) return "Indicates what algorithm to use when running sparse2dense. Possible choices are " "default: 0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct sddmm_alg_support { static hipsparseSDDMMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) return HIPSPARSE_SDDMM_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11022) return "Indicates what algorithm to use when running sddmm. Possible choices are default: " "0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct spgemm_alg_support { static hipsparseSpGEMMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPGEMM_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPGEMM_DEFAULT; #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) return HIPSPARSE_SPGEMM_DEFAULT; #elif(CUDART_VERSION >= 11000) return HIPSPARSE_SPGEMM_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2, Alg1: 3, Alg2: 4, Alg3: 5 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2, Alg1: 3, Alg2: 4, Alg3: 5 (default:0)"; #elif(CUDART_VERSION >= 11031 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0, Deterministic: 1, Non-Deterministic: 2 (default:0)"; #elif(CUDART_VERSION >= 11000) return "Indicates what algorithm to use when running spgemm. Possible choices are default: " "0 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spmm_alg_support { static hipsparseSpMMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPMM_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) return HIPSPARSE_SPMM_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) return HIPSPARSE_MM_ALG_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5 CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "CSR Alg3: 12, Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 11003 && CUDART_VERSION < 11021) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4, COO Alg4: 5, CSR Alg2: 6, " "Blocked ELL Alg1: 13 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11003) return "Indicates what algorithm to use when running spmm. Possible choices are default: " "0, COO Alg1: 1, COO Alg2: 2, COO Alg3: 3, CSR Alg1: 4 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spmv_alg_support { static hipsparseSpMVAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION)) return HIPSPARSE_SPMV_ALG_DEFAULT; #else #if(CUDART_VERSION >= 12000) return HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return HIPSPARSE_SPMV_ALG_DEFAULT; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) return HIPSPARSE_MV_ALG_DEFAULT; #else return -1; #endif #endif } static std::string get_description() { #if(!defined(CUDART_VERSION)) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #else #if(CUDART_VERSION >= 12000) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #elif(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg1: 1, CSR Alg1: 2, CSR Alg2: 3, COO Alg2: 4 (default:0)"; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) return "Indicates what algorithm to use when running spmv. Possible choices are default: " "0, COO Alg: 1, CSR Alg1: 2, CSR Alg2: 3 (default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif #endif } }; struct spsm_alg_support { static hipsparseSpSMAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return HIPSPARSE_SPSM_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) return "Indicates what algorithm to use when running spsm. Possible choices are default: 0 " "(default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; struct spsv_alg_support { static hipsparseSpSVAlg_t get_default_algorithm() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return HIPSPARSE_SPSV_ALG_DEFAULT; #else return -1; #endif } static std::string get_description() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) return "Indicates what algorithm to use when running spsv. Possible choices are default: 0 " "(default:0)"; #else return "No algorithm supported in selected cusparse version"; #endif } }; ./clients/include/hipsparse_test_unique_ptr.hpp0000664000175100017510000002413015176134305022215 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef GUARD_HIPSPARSE_MANAGE_PTR #define GUARD_HIPSPARSE_MANAGE_PTR #include "arg_check.hpp" #include #include #include #include #define PRINT_IF_HIP_ERROR(INPUT_STATUS_FOR_CHECK) \ { \ hipError_t TMP_STATUS_FOR_CHECK = INPUT_STATUS_FOR_CHECK; \ if(TMP_STATUS_FOR_CHECK != hipSuccess) \ { \ fprintf(stderr, \ "hip error code: %d at %s:%d\n", \ TMP_STATUS_FOR_CHECK, \ __FILE__, \ __LINE__); \ } \ } namespace hipsparse_test { // device_malloc wraps hipMalloc and provides same API as malloc static void* device_malloc(size_t byte_size) { void* pointer; PRINT_IF_HIP_ERROR(hipMalloc(&pointer, byte_size)); return pointer; } // device_free wraps hipFree and provides same API as free static void device_free(void* ptr) { PRINT_IF_HIP_ERROR(hipFree(ptr)); } struct handle_struct { hipsparseHandle_t handle; handle_struct() { hipsparseStatus_t status = hipsparseCreate(&handle); verify_hipsparse_status_success(status, "ERROR: handle_struct constructor"); } ~handle_struct() { hipsparseStatus_t status = hipsparseDestroy(handle); verify_hipsparse_status_success(status, "ERROR: handle_struct destructor"); } }; struct descr_struct { hipsparseMatDescr_t descr; descr_struct() { hipsparseStatus_t status = hipsparseCreateMatDescr(&descr); verify_hipsparse_status_success(status, "ERROR: descr_struct constructor"); } ~descr_struct() { hipsparseStatus_t status = hipsparseDestroyMatDescr(descr); verify_hipsparse_status_success(status, "ERROR: descr_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) struct hyb_struct { hipsparseHybMat_t hyb; hyb_struct() { hipsparseStatus_t status = hipsparseCreateHybMat(&hyb); verify_hipsparse_status_success(status, "ERROR: hyb_struct constructor"); } ~hyb_struct() { hipsparseStatus_t status = hipsparseDestroyHybMat(hyb); verify_hipsparse_status_success(status, "ERROR: hyb_struct destructor"); } }; #endif struct bsrsv2_struct { bsrsv2Info_t info; bsrsv2_struct() { hipsparseStatus_t status = hipsparseCreateBsrsv2Info(&info); verify_hipsparse_status_success(status, "ERROR: bsrsv2_struct constructor"); } ~bsrsv2_struct() { hipsparseStatus_t status = hipsparseDestroyBsrsv2Info(info); verify_hipsparse_status_success(status, "ERROR: bsrsv2_struct destructor"); } }; struct bsrsm2_struct { bsrsm2Info_t info; bsrsm2_struct() { hipsparseStatus_t status = hipsparseCreateBsrsm2Info(&info); verify_hipsparse_status_success(status, "ERROR: bsrsm2_struct constructor"); } ~bsrsm2_struct() { hipsparseStatus_t status = hipsparseDestroyBsrsm2Info(info); verify_hipsparse_status_success(status, "ERROR: bsrsm2_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) struct csrsv2_struct { csrsv2Info_t info; csrsv2_struct() { hipsparseStatus_t status = hipsparseCreateCsrsv2Info(&info); verify_hipsparse_status_success(status, "ERROR: csrsv2_struct constructor"); } ~csrsv2_struct() { hipsparseStatus_t status = hipsparseDestroyCsrsv2Info(info); verify_hipsparse_status_success(status, "ERROR: csrsv2_struct destructor"); } }; struct csrsm2_struct { csrsm2Info_t info; csrsm2_struct() { hipsparseStatus_t status = hipsparseCreateCsrsm2Info(&info); verify_hipsparse_status_success(status, "ERROR: csrsm2_struct constructor"); } ~csrsm2_struct() { hipsparseStatus_t status = hipsparseDestroyCsrsm2Info(info); verify_hipsparse_status_success(status, "ERROR: csrsm2_struct destructor"); } }; #endif struct bsrilu02_struct { bsrilu02Info_t info; bsrilu02_struct() { hipsparseStatus_t status = hipsparseCreateBsrilu02Info(&info); verify_hipsparse_status_success(status, "ERROR: bsrilu02_struct constructor"); } ~bsrilu02_struct() { hipsparseStatus_t status = hipsparseDestroyBsrilu02Info(info); verify_hipsparse_status_success(status, "ERROR: bsrilu02_struct destructor"); } }; struct csrilu02_struct { csrilu02Info_t info; csrilu02_struct() { hipsparseStatus_t status = hipsparseCreateCsrilu02Info(&info); verify_hipsparse_status_success(status, "ERROR: csrilu02_struct constructor"); } ~csrilu02_struct() { hipsparseStatus_t status = hipsparseDestroyCsrilu02Info(info); verify_hipsparse_status_success(status, "ERROR: csrilu02_struct destructor"); } }; struct bsric02_struct { bsric02Info_t info; bsric02_struct() { hipsparseStatus_t status = hipsparseCreateBsric02Info(&info); verify_hipsparse_status_success(status, "ERROR: bsric02_struct constructor"); } ~bsric02_struct() { hipsparseStatus_t status = hipsparseDestroyBsric02Info(info); verify_hipsparse_status_success(status, "ERROR: bsric02_struct destructor"); } }; struct csric02_struct { csric02Info_t info; csric02_struct() { hipsparseStatus_t status = hipsparseCreateCsric02Info(&info); verify_hipsparse_status_success(status, "ERROR: csric02_struct constructor"); } ~csric02_struct() { hipsparseStatus_t status = hipsparseDestroyCsric02Info(info); verify_hipsparse_status_success(status, "ERROR: csric02_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) struct csrgemm2_struct { csrgemm2Info_t info; csrgemm2_struct() { hipsparseStatus_t status = hipsparseCreateCsrgemm2Info(&info); verify_hipsparse_status_success(status, "ERROR: csrgemm2_struct constructor"); } ~csrgemm2_struct() { hipsparseStatus_t status = hipsparseDestroyCsrgemm2Info(info); verify_hipsparse_status_success(status, "ERROR: csrgemm2_struct destructor"); } }; #endif struct prune_struct { pruneInfo_t info; prune_struct() { hipsparseStatus_t status = hipsparseCreatePruneInfo(&info); verify_hipsparse_status_success(status, "ERROR: prune_struct constructor"); } ~prune_struct() { hipsparseStatus_t status = hipsparseDestroyPruneInfo(info); verify_hipsparse_status_success(status, "ERROR: prune_struct destructor"); } }; struct csru2csr_struct { csru2csrInfo_t info; csru2csr_struct() { hipsparseStatus_t status = hipsparseCreateCsru2csrInfo(&info); verify_hipsparse_status_success(status, "ERROR: csru2csr_struct constructor"); } ~csru2csr_struct() { hipsparseStatus_t status = hipsparseDestroyCsru2csrInfo(info); verify_hipsparse_status_success(status, "ERROR: csru2csr_struct destructor"); } }; #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11000) struct spgemm_struct { hipsparseSpGEMMDescr_t descr; spgemm_struct() { hipsparseStatus_t status = hipsparseSpGEMM_createDescr(&descr); verify_hipsparse_status_success(status, "ERROR: spgemm_struct constructor"); } ~spgemm_struct() { hipsparseStatus_t status = hipsparseSpGEMM_destroyDescr(descr); verify_hipsparse_status_success(status, "ERROR: spgemm_struct destructor"); } }; #endif } // namespace hipsparse_test using hipsparse_unique_ptr = std::unique_ptr; #endif // GUARD_HIPSPARSE_MANAGE_PTR ./clients/include/testing_identity.hpp0000664000175100017510000001051515176134511020274 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_IDENTITY_HPP #define TESTING_IDENTITY_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_identity_bad_arg(void) { #if(!defined(CUDART_VERSION)) int n = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto p_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; int* p = (int*)p_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseCreateIdentityPermutation(handle, n, (int*)nullptr), "Error: p is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseCreateIdentityPermutation(nullptr, n, p)); #endif } hipsparseStatus_t testing_identity(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int n = argus.N; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hp(n); std::vector hp_gold(n); // create_identity_permutation on host for(int i = 0; i < n; ++i) { hp_gold[i] = i; } // Allocate memory on the device auto dp_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * n), device_free}; int* dp = (int*)dp_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, n, dp)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy(hp.data(), dp, sizeof(int) * n, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, n, 1, hp_gold.data(), hp.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, n, dp)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCreateIdentityPermutation(handle, n, dp)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = identity_gbyte_count(n); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::N, n, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_IDENTITY_HPP ./clients/include/testing_sddmm_coo.hpp0000664000175100017510000004754515176134511020424 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_COO_HPP #define TESTING_SDDMM_COO_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_coo_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drow = (int32_t*)drow_managed.get(); int32_t* dcol = (int32_t*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCoo(&C, m, n, nnz, drow, dcol, dval, idxTypeI, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_coo(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrow_ind(nnz); // Convert to COO for(I i = 0; i < m; ++i) { for(I j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { hrow_ind[j - idx_base] = i + idx_base; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(nnz_A); std::vector hB(nnz_B); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto drow_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow = (I*)drow_managed.get(); I* dcol = (I*)dcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(drow, hrow_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&C1, C_m, C_n, nnz, drow, dcol, dval1, typeI, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCoo(&C2, C_m, C_n, nnz, drow, dcol, dval2, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(I i = 0; i < nnz; ++i) { const I r = hrow_ind[i] - idx_base; const I c = hcsr_col_ind[i] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I j = 0; j < k; ++j) { sum = testing_fma(Aptr[incA * j], Bptr[incB * j], sum); } hcsr_val[i] = testing_mult(hcsr_val[i], h_beta) + testing_mult(h_alpha, sum); } unit_check_near(1, nnz, 1, hval1.data(), hcsr_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_coo_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_COO), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_COO_HPP ./clients/include/testing_gpsv_interleaved_batch.hpp0000664000175100017510000002746215176134511023156 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GPSV_INTERLEAVED_BATCH_HPP #define TESTING_GPSV_INTERLEAVED_BATCH_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gpsv_interleaved_batch_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int algo = 0; int m = 10; int batch_count = 10; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dds_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddw_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* dds = (T*)dds_managed.get(); T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* ddw = (T*)ddw_managed.get(); T* dx = (T*)dx_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gpsvInterleavedBatch_bufferSizeExt verify_hipsparse_status_invalid_handle(hipsparseXgpsvInterleavedBatch_bufferSizeExt( nullptr, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, -1, dds, ddl, dd, ddu, ddw, dx, batch_count, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, -1, &bsize), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, nullptr), "Error: bsize is nullptr"); // gpsvInterleavedBatch verify_hipsparse_status_invalid_handle(hipsparseXgpsvInterleavedBatch( nullptr, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch( handle, algo, -1, dds, ddl, dd, ddu, ddw, dx, batch_count, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgpsvInterleavedBatch(handle, algo, m, dds, ddl, dd, ddu, ddw, dx, -1, dbuf), "Error: batch_count is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, (T*)nullptr, ddl, dd, ddu, ddw, dx, batch_count, dbuf), "Error: dds is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, (T*)nullptr, dd, ddu, ddw, dx, batch_count, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, (T*)nullptr, ddu, ddw, dx, batch_count, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, (T*)nullptr, ddw, dx, batch_count, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, (T*)nullptr, dx, batch_count, dbuf), "Error: ddw is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, (T*)nullptr, batch_count, dbuf), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gpsv_interleaved_batch(Arguments argus) { int m = argus.M; int batch_count = argus.batch_count; int algo = argus.gpsv_alg; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hds(m * batch_count, make_DataType(1)); std::vector hdl(m * batch_count, make_DataType(1)); std::vector hd(m * batch_count, make_DataType(2)); std::vector hdu(m * batch_count, make_DataType(1)); std::vector hdw(m * batch_count, make_DataType(1)); std::vector hx(m * batch_count, make_DataType(3)); for(int i = 0; i < batch_count; i++) { hds[i] = make_DataType(0); hds[batch_count + i] = make_DataType(0); hdl[i] = make_DataType(0); hdu[batch_count * (m - 1) + i] = make_DataType(0); hdw[batch_count * (m - 1) + i] = make_DataType(0); hdw[batch_count * (m - 2) + i] = make_DataType(0); } std::vector hx_original = hx; // allocate memory on device auto dds_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto ddw_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * batch_count), device_free}; T* dds = (T*)dds_managed.get(); T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* ddw = (T*)ddw_managed.get(); T* dx = (T*)dx_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dds, hds.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddw, hdw.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m * batch_count, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch_bufferSizeExt( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, buffer)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx.data(), dx, sizeof(T) * m * batch_count, hipMemcpyDeviceToHost)); // Check std::vector hresult(m * batch_count, make_DataType(3)); for(int b = 0; b < batch_count; b++) { for(int i = 0; i < m; ++i) { T sum = testing_mult(hd[batch_count * i + b], hx[batch_count * i + b]); sum = sum + ((i - 2 >= 0) ? testing_mult(hds[batch_count * i + b], hx[batch_count * (i - 2) + b]) : make_DataType(0)); sum = sum + ((i - 1 >= 0) ? testing_mult(hdl[batch_count * i + b], hx[batch_count * (i - 1) + b]) : make_DataType(0)); sum = sum + ((i + 1 < m) ? testing_mult(hdu[batch_count * i + b], hx[batch_count * (i + 1) + b]) : make_DataType(0)); sum = sum + ((i + 2 < m) ? testing_mult(hdw[batch_count * i + b], hx[batch_count * (i + 2) + b]) : make_DataType(0)); hresult[batch_count * i + b] = sum; } } unit_check_near(1, m * batch_count, 1, hx_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgpsvInterleavedBatch( handle, algo, m, dds, ddl, dd, ddu, ddw, dx, batch_count, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gpsv_interleaved_batch_gbyte_count(m, batch_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::batch_count, batch_count, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GPSV_INTERLEAVED_BATCH_HPP ./clients/include/testing_bsric02.hpp0000664000175100017510000011371515176134511017715 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRIC02_HPP #define TESTING_BSRIC02_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsric02_bad_arg(void) { #if(!defined(CUDART_VERSION)) int mb = 100; int nnzb = 100; int block_dim = 4; int safe_size = 100; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_COLUMN; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsric02(new bsric02_struct); bsric02Info_t info = unique_ptr_bsric02->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize( handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_bufferSize(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_bufferSize(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsric02Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsric02_bufferSize((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02_analysis(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsric02_analysis((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, (int*)nullptr, dcol, block_dim, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, (int*)nullptr, block_dim, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, (T*)nullptr, dptr, dcol, block_dim, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, block_dim, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsric02(handle, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, (bsric02Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXbsric02((hipsparseHandle_t) nullptr, dirA, mb, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXbsric02_zeroPivot(handle, (bsric02Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXbsric02_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_bsric02(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int block_dim = argus.block_dim; hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseSolvePolicy_t policy = argus.solve_policy; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsric02(new bsric02_struct); bsric02Info_t info = unique_ptr_bsric02->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; // allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_1_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto dbsr_val_2_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; auto d_analysis_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_solve_pivot_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val_1 = (T*)dbsr_val_1_managed.get(); T* dbsr_val_2 = (T*)dbsr_val_2_managed.get(); int* d_analysis_pivot_2 = (int*)d_analysis_pivot_2_managed.get(); int* d_solve_pivot_2 = (int*)d_solve_pivot_2_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind)); CHECK_HIP_ERROR(hipMemcpy( dbsr_val_2, dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToDevice)); // Host BSR matrix std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); std::vector hbsr_val_orig(nnzb * block_dim * block_dim); // Copy device BSR matrix to host CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val_orig.data(), dbsr_val_1, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); // Obtain bsric02 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_bufferSize(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); int h_analysis_pivot_gold; int h_analysis_pivot_1; int h_analysis_pivot_2; int h_solve_pivot_gold; int h_solve_pivot_1; int h_solve_pivot_2; hipsparseStatus_t status_analysis_1; hipsparseStatus_t status_analysis_2; hipsparseStatus_t status_solve_1; hipsparseStatus_t status_solve_2; if(argus.unit_check) { // bsric02 analysis - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_1 = hipsparseXbsric02_zeroPivot(handle, info, &h_analysis_pivot_1); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsric02 analysis - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02_analysis(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_analysis_2 = hipsparseXbsric02_zeroPivot(handle, info, d_analysis_pivot_2); if(h_analysis_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_analysis_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsric02 solve - host mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_1 = hipsparseXbsric02_zeroPivot(handle, info, &h_solve_pivot_1); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // bsric02 solve - device mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_2, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); // Get pivot status_solve_2 = hipsparseXbsric02_zeroPivot(handle, info, d_solve_pivot_2); if(h_solve_pivot_1 != -1) { verify_hipsparse_status_zero_pivot(status_solve_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); } // Copy output from device to CPU std::vector result_1(block_dim * block_dim * nnzb); std::vector result_2(block_dim * block_dim * nnzb); CHECK_HIP_ERROR(hipMemcpy(result_1.data(), dbsr_val_1, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(result_2.data(), dbsr_val_2, sizeof(T) * block_dim * block_dim * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_analysis_pivot_2, d_analysis_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(&h_solve_pivot_2, d_solve_pivot_2, sizeof(int), hipMemcpyDeviceToHost)); // Host csric02 int numerical_pivot; int structural_pivot; host_bsric02(dir, mb, block_dim, hbsr_row_ptr, hbsr_col_ind, hbsr_val, idx_base, &structural_pivot, &numerical_pivot); h_analysis_pivot_gold = structural_pivot; // Solve pivot gives the first numerical or structural non-invertible block if(structural_pivot == -1) { h_solve_pivot_gold = numerical_pivot; } else if(numerical_pivot == -1) { h_solve_pivot_gold = structural_pivot; } else { h_solve_pivot_gold = std::min(numerical_pivot, structural_pivot); } #ifndef __HIP_PLATFORM_NVIDIA__ // Do not check pivots in cusparse unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_1); unit_check_general(1, 1, 1, &h_analysis_pivot_gold, &h_analysis_pivot_2); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_1); unit_check_general(1, 1, 1, &h_solve_pivot_gold, &h_solve_pivot_2); #endif if(h_analysis_pivot_gold == -1 && h_solve_pivot_gold == -1) { unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_1.data()); unit_check_near(1, nnzb * block_dim * block_dim, 1, hbsr_val.data(), result_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); } // Solve run double gpu_time_used = 0; for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIP_ERROR(hipMemcpy(dbsr_val_1, hbsr_val_orig.data(), sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyHostToDevice)); double temp = get_time_us(); CHECK_HIPSPARSE_ERROR(hipsparseXbsric02(handle, dir, mb, nnzb, descr, dbsr_val_1, dbsr_row_ptr, dbsr_col_ind, block_dim, info, policy, dbuffer)); gpu_time_used += (get_time_us() - temp); } gpu_time_used = gpu_time_used / number_hot_calls; double gbyte_count = bsric0_gbyte_count(mb, block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::Mb, mb, display_key_t::nnzb, nnzb, display_key_t::block_dim, block_dim, display_key_t::direction, hipsparse_direction2string(dir), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRIC02_HPP ./clients/include/utility.hpp0000664000175100017510000065260015176134511016420 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_UTILITY_HPP #define TESTING_UTILITY_HPP #include #include #include #include #include #include #include #include #include #include #include #include #ifdef GOOGLE_TEST #include "gtest/gtest.h" #endif #ifdef _OPENMP #include #endif /*! \brief Return path of this executable */ std::string hipsparse_exepath(); /*! \brief Return path where the test data file (hipsparse_test.data) is located */ std::string hipsparse_datapath(); inline void missing_file_error_message(const char* filename) { std::cerr << "#" << std::endl; std::cerr << "# error:" << std::endl; std::cerr << "# cannot open file '" << filename << "'" << std::endl; std::cerr << "#" << std::endl; std::cerr << "# PLEASE READ CAREFULLY !" << std::endl; std::cerr << "#" << std::endl; std::cerr << "# What could be the reason of this error: " << std::endl; std::cerr << "# You are running the testing application and it expects to find the file " "at the specified location. This means that either you did not download the test " "matrices, or you did not specify the location of the folder containing your " "files. If you want to specify the location of the folder containing your files, " "then you will find the needed information with 'hipsparse-test --help'." "If you need to download matrices, then a cmake script " "'hipsparse_clientmatrices.cmake' is available from the hipsparse client package." << std::endl; std::cerr << "#" << std::endl; std::cerr << "# Examples: 'hipsparse_clientmatrices.cmake -DCMAKE_MATRICES_DIR='" << std::endl; std::cerr << "# 'hipsparse-test --matrices-dir '" << std::endl; std::cerr << "# (or 'export " "HIPSPARSE_CLIENTS_MATRICES_DIR=;hipsparse-test')" << std::endl; std::cerr << "#" << std::endl; } static const char* s_hipsparse_clients_matrices_dir = nullptr; inline const char* get_hipsparse_clients_matrices_dir() { return s_hipsparse_clients_matrices_dir; } inline std::string get_filename(const std::string& matrix_filename) { std::string matrix_filename_with_ext = matrix_filename; // Check if file already has extension, keep it, otherwise add .bin extension size_t last_dot_pos = matrix_filename_with_ext.find_last_of('.'); if(last_dot_pos == std::string::npos || last_dot_pos == 0) { matrix_filename_with_ext += ".bin"; } const char* matrices_dir = get_hipsparse_clients_matrices_dir(); if(matrices_dir == nullptr) { matrices_dir = getenv("HIPSPARSE_CLIENTS_MATRICES_DIR"); } std::string r; if(matrices_dir != nullptr) { r = std::string(matrices_dir) + "/" + matrix_filename_with_ext; } else { r = hipsparse_exepath() + "../matrices/" + matrix_filename_with_ext; } FILE* tmpf = fopen(r.c_str(), "r"); if(!tmpf) { missing_file_error_message(r.c_str()); std::cerr << "exit(HIPSPARSE_STATUS_INTERNAL_ERROR)" << std::endl; exit(HIPSPARSE_STATUS_INTERNAL_ERROR); } else { fclose(tmpf); } return r; } /*!\file * \brief provide data initialization and timing utilities. */ // BSR indexing macros #define BSR_IND(j, bi, bj, dir) \ ((dir == HIPSPARSE_DIRECTION_ROW) ? BSR_IND_R(j, bi, bj) : BSR_IND_C(j, bi, bj)) #define BSR_IND_R(j, bi, bj) (bsr_dim * bsr_dim * (j) + (bi)*bsr_dim + (bj)) #define BSR_IND_C(j, bi, bj) (bsr_dim * bsr_dim * (j) + (bi) + (bj)*bsr_dim) #define CHECK_HIP_ERROR(error) \ if(error != hipSuccess) \ { \ fprintf(stderr, \ "error: '%s'(%d) at %s:%d\n", \ hipGetErrorString(error), \ error, \ __FILE__, \ __LINE__); \ exit(EXIT_FAILURE); \ } #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11003)) #define CHECK_HIPSPARSE_ERROR_CASE__(token_) \ case token_: \ fprintf(stderr, #token_); \ break #define CHECK_HIPSPARSE_ERROR(error) \ { \ auto local_error = (error); \ if(local_error != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "hipSPARSE error: "); \ switch(local_error) \ { \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_SUCCESS); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_INITIALIZED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ALLOC_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INVALID_VALUE); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ARCH_MISMATCH); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MAPPING_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_EXECUTION_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INTERNAL_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ZERO_PIVOT); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_SUPPORTED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INSUFFICIENT_RESOURCES); \ } \ fprintf(stderr, "\n"); \ return local_error; \ } \ } \ (void)0 #else #define CHECK_HIPSPARSE_ERROR_CASE__(token_) \ case token_: \ fprintf(stderr, #token_); \ break #define CHECK_HIPSPARSE_ERROR(error) \ { \ auto local_error = (error); \ if(local_error != HIPSPARSE_STATUS_SUCCESS) \ { \ fprintf(stderr, "hipSPARSE error: "); \ switch(local_error) \ { \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_SUCCESS); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_INITIALIZED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ALLOC_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INVALID_VALUE); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ARCH_MISMATCH); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MAPPING_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_EXECUTION_FAILED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_INTERNAL_ERROR); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_ZERO_PIVOT); \ CHECK_HIPSPARSE_ERROR_CASE__(HIPSPARSE_STATUS_NOT_SUPPORTED); \ } \ fprintf(stderr, "\n"); \ return local_error; \ } \ } \ (void)0 #endif #ifdef __HIP_PLATFORM_NVIDIA__ static inline hipComplex operator-(const hipComplex& op) { hipComplex ret; ret.x = -op.x; ret.y = -op.y; return ret; } static inline hipDoubleComplex operator-(const hipDoubleComplex& op) { hipDoubleComplex ret; ret.x = -op.x; ret.y = -op.y; return ret; } static inline bool operator==(const hipComplex& lhs, const hipComplex& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } static inline bool operator==(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y; } static inline bool operator!=(const hipComplex& lhs, const hipComplex& rhs) { return !(lhs == rhs); } static inline bool operator!=(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { return !(lhs == rhs); } static inline hipComplex operator+(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = lhs.x + rhs.x; ret.y = lhs.y + rhs.y; return ret; } static inline hipDoubleComplex operator+(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = lhs.x + rhs.x; ret.y = lhs.y + rhs.y; return ret; } static inline hipComplex operator-(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = lhs.x - rhs.x; ret.y = lhs.y - rhs.y; return ret; } static inline hipDoubleComplex operator-(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = lhs.x - rhs.x; ret.y = lhs.y - rhs.y; return ret; } static inline hipComplex operator*(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = lhs.x * rhs.x - lhs.y * rhs.y; ret.y = lhs.x * rhs.y + lhs.y * rhs.x; return ret; } static inline hipDoubleComplex operator*(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = lhs.x * rhs.x - lhs.y * rhs.y; ret.y = lhs.x * rhs.y + lhs.y * rhs.x; return ret; } static inline hipComplex operator/(const hipComplex& lhs, const hipComplex& rhs) { hipComplex ret; ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); return ret; } static inline hipDoubleComplex operator/(const hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { hipDoubleComplex ret; ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); return ret; } static inline hipComplex operator+=(hipComplex& lhs, const hipComplex& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } static inline hipDoubleComplex operator+=(hipDoubleComplex& lhs, const hipDoubleComplex& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } #endif /* ============================================================================================ */ /*! \brief Make data type */ template inline T make_DataType2(double real, double imag) { return static_cast(real); } template <> inline hipComplex make_DataType2(double real, double imag) { return make_hipFloatComplex(static_cast(real), static_cast(imag)); } template <> inline hipDoubleComplex make_DataType2(double real, double imag) { return make_hipDoubleComplex(real, imag); } template inline T make_DataType(double real, double imag = 0.0) { return make_DataType2(real, imag); } /* ============================================================================================ */ /*! \brief mult */ template inline T testing_mult(T p, T q) { return p * q; } template <> inline hipComplex testing_mult(hipComplex p, hipComplex q) { return hipCmulf(p, q); } template <> inline hipDoubleComplex testing_mult(hipDoubleComplex p, hipDoubleComplex q) { return hipCmul(p, q); } /* ============================================================================================ */ /*! \brief div */ template inline T testing_div(T p, T q) { return p / q; } template <> inline hipComplex testing_div(hipComplex p, hipComplex q) { return hipCdivf(p, q); } template <> inline hipDoubleComplex testing_div(hipDoubleComplex p, hipDoubleComplex q) { return hipCdiv(p, q); } /* ============================================================================================ */ /*! \brief fma */ template inline T testing_fma(T p, T q, T r) { return std::fma(p, q, r); } template <> inline hipComplex testing_fma(hipComplex p, hipComplex q, hipComplex r) { return hipCfmaf(p, q, r); } template <> inline hipDoubleComplex testing_fma(hipDoubleComplex p, hipDoubleComplex q, hipDoubleComplex r) { return hipCfma(p, q, r); } /* ============================================================================================ */ /*! \brief abs */ static inline float testing_abs(float x) { return std::abs(x); } static inline double testing_abs(double x) { return std::abs(x); } static inline float testing_abs(hipComplex x) { return hipCabsf(x); } static inline double testing_abs(hipDoubleComplex x) { return hipCabs(x); } /* ============================================================================================ */ /*! \brief conj */ static inline float testing_conj(float x) { return x; } static inline double testing_conj(double x) { return x; } static inline hipComplex testing_conj(hipComplex x) { return make_DataType(x.x, -x.y); } static inline hipDoubleComplex testing_conj(hipDoubleComplex x) { return make_DataType(x.x, -x.y); } template inline T testing_conj(T val, bool conj) { return conj ? testing_conj(val) : val; } /* ============================================================================================ */ /*! \brief real */ static inline float testing_real(float x) { return std::real(x); } static inline double testing_real(double x) { return std::real(x); } static inline float testing_real(hipComplex x) { return hipCrealf(x); } static inline double testing_real(hipDoubleComplex x) { return hipCreal(x); } /* ============================================================================================ */ /* generate random number :*/ /*! \brief generate a random number between [0, 0.999...] . */ template inline T random_generator() { // return rand()/( (T)RAND_MAX + 1); return make_DataType(rand() % 10 + 1, rand() % 10 + 1); // generate a integer number between [1, 10] }; /* ============================================================================================ */ /*! \brief matrix/vector initialization: */ // for vector x (M=1, N=lengthX); // for complex number, the real/imag part would be initialized with the same value template void hipsparseInit(std::vector& A, int M, int N) { for(int i = 0; i < M; ++i) { for(int j = 0; j < N; ++j) { A[i + j] = random_generator(); } } }; /* ============================================================================================ */ /*! \brief vector initialization: */ // initialize sparse index vector with nnz entries ranging from start to end template void hipsparseInitIndex(I* x, int nnz, int start, int end) { std::vector check(end - start, false); int num = 0; while(num < nnz) { int val = start + rand() % (end - start); if(!check[val - start]) { x[num] = val; check[val - start] = true; ++num; } } std::sort(x, x + nnz); }; /* ============================================================================================ */ /*! \brief csr matrix initialization */ template void hipsparseInitCSR( std::vector& ptr, std::vector& col, std::vector& val, int nrow, int ncol, int nnz) { // Row offsets ptr[0] = 0; ptr[nrow] = nnz; for(int i = 1; i < nrow; ++i) { ptr[i] = rand() % (nnz - 1) + 1; } std::sort(ptr.begin(), ptr.end()); // Column indices for(int i = 0; i < nrow; ++i) { hipsparseInitIndex(&col[ptr[i]], ptr[i + 1] - ptr[i], 0, ncol - 1); std::sort(&col[ptr[i]], &col[ptr[i + 1]]); } // Random values for(int i = 0; i < nnz; ++i) { val[i] = random_generator(); } } /* ============================================================================================ */ /*! \brief Generate 2D laplacian on unit square in CSR format */ template J gen_2d_laplacian(int ndim, std::vector& rowptr, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { if(ndim == 0) { return 0; } J n = ndim * ndim; I nnz_mat = n * 5 - ndim * 4; rowptr.resize(n + 1); col.resize(nnz_mat); val.resize(nnz_mat); I nnz = 0; // Fill local arrays for(int i = 0; i < ndim; ++i) { for(int j = 0; j < ndim; ++j) { J idx = i * ndim + j; rowptr[idx] = nnz + idx_base; // if no upper boundary element, connect with upper neighbor if(i != 0) { col[nnz] = idx - ndim + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } // if no left boundary element, connect with left neighbor if(j != 0) { col[nnz] = idx - 1 + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } // element itself col[nnz] = idx + idx_base; val[nnz] = make_DataType(4.0); ++nnz; // if no right boundary element, connect with right neighbor if(j != ndim - 1) { col[nnz] = idx + 1 + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } // if no lower boundary element, connect with lower neighbor if(i != ndim - 1) { col[nnz] = idx + ndim + idx_base; val[nnz] = make_DataType(-1.0); ++nnz; } } } rowptr[n] = nnz + idx_base; return n; } /* ============================================================================================ */ /*! \brief Generate a random sparsity pattern with a dense format, generated floating point values of type T are positive and normalized. */ template void gen_dense_random_sparsity_pattern( int m, int n, T* A, int lda, hipsparseOrder_t order, float sparsity_ratio = 0.3) { if(order == HIPSPARSE_ORDER_COL) { for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { const float d = ((float)rand()) / ((float)RAND_MAX); A[j * lda + i] = (d < sparsity_ratio) ? testing_div(make_DataType(rand()), make_DataType(RAND_MAX)) : make_DataType(0); } } } else { for(int j = 0; j < m; ++j) { for(int i = 0; i < n; ++i) { const float d = ((float)rand()) / ((float)RAND_MAX); A[j * lda + i] = (d < sparsity_ratio) ? testing_div(make_DataType(rand()), make_DataType(RAND_MAX)) : make_DataType(0); } } } } /* ============================================================================================ */ /*! \brief Generate a random sparse matrix in COO format */ template void gen_matrix_coo(I m, I n, I nnz, std::vector& row_ind, std::vector& col_ind, std::vector& val, hipsparseIndexBase_t idx_base) { if((I)row_ind.size() != nnz) { row_ind.resize(nnz); } if((I)col_ind.size() != nnz) { col_ind.resize(nnz); } if((I)val.size() != nnz) { val.resize(nnz); } // Uniform distributed row indices for(I i = 0; i < nnz; ++i) { row_ind[i] = rand() % m; } // Sort row indices std::sort(row_ind.begin(), row_ind.end()); // Sample column indices std::vector check(nnz, false); { I i = 0; while(i < nnz) { I begin = i; while(row_ind[i] == row_ind[begin]) { ++i; if(i >= nnz) { break; } } // Sample i disjunct column indices I idx = begin; while(idx < i) { #define MM_PI 3.1415 // Normal distribution around the diagonal I rng = (i - begin) * sqrt(-2.0 * log((double)rand() / RAND_MAX)) * cos(2.0 * MM_PI * (double)rand() / RAND_MAX); if(m <= n) { rng += row_ind[begin]; } // Repeat if running out of bounds if(rng < 0 || rng > n - 1) { continue; } // Check for disjunct column index in current row if(!check[rng]) { check[rng] = true; col_ind[idx] = rng; ++idx; } } // Reset disjunct check array for(I j = begin; j < i; ++j) { check[col_ind[j]] = false; } // Partially sort column indices std::sort(&col_ind[begin], &col_ind[i]); } } // Correct index base accordingly if(idx_base == HIPSPARSE_INDEX_BASE_ONE) { for(I i = 0; i < nnz; ++i) { ++row_ind[i]; ++col_ind[i]; } } // Sample random values for(I i = 0; i < nnz; ++i) { val[i] = random_generator(); //(double) rand() / RAND_MAX; } } /* ============================================================================================ */ /*! \brief Read matrix from mtx file in COO format */ template static inline void read_mtx_value(std::istringstream& is, I& row, I& col, int8_t& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, float& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, double& val) { is >> row >> col >> val; } template static void read_mtx_value(std::istringstream& is, I& row, I& col, hipComplex& val) { float real; float imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } template static void read_mtx_value(std::istringstream& is, I& row, I& col, hipDoubleComplex& val) { double real; double imag; is >> row >> col >> real >> imag; val = make_DataType(real, imag); } template static void sort(std::vector& perm, std::vector& unsorted_row, std::vector& unsorted_col) { std::sort(perm.begin(), perm.end(), [&](const I& a, const I& b) { if(unsorted_row[a] < unsorted_row[b]) { return true; } else if(unsorted_row[a] == unsorted_row[b]) { return (unsorted_col[a] < unsorted_col[b]); } else { return false; } }); } template inline void scan(const char* line, I* nrow, I* ncol, int64_t* nnz) { sscanf(line, "%d %d %ld", nrow, ncol, nnz); } template <> inline void scan(const char* line, int64_t* nrow, int64_t* ncol, int64_t* nnz) { sscanf(line, "%ld %ld %ld", nrow, ncol, nnz); } template int read_mtx_matrix(const char* filename, I& nrow, I& ncol, int64_t& nnz, std::vector& row, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { const char* env = getenv("GTEST_LISTENER"); if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("Reading matrix %s...", filename); fflush(stdout); } FILE* f = fopen(filename, "r"); if(!f) { fprintf(stderr, "Failed to open matrix file %s because it does not exist. Please download the " "matrix file using the install script with -c flag.", filename); return -1; } char line[1024]; // Check for banner if(!fgets(line, 1024, f)) { return -1; } char banner[16]; char array[16]; char coord[16]; char data[16]; char type[16]; // Extract banner if(sscanf(line, "%15s %15s %15s %15s %15s", banner, array, coord, data, type) != 5) { return -1; } // Convert to lower case for(char* p = array; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = coord; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = data; *p != '\0'; *p = tolower(*p), p++) ; for(char* p = type; *p != '\0'; *p = tolower(*p), p++) ; // Check banner if(strncmp(line, "%%MatrixMarket", 14) != 0) { return -1; } // Check array type if(strcmp(array, "matrix") != 0) { return -1; } // Check coord if(strcmp(coord, "coordinate") != 0) { return -1; } // Check data if(strcmp(data, "real") != 0 && strcmp(data, "integer") != 0 && strcmp(data, "pattern") != 0) { return -1; } // Check type if(strcmp(type, "general") != 0 && strcmp(type, "symmetric") != 0) { return -1; } // Symmetric flag int symm = !strcmp(type, "symmetric"); // Skip comments while(fgets(line, 1024, f)) { if(line[0] != '%') { break; } } // Read dimensions int64_t snnz; scan(line, &nrow, &ncol, &snnz); nnz = symm ? (snnz - nrow) * 2 + nrow : snnz; std::vector unsorted_row(nnz); std::vector unsorted_col(nnz); std::vector unsorted_val(nnz); // Read entries int64_t idx = 0; while(fgets(line, 1024, f)) { if(idx >= nnz) { return 1; } I irow; I icol; T ival; std::istringstream ss(line); if(!strcmp(data, "pattern")) { ss >> irow >> icol; ival = make_DataType(1.0); } else { read_mtx_value(ss, irow, icol, ival); } if(idx_base == HIPSPARSE_INDEX_BASE_ZERO) { --irow; --icol; } unsorted_row[idx] = irow; unsorted_col[idx] = icol; unsorted_val[idx] = ival; ++idx; if(symm && irow != icol) { if(idx >= nnz) { return 1; } unsorted_row[idx] = icol; unsorted_col[idx] = irow; unsorted_val[idx] = ival; ++idx; } } fclose(f); row.resize(nnz); col.resize(nnz); val.resize(nnz); // Sort by row and column index std::vector perm(nnz); for(int64_t i = 0; i < nnz; ++i) { perm[i] = i; } sort(perm, unsorted_row, unsorted_col); for(int64_t i = 0; i < nnz; ++i) { row[i] = unsorted_row[perm[i]]; col[i] = unsorted_col[perm[i]]; val[i] = unsorted_val[perm[i]]; } if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("done.\n"); fflush(stdout); } return 0; } /* ============================================================================================ */ /*! \brief Read matrix from binary file in CSR format */ template int read_bin_matrix(const char* filename, J& nrow, J& ncol, I& nnz, std::vector& ptr, std::vector& col, std::vector& val, hipsparseIndexBase_t idx_base) { const char* env = getenv("GTEST_LISTENER"); if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("Reading matrix %s...", filename); fflush(stdout); } FILE* f = fopen(filename, "rb"); if(!f) { return -1; } int err; int nrowf, ncolf, nnzf; err = fread(&nrowf, sizeof(int), 1, f); err |= fread(&ncolf, sizeof(int), 1, f); err |= fread(&nnzf, sizeof(int), 1, f); if(!err) { fclose(f); return -1; } nrow = (J)nrowf; ncol = (J)ncolf; nnz = (I)nnzf; // Allocate memory std::vector ptrf(nrow + 1); std::vector colf(nnz); std::vector valf(nnz); ptr.resize(nrow + 1); col.resize(nnz); val.resize(nnz); err |= fread(ptrf.data(), sizeof(int), nrow + 1, f); err |= fread(colf.data(), sizeof(int), nnz, f); err |= fread(valf.data(), sizeof(double), nnz, f); if(!err) { fclose(f); return -1; } fclose(f); for(J i = 0; i < nrow + 1; ++i) { ptr[i] = (I)ptrf[i]; } for(I i = 0; i < nnz; ++i) { col[i] = (J)colf[i]; val[i] = make_DataType(valf[i]); } if(idx_base == HIPSPARSE_INDEX_BASE_ONE) { for(J i = 0; i < nrow + 1; ++i) { ++ptr[i]; } for(I i = 0; i < nnz; ++i) { ++col[i]; } } if(!env || strcmp(env, "NO_PASS_LINE_IN_LOG")) { printf("done.\n"); fflush(stdout); } return 0; } /* ============================================================================================ */ /*! \brief Generate CSR matrix from file. File can be either mtx or bin. If filename is empty, a random matrix is generated*/ template bool generate_csr_matrix(const std::string filename, J& nrow, J& ncol, I& nnz, std::vector& csr_row_ptr, std::vector& csr_col_ind, std::vector& csr_val, hipsparseIndexBase_t idx_base) { // If no filename passed, generate matrix if(filename == "" || filename == "*") { double scale = 0.02; if(nrow > 1000 || ncol > 1000) { scale = 2.0 / std::max(nrow, ncol); } nnz = nrow * scale * ncol; std::vector coo_row_ind; gen_matrix_coo(nrow, ncol, (J)nnz, coo_row_ind, csr_col_ind, csr_val, idx_base); csr_row_ptr.resize(nrow + 1, 0); for(int i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } csr_row_ptr[0] = idx_base; for(int i = 0; i < nrow; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } return true; } else { std::string full_filename_path = get_filename(filename); std::string extension = full_filename_path.substr(full_filename_path.find_last_of(".") + 1); if(extension == "bin") { if(read_bin_matrix(full_filename_path.c_str(), nrow, ncol, nnz, csr_row_ptr, csr_col_ind, csr_val, idx_base) == 0) { return true; } } else if(extension == "mtx") { int64_t nnz_count; std::vector coo_row_ind; if(read_mtx_matrix(full_filename_path.c_str(), nrow, ncol, nnz_count, coo_row_ind, csr_col_ind, csr_val, idx_base) == 0) { if(nnz_count < std::numeric_limits::max()) { nnz = (I)nnz_count; csr_row_ptr.resize(nrow + 1, 0); for(int i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - idx_base]; } csr_row_ptr[0] = idx_base; for(int i = 0; i < nrow; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } return true; } } } } return false; } /* ============================================================================================ */ /*! \brief Generate COO matrix from file. File can be either mtx or bin. If filename is empty, a random matrix is generated*/ template bool generate_coo_matrix(const std::string filename, I& nrow, I& ncol, I& nnz, std::vector& coo_row_ind, std::vector& coo_col_ind, std::vector& coo_val, hipsparseIndexBase_t idx_base) { // If no filename passed, generate matrix if(filename == "" || filename == "*") { double scale = 0.02; if(nrow > 1000 || ncol > 1000) { scale = 2.0 / std::max(nrow, ncol); } nnz = nrow * scale * ncol; gen_matrix_coo(nrow, ncol, nnz, coo_row_ind, coo_col_ind, coo_val, idx_base); return true; } else { std::string full_filename_path = get_filename(filename); std::string extension = full_filename_path.substr(full_filename_path.find_last_of(".") + 1); if(extension == "bin") { std::vector csr_row_ptr; if(read_bin_matrix(full_filename_path.c_str(), nrow, ncol, nnz, csr_row_ptr, coo_col_ind, coo_val, idx_base) == 0) { coo_row_ind.resize(nnz); for(I i = 0; i < nrow; ++i) { I row_begin = csr_row_ptr[i] - idx_base; I row_end = csr_row_ptr[i + 1] - idx_base; for(I j = row_begin; j < row_end; ++j) { coo_row_ind[j] = i + idx_base; } } return true; } } else if(extension == "mtx") { int64_t nnz_count; if(read_mtx_matrix(full_filename_path.c_str(), nrow, ncol, nnz_count, coo_row_ind, coo_col_ind, coo_val, idx_base) == 0) { if(nnz_count < std::numeric_limits::max()) { nnz = (I)nnz_count; return true; } } } } return false; } /* ============================================================================================ */ /*! \brief Compute incomplete LU factorization without fill-ins and no pivoting using CSR * matrix storage format. */ static inline float testing_neg(float val) { return -val; } static inline double testing_neg(double val) { return -val; } static inline hipComplex testing_neg(hipComplex val) { hipComplex ret; ret.x = -val.x; ret.y = -val.y; return ret; } static inline hipDoubleComplex testing_neg(hipDoubleComplex val) { hipDoubleComplex ret; ret.x = -val.x; ret.y = -val.y; return ret; } template void host_nnz(hipsparseDirection_t dirA, int m, int n, const hipsparseMatDescr_t descrA, const T* A, int lda, int* nnzPerRowColumn, int* nnzTotalDevHostPtr) { int mn = (dirA == HIPSPARSE_DIRECTION_ROW) ? m : n; #ifdef _OPENMP #pragma omp parallel for #endif for(int j = 0; j < mn; ++j) { nnzPerRowColumn[j] = 0; } for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { if(A[j * lda + i] != make_DataType(0)) { if(dirA == HIPSPARSE_DIRECTION_ROW) { nnzPerRowColumn[i] += 1; } else { nnzPerRowColumn[j] += 1; } } } } int sum = 0; #ifdef _OPENMP #pragma omp parallel for reduction(+ : sum) #endif for(int j = 0; j < mn; ++j) { sum = sum + nnzPerRowColumn[j]; } nnzTotalDevHostPtr[0] = sum; } template void host_dense2csx(int m, int n, hipsparseIndexBase_t base, const T* A, int ld, const int* nnz_per_row_columns, T* csx_val, int* csx_row_col_ptr, int* csx_col_row_ind) { static constexpr T s_zero = {}; int len = (HIPSPARSE_DIRECTION_ROW == DIRA) ? m : n; *csx_row_col_ptr = base; for(int i = 0; i < len; ++i) { csx_row_col_ptr[i + 1] = nnz_per_row_columns[i] + csx_row_col_ptr[i]; } switch(DIRA) { case HIPSPARSE_DIRECTION_COLUMN: { for(int j = 0; j < n; ++j) { for(int i = 0; i < m; ++i) { if(A[j * ld + i] != s_zero) { *csx_val++ = A[j * ld + i]; *csx_col_row_ind++ = i + base; } } } break; } case HIPSPARSE_DIRECTION_ROW: { // // Does not matter having an orthogonal traversal ... testing only. // Otherwise, we would use csxRowPtrA to store the shifts. // and once the job is done a simple memory move would reinitialize the csxRowPtrA to its initial state) // for(int i = 0; i < m; ++i) { for(int j = 0; j < n; ++j) { if(A[j * ld + i] != s_zero) { *csx_val++ = A[j * ld + i]; *csx_col_row_ind++ = j + base; } } } break; } } } template void host_prune_dense2csr(int m, int n, const std::vector& A, int lda, hipsparseIndexBase_t base, T threshold, int& nnz, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind) { csr_row_ptr.resize(m + 1, 0); csr_row_ptr[0] = base; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(testing_abs(A[lda * j + i]) > threshold) { csr_row_ptr[i + 1]++; } } } for(int i = 1; i <= m; i++) { csr_row_ptr[i] += csr_row_ptr[i - 1]; } nnz = csr_row_ptr[m] - csr_row_ptr[0]; csr_col_ind.resize(nnz); csr_val.resize(nnz); int index = 0; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { if(testing_abs(A[lda * j + i]) > threshold) { csr_val[index] = A[lda * j + i]; csr_col_ind[index] = j + base; index++; } } } } template void host_prune_dense2csr_by_percentage(int m, int n, const std::vector& A, int lda, hipsparseIndexBase_t base, T percentage, int& nnz, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind) { int nnz_A = m * n; int pos = std::ceil(nnz_A * (percentage / 100)) - 1; pos = std::min(pos, nnz_A - 1); pos = std::max(pos, 0); std::vector sorted_A(nnz_A); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { sorted_A[m * i + j] = std::abs(A[lda * i + j]); } } std::sort(sorted_A.begin(), sorted_A.end()); T threshold = (nnz_A > 0) ? sorted_A[pos] : make_DataType(0); host_prune_dense2csr(m, n, A, lda, base, threshold, nnz, csr_val, csr_row_ptr, csr_col_ind); } template void host_csx2dense(int m, int n, hipsparseIndexBase_t base, const T* csx_val, const int* csx_row_col_ptr, const int* csx_col_row_ind, T* A, int ld) { static constexpr T s_zero = {}; switch(DIRA) { case HIPSPARSE_DIRECTION_COLUMN: { for(int col = 0; col < n; ++col) { for(int row = 0; row < m; ++row) { A[row + ld * col] = s_zero; } const int bound = csx_row_col_ptr[col + 1] - base; for(int at = csx_row_col_ptr[col] - base; at < bound; ++at) { A[(csx_col_row_ind[at] - base) + ld * col] = csx_val[at]; } } break; } case HIPSPARSE_DIRECTION_ROW: { for(int row = 0; row < m; ++row) { for(int col = 0; col < n; ++col) { A[col * ld + row] = s_zero; } const int bound = csx_row_col_ptr[row + 1] - base; for(int at = csx_row_col_ptr[row] - base; at < bound; ++at) { A[(csx_col_row_ind[at] - base) * ld + row] = csx_val[at]; } } break; } } } template inline void host_csr_to_csr_compress(int M, int N, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t base, T tol) { if(M <= 0 || N <= 0) { return; } // find how many entries will be in each compressed CSR matrix row std::vector nnz_per_row(M); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int start = csr_row_ptr_A[i] - base; int end = csr_row_ptr_A[i + 1] - base; int count = 0; for(int j = start; j < end; j++) { if(testing_abs(csr_val_A[j]) > testing_real(tol) && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { count++; } } nnz_per_row[i] = count; } // add up total number of entries int nnz_C = 0; for(int i = 0; i < M; i++) { nnz_C += nnz_per_row[i]; } //column indices and value arrays for compressed CSR matrix csr_col_ind_C.resize(nnz_C); csr_val_C.resize(nnz_C); // fill in row pointer array for compressed CSR matrix csr_row_ptr_C.resize(M + 1); csr_row_ptr_C[0] = base; for(int i = 0; i < M; i++) { csr_row_ptr_C[i + 1] = csr_row_ptr_C[i] + nnz_per_row[i]; } // fill in column indices and value arrays for compressed CSR matrix #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int start = csr_row_ptr_A[i] - base; int end = csr_row_ptr_A[i + 1] - base; int index = csr_row_ptr_C[i] - base; for(int j = start; j < end; j++) { if(testing_abs(csr_val_A[j]) > testing_real(tol) && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_col_ind_C[index] = csr_col_ind_A[j]; csr_val_C[index] = csr_val_A[j]; index++; } } } } template inline void host_prune_csr_to_csr(int M, int N, int nnz_A, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, int& nnz_C, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t csr_base_A, hipsparseIndexBase_t csr_base_C, T threshold) { csr_row_ptr_C.resize(M + 1, 0); csr_row_ptr_C[0] = csr_base_C; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { for(int j = csr_row_ptr_A[i] - csr_base_A; j < csr_row_ptr_A[i + 1] - csr_base_A; j++) { if(testing_abs(csr_val_A[j]) > threshold && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_row_ptr_C[i + 1]++; } } } for(int i = 1; i <= M; i++) { csr_row_ptr_C[i] += csr_row_ptr_C[i - 1]; } nnz_C = csr_row_ptr_C[M] - csr_row_ptr_C[0]; csr_col_ind_C.resize(nnz_C); csr_val_C.resize(nnz_C); int index = 0; for(int i = 0; i < M; i++) { for(int j = csr_row_ptr_A[i] - csr_base_A; j < csr_row_ptr_A[i + 1] - csr_base_A; j++) { if(testing_abs(csr_val_A[j]) > threshold && testing_abs(csr_val_A[j]) > (std::numeric_limits::min)()) { csr_col_ind_C[index] = (csr_col_ind_A[j] - csr_base_A) + csr_base_C; csr_val_C[index] = csr_val_A[j]; index++; } } } } template void host_prune_csr_to_csr_by_percentage(int M, int N, int nnz_A, const std::vector& csr_row_ptr_A, const std::vector& csr_col_ind_A, const std::vector& csr_val_A, int& nnz_C, std::vector& csr_row_ptr_C, std::vector& csr_col_ind_C, std::vector& csr_val_C, hipsparseIndexBase_t csr_base_A, hipsparseIndexBase_t csr_base_C, T percentage) { int pos = std::ceil(nnz_A * (percentage / 100)) - 1; pos = std::min(pos, nnz_A - 1); pos = std::max(pos, 0); std::vector sorted_A(nnz_A); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < nnz_A; i++) { sorted_A[i] = testing_abs(csr_val_A[i]); } std::sort(sorted_A.begin(), sorted_A.end()); T threshold = sorted_A[pos]; host_prune_csr_to_csr(M, N, nnz_A, csr_row_ptr_A, csr_col_ind_A, csr_val_A, nnz_C, csr_row_ptr_C, csr_col_ind_C, csr_val_C, csr_base_A, csr_base_C, threshold); } template inline void host_csr_to_csc(J M, J N, I nnz, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, //const std::vector& csr_row_ptr, //const std::vector& csr_col_ind, //const std::vector& csr_val, std::vector& csc_row_ind, std::vector& csc_col_ptr, std::vector& csc_val, hipsparseAction_t action, hipsparseIndexBase_t base) { csc_row_ind.resize(nnz); csc_col_ptr.resize(N + 1, 0); csc_val.resize(nnz); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++csc_col_ptr[csr_col_ind[i] + 1 - base]; } // Scan for(J i = 0; i < N; ++i) { csc_col_ptr[i + 1] += csc_col_ptr[i]; } // Fill row indices and values for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind[j] - base; I idx = csc_col_ptr[col]; csc_row_ind[idx] = i + base; csc_val[idx] = csr_val[j]; ++csc_col_ptr[col]; } } // Shift column pointer array for(J i = N; i > 0; --i) { csc_col_ptr[i] = csc_col_ptr[i - 1] + base; } csc_col_ptr[0] = base; } template inline void host_csr_to_bsr(hipsparseDirection_t direction, int M, int N, int block_dim, int& nnzb, hipsparseIndexBase_t csr_base, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, hipsparseIndexBase_t bsr_base, std::vector& bsr_row_ptr, std::vector& bsr_col_ind, std::vector& bsr_val) { int mb = (M + block_dim - 1) / block_dim; int nb = (N + block_dim - 1) / block_dim; // quick return if block_dim == 1 if(block_dim == 1) { bsr_row_ptr.resize(mb + 1, 0); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_row_ptr.size(); i++) { bsr_row_ptr[i] = (csr_row_ptr[i] - csr_base) + bsr_base; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; bsr_col_ind.resize(nnzb, 0); bsr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_col_ind.size(); i++) { bsr_col_ind[i] = (csr_col_ind[i] - csr_base) + bsr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < csr_val.size(); i++) { bsr_val[i] = csr_val[i]; } return; } // determine number of non-zero block columns for each block row of the bsr matrix bsr_row_ptr.resize(mb + 1, 0); bsr_row_ptr[0] = bsr_base; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int start = csr_row_ptr[i * block_dim] - csr_base; int end = csr_row_ptr[std::min(M, block_dim * i + block_dim)] - csr_base; std::vector temp(nb, 0); for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; temp[blockCol] = 1; } int sum = 0; for(size_t j = 0; j < temp.size(); j++) { sum += temp[j]; } bsr_row_ptr[i + 1] = sum; } for(int i = 0; i < mb; i++) { bsr_row_ptr[i + 1] += bsr_row_ptr[i]; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; // find bsr col indices array bsr_col_ind.resize(nnzb, 0); bsr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); int colIndex = 0; for(int i = 0; i < mb; i++) { int start = csr_row_ptr[i * block_dim] - csr_base; int end = csr_row_ptr[std::min(M, block_dim * i + block_dim)] - csr_base; std::vector temp(nb, 0); for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; temp[blockCol] = 1; } for(int j = 0; j < nb; j++) { if(temp[j] == 1) { bsr_col_ind[colIndex] = j + bsr_base; colIndex++; } } } // find bsr values array for(int i = 0; i < M; i++) { int blockRow = i / block_dim; int start = csr_row_ptr[i] - csr_base; int end = csr_row_ptr[i + 1] - csr_base; for(int j = start; j < end; j++) { int blockCol = (csr_col_ind[j] - csr_base) / block_dim; colIndex = -1; for(int k = bsr_row_ptr[blockRow] - bsr_base; k < bsr_row_ptr[blockRow + 1] - bsr_base; k++) { if(bsr_col_ind[k] - bsr_base == blockCol) { colIndex = k - (bsr_row_ptr[blockRow] - bsr_base); break; } } assert(colIndex != -1); int blockIndex = 0; if(direction == HIPSPARSE_DIRECTION_ROW) { blockIndex = (csr_col_ind[j] - csr_base) % block_dim + (i % block_dim) * block_dim; } else { blockIndex = ((csr_col_ind[j] - csr_base) % block_dim) * block_dim + (i % block_dim); } int index = (bsr_row_ptr[blockRow] - bsr_base) * block_dim * block_dim + colIndex * block_dim * block_dim + blockIndex; bsr_val[index] = csr_val[j]; } } } template void host_bsr_to_bsc(int mb, int nb, int nnzb, int bsr_dim, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, std::vector& bsc_row_ind, std::vector& bsc_col_ptr, std::vector& bsc_val, hipsparseIndexBase_t bsr_base, hipsparseIndexBase_t bsc_base) { bsc_row_ind.resize(nnzb); bsc_col_ptr.resize(nb + 1, 0); bsc_val.resize(nnzb * bsr_dim * bsr_dim); // Determine nnz per column for(int i = 0; i < nnzb; ++i) { ++bsc_col_ptr[bsr_col_ind[i] + 1 - bsr_base]; } // Scan for(int i = 0; i < nb; ++i) { bsc_col_ptr[i + 1] += bsc_col_ptr[i]; } // Fill row indices and values for(int i = 0; i < mb; ++i) { int row_begin = bsr_row_ptr[i] - bsr_base; int row_end = bsr_row_ptr[i + 1] - bsr_base; for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind[j] - bsr_base; int idx = bsc_col_ptr[col]; bsc_row_ind[idx] = i + bsc_base; for(int bi = 0; bi < bsr_dim; ++bi) { for(int bj = 0; bj < bsr_dim; ++bj) { bsc_val[bsr_dim * bsr_dim * idx + bi + bj * bsr_dim] = bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj]; } } ++bsc_col_ptr[col]; } } // Shift column pointer array for(int i = nb; i > 0; --i) { bsc_col_ptr[i] = bsc_col_ptr[i - 1] + bsc_base; } bsc_col_ptr[0] = bsc_base; } template inline void host_gebsr_to_csr(hipsparseDirection_t direction, int mb, int nb, int nnzb, const std::vector& bsr_val, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, int row_block_dim, int col_block_dim, hipsparseIndexBase_t bsr_base, std::vector& csr_val, std::vector& csr_row_ptr, std::vector& csr_col_ind, hipsparseIndexBase_t csr_base) { csr_col_ind.resize(nnzb * row_block_dim * col_block_dim); csr_row_ptr.resize(mb * row_block_dim + 1); csr_val.resize(nnzb * row_block_dim * col_block_dim); int at = 0; csr_row_ptr[0] = csr_base; for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { int row = i * row_block_dim + r; for(int k = bsr_row_ptr[i] - bsr_base; k < bsr_row_ptr[i + 1] - bsr_base; ++k) { int j = bsr_col_ind[k] - bsr_base; for(int c = 0; c < col_block_dim; ++c) { int col = col_block_dim * j + c; csr_col_ind[at] = col + csr_base; if(direction == HIPSPARSE_DIRECTION_ROW) { csr_val[at] = bsr_val[k * row_block_dim * col_block_dim + col_block_dim * r + c]; } else { csr_val[at] = bsr_val[k * row_block_dim * col_block_dim + row_block_dim * c + r]; } ++at; } } csr_row_ptr[row + 1] = csr_row_ptr[row] + (bsr_row_ptr[i + 1] - bsr_row_ptr[i]) * col_block_dim; } } } template inline void host_csr_to_gebsr(hipsparseDirection_t direction, int m, int n, int row_block_dim, int col_block_dim, int& nnzb, hipsparseIndexBase_t csr_base, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, hipsparseIndexBase_t bsr_base, std::vector& bsr_row_ptr, std::vector& bsr_col_ind, std::vector& bsr_val) { int mb = (m + row_block_dim - 1) / row_block_dim; int nnz = csr_col_ind.size(); bsr_row_ptr.resize(mb + 1, 0); std::vector temp(nnz); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < nnz; i++) { temp[i] = (csr_col_ind[i] - csr_base) / col_block_dim; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int frow = row_block_dim * i; int lrow = row_block_dim * (i + 1); if(lrow > m) { lrow = m; } int start = csr_row_ptr[frow] - csr_base; int end = csr_row_ptr[lrow] - csr_base; std::sort(temp.begin() + start, temp.begin() + end); } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < mb; i++) { int frow = row_block_dim * i; int lrow = row_block_dim * (i + 1); if(lrow > m) { lrow = m; } int start = csr_row_ptr[frow] - csr_base; int end = csr_row_ptr[lrow] - csr_base; int col = -1; int count = 0; for(int j = start; j < end; j++) { if(temp[j] > col) { col = temp[j]; temp[j] = -1; temp[start + count] = col; count++; } else { temp[j] = -1; } } bsr_row_ptr[i + 1] = count; } // fill GEBSR row pointer array bsr_row_ptr[0] = bsr_base; for(int i = 0; i < mb; i++) { bsr_row_ptr[i + 1] += bsr_row_ptr[i]; } nnzb = bsr_row_ptr[mb] - bsr_row_ptr[0]; bsr_col_ind.resize(nnzb); bsr_val.resize(nnzb * row_block_dim * col_block_dim, make_DataType(0)); // fill GEBSR col indices array { int index = 0; for(int i = 0; i < nnz; i++) { if(temp[i] != -1) { bsr_col_ind[index] = temp[i] + bsr_base; index++; } } } // fill GEBSR values array #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < m; i++) { int start = csr_row_ptr[i] - csr_base; int end = csr_row_ptr[i + 1] - csr_base; int bstart = bsr_row_ptr[i / row_block_dim] - bsr_base; int bend = bsr_row_ptr[i / row_block_dim + 1] - bsr_base; int local_row = i % row_block_dim; for(int j = start; j < end; j++) { int col = csr_col_ind[j] - csr_base; int local_col = col % col_block_dim; { int index = 0; for(int k = bstart; k < bend; k++) { if(bsr_col_ind[k] - bsr_base == col / col_block_dim) { index = k; bstart = k; break; } } if(direction == HIPSPARSE_DIRECTION_ROW) { bsr_val[row_block_dim * col_block_dim * index + col_block_dim * local_row + local_col] = csr_val[j]; } else { bsr_val[row_block_dim * col_block_dim * index + row_block_dim * local_col + local_row] = csr_val[j]; } } } } } template inline void host_gebsr_to_gebsr(hipsparseDirection_t direction, int mb, int nb, int nnzb, const std::vector& bsr_val_A, const std::vector& bsr_row_ptr_A, const std::vector& bsr_col_ind_A, int row_block_dim_A, int col_block_dim_A, hipsparseIndexBase_t base_A, std::vector& bsr_val_C, std::vector& bsr_row_ptr_C, std::vector& bsr_col_ind_C, int row_block_dim_C, int col_block_dim_C, hipsparseIndexBase_t base_C) { int m = mb * row_block_dim_A; int n = nb * col_block_dim_A; // convert GEBSR to CSR format std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; host_gebsr_to_csr(direction, mb, nb, nnzb, bsr_val_A, bsr_row_ptr_A, bsr_col_ind_A, row_block_dim_A, col_block_dim_A, base_A, csr_val, csr_row_ptr, csr_col_ind, HIPSPARSE_INDEX_BASE_ZERO); // convert CSR to GEBSR format int nnzb_C; host_csr_to_gebsr(direction, m, n, row_block_dim_C, col_block_dim_C, nnzb_C, HIPSPARSE_INDEX_BASE_ZERO, csr_row_ptr, csr_col_ind, csr_val, base_C, bsr_row_ptr_C, bsr_col_ind_C, bsr_val_C); } template void host_gebsr_to_gebsc(int Mb, int Nb, int nnzb, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, const std::vector& bsr_val, int row_block_dim, int col_block_dim, std::vector& bsc_row_ind, std::vector& bsc_col_ptr, std::vector& bsc_val, hipsparseAction_t action, hipsparseIndexBase_t base) { bsc_row_ind.resize(nnzb); bsc_col_ptr.resize(Nb + 1, 0); bsc_val.resize(nnzb); const int block_shift = row_block_dim * col_block_dim; // // Determine nnz per column // for(int i = 0; i < nnzb; ++i) { ++bsc_col_ptr[bsr_col_ind[i] + 1 - base]; } // Scan for(int i = 0; i < Nb; ++i) { bsc_col_ptr[i + 1] += bsc_col_ptr[i]; } // Fill row indices and values for(int i = 0; i < Mb; ++i) { const int row_begin = bsr_row_ptr[i] - base; const int row_end = bsr_row_ptr[i + 1] - base; for(int j = row_begin; j < row_end; ++j) { const int col = bsr_col_ind[j] - base; const int idx = bsc_col_ptr[col]; bsc_row_ind[idx] = i + base; for(int k = 0; k < block_shift; ++k) { bsc_val[idx * block_shift + k] = bsr_val[j * block_shift + k]; } ++bsc_col_ptr[col]; } } // Shift column pointer array for(int i = Nb; i > 0; --i) { bsc_col_ptr[i] = bsc_col_ptr[i - 1] + base; } bsc_col_ptr[0] = base; } template inline void host_bsr_to_csr(hipsparseDirection_t direction, int Mb, int Nb, int block_dim, hipsparseIndexBase_t bsr_base, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, const std::vector& bsr_val, hipsparseIndexBase_t csr_base, std::vector& csr_row_ptr, std::vector& csr_col_ind, std::vector& csr_val) { int m = Mb * block_dim; int nnzb = bsr_row_ptr[Mb] - bsr_row_ptr[0]; csr_row_ptr.resize(m + 1, 0); csr_col_ind.resize(nnzb * block_dim * block_dim, 0); csr_val.resize(nnzb * block_dim * block_dim, make_DataType(0)); // quick return if block_dim == 1 if(block_dim == 1) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_row_ptr.size(); i++) { csr_row_ptr[i] = (bsr_row_ptr[i] - bsr_base) + csr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_col_ind.size(); i++) { csr_col_ind[i] = (bsr_col_ind[i] - bsr_base) + csr_base; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(size_t i = 0; i < bsr_val.size(); i++) { csr_val[i] = bsr_val[i]; } return; } csr_row_ptr[0] = csr_base; // find csr row ptr array for(int i = 0; i < Mb; i++) { int entries_in_row = block_dim * (bsr_row_ptr[i + 1] - bsr_row_ptr[i]); for(int j = 0; j < block_dim; j++) { csr_row_ptr[i * block_dim + j + 1] = csr_row_ptr[i * block_dim + j] + entries_in_row; } } int entries_in_block = block_dim * block_dim; // find csr col indices and values arrays #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < Mb; i++) { int entries_in_Row = (bsr_row_ptr[i + 1] - bsr_row_ptr[i]) * block_dim; int entries_in_row_sum = (bsr_row_ptr[i] - bsr_base) * entries_in_block; for(int j = bsr_row_ptr[i] - bsr_base; j < bsr_row_ptr[i + 1] - bsr_base; j++) { int col = bsr_col_ind[j] - bsr_base; int offset = entries_in_row_sum + block_dim * (j - (bsr_row_ptr[i] - bsr_base)); for(int k = 0; k < block_dim; k++) { for(int l = 0; l < block_dim; l++) { csr_col_ind[offset + k * entries_in_Row + l] = block_dim * col + l + csr_base; if(direction == HIPSPARSE_DIRECTION_ROW) { csr_val[offset + k * entries_in_Row + l] = bsr_val[j * entries_in_block + k * block_dim + l]; } else { csr_val[offset + k * entries_in_Row + l] = bsr_val[j * entries_in_block + k + block_dim * l]; } } } } } } template inline void host_bsrmv(hipsparseDirection_t dir, hipsparseOperation_t trans, int mb, int nb, int nnzb, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* x, T beta, T* y, hipsparseIndexBase_t base) { // Quick return if(alpha == make_DataType(0)) { if(beta != make_DataType(1)) { for(int i = 0; i < mb * bsr_dim; ++i) { y[i] = testing_mult(beta, y[i]); } } return; } int WFSIZE; if(bsr_dim == 2) { int blocks_per_row = nnzb / mb; if(blocks_per_row < 8) { WFSIZE = 4; } else if(blocks_per_row < 16) { WFSIZE = 8; } else if(blocks_per_row < 32) { WFSIZE = 16; } else if(blocks_per_row < 64) { WFSIZE = 32; } else { WFSIZE = 64; } } else if(bsr_dim <= 8) { WFSIZE = 8; } else if(bsr_dim <= 16) { WFSIZE = 16; } else { WFSIZE = 32; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int row = 0; row < mb; ++row) { int row_begin = bsr_row_ptr[row] - base; int row_end = bsr_row_ptr[row + 1] - base; if(bsr_dim == 2) { std::vector sum0(WFSIZE, make_DataType(0)); std::vector sum1(WFSIZE, make_DataType(0)); for(int j = row_begin; j < row_end; j += WFSIZE) { for(int k = 0; k < WFSIZE; ++k) { if(j + k < row_end) { int col = bsr_col_ind[j + k] - base; if(dir == HIPSPARSE_DIRECTION_COLUMN) { sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 0], x[col * bsr_dim + 0], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 1], x[col * bsr_dim + 0], sum1[k]); sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 2], x[col * bsr_dim + 1], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 3], x[col * bsr_dim + 1], sum1[k]); } else { sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 0], x[col * bsr_dim + 0], sum0[k]); sum0[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 1], x[col * bsr_dim + 1], sum0[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 2], x[col * bsr_dim + 0], sum1[k]); sum1[k] = testing_fma(bsr_val[bsr_dim * bsr_dim * (j + k) + 3], x[col * bsr_dim + 1], sum1[k]); } } } } for(int j = 1; j < WFSIZE; j <<= 1) { for(int k = 0; k < WFSIZE - j; ++k) { sum0[k] = sum0[k] + sum0[k + j]; sum1[k] = sum1[k] + sum1[k + j]; } } if(beta != make_DataType(0)) { y[row * bsr_dim + 0] = testing_fma(beta, y[row * bsr_dim + 0], testing_mult(alpha, sum0[0])); y[row * bsr_dim + 1] = testing_fma(beta, y[row * bsr_dim + 1], testing_mult(alpha, sum1[0])); } else { y[row * bsr_dim + 0] = testing_mult(alpha, sum0[0]); y[row * bsr_dim + 1] = testing_mult(alpha, sum1[0]); } } else { for(int bi = 0; bi < bsr_dim; ++bi) { std::vector sum(WFSIZE, make_DataType(0)); for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind[j] - base; for(int bj = 0; bj < bsr_dim; bj += WFSIZE) { for(int k = 0; k < WFSIZE; ++k) { if(bj + k < bsr_dim) { if(dir == HIPSPARSE_DIRECTION_COLUMN) { sum[k] = testing_fma( bsr_val[bsr_dim * bsr_dim * j + bsr_dim * (bj + k) + bi], x[bsr_dim * col + (bj + k)], sum[k]); } else { sum[k] = testing_fma( bsr_val[bsr_dim * bsr_dim * j + bsr_dim * bi + (bj + k)], x[bsr_dim * col + (bj + k)], sum[k]); } } } } } for(int j = 1; j < WFSIZE; j <<= 1) { for(int k = 0; k < WFSIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(beta != make_DataType(0)) { y[row * bsr_dim + bi] = testing_fma(beta, y[row * bsr_dim + bi], testing_mult(alpha, sum[0])); } else { y[row * bsr_dim + bi] = testing_mult(alpha, sum[0]); } } } } } template inline void host_csrmv(hipsparseOperation_t trans, J M, J N, I nnz, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T beta, T* y, hipsparseIndexBase_t base) { if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); int WF_SIZE; J nnz_per_row = (M == 0) ? 0 : (nnz / M); if(nnz_per_row < 4) WF_SIZE = 2; else if(nnz_per_row < 8) WF_SIZE = 4; else if(nnz_per_row < 16) WF_SIZE = 8; else if(nnz_per_row < 32) WF_SIZE = 16; else if(nnz_per_row < 64 || prop.warpSize == 32) WF_SIZE = 32; else WF_SIZE = 64; for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; std::vector sum(WF_SIZE, static_cast(0)); for(I j = row_begin; j < row_end; j += WF_SIZE) { for(int k = 0; k < WF_SIZE; ++k) { if(j + k < row_end) { sum[k] = testing_fma(testing_mult(alpha, csr_val[j + k]), x[csr_col_ind[j + k] - base], sum[k]); } } } for(int j = 1; j < WF_SIZE; j <<= 1) { for(int k = 0; k < WF_SIZE - j; ++k) { sum[k] = sum[k] + sum[k + j]; } } if(beta == make_DataType(0.0)) { y[i] = sum[0]; } else { y[i] = testing_fma(beta, y[i], sum[0]); } } } else { // Scale y with beta for(J i = 0; i < N; ++i) { y[i] = testing_mult(y[i], beta); } // Transposed SpMV for(J i = 0; i < M; ++i) { I row_begin = csr_row_ptr[i] - base; I row_end = csr_row_ptr[i + 1] - base; T row_val = testing_mult(alpha, x[i]); for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind[j] - base; T val = (trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) ? testing_conj(csr_val[j]) : csr_val[j]; y[col] = testing_fma(val, row_val, y[col]); } } } } template inline void host_bsrmm(int Mb, int N, int Kb, int block_dim, hipsparseDirection_t dir, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& bsr_row_ptr_A, const std::vector& bsr_col_ind_A, const std::vector& bsr_val_A, const std::vector& B, int ldb, T beta, std::vector& C, int ldc, hipsparseIndexBase_t base) { if(transA != HIPSPARSE_OPERATION_NON_TRANSPOSE) { return; } if(transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && transB != HIPSPARSE_OPERATION_TRANSPOSE) { return; } int M = Mb * block_dim; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; i++) { int local_row = i % block_dim; int row_begin = bsr_row_ptr_A[i / block_dim] - base; int row_end = bsr_row_ptr_A[i / block_dim + 1] - base; for(int j = 0; j < N; j++) { int idx_C = i + j * ldc; T sum = make_DataType(0.0); for(int s = row_begin; s < row_end; s++) { for(int t = 0; t < block_dim; t++) { int idx_A = (dir == HIPSPARSE_DIRECTION_ROW) ? block_dim * block_dim * s + block_dim * local_row + t : block_dim * block_dim * s + block_dim * t + local_row; int idx_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? j * ldb + block_dim * (bsr_col_ind_A[s] - base) + t : (block_dim * (bsr_col_ind_A[s] - base) + t) * ldb + j; sum = sum + testing_mult(alpha, testing_mult(bsr_val_A[idx_A], B[idx_B])); } } if(beta == make_DataType(0.0)) { C[idx_C] = sum; } else { C[idx_C] = sum + testing_mult(beta, C[idx_C]); } } } } template void host_csrmm(J M, J N, J K, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const T* B, J ldb, hipsparseOrder_t orderB, T beta, T* C, J ldc, hipsparseOrder_t orderC, hipsparseIndexBase_t base, bool force_conj_A) { bool conj_A = (transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE || force_conj_A); bool conj_B = (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(J i = 0; i < M; i++) { for(J j = 0; j < N; ++j) { I row_begin = csr_row_ptr_A[i] - base; I row_end = csr_row_ptr_A[i + 1] - base; J idx_C = orderC == HIPSPARSE_ORDER_COL ? i + j * ldc : i * ldc + j; T sum = make_DataType(0); for(I k = row_begin; k < row_end; ++k) { J idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && orderB == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL)) { idx_B = (csr_col_ind_A[k] - base + j * ldb); } else { idx_B = (j + (csr_col_ind_A[k] - base) * ldb); } sum = testing_fma( testing_conj(csr_val_A[k], conj_A), testing_conj(B[idx_B], conj_B), sum); } if(beta == make_DataType(0)) { C[idx_C] = testing_mult(alpha, sum); } else { C[idx_C] = testing_fma(beta, C[idx_C], testing_mult(alpha, sum)); } } } } else { // scale C by beta for(J i = 0; i < K; i++) { for(J j = 0; j < N; ++j) { J idx_C = (orderC == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } for(J i = 0; i < M; i++) { I row_begin = csr_row_ptr_A[i] - base; I row_end = csr_row_ptr_A[i + 1] - base; for(J j = 0; j < N; ++j) { for(I k = row_begin; k < row_end; ++k) { J col = csr_col_ind_A[k] - base; T val = testing_conj(csr_val_A[k], conj_A); J idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && orderB == HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL) || (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE && orderB != HIPSPARSE_ORDER_COL)) { idx_B = (i + j * ldb); } else { idx_B = (j + i * ldb); } J idx_C = (orderC == HIPSPARSE_ORDER_COL) ? col + j * ldc : col * ldc + j; C[idx_C] = C[idx_C] + testing_mult(alpha, testing_mult(val, testing_conj(B[idx_B], conj_B))); } } } } } template void host_csrmm_batched(J M, J N, J K, J batch_count_A, J offsets_batch_stride_A, I columns_values_batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const T* B, J ldb, J batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base, bool force_conj_A) { bool Ci_A_Bi = (batch_count_A == 1 && batch_count_B == batch_count_C); bool Ci_Ai_B = (batch_count_B == 1 && batch_count_A == batch_count_C); bool Ci_Ai_Bi = (batch_count_A == batch_count_C && batch_count_A == batch_count_B); if(!Ci_A_Bi && !Ci_Ai_B && !Ci_Ai_Bi) { return; } if(Ci_A_Bi) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A, csr_col_ind_A, csr_val_A, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } else if(Ci_Ai_B) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A + offsets_batch_stride_A * i, csr_col_ind_A + columns_values_batch_stride_A * i, csr_val_A + columns_values_batch_stride_A * i, B, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } else if(Ci_Ai_Bi) { for(J i = 0; i < batch_count_C; i++) { host_csrmm(M, N, K, transA, transB, alpha, csr_row_ptr_A + offsets_batch_stride_A * i, csr_col_ind_A + columns_values_batch_stride_A * i, csr_val_A + columns_values_batch_stride_A * i, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base, force_conj_A); } } } template void host_cscmm(J M, J N, J K, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csc_col_ptr_A, const J* csc_row_ind_A, const T* csc_val_A, const T* B, J ldb, hipsparseOrder_t order_B, T beta, T* C, J ldc, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { switch(transA) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, false); } case HIPSPARSE_OPERATION_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, false); } case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: { return host_csrmm(K, N, M, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, order_B, beta, C, ldc, order_C, base, true); } } } template void host_cscmm_batched(J M, J N, J K, J batch_count_A, I offsets_batch_stride_A, I rows_values_batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* csc_col_ptr_A, const J* csc_row_ind_A, const T* csc_val_A, const T* B, J ldb, J batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, J ldc, J batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { switch(transA) { case HIPSPARSE_OPERATION_NON_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, false); } case HIPSPARSE_OPERATION_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, false); } case HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE: { return host_csrmm_batched(K, N, M, batch_count_A, offsets_batch_stride_A, rows_values_batch_stride_A, HIPSPARSE_OPERATION_NON_TRANSPOSE, transB, alpha, csc_col_ptr_A, csc_row_ind_A, csc_val_A, B, ldb, batch_count_B, batch_stride_B, order_B, beta, C, ldc, batch_count_C, batch_stride_C, order_C, base, true); } } } template void host_coomm(I M, I N, I K, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* coo_row_ind_A, const I* coo_col_ind_A, const T* coo_val_A, const T* B, I ldb, hipsparseOrder_t order_B, T beta, T* C, I ldc, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { bool conj_A = (transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); bool conj_B = (transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE); if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { for(I j = 0; j < N; j++) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < M; ++i) { I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I j = 0; j < N; j++) { for(I i = 0; i < nnz; ++i) { I row = coo_row_ind_A[i] - base; I col = coo_col_ind_A[i] - base; T val = testing_mult(alpha, coo_val_A[i]); I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? row + j * ldc : row * ldc + j; I idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) || (transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B != HIPSPARSE_ORDER_COL)) { idx_B = (col + j * ldb); } else { idx_B = (j + col * ldb); } C[idx_C] = testing_fma(val, testing_conj(B[idx_B], conj_B), C[idx_C]); } } } else { for(I j = 0; j < N; j++) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I i = 0; i < K; ++i) { I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? i + j * ldc : i * ldc + j; C[idx_C] = testing_mult(beta, C[idx_C]); } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(I j = 0; j < N; j++) { for(I i = 0; i < nnz; ++i) { I row = coo_row_ind_A[i] - base; I col = coo_col_ind_A[i] - base; T val = testing_mult(alpha, testing_conj(coo_val_A[i], conj_A)); I idx_C = (order_C == HIPSPARSE_ORDER_COL) ? col + j * ldc : col * ldc + j; I idx_B = 0; if((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) || (transB != HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B != HIPSPARSE_ORDER_COL)) { idx_B = (row + j * ldb); } else { idx_B = (j + row * ldb); } C[idx_C] = testing_fma(val, testing_conj(B[idx_B], conj_B), C[idx_C]); } } } } template void host_coomm_batched(I M, I N, I K, I nnz, I batch_count_A, I batch_stride_A, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const I* coo_row_ind_A, const I* coo_col_ind_A, const T* coo_val_A, const T* B, I ldb, I batch_count_B, I batch_stride_B, hipsparseOrder_t order_B, T beta, T* C, I ldc, I batch_count_C, I batch_stride_C, hipsparseOrder_t order_C, hipsparseIndexBase_t base) { bool Ci_A_Bi = (batch_count_A == 1 && batch_count_B == batch_count_C); bool Ci_Ai_B = (batch_count_B == 1 && batch_count_A == batch_count_C); bool Ci_Ai_Bi = (batch_count_A == batch_count_C && batch_count_A == batch_count_B); if(!Ci_A_Bi && !Ci_Ai_B && !Ci_Ai_Bi) { return; } if(Ci_A_Bi) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A, coo_col_ind_A, coo_val_A, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } else if(Ci_Ai_B) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A + batch_stride_A * i, coo_col_ind_A + batch_stride_A * i, coo_val_A + batch_stride_A * i, B, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } else if(Ci_Ai_Bi) { for(I i = 0; i < batch_count_C; i++) { host_coomm(M, N, K, nnz, transA, transB, alpha, coo_row_ind_A + batch_stride_A * i, coo_col_ind_A + batch_stride_A * i, coo_val_A + batch_stride_A * i, B + batch_stride_B * i, ldb, order_B, beta, C + batch_stride_C * i, ldc, order_C, base); } } } template int csrilu0(int m, const int* ptr, const int* col, T* val, hipsparseIndexBase_t idx_base, bool boost, double boost_tol, T boost_val) { // pointer of upper part of each row std::vector diag_offset(m); std::vector nnz_entries(m, 0); // ai = 0 to N loop over all rows for(int ai = 0; ai < m; ++ai) { // ai-th row entries int row_start = ptr[ai] - idx_base; int row_end = ptr[ai + 1] - idx_base; int j; // nnz position of ai-th row in val array for(j = row_start; j < row_end; ++j) { nnz_entries[col[j] - idx_base] = j; } bool has_diag = false; // loop over ai-th row nnz entries for(j = row_start; j < row_end; ++j) { // if nnz entry is in lower matrix if(col[j] - idx_base < ai) { int col_j = col[j] - idx_base; int diag_j = diag_offset[col_j]; T diag_val = val[diag_j]; if(boost) { diag_val = (boost_tol >= testing_abs(diag_val)) ? boost_val : diag_val; val[diag_j] = diag_val; } else { // Check for numeric pivot if(diag_val == make_DataType(0.0)) { // Numerical zero diagonal return col_j + idx_base; } } // multiplication factor val[j] = testing_div(val[j], diag_val); // loop over upper offset pointer and do linear combination for nnz entry for(int k = diag_j + 1; k < ptr[col_j + 1] - idx_base; ++k) { // if nnz at this position do linear combination if(nnz_entries[col[k] - idx_base] != 0) { int idx = nnz_entries[col[k] - idx_base]; val[idx] = testing_fma(testing_neg(val[j]), val[k], val[idx]); } } } else if(col[j] - idx_base == ai) { has_diag = true; break; } else { break; } } if(!has_diag) { // Structural zero digonal return ai + idx_base; } // set diagonal pointer to diagonal element diag_offset[ai] = j; // clear nnz entries for(j = row_start; j < row_end; ++j) { nnz_entries[col[j] - idx_base] = 0; } } return -1; } template inline void host_bsrilu02(hipsparseDirection_t dir, int mb, int bsr_dim, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, std::vector& bsr_val, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot, bool boost, double boost_tol, T boost_val) { // Initialize pivots *struct_pivot = mb + 1; *numeric_pivot = mb + 1; // Temporary vector to hold diagonal offset to access diagonal BSR block std::vector diag_offset(mb); std::vector nnz_entries(mb, -1); // First diagonal block is index 0 if(mb > 0) { diag_offset[0] = 0; } // Loop over all BSR rows for(int i = 0; i < mb; ++i) { // Flag whether we have a diagonal block or not bool has_diag = false; // BSR column entry and exit point int row_begin = bsr_row_ptr[i] - base; int row_end = bsr_row_ptr[i + 1] - base; int j; // Set up entry points for linear combination for(j = row_begin; j < row_end; ++j) { int col_j = bsr_col_ind[j] - base; nnz_entries[col_j] = j; } // Process lower diagonal BSR blocks (diagonal BSR block is excluded) for(j = row_begin; j < row_end; ++j) { // Column index of current BSR block int bsr_col = bsr_col_ind[j] - base; // If this is a diagonal block, set diagonal flag to true and skip // all upcoming blocks as we exceed the lower matrix part if(bsr_col == i) { has_diag = true; break; } // Skip all upper matrix blocks if(bsr_col > i) { break; } // Process all lower matrix BSR blocks // Obtain corresponding row entry and exit point that corresponds with the // current BSR column. Actually, we skip all lower matrix column indices, // therefore starting with the diagonal entry. int diag_j = diag_offset[bsr_col]; int row_end_j = bsr_row_ptr[bsr_col + 1] - base; // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { T diag = bsr_val[BSR_IND(diag_j, bi, bi, dir)]; // Process all rows within the BSR block for(int bk = 0; bk < bsr_dim; ++bk) { T val = bsr_val[BSR_IND(j, bk, bi, dir)]; // Multiplication factor bsr_val[BSR_IND(j, bk, bi, dir)] = val = testing_div(val, diag); // Loop through columns of bk-th row and do linear combination for(int bj = bi + 1; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-val, bsr_val[BSR_IND(diag_j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } // Loop over upper offset pointer and do linear combination for nnz entry for(int k = diag_j + 1; k < row_end_j; ++k) { int bsr_col_k = bsr_col_ind[k] - base; if(nnz_entries[bsr_col_k] != -1) { int m = nnz_entries[bsr_col_k]; // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { // Loop through columns of bi-th row and do linear combination for(int bj = 0; bj < bsr_dim; ++bj) { T sum = make_DataType(0); for(int bk = 0; bk < bsr_dim; ++bk) { sum = testing_fma(bsr_val[BSR_IND(j, bi, bk, dir)], bsr_val[BSR_IND(k, bk, bj, dir)], sum); } bsr_val[BSR_IND(m, bi, bj, dir)] = bsr_val[BSR_IND(m, bi, bj, dir)] - sum; } } } } } // Check for structural pivot if(!has_diag) { *struct_pivot = std::min(*struct_pivot, i + base); break; } // Process diagonal if(bsr_col_ind[j] - base == i) { // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { T diag = bsr_val[BSR_IND(j, bi, bi, dir)]; if(boost) { diag = (boost_tol >= testing_abs(diag)) ? boost_val : diag; bsr_val[BSR_IND(j, bi, bi, dir)] = diag; } else { // Check for numeric pivot if(diag == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, bsr_col_ind[j]); continue; } } // Process all rows within the BSR block after bi-th row for(int bk = bi + 1; bk < bsr_dim; ++bk) { T val = bsr_val[BSR_IND(j, bk, bi, dir)]; // Multiplication factor bsr_val[BSR_IND(j, bk, bi, dir)] = val = testing_div(val, diag); // Loop through remaining columns of bk-th row and do linear combination for(int bj = bi + 1; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-val, bsr_val[BSR_IND(j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } } // Store diagonal BSR block entry point int row_diag = diag_offset[i] = j; // Process upper diagonal BSR blocks for(j = row_diag + 1; j < row_end; ++j) { // Loop through all rows within the BSR block for(int bi = 0; bi < bsr_dim; ++bi) { // Process all rows within the BSR block after bi-th row for(int bk = bi + 1; bk < bsr_dim; ++bk) { // Loop through columns of bk-th row and do linear combination for(int bj = 0; bj < bsr_dim; ++bj) { bsr_val[BSR_IND(j, bk, bj, dir)] = testing_fma(-bsr_val[BSR_IND(row_diag, bk, bi, dir)], bsr_val[BSR_IND(j, bi, bj, dir)], bsr_val[BSR_IND(j, bk, bj, dir)]); } } } } // Reset entry points for(j = row_begin; j < row_end; ++j) { int col_j = bsr_col_ind[j] - base; nnz_entries[col_j] = -1; } } *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } template inline void host_bsric02(hipsparseDirection_t direction, int Mb, int block_dim, const std::vector& bsr_row_ptr, const std::vector& bsr_col_ind, std::vector& bsr_val, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { int M = Mb * block_dim; // Initialize pivot *struct_pivot = -1; *numeric_pivot = -1; if(bsr_col_ind.size() == 0 && bsr_val.size() == 0) { return; } // pointer of upper part of each row std::vector diag_block_offset(Mb); std::vector diag_offset(M, -1); std::vector nnz_entries(M, -1); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < Mb; i++) { int row_begin = bsr_row_ptr[i] - base; int row_end = bsr_row_ptr[i + 1] - base; for(int j = row_begin; j < row_end; j++) { if(bsr_col_ind[j] - base == i) { diag_block_offset[i] = j; break; } } } for(int i = 0; i < M; i++) { int local_row = i % block_dim; int row_begin = bsr_row_ptr[i / block_dim] - base; int row_end = bsr_row_ptr[i / block_dim + 1] - base; for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { if(direction == HIPSPARSE_DIRECTION_ROW) { nnz_entries[block_dim * block_col_j + k] = block_dim * block_dim * j + block_dim * local_row + k; } else { nnz_entries[block_dim * block_col_j + k] = block_dim * block_dim * j + block_dim * k + local_row; } } } T sum = make_DataType(0); int diag_val_index = -1; bool has_diag = false; bool break_outer_loop = false; for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { int col_j = block_dim * block_col_j + k; // Mark diagonal and skip row if(col_j == i) { diag_val_index = block_dim * block_dim * j + block_dim * k + k; has_diag = true; break_outer_loop = true; break; } // Skip upper triangular if(col_j > i) { break_outer_loop = true; break; } T val_j; if(direction == HIPSPARSE_DIRECTION_ROW) { val_j = bsr_val[block_dim * block_dim * j + block_dim * local_row + k]; } else { val_j = bsr_val[block_dim * block_dim * j + block_dim * k + local_row]; } int local_row_j = col_j % block_dim; int row_begin_j = bsr_row_ptr[col_j / block_dim] - base; int row_end_j = diag_block_offset[col_j / block_dim]; int row_diag_j = diag_offset[col_j]; T local_sum = make_DataType(0); T inv_diag = row_diag_j != -1 ? bsr_val[row_diag_j] : make_DataType(0); // Check for numeric zero if(inv_diag == make_DataType(0)) { // Numerical non-invertible block diagonal if(*numeric_pivot == -1) { *numeric_pivot = block_col_j + base; } *numeric_pivot = std::min(*numeric_pivot, block_col_j + base); inv_diag = make_DataType(1); } inv_diag = testing_div(make_DataType(1), inv_diag); // loop over upper offset pointer and do linear combination for nnz entry for(int l = row_begin_j; l < row_end_j + 1; l++) { int block_col_l = bsr_col_ind[l] - base; for(int m = 0; m < block_dim; m++) { int idx = nnz_entries[block_dim * block_col_l + m]; if(idx != -1 && block_dim * block_col_l + m < col_j) { if(direction == HIPSPARSE_DIRECTION_ROW) { local_sum = testing_fma(bsr_val[block_dim * block_dim * l + block_dim * local_row_j + m], testing_conj(bsr_val[idx]), local_sum); } else { local_sum = testing_fma(bsr_val[block_dim * block_dim * l + block_dim * m + local_row_j], testing_conj(bsr_val[idx]), local_sum); } } } } val_j = testing_mult((val_j - local_sum), inv_diag); sum = testing_fma(val_j, testing_conj(val_j), sum); if(direction == HIPSPARSE_DIRECTION_ROW) { bsr_val[block_dim * block_dim * j + block_dim * local_row + k] = val_j; } else { bsr_val[block_dim * block_dim * j + block_dim * k + local_row] = val_j; } } if(break_outer_loop) { break; } } if(!has_diag) { // Structural missing block diagonal if(*struct_pivot == -1) { *struct_pivot = i / block_dim + base; } } // Process diagonal entry if(has_diag) { T diag_entry = make_DataType(std::sqrt(testing_abs(bsr_val[diag_val_index] - sum))); bsr_val[diag_val_index] = diag_entry; if(diag_entry == make_DataType(0)) { // Numerical non-invertible block diagonal if(*numeric_pivot == -1) { *numeric_pivot = i / block_dim + base; } *numeric_pivot = std::min(*numeric_pivot, i / block_dim + base); } // Store diagonal offset diag_offset[i] = diag_val_index; } for(int j = row_begin; j < row_end; j++) { int block_col_j = bsr_col_ind[j] - base; for(int k = 0; k < block_dim; k++) { if(direction == HIPSPARSE_DIRECTION_ROW) { nnz_entries[block_dim * block_col_j + k] = -1; } else { nnz_entries[block_dim * block_col_j + k] = -1; } } } } } template void csric0(int M, const int* csr_row_ptr, const int* csr_col_ind, T* csr_val, hipsparseIndexBase_t idx_base, int& struct_pivot, int& numeric_pivot) { // Initialize pivot struct_pivot = -1; numeric_pivot = -1; // pointer of upper part of each row std::vector diag_offset(M); std::vector nnz_entries(M, 0); // ai = 0 to N loop over all rows for(int ai = 0; ai < M; ++ai) { // ai-th row entries int row_begin = csr_row_ptr[ai] - idx_base; int row_end = csr_row_ptr[ai + 1] - idx_base; int j; // nnz position of ai-th row in val array for(j = row_begin; j < row_end; ++j) { nnz_entries[csr_col_ind[j] - idx_base] = j; } T sum = make_DataType(0.0); bool has_diag = false; // loop over ai-th row nnz entries for(j = row_begin; j < row_end; ++j) { int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; // Mark diagonal and skip row if(col_j == ai) { has_diag = true; break; } // Skip upper triangular if(col_j > ai) { break; } int row_begin_j = csr_row_ptr[col_j] - idx_base; int row_diag_j = diag_offset[col_j]; T local_sum = make_DataType(0.0); T inv_diag = csr_val[row_diag_j]; // Check for numeric zero if(inv_diag == make_DataType(0.0)) { // Numerical zero diagonal numeric_pivot = col_j + idx_base; return; } inv_diag = testing_div(make_DataType(1.0), inv_diag); // loop over upper offset pointer and do linear combination for nnz entry for(int k = row_begin_j; k < row_diag_j; ++k) { int col_k = csr_col_ind[k] - idx_base; // if nnz at this position do linear combination if(nnz_entries[col_k] != 0) { int idx = nnz_entries[col_k]; local_sum = testing_fma(csr_val[k], testing_conj(csr_val[idx]), local_sum); } } val_j = testing_mult((val_j - local_sum), inv_diag); sum = testing_fma(val_j, testing_conj(val_j), sum); csr_val[j] = val_j; } if(!has_diag) { // Structural (and numerical) zero diagonal struct_pivot = ai + idx_base; numeric_pivot = ai + idx_base; return; } // Process diagonal entry T diag_entry = make_DataType(std::sqrt(testing_abs(csr_val[j] - sum))); csr_val[j] = diag_entry; // Store diagonal offset diag_offset[ai] = j; // clear nnz entries for(j = row_begin; j < row_end; ++j) { nnz_entries[csr_col_ind[j] - idx_base] = 0; } } } /* ============================================================================================ */ /*! \brief Sparse triangular system solve using CSR storage format. */ template static inline void host_lssolve(J M, J nrhs, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); #ifdef _OPENMP #pragma omp parallel for #endif for(J i = 0; i < nrhs; ++i) { std::vector temp(prop.warpSize); // Process lower triangular part for(J row = 0; row < M; ++row) { temp.assign(prop.warpSize, make_DataType(0.0)); J idx_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + row : row * ldb + i; if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[0] = testing_mult(alpha, testing_conj(B[idx_B])); } else { temp[0] = testing_mult(alpha, B[idx_B]); } I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_begin; l < row_end; l += prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l + k; // Do not run out of bounds if(j >= row_end) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; if(local_val == make_DataType(0.0) && local_col == row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 and store // index for later use *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1.0); } // Ignore all entries that are above the diagonal if(local_col > row) { break; } // Diagonal entry if(local_col == row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1.0), local_val); } break; } // Lower triangular part J idx = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + local_col : local_col * ldb + i; T neg_val = testing_mult(make_DataType(-1.0), local_val); if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[k] = testing_fma(neg_val, testing_conj(B[idx]), temp[k]); } else { temp[k] = testing_fma(neg_val, B[idx], temp[k]); } } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } B[idx_B] = testing_mult(temp[0], diag_val); } else { B[idx_B] = temp[0]; } } } } template static inline void host_ussolve(J M, J nrhs, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); #ifdef _OPENMP #pragma omp parallel for #endif for(J i = 0; i < nrhs; ++i) { std::vector temp(prop.warpSize); // Process upper triangular part for(J row = M - 1; row >= 0; --row) { temp.assign(prop.warpSize, make_DataType(0.0)); J idx_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + row : row * ldb + i; if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[0] = testing_mult(alpha, testing_conj(B[idx_B])); } else { temp[0] = testing_mult(alpha, B[idx_B]); } I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_end - 1; l >= row_begin; l -= prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l - k; // Do not run out of bounds if(j < row_begin) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; // Ignore all entries that are below the diagonal if(local_col < row) { continue; } // Diagonal entry if(local_col == row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0.0)) { *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), local_val); } continue; } // Upper triangular part J idx = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE && order_B == HIPSPARSE_ORDER_COL) ? i * ldb + local_col : local_col * ldb + i; T neg_val = testing_mult(make_DataType(-1.0), local_val); if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { temp[k] = testing_fma(neg_val, testing_conj(B[idx]), temp[k]); } else { temp[k] = testing_fma(neg_val, B[idx], temp[k]); } } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } B[idx_B] = testing_mult(temp[0], diag_val); } else { B[idx_B] = temp[0]; } } } } template void host_bsrsm(int mb, int nrhs, int nnzb, hipsparseDirection_t dir, hipsparseOperation_t transA, hipsparseOperation_t transX, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { // Initialize pivot *struct_pivot = mb + 1; *numeric_pivot = mb + 1; if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_lsolve(dir, transX, mb, nrhs, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_usolve(dir, transX, mb, nrhs, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } } else if(transA == HIPSPARSE_OPERATION_TRANSPOSE) { // Transpose matrix std::vector bsrt_row_ptr(mb + 1); std::vector bsrt_col_ind(nnzb); std::vector bsrt_val(nnzb * bsr_dim * bsr_dim); host_bsr_to_bsc(mb, mb, nnzb, bsr_dim, bsr_row_ptr, bsr_col_ind, bsr_val, bsrt_col_ind, bsrt_row_ptr, bsrt_val, base, base); if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_usolve(dir, transX, mb, nrhs, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_lsolve(dir, transX, mb, nrhs, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, B, ldb, X, ldx, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } template void host_csr_lsolve(J M, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); std::vector temp(prop.warpSize); // Process lower triangular part for(J row = 0; row < M; ++row) { temp.assign(prop.warpSize, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[row]); I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0.0); for(I l = row_begin; l < row_end; l += prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l + k; // Do not run out of bounds if(j >= row_end) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; if(local_val == make_DataType(0.0) && local_col == row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 // and store index for later use. *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1); } // Ignore all entries that are above the diagonal if(local_col > row) { break; } // Diagonal entry if(local_col == row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1), local_val); } break; } // Lower triangular part temp[k] = testing_fma(-local_val, y[local_col], temp[k]); } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } y[row] = testing_mult(temp[0], diag_val); } else { y[row] = temp[0]; } } } template void host_csr_usolve(J M, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Get device properties int dev; hipDeviceProp_t prop; std::ignore = hipGetDevice(&dev); std::ignore = hipGetDeviceProperties(&prop, dev); std::vector temp(prop.warpSize); // Process upper triangular part for(J row = M - 1; row >= 0; --row) { temp.assign(prop.warpSize, make_DataType(0)); temp[0] = testing_mult(alpha, x[row]); I diag = -1; I row_begin = csr_row_ptr[row] - base; I row_end = csr_row_ptr[row + 1] - base; T diag_val = make_DataType(0); for(I l = row_end - 1; l >= row_begin; l -= prop.warpSize) { for(int k = 0; k < prop.warpSize; ++k) { I j = l - k; // Do not run out of bounds if(j < row_begin) { break; } J local_col = csr_col_ind[j] - base; T local_val = csr_val[j]; // Ignore all entries that are below the diagonal if(local_col < row) { continue; } // Diagonal entry if(local_col == row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, row + base); local_val = make_DataType(1); } diag = j; diag_val = testing_div(make_DataType(1), local_val); } continue; } // Upper triangular part temp[k] = testing_fma(-local_val, y[local_col], temp[k]); } } for(int j = 1; j < prop.warpSize; j <<= 1) { for(int k = 0; k < prop.warpSize - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, row + base); } y[row] = testing_mult(temp[0], diag_val); } else { y[row] = temp[0]; } } } template void host_csrsv(hipsparseOperation_t trans, J M, I nnz, T alpha, const I* csr_row_ptr, const J* csr_col_ind, const T* csr_val, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Initialize pivot *struct_pivot = M + 1; *numeric_pivot = M + 1; if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_csr_lsolve(M, alpha, csr_row_ptr, csr_col_ind, csr_val, x, y, diag_type, base, struct_pivot, numeric_pivot); } else { host_csr_usolve(M, alpha, csr_row_ptr, csr_col_ind, csr_val, x, y, diag_type, base, struct_pivot, numeric_pivot); } } else if(trans == HIPSPARSE_OPERATION_TRANSPOSE || trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { // Transpose matrix std::vector csrt_row_ptr(M + 1); std::vector csrt_col_ind(nnz); std::vector csrt_val(nnz); host_csr_to_csc(M, M, nnz, csr_row_ptr, csr_col_ind, csr_val, csrt_col_ind, csrt_row_ptr, csrt_val, HIPSPARSE_ACTION_NUMERIC, base); if(trans == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { for(size_t i = 0; i < csrt_val.size(); i++) { csrt_val[i] = testing_conj(csrt_val[i]); } } if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_csr_usolve(M, alpha, csrt_row_ptr.data(), csrt_col_ind.data(), csrt_val.data(), x, y, diag_type, base, struct_pivot, numeric_pivot); } else { host_csr_lsolve(M, alpha, csrt_row_ptr.data(), csrt_col_ind.data(), csrt_val.data(), x, y, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == M + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == M + 1) ? -1 : *numeric_pivot; } template void host_coosv(hipsparseOperation_t trans, I M, I nnz, T alpha, const std::vector& coo_row_ind, const std::vector& coo_col_ind, const std::vector& coo_val, const std::vector& x, std::vector& y, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, I* struct_pivot, I* numeric_pivot) { std::vector csr_row_ptr(M + 1); //host_coo_to_csr(M, coo_row_ind, csr_row_ptr, base); // coo2csr on host for(I i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - base]; } csr_row_ptr[0] = base; for(I i = 0; i < M; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } host_csrsv(trans, M, nnz, alpha, csr_row_ptr.data(), coo_col_ind.data(), coo_val.data(), x.data(), y.data(), diag_type, fill_mode, base, struct_pivot, numeric_pivot); } template void host_csrsm2(J M, J nrhs, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, std::vector& B, J ldb, hipsparseOrder_t order_B, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { // Initialize pivot *struct_pivot = M + 1; *numeric_pivot = M + 1; if(transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_lssolve(M, nrhs, transB, alpha, csr_row_ptr, csr_col_ind, csr_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } else { host_ussolve(M, nrhs, transB, alpha, csr_row_ptr, csr_col_ind, csr_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } } else if(transA == HIPSPARSE_OPERATION_TRANSPOSE || transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { // Transpose matrix std::vector csrt_row_ptr(M + 1); std::vector csrt_col_ind(nnz); std::vector csrt_val(nnz); host_csr_to_csc(M, M, nnz, csr_row_ptr.data(), csr_col_ind.data(), csr_val.data(), csrt_col_ind, csrt_row_ptr, csrt_val, HIPSPARSE_ACTION_NUMERIC, base); if(transA == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { for(size_t i = 0; i < csrt_val.size(); i++) { csrt_val[i] = testing_conj(csrt_val[i]); } } if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { host_ussolve(M, nrhs, transB, alpha, csrt_row_ptr, csrt_col_ind, csrt_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } else { host_lssolve(M, nrhs, transB, alpha, csrt_row_ptr, csrt_col_ind, csrt_val, B, ldb, order_B, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == M + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == M + 1) ? -1 : *numeric_pivot; } template void host_csrsm(J M, J nrhs, I nnz, hipsparseOperation_t trans_A, hipsparseOperation_t trans_B, T alpha, const std::vector& csr_row_ptr, const std::vector& csr_col_ind, const std::vector& csr_val, const std::vector& B, J ldb, hipsparseOrder_t order_B, std::vector& C, J ldc, hipsparseOrder_t order_C, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, J* struct_pivot, J* numeric_pivot) { J B_m = (trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? M : nrhs; J B_n = (trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : M; J C_m = M; J C_n = nrhs; // Copy B to C if(order_B == HIPSPARSE_ORDER_COL) { if(trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } } } else { if(trans_B == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } else { for(J j = 0; j < B_n; j++) { for(J i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } } } if(trans_B == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(J j = 0; j < C_n; j++) { for(J i = 0; i < C_m; i++) { C[i + ldc * j] = testing_conj(C[i + ldc * j]); } } } else { for(J i = 0; i < C_m; i++) { for(J j = 0; j < C_n; j++) { C[ldc * i + j] = testing_conj(C[ldc * i + j]); } } } } hipsparseOperation_t trans_C = HIPSPARSE_OPERATION_NON_TRANSPOSE; host_csrsm2(M, nrhs, nnz, trans_A, trans_C, alpha, csr_row_ptr, csr_col_ind, csr_val, C, ldc, order_C, diag_type, fill_mode, base, struct_pivot, numeric_pivot); } template void host_coosm(I M, I nrhs, I nnz, hipsparseOperation_t transA, hipsparseOperation_t transB, T alpha, const std::vector& coo_row_ind, const std::vector& coo_col_ind, const std::vector& coo_val, const std::vector& B, I ldb, hipsparseOrder_t order_B, std::vector& C, I ldc, hipsparseOrder_t order_C, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, I* struct_pivot, I* numeric_pivot) { I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? M : nrhs; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : M; I C_m = M; I C_n = nrhs; // Copy B to C if(order_B == HIPSPARSE_ORDER_COL) { if(transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[i + ldb * j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[i + ldb * j]; } } } } } else { if(transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } } else { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i * ldc + j] = B[ldb * i + j]; } } } else { for(I j = 0; j < B_n; j++) { for(I i = 0; i < B_m; i++) { C[i + ldc * j] = B[ldb * i + j]; } } } } } if(transB == HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE) { if(order_C == HIPSPARSE_ORDER_COL) { for(I j = 0; j < C_n; j++) { for(I i = 0; i < C_m; i++) { C[i + ldc * j] = testing_conj(C[i + ldc * j]); } } } else { for(I i = 0; i < C_m; i++) { for(I j = 0; j < C_n; j++) { C[ldc * i + j] = testing_conj(C[ldc * i + j]); } } } } hipsparseOperation_t transC = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::vector csr_row_ptr(M + 1); //host_coo_to_csr(M, coo_row_ind, csr_row_ptr, base); // coo2csr on host for(I i = 0; i < nnz; ++i) { ++csr_row_ptr[coo_row_ind[i] + 1 - base]; } csr_row_ptr[0] = base; for(I i = 0; i < M; ++i) { csr_row_ptr[i + 1] += csr_row_ptr[i]; } host_csrsm2(M, nrhs, nnz, transA, transC, alpha, csr_row_ptr, coo_col_ind, coo_val, C, ldc, order_C, diag_type, fill_mode, base, struct_pivot, numeric_pivot); } /* ============================================================================================ */ /*! \brief Sparse triangular lower solve using BSR storage format. */ template void bsr_lsolve(hipsparseDirection_t dir, hipsparseOperation_t trans_X, int mb, int nrhs, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { #ifdef _OPENMP #pragma omp parallel for #endif for(int i = 0; i < nrhs; ++i) { // Process lower triangular part for(int bsr_row = 0; bsr_row < mb; ++bsr_row) { int bsr_row_begin = bsr_row_ptr[bsr_row] - base; int bsr_row_end = bsr_row_ptr[bsr_row + 1] - base; // Loop over blocks rows for(int bi = 0; bi < bsr_dim; ++bi) { int diag = -1; int local_row = bsr_row * bsr_dim + bi; int idx_B = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldb + local_row : local_row * ldb + i; int idx_X = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_row : local_row * ldx + i; T sum = testing_mult(alpha, B[idx_B]); T diag_val = make_DataType(0); // Loop over BSR columns for(int j = bsr_row_begin; j < bsr_row_end; ++j) { int bsr_col = bsr_col_ind[j] - base; // Loop over blocks columns for(int bj = 0; bj < bsr_dim; ++bj) { int local_col = bsr_col * bsr_dim + bj; T local_val = (dir == HIPSPARSE_DIRECTION_ROW) ? bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj] : bsr_val[bsr_dim * bsr_dim * j + bi + bj * bsr_dim]; if(local_val == make_DataType(0) && local_col == local_row && diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Numerical zero pivot found, avoid division by 0 // and store index for later use. *numeric_pivot = std::min(*numeric_pivot, bsr_row + base); local_val = make_DataType(1); } // Ignore all entries that are above the diagonal if(local_col > local_row) { break; } // Diagonal if(local_col == local_row) { // If diagonal type is non unit, do division by diagonal entry // This is not required for unit diagonal for obvious reasons if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { diag = j; diag_val = testing_div(make_DataType(1), local_val); } break; } // Lower triangular part int idx = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_col : local_col * ldx + i; sum = testing_fma(-local_val, X[idx], sum); } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, bsr_row + base); } X[idx_X] = testing_mult(sum, diag_val); } else { X[idx_X] = sum; } } } } } /* ============================================================================================ */ /*! \brief Sparse triangular upper solve using BSR storage format. */ template void bsr_usolve(hipsparseDirection_t dir, hipsparseOperation_t trans_X, int mb, int nrhs, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* B, int ldb, T* X, int ldx, hipsparseDiagType_t diag_type, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { #ifdef _OPENMP #pragma omp parallel for #endif for(int i = 0; i < nrhs; ++i) { // Process upper triangular part for(int bsr_row = mb - 1; bsr_row >= 0; --bsr_row) { int bsr_row_begin = bsr_row_ptr[bsr_row] - base; int bsr_row_end = bsr_row_ptr[bsr_row + 1] - base; for(int bi = bsr_dim - 1; bi >= 0; --bi) { int local_row = bsr_row * bsr_dim + bi; int idx_B = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldb + local_row : local_row * ldb + i; int idx_X = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_row : local_row * ldx + i; T sum = testing_mult(alpha, B[idx_B]); int diag = -1; T diag_val = make_DataType(0); for(int j = bsr_row_end - 1; j >= bsr_row_begin; --j) { int bsr_col = bsr_col_ind[j] - base; for(int bj = bsr_dim - 1; bj >= 0; --bj) { int local_col = bsr_col * bsr_dim + bj; T local_val = dir == HIPSPARSE_DIRECTION_ROW ? bsr_val[bsr_dim * bsr_dim * j + bi * bsr_dim + bj] : bsr_val[bsr_dim * bsr_dim * j + bi + bj * bsr_dim]; // Ignore all entries that are below the diagonal if(local_col < local_row) { continue; } // Diagonal if(local_col == local_row) { if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(local_val == make_DataType(0)) { *numeric_pivot = std::min(*numeric_pivot, bsr_row + base); local_val = make_DataType(1); } diag = j; diag_val = testing_div(make_DataType(1), local_val); } continue; } // Upper triangular part int idx = (trans_X == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? i * ldx + local_col : local_col * ldx + i; sum = testing_fma(-local_val, X[idx], sum); } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { *struct_pivot = std::min(*struct_pivot, bsr_row + base); } X[idx_X] = testing_mult(sum, diag_val); } else { X[idx_X] = sum; } } } } } template void bsrsv(hipsparseOperation_t trans, hipsparseDirection_t dir, int mb, int nnzb, T alpha, const int* bsr_row_ptr, const int* bsr_col_ind, const T* bsr_val, int bsr_dim, const T* x, T* y, hipsparseDiagType_t diag_type, hipsparseFillMode_t fill_mode, hipsparseIndexBase_t base, int* struct_pivot, int* numeric_pivot) { // Initialize pivot *struct_pivot = mb + 1; *numeric_pivot = mb + 1; if(trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) { if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_lsolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_usolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } } else if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { // Transpose matrix std::vector bsrt_row_ptr; std::vector bsrt_col_ind; std::vector bsrt_val; host_bsr_to_bsc(mb, mb, nnzb, bsr_dim, bsr_row_ptr, bsr_col_ind, bsr_val, bsrt_col_ind, bsrt_row_ptr, bsrt_val, base, base); if(fill_mode == HIPSPARSE_FILL_MODE_LOWER) { bsr_usolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } else { bsr_lsolve(dir, HIPSPARSE_OPERATION_NON_TRANSPOSE, mb, 1, alpha, bsrt_row_ptr.data(), bsrt_col_ind.data(), bsrt_val.data(), bsr_dim, x, mb * bsr_dim, y, mb * bsr_dim, diag_type, base, struct_pivot, numeric_pivot); } } *numeric_pivot = std::min(*numeric_pivot, *struct_pivot); *struct_pivot = (*struct_pivot == mb + 1) ? -1 : *struct_pivot; *numeric_pivot = (*numeric_pivot == mb + 1) ? -1 : *numeric_pivot; } /* ============================================================================================ */ /*! \brief Sparse triangular lower solve using CSR storage format. */ template int csr_lsolve(hipsparseOperation_t trans, int m, const int* ptr, const int* col, const T* val, T alpha, const T* x, T* y, hipsparseIndexBase_t idx_base, hipsparseDiagType_t diag_type, unsigned int wf_size) { const int* csr_row_ptr = ptr; const int* csr_col_ind = col; const T* csr_val = val; std::vector vptr; std::vector vcol; std::vector vval; if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { int nnz = ptr[m] - idx_base; vptr.resize(m + 1); vcol.resize(nnz); vval.resize(nnz); // Transpose transpose_csr( m, m, nnz, ptr, col, val, vptr.data(), vcol.data(), vval.data(), idx_base, idx_base); csr_row_ptr = vptr.data(); csr_col_ind = vcol.data(); csr_val = vval.data(); } int pivot = (std::numeric_limits::max)(); std::vector temp(wf_size); for(int i = 0; i < m; ++i) { temp.assign(wf_size, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[i]); int diag = -1; int row_begin = csr_row_ptr[i] - idx_base; int row_end = csr_row_ptr[i + 1] - idx_base; T diag_val = make_DataType(0.0); for(int l = row_begin; l < row_end; l += wf_size) { for(unsigned int k = 0; k < wf_size; ++k) { int j = l + k; // Do not run out of bounds if(j >= row_end) { break; } int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; if(col_j < i) { // Lower part temp[k] = testing_fma(-csr_val[j], y[col_j], temp[k]); } else if(col_j == i) { // Diagonal if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(val_j == make_DataType(0.0)) { pivot = std::min(pivot, i + idx_base); val_j = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), val_j); } break; } else { // Upper part break; } } } for(unsigned int j = 1; j < wf_size; j <<= 1) { for(unsigned int k = 0; k < wf_size - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { pivot = std::min(pivot, i + idx_base); } y[i] = testing_mult(temp[0], diag_val); } else { y[i] = temp[0]; } } if(pivot != (std::numeric_limits::max)()) { return pivot; } return -1; } /* ============================================================================================ */ /*! \brief Sparse triangular upper solve using CSR storage format. */ template int csr_usolve(hipsparseOperation_t trans, int m, const int* ptr, const int* col, const T* val, T alpha, const T* x, T* y, hipsparseIndexBase_t idx_base, hipsparseDiagType_t diag_type, unsigned int wf_size) { const int* csr_row_ptr = ptr; const int* csr_col_ind = col; const T* csr_val = val; std::vector vptr; std::vector vcol; std::vector vval; if(trans == HIPSPARSE_OPERATION_TRANSPOSE) { int nnz = ptr[m] - idx_base; vptr.resize(m + 1); vcol.resize(nnz); vval.resize(nnz); // Transpose transpose_csr( m, m, nnz, ptr, col, val, vptr.data(), vcol.data(), vval.data(), idx_base, idx_base); csr_row_ptr = vptr.data(); csr_col_ind = vcol.data(); csr_val = vval.data(); } int pivot = (std::numeric_limits::max)(); std::vector temp(wf_size); for(int i = m - 1; i >= 0; --i) { temp.assign(wf_size, make_DataType(0.0)); temp[0] = testing_mult(alpha, x[i]); int diag = -1; int row_begin = csr_row_ptr[i] - idx_base; int row_end = csr_row_ptr[i + 1] - idx_base; T diag_val = make_DataType(0.0); for(int l = row_end - 1; l >= row_begin; l -= wf_size) { for(unsigned int k = 0; k < wf_size; ++k) { int j = l - k; // Do not run out of bounds if(j < row_begin) { break; } int col_j = csr_col_ind[j] - idx_base; T val_j = csr_val[j]; if(col_j < i) { // Lower part continue; } else if(col_j == i) { // Diagonal if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { // Check for numerical zero if(val_j == make_DataType(0.0)) { pivot = std::min(pivot, i + idx_base); val_j = make_DataType(1.0); } diag = j; diag_val = testing_div(make_DataType(1.0), val_j); } continue; } else { // Upper part temp[k] = testing_fma(-csr_val[j], y[col_j], temp[k]); } } } for(unsigned int j = 1; j < wf_size; j <<= 1) { for(unsigned int k = 0; k < wf_size - j; ++k) { temp[k] = temp[k] + temp[k + j]; } } if(diag_type == HIPSPARSE_DIAG_TYPE_NON_UNIT) { if(diag == -1) { pivot = std::min(pivot, i + idx_base); } y[i] = testing_mult(temp[0], diag_val); } else { y[i] = temp[0]; } } if(pivot != (std::numeric_limits::max)()) { return pivot; } return -1; } /* ============================================================================================ */ /*! \brief Transpose sparse matrix using CSR storage format. */ template void transpose_csr(J m, J n, I nnz, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, I* csr_row_ptr_B, J* csr_col_ind_B, T* csr_val_B, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B) { memset(csr_row_ptr_B, 0, sizeof(I) * (n + 1)); // Determine nnz per column for(I i = 0; i < nnz; ++i) { ++csr_row_ptr_B[csr_col_ind_A[i] + 1 - idx_base_A]; } // Scan for(J i = 0; i < n; ++i) { csr_row_ptr_B[i + 1] += csr_row_ptr_B[i]; } // Fill row indices and values for(J i = 0; i < m; ++i) { I row_begin = csr_row_ptr_A[i] - idx_base_A; I row_end = csr_row_ptr_A[i + 1] - idx_base_A; for(I j = row_begin; j < row_end; ++j) { J col = csr_col_ind_A[j] - idx_base_A; I idx = csr_row_ptr_B[col]; csr_col_ind_B[idx] = i + idx_base_B; csr_val_B[idx] = csr_val_A[j]; ++csr_row_ptr_B[col]; } } // Shift column pointer array for(J i = n; i > 0; --i) { csr_row_ptr_B[i] = csr_row_ptr_B[i - 1] + idx_base_B; } csr_row_ptr_B[0] = idx_base_B; } /* ============================================================================================ */ /*! \brief Transpose sparse matrix using CSR storage format. */ template void transpose_bsr(int mb, int nb, int nnzb, int bsr_dim, const int* bsr_row_ptr_A, const int* bsr_col_ind_A, const T* bsr_val_A, int* bsr_row_ptr_B, int* bsr_col_ind_B, T* bsr_val_B, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B) { memset(bsr_row_ptr_B, 0, sizeof(int) * (nb + 1)); // Determine nnz per column for(int i = 0; i < nnzb; ++i) { ++bsr_row_ptr_B[bsr_col_ind_A[i] + 1 - idx_base_A]; } // Scan for(int i = 0; i < nb; ++i) { bsr_row_ptr_B[i + 1] += bsr_row_ptr_B[i]; } // Fill row indices and values for(int i = 0; i < mb; ++i) { int row_begin = bsr_row_ptr_A[i] - idx_base_A; int row_end = bsr_row_ptr_A[i + 1] - idx_base_A; for(int j = row_begin; j < row_end; ++j) { int col = bsr_col_ind_A[j] - idx_base_A; int idx = bsr_row_ptr_B[col]; bsr_col_ind_B[idx] = i + idx_base_B; for(int bi = 0; bi < bsr_dim; ++bi) { for(int bj = 0; bj < bsr_dim; ++bj) { bsr_val_B[bsr_dim * bsr_dim * idx + bi + bj * bsr_dim] = bsr_val_A[bsr_dim * bsr_dim * j + bi * bsr_dim + bj]; } } ++bsr_row_ptr_B[col]; } } // Shift column pointer array for(int i = nb; i > 0; --i) { bsr_row_ptr_B[i] = bsr_row_ptr_B[i - 1] + idx_base_B; } bsr_row_ptr_B[0] = idx_base_B; } /* ============================================================================================ */ /*! \brief Compute sparse matrix sparse matrix addition. */ template static int host_csrgeam_nnz(int M, int N, T alpha, const int* csr_row_ptr_A, const int* csr_col_ind_A, T beta, const int* csr_row_ptr_B, const int* csr_col_ind_B, int* csr_row_ptr_C, hipsparseIndexBase_t base_A, hipsparseIndexBase_t base_B, hipsparseIndexBase_t base_C) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(N, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif int rows_per_thread = (M + nthreads - 1) / nthreads; int chunk_begin = rows_per_thread * tid; int chunk_end = std::min(chunk_begin + rows_per_thread, M); // Index base csr_row_ptr_C[0] = base_C; // Loop over rows for(int i = chunk_begin; i < chunk_end; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = 0; int row_begin_A = csr_row_ptr_A[i] - base_A; int row_end_A = csr_row_ptr_A[i + 1] - base_A; // Loop over columns of A for(int j = row_begin_A; j < row_end_A; ++j) { int col_A = csr_col_ind_A[j] - base_A; nnz[col_A] = i; ++csr_row_ptr_C[i + 1]; } int row_begin_B = csr_row_ptr_B[i] - base_B; int row_end_B = csr_row_ptr_B[i + 1] - base_B; // Loop over columns of B for(int j = row_begin_B; j < row_end_B; ++j) { int col_B = csr_col_ind_B[j] - base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } // Scan to obtain row offsets for(int i = 0; i < M; ++i) { csr_row_ptr_C[i + 1] += csr_row_ptr_C[i]; } return csr_row_ptr_C[M] - base_C; } template static void host_csrgeam(int M, int N, T alpha, const int* csr_row_ptr_A, const int* csr_col_ind_A, const T* csr_val_A, T beta, const int* csr_row_ptr_B, const int* csr_col_ind_B, const T* csr_val_B, const int* csr_row_ptr_C, int* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t base_A, hipsparseIndexBase_t base_B, hipsparseIndexBase_t base_C) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(N, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif int rows_per_thread = (M + nthreads - 1) / nthreads; int chunk_begin = rows_per_thread * tid; int chunk_end = std::min(chunk_begin + rows_per_thread, M); // Loop over rows for(int i = chunk_begin; i < chunk_end; ++i) { int row_begin_C = csr_row_ptr_C[i] - base_C; int row_end_C = row_begin_C; int row_begin_A = csr_row_ptr_A[i] - base_A; int row_end_A = csr_row_ptr_A[i + 1] - base_A; // Copy A into C for(int j = row_begin_A; j < row_end_A; ++j) { // Current column of A int col_A = csr_col_ind_A[j] - base_A; // Current value of A T val_A = testing_mult(alpha, csr_val_A[j]); nnz[col_A] = row_end_C; csr_col_ind_C[row_end_C] = col_A + base_C; csr_val_C[row_end_C] = val_A; ++row_end_C; } int row_begin_B = csr_row_ptr_B[i] - base_B; int row_end_B = csr_row_ptr_B[i + 1] - base_B; // Loop over columns of B for(int j = row_begin_B; j < row_end_B; ++j) { // Current column of B int col_B = csr_col_ind_B[j] - base_B; // Current value of B T val_B = testing_mult(beta, csr_val_B[j]); // Check if a new nnz is generated or if the value is added if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + base_C; csr_val_C[row_end_C] = val_B; ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + val_B; } } } } int nnz = csr_row_ptr_C[M] - base_C; std::vector col(nnz); std::vector val(nnz); for(int i = 0; i < nnz; ++i) { col[i] = csr_col_ind_C[i]; val[i] = csr_val_C[i]; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic, 1024) #endif for(int i = 0; i < M; ++i) { int row_begin = csr_row_ptr_C[i] - base_C; int row_end = csr_row_ptr_C[i + 1] - base_C; int row_nnz = row_end - row_begin; std::vector perm(row_nnz); for(int j = 0; j < row_nnz; ++j) { perm[j] = j; } int* col_entry = &col[row_begin]; T* val_entry = &val[row_begin]; std::sort(perm.begin(), perm.end(), [&](const int& a, const int& b) { return col_entry[a] <= col_entry[b]; }); for(int j = 0; j < row_nnz; ++j) { csr_col_ind_C[row_begin + j] = col_entry[perm[j]]; csr_val_C[row_begin + j] = val_entry[perm[j]]; } } } /* ============================================================================================ */ /*! \brief Compute sparse matrix sparse matrix multiplication. */ template static I host_csrgemm2_nnz(J m, J n, J k, const T* alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const I* csr_row_ptr_B, const J* csr_col_ind_B, const T* beta, const I* csr_row_ptr_D, const J* csr_col_ind_D, I* csr_row_ptr_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C, hipsparseIndexBase_t idx_base_D) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(n, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif J rows_per_thread = (m + nthreads - 1) / nthreads; J chunk_begin = rows_per_thread * tid; J chunk_end = std::min(chunk_begin + rows_per_thread, m); // Index base csr_row_ptr_C[0] = idx_base_C; // Loop over rows of A for(J i = chunk_begin; i < chunk_end; ++i) { // Initialize csr row pointer with previous row offset csr_row_ptr_C[i + 1] = 0; if(alpha) { I row_begin_A = csr_row_ptr_A[i] - idx_base_A; I row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - idx_base_A; I row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; I row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(I irow = row_begin_B; irow < row_end_B; ++irow) { // Current column of B J col_B = csr_col_ind_B[irow] - idx_base_B; // Check if a new nnz is generated if(nnz[col_B] != i) { nnz[col_B] = i; ++csr_row_ptr_C[i + 1]; } } } } // Add nnz of D if beta != 0 if(beta) { I row_begin_D = csr_row_ptr_D[i] - idx_base_D; I row_end_D = csr_row_ptr_D[i + 1] - idx_base_D; // Loop over columns of D for(I j = row_begin_D; j < row_end_D; ++j) { J col_D = csr_col_ind_D[j] - idx_base_D; // Check if a new nnz is generated if(nnz[col_D] != i) { nnz[col_D] = i; ++csr_row_ptr_C[i + 1]; } } } } } // Scan to obtain row offsets for(J i = 0; i < m; ++i) { csr_row_ptr_C[i + 1] += csr_row_ptr_C[i]; } return csr_row_ptr_C[m] - idx_base_C; } template static void host_csrgemm2(J m, J n, J k, const T* alpha, const I* csr_row_ptr_A, const J* csr_col_ind_A, const T* csr_val_A, const I* csr_row_ptr_B, const J* csr_col_ind_B, const T* csr_val_B, const T* beta, const I* csr_row_ptr_D, const J* csr_col_ind_D, const T* csr_val_D, const I* csr_row_ptr_C, J* csr_col_ind_C, T* csr_val_C, hipsparseIndexBase_t idx_base_A, hipsparseIndexBase_t idx_base_B, hipsparseIndexBase_t idx_base_C, hipsparseIndexBase_t idx_base_D) { #ifdef _OPENMP #pragma omp parallel #endif { std::vector nnz(n, -1); #ifdef _OPENMP int nthreads = omp_get_num_threads(); int tid = omp_get_thread_num(); #else int nthreads = 1; int tid = 0; #endif J rows_per_thread = (m + nthreads - 1) / nthreads; J chunk_begin = rows_per_thread * tid; J chunk_end = std::min(chunk_begin + rows_per_thread, m); // Loop over rows of A for(J i = chunk_begin; i < chunk_end; ++i) { I row_begin_C = csr_row_ptr_C[i] - idx_base_C; I row_end_C = row_begin_C; if(alpha) { I row_begin_A = csr_row_ptr_A[i] - idx_base_A; I row_end_A = csr_row_ptr_A[i + 1] - idx_base_A; // Loop over columns of A for(I j = row_begin_A; j < row_end_A; ++j) { // Current column of A J col_A = csr_col_ind_A[j] - idx_base_A; // Current value of A T val_A = testing_mult(*alpha, csr_val_A[j]); I row_begin_B = csr_row_ptr_B[col_A] - idx_base_B; I row_end_B = csr_row_ptr_B[col_A + 1] - idx_base_B; // Loop over columns of B in row col_A for(I l = row_begin_B; l < row_end_B; ++l) { // Current column of B J col_B = csr_col_ind_B[l] - idx_base_B; // Current value of B T val_B = csr_val_B[l]; // Check if a new nnz is generated or if the product is appended if(nnz[col_B] < row_begin_C) { nnz[col_B] = row_end_C; csr_col_ind_C[row_end_C] = col_B + idx_base_C; csr_val_C[row_end_C] = testing_mult(val_A, val_B); ++row_end_C; } else { csr_val_C[nnz[col_B]] = csr_val_C[nnz[col_B]] + testing_mult(val_A, val_B); } } } } // Add nnz of D if beta != 0 if(beta) { I row_begin_D = csr_row_ptr_D[i] - idx_base_D; I row_end_D = csr_row_ptr_D[i + 1] - idx_base_D; // Loop over columns of D for(I j = row_begin_D; j < row_end_D; ++j) { // Current column of D J col_D = csr_col_ind_D[j] - idx_base_D; // Current value of D T val_D = testing_mult(*beta, csr_val_D[j]); // Check if a new nnz is generated or if the value is added if(nnz[col_D] < row_begin_C) { nnz[col_D] = row_end_C; csr_col_ind_C[row_end_C] = col_D + idx_base_C; csr_val_C[row_end_C] = val_D; ++row_end_C; } else { csr_val_C[nnz[col_D]] = csr_val_C[nnz[col_D]] + val_D; } } } } } I nnz_C = csr_row_ptr_C[m] - idx_base_C; std::vector col(nnz_C); std::vector val(nnz_C); memcpy(col.data(), csr_col_ind_C, sizeof(J) * nnz_C); memcpy(val.data(), csr_val_C, sizeof(T) * nnz_C); #ifdef _OPENMP #pragma omp parallel for #endif for(J i = 0; i < m; ++i) { I row_begin = csr_row_ptr_C[i] - idx_base_C; I row_end = csr_row_ptr_C[i + 1] - idx_base_C; J row_nnz = row_end - row_begin; std::vector perm(row_nnz); for(J j = 0; j < row_nnz; ++j) { perm[j] = j; } J* col_entry = &col[row_begin]; T* val_entry = &val[row_begin]; std::sort(perm.begin(), perm.end(), [&](const I& a, const I& b) { return col_entry[a] <= col_entry[b]; }); for(J j = 0; j < row_nnz; ++j) { csr_col_ind_C[row_begin + j] = col_entry[perm[j]]; csr_val_C[row_begin + j] = val_entry[perm[j]]; } } } #ifdef __cplusplus extern "C" { #endif /* ============================================================================================ */ /* query for hipsparse version and git commit SHA-1. */ void query_version(char* version); /* ============================================================================================ */ /* device query and print out their ID and name */ int query_device_property(); /* set current device to device_id */ void set_device(int device_id); /* ============================================================================================ */ /* timing: HIP only provides very limited timers function clock() and not general; hipsparse sync CPU and device and use more accurate CPU timer*/ /*! \brief CPU Timer(in microsecond): synchronize with the default device and return wall time */ double get_time_us(void); /*! \brief CPU Timer(in microsecond): synchronize with given queue/stream and return wall time */ double get_time_us_sync(hipStream_t stream); #ifdef __cplusplus } #endif struct testhyb { int m; int n; hipsparseHybPartition_t partition; int ell_nnz; int ell_width; int* ell_col_ind; void* ell_val; int coo_nnz; int* coo_row_ind; int* coo_col_ind; void* coo_val; }; template hipsparseIndexType_t getIndexType() { return (typeid(I) == typeid(int32_t)) ? HIPSPARSE_INDEX_32I : HIPSPARSE_INDEX_64I; } template hipDataType getDataType() { return (typeid(T) == typeid(int8_t)) ? HIP_R_8I : (typeid(T) == typeid(float)) ? HIP_R_32F : ((typeid(T) == typeid(double)) ? HIP_R_64F : ((typeid(T) == typeid(hipComplex) ? HIP_C_32F : HIP_C_64F))); } #endif // TESTING_UTILITY_HPP ./clients/include/testing_spsv_csr.hpp0000664000175100017510000003714415176134511020314 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPSV_CSR_HPP #define TESTING_SPSV_CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spsv_csr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t m = 100; int64_t n = 100; int64_t nnz = 100; int64_t safe_size = 100; float alpha = 0.6; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpSVAlg_t alg = HIPSPARSE_SPSV_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dx = (float*)dx_managed.get(); float* dy = (float*)dy_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpSV structures hipsparseSpMatDescr_t A; hipsparseDnVecDescr_t x, y; hipsparseSpSVDescr_t descr; verify_hipsparse_status_success(hipsparseSpSV_createDescr(&descr), "success"); size_t bsize; // Create SpSV structures verify_hipsparse_status_success( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, idxType, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&x, m, dx, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, m, dy, dataType), "success"); // SpSV buffer verify_hipsparse_status_invalid_handle( hipsparseSpSV_bufferSize(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, nullptr, A, x, y, dataType, alg, descr, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, &bsize), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize( handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, &bsize), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_bufferSize(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: bsize is nullptr"); // SpSV analysis verify_hipsparse_status_invalid_handle( hipsparseSpSV_analysis(nullptr, transA, &alpha, A, x, y, dataType, alg, descr, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, nullptr, A, x, y, dataType, alg, descr, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr, dbuf), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr, dbuf), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_analysis(handle, transA, &alpha, A, x, y, dataType, alg, descr, nullptr), "Error: dbuf is nullptr"); #endif // SpSV solve verify_hipsparse_status_invalid_handle( hipsparseSpSV_solve(nullptr, transA, &alpha, A, x, y, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, nullptr, A, x, y, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, nullptr, x, y, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, nullptr, y, dataType, alg, descr), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, nullptr, dataType, alg, descr), "Error: y is nullptr"); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseSpSV_solve(handle, transA, &alpha, A, x, y, dataType, alg, nullptr), "Error: descr is nullptr"); #endif // Destruct verify_hipsparse_status_success(hipsparseSpSV_destroyDescr(descr), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(x), "success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "success"); #endif } template hipsparseStatus_t testing_spsv_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11030) J m = argus.M; J n = argus.N; T h_alpha = make_DataType(argus.alpha); hipsparseOperation_t transA = argus.transA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseDiagType_t diag = argus.diag_type; hipsparseFillMode_t uplo = argus.fill_mode; hipsparseSpSVAlg_t alg = static_cast(argus.spsv_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); I nnz; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(m); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, m); hipsparseInit(hy_1, 1, m); // copy vector is easy in STL; hy_gold = hx: save a copy in hy_gold which will be output of CPU hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dptr = (I*)dptr_managed.get(); J* dcol = (J*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(J) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); hipsparseSpSVDescr_t descr; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_createDescr(&descr)); // Create matrices hipsparseSpMatDescr_t A; CHECK_HIPSPARSE_ERROR( hipsparseCreateCsr(&A, m, n, nnz, dptr, dcol, dval, typeI, typeJ, idx_base, typeT)); // Create dense vectors hipsparseDnVecDescr_t x, y1, y2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&x, m, dx, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, m, dy_1, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, m, dy_2, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_FILL_MODE, &uplo, sizeof(uplo))); CHECK_HIPSPARSE_ERROR( hipsparseSpMatSetAttribute(A, HIPSPARSE_SPMAT_DIAG_TYPE, &diag, sizeof(diag))); // Query SpSV buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSpSV_bufferSize( handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_analysis(handle, transA, d_alpha, A, x, y2, typeT, alg, descr, buffer)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, d_alpha, A, x, y2, typeT, alg, descr)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); J struct_pivot = -1; J numeric_pivot = -1; host_csrsv(transA, m, nnz, h_alpha, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), hx.data(), hy_gold.data(), diag, uplo, idx_base, &struct_pivot, &numeric_pivot); if(struct_pivot == -1 && numeric_pivot == -1) { unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseSpSV_solve(handle, transA, &h_alpha, A, x, y1, typeT, alg, descr)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = spsv_gflop_count(m, nnz, diag); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gbyte_count = csrsv_gbyte_count(m, nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::algorithm, hipsparse_spsvalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSpSV_destroyDescr(descr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(x)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPSV_CSR_HPP ./clients/include/testing_hyb2csr.hpp0000664000175100017510000002225415176134511020022 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_HYB2CSR_HPP #define TESTING_HYB2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_hyb2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; testhyb* dhyb = (testhyb*)hyb; dhyb->m = safe_size; dhyb->n = safe_size; dhyb->ell_nnz = safe_size; dhyb->coo_nnz = safe_size; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, csr_val, (int*)nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, csr_val, csr_row_ptr, (int*)nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr(handle, descr, hyb, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr( handle, (hipsparseMatDescr_t) nullptr, hyb, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXhyb2csr( handle, descr, (hipsparseHybMat_t) nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXhyb2csr( (hipsparseHandle_t) nullptr, descr, hyb, csr_val, csr_row_ptr, csr_col_ind)); #endif } template hipsparseStatus_t testing_hyb2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_gold; std::vector hcsr_col_ind_gold; std::vector hcsr_val_gold; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix( filename, m, n, nnz, hcsr_row_ptr_gold, hcsr_col_ind_gold, hcsr_val_gold, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr, hcsr_row_ptr_gold.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_col_ind, hcsr_col_ind_gold.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val, hcsr_val_gold.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert CSR to HYB CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO)); // Set all CSR arrays to zero CHECK_HIP_ERROR(hipMemset(dcsr_row_ptr, 0, sizeof(int) * (m + 1))); CHECK_HIP_ERROR(hipMemset(dcsr_col_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsr_val, 0, sizeof(T) * nnz)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Copy output from device to host std::vector hcsr_row_ptr(m + 1); std::vector hcsr_col_ind(nnz); std::vector hcsr_val(nnz); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, m + 1, 1, hcsr_row_ptr_gold.data(), hcsr_row_ptr.data()); unit_check_general(1, nnz, 1, hcsr_col_ind_gold.data(), hcsr_col_ind.data()); unit_check_general(1, nnz, 1, hcsr_val_gold.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXhyb2csr(handle, descr, hyb, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; testhyb* dhyb = (testhyb*)hyb; double gbyte_count = hyb2csr_gbyte_count(m, nnz, dhyb->ell_nnz, dhyb->coo_nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_HYB2CSR_HPP ./clients/include/testing_spgemmreuse_csr.hpp0000664000175100017510000005715715176134511021663 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPGEMMREUSE_CSR_HPP #define TESTING_SPGEMMREUSE_CSR_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse_test; void testing_spgemmreuse_csr_bad_arg(void) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) int64_t m = 100; int64_t n = 100; int64_t k = 100; int64_t nnz_A = 100; int64_t nnz_B = 100; int64_t nnz_C = 100; int64_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseIndexBase_t idxBaseA = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseB = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t idxBaseC = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpGEMMAlg_t alg = HIPSPARSE_SPGEMM_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; int* dcsr_row_ptr_A = (int*)dcsr_row_ptr_A_managed.get(); int* dcsr_col_ind_A = (int*)dcsr_col_ind_A_managed.get(); float* dcsr_val_A = (float*)dcsr_val_A_managed.get(); int* dcsr_row_ptr_B = (int*)dcsr_row_ptr_B_managed.get(); int* dcsr_col_ind_B = (int*)dcsr_col_ind_B_managed.get(); float* dcsr_val_B = (float*)dcsr_val_B_managed.get(); int* dcsr_row_ptr_C = (int*)dcsr_row_ptr_C_managed.get(); int* dcsr_col_ind_C = (int*)dcsr_col_ind_C_managed.get(); float* dcsr_val_C = (float*)dcsr_val_C_managed.get(); // SpGEMM structures hipsparseSpMatDescr_t A, B, C; size_t bufferSize; // Create SpGEMM structures verify_hipsparse_status_success(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, idxType, idxType, idxBaseA, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, idxType, idxType, idxBaseB, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateCsr(&C, m, n, nnz_C, dcsr_row_ptr_C, dcsr_col_ind_C, dcsr_val_C, idxType, idxType, idxBaseC, dataType), "success"); // SpGEMM work estimation verify_hipsparse_status_invalid_handle(hipsparseSpGEMMreuse_workEstimation( nullptr, transA, transB, A, B, C, alg, descr, &bufferSize, nullptr)); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, nullptr, B, C, alg, descr, &bufferSize, nullptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, nullptr, C, alg, descr, &bufferSize, nullptr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, nullptr, alg, descr, &bufferSize, nullptr), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, C, alg, descr, nullptr, nullptr), "Error: bufferSize is nullptr"); // SpGEMM compute verify_hipsparse_status_invalid_handle(hipsparseSpGEMMreuse_compute( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, descr)); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, descr), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, descr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, descr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, descr), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_compute( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, descr), "Error: C is nullptr"); // SpGEMMreuse copy verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy( handle, transA, transB, nullptr, B, C, alg, descr, &bufferSize, nullptr), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy( handle, transA, transB, A, nullptr, C, alg, descr, &bufferSize, nullptr), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy( handle, transA, transB, A, B, nullptr, alg, descr, &bufferSize, nullptr), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpGEMMreuse_copy(handle, transA, transB, A, B, C, alg, descr, nullptr, nullptr), "Error: bufferSize is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_spgemmreuse_csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11031) J m = argus.M; J k = argus.K; T h_alpha = make_DataType(argus.alpha); hipsparseIndexBase_t idxBaseA = argus.baseA; hipsparseIndexBase_t idxBaseB = argus.baseB; hipsparseIndexBase_t idxBaseC = argus.baseC; hipsparseSpGEMMAlg_t alg = static_cast(argus.spgemm_alg); std::string filename = argus.filename; T h_beta = make_DataType(0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipsparseIndexType_t typeJ = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handles std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new spgemm_struct); hipsparseSpGEMMDescr_t descr = unique_ptr_descr->descr; // Host structures std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; // Initial Data on CPU srand(12345ULL); I nnz_A; if(!generate_csr_matrix( filename, m, k, nnz_A, hcsr_row_ptr_A, hcsr_col_ind_A, hcsr_val_A, idxBaseA)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Sparse matrix B as the transpose of A J n = m; I nnz_B = nnz_A; std::vector hcsr_row_ptr_B(k + 1); std::vector hcsr_col_ind_B(nnz_B); std::vector hcsr_val_B(nnz_B); transpose_csr(m, k, nnz_A, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), idxBaseA, idxBaseB); // allocate memory on device auto dcsr_row_ptr_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcsr_col_ind_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_A), device_free}; auto dcsr_val_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dcsr_row_ptr_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (k + 1)), device_free}; auto dcsr_col_ind_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_B), device_free}; auto dcsr_val_B_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dcsr_row_ptr_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dcsr_row_ptr_A = (I*)dcsr_row_ptr_A_managed.get(); J* dcsr_col_ind_A = (J*)dcsr_col_ind_A_managed.get(); T* dcsr_val_A = (T*)dcsr_val_A_managed.get(); I* dcsr_row_ptr_B = (I*)dcsr_row_ptr_B_managed.get(); J* dcsr_col_ind_B = (J*)dcsr_col_ind_B_managed.get(); T* dcsr_val_B = (T*)dcsr_val_B_managed.get(); I* dcsr_row_ptr_C = (I*)dcsr_row_ptr_C_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(J) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy( dcsr_row_ptr_B, hcsr_row_ptr_B.data(), sizeof(I) * (k + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind_B, hcsr_col_ind_B.data(), sizeof(J) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_val_B, hcsr_val_B.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A, B, C; CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&A, m, k, nnz_A, dcsr_row_ptr_A, dcsr_col_ind_A, dcsr_val_A, typeI, typeJ, idxBaseA, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr(&B, k, n, nnz_B, dcsr_row_ptr_B, dcsr_col_ind_B, dcsr_val_B, typeI, typeJ, idxBaseB, typeT)); CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &C, m, n, 0, dcsr_row_ptr_C, nullptr, nullptr, typeI, typeJ, idxBaseC, typeT)); // Query SpGEMM work estimation buffer size_t bufferSize1; CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, C, alg, descr, &bufferSize1, nullptr)); auto externalBuffer1_managed = hipsparse_unique_ptr{device_malloc(bufferSize1), device_free}; void* externalBuffer1 = (void*)externalBuffer1_managed.get(); // SpGEMMreuse work estimation CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_workEstimation( handle, transA, transB, A, B, C, alg, descr, &bufferSize1, externalBuffer1)); size_t bufferSize2, bufferSize3, bufferSize4, bufferSize5; void * externalBuffer2 = nullptr, *externalBuffer3 = nullptr, *externalBuffer4 = nullptr, *externalBuffer5 = nullptr; // Query SpGEMM_nnz CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_nnz(handle, transA, transB, A, B, C, alg, descr, &bufferSize2, externalBuffer2, &bufferSize3, externalBuffer3, &bufferSize4, externalBuffer4)); auto externalBuffer2_managed = hipsparse_unique_ptr{device_malloc(bufferSize2), device_free}; externalBuffer2 = (void*)externalBuffer2_managed.get(); auto externalBuffer3_managed = hipsparse_unique_ptr{device_malloc(bufferSize3), device_free}; externalBuffer3 = (void*)externalBuffer3_managed.get(); auto externalBuffer4_managed = hipsparse_unique_ptr{device_malloc(bufferSize4), device_free}; externalBuffer4 = (void*)externalBuffer4_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_nnz(handle, transA, transB, A, B, C, alg, descr, &bufferSize2, externalBuffer2, &bufferSize3, externalBuffer3, &bufferSize4, externalBuffer4)); // We can already free buffer1 externalBuffer1_managed.reset(nullptr); externalBuffer1 = nullptr; externalBuffer2_managed.reset(nullptr); externalBuffer2 = nullptr; // Get nnz of C int64_t rows_C, cols_C, nnz_C; CHECK_HIPSPARSE_ERROR(hipsparseSpMatGetSize(C, &rows_C, &cols_C, &nnz_C)); // Allocate C auto dcsr_col_ind_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(J) * nnz_C), device_free}; auto dcsr_val_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; J* dcsr_col_ind_C = (J*)dcsr_col_ind_C_managed.get(); T* dcsr_val_C = (T*)dcsr_val_C_managed.get(); CHECK_HIP_ERROR(hipMemset(dcsr_val_C, 0, sizeof(T) * nnz_C)); // Set C pointers CHECK_HIPSPARSE_ERROR(hipsparseCsrSetPointers(C, dcsr_row_ptr_C, dcsr_col_ind_C, dcsr_val_C)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_copy( handle, transA, transB, A, B, C, alg, descr, &bufferSize5, externalBuffer5)); auto externalBuffer5_managed = hipsparse_unique_ptr{device_malloc(bufferSize5), device_free}; externalBuffer5 = (void*)externalBuffer5_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_copy( handle, transA, transB, A, B, C, alg, descr, &bufferSize5, externalBuffer5)); externalBuffer3_managed.reset(nullptr); externalBuffer3 = nullptr; // Query SpGEMM compute buffer CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_compute( handle, transA, transB, &h_alpha, A, B, &h_beta, C, typeT, alg, descr)); CHECK_HIPSPARSE_ERROR(hipsparseSpGEMMreuse_compute( handle, transA, transB, &h_alpha, A, B, &h_beta, C, typeT, alg, descr)); externalBuffer4_managed.reset(nullptr); externalBuffer4 = nullptr; externalBuffer5_managed.reset(nullptr); externalBuffer5 = nullptr; // Copy output from device to CPU std::vector hcsr_row_ptr_C(m + 1); std::vector hcsr_col_ind_C(nnz_C); std::vector hcsr_val_C(nnz_C); CHECK_HIP_ERROR(hipMemcpy( hcsr_row_ptr_C.data(), dcsr_row_ptr_C, sizeof(I) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_col_ind_C.data(), dcsr_col_ind_C, sizeof(J) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C.data(), dcsr_val_C, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // Compute SpGEMM nnz of C on host std::vector hcsr_row_ptr_C_gold(m + 1); int64_t nnz_C_gold = host_csrgemm2_nnz(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, hcsr_row_ptr_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify nnz and row pointer array unit_check_general(1, 1, 1, &nnz_C_gold, &nnz_C); unit_check_general(1, m + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); // Compute SpGEMM on host std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(m, n, k, &h_alpha, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), (const T*)nullptr, (const I*)nullptr, (const J*)nullptr, (const T*)nullptr, hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), idxBaseA, idxBaseB, idxBaseC, HIPSPARSE_INDEX_BASE_ZERO); // Verify column and value array unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C.data()); // Clean up CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPGEMM_CSR_HPP ./clients/include/testing_csr2hyb.hpp0000664000175100017510000004314415176134511020023 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2HYB_HPP #define TESTING_CSR2HYB_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; #define ELL_IND_ROW(i, el, m, width) (el) * (m) + (i) #define ELL_IND_EL(i, el, m, width) (el) + (width) * (i) #define ELL_IND(i, el, m, width) ELL_IND_ROW(i, el, m, width) template void testing_csr2hyb_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = 100; int n = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, csr_val, (int*)nullptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, csr_val, csr_row_ptr, (int*)nullptr, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2hyb(handle, m, n, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2hyb((hipsparseHandle_t) nullptr, m, n, descr, csr_val, csr_row_ptr, csr_col_ind, hyb, 0, HIPSPARSE_HYB_PARTITION_AUTO)); #endif } template hipsparseStatus_t testing_csr2hyb(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseHybPartition_t part = argus.part; int user_ell_width = argus.ell_width; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); std::unique_ptr unique_ptr_hyb(new hyb_struct); hipsparseHybMat_t hyb = unique_ptr_hyb->hyb; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } if(m == 0 || n == 0) { return HIPSPARSE_STATUS_SUCCESS; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // User given ELL width check hipsparseStatus_t status; if(part == HIPSPARSE_HYB_PARTITION_USER) { // ELL width -33 means we take a reasonable pre-computed width if(user_ell_width == -33) { user_ell_width = nnz / m; } // Test invalid user_ell_width int max_allowed_ell_nnz_per_row = (2 * nnz - 1) / m + 1; if(user_ell_width < 0 || user_ell_width > max_allowed_ell_nnz_per_row) { status = hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part); verify_hipsparse_status_invalid_value( status, "Error: user_ell_width < 0 || user_ell_width > max_ell_width"); return HIPSPARSE_STATUS_SUCCESS; } } // Max width check if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Compute max ELL width int ell_max_width = 0; for(int i = 0; i < m; ++i) { ell_max_width = std::max(hcsr_row_ptr[i + 1] - hcsr_row_ptr[i], ell_max_width); } int width_limit = (2 * nnz - 1) / m + 1; if(ell_max_width > width_limit) { status = hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part); verify_hipsparse_status_invalid_value(status, "ell_max_width > width_limit"); return HIPSPARSE_STATUS_SUCCESS; } } // Host structures for verification std::vector hhyb_ell_col_ind_gold; std::vector hhyb_ell_val_gold; std::vector hhyb_coo_row_ind_gold; std::vector hhyb_coo_col_ind_gold; std::vector hhyb_coo_val_gold; // Host csr2hyb conversion int ell_width = 0; int ell_nnz = 0; int coo_nnz = 0; if(part == HIPSPARSE_HYB_PARTITION_AUTO || part == HIPSPARSE_HYB_PARTITION_USER) { if(part == HIPSPARSE_HYB_PARTITION_AUTO) { // ELL width is average nnz per row ell_width = (nnz - 1) / m + 1; } else { // User given ELL width ell_width = user_ell_width; } ell_nnz = ell_width * m; // Determine COO nnz for(int i = 0; i < m; ++i) { int row_nnz = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; if(row_nnz > ell_width) { coo_nnz += row_nnz - ell_width; } } } else if(part == HIPSPARSE_HYB_PARTITION_MAX) { // Determine max nnz per row for(int i = 0; i < m; ++i) { int row_nnz = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; ell_width = (row_nnz > ell_width) ? row_nnz : ell_width; } ell_nnz = ell_width * m; } // Allocate host memory // ELL hhyb_ell_col_ind_gold.resize(ell_nnz); hhyb_ell_val_gold.resize(ell_nnz); // COO hhyb_coo_row_ind_gold.resize(coo_nnz); hhyb_coo_col_ind_gold.resize(coo_nnz); hhyb_coo_val_gold.resize(coo_nnz); // Fill HYB int coo_idx = 0; for(int i = 0; i < m; ++i) { int p = 0; for(int j = hcsr_row_ptr[i] - idx_base; j < hcsr_row_ptr[i + 1] - idx_base; ++j) { if(p < ell_width) { int idx = ELL_IND(i, p++, m, ell_width); hhyb_ell_col_ind_gold[idx] = hcsr_col_ind[j]; hhyb_ell_val_gold[idx] = hcsr_val[j]; } else { hhyb_coo_row_ind_gold[coo_idx] = i + idx_base; hhyb_coo_col_ind_gold[coo_idx] = hcsr_col_ind[j]; hhyb_coo_val_gold[coo_idx] = hcsr_val[j]; ++coo_idx; } } for(int j = hcsr_row_ptr[i + 1] - hcsr_row_ptr[i]; j < ell_width; ++j) { int idx = ELL_IND(i, p++, m, ell_width); hhyb_ell_col_ind_gold[idx] = -1; hhyb_ell_val_gold[idx] = make_DataType(0.0); } } // Allocate verification structures std::vector hhyb_ell_col_ind(ell_nnz); std::vector hhyb_ell_val(ell_nnz); std::vector hhyb_coo_row_ind(coo_nnz); std::vector hhyb_coo_col_ind(coo_nnz); std::vector hhyb_coo_val(coo_nnz); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb( handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); // Copy output from device to host testhyb* dhyb = (testhyb*)hyb; // Check if sizes match unit_check_general(1, 1, 1, &m, &dhyb->m); unit_check_general(1, 1, 1, &n, &dhyb->n); unit_check_general(1, 1, 1, &ell_width, &dhyb->ell_width); unit_check_general(1, 1, 1, &ell_nnz, &dhyb->ell_nnz); unit_check_general(1, 1, 1, &coo_nnz, &dhyb->coo_nnz); CHECK_HIP_ERROR(hipMemcpy(hhyb_ell_col_ind.data(), dhyb->ell_col_ind, sizeof(int) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hhyb_ell_val.data(), dhyb->ell_val, sizeof(T) * ell_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hhyb_coo_row_ind.data(), dhyb->coo_row_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hhyb_coo_col_ind.data(), dhyb->coo_col_ind, sizeof(int) * coo_nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hhyb_coo_val.data(), dhyb->coo_val, sizeof(T) * coo_nnz, hipMemcpyDeviceToHost)); // Unit check unit_check_general(1, ell_nnz, 1, hhyb_ell_col_ind_gold.data(), hhyb_ell_col_ind.data()); unit_check_general(1, ell_nnz, 1, hhyb_ell_val_gold.data(), hhyb_ell_val.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_row_ind_gold.data(), hhyb_coo_row_ind.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_col_ind_gold.data(), hhyb_coo_col_ind.data()); unit_check_general(1, coo_nnz, 1, hhyb_coo_val_gold.data(), hhyb_coo_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2hyb(handle, m, n, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, hyb, user_ell_width, part)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2hyb_gbyte_count(m, nnz, ell_nnz, coo_nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::ell_nnz, ell_nnz, display_key_t::coo_nnz, coo_nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2HYB_HPP ./clients/include/testing_csrsv2.hpp0000664000175100017510000010034015176134511017661 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRSV2_HPP #define TESTING_CSRSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrsv2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int nnz = 100; int safe_size = 100; T h_alpha = make_DataType(0.6); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsv2_info(new csrsv2_struct); csrsv2Info_t info = unique_ptr_csrsv2_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy = (T*)dy_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); int size; int position; verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, (int*)nullptr, dcol, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, (int*)nullptr, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, info, (int*)nullptr), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_bufferSize( handle, transA, m, nnz, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_bufferSize( (hipsparseHandle_t) nullptr, transA, m, nnz, descr, dval, dptr, dcol, info, &size)); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, (int*)nullptr, dcol, info, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, (int*)nullptr, info, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, (T*)nullptr, dptr, dcol, info, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_analysis( handle, transA, m, nnz, descr, dval, dptr, dcol, info, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_analysis(handle, transA, m, nnz, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_analysis(handle, transA, m, nnz, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_analysis((hipsparseHandle_t) nullptr, transA, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, (int*)nullptr, dcol, info, dx, dy, policy, dbuffer), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, (int*)nullptr, info, dx, dy, policy, dbuffer), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, (T*)nullptr, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, (T*)nullptr, dy, policy, dbuffer), "Error: dx is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, (T*)nullptr, policy, dbuffer), "Error: dy is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, (T*)nullptr, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, (void*)nullptr), "Error: dbuffer is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, (hipsparseMatDescr_t) nullptr, dval, dptr, dcol, info, dx, dy, policy, dbuffer), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_solve(handle, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, (csrsv2Info_t) nullptr, dx, dy, policy, dbuffer), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsrsv2_solve((hipsparseHandle_t) nullptr, transA, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy, policy, dbuffer)); verify_hipsparse_status_invalid_pointer(hipsparseXcsrsv2_zeroPivot(handle, info, (int*)nullptr), "Error: position is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXcsrsv2_zeroPivot(handle, (csrsv2Info_t) nullptr, &position), "Error: info is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXcsrsv2_zeroPivot((hipsparseHandle_t) nullptr, info, &position)); #endif } template hipsparseStatus_t testing_csrsv2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int m = argus.M; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t trans = argus.transA; hipsparseDiagType_t diag_type = argus.diag_type; hipsparseFillMode_t fill_mode = argus.fill_mode; hipsparseSolvePolicy_t policy = argus.solve_policy; T h_alpha = make_DataType(argus.alpha); std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_csrsv2_info(new csrsv2_struct); csrsv2Info_t info = unique_ptr_csrsv2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); // Set matrix diag type CHECK_HIPSPARSE_ERROR(hipsparseSetMatDiagType(descr, diag_type)); // Set matrix fill mode CHECK_HIPSPARSE_ERROR(hipsparseSetMatFillMode(descr, fill_mode)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hx(m); std::vector hy_1(m); std::vector hy_2(m); std::vector hy_gold(m); hipsparseInit(hx, 1, m); // Allocate memory on device auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_position_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); T* dval = (T*)dval_managed.get(); T* dx = (T*)dx_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); int* d_position = (int*)d_position_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx, hx.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrsv2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_bufferSize( handle, trans, m, nnz, descr, dval, dptr, dcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrsv2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_analysis( handle, trans, m, nnz, descr, dval, dptr, dcol, info, policy, dbuffer)); if(argus.unit_check) { CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * m, hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1; pivot_status_1 = hipsparseXcsrsv2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, d_alpha, descr, dval, dptr, dcol, info, dx, dy_2, policy, dbuffer)); hipsparseStatus_t pivot_status_2; pivot_status_2 = hipsparseXcsrsv2_zeroPivot(handle, info, d_position); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * m, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, d_position, sizeof(int), hipMemcpyDeviceToHost)); // Host csrsv2 hipDeviceProp_t prop; CHECK_HIP_ERROR(hipGetDeviceProperties(&prop, 0)); int position_gold; if((fill_mode == HIPSPARSE_FILL_MODE_LOWER && trans == HIPSPARSE_OPERATION_NON_TRANSPOSE) || (fill_mode == HIPSPARSE_FILL_MODE_UPPER && trans == HIPSPARSE_OPERATION_TRANSPOSE)) { position_gold = csr_lsolve(trans, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hy_gold.data(), idx_base, diag_type, prop.warpSize); } else { position_gold = csr_usolve(trans, m, hcsr_row_ptr.data(), hcsr_col_ind.data(), hcsr_val.data(), h_alpha, hx.data(), hy_gold.data(), idx_base, diag_type, prop.warpSize); } unit_check_general(1, 1, 1, &position_gold, &hposition_1); unit_check_general(1, 1, 1, &position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(1, m, 1, hy_gold.data(), hy_1.data()); unit_check_near(1, m, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsrsv2_solve(handle, trans, m, nnz, &h_alpha, descr, dval, dptr, dcol, info, dx, dy_1, policy, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, nnz, diag_type); double gbyte_count = csrsv_gbyte_count(m, nnz); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::trans, hipsparse_operation2string(trans), display_key_t::diag_type, hipsparse_diagtype2string(diag_type), display_key_t::fill_mode, hipsparse_fillmode2string(fill_mode), display_key_t::solve_policy, hipsparse_solvepolicy2string(policy), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRSV2_HPP ./clients/include/testing_csr2csc_ex2.hpp0000664000175100017510000006367215176134511020577 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2CSC_EX2_HPP #define TESTING_CSR2CSC_EX2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csc_ex2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; size_t buffer_size = 0; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); T* csc_val = (T*)csc_val_managed.get(); void* buffer = (void*)buffer_managed.get(); verify_hipsparse_status_invalid_handle( hipsparseCsr2cscEx2_bufferSize((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size)); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, &buffer_size), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, (size_t*)nullptr), "Error: buffer_size is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseCsr2cscEx2((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer)); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, (T*)nullptr, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, (int*)nullptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, (int*)nullptr, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, (T*)nullptr, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, buffer), "Error: csc_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseCsr2cscEx2(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_col_ptr, csc_row_ind, HIP_R_32F, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_CSR2CSC_ALG1, (T*)nullptr), "Error: buffer is nullptr"); #endif } template hipsparseStatus_t testing_csr2csc_ex2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 10010) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseAction_t action = argus.action; hipsparseCsr2CscAlg_t alg = static_cast(argus.csr2csc_alg); std::string filename = argus.filename; hipDataType dataType = getDataType(); std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); T* dcsc_val = (T*)dcsc_val_managed.get(); // Reset CSC arrays CHECK_HIP_ERROR(hipMemset(dcsc_row_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsc_col_ptr, 0, sizeof(int) * (n + 1))); CHECK_HIP_ERROR(hipMemset(dcsc_val, 0, sizeof(T) * nnz)); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2_bufferSize(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); // Copy output from device to host std::vector hcsc_row_ind(nnz); std::vector hcsc_col_ptr(n + 1); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsc_col_ptr.data(), dcsc_col_ptr, sizeof(int) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_val.data(), dcsc_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsc_row_ind_gold(nnz); std::vector hcsc_col_ptr_gold(n + 1, 0); std::vector hcsc_val_gold(nnz); // Determine nnz per column for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptr_gold[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(int i = 0; i < n; ++i) { hcsc_col_ptr_gold[i + 1] += hcsc_col_ptr_gold[i]; } // Fill row indices and values for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { int col = hcsr_col_ind[j - idx_base] - idx_base; int idx = hcsc_col_ptr_gold[col]; hcsc_row_ind_gold[idx] = i + idx_base; hcsc_val_gold[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr_gold[col]; } } // Shift column pointer array for(int i = n; i > 0; --i) { hcsc_col_ptr_gold[i] = hcsc_col_ptr_gold[i - 1] + idx_base; } hcsc_col_ptr_gold[0] = idx_base; // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind_gold.data(), hcsc_row_ind.data()); unit_check_general(1, n + 1, 1, hcsc_col_ptr_gold.data(), hcsc_col_ptr.data()); // If action == HIPSPARSE_ACTION_NUMERIC also check values if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnz, 1, hcsc_val_gold.data(), hcsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseCsr2cscEx2(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_col_ptr, dcsc_row_ind, dataType, action, idx_base, alg, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csc_gbyte_count(m, n, nnz, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_EX2_HPP ./clients/include/testing_prune_dense2csr.hpp0000664000175100017510000005410315176134511021545 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_PRUNE_DENSE2CSR_HPP #define TESTING_PRUNE_DENSE2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_prune_dense2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) size_t safe_size = 100; int M = 1; int N = 1; int LDA = M; T threshold = static_cast(1); int nnz_total_dev_host_ptr = 100; size_t buffer_size = 100; hipsparseStatus_t status; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto temp_buffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); T* A = (T*)A_managed.get(); T* temp_buffer = (T*)temp_buffer_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(csr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); // Test hipsparseXpruneDense2csr_bufferSize status = hipsparseXpruneDense2csr_bufferSize( nullptr, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, &buffer_size); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csr_bufferSize( handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: buffer size is nullptr"); // Test hipsparseXpruneDense2csrNnz status = hipsparseXpruneDense2csrNnz(nullptr, M, N, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csrNnz(handle, -1, N, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csrNnz(handle, M, -1, A, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, -1, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csrNnz(handle, M, N, (const T*)nullptr, LDA, &threshold, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csrNnz(handle, M, N, A, LDA, (const T*)nullptr, descr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneDense2csrNnz(handle, M, N, A, LDA, &threshold, nullptr, csr_row_ptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, LDA, &threshold, descr, nullptr, &nnz_total_dev_host_ptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csrNnz( handle, M, N, A, LDA, &threshold, descr, csr_row_ptr, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_total_dev_host_ptr is nullptr"); // Test hipsparseXpruneDense2csr status = hipsparseXpruneDense2csr( nullptr, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_handle(status); status = hipsparseXpruneDense2csr( handle, -1, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: M is invalid"); status = hipsparseXpruneDense2csr( handle, M, -1, A, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: N is invalid"); status = hipsparseXpruneDense2csr( handle, M, N, A, -1, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_size(status, "Error: LDA is invalid"); status = hipsparseXpruneDense2csr(handle, M, N, (const T*)nullptr, LDA, &threshold, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: A is nullptr"); status = hipsparseXpruneDense2csr(handle, M, N, A, LDA, (const T*)nullptr, descr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: threshold is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, nullptr, csr_val, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr is nullptr"); status = hipsparseXpruneDense2csr(handle, M, N, A, LDA, &threshold, descr, (T*)nullptr, csr_row_ptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_val is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, descr, csr_val, nullptr, csr_col_ind, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_row_ptr is nullptr"); status = hipsparseXpruneDense2csr( handle, M, N, A, LDA, &threshold, descr, csr_val, csr_row_ptr, nullptr, temp_buffer); verify_hipsparse_status_invalid_pointer(status, "Error: csr_col_ind is nullptr"); #endif } template hipsparseStatus_t testing_prune_dense2csr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int M = argus.M; int N = argus.N; int LDA = argus.lda; T threshold = make_DataType(argus.threshold); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(M == 0 || N == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ return HIPSPARSE_STATUS_SUCCESS; #endif } // Allocate host memory std::vector h_A(LDA * N); std::vector h_nnz_total_dev_host_ptr(1); // Allocate device memory auto d_A_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * LDA * N), device_free}; auto d_nnz_total_dev_host_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; auto d_csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; T* d_A = (T*)d_A_managed.get(); int* d_nnz_total_dev_host_ptr = (int*)d_nnz_total_dev_host_ptr_managed.get(); int* d_csr_row_ptr = (int*)d_csr_row_ptr_managed.get(); // Initialize the entire allocated memory. for(int i = 0; i < LDA; ++i) { for(int j = 0; j < N; ++j) { h_A[j * LDA + i] = make_DataType(-1); } } // Initialize a random dense matrix. srand(0); gen_dense_random_sparsity_pattern(M, N, h_A.data(), LDA, HIPSPARSE_ORDER_COL, 0.2); // Transfer. CHECK_HIP_ERROR(hipMemcpy(d_A, h_A.data(), sizeof(T) * LDA * N, hipMemcpyHostToDevice)); size_t buffer_size = 512; CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr_bufferSize(handle, M, N, d_A, LDA, &threshold, descr, (const T*)nullptr, d_csr_row_ptr, (const int*)nullptr, &buffer_size)); auto d_temp_buffer_managed = hipsparse_unique_ptr{device_malloc(buffer_size), device_free}; T* d_temp_buffer = (T*)d_temp_buffer_managed.get(); auto d_threshold_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* d_threshold = (T*)d_threshold_managed.get(); CHECK_HIP_ERROR(hipMemcpy(d_threshold, &threshold, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnz(handle, M, N, d_A, LDA, &threshold, descr, d_csr_row_ptr, &h_nnz_total_dev_host_ptr[0], d_temp_buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csrNnz(handle, M, N, d_A, LDA, d_threshold, descr, d_csr_row_ptr, d_nnz_total_dev_host_ptr, d_temp_buffer)); std::vector h_nnz_total_copied_from_device(1); CHECK_HIP_ERROR(hipMemcpy(h_nnz_total_copied_from_device.data(), d_nnz_total_dev_host_ptr, sizeof(int), hipMemcpyDeviceToHost)); if(argus.unit_check) { unit_check_general( 1, 1, 1, h_nnz_total_dev_host_ptr.data(), h_nnz_total_copied_from_device.data()); } auto d_csr_col_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(int) * h_nnz_total_dev_host_ptr[0]), device_free}; auto d_csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * h_nnz_total_dev_host_ptr[0]), device_free}; int* d_csr_col_ind = (int*)d_csr_col_ind_managed.get(); T* d_csr_val = (T*)d_csr_val_managed.get(); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); std::vector h_csr_row_ptr(M + 1); std::vector h_csr_col_ind(h_nnz_total_dev_host_ptr[0]); std::vector h_csr_val(h_nnz_total_dev_host_ptr[0]); CHECK_HIP_ERROR(hipMemcpy( h_csr_row_ptr.data(), d_csr_row_ptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_col_ind.data(), d_csr_col_ind, sizeof(int) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(h_csr_val.data(), d_csr_val, sizeof(T) * h_nnz_total_dev_host_ptr[0], hipMemcpyDeviceToHost)); // call host and check results std::vector h_nnz_cpu(1); std::vector h_csr_row_ptr_cpu; std::vector h_csr_col_ind_cpu; std::vector h_csr_val_cpu; host_prune_dense2csr(M, N, h_A, LDA, idx_base, threshold, h_nnz_cpu[0], h_csr_val_cpu, h_csr_row_ptr_cpu, h_csr_col_ind_cpu); unit_check_general(1, 1, 1, h_nnz_cpu.data(), h_nnz_total_dev_host_ptr.data()); unit_check_general(1, (M + 1), 1, h_csr_row_ptr_cpu.data(), h_csr_row_ptr.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_col_ind_cpu.data(), h_csr_col_ind.data()); unit_check_general( 1, h_nnz_total_dev_host_ptr[0], 1, h_csr_val_cpu.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXpruneDense2csr(handle, M, N, d_A, LDA, &threshold, descr, d_csr_val, d_csr_row_ptr, d_csr_col_ind, d_temp_buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = prune_dense2csr_gbyte_count(M, N, h_nnz_total_dev_host_ptr[0]); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, M, display_key_t::N, N, display_key_t::LD, LDA, display_key_t::nnz, h_nnz_total_dev_host_ptr[0], display_key_t::threshold, threshold, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_PRUNE_DENSE2CSR_HPP ./clients/include/testing_spvec_descr.hpp0000664000175100017510000001351715176134305020751 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPVEC_DESCR_HPP #define TESTING_SPVEC_DESCR_HPP #include "hipsparse_test_unique_ptr.hpp" #ifdef GOOGLE_TEST #include #endif #include using namespace hipsparse_test; void testing_spvec_descr_bad_arg(void) { #if(!defined(CUDART_VERSION)) int64_t size = 100; int64_t nnz = 100; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; // Allocate memory on device auto idx_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto val_data_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; int* idx_data = (int*)idx_data_managed.get(); float* val_data = (float*)val_data_managed.get(); hipsparseSpVecDescr_t x; // hipsparseCreateSpVec verify_hipsparse_status_invalid_pointer( hipsparseCreateSpVec(nullptr, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_size( hipsparseCreateSpVec(&x, -1, nnz, idx_data, val_data, idxType, idxBase, dataType), "Error: size is < 0"); verify_hipsparse_status_invalid_size( hipsparseCreateSpVec(&x, size, -1, idx_data, val_data, idxType, idxBase, dataType), "Error: nnz is < 0"); verify_hipsparse_status_invalid_pointer( hipsparseCreateSpVec(&x, size, nnz, nullptr, val_data, idxType, idxBase, dataType), "Error: idx_data is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseCreateSpVec(&x, size, nnz, idx_data, nullptr, idxType, idxBase, dataType), "Error: val_data is nullptr"); // hipsparseDestroySpVec verify_hipsparse_status_invalid_pointer(hipsparseDestroySpVec(nullptr), "Error: x is nullptr"); // Create valid descriptor verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, idx_data, val_data, idxType, idxBase, dataType), "Success"); // hipsparseSpVecGet void* idx; void* data; verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(nullptr, &size, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, nullptr, &nnz, &idx, &data, &idxType, &idxBase, &dataType), "Error: size is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, nullptr, &idx, &data, &idxType, &idxBase, &dataType), "Error: nnz is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, nullptr, &data, &idxType, &idxBase, &dataType), "Error: idx is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, nullptr, &idxType, &idxBase, &dataType), "Error: val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, &data, nullptr, &idxBase, &dataType), "Error: idxType is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, &data, &idxType, nullptr, &dataType), "Error: idxBase is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpVecGet(x, &size, &nnz, &idx, &data, &idxType, &idxBase, nullptr), "Error: dataType is nullptr"); // hipsparseSpVecGetIndexBase verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(nullptr, &idxBase), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetIndexBase(x, nullptr), "Error: idxBase is nullptr"); // hipsparseSpVecGetValues verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetValues(nullptr, &data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecGetValues(x, nullptr), "Error: val is nullptr"); // hipsparseSpVecSetValues verify_hipsparse_status_invalid_pointer(hipsparseSpVecSetValues(nullptr, data), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseSpVecSetValues(x, nullptr), "Error: val is nullptr"); // Destroy valid descriptor verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); #endif } #endif // TESTING_SPVEC_DESCR_HPP ./clients/include/testing_csr2csc.hpp0000664000175100017510000004267615176134511020022 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2CSC_HPP #define TESTING_CSR2CSC_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csr2csc_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 100; int n = 100; int nnz = 100; int safe_size = 100; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int* csc_row_ind = (int*)csc_row_ind_managed.get(); int* csc_col_ptr = (int*)csc_col_ptr_managed.get(); T* csc_val = (T*)csc_val_managed.get(); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, (int*)nullptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, (int*)nullptr, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, (T*)nullptr, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, (int*)nullptr, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_row_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, (int*)nullptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_col_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXcsr2csc(handle, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, (T*)nullptr, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO), "Error: csc_val is nullptr"); verify_hipsparse_status_invalid_handle(hipsparseXcsr2csc((hipsparseHandle_t) nullptr, m, n, nnz, csr_val, csr_row_ptr, csr_col_ind, csc_val, csc_row_ind, csc_col_ptr, HIPSPARSE_ACTION_NUMERIC, HIPSPARSE_INDEX_BASE_ZERO)); #endif } template hipsparseStatus_t testing_csr2csc(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) int m = argus.M; int n = argus.N; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseAction_t action = argus.action; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // Allocate memory on the device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsc_row_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsc_col_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (n + 1)), device_free}; auto dcsc_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dcsc_row_ind = (int*)dcsc_row_ind_managed.get(); int* dcsc_col_ptr = (int*)dcsc_col_ptr_managed.get(); T* dcsc_val = (T*)dcsc_val_managed.get(); // Reset CSC arrays CHECK_HIP_ERROR(hipMemset(dcsc_row_ind, 0, sizeof(int) * nnz)); CHECK_HIP_ERROR(hipMemset(dcsc_col_ptr, 0, sizeof(int) * (n + 1))); CHECK_HIP_ERROR(hipMemset(dcsc_val, 0, sizeof(T) * nnz)); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); // Copy output from device to host std::vector hcsc_row_ind(nnz); std::vector hcsc_col_ptr(n + 1); std::vector hcsc_val(nnz); CHECK_HIP_ERROR( hipMemcpy(hcsc_row_ind.data(), dcsc_row_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsc_col_ptr.data(), dcsc_col_ptr, sizeof(int) * (n + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsc_val.data(), dcsc_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host csr2csc conversion std::vector hcsc_row_ind_gold(nnz); std::vector hcsc_col_ptr_gold(n + 1, 0); std::vector hcsc_val_gold(nnz); // Determine nnz per column for(int i = 0; i < nnz; ++i) { ++hcsc_col_ptr_gold[hcsr_col_ind[i] + 1 - idx_base]; } // Scan for(int i = 0; i < n; ++i) { hcsc_col_ptr_gold[i + 1] += hcsc_col_ptr_gold[i]; } // Fill row indices and values for(int i = 0; i < m; ++i) { for(int j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { int col = hcsr_col_ind[j - idx_base] - idx_base; int idx = hcsc_col_ptr_gold[col]; hcsc_row_ind_gold[idx] = i + idx_base; hcsc_val_gold[idx] = hcsr_val[j - idx_base]; ++hcsc_col_ptr_gold[col]; } } // Shift column pointer array for(int i = n; i > 0; --i) { hcsc_col_ptr_gold[i] = hcsc_col_ptr_gold[i - 1] + idx_base; } hcsc_col_ptr_gold[0] = idx_base; // Unit check unit_check_general(1, nnz, 1, hcsc_row_ind_gold.data(), hcsc_row_ind.data()); unit_check_general(1, n + 1, 1, hcsc_col_ptr_gold.data(), hcsc_col_ptr.data()); // If action == HIPSPARSE_ACTION_NUMERIC also check values if(action == HIPSPARSE_ACTION_NUMERIC) { unit_check_general(1, nnz, 1, hcsc_val_gold.data(), hcsc_val.data()); } } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXcsr2csc(handle, m, n, nnz, dcsr_val, dcsr_row_ptr, dcsr_col_ind, dcsc_val, dcsc_row_ind, dcsc_col_ptr, action, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = csr2csc_gbyte_count(m, n, nnz, action); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::nnz, nnz, display_key_t::action, hipsparse_action2string(action), display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSR2CSC_HPP ./clients/include/testing_spmm_bell.hpp0000664000175100017510000004343415176134511020423 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SPMM_BELL_HPP #define TESTING_SPMM_BELL_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_spmm_bell_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int32_t ell_blocksize = 2; int32_t ell_cols = 10; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_BLOCKED_ELL_ALG1; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* dind = (int32_t*)dind_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dC = (float*)dC_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SpMM structures hipsparseSpMatDescr_t A; hipsparseDnMatDescr_t B, C; size_t bsize; // Create SpMM structures verify_hipsparse_status_success( hipsparseCreateBlockedEll( &A, m, k, ell_blocksize, ell_cols, dind, dval, idxType, idxBase, dataType), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, order), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&C, m, n, m, dC, dataType, order), "success"); // SpMM buffer verify_hipsparse_status_invalid_handle(hipsparseSpMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SpMM_preprocess verify_hipsparse_status_invalid_handle(hipsparseSpMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SpMM verify_hipsparse_status_invalid_handle( hipsparseSpMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSpMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(C), "success"); #endif } template hipsparseStatus_t testing_spmm_bell() { #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) std::vector hval = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0)}; std::vector hcol_ind = {1, 2, 1, 2, 1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 5, 6}; std::vector hrow_ptr = {1, 3, 5, 9, 13, 15, 17}; std::vector hbell_val = {make_DataType(1.0), make_DataType(2.0), make_DataType(3.0), make_DataType(4.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(5.0), make_DataType(6.0), make_DataType(7.0), make_DataType(8.0), make_DataType(9.0), make_DataType(10.0), make_DataType(11.0), make_DataType(12.0), make_DataType(13.0), make_DataType(14.0), make_DataType(15.0), make_DataType(16.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0), make_DataType(-7.0)}; std::vector hbell_ind = {1, 0, 1, 2, 3, 0}; I ell_cols = 4; I ell_blocksize = 2; I m = 6; I k = 6; I nnz = 16; I n = 2; I ldb = k; I ldc = m; T h_alpha = make_DataType(2.0); T h_beta = make_DataType(1.0); hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t order = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ONE; hipsparseSpMMAlg_t alg = HIPSPARSE_SPMM_BLOCKED_ELL_ALG1; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::vector hB = {make_DataType(1.0), make_DataType(1.0), make_DataType(-1.0), make_DataType(2.0), make_DataType(1.0), make_DataType(3.0), make_DataType(-1.0), make_DataType(4.0), make_DataType(1.0), make_DataType(5.0), make_DataType(-1.0), make_DataType(6.0)}; std::vector hC_1 = {make_DataType(1.0), make_DataType(1.0), make_DataType(-1.0), make_DataType(2.0), make_DataType(1.0), make_DataType(3.0), make_DataType(-1.0), make_DataType(4.0), make_DataType(1.0), make_DataType(5.0), make_DataType(-1.0), make_DataType(6.0)}; std::vector hC_gold = {make_DataType(35.0), make_DataType(41.0), make_DataType(115.0), make_DataType(126.0), make_DataType(25.0), make_DataType(31.0), make_DataType(149.0), make_DataType(172.0), make_DataType(155.0), make_DataType(169.0), make_DataType(45.0), make_DataType(58.0)}; std::vector hC_2(hC_1); // allocate memory on device auto drow_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * (m + 1)), device_free}; auto dcol_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbell_ind_managed = hipsparse_unique_ptr{ device_malloc(sizeof(I) * (ell_cols / ell_blocksize) * (m / ell_blocksize)), device_free}; auto dbell_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * ell_cols * m), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * k * n), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m * n), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drow_ptr = (I*)drow_ptr_managed.get(); I* dcol_ind = (I*)dcol_ind_managed.get(); T* dval = (T*)dval_managed.get(); T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); I* dbell_ind = (I*)dbell_ind_managed.get(); T* dbell_val = (T*)dbell_val_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drow_ptr, hrow_ptr.data(), sizeof(I) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcol_ind, hcol_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval, hval.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * k * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * m * n, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbell_ind, hbell_ind.data(), sizeof(I) * (ell_cols / ell_blocksize) * (m / ell_blocksize), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbell_val, hbell_val.data(), sizeof(T) * ell_cols * m, hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t A_bell; CHECK_HIPSPARSE_ERROR(hipsparseCreateBlockedEll( &A_bell, m, k, ell_blocksize, ell_cols, dbell_ind, dbell_val, typeI, idx_base, typeT)); hipsparseSpMatDescr_t A_csr; CHECK_HIPSPARSE_ERROR(hipsparseCreateCsr( &A_csr, m, k, nnz, drow_ptr, dcol_ind, dval, typeI, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t B, C1, C2; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, k, n, ldb, dB, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C1, m, n, ldc, dC_1, typeT, order)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&C2, m, n, ldc, dC_2, typeT, order)); // Query SpMM buffer size_t bufferSize_bell; CHECK_HIPSPARSE_ERROR(hipsparseSpMM_bufferSize( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, &bufferSize_bell)); void* buffer_bell; CHECK_HIP_ERROR(hipMalloc(&buffer_bell, bufferSize_bell)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, buffer_bell)); #endif CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, &h_alpha, A_bell, B, &h_beta, C1, typeT, alg, buffer_bell)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11021) CHECK_HIPSPARSE_ERROR(hipsparseSpMM_preprocess( handle, transA, transB, d_alpha, A_bell, B, d_beta, C2, typeT, alg, buffer_bell)); #endif CHECK_HIPSPARSE_ERROR(hipsparseSpMM( handle, transA, transB, d_alpha, A_bell, B, d_beta, C2, typeT, alg, buffer_bell)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * m * n, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * m * n, hipMemcpyDeviceToHost)); unit_check_near(1, m * n, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, m * n, 1, hC_gold.data(), hC_2.data()); CHECK_HIP_ERROR(hipFree(buffer_bell)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A_csr)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(A_bell)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(C2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SPMM_BELL_HPP ./clients/include/testing_gthrz.hpp0000664000175100017510000001506215176134511017603 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTHRZ_HPP #define TESTING_GTHRZ_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gthrz_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, dy, dx_val, (int*)nullptr, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, dy, (T*)nullptr, dx_ind, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgthrz(handle, nnz, (T*)nullptr, dx_val, dx_ind, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXgthrz((hipsparseHandle_t) nullptr, nnz, dy, dx_val, dx_ind, idx_base)); #endif } template hipsparseStatus_t testing_gthrz(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hx_val_gold(nnz); std::vector hy(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hy, 1, N); hy_gold = hy; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hx_val_gold[i] = hy_gold[hx_ind[i] - idx_base]; hy_gold[hx_ind[i] - idx_base] = make_DataType(0.0); } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data()); unit_check_general(1, N, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgthrz(handle, nnz, dy, dx_val, dx_ind, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gthrz_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTHRZ_HPP ./clients/include/testing_csr2dense.hpp0000664000175100017510000000404315176134511020332 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSR2DENSE_HPP #define TESTING_CSR2DENSE_HPP #include "testing_csx2dense.hpp" template void testing_csr2dense_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; testing_csx2dense_bad_arg(hipsparseXcsr2dense); #endif } template hipsparseStatus_t testing_csr2dense(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_ROW; return testing_csx2dense(argus, hipsparseXcsr2dense, hipsparseXdense2csr); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_CSR2DENSE ./clients/include/testing_rot.hpp0000664000175100017510000002437515176134511017260 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_ROT_HPP #define TESTING_ROT_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse_test; void testing_rot_bad_arg(void) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11000 && CUDART_VERSION < 13000)) int64_t size = 100; int64_t nnz = 100; float c_coeff = 3.7; float s_coeff = 1.2; hipsparseIndexType_t idxType = HIPSPARSE_INDEX_32I; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipDataType dataType = HIP_R_32F; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * nnz), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * size), device_free}; float* dx_val = (float*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); float* dy = (float*)dy_managed.get(); // Structures hipsparseSpVecDescr_t x; hipsparseDnVecDescr_t y; verify_hipsparse_status_success( hipsparseCreateSpVec(&x, size, nnz, dx_ind, dx_val, idxType, idxBase, dataType), "Success"); verify_hipsparse_status_success(hipsparseCreateDnVec(&y, size, dy, dataType), "Success"); // Rot verify_hipsparse_status_invalid_handle(hipsparseRot(nullptr, &c_coeff, &s_coeff, x, y)); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, nullptr, &s_coeff, x, y), "Error: c_coeff is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, &c_coeff, nullptr, x, y), "Error: s_coeff is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, &c_coeff, &s_coeff, nullptr, y), "Error: x is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseRot(handle, &c_coeff, &s_coeff, x, nullptr), "Error: y is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroySpVec(x), "Success"); verify_hipsparse_status_success(hipsparseDestroyDnVec(y), "Success"); #endif } template hipsparseStatus_t testing_rot(Arguments argus) { #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 11000 && CUDART_VERSION < 13000)) I size = argus.N; I nnz = argus.nnz; T hc_coeff = make_DataType(argus.alpha); T hs_coeff = make_DataType(argus.beta); hipsparseIndexBase_t idxBase = argus.baseA; // Index and data type hipsparseIndexType_t idxType = getIndexType(); hipDataType dataType = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val_1(nnz); std::vector hx_val_2(nnz); std::vector hx_val_gold(nnz); std::vector hy_1(size); std::vector hy_2(size); std::vector hy_gold(size); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, size); hipsparseInit(hx_val_1, 1, nnz); hipsparseInit(hy_1, 1, size); hx_val_2 = hx_val_1; hx_val_gold = hx_val_1; hy_2 = hy_1; hy_gold = hy_1; // Allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz), device_free}; auto dx_val_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_val_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * size), device_free}; auto dc_coeff_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto ds_coeff_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* dx_ind = (I*)dx_ind_managed.get(); T* dx_val_1 = (T*)dx_val_1_managed.get(); T* dx_val_2 = (T*)dx_val_2_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dc_coeff = (T*)dc_coeff_managed.get(); T* ds_coeff = (T*)ds_coeff_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(I) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val_1, hx_val_1.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val_2, hx_val_2.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * size, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * size, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dc_coeff, &hc_coeff, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ds_coeff, &hs_coeff, sizeof(T), hipMemcpyHostToDevice)); // Create structures hipsparseSpVecDescr_t x1, x2; hipsparseDnVecDescr_t y1, y2; CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x1, size, nnz, dx_ind, dx_val_1, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR( hipsparseCreateSpVec(&x2, size, nnz, dx_ind, dx_val_2, idxType, idxBase, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y1, size, dy_1, dataType)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnVec(&y2, size, dy_2, dataType)); if(argus.unit_check) { // hipSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, &hc_coeff, &hs_coeff, x1, y1)); // hipSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, dc_coeff, ds_coeff, x2, y2)); // Copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx_val_1.data(), dx_val_1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hx_val_2.data(), dx_val_2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * size, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * size, hipMemcpyDeviceToHost)); // CPU for(int64_t i = 0; i < nnz; ++i) { I idx = hx_ind[i] - idxBase; T x = hx_val_gold[i]; T y = hy_gold[idx]; hx_val_gold[i] = testing_mult(hc_coeff, x) + testing_mult(hs_coeff, y); hy_gold[idx] = testing_mult(hc_coeff, y) - testing_mult(hs_coeff, x); } // Verify results against host unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_1.data()); unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_2.data()); unit_check_general(1, size, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, size, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, &hc_coeff, &hs_coeff, x1, y1)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseRot(handle, &hc_coeff, &hs_coeff, x1, y1)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = roti_gflop_count(nnz); double gbyte_count = roti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpVec(x2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnVec(y2)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_ROT_HPP ./clients/include/testing_gtsv.hpp0000664000175100017510000002160015176134511017423 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GTSV2_HPP #define TESTING_GTSV2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gtsv2_bad_arg(void) { // Dont do bad argument checking for cuda #if(!defined(CUDART_VERSION)) int safe_size = 100; int m = 10; int n = 10; int ldb = m; // Create handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); void* dbuf = (void*)dbuf_managed.get(); size_t bsize; // gtsv buffer size verify_hipsparse_status_invalid_handle( hipsparseXgtsv2_bufferSizeExt(nullptr, m, n, ddl, dd, ddu, dB, ldb, &bsize)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_bufferSizeExt(handle, -1, n, ddl, dd, ddu, dB, ldb, &bsize), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_bufferSizeExt(handle, m, -1, ddl, dd, ddu, dB, ldb, &bsize), "Error: n is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, -1, &bsize), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, nullptr), "Error: bsize is nullptr"); // gtsv verify_hipsparse_status_invalid_handle( hipsparseXgtsv2(nullptr, m, n, ddl, dd, ddu, dB, ldb, dbuf)); verify_hipsparse_status_invalid_value( hipsparseXgtsv2(handle, -1, n, ddl, dd, ddu, dB, ldb, dbuf), "Error: m is invalid"); verify_hipsparse_status_invalid_value( hipsparseXgtsv2(handle, m, -1, ddl, dd, ddu, dB, ldb, dbuf), "Error: n is invalid"); verify_hipsparse_status_invalid_value(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, -1, dbuf), "Error: ldb is invalid"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, (const T*)nullptr, dd, ddu, dB, ldb, dbuf), "Error: ddl is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, (const T*)nullptr, ddu, dB, ldb, dbuf), "Error: dd is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, dd, (const T*)nullptr, dB, ldb, dbuf), "Error: ddu is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, (T*)nullptr, ldb, dbuf), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, nullptr), "Error: bsize is nullptr"); #endif } template hipsparseStatus_t testing_gtsv2(Arguments argus) { int m = argus.M; int n = argus.N; // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; int ldb = 2 * m; // Host structures std::vector hdl(m, make_DataType(1)); std::vector hd(m, make_DataType(2)); std::vector hdu(m, make_DataType(1)); std::vector hB(ldb * n, make_DataType(3)); hdl[0] = make_DataType(0); hdu[m - 1] = make_DataType(0); std::vector hB_original = hB; // allocate memory on device auto ddl_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dd_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto ddu_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * m), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * ldb * n), device_free}; T* ddl = (T*)ddl_managed.get(); T* dd = (T*)dd_managed.get(); T* ddu = (T*)ddu_managed.get(); T* dB = (T*)dB_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(ddl, hdl.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dd, hd.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ddu, hdu.data(), sizeof(T) * m, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * ldb * n, hipMemcpyHostToDevice)); // Query SparseToDense buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR( hipsparseXgtsv2_bufferSizeExt(handle, m, n, ddl, dd, ddu, dB, ldb, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hB.data(), dB, sizeof(T) * ldb * n, hipMemcpyDeviceToHost)); // Check std::vector hresult = hB_original; for(int j = 0; j < n; j++) { hresult[ldb * j] = testing_mult(hd[0], hB[ldb * j]) + testing_mult(hdu[0], hB[ldb * j + 1]); hresult[ldb * j + m - 1] = testing_mult(hdl[m - 1], hB[ldb * j + m - 2]) + testing_mult(hd[m - 1], hB[ldb * j + m - 1]); for(int i = 1; i < m - 1; i++) { hresult[ldb * j + i] = testing_mult(hdl[i], hB[ldb * j + i - 1]) + testing_mult(hd[i], hB[ldb * j + i]) + testing_mult(hdu[i], hB[ldb * j + i + 1]); } } unit_check_near(m, n, ldb, hB_original.data(), hresult.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgtsv2(handle, m, n, ddl, dd, ddu, dB, ldb, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gtsv_gbyte_count(m, n); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } CHECK_HIP_ERROR(hipFree(buffer)); return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GTSV2_HPP ./clients/include/testing_roti.hpp0000664000175100017510000002261615176134511017425 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_ROTI_HPP #define TESTING_ROTI_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_roti_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; T c = 3.7; T s = 1.2; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_value( hipsparseXroti(handle, -1, dx_val, dx_ind, dy, &c, &s, idx_base), "Error: nnz is invalid"); // cusparse returns success when passed nullptrs #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, (int*)nullptr, dy, &c, &s, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, (T*)nullptr, dx_ind, dy, &c, &s, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, (T*)nullptr, &c, &s, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, dy, (T*)nullptr, &s, idx_base), "Error: c is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXroti(handle, nnz, dx_val, dx_ind, dy, &c, (T*)nullptr, idx_base), "Error: s is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXroti(nullptr, nnz, dx_val, dx_ind, dy, &c, &s, idx_base)); #endif } template hipsparseStatus_t testing_roti(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; T c = argus.get_alpha(); T s = argus.get_beta(); hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val_1(nnz); std::vector hx_val_2(nnz); std::vector hx_val_gold(nnz); std::vector hy_1(N); std::vector hy_2(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val_1, 1, nnz); hipsparseInit(hy_1, 1, N); hx_val_2 = hx_val_1; hx_val_gold = hx_val_1; hy_2 = hy_1; hy_gold = hy_1; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dx_val_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dy_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; auto dc_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto ds_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val_1 = (T*)dx_val_1_managed.get(); T* dx_val_2 = (T*)dx_val_2_managed.get(); T* dy_1 = (T*)dy_1_managed.get(); T* dy_2 = (T*)dy_2_managed.get(); T* dc = (T*)dc_managed.get(); T* ds = (T*)ds_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val_1, hx_val_1.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_1, hy_1.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIP_ERROR( hipMemcpy(dx_val_2, hx_val_2.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy_2, hy_2.data(), sizeof(T) * N, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dc, &c, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(ds, &s, sizeof(T), hipMemcpyHostToDevice)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_2, dx_ind, dy_2, dc, ds, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR( hipMemcpy(hx_val_1.data(), dx_val_1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hx_val_2.data(), dx_val_2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_1.data(), dy_1, sizeof(T) * N, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hy_2.data(), dy_2, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { int idx = hx_ind[i] - idx_base; T x = hx_val_gold[i]; T y = hy_gold[idx]; hx_val_gold[i] = c * x + s * y; hy_gold[idx] = c * y - s * x; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_1.data()); unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val_2.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_1.data()); unit_check_general(1, N, 1, hy_gold.data(), hy_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR( hipsparseXroti(handle, nnz, dx_val_1, dx_ind, dy_1, &c, &s, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = roti_gflop_count(nnz); double gbyte_count = roti_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_ROTI_HPP ./clients/include/testing_bsrsm2.hpp0000664000175100017510000015310615176134511017657 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRSM2_HPP #define TESTING_BSRSM2_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrsm2_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int mb = 100; int nrhs = 100; int nnzb = 100; int block_dim = 100; int safe_size = 100; float alpha = 0.6; int ldb = 100; int ldx = 100; hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transX = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseSolvePolicy_t policy = HIPSPARSE_SOLVE_POLICY_USE_LEVEL; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_info(new bsrsm2_struct); bsrsm2Info_t info = unique_ptr_info->info; auto dptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dX_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dptr = (int*)dptr_managed.get(); int* dcol = (int*)dcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dX = (float*)dX_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // testing hipsparseXbsrsm2_bufferSize int size; verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_bufferSize(nullptr, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, &size)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, nullptr, dval, dptr, dcol, block_dim, info, &size), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, (float*)nullptr, dptr, dcol, block_dim, info, &size), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, nullptr, dcol, block_dim, info, &size), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, nullptr, block_dim, info, &size), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, nullptr, &size), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_bufferSize(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, nullptr), "Error: size is nullptr"); // testing hipsparseXbsrsm2_analysis verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_analysis(nullptr, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, nullptr, dval, dptr, dcol, block_dim, info, policy, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, (const float*)nullptr, dptr, dcol, block_dim, info, policy, dbuf), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, nullptr, dcol, block_dim, info, policy, dbuf), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, nullptr, block_dim, info, policy, dbuf), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, nullptr, policy, dbuf), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_analysis(handle, dirA, transA, transX, mb, nrhs, nnzb, descr, dval, dptr, dcol, block_dim, info, policy, nullptr), "Error: dbuf is nullptr"); // testing hipsparseXbsrsm2_solve verify_hipsparse_status_invalid_handle(hipsparseXbsrsm2_solve(nullptr, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, (const float*)nullptr, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, nullptr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, (const float*)nullptr, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dval is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, nullptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, nullptr, block_dim, info, dB, ldb, dX, ldx, policy, dbuf), "Error: dcol is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, nullptr, dB, ldb, dX, ldx, policy, dbuf), "Error: info is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, (const float*)nullptr, ldb, dX, ldx, policy, dbuf), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, (float*)nullptr, ldx, policy, dbuf), "Error: dX is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrsm2_solve(handle, dirA, transA, transX, mb, nrhs, nnzb, &alpha, descr, dval, dptr, dcol, block_dim, info, dB, ldb, dX, ldx, policy, nullptr), "Error: dbuf is nullptr"); #endif } template hipsparseStatus_t testing_bsrsm2(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) int m = argus.M; int nrhs = argus.N; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); hipsparseDirection_t dir = argus.dirA; hipsparseIndexBase_t idx_base = argus.baseA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transX = argus.transB; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; std::unique_ptr unique_ptr_bsrsm2_info(new bsrsm2_struct); bsrsm2Info_t info = unique_ptr_bsrsm2_info->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, m, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } int mb = (m + block_dim - 1) / block_dim; int ldb = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int ldx = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int64_t nrowB = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? mb * block_dim : nrhs; int64_t ncolB = (transX == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? nrhs : mb * block_dim; int64_t nrowX = nrowB; int64_t ncolX = ncolB; std::vector hB(nrowB * ncolB); std::vector hX_1(nrowX * ncolX); std::vector hX_2(nrowX * ncolX); std::vector hX_gold(nrowX * ncolX); hipsparseInit(hB, nrowB, ncolB); // Allocate memory on device auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowB * ncolB), device_free}; auto dX_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowX * ncolX), device_free}; auto dX_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nrowX * ncolX), device_free}; auto dalpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto dpos_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); T* dB = (T*)dB_managed.get(); T* dX_1 = (T*)dX_1_managed.get(); T* dX_2 = (T*)dX_2_managed.get(); T* dalpha = (T*)dalpha_managed.get(); int* dposition = (int*)dpos_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptr, hcsr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_ind, hcsr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_val, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nrowB * ncolB, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dalpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); // Convert to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dir, m, m, descr, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_row_ptr, &nnzb)); auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dir, m, m, descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind, block_dim, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind)); // Obtain bsrsm2 buffer size int bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_bufferSize(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // bsrsm2 analysis CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_analysis(handle, dir, transA, transX, mb, nrhs, nnzb, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); int pos_analysis; hipsparseXbsrsm2_zeroPivot(handle, info, &pos_analysis); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); int hposition_1; hipsparseStatus_t pivot_status_1 = hipsparseXbsrsm2_zeroPivot(handle, info, &hposition_1); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, dalpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_2, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); hipsparseStatus_t pivot_status_2 = hipsparseXbsrsm2_zeroPivot(handle, info, dposition); // Copy output from device to CPU int hposition_2; CHECK_HIP_ERROR( hipMemcpy(hX_1.data(), dX_1, sizeof(T) * nrowX * ncolX, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hX_2.data(), dX_2, sizeof(T) * nrowX * ncolX, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(&hposition_2, dposition, sizeof(int), hipMemcpyDeviceToHost)); // Host bsrsm2 std::vector hbsr_row_ptr(mb + 1); std::vector hbsr_col_ind(nnzb); std::vector hbsr_val(nnzb * block_dim * block_dim); CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptr.data(), dbsr_row_ptr, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hbsr_col_ind.data(), dbsr_col_ind, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_val.data(), dbsr_val, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); int struct_position_gold; int numeric_position_gold; CHECK_HIP_ERROR(hipDeviceSynchronize()); host_bsrsm(mb, nrhs, nnzb, dir, transA, transX, h_alpha, hbsr_row_ptr.data(), hbsr_col_ind.data(), hbsr_val.data(), block_dim, hB.data(), ldb, hX_gold.data(), ldx, HIPSPARSE_DIAG_TYPE_NON_UNIT, HIPSPARSE_FILL_MODE_LOWER, idx_base, &struct_position_gold, &numeric_position_gold); unit_check_general(1, 1, 1, &struct_position_gold, &pos_analysis); unit_check_general(1, 1, 1, &numeric_position_gold, &hposition_1); unit_check_general(1, 1, 1, &numeric_position_gold, &hposition_2); if(hposition_1 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_1, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } if(hposition_2 != -1) { verify_hipsparse_status_zero_pivot(pivot_status_2, "expected HIPSPARSE_STATUS_ZERO_PIVOT"); return HIPSPARSE_STATUS_SUCCESS; } unit_check_near(nrowX, ncolX, ldx, hX_gold.data(), hX_1.data()); unit_check_near(nrowX, ncolX, ldx, hX_gold.data(), hX_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrsm2_solve(handle, dir, transA, transX, mb, nrhs, nnzb, &h_alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, info, dB, ldb, dX_1, ldx, HIPSPARSE_SOLVE_POLICY_USE_LEVEL, dbuffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = csrsv_gflop_count(m, size_t(nnzb) * block_dim * block_dim, HIPSPARSE_DIAG_TYPE_NON_UNIT) * nrhs; double gbyte_count = bsrsv_gbyte_count(mb, nnzb, block_dim) * nrhs; double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::nnz, nnzb * block_dim * block_dim, display_key_t::nrhs, nrhs, display_key_t::block_dim, block_dim, display_key_t::alpha, h_alpha, display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transX, hipsparse_operation2string(transX), display_key_t::diag_type, hipsparse_diagtype2string(HIPSPARSE_DIAG_TYPE_NON_UNIT), display_key_t::fill_mode, hipsparse_fillmode2string(HIPSPARSE_FILL_MODE_LOWER), display_key_t::solve_policy, hipsparse_solvepolicy2string(HIPSPARSE_SOLVE_POLICY_USE_LEVEL), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRSV2_HPP ./clients/include/testing_csrgemm2_b.hpp0000664000175100017510000014501215176134511020464 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2019 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSRGEMM2_B_HPP #define TESTING_CSRGEMM2_B_HPP #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_csrgemm2_b_bad_arg(void) { #if(!defined(CUDART_VERSION)) int M = 1; int N = 1; int nnz_D = 1; int safe_size = 1; T beta = 1.0; hipsparseStatus_t status; size_t size; int nnz_C; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = unique_ptr_descr_D->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; auto dDptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dDcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dDval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int* dDptr = (int*)dDptr_managed.get(); int* dDcol = (int*)dDcol_managed.get(); T* dDval = (T*)dDval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); void* dbuffer = (void*)dbuffer_managed.get(); std::vector hcsr_row_ptr_C(M + 1); hcsr_row_ptr_C[0] = 0; hcsr_row_ptr_C[1] = 1; CHECK_HIP_ERROR( hipMemcpy(dCptr, hcsr_row_ptr_C.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); // Scenario: alpha == 0 and beta != 0 // testing hipsparseXcsrgemm2_bufferSizeExt // testing for(nullptr == handle) { status = hipsparseXcsrgemm2_bufferSizeExt(nullptr, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, dDcol, info, &size); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == beta) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, (T*)nullptr, descr_D, nnz_D, dDptr, dDcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); } // testing for(nullptr == descr_D) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, nullptr, nnz_D, dDptr, dDcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: descr_D is nullptr"); } // testing for(nullptr == dDptr) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, nullptr, dDcol, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dDptr is nullptr"); } // testing for(nullptr == dDcol) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, nullptr, info, &size); verify_hipsparse_status_invalid_pointer(status, "Error: dDcol is nullptr"); } // testing for(nullptr == info) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, dDcol, nullptr, &size); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing for(nullptr == size) { status = hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, &beta, descr_D, nnz_D, dDptr, dDcol, info, nullptr); verify_hipsparse_status_invalid_pointer(status, "Error: size is nullptr"); } // testing hipsparseXcsrgemm2Nnz // testing for(nullptr == handle) { status = hipsparseXcsrgemm2Nnz(nullptr, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == descr_D) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr, nnz_D, dDptr, dDcol, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_D is nullptr"); } // testing for(nullptr == dDptr) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, nullptr, dDcol, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDptr is nullptr"); } // testing for(nullptr == dDcol) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, nullptr, descr_C, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDcol is nullptr"); } // testing for(nullptr == descr_C) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, nullptr, dCptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == dCptr) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, nullptr, &nnz_C, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == nnz_C) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, nullptr, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: nnz_C is nullptr"); } // testing for(nullptr == info) { status = hipsparseXcsrgemm2Nnz(handle, M, N, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, &nnz_C, nullptr, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } // testing hipsparseXcsrgemm2 // testing for(nullptr == handle) { status = hipsparseXcsrgemm2(nullptr, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_handle(status); } // testing for(nullptr == beta) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, (T*)nullptr, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: beta is nullptr"); } // testing for(nullptr == descr_D) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, nullptr, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_D is nullptr"); } // testing for(nullptr == dDval) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, (T*)nullptr, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDval is nullptr"); } // testing for(nullptr == dDptr) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, nullptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDptr is nullptr"); } // testing for(nullptr == dDcol) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, nullptr, descr_C, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dDcol is nullptr"); } // testing for(nullptr == descr_C) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, nullptr, dCval, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: descr_C is nullptr"); } // testing for(nullptr == dCval) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, (T*)nullptr, dCptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCval is nullptr"); } // testing for(nullptr == dCptr) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, nullptr, dCcol, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCptr is nullptr"); } // testing for(nullptr == dCcol) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, nullptr, info, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: dCcol is nullptr"); } // testing for(nullptr == info) { status = hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, nullptr, 0, (T*)nullptr, nullptr, nullptr, &beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, nullptr, dbuffer); verify_hipsparse_status_invalid_pointer(status, "Error: info is nullptr"); } #endif } template hipsparseStatus_t testing_csrgemm2_b(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int M = argus.M; int N = argus.N; hipsparseIndexBase_t idx_base_C = argus.baseC; hipsparseIndexBase_t idx_base_D = argus.baseD; std::string filename = argus.filename; T beta = make_DataType(argus.beta); T* h_beta = β std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr_A(new descr_struct); hipsparseMatDescr_t descr_A = unique_ptr_descr_A->descr; std::unique_ptr unique_ptr_descr_B(new descr_struct); hipsparseMatDescr_t descr_B = unique_ptr_descr_B->descr; std::unique_ptr unique_ptr_descr_C(new descr_struct); hipsparseMatDescr_t descr_C = unique_ptr_descr_C->descr; std::unique_ptr unique_ptr_descr_D(new descr_struct); hipsparseMatDescr_t descr_D = unique_ptr_descr_D->descr; std::unique_ptr unique_ptr_csrgemm2(new csrgemm2_struct); csrgemm2Info_t info = unique_ptr_csrgemm2->info; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_C, idx_base_C)); CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr_D, idx_base_D)); srand(12345ULL); // Host structures std::vector hcsr_row_ptr_D; std::vector hcsr_col_ind_D; std::vector hcsr_val_D; // Read or construct CSR matrix int nnz_D = 0; if(!generate_csr_matrix( filename, M, N, nnz_D, hcsr_row_ptr_D, hcsr_col_ind_D, hcsr_val_D, idx_base_D)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hcsr_row_ptr_A; std::vector hcsr_col_ind_A; std::vector hcsr_val_A; std::vector hcsr_row_ptr_B; std::vector hcsr_col_ind_B; std::vector hcsr_val_B; // Allocate memory on device int one = 1; int safe_nnz_D = std::max(nnz_D, one); auto dDptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dDcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_D), device_free}; auto dDval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_D), device_free}; auto dCptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (M + 1)), device_free}; auto dbeta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; int* dDptr = (int*)dDptr_managed.get(); int* dDcol = (int*)dDcol_managed.get(); T* dDval = (T*)dDval_managed.get(); int* dCptr = (int*)dCptr_managed.get(); T* dbeta = (T*)dbeta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(dDptr, hcsr_row_ptr_D.data(), sizeof(int) * (M + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dDcol, hcsr_col_ind_D.data(), sizeof(int) * nnz_D, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dDval, hcsr_val_D.data(), sizeof(T) * nnz_D, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbeta, h_beta, sizeof(T), hipMemcpyHostToDevice)); // Obtain csrgemm2 buffer size size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2_bufferSizeExt(handle, M, N, 0, (T*)nullptr, descr_A, 0, nullptr, nullptr, descr_B, 0, nullptr, nullptr, h_beta, descr_D, nnz_D, dDptr, dDcol, info, &bufferSize)); // Allocate buffer on the device auto dbuffer_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * bufferSize), device_free}; void* dbuffer = (void*)dbuffer_managed.get(); // csrgemm2 nnz // hipsparse pointer mode host int hnnz_C_1; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, 0, descr_A, 0, nullptr, nullptr, descr_B, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, &hnnz_C_1, info, dbuffer)); // Allocate result matrix int safe_nnz_C = std::max(hnnz_C_1, one); auto dCcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_nnz_C), device_free}; auto dCval_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_nnz_C), device_free}; int* dCcol = (int*)dCcol_managed.get(); T* dCval = (T*)dCval_managed.get(); if(argus.unit_check) { // hipsparse pointer mode device auto dnnz_C_managed = hipsparse_unique_ptr{device_malloc(sizeof(int)), device_free}; int* dnnz_C = (int*)dnnz_C_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2Nnz(handle, M, N, 0, descr_A, 0, nullptr, nullptr, descr_B, 0, nullptr, nullptr, descr_D, nnz_D, dDptr, dDcol, descr_C, dCptr, dnnz_C, info, dbuffer)); // Compute csrgemm host solution std::vector hcsr_row_ptr_C_gold(M + 1); double cpu_time_used = get_time_us(); int nnz_C_gold = host_csrgemm2_nnz(M, N, 0, (T*)nullptr, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), h_beta, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_row_ptr_C_gold.data(), HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ZERO, idx_base_C, idx_base_D); // If nnz_C == 0, we are done if(nnz_C_gold == 0) { return HIPSPARSE_STATUS_SUCCESS; } std::vector hcsr_col_ind_C_gold(nnz_C_gold); std::vector hcsr_val_C_gold(nnz_C_gold); host_csrgemm2(M, N, 0, (T*)nullptr, hcsr_row_ptr_A.data(), hcsr_col_ind_A.data(), hcsr_val_A.data(), hcsr_row_ptr_B.data(), hcsr_col_ind_B.data(), hcsr_val_B.data(), h_beta, hcsr_row_ptr_D.data(), hcsr_col_ind_D.data(), hcsr_val_D.data(), hcsr_row_ptr_C_gold.data(), hcsr_col_ind_C_gold.data(), hcsr_val_C_gold.data(), HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ZERO, idx_base_C, idx_base_D); cpu_time_used = get_time_us() - cpu_time_used; // Copy output from device to CPU int hnnz_C_2; CHECK_HIP_ERROR(hipMemcpy(&hnnz_C_2, dnnz_C, sizeof(int), hipMemcpyDeviceToHost)); // Check nnz of C unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_1); unit_check_general(1, 1, 1, &nnz_C_gold, &hnnz_C_2); // Compute csrgemm2 CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, descr_A, 0, (T*)nullptr, nullptr, nullptr, descr_B, 0, (T*)nullptr, nullptr, nullptr, h_beta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer)); // Copy output from device to CPU std::vector hcsr_row_ptr_C(M + 1); std::vector hcsr_col_ind_C(nnz_C_gold); std::vector hcsr_val_C_1(nnz_C_gold); std::vector hcsr_val_C_2(nnz_C_gold); CHECK_HIP_ERROR( hipMemcpy(hcsr_row_ptr_C.data(), dCptr, sizeof(int) * (M + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( hcsr_col_ind_C.data(), dCcol, sizeof(int) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_1.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemset(dCval, 0, sizeof(T) * nnz_C_gold)); // Check structure and entries of C unit_check_general(1, M + 1, 1, hcsr_row_ptr_C_gold.data(), hcsr_row_ptr_C.data()); unit_check_general(1, nnz_C_gold, 1, hcsr_col_ind_C_gold.data(), hcsr_col_ind_C.data()); unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_1.data()); #ifdef __HIP_PLATFORM_AMD__ // Device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXcsrgemm2(handle, M, N, 0, (T*)nullptr, descr_A, 0, (T*)nullptr, nullptr, nullptr, descr_B, 0, (T*)nullptr, nullptr, nullptr, dbeta, descr_D, nnz_D, dDval, dDptr, dDcol, descr_C, dCval, dCptr, dCcol, info, dbuffer)); CHECK_HIP_ERROR( hipMemcpy(hcsr_val_C_2.data(), dCval, sizeof(T) * nnz_C_gold, hipMemcpyDeviceToHost)); // Check device pointer results unit_check_near(1, nnz_C_gold, 1, hcsr_val_C_gold.data(), hcsr_val_C_2.data()); #endif } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_CSRGEMM2_B_HPP ./clients/include/hipsparse_test.hpp0000664000175100017510000002025415176134305017745 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef HIPSPARSE_TEST_HPP #define HIPSPARSE_TEST_HPP #include "hipsparse_arguments.hpp" #include "hipsparse_test_cleanup.hpp" #include #include #include #include #include #include #include #ifdef GOOGLE_TEST #include // The tests are instantiated by filtering through the HipSPARSE_Data stream // The filter is by category and by the type_filter() and function_filter() // functions in the testclass #define INSTANTIATE_TEST_CATEGORY(testclass, categ0ry) \ INSTANTIATE_TEST_SUITE_P( \ categ0ry, \ testclass, \ testing::ValuesIn(HipSPARSE_TestData::begin([](const Arguments& arg) { \ return !strcmp(arg.category, #categ0ry) \ && testclass::type_filter(arg) \ && testclass::function_filter(arg); \ }), \ HipSPARSE_TestData::end()), \ testclass::PrintToStringParamName()); #if defined(GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST) #define HIPSPARSE_ALLOW_UNINSTANTIATED_GTEST(testclass) \ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(testclass); #else #define HIPSPARSE_ALLOW_UNINSTANTIATED_GTEST(testclass) #endif // Instantiate all test categories #define INSTANTIATE_TEST_CATEGORIES(testclass) \ HIPSPARSE_ALLOW_UNINSTANTIATED_GTEST(testclass) \ INSTANTIATE_TEST_CATEGORY(testclass, quick) \ INSTANTIATE_TEST_CATEGORY(testclass, pre_checkin) \ INSTANTIATE_TEST_CATEGORY(testclass, nightly) \ INSTANTIATE_TEST_CATEGORY(testclass, stress) \ INSTANTIATE_TEST_CATEGORY(testclass, known_bug) /* ============================================================================================ */ /*! \brief Normalized test name to conform to Google Tests */ // Template parameter is used to generate multiple instantiations template class HipSPARSE_TestName { std::ostringstream str; static auto& get_table() { // Placed inside function to avoid dependency on initialization order static std::unordered_map* table = test_cleanup::allocate(&table); return *table; } public: // Convert stream to normalized Google Test name // rvalue reference qualified so that it can only be called once // The name should only be generated once before the stream is destroyed operator std::string() && { // This table is private to each instantation of HipSPARSE_TestName auto& table = get_table(); std::string name(str.str()); if(name == "") name = "1"; // Warn about unset letter parameters if(name.find('*') != name.npos) fputs("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" "Warning: Character * found in name." " This means a required letter parameter\n" "(e.g., transA, diag, etc.) has not been set in the YAML file." " Check the YAML file.\n" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", stderr); // Replace non-alphanumeric characters with letters std::replace(name.begin(), name.end(), '-', 'n'); // minus std::replace(name.begin(), name.end(), '.', 'p'); // decimal point // Complex (A,B) is replaced with ArBi name.erase(std::remove(name.begin(), name.end(), '('), name.end()); std::replace(name.begin(), name.end(), ',', 'r'); std::replace(name.begin(), name.end(), ')', 'i'); // If parameters are repeated, append an incrementing suffix auto p = table.find(name); if(p != table.end()) name += "_t" + std::to_string(++p->second); else table[name] = 1; return name; } // Stream output operations template // Lvalue LHS friend HipSPARSE_TestName& operator<<(HipSPARSE_TestName& name, U&& obj) { name.str << std::forward(obj); return name; } template // Rvalue LHS friend HipSPARSE_TestName&& operator<<(HipSPARSE_TestName&& name, U&& obj) { name.str << std::forward(obj); return std::move(name); } HipSPARSE_TestName() = default; HipSPARSE_TestName(const HipSPARSE_TestName&) = delete; HipSPARSE_TestName& operator=(const HipSPARSE_TestName&) = delete; }; // ---------------------------------------------------------------------------- // HipSPARSE_Test base class. All non-legacy hipSPARSE Google tests derive from it. // It defines a type_filter_functor() and a PrintToStringParamName class // which calls name_suffix() in the derived class to form the test name suffix. // ---------------------------------------------------------------------------- template class FILTER> class HipSPARSE_Test : public testing::TestWithParam { protected: // This template functor returns true if the type arguments are valid. // It converts a FILTER specialization to bool to test type matching. template struct type_filter_functor { bool operator()(const Arguments&) { return static_cast(FILTER{}); } }; public: // Wrapper functor class which calls name_suffix() struct PrintToStringParamName { std::string operator()(const testing::TestParamInfo& info) const { return TEST::name_suffix(info.param); } }; }; #endif // GOOGLE_TEST // ---------------------------------------------------------------------------- // Error case which returns false when converted to bool. A void specialization // of the FILTER class template above, should be derived from this class, in // order to indicate that the type combination is invalid. // ---------------------------------------------------------------------------- struct hipsparse_test_invalid { // Return false to indicate the type combination is invalid, for filtering explicit operator bool() { return false; } // If this specialization is actually called, print fatal error message void operator()(const Arguments&) { static constexpr char msg[] = "Internal error: Test called with invalid types\n"; #ifdef GOOGLE_TEST FAIL() << msg; #else fputs(msg, stderr); exit(EXIT_FAILURE); #endif } }; #endif // HIPSPARSE_TEST_HPP./clients/include/testing_bsrmm.hpp0000664000175100017510000011617015176134511017567 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_BSRMM_HPP #define TESTING_BSRMM_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_bsrmm_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int mb = 100; int n = 100; int kb = 100; int nnzb = 100; int block_dim = 100; int ldb = 100; int ldc = 100; int safe_size = 100; T alpha = make_DataType(0.6); T beta = make_DataType(0.2); hipsparseDirection_t dirA = HIPSPARSE_DIRECTION_ROW; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dC_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); T* dB = (T*)dB_managed.get(); T* dC = (T*)dC_managed.get(); verify_hipsparse_status_invalid_handle(hipsparseXbsrmm((hipsparseHandle_t) nullptr, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc)); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, (T*)nullptr, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, (hipsparseMatDescr_t) nullptr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, (T*)nullptr, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, (int*)nullptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, (int*)nullptr, block_dim, dB, ldb, &beta, dC, ldc), "Error: dbsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, (T*)nullptr, ldb, &beta, dC, ldc), "Error: dB is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, (T*)nullptr, dC, ldc), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, (T*)nullptr, ldc), "Error: dC is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, -1, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: mb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, -1, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, -1, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: kb is invalid"); verify_hipsparse_status_invalid_size(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, 0, dB, ldb, &beta, dC, ldc), "Error: block_dim is invalid"); // Test not implemented (mapped to hiparse internal error) verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, HIPSPARSE_OPERATION_TRANSPOSE, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transA is not supported"); verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, transB, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transA is not supported"); verify_hipsparse_status_not_supported(hipsparseXbsrmm(handle, dirA, transA, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE, mb, n, kb, nnzb, &alpha, descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, block_dim, dB, ldb, &beta, dC, ldc), "Error: Passed value for transB is not supported"); #endif } template hipsparseStatus_t testing_bsrmm(const Arguments& argus) { int m = argus.M; int n = argus.N; int k = argus.K; int block_dim = argus.block_dim; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseDirection_t dirA = argus.dirA; hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseIndexBase_t idx_base = argus.baseA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_descr(new descr_struct); hipsparseMatDescr_t descr = unique_ptr_descr->descr; // Set matrix index base CHECK_HIPSPARSE_ERROR(hipsparseSetMatIndexBase(descr, idx_base)); if(m == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } srand(12345ULL); // Host structures std::vector csr_row_ptr; std::vector csr_col_ind; std::vector csr_val; // Read or construct CSR matrix int nnz = 0; if(!generate_csr_matrix(filename, m, k, nnz, csr_row_ptr, csr_col_ind, csr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } // m and k can be modifed if we read in a matrix from a file int mb = (m + block_dim - 1) / block_dim; int kb = (k + block_dim - 1) / block_dim; // Allocate memory on device for CSR matrix and BSR row pointer array auto dcsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_valA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dbsr_row_ptrA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; int* dcsr_row_ptrA = (int*)dcsr_row_ptrA_managed.get(); int* dcsr_col_indA = (int*)dcsr_col_indA_managed.get(); T* dcsr_valA = (T*)dcsr_valA_managed.get(); int* dbsr_row_ptrA = (int*)dbsr_row_ptrA_managed.get(); // Copy CSR from host to device CHECK_HIP_ERROR( hipMemcpy(dcsr_row_ptrA, csr_row_ptr.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dcsr_col_indA, csr_col_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dcsr_valA, csr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); // Convert CSR to BSR int nnzb; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsrNnz(handle, dirA, m, k, descr, dcsr_row_ptrA, dcsr_col_indA, block_dim, descr, dbsr_row_ptrA, &nnzb)); auto dbsr_col_indA_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_valA_managed = hipsparse_unique_ptr{ device_malloc(sizeof(T) * nnzb * block_dim * block_dim), device_free}; int* dbsr_col_indA = (int*)dbsr_col_indA_managed.get(); T* dbsr_valA = (T*)dbsr_valA_managed.get(); CHECK_HIPSPARSE_ERROR(hipsparseXcsr2bsr(handle, dirA, m, k, descr, dcsr_valA, dcsr_row_ptrA, dcsr_col_indA, block_dim, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA)); // Host BSR matrix std::vector hbsr_row_ptrA(mb + 1); std::vector hbsr_col_indA(nnzb); std::vector hbsr_valA(nnzb * block_dim * block_dim); // Copy BSR matrix to host CHECK_HIP_ERROR(hipMemcpy( hbsr_row_ptrA.data(), dbsr_row_ptrA, sizeof(int) * (mb + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(hbsr_col_indA.data(), dbsr_col_indA, sizeof(int) * nnzb, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hbsr_valA.data(), dbsr_valA, sizeof(T) * nnzb * block_dim * block_dim, hipMemcpyDeviceToHost)); m = mb * block_dim; k = kb * block_dim; // Some matrix properties int ldb = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; int ldc = m; int ncol_B = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE ? n : k); int nnz_B = ldb * ncol_B; int nnz_C = ldc * n; // Allocate host memory for dense matrices std::vector hB(nnz_B); std::vector hC_1(nnz_C); std::vector hC_2(nnz_C); std::vector hC_gold(nnz_C); hipsparseInit(hB, ldb, ncol_B); hipsparseInit(hC_1, ldc, n); // copy vector is easy in STL; hC_gold = hC_1: save a copy in hy_gold which will be output of // CPU hC_gold = hC_1; hC_2 = hC_1; // allocate memory on device auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto dC_1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto dC_2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_C), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; T* dB = (T*)dB_managed.get(); T* dC_1 = (T*)dC_1_managed.get(); T* dC_2 = (T*)dC_2_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // Copy data from host to device CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_1, hC_1.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dC_2, hC_2.data(), sizeof(T) * nnz_C, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); if(argus.unit_check) { // Testing using host pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); // Testing using device pointer mode CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, d_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, d_beta, dC_2, ldc)); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy(hC_1.data(), dC_1, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hC_2.data(), dC_2, sizeof(T) * nnz_C, hipMemcpyDeviceToHost)); // Host bsrmm host_bsrmm(mb, n, kb, block_dim, dirA, transA, transB, h_alpha, hbsr_row_ptrA, hbsr_col_indA, hbsr_valA, hB, ldb, h_beta, hC_gold, ldc, idx_base); // Unit check unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_1.data()); unit_check_near(1, nnz_C, 1, hC_gold.data(), hC_2.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXbsrmm(handle, dirA, transA, transB, mb, n, kb, nnzb, &h_alpha, descr, dbsr_valA, dbsr_row_ptrA, dbsr_col_indA, block_dim, dB, ldb, &h_beta, dC_1, ldc)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = bsrmm_gflop_count(n, nnzb, block_dim, m * n, h_beta != make_DataType(0.0)); double gbyte_count = bsrmm_gbyte_count( mb, nnzb, block_dim, k * n, m * n, h_beta != make_DataType(0.0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::direction, dirA, display_key_t::transA, transA, display_key_t::transB, transB, display_key_t::nnzb, nnzb, display_key_t::block_dim, block_dim, display_key_t::nnzB, nnz_B, display_key_t::nnzC, nnz_C, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_BSRMM_HPP ./clients/include/hipsparse_arguments.hpp0000664000175100017510000004107515176134511020776 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ /*! \file * \brief hipsparse_arguments.hpp provides a class to parse command arguments in both, * clients and gtest. */ #pragma once #include #include #include #include #include "hipsparse_arguments_support.hpp" #include "hipsparse_datatype2string.hpp" template static T convert_alpha_beta(double r, double i) { return static_cast(r); } struct Arguments { int M; int N; int K; int nnz; int block_dim; int row_block_dimA; int col_block_dimA; int row_block_dimB; int col_block_dimB; int lda; int ldb; int ldc; int batch_count; hipsparseIndexType_t index_type_I; hipsparseIndexType_t index_type_J; hipDataType compute_type; double alpha; double alphai; double beta; double betai; double threshold; double percentage; double c; double s; hipsparseOperation_t transA; hipsparseOperation_t transB; hipsparseIndexBase_t baseA; hipsparseIndexBase_t baseB; hipsparseIndexBase_t baseC; hipsparseIndexBase_t baseD; hipsparseAction_t action; hipsparseHybPartition_t part; hipsparseDiagType_t diag_type; hipsparseFillMode_t fill_mode; hipsparseSolvePolicy_t solve_policy; hipsparseDirection_t dirA; hipsparseOrder_t orderA; hipsparseOrder_t orderB; hipsparseOrder_t orderC; hipsparseFormat_t formatA; hipsparseFormat_t formatB; hipsparseCsr2CscAlg_t csr2csc_alg; hipsparseDenseToSparseAlg_t dense2sparse_alg; hipsparseSparseToDenseAlg_t sparse2dense_alg; hipsparseSDDMMAlg_t sddmm_alg; hipsparseSpGEMMAlg_t spgemm_alg; hipsparseSpMMAlg_t spmm_alg; hipsparseSpMVAlg_t spmv_alg; hipsparseSpSMAlg_t spsm_alg; hipsparseSpSVAlg_t spsv_alg; int numericboost; double boosttol; double boostval; double boostvali; int ell_width; int permute; int gtsv_alg; int gpsv_alg; int unit_check; int timing; int iters; char filename[192]; // nos2.bin, bmwcra_1.bin, etc char function[64]; // axpby, spmv_csr, etc char category[32]; // quick, pre_checkin, etc Arguments() { this->M = -1; this->N = -1; this->K = -1; this->nnz = -1; this->block_dim = 2; this->row_block_dimA = 2; this->col_block_dimA = 2; this->row_block_dimB = 2; this->col_block_dimB = 2; this->lda = -1; this->ldb = -1; this->ldc = -1; this->batch_count = -1; this->index_type_I = HIPSPARSE_INDEX_32I; this->index_type_J = HIPSPARSE_INDEX_32I; this->compute_type = HIP_R_32F; this->alpha = 0.0; this->alphai = 0.0; this->beta = 0.0; this->betai = 0.0; this->threshold = 0.0; this->percentage = 0.0; this->c = 1.0; this->s = 1.0; this->transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; this->baseA = HIPSPARSE_INDEX_BASE_ZERO; this->baseB = HIPSPARSE_INDEX_BASE_ZERO; this->baseC = HIPSPARSE_INDEX_BASE_ZERO; this->baseD = HIPSPARSE_INDEX_BASE_ZERO; this->action = HIPSPARSE_ACTION_NUMERIC; this->part = HIPSPARSE_HYB_PARTITION_AUTO; this->diag_type = HIPSPARSE_DIAG_TYPE_NON_UNIT; this->fill_mode = HIPSPARSE_FILL_MODE_LOWER; this->solve_policy = HIPSPARSE_SOLVE_POLICY_NO_LEVEL; this->dirA = HIPSPARSE_DIRECTION_ROW; this->orderA = HIPSPARSE_ORDER_COL; this->orderB = HIPSPARSE_ORDER_COL; this->orderC = HIPSPARSE_ORDER_COL; this->formatA = HIPSPARSE_FORMAT_COO; this->formatB = HIPSPARSE_FORMAT_COO; this->csr2csc_alg = csr2csc_alg_support::get_default_algorithm(); this->dense2sparse_alg = dense2sparse_alg_support::get_default_algorithm(); this->sparse2dense_alg = sparse2dense_alg_support::get_default_algorithm(); this->sddmm_alg = sddmm_alg_support::get_default_algorithm(); this->spgemm_alg = spgemm_alg_support::get_default_algorithm(); this->spmm_alg = spmm_alg_support::get_default_algorithm(); this->spmv_alg = spmv_alg_support::get_default_algorithm(); this->spsm_alg = spsm_alg_support::get_default_algorithm(); this->spsv_alg = spsv_alg_support::get_default_algorithm(); this->numericboost = 0; this->boosttol = 0.0; this->boostval = 1.0; this->boostvali = 0.0; this->ell_width = 0; this->permute = 0; this->gtsv_alg = 0; this->gpsv_alg = 0; this->unit_check = 1; this->timing = 0; this->iters = 10; this->filename[0] = '\0'; this->function[0] = '\0'; this->category[0] = '\0'; } template T get_alpha() const { return convert_alpha_beta(alpha, alphai); } template T get_beta() const { return convert_alpha_beta(beta, betai); } template T get_threshold() const { return threshold; } template T get_percentage() const { return percentage; } // Validate input format. // hipsparse_gentest.py is expected to conform to this format. // hipsparse_gentest.py uses hipsparse_common.yaml to generate this format. static void validate(std::istream& ifs) { auto error = [](auto name) { std::cerr << "Arguments field " << name << " does not match format.\n\n" << "Fatal error: Binary test data does match input format.\n" "Ensure that hipsparse_arguments.hpp and hipsparse_common.yaml\n" "define exactly the same Arguments, that hipsparse_gentest.py\n" "generates the data correctly, and that endianness is the same.\n"; abort(); }; char header[10]{}, trailer[10]{}; Arguments arg{}; ifs.read(header, sizeof(header)); ifs >> arg; ifs.read(trailer, sizeof(trailer)); if(strcmp(header, "hipSPARSE")) error("header"); else if(strcmp(trailer, "HIPsparse")) error("trailer"); auto check_func = [&, sig = (uint8_t)0](const auto& elem, auto name) mutable { static_assert(sizeof(elem) <= 255, "One of the fields of Arguments is too large (> 255 bytes)"); for(uint8_t i = 0; i < sizeof(elem); ++i) if(reinterpret_cast(&elem)[i] ^ sig ^ i) error(name); sig += 89; }; #define HIPSPARSE_FORMAT_CHECK(x) check_func(arg.x, #x) // Order is important HIPSPARSE_FORMAT_CHECK(M); HIPSPARSE_FORMAT_CHECK(N); HIPSPARSE_FORMAT_CHECK(K); HIPSPARSE_FORMAT_CHECK(nnz); HIPSPARSE_FORMAT_CHECK(block_dim); HIPSPARSE_FORMAT_CHECK(row_block_dimA); HIPSPARSE_FORMAT_CHECK(col_block_dimA); HIPSPARSE_FORMAT_CHECK(row_block_dimB); HIPSPARSE_FORMAT_CHECK(col_block_dimB); HIPSPARSE_FORMAT_CHECK(lda); HIPSPARSE_FORMAT_CHECK(ldb); HIPSPARSE_FORMAT_CHECK(ldc); HIPSPARSE_FORMAT_CHECK(batch_count); HIPSPARSE_FORMAT_CHECK(index_type_I); HIPSPARSE_FORMAT_CHECK(index_type_J); HIPSPARSE_FORMAT_CHECK(compute_type); HIPSPARSE_FORMAT_CHECK(alpha); HIPSPARSE_FORMAT_CHECK(alphai); HIPSPARSE_FORMAT_CHECK(beta); HIPSPARSE_FORMAT_CHECK(betai); HIPSPARSE_FORMAT_CHECK(threshold); HIPSPARSE_FORMAT_CHECK(percentage); HIPSPARSE_FORMAT_CHECK(c); HIPSPARSE_FORMAT_CHECK(s); HIPSPARSE_FORMAT_CHECK(transA); HIPSPARSE_FORMAT_CHECK(transB); HIPSPARSE_FORMAT_CHECK(baseA); HIPSPARSE_FORMAT_CHECK(baseB); HIPSPARSE_FORMAT_CHECK(baseC); HIPSPARSE_FORMAT_CHECK(baseD); HIPSPARSE_FORMAT_CHECK(action); HIPSPARSE_FORMAT_CHECK(part); HIPSPARSE_FORMAT_CHECK(diag_type); HIPSPARSE_FORMAT_CHECK(fill_mode); HIPSPARSE_FORMAT_CHECK(solve_policy); HIPSPARSE_FORMAT_CHECK(dirA); HIPSPARSE_FORMAT_CHECK(orderA); HIPSPARSE_FORMAT_CHECK(orderB); HIPSPARSE_FORMAT_CHECK(orderC); HIPSPARSE_FORMAT_CHECK(formatA); HIPSPARSE_FORMAT_CHECK(formatB); HIPSPARSE_FORMAT_CHECK(csr2csc_alg); HIPSPARSE_FORMAT_CHECK(dense2sparse_alg); HIPSPARSE_FORMAT_CHECK(sparse2dense_alg); HIPSPARSE_FORMAT_CHECK(sddmm_alg); HIPSPARSE_FORMAT_CHECK(spgemm_alg); HIPSPARSE_FORMAT_CHECK(spmm_alg); HIPSPARSE_FORMAT_CHECK(spmv_alg); HIPSPARSE_FORMAT_CHECK(spsm_alg); HIPSPARSE_FORMAT_CHECK(spsv_alg); HIPSPARSE_FORMAT_CHECK(numericboost); HIPSPARSE_FORMAT_CHECK(boosttol); HIPSPARSE_FORMAT_CHECK(boostval); HIPSPARSE_FORMAT_CHECK(boostvali); HIPSPARSE_FORMAT_CHECK(ell_width); HIPSPARSE_FORMAT_CHECK(permute); HIPSPARSE_FORMAT_CHECK(gtsv_alg); HIPSPARSE_FORMAT_CHECK(gpsv_alg); HIPSPARSE_FORMAT_CHECK(unit_check); HIPSPARSE_FORMAT_CHECK(timing); HIPSPARSE_FORMAT_CHECK(iters); HIPSPARSE_FORMAT_CHECK(filename); HIPSPARSE_FORMAT_CHECK(function); HIPSPARSE_FORMAT_CHECK(category); } void set_filename(const std::string& bin_file) { strncpy(this->filename, bin_file.c_str(), bin_file.length()); this->filename[bin_file.length()] = '\0'; } private: // Function to read Structures data from stream friend std::istream& operator>>(std::istream& str, Arguments& arg) { str.read(reinterpret_cast(&arg), sizeof(arg)); return str; } // print_value is for formatting different data types // Default output template static void print_value(std::ostream& str, const T& x) { str << x; } // Floating-point output static void print_value(std::ostream& str, double x) { if(std::isnan(x)) str << ".nan"; else if(std::isinf(x)) str << (x < 0 ? "-.inf" : ".inf"); else { char s[32]; snprintf(s, sizeof(s) - 2, "%.17g", x); // If no decimal point or exponent, append .0 char* end = s + strcspn(s, ".eE"); if(!*end) strcat(end, ".0"); str << s; } } // Character output static void print_value(std::ostream& str, char c) { char s[]{c, 0}; str << std::quoted(s, '\''); } // bool output static void print_value(std::ostream& str, bool b) { str << (b ? "true" : "false"); } // string output static void print_value(std::ostream& str, const char* s) { str << std::quoted(s); } // Function to print Arguments out to stream in YAML format // Google Tests uses this automatically to dump parameters friend std::ostream& operator<<(std::ostream& str, const Arguments& arg) { // delim starts as '{' opening brace and becomes ',' afterwards auto print = [&, delim = '{'](const char* name, auto x) mutable { str << delim << " " << name << ": "; print_value(str, x); delim = ','; }; print("filename", arg.filename); print("function", arg.function); print("category", arg.category); print("M", arg.M); print("N", arg.N); print("K", arg.K); print("nnz", arg.nnz); print("block_dim", arg.block_dim); print("row_block_dimA", arg.row_block_dimA); print("col_block_dimA", arg.col_block_dimA); print("row_block_dimB", arg.row_block_dimB); print("col_block_dimB", arg.col_block_dimB); print("lda", arg.lda); print("ldb", arg.ldb); print("ldc", arg.ldc); print("batch_count", arg.batch_count); print("index_type_I", hipsparse_indextype2string(arg.index_type_I)); print("index_type_J", hipsparse_indextype2string(arg.index_type_J)); print("compute_type", hipsparse_datatype2string(arg.compute_type)); print("alpha", arg.alpha); print("alphai", arg.alphai); print("beta", arg.beta); print("betai", arg.betai); print("threshold", arg.threshold); print("percentage", arg.percentage); print("c", arg.c); print("s", arg.s); print("transA", hipsparse_operation2string(arg.transA)); print("transB", hipsparse_operation2string(arg.transB)); print("baseA", hipsparse_indexbase2string(arg.baseA)); print("baseB", hipsparse_indexbase2string(arg.baseB)); print("baseC", hipsparse_indexbase2string(arg.baseC)); print("baseD", hipsparse_indexbase2string(arg.baseD)); print("action", hipsparse_action2string(arg.action)); print("part", hipsparse_partition2string(arg.part)); print("diag_type", hipsparse_diagtype2string(arg.diag_type)); print("fill_mode", hipsparse_fillmode2string(arg.fill_mode)); print("solve_policy", hipsparse_solvepolicy2string(arg.solve_policy)); print("dirA", hipsparse_direction2string(arg.dirA)); print("orderA", hipsparse_order2string(arg.orderA)); print("orderB", hipsparse_order2string(arg.orderB)); print("orderC", hipsparse_order2string(arg.orderC)); print("formatA", hipsparse_format2string(arg.formatA)); print("formatB", hipsparse_format2string(arg.formatB)); print("csr2csc_alg", hipsparse_csr2cscalg2string(arg.csr2csc_alg)); print("dense2sparse_alg", hipsparse_densetosparsealg2string(arg.dense2sparse_alg)); print("sparse2dense_alg", hipsparse_sparsetodensealg2string(arg.sparse2dense_alg)); print("sddmm_alg", hipsparse_sddmmalg2string(arg.sddmm_alg)); print("spgemm_alg", hipsparse_spgemmalg2string(arg.spgemm_alg)); print("spmm_alg", hipsparse_spmmalg2string(arg.spmm_alg)); print("spmv_alg", hipsparse_spmvalg2string(arg.spmv_alg)); print("spsm_alg", hipsparse_spsmalg2string(arg.spsm_alg)); print("spsv_alg", hipsparse_spsvalg2string(arg.spsv_alg)); print("csr2csc_alg", arg.csr2csc_alg); print("dense2sparse_alg", arg.dense2sparse_alg); print("sparse2dense_alg", arg.sparse2dense_alg); print("sddmm_alg", arg.sddmm_alg); print("spgemm_alg", arg.spgemm_alg); print("spmm_alg", arg.spmm_alg); print("spmv_alg", arg.spmv_alg); print("spsm_alg", arg.spsm_alg); print("spsv_alg", arg.spsv_alg); print("numeric_boost", arg.numericboost); print("boosttol", arg.boosttol); print("boostval", arg.boostval); print("boostvali", arg.boostvali); print("ell_width", arg.ell_width); print("permute", arg.permute); print("gtsv_alg", arg.gtsv_alg); print("gpsv_alg", arg.gpsv_alg); print("unit_check", arg.unit_check); print("timing", arg.timing); print("iters", arg.iters); return str << " }\n"; } }; ./clients/include/testing_gebsr2csr.hpp0000664000175100017510000006764315176134511020355 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_GEBSR2CSR_HPP #define TESTING_GEBSR2CSR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include #include using namespace hipsparse; using namespace hipsparse_test; template void testing_gebsr2csr_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION)) int m = 1; int n = 1; int safe_size = 1; int row_block_dim = 2; int col_block_dim = 2; hipsparseIndexBase_t csr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexBase_t bsr_idx_base = HIPSPARSE_INDEX_BASE_ZERO; hipsparseDirection_t dir = HIPSPARSE_DIRECTION_ROW; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); auto bsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto bsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto bsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto csr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (safe_size + 1)), device_free}; auto csr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto csr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; int* bsr_row_ptr = (int*)bsr_row_ptr_managed.get(); int* bsr_col_ind = (int*)bsr_col_ind_managed.get(); T* bsr_val = (T*)bsr_val_managed.get(); int* csr_row_ptr = (int*)csr_row_ptr_managed.get(); int* csr_col_ind = (int*)csr_col_ind_managed.get(); T* csr_val = (T*)csr_val_managed.get(); int local_ptr[2] = {0, 1}; CHECK_HIP_ERROR( hipMemcpy(bsr_row_ptr, local_ptr, sizeof(int) * (1 + 1), hipMemcpyHostToDevice)); verify_hipsparse_status_invalid_handle(hipsparseXgebsr2csr(nullptr, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind)); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, nullptr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, (T*)nullptr, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, nullptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, nullptr, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: bsr_col_ind is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, nullptr, csr_val, csr_row_ptr, csr_col_ind), "Error: csr_descr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, (T*)nullptr, csr_row_ptr, csr_col_ind), "Error: csr_val is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, nullptr, csr_col_ind), "Error: csr_row_ptr is nullptr"); verify_hipsparse_status_invalid_pointer(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, nullptr), "Error: csr_col_ind is nullptr"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, -1, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: m is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, -1, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: n is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, -1, col_block_dim, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: row_block_dim is invalid"); verify_hipsparse_status_invalid_size(hipsparseXgebsr2csr(handle, dir, m, n, bsr_descr, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, -1, csr_descr, csr_val, csr_row_ptr, csr_col_ind), "Error: col_block_dim is invalid"); #endif } template hipsparseStatus_t testing_gebsr2csr(Arguments argus) { int m = argus.M; int n = argus.N; int row_block_dim = argus.row_block_dimA; int col_block_dim = argus.col_block_dimA; hipsparseIndexBase_t csr_idx_base = argus.baseA; hipsparseIndexBase_t bsr_idx_base = argus.baseB; hipsparseDirection_t dir = argus.dirA; std::string filename = argus.filename; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; std::unique_ptr unique_ptr_csr_descr(new descr_struct); hipsparseMatDescr_t csr_descr = unique_ptr_csr_descr->descr; std::unique_ptr unique_ptr_bsr_descr(new descr_struct); hipsparseMatDescr_t bsr_descr = unique_ptr_bsr_descr->descr; hipsparseSetMatIndexBase(csr_descr, csr_idx_base); hipsparseSetMatIndexBase(bsr_descr, bsr_idx_base); if(m == 0 || n == 0) { #ifdef __HIP_PLATFORM_NVIDIA__ // cusparse does not support m == 0 for csr2bsr return HIPSPARSE_STATUS_SUCCESS; #endif } int mb = m * row_block_dim; int nb = n * col_block_dim; srand(12345ULL); // Host structures std::vector bsr_row_ptr; std::vector bsr_col_ind; std::vector bsr_val; // Read or construct CSR matrix int nnzb = 0; if(!generate_csr_matrix( filename, mb, nb, nnzb, bsr_row_ptr, bsr_col_ind, bsr_val, bsr_idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } m = mb * row_block_dim; n = nb * col_block_dim; size_t nnz = nnzb * row_block_dim * col_block_dim; // Now use the csr matrix as the symbolic for the gebsr matrix. bsr_val.resize(nnz); int idx = 0; switch(dir) { case HIPSPARSE_DIRECTION_COLUMN: { for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { for(int k = bsr_row_ptr[i] - bsr_idx_base; k < bsr_row_ptr[i + 1] - bsr_idx_base; ++k) { for(int c = 0; c < col_block_dim; ++c) { bsr_val[k * row_block_dim * col_block_dim + c * row_block_dim + r] = make_DataType(++idx); } } } } break; } case HIPSPARSE_DIRECTION_ROW: { for(int i = 0; i < mb; ++i) { for(int r = 0; r < row_block_dim; ++r) { for(int k = bsr_row_ptr[i] - bsr_idx_base; k < bsr_row_ptr[i + 1] - bsr_idx_base; ++k) { for(int c = 0; c < col_block_dim; ++c) { bsr_val[k * row_block_dim * col_block_dim + r * col_block_dim + c] = make_DataType(++idx); } } } } break; } } // Allocate memory on the device auto dbsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (mb + 1)), device_free}; auto dbsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnzb), device_free}; auto dbsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dcsr_row_ptr_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * (m + 1)), device_free}; auto dcsr_col_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dcsr_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; int* dbsr_row_ptr = (int*)dbsr_row_ptr_managed.get(); int* dbsr_col_ind = (int*)dbsr_col_ind_managed.get(); T* dbsr_val = (T*)dbsr_val_managed.get(); int* dcsr_row_ptr = (int*)dcsr_row_ptr_managed.get(); int* dcsr_col_ind = (int*)dcsr_col_ind_managed.get(); T* dcsr_val = (T*)dcsr_val_managed.get(); // Copy data from host to device CHECK_HIP_ERROR( hipMemcpy(dbsr_row_ptr, bsr_row_ptr.data(), sizeof(int) * (mb + 1), hipMemcpyHostToDevice)); CHECK_HIP_ERROR( hipMemcpy(dbsr_col_ind, bsr_col_ind.data(), sizeof(int) * nnzb, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dbsr_val, bsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); // Host CSR matrix std::vector dh_csr_row_ptr(m + 1); std::vector dh_csr_col_ind(nnz); std::vector dh_csr_val(nnz); // Copy output from device to host CHECK_HIP_ERROR(hipMemcpy( dh_csr_row_ptr.data(), dcsr_row_ptr, sizeof(int) * (m + 1), hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy( dh_csr_col_ind.data(), dcsr_col_ind, sizeof(int) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR( hipMemcpy(dh_csr_val.data(), dcsr_val, sizeof(T) * nnz, hipMemcpyDeviceToHost)); // Host CSR matrix std::vector h_csr_row_ptr(m + 1); std::vector h_csr_col_ind(nnz); std::vector h_csr_val(nnz); // Host gebsr2csr host_gebsr_to_csr(dir, mb, nb, nnzb, bsr_val, bsr_row_ptr, bsr_col_ind, row_block_dim, col_block_dim, bsr_idx_base, h_csr_val, h_csr_row_ptr, h_csr_col_ind, csr_idx_base); // Unit check unit_check_general(1, m + 1, 1, dh_csr_row_ptr.data(), h_csr_row_ptr.data()); unit_check_general(1, nnz, 1, dh_csr_col_ind.data(), h_csr_col_ind.data()); unit_check_general(1, nnz, 1, dh_csr_val.data(), h_csr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXgebsr2csr(handle, dir, mb, nb, bsr_descr, dbsr_val, dbsr_row_ptr, dbsr_col_ind, row_block_dim, col_block_dim, csr_descr, dcsr_val, dcsr_row_ptr, dcsr_col_ind)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = gebsr2csr_gbyte_count(mb, row_block_dim, col_block_dim, nnzb); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::M, m, display_key_t::N, n, display_key_t::Mb, mb, display_key_t::Nb, nb, display_key_t::row_block_dim, row_block_dim, display_key_t::col_block_dim, col_block_dim, display_key_t::nnzb, nnzb, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_GEBSR2CSR_HPP ./clients/include/testing_csc2dense.hpp0000664000175100017510000000405115176134511020312 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_CSC2DENSE_HPP #define TESTING_CSC2DENSE_HPP #include "testing_csx2dense.hpp" template void testing_csc2dense_bad_arg(const Arguments& argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; testing_csx2dense_bad_arg(hipsparseXcsc2dense); #endif } template hipsparseStatus_t testing_csc2dense(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) static constexpr hipsparseDirection_t DIRA = HIPSPARSE_DIRECTION_COLUMN; return testing_csx2dense(argus, hipsparseXcsc2dense, hipsparseXdense2csc); #else return HIPSPARSE_STATUS_SUCCESS; #endif } #endif // TESTING_CSC2DENSE ./clients/include/testing_sddmm_coo_aos.hpp0000664000175100017510000004727515176134511021266 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SDDMM_COO_AOS_HPP #define TESTING_SDDMM_COO_AOS_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include #include #include using namespace hipsparse; using namespace hipsparse_test; void testing_sddmm_coo_aos_bad_arg(void) { #if(!defined(CUDART_VERSION)) int32_t n = 100; int32_t m = 100; int32_t k = 100; int64_t nnz = 100; int32_t safe_size = 100; float alpha = 0.6; float beta = 0.2; hipsparseOperation_t transA = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOperation_t transB = HIPSPARSE_OPERATION_NON_TRANSPOSE; hipsparseOrder_t orderA = HIPSPARSE_ORDER_COL; hipsparseOrder_t orderB = HIPSPARSE_ORDER_COL; hipsparseIndexBase_t idxBase = HIPSPARSE_INDEX_BASE_ZERO; hipsparseIndexType_t idxTypeI = HIPSPARSE_INDEX_32I; hipDataType dataType = HIP_R_32F; hipsparseSDDMMAlg_t alg = HIPSPARSE_SDDMM_ALG_DEFAULT; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto drowcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(int32_t) * safe_size), device_free}; auto dval_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(float) * safe_size), device_free}; auto dbuf_managed = hipsparse_unique_ptr{device_malloc(sizeof(char) * safe_size), device_free}; int32_t* drowcol = (int32_t*)drowcol_managed.get(); float* dval = (float*)dval_managed.get(); float* dB = (float*)dB_managed.get(); float* dA = (float*)dA_managed.get(); void* dbuf = (void*)dbuf_managed.get(); // SDDMM structures hipsparseDnMatDescr_t A, B; hipsparseSpMatDescr_t C; size_t bsize; // Create SDDMM structures verify_hipsparse_status_success(hipsparseCreateDnMat(&A, m, k, m, dA, dataType, orderA), "success"); verify_hipsparse_status_success(hipsparseCreateDnMat(&B, k, n, k, dB, dataType, orderB), "success"); verify_hipsparse_status_success( hipsparseCreateCooAoS(&C, m, n, nnz, drowcol, dval, idxTypeI, idxBase, dataType), "success"); // SDDMM buffer verify_hipsparse_status_invalid_handle(hipsparseSDDMM_bufferSize( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, &bsize)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, &bsize), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, &bsize), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, &bsize), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, &bsize), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, &bsize), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_bufferSize( handle, transA, transB, &alpha, A, B, &beta, C, dataType, alg, nullptr), "Error: bsize is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle(hipsparseSDDMM_preprocess( nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM_preprocess( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // SDDMM verify_hipsparse_status_invalid_handle( hipsparseSDDMM(nullptr, transA, transB, &alpha, A, B, &beta, C, dataType, alg, dbuf)); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, nullptr, A, B, &beta, C, dataType, alg, dbuf), "Error: alpha is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, nullptr, B, &beta, C, dataType, alg, dbuf), "Error: A is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, nullptr, &beta, C, dataType, alg, dbuf), "Error: B is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, nullptr, C, dataType, alg, dbuf), "Error: beta is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM(handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, dbuf), "Error: C is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseSDDMM( handle, transA, transB, &alpha, A, B, &beta, nullptr, dataType, alg, nullptr), "Error: dbuf is nullptr"); // Destruct verify_hipsparse_status_success(hipsparseDestroyDnMat(A), "success"); verify_hipsparse_status_success(hipsparseDestroyDnMat(B), "success"); verify_hipsparse_status_success(hipsparseDestroySpMat(C), "success"); #endif } template hipsparseStatus_t testing_sddmm_coo_aos(Arguments argus) { #if(!defined(CUDART_VERSION)) I m = argus.M; I n = argus.N; I k = argus.K; T h_alpha = make_DataType(argus.alpha); T h_beta = make_DataType(argus.beta); hipsparseOperation_t transA = argus.transA; hipsparseOperation_t transB = argus.transB; hipsparseOrder_t orderA = argus.orderA; hipsparseOrder_t orderB = argus.orderB; hipsparseIndexBase_t idx_base = argus.baseC; hipsparseSDDMMAlg_t alg = static_cast(argus.sddmm_alg); std::string filename = argus.filename; // Index and data type hipsparseIndexType_t typeI = getIndexType(); hipDataType typeT = getDataType(); // hipSPARSE handle std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hcsr_row_ptr; std::vector hcsr_col_ind; std::vector hcsr_val; // Initial Data on CPU srand(12345ULL); // Read or construct CSR matrix I nnz = 0; if(!generate_csr_matrix(filename, m, n, nnz, hcsr_row_ptr, hcsr_col_ind, hcsr_val, idx_base)) { fprintf(stderr, "Cannot open [read] %s\ncol", filename.c_str()); return HIPSPARSE_STATUS_INTERNAL_ERROR; } std::vector hrowcol_ind(nnz * 2); // Convert to COO_AOS for(I i = 0; i < m; ++i) { for(I j = hcsr_row_ptr[i]; j < hcsr_row_ptr[i + 1]; ++j) { hrowcol_ind[2 * (j - idx_base) + 0] = i + idx_base; hrowcol_ind[2 * (j - idx_base) + 1] = hcsr_col_ind[j - idx_base]; } } // Some matrix properties I A_m = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? m : k; I A_n = (transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : m; I B_m = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? k : n; I B_n = (transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? n : k; I C_m = m; I C_n = n; int ld_multiplier_A = 1; int ld_multiplier_B = 1; int64_t lda = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * m) : (int64_t(ld_multiplier_A) * k)) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_A) * k) : (int64_t(ld_multiplier_A) * m)); int64_t ldb = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * k) : (int64_t(ld_multiplier_B) * n)) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? (int64_t(ld_multiplier_B) * n) : (int64_t(ld_multiplier_B) * k)); lda = std::max(int64_t(1), lda); ldb = std::max(int64_t(1), ldb); int64_t nrowA = (orderA == HIPSPARSE_ORDER_COL) ? lda : A_m; int64_t ncolA = (orderA == HIPSPARSE_ORDER_COL) ? A_n : lda; int64_t nrowB = (orderB == HIPSPARSE_ORDER_COL) ? ldb : B_m; int64_t ncolB = (orderB == HIPSPARSE_ORDER_COL) ? B_n : ldb; int64_t nnz_A = nrowA * ncolA; int64_t nnz_B = nrowB * ncolB; std::vector hA(A_m * A_n); std::vector hB(B_m * B_n); hipsparseInit(hA, nnz_A, 1); hipsparseInit(hB, nnz_B, 1); // allocate memory on device auto drowcol_managed = hipsparse_unique_ptr{device_malloc(sizeof(I) * nnz * 2), device_free}; auto dval1_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dval2_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dA_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_A), device_free}; auto dB_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz_B), device_free}; auto d_alpha_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; auto d_beta_managed = hipsparse_unique_ptr{device_malloc(sizeof(T)), device_free}; I* drowcol = (I*)drowcol_managed.get(); T* dval1 = (T*)dval1_managed.get(); T* dval2 = (T*)dval2_managed.get(); T* dA = (T*)dA_managed.get(); T* dB = (T*)dB_managed.get(); T* d_alpha = (T*)d_alpha_managed.get(); T* d_beta = (T*)d_beta_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR( hipMemcpy(drowcol, hrowcol_ind.data(), sizeof(I) * nnz * 2, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval1, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dval2, hcsr_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dA, hA.data(), sizeof(T) * nnz_A, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dB, hB.data(), sizeof(T) * nnz_B, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_alpha, &h_alpha, sizeof(T), hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(d_beta, &h_beta, sizeof(T), hipMemcpyHostToDevice)); // Create matrices hipsparseSpMatDescr_t C1, C2; CHECK_HIPSPARSE_ERROR( hipsparseCreateCooAoS(&C1, C_m, C_n, nnz, drowcol, dval1, typeI, idx_base, typeT)); CHECK_HIPSPARSE_ERROR( hipsparseCreateCooAoS(&C2, C_m, C_n, nnz, drowcol, dval2, typeI, idx_base, typeT)); // Create dense matrices hipsparseDnMatDescr_t A, B; CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&A, A_m, A_n, lda, dA, typeT, orderA)); CHECK_HIPSPARSE_ERROR(hipsparseCreateDnMat(&B, B_m, B_n, ldb, dB, typeT, orderB)); // Query SDDMM buffer size_t bufferSize; CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_bufferSize( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, &bufferSize)); void* buffer; CHECK_HIP_ERROR(hipMalloc(&buffer, bufferSize)); // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); // HIPSPARSE pointer mode device CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM_preprocess( handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); if(argus.unit_check) { CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_DEVICE)); CHECK_HIPSPARSE_ERROR( hipsparseSDDMM(handle, transA, transB, d_alpha, A, B, d_beta, C2, typeT, alg, buffer)); // copy output from device to CPU. std::vector hval1(nnz); std::vector hval2(nnz); CHECK_HIP_ERROR(hipMemcpy(hval1.data(), dval1, sizeof(T) * nnz, hipMemcpyDeviceToHost)); CHECK_HIP_ERROR(hipMemcpy(hval2.data(), dval2, sizeof(T) * nnz, hipMemcpyDeviceToHost)); const int64_t incA = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? lda : 1) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : lda); const int64_t incB = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? 1 : ldb) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? ldb : 1); for(I i = 0; i < nnz; ++i) { const I r = hrowcol_ind[2 * i] - idx_base; const I c = hrowcol_ind[2 * i + 1] - idx_base; const T* Aptr = (orderA == HIPSPARSE_ORDER_COL) ? ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[r] : &hA[lda * r]) : ((transA == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hA[lda * r] : &hA[r]); const T* Bptr = (orderB == HIPSPARSE_ORDER_COL) ? ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[ldb * c] : &hB[c]) : ((transB == HIPSPARSE_OPERATION_NON_TRANSPOSE) ? &hB[c] : &hB[ldb * c]); T sum = static_cast(0); for(I j = 0; j < k; ++j) { sum = testing_fma(Aptr[incA * j], Bptr[incB * j], sum); } hcsr_val[i] = testing_mult(hcsr_val[i], h_beta) + testing_mult(h_alpha, sum); } unit_check_near(1, nnz, 1, hval1.data(), hcsr_val.data()); unit_check_near(1, nnz, 1, hval2.data(), hcsr_val.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseSDDMM( handle, transA, transB, &h_alpha, A, B, &h_beta, C1, typeT, alg, buffer)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gflop_count = sddmm_gflop_count(k, nnz, h_beta != make_DataType(0)); double gbyte_count = sddmm_coo_aos_gbyte_count(m, n, k, nnz, h_beta != make_DataType(0)); double gpu_gflops = get_gpu_gflops(gpu_time_used, gflop_count); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::format, hipsparse_format2string(HIPSPARSE_FORMAT_COO_AOS), display_key_t::transA, hipsparse_operation2string(transA), display_key_t::transB, hipsparse_operation2string(transB), display_key_t::M, m, display_key_t::N, n, display_key_t::K, k, display_key_t::nnz, nnz, display_key_t::alpha, h_alpha, display_key_t::beta, h_beta, display_key_t::algorithm, hipsparse_sddmmalg2string(alg), display_key_t::gflops, gpu_gflops, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } // free. CHECK_HIP_ERROR(hipFree(buffer)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C1)); CHECK_HIPSPARSE_ERROR(hipsparseDestroySpMat(C2)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(A)); CHECK_HIPSPARSE_ERROR(hipsparseDestroyDnMat(B)); #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SDDMM_COO_AOS_HPP ./clients/include/testing_sctr.hpp0000664000175100017510000001507515176134511017424 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #ifndef TESTING_SCTR_HPP #define TESTING_SCTR_HPP #include "display.hpp" #include "flops.hpp" #include "gbyte.hpp" #include "hipsparse.hpp" #include "hipsparse_arguments.hpp" #include "hipsparse_test_unique_ptr.hpp" #include "unit.hpp" #include "utility.hpp" #include using namespace hipsparse; using namespace hipsparse_test; template void testing_sctr_bad_arg(const Arguments& argus) { int nnz = 100; int safe_size = 100; hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free}; T* dx_val = (T*)dx_val_managed.get(); int* dx_ind = (int*)dx_ind_managed.get(); T* dy = (T*)dy_managed.get(); verify_hipsparse_status_invalid_value(hipsparseXsctr(handle, -1, dx_val, dx_ind, dy, idx_base), "Error: nnz is invalid"); // cusparse returns success for these #if(!defined(CUDART_VERSION)) verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, dx_val, (int*)nullptr, dy, idx_base), "Error: x_ind is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, (T*)nullptr, dx_ind, dy, idx_base), "Error: x_val is nullptr"); verify_hipsparse_status_invalid_pointer( hipsparseXsctr(handle, nnz, dx_val, dx_ind, (T*)nullptr, idx_base), "Error: y is nullptr"); verify_hipsparse_status_invalid_handle( hipsparseXsctr(nullptr, nnz, dx_val, dx_ind, dy, idx_base)); #endif } template hipsparseStatus_t testing_sctr(Arguments argus) { #if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000) int N = argus.N; int nnz = argus.nnz; hipsparseIndexBase_t idx_base = argus.baseA; std::unique_ptr unique_ptr_handle(new handle_struct); hipsparseHandle_t handle = unique_ptr_handle->handle; // Host structures std::vector hx_ind(nnz); std::vector hx_val(nnz); std::vector hy(N); std::vector hy_gold(N); // Initial Data on CPU srand(12345ULL); hipsparseInitIndex(hx_ind.data(), nnz, 1, N); hipsparseInit(hx_val, 1, nnz); hipsparseInit(hy, 1, N); hy_gold = hy; // allocate memory on device auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free}; auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free}; auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free}; int* dx_ind = (int*)dx_ind_managed.get(); T* dx_val = (T*)dx_val_managed.get(); T* dy = (T*)dy_managed.get(); // copy data from CPU to device CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dx_val, hx_val.data(), sizeof(T) * nnz, hipMemcpyHostToDevice)); CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice)); if(argus.unit_check) { // HIPSPARSE pointer mode host CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); // copy output from device to CPU CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * N, hipMemcpyDeviceToHost)); // CPU for(int i = 0; i < nnz; ++i) { hy_gold[hx_ind[i] - idx_base] = hx_val[i]; } // enable unit check, notice unit check is not invasive, but norm check is, // unit check and norm check can not be interchanged their order unit_check_general(1, N, 1, hy_gold.data(), hy.data()); } if(argus.timing) { int number_cold_calls = 2; int number_hot_calls = argus.iters; CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST)); // Warm up for(int iter = 0; iter < number_cold_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); } double gpu_time_used = get_time_us(); // Performance run for(int iter = 0; iter < number_hot_calls; ++iter) { CHECK_HIPSPARSE_ERROR(hipsparseXsctr(handle, nnz, dx_val, dx_ind, dy, idx_base)); } gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls; double gbyte_count = sctr_gbyte_count(nnz); double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count); display_timing_info(display_key_t::nnz, nnz, display_key_t::bandwidth, gpu_gbyte, display_key_t::time_ms, get_gpu_time_msec(gpu_time_used)); } #endif return HIPSPARSE_STATUS_SUCCESS; } #endif // TESTING_SCTR_HPP ./clients/tests/0000775000175100017510000000000015176134511013712 5ustar jenkinsjenkins./clients/tests/test_spmat_descr.cpp0000664000175100017510000000321015176134511017755 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_spmat_descr.hpp" // Only run tests for CUDA 11.1 or greater #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spmat_descr_bad_arg, spmat_descr_float) { testing_spmat_descr_bad_arg(); } TEST(spmat_descr, spmat_descr) { hipsparseStatus_t status = testing_spmat_descr(); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif ./clients/tests/test_csr2bsr.yaml0000664000175100017510000000412415176134511017216 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## --- include: hipsparse_common.yaml Tests: - name: csr2bsr_bad_arg category: pre_checkin function: csr2bsr_bad_arg precision: *single_double_precisions_complex_real - name: csr2bsr category: quick function: csr2bsr precision: *single_double_precisions_complex_real M: [0, 872, 21453] N: [0, 623, 29285] block_dim: [1, 2, 4, 7, 16] baseA: [HIPSPARSE_INDEX_BASE_ZERO] baseB: [HIPSPARSE_INDEX_BASE_ONE] dirA: [HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN] - name: csr2bsr_file category: pre_checkin function: csr2bsr precision: *single_double_precisions M: 1 block_dim: [5] baseA: [HIPSPARSE_INDEX_BASE_ONE] baseB: [HIPSPARSE_INDEX_BASE_ONE] dirA: [HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN] filename: [scircuit, nos2, nos4, nos6, sme3Dc] ./clients/tests/test_const_dnvec_descr.cpp0000664000175100017510000000275215176134305021151 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_const_dnvec_descr.hpp" #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 12000) TEST(const_dnvec_descr_bad_arg, const_dnvec_descr_float) { testing_const_dnvec_descr_bad_arg(); } #endif ./clients/tests/test_sparse_to_dense_csc.cpp0000664000175100017510000001535115176134511021467 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_sparse_to_dense_csc.hpp" #include typedef std::tuple sparse_to_dense_csc_tuple; typedef std::tuple sparse_to_dense_csc_bin_tuple; int sparse_to_dense_csc_M_range[] = {50}; int sparse_to_dense_csc_N_range[] = {5}; hipsparseOrder_t sparse_to_dense_csc_order_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sparse_to_dense_csc_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSparseToDenseAlg_t sparse_to_dense_csc_alg_range[] = {HIPSPARSE_SPARSETODENSE_ALG_DEFAULT}; std::string sparse_to_dense_csc_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "bibd_22_8.bin"}; class parameterized_sparse_to_dense_csc : public testing::TestWithParam { protected: parameterized_sparse_to_dense_csc() {} virtual ~parameterized_sparse_to_dense_csc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sparse_to_dense_csc_bin : public testing::TestWithParam { protected: parameterized_sparse_to_dense_csc_bin() {} virtual ~parameterized_sparse_to_dense_csc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sparse_to_dense_csc_arguments(sparse_to_dense_csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.orderA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.sparse2dense_alg = std::get<4>(tup); arg.timing = 0; return arg; } Arguments setup_sparse_to_dense_csc_arguments(sparse_to_dense_csc_bin_tuple tup) { Arguments arg; arg.orderA = std::get<0>(tup); arg.baseA = std::get<1>(tup); arg.sparse2dense_alg = std::get<2>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<3>(tup); // Matrices are stored at the same path in matrices directory arg.set_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11020) TEST(sparse_to_dense_csc_bad_arg, sparse_to_dense_csc_float) { testing_sparse_to_dense_csc_bad_arg(); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i32_float) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i64_double) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i32_float_complex) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc, sparse_to_dense_csc_i64_double_complex) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc_bin, sparse_to_dense_csc_bin_i32_float) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sparse_to_dense_csc_bin, sparse_to_dense_csc_bin_i64_double) { Arguments arg = setup_sparse_to_dense_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sparse_to_dense_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sparse_to_dense_csc, parameterized_sparse_to_dense_csc, testing::Combine(testing::ValuesIn(sparse_to_dense_csc_M_range), testing::ValuesIn(sparse_to_dense_csc_N_range), testing::ValuesIn(sparse_to_dense_csc_order_range), testing::ValuesIn(sparse_to_dense_csc_idxbase_range), testing::ValuesIn(sparse_to_dense_csc_alg_range))); INSTANTIATE_TEST_SUITE_P(sparse_to_dense_csc_bin, parameterized_sparse_to_dense_csc_bin, testing::Combine(testing::ValuesIn(sparse_to_dense_csc_order_range), testing::ValuesIn(sparse_to_dense_csc_idxbase_range), testing::ValuesIn(sparse_to_dense_csc_alg_range), testing::ValuesIn(sparse_to_dense_csc_bin))); #endif ./clients/tests/test.hpp0000664000175100017510000001330415176134305015404 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_data.hpp" #include "hipsparse_test.hpp" #include "hipsparse_test_enum.hpp" #include "hipsparse_test_template_traits.hpp" // INTERNAL MACRO TO SPECIALIZE TEST CALL NEEDED TO INSTANTIATE #define SPECIALIZE_HIPSPARSE_TEST_CALL(ROUTINE) \ template <> \ struct temp::hipsparse_test_call \ { \ template \ static void testing_bad_arg(const Arguments& arg) \ { \ testing_##ROUTINE##_bad_arg(arg); \ } \ template \ static void testing(const Arguments& arg) \ { \ testing_##ROUTINE(arg); \ } \ }; // INTERNAL MACRO TO SPECIALIZE TEST FUNCTOR NEEDED TO INSTANTIATE #define SPECIALIZE_HIPSPARSE_TEST_FUNCTORS(ROUTINE, ...) \ template <> \ struct hipsparse_test_functors \ { \ static std::string name_suffix(const Arguments& arg) \ { \ std::ostringstream s; \ hipsparse_test_name_suffix_generator(s, __VA_ARGS__); \ return s.str(); \ } \ } // INTERNAL MACRO TO SPECIALIZE TEST TRAITS NEEDED TO INSTANTIATE #define SPECIALIZE_HIPSPARSE_TEST_TRAITS(ROUTINE, CONFIG) \ template <> \ struct hipsparse_test_traits : CONFIG \ { \ } // INSTANTIATE TESTS template using test_template_traits_t = hipsparse_test_template_traits::s_dispatch>; template using test_dispatch_t = hipsparse_test_dispatch::s_dispatch>; #define INSTANTIATE_HIPSPARSE_TEST(ROUTINE, CATEGORY) \ using ROUTINE = test_template_traits_t::filter; \ template \ using ROUTINE##_call = test_template_traits_t::caller; \ TEST_P(ROUTINE, CATEGORY) \ { \ test_dispatch_t::template dispatch( \ GetParam()); \ } \ INSTANTIATE_TEST_CATEGORIES(ROUTINE) // DEFINE ALL REQUIRED INFORMATION FOR A TEST ROUTINE BUT WITH A PREDEFINED CONFIGURATION // (i.e. [T (default) | | ] + a selection of numeric types (all (default), real_only, complex_only, some other specific situations (?) ) ) #define TEST_ROUTINE_WITH_CONFIG(ROUTINE, CATEGORY, CONFIG, ...) \ SPECIALIZE_HIPSPARSE_TEST_TRAITS(ROUTINE, CONFIG); \ SPECIALIZE_HIPSPARSE_TEST_FUNCTORS(ROUTINE, __VA_ARGS__); \ SPECIALIZE_HIPSPARSE_TEST_CALL(ROUTINE); \ namespace \ { \ INSTANTIATE_HIPSPARSE_TEST(ROUTINE, CATEGORY); \ } // DEFINE ALL REQUIRED INFORMATION FOR A TEST ROUTINE WITH A DEFAULT CONFIGURATION (i.e T + all numeric types) #define TEST_ROUTINE(ROUTINE, CATEGORY, ...) \ TEST_ROUTINE_WITH_CONFIG(ROUTINE, CATEGORY, hipsparse_test_config, __VA_ARGS__) ./clients/tests/test_gtsv.cpp0000664000175100017510000000571615176134511016451 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_gtsv.hpp" #include #include typedef std::tuple gtsv_tuple; int gtsv_M_range[] = {512}; int gtsv_N_range[] = {512}; class parameterized_gtsv : public testing::TestWithParam { protected: parameterized_gtsv() {} virtual ~parameterized_gtsv() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_gtsv_arguments(gtsv_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.timing = 0; return arg; } TEST(gtsv_bad_arg, gtsv_float) { testing_gtsv2_bad_arg(); } TEST_P(parameterized_gtsv, gtsv_float) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv, gtsv_double) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv, gtsv_float_complex) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_gtsv, gtsv_double_complex) { Arguments arg = setup_gtsv_arguments(GetParam()); hipsparseStatus_t status = testing_gtsv2(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(gtsv, parameterized_gtsv, testing::Combine(testing::ValuesIn(gtsv_M_range), testing::ValuesIn(gtsv_N_range))); ./clients/tests/test_dotci.cpp0000664000175100017510000000277515176134305016573 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2019-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "test.hpp" #include "testing_dotci.hpp" #if(!defined(CUDART_VERSION) || CUDART_VERSION < 11000) TEST_ROUTINE_WITH_CONFIG( dotci, level1, hipsparse_test_config_complex_only, arg.N, arg.nnz, arg.baseA); #endif ./clients/tests/hipsparse_test_config.hpp0000664000175100017510000000675115176134305021017 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_test_dispatch_enum.hpp" #include "hipsparse_test_numeric_types_enum.hpp" template struct hipsparse_test_config_template { static constexpr hipsparse_test_dispatch_enum::value_type s_dispatch = DISPATCH; static constexpr hipsparse_test_numeric_types_enum::value_type s_numeric_types = NUMERIC_TYPES; }; struct hipsparse_test_config : hipsparse_test_config_template { }; struct hipsparse_test_config_real_only : hipsparse_test_config_template { }; struct hipsparse_test_config_complex_only : hipsparse_test_config_template { }; struct hipsparse_test_config_it : hipsparse_test_config_template { }; struct hipsparse_test_config_it_real_only : hipsparse_test_config_template { }; struct hipsparse_test_config_it_complex_only : hipsparse_test_config_template { }; struct hipsparse_test_config_ijt : hipsparse_test_config_template { }; struct hipsparse_test_config_ijt_real_only : hipsparse_test_config_template { }; struct hipsparse_test_config_ijt_complex_only : hipsparse_test_config_template { };./clients/tests/test_sddmm_csc.cpp0000664000175100017510000002001215176134511017404 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_sddmm_csc.hpp" #include struct alpha_beta { double alpha; double beta; }; typedef std::tuple sddmm_csc_tuple; typedef std::tuple sddmm_csc_bin_tuple; int sddmm_csc_M_range[] = {50}; int sddmm_csc_N_range[] = {84}; int sddmm_csc_K_range[] = {5}; alpha_beta sddmm_csc_alpha_beta_range[] = {{2.0, 1.0}}; hipsparseOperation_t sddmm_csc_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOperation_t sddmm_csc_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_TRANSPOSE}; hipsparseOrder_t sddmm_csc_orderA_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t sddmm_csc_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t sddmm_csc_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; hipsparseSDDMMAlg_t sddmm_csc_alg_range[] = {HIPSPARSE_SDDMM_ALG_DEFAULT}; std::string sddmm_csc_bin[] = {"nos1.bin", "nos3.bin", "nos5.bin", "nos7.bin", "shipsec1.bin"}; class parameterized_sddmm_csc : public testing::TestWithParam { protected: parameterized_sddmm_csc() {} virtual ~parameterized_sddmm_csc() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_sddmm_csc_bin : public testing::TestWithParam { protected: parameterized_sddmm_csc_bin() {} virtual ~parameterized_sddmm_csc_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_sddmm_csc_arguments(sddmm_csc_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.K = std::get<2>(tup); arg.alpha = std::get<3>(tup).alpha; arg.beta = std::get<3>(tup).beta; arg.transA = std::get<4>(tup); arg.transB = std::get<5>(tup); arg.orderA = std::get<6>(tup); arg.orderB = std::get<7>(tup); arg.baseA = std::get<8>(tup); arg.sddmm_alg = std::get<9>(tup); arg.timing = 0; return arg; } Arguments setup_sddmm_csc_arguments(sddmm_csc_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.K = std::get<0>(tup); arg.alpha = std::get<1>(tup).alpha; arg.beta = std::get<1>(tup).beta; arg.transA = std::get<2>(tup); arg.transB = std::get<3>(tup); arg.orderA = std::get<4>(tup); arg.orderB = std::get<5>(tup); arg.baseA = std::get<6>(tup); arg.sddmm_alg = std::get<7>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<8>(tup); // Matrices are stored at the same path in matrices directory arg.set_filename(bin_file); return arg; } // CSC format not supported in cusparse #if(!defined(CUDART_VERSION)) TEST(sddmm_csc_bad_arg, sddmm_csc_float) { testing_sddmm_csc_bad_arg(); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i32_float) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i64_double) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i32_float_complex) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc, sddmm_csc_i64_double_complex) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc_bin, sddmm_csc_bin_i32_float) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_sddmm_csc_bin, sddmm_csc_bin_i64_double) { Arguments arg = setup_sddmm_csc_arguments(GetParam()); hipsparseStatus_t status = testing_sddmm_csc(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(sddmm_csc, parameterized_sddmm_csc, testing::Combine(testing::ValuesIn(sddmm_csc_M_range), testing::ValuesIn(sddmm_csc_N_range), testing::ValuesIn(sddmm_csc_K_range), testing::ValuesIn(sddmm_csc_alpha_beta_range), testing::ValuesIn(sddmm_csc_transA_range), testing::ValuesIn(sddmm_csc_transB_range), testing::ValuesIn(sddmm_csc_orderA_range), testing::ValuesIn(sddmm_csc_orderB_range), testing::ValuesIn(sddmm_csc_idxbase_range), testing::ValuesIn(sddmm_csc_alg_range))); INSTANTIATE_TEST_SUITE_P(sddmm_csc_bin, parameterized_sddmm_csc_bin, testing::Combine(testing::ValuesIn(sddmm_csc_K_range), testing::ValuesIn(sddmm_csc_alpha_beta_range), testing::ValuesIn(sddmm_csc_transA_range), testing::ValuesIn(sddmm_csc_transB_range), testing::ValuesIn(sddmm_csc_orderA_range), testing::ValuesIn(sddmm_csc_orderB_range), testing::ValuesIn(sddmm_csc_idxbase_range), testing::ValuesIn(sddmm_csc_alg_range), testing::ValuesIn(sddmm_csc_bin))); #endif ./clients/tests/test_spmv_coo_aos.cpp0000664000175100017510000001702415176134511020150 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_spmv_coo_aos.hpp" #include typedef std:: tuple spmv_coo_aos_tuple; typedef std::tuple spmv_coo_aos_bin_tuple; int spmv_coo_aos_M_range[] = {50}; int spmv_coo_aos_N_range[] = {84}; std::vector spmv_coo_aos_alpha_range = {2.0}; std::vector spmv_coo_aos_beta_range = {1.0}; hipsparseOperation_t spmv_coo_aos_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseIndexBase_t spmv_coo_aos_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; #if(!defined(CUDART_VERSION)) hipsparseSpMVAlg_t spmv_coo_aos_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_COO_ALG1, HIPSPARSE_SPMV_COO_ALG2}; #else // coo_aos format not supported in cusparse 12 or later #if(CUDART_VERSION >= 11021 && CUDART_VERSION < 12000) hipsparseSpMVAlg_t spmv_coo_aos_alg_range[] = {HIPSPARSE_SPMV_ALG_DEFAULT, HIPSPARSE_SPMV_COO_ALG1, HIPSPARSE_SPMV_COO_ALG2}; #elif(CUDART_VERSION >= 10010 && CUDART_VERSION < 11021) hipsparseSpMVAlg_t spmv_coo_aos_alg_range[] = {HIPSPARSE_MV_ALG_DEFAULT, HIPSPARSE_COOMV_ALG}; #endif #endif std::string spmv_coo_aos_bin[] = {"nos1.bin", "nos2.bin", "nos3.bin", "nos4.bin", "nos5.bin", "nos6.bin", "nos7.bin", "Chebyshev4.bin", "shipsec1.bin"}; class parameterized_spmv_coo_aos : public testing::TestWithParam { protected: parameterized_spmv_coo_aos() {} virtual ~parameterized_spmv_coo_aos() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spmv_coo_aos_bin : public testing::TestWithParam { protected: parameterized_spmv_coo_aos_bin() {} virtual ~parameterized_spmv_coo_aos_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spmv_coo_aos_arguments(spmv_coo_aos_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.alpha = std::get<2>(tup); arg.beta = std::get<3>(tup); arg.transA = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.spmv_alg = std::get<6>(tup); arg.timing = 0; return arg; } Arguments setup_spmv_coo_aos_arguments(spmv_coo_aos_bin_tuple tup) { Arguments arg; arg.M = -99; arg.N = -99; arg.alpha = std::get<0>(tup); arg.beta = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.spmv_alg = std::get<4>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<5>(tup); // Matrices are stored at the same path in matrices directory arg.set_filename(bin_file); return arg; } // coo_aos format not supported in cusparse 12.0 or later #if(!defined(CUDART_VERSION) || (CUDART_VERSION >= 10010 && CUDART_VERSION < 12000)) TEST(spmv_coo_aos_bad_arg, spmv_coo_aos_float) { testing_spmv_coo_aos_bad_arg(); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i32_float) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i64_double) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i32_float_complex) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos, spmv_coo_aos_i64_double_complex) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos_bin, spmv_coo_aos_bin_i32_float) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spmv_coo_aos_bin, spmv_coo_aos_bin_i64_double) { Arguments arg = setup_spmv_coo_aos_arguments(GetParam()); hipsparseStatus_t status = testing_spmv_coo_aos(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spmv_coo_aos, parameterized_spmv_coo_aos, testing::Combine(testing::ValuesIn(spmv_coo_aos_M_range), testing::ValuesIn(spmv_coo_aos_N_range), testing::ValuesIn(spmv_coo_aos_alpha_range), testing::ValuesIn(spmv_coo_aos_beta_range), testing::ValuesIn(spmv_coo_aos_transA_range), testing::ValuesIn(spmv_coo_aos_idxbase_range), testing::ValuesIn(spmv_coo_aos_alg_range))); INSTANTIATE_TEST_SUITE_P(spmv_coo_aos_bin, parameterized_spmv_coo_aos_bin, testing::Combine(testing::ValuesIn(spmv_coo_aos_alpha_range), testing::ValuesIn(spmv_coo_aos_beta_range), testing::ValuesIn(spmv_coo_aos_transA_range), testing::ValuesIn(spmv_coo_aos_idxbase_range), testing::ValuesIn(spmv_coo_aos_alg_range), testing::ValuesIn(spmv_coo_aos_bin))); #endif ./clients/tests/test_spvv.cpp0000664000175100017510000001073415176134511016460 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_spvv.hpp" #include typedef std::tuple spvv_tuple; typedef std::tuple spvv_bin_tuple; int spvv_N_range[] = {50, 750, 2135}; int spvv_nnz_range[] = {5, 45}; hipsparseOperation_t spvv_trans_real_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOperation_t spvv_trans_complex_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE, HIPSPARSE_OPERATION_CONJUGATE_TRANSPOSE}; hipsparseIndexBase_t spvv_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE}; class parameterized_spvv_real : public testing::TestWithParam { protected: parameterized_spvv_real() {} virtual ~parameterized_spvv_real() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spvv_complex : public testing::TestWithParam { protected: parameterized_spvv_complex() {} virtual ~parameterized_spvv_complex() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spvv_arguments(spvv_tuple tup) { Arguments arg; arg.N = std::get<0>(tup); arg.nnz = std::get<1>(tup); arg.transA = std::get<2>(tup); arg.baseA = std::get<3>(tup); arg.timing = 0; return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION > 10010 \ || (CUDART_VERSION == 10010 && CUDART_10_1_UPDATE_VERSION == 1)) TEST(spvv_bad_arg, spvv_float) { testing_spvv_bad_arg(); } TEST_P(parameterized_spvv_real, spvv_i32_float) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spvv_real, spvv_i64_double) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spvv_complex, spvv_i32_float_complex) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spvv_complex, spvv_i64_double_complex) { Arguments arg = setup_spvv_arguments(GetParam()); hipsparseStatus_t status = testing_spvv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spvv, parameterized_spvv_real, testing::Combine(testing::ValuesIn(spvv_N_range), testing::ValuesIn(spvv_nnz_range), testing::ValuesIn(spvv_trans_real_range), testing::ValuesIn(spvv_idxbase_range))); INSTANTIATE_TEST_SUITE_P(spvv, parameterized_spvv_complex, testing::Combine(testing::ValuesIn(spvv_N_range), testing::ValuesIn(spvv_nnz_range), testing::ValuesIn(spvv_trans_complex_range), testing::ValuesIn(spvv_idxbase_range))); #endif ./clients/tests/test_csr2gebsr.yaml0000664000175100017510000000427415176134511017540 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## --- include: hipsparse_common.yaml Tests: - name: csr2gebsr_bad_arg category: pre_checkin function: csr2gebsr_bad_arg precision: *single_double_precisions_complex_real - name: csr2gebsr category: quick function: csr2gebsr precision: *single_double_precisions_complex_real M: [0, 13095] N: [0, 12766] row_block_dimA: [1, 2, 7] col_block_dimA: [1, 2] baseA: [HIPSPARSE_INDEX_BASE_ZERO] baseB: [HIPSPARSE_INDEX_BASE_ONE] dirA: [HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN] - name: csr2gebsr_file category: pre_checkin function: csr2gebsr precision: *single_double_precisions M: 1 row_block_dimA: [5] col_block_dimA: [5] baseA: [HIPSPARSE_INDEX_BASE_ONE] baseB: [HIPSPARSE_INDEX_BASE_ONE] dirA: [HIPSPARSE_DIRECTION_ROW, HIPSPARSE_DIRECTION_COLUMN] filename: [rma10, mac_econ_fwd500, scircuit, bmwcra_1, nos1, nos6, nos7] ./clients/tests/test_bsr2csr.cpp0000664000175100017510000000266315176134511017044 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "test.hpp" #include "testing_bsr2csr.hpp" TEST_ROUTINE(bsr2csr, conversion, arg.M, arg.N, arg.block_dim, arg.baseA, arg.baseB, arg.dirA); ./clients/tests/test_axpyi.cpp0000664000175100017510000000263715176134511016617 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "test.hpp" #include "testing_axpyi.hpp" TEST_ROUTINE(axpyi, level1, arg.N, arg.nnz, arg.alpha, arg.alphai, arg.baseA);./clients/tests/test_gemvi.yaml0000664000175100017510000000334715176134511016753 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## --- include: hipsparse_common.yaml Tests: - name: gemvi_bad_arg category: pre_checkin function: gemvi_bad_arg precision: *single_double_precisions_complex_real - name: gemvi category: quick function: gemvi precision: *single_double_precisions_complex_real M: [1291] N: [724] nnz: [237] alpha: [-0.5, 2.0] alphai: [-0.2] beta: [0.5, 0.0] betai: [1.7] transA: [HIPSPARSE_OPERATION_NON_TRANSPOSE] baseA: [HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE]./clients/tests/test_spsm_csr.cpp0000664000175100017510000002011515176134511017305 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_spsm_csr.hpp" #include struct M_N_K_alpha { int M; int N; int K; double alpha; }; typedef std::tuple spsm_csr_tuple; typedef std::tuple spsm_csr_bin_tuple; M_N_K_alpha spsm_csr_M_N_K_alpha_range[] = {{50, 50, 22, 2.0}}; hipsparseOperation_t spsm_csr_transA_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOperation_t spsm_csr_transB_range[] = {HIPSPARSE_OPERATION_NON_TRANSPOSE}; hipsparseOrder_t spsm_csr_orderB_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseOrder_t spsm_csr_orderC_range[] = {HIPSPARSE_ORDER_COL, HIPSPARSE_ORDER_ROW}; hipsparseIndexBase_t spsm_csr_idxbase_range[] = {HIPSPARSE_INDEX_BASE_ZERO}; hipsparseDiagType_t spsm_csr_diag_type_range[] = {HIPSPARSE_DIAG_TYPE_NON_UNIT}; hipsparseFillMode_t spsm_csr_fill_mode_range[] = {HIPSPARSE_FILL_MODE_LOWER, HIPSPARSE_FILL_MODE_UPPER}; hipsparseSpSMAlg_t spsm_csr_alg_range[] = {HIPSPARSE_SPSM_ALG_DEFAULT}; std::string spsm_csr_bin[] = {"nos1.bin", "nos3.bin", "nos5.bin", "scircuit.bin"}; class parameterized_spsm_csr : public testing::TestWithParam { protected: parameterized_spsm_csr() {} virtual ~parameterized_spsm_csr() {} virtual void SetUp() {} virtual void TearDown() {} }; class parameterized_spsm_csr_bin : public testing::TestWithParam { protected: parameterized_spsm_csr_bin() {} virtual ~parameterized_spsm_csr_bin() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_spsm_csr_arguments(spsm_csr_tuple tup) { Arguments arg; arg.M = std::get<0>(tup).M; arg.N = std::get<0>(tup).N; arg.K = std::get<0>(tup).K; arg.alpha = std::get<0>(tup).alpha; arg.transA = std::get<1>(tup); arg.transB = std::get<2>(tup); arg.orderB = std::get<3>(tup); arg.orderC = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.spsm_alg = std::get<8>(tup); arg.timing = 0; return arg; } Arguments setup_spsm_csr_arguments(spsm_csr_bin_tuple tup) { Arguments arg; arg.K = std::get<0>(tup).K; arg.alpha = std::get<0>(tup).alpha; arg.transA = std::get<1>(tup); arg.transB = std::get<2>(tup); arg.orderB = std::get<3>(tup); arg.orderC = std::get<4>(tup); arg.baseA = std::get<5>(tup); arg.diag_type = std::get<6>(tup); arg.fill_mode = std::get<7>(tup); arg.spsm_alg = std::get<8>(tup); arg.timing = 0; // Determine absolute path of test matrix std::string bin_file = std::get<9>(tup); // Matrices are stored at the same path in matrices directory arg.set_filename(bin_file); return arg; } #if(!defined(CUDART_VERSION) || CUDART_VERSION >= 11010) TEST(spsm_csr_bad_arg, spsm_csr_float) { testing_spsm_csr_bad_arg(); } TEST_P(parameterized_spsm_csr, spsm_csr_i32_float) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr, spsm_csr_i64_double) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr, spsm_csr_i32_float_complex) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr, spsm_csr_i64_double_complex) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr_bin, spsm_csr_bin_i32_float) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_spsm_csr_bin, spsm_csr_bin_i64_double) { Arguments arg = setup_spsm_csr_arguments(GetParam()); hipsparseStatus_t status = testing_spsm_csr(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(spsm_csr, parameterized_spsm_csr, testing::Combine(testing::ValuesIn(spsm_csr_M_N_K_alpha_range), testing::ValuesIn(spsm_csr_transA_range), testing::ValuesIn(spsm_csr_transB_range), testing::ValuesIn(spsm_csr_orderB_range), testing::ValuesIn(spsm_csr_orderC_range), testing::ValuesIn(spsm_csr_idxbase_range), testing::ValuesIn(spsm_csr_diag_type_range), testing::ValuesIn(spsm_csr_fill_mode_range), testing::ValuesIn(spsm_csr_alg_range))); INSTANTIATE_TEST_SUITE_P(spsm_csr_bin, parameterized_spsm_csr_bin, testing::Combine(testing::ValuesIn(spsm_csr_M_N_K_alpha_range), testing::ValuesIn(spsm_csr_transA_range), testing::ValuesIn(spsm_csr_transB_range), testing::ValuesIn(spsm_csr_orderB_range), testing::ValuesIn(spsm_csr_orderC_range), testing::ValuesIn(spsm_csr_idxbase_range), testing::ValuesIn(spsm_csr_diag_type_range), testing::ValuesIn(spsm_csr_fill_mode_range), testing::ValuesIn(spsm_csr_alg_range), testing::ValuesIn(spsm_csr_bin))); #endif ./clients/tests/test_csr2bsr.cpp0000664000175100017510000000266315176134305017045 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "test.hpp" #include "testing_csr2bsr.hpp" TEST_ROUTINE(csr2bsr, conversion, arg.M, arg.N, arg.block_dim, arg.baseA, arg.baseB, arg.dirA); ./clients/tests/test_nnz.cpp0000664000175100017510000000614415176134511016267 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "testing_nnz.hpp" #include "utility.hpp" #include #include #include typedef std::tuple nnz_tuple; int nnz_M_range[] = {0, 10, 500, 872, 1000}; int nnz_N_range[] = {0, 33, 242, 623, 1000}; int nnz_LD_range[] = {1000}; class parameterized_nnz : public testing::TestWithParam { protected: parameterized_nnz() {} virtual ~parameterized_nnz() {} virtual void SetUp() {} virtual void TearDown() {} }; Arguments setup_nnz_arguments(nnz_tuple tup) { Arguments arg; arg.M = std::get<0>(tup); arg.N = std::get<1>(tup); arg.lda = std::get<2>(tup); return arg; } TEST(nnz_bad_arg, nnz) { testing_nnz_bad_arg(); } TEST_P(parameterized_nnz, nnz_float) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_nnz, nnz_double) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_nnz, nnz_float_complex) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST_P(parameterized_nnz, nnz_double_complex) { Arguments arg = setup_nnz_arguments(GetParam()); hipsparseStatus_t status = testing_nnz(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } INSTANTIATE_TEST_SUITE_P(nnz, parameterized_nnz, testing::Combine(testing::ValuesIn(nnz_M_range), testing::ValuesIn(nnz_N_range), testing::ValuesIn(nnz_LD_range))); ./clients/tests/test_csr2coo.cpp0000664000175100017510000000261715176134511017035 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2018-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "test.hpp" #include "testing_csr2coo.hpp" TEST_ROUTINE(csr2coo, conversion, arg.M, arg.N, arg.baseA); ./clients/tests/test_bsrxmv.cpp0000664000175100017510000000445215176134511017003 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2021 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "hipsparse_arguments.hpp" #include "testing_bsrxmv.hpp" #include #if(!defined(CUDART_VERSION) || CUDART_VERSION < 13000) TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_float) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_double) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_float_complex) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv_bad_arg, bsrxmv_bad_arg_double_complex) { testing_bsrxmv_bad_arg(); } TEST(bsrxmv, bsrxmv_float) { Arguments arg; hipsparseStatus_t status = testing_bsrxmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrxmv, bsrxmv_double) { Arguments arg; hipsparseStatus_t status = testing_bsrxmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } TEST(bsrxmv, bsrxmv_hipComplex) { Arguments arg; hipsparseStatus_t status = testing_bsrxmv(arg); EXPECT_EQ(status, HIPSPARSE_STATUS_SUCCESS); } #endif ./clients/tests/test_bsrmv.cpp0000664000175100017510000000311615176134511016607 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "test.hpp" #include "testing_bsrmv.hpp" TEST_ROUTINE(bsrmv, level2, arg.M, arg.N, arg.block_dim, arg.alpha, arg.alphai, arg.beta, arg.betai, arg.dirA, arg.baseA); ./clients/tests/test_prune_dense2csr.cpp0000664000175100017510000000322315176134305020557 0ustar jenkinsjenkins/* ************************************************************************ * Copyright (C) 2020-2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #include "test.hpp" #include "testing_prune_dense2csr.hpp" TEST_ROUTINE_WITH_CONFIG(prune_dense2csr, conversion, hipsparse_test_config_real_only, arg.M, arg.N, arg.lda, arg.threshold, arg.baseA); ./clients/tests/test_prune_dense2csr.yaml0000664000175100017510000000331315176134511020736 0ustar jenkinsjenkins# ######################################################################## # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # ######################################################################## --- include: hipsparse_common.yaml Tests: - name: prune_dense2csr_bad_arg category: pre_checkin function: prune_dense2csr_bad_arg precision: *single_double_precisions - name: prune_dense2csr category: quick function: prune_dense2csr precision: *single_double_precisions M: [10, 500, 872] N: [33, 242, 623] lda: [1000] threshold: [0.0, 0.0012, 0.08736, 0.33333, 0.5, 1.7] baseA: [HIPSPARSE_INDEX_BASE_ZERO, HIPSPARSE_INDEX_BASE_ONE] ./clients/tests/hipsparse_test_dispatch.hpp0000664000175100017510000000435115176134305021343 0ustar jenkinsjenkins/*! \file */ /* ************************************************************************ * Copyright (C) 2025 Advanced Micro Devices, Inc. All rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * ************************************************************************ */ #pragma once #include "hipsparse_test.hpp" #include "hipsparse_test_dispatch_enum.hpp" #include "hipsparse_type_dispatch.hpp" template struct hipsparse_test_dispatch; template <> struct hipsparse_test_dispatch { template